Skip to content

Commit

Permalink
Merge e9b63e8 into dd0c3c7
Browse files Browse the repository at this point in the history
  • Loading branch information
heyjul3s committed Nov 9, 2020
2 parents dd0c3c7 + e9b63e8 commit e32b783
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 18 deletions.
7 changes: 4 additions & 3 deletions packages/component-generator/src/createBaseComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import { AnyStyledComponent } from 'styled-components';
import { ComponentVariant } from './typings';

export function createBaseComponents<ST, CP>(
BaseStyledComponent: AnyStyledComponent,
styles: ST
): { [key in keyof ST]: React.FC<CP> } {
): { [key in keyof ST]: React.FC<CP & ComponentVariant> } {
return !!styles && Object.keys(styles).length >= 1
? Object.entries(styles).reduce((acc, entry) => {
const [prop, style] = entry;
Expand All @@ -18,8 +19,8 @@ export function createBaseComponents<ST, CP>(
}

return acc;
}, {} as { [key in keyof ST]: React.FC<CP> })
: ({} as { [key in keyof ST]: React.FC<CP> });
}, {} as { [key in keyof ST]: React.FC<CP & ComponentVariant> })
: ({} as { [key in keyof ST]: React.FC<CP & ComponentVariant> });
}

export function createStyledFunctionComponent<ST, CP>(
Expand Down
6 changes: 5 additions & 1 deletion packages/component-generator/src/createStyledComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ import {
shadow,
space,
typography,
variant,
VariantArgs,
styleFn
} from 'styled-system';

import { BaseComponentProps } from './typings';

export function createStyledComponent<CP>(
systemStyleProps: styleFn[] = [],
baseStyles: CSSObject = {},
variants: VariantArgs<Record<string, unknown>, string, string> = {},
systemStyleProps: styleFn[] = [],
element: keyof JSX.IntrinsicElements = 'div'
): AnyStyledComponent {
return styled(element)<BaseComponentProps & CP>(
baseStyles,
variant(variants),
compose(
background,
border,
Expand Down
2 changes: 2 additions & 0 deletions packages/component-generator/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ export type BaseComponentProps =
| ShadowProps
| SpaceProps
| TypographyProps;

export type ComponentVariant = { variant?: string };
14 changes: 9 additions & 5 deletions packages/flex/src/FlexColBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { flexbox } from 'styled-system';
import { createStyledComponent } from '@artifak/component-generator';
import { FlexColBaseProps } from './typings';

export const FlexColBase = createStyledComponent<FlexColBaseProps>([flexbox], {
boxSizing: 'border-box',
position: 'relative',
flex: '0 0 auto'
});
export const FlexColBase = createStyledComponent<FlexColBaseProps>(
{
boxSizing: 'border-box',
position: 'relative',
flex: '0 0 auto'
},
{},
[flexbox]
);
14 changes: 9 additions & 5 deletions packages/flex/src/FlexRowBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { flexbox } from 'styled-system';
import { createStyledComponent } from '@artifak/component-generator';
import { FlexRowBaseProps } from './typings';

export const FlexRowBase = createStyledComponent<FlexRowBaseProps>([flexbox], {
display: 'flex',
flex: '0 1 auto',
flexWrap: 'wrap'
});
export const FlexRowBase = createStyledComponent<FlexRowBaseProps>(
{
display: 'flex',
flex: '0 1 auto',
flexWrap: 'wrap'
},
{},
[flexbox]
);
2 changes: 1 addition & 1 deletion packages/grid/src/GridBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

import { GridBaseProps } from './typings';

export const GridBase = createStyledComponent<GridBaseProps>([
export const GridBase = createStyledComponent<GridBaseProps>({}, {}, [
alignItems,
alignContent,
justifyItems,
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/src/GridItemBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

import { GridItemBaseProps } from './typings';

export const GridItemBase = createStyledComponent<GridItemBaseProps>([
export const GridItemBase = createStyledComponent<GridItemBaseProps>({}, {}, [
alignSelf,
gridArea,
gridRow,
Expand Down
3 changes: 2 additions & 1 deletion packages/imagery/src/ImageryBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const imageStylesConfig = system({

/* eslint-disable @typescript-eslint/no-explicit-any */
export const ImageryBase = createStyledComponent<Partial<ImageryProps>>(
[imageStylesConfig],
{ display: 'block', width: '100%', height: 'auto' },
{},
[imageStylesConfig],
'img'
);
2 changes: 1 addition & 1 deletion packages/typography/src/TypographyBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ const typographyStylesConfig = system({

export const TypographyBase = createStyledComponent<
typeof typographyStylesConfig
>([typographyStylesConfig]);
>({}, {}, [typographyStylesConfig]);

0 comments on commit e32b783

Please sign in to comment.