diff --git a/packages/block/src/createBlocks.tsx b/packages/block/src/createBlocks.tsx index 11db5e0..9e73eae 100644 --- a/packages/block/src/createBlocks.tsx +++ b/packages/block/src/createBlocks.tsx @@ -2,7 +2,7 @@ import { createComponents, ComponentsRecord, Settings, - StyledComponentConfig + BaseConfig } from '@artifak/component-generator'; /* eslint-disable @typescript-eslint/no-explicit-any */ @@ -12,7 +12,7 @@ export function createBlocks< Props = Record, Element = HTMLDivElement >( - base: StyledComponentConfig, + base: BaseConfig, settings: Settings ): ComponentsRecord { return createComponents(base, settings); diff --git a/packages/component-generator/src/createComponents.tsx b/packages/component-generator/src/createComponents.tsx index f38c2b4..1b6ce45 100644 --- a/packages/component-generator/src/createComponents.tsx +++ b/packages/component-generator/src/createComponents.tsx @@ -4,12 +4,7 @@ import isPlainObject from 'lodash.isplainobject'; import isEmpty from 'lodash.isempty'; import { createStyledComponent, createFC } from './createStyledComponent'; -import { - Settings, - StyledComponentConfig, - Variant, - ComponentsRecord -} from './typings'; +import { Settings, BaseConfig, Variant, ComponentsRecord } from './typings'; export function createComponents< Config = any, @@ -18,7 +13,7 @@ export function createComponents< Element = HTMLDivElement >( base: - | StyledComponentConfig, ThemeType> + | BaseConfig, ThemeType> | React.FC, settings: Settings ): ComponentsRecord { @@ -71,7 +66,7 @@ export function generateComponent< styles: { ...base.styles, ...setting }, attrs: { ...base.attrs, ...setting.attrs } || {}, element: !!setting.as ? setting.as : base.element - } as StyledComponentConfig, ThemeType, AllHTMLAttributes>); + } as BaseConfig, ThemeType, AllHTMLAttributes>); } /* eslint-disable @typescript-eslint/no-explicit-any */ diff --git a/packages/component-generator/src/createStyledComponent.tsx b/packages/component-generator/src/createStyledComponent.tsx index 964502b..2c5d730 100644 --- a/packages/component-generator/src/createStyledComponent.tsx +++ b/packages/component-generator/src/createStyledComponent.tsx @@ -15,7 +15,7 @@ import { typography } from 'styled-system'; -import { StyledComponentConfig, StyledSystemCSSObject } from './typings'; +import { BaseConfig, ScalableCSS } from './typings'; const pipe = (...fns) => value => fns.reduce((acc, fn) => fn(acc), value); @@ -24,13 +24,13 @@ export function createStyledComponent< Props extends any, Theme = void, Attributes = void ->(config: StyledComponentConfig): React.FC { +>(config: BaseConfig): React.FC { const Styled = createStyled(config); return createFC(Styled, config.styles); } export function createStyled( - config: StyledComponentConfig + config: BaseConfig ) { return pipe( createStyledElement, @@ -52,8 +52,8 @@ export function createStyledElement< Theme = void, Attributes = void >( - config: StyledComponentConfig -): StyledComponentConfig { + config: BaseConfig +): BaseConfig { const { element = 'div' } = config; return { ...config, @@ -67,8 +67,8 @@ export function createStyledAttributes< Theme = void, Attributes = void >( - config: StyledComponentConfig -): StyledComponentConfig { + config: BaseConfig +): BaseConfig { const { attrs = {} } = config; return !!config.component && config.hasOwnProperty('attrs') && !isEmpty(attrs) ? { ...config, component: config.component.attrs(attrs) } @@ -83,7 +83,7 @@ export function applyStyledProps< component = styled.div, styleProps = [], styles -}: StyledComponentConfig) { +}: BaseConfig) { const pseudoStyles = extractStylePseudos(styles); return component( @@ -103,9 +103,7 @@ export function applyStyledProps< ); } -export function extractStylePseudos( - styles: StyledSystemCSSObject = {} -): CSSObject { +export function extractStylePseudos(styles: ScalableCSS = {}): CSSObject { return Object.keys(styles).reduce((acc, key) => { if (key.includes('&:')) { acc[key] = styles[key]; diff --git a/packages/component-generator/src/index.tsx b/packages/component-generator/src/index.tsx index b2dc6e5..30bbc1c 100644 --- a/packages/component-generator/src/index.tsx +++ b/packages/component-generator/src/index.tsx @@ -9,6 +9,7 @@ export { BaseComponentProps, ComponentsRecord, Settings, - StyledComponentConfig, + BaseConfig, + ScalableCSS, Variant } from './typings'; diff --git a/packages/component-generator/src/typings.ts b/packages/component-generator/src/typings.ts index a3aad0b..8ca864b 100644 --- a/packages/component-generator/src/typings.ts +++ b/packages/component-generator/src/typings.ts @@ -38,12 +38,8 @@ export type Attrs, ThemeType> = | Attributes; /* eslint-disable @typescript-eslint/no-explicit-any */ -export type StyledComponentConfig< - Props = void, - Attributes = void, - ThemeType = void -> = { - styles?: StyledSystemCSSObject; +export type BaseConfig = { + styles?: ScalableCSS; attrs?: Attributes; styleProps?: styleFn[]; element?: keyof JSX.IntrinsicElements; @@ -57,14 +53,14 @@ export type StyledComponentConfig< export type CSSObjectWithScale = CSS.Properties; export type CSSPseudos = { [K in CSS.Pseudos]?: CSSObjectWithScale }; -export type StyledSystemCSSObject = CSSObjectWithScale & CSSPseudos; +export type ScalableCSS = CSSObjectWithScale & CSSPseudos; export type ComponentsRecord = { [key in keyof Dict | 'Base']: React.FC>; }; export type Settings = { - [key: string]: StyledSystemCSSObject & { + [key: string]: ScalableCSS & { as?: string; attrs?: AllHTMLAttributes; }; diff --git a/packages/text-input/src/createTextInputs.tsx b/packages/text-input/src/createTextInputs.tsx index 1854d95..9276dc0 100644 --- a/packages/text-input/src/createTextInputs.tsx +++ b/packages/text-input/src/createTextInputs.tsx @@ -3,7 +3,7 @@ import { createComponents, ComponentsRecord, Settings, - StyledComponentConfig + BaseConfig } from '@artifak/component-generator'; /* eslint-disable @typescript-eslint/no-explicit-any */ @@ -13,7 +13,7 @@ export function createTextInputs< ThemeType = any, Element = HTMLInputElement >( - base: StyledComponentConfig>, + base: BaseConfig>, settings: Settings ): ComponentsRecord { return createComponents( diff --git a/packages/typography/src/createTypography.ts b/packages/typography/src/createTypography.ts index e286149..4740da5 100644 --- a/packages/typography/src/createTypography.ts +++ b/packages/typography/src/createTypography.ts @@ -2,7 +2,7 @@ import { ComponentsRecord, createComponents, Settings, - StyledComponentConfig + BaseConfig } from '@artifak/component-generator'; import { styleFn } from 'styled-system'; import { TypographyBaseProps } from './typings'; @@ -15,7 +15,7 @@ export function createTypography< Props = Record, Element = HTMLDivElement >( - base: StyledComponentConfig, + base: BaseConfig, settings: Settings ): ComponentsRecord { const { styleProps } = getStyleProps(base); @@ -40,8 +40,8 @@ export function getStyleProps< Props = Record, Element = HTMLDivElement >( - base: StyledComponentConfig -): StyledComponentConfig { + base: BaseConfig +): BaseConfig { if (!base || !Object.keys(base).length) { return { styleProps: [] }; }