diff --git a/packages/brandeur-plugin-debug/index.d.ts b/packages/brandeur-plugin-debug/index.d.ts new file mode 100644 index 0000000..35deb2f --- /dev/null +++ b/packages/brandeur-plugin-debug/index.d.ts @@ -0,0 +1,17 @@ +declare module 'brandeur-plugin-debug' { + import { Style } from 'brandeur' + + type Config = { + enabled?: boolean + position?: 1 | 2 | 3 | 4 + color?: string + debugWith?: 'border' | 'background' + borderSize?: number + showText?: boolean + styles?: Style + } + export default function debug( + autoActive?: boolean, + config?: Config + ): (style: Style) => Style +} diff --git a/packages/brandeur-plugin-enforce-longhand/index.d.ts b/packages/brandeur-plugin-enforce-longhand/index.d.ts index 5f3dad1..b596baf 100644 --- a/packages/brandeur-plugin-enforce-longhand/index.d.ts +++ b/packages/brandeur-plugin-enforce-longhand/index.d.ts @@ -1,10 +1,7 @@ declare module 'brandeur-plugin-enforce-longhand' { import { Style } from 'brandeur' - type Config = { - borderMode: 'none' | 'directional' | 'longhand' - } export default function enforceLonghand( - config?: Config + borderMode?: 'none' | 'directional' | 'longhand' ): (style: Style) => Style } diff --git a/packages/brandeur-plugin-sort-property/index.d.ts b/packages/brandeur-plugin-sort-property/index.d.ts index 3f6afb8..d88174b 100644 --- a/packages/brandeur-plugin-sort-property/index.d.ts +++ b/packages/brandeur-plugin-sort-property/index.d.ts @@ -1,11 +1,11 @@ declare module 'brandeur-plugin-sort-property' { import { Style } from 'brandeur' - type Config = { + type PropertyPriority = { [Property in keyof Style]: number } export default function enforceLonghand( - config?: Config + propertyPriority?: PropertyPriority ): (style: Style) => Style } diff --git a/packages/brandeur-primitives/index.d.ts b/packages/brandeur-primitives/index.d.ts index 7cdbb73..2466035 100644 --- a/packages/brandeur-primitives/index.d.ts +++ b/packages/brandeur-primitives/index.d.ts @@ -1,10 +1,9 @@ declare module 'brandeur-primitives' { - import { Config, Style, Rules, PluginProperties, Properties } from 'brandeur' + import { Style } from 'brandeur' import { ComponentProps, - ComponentPropsWithRef, - PropsWithChildren, ComponentType, + ComponentPropsWithRef, ElementType, RefAttributes, JSX, @@ -14,16 +13,8 @@ declare module 'brandeur-primitives' { ? Omit : never - type Options = Config< - Hooks, - Theme, - Plugins - > & { - baselineGrid?: number - } - - type ElProps = { - style?: Rules> + type ElProps = { + style?: Style as?: E | undefined } & DistributiveOmit< ComponentPropsWithRef, @@ -31,43 +22,20 @@ declare module 'brandeur-primitives' { > & RefAttributes - export function createSystem( - config: Options - ): { + type Options = { + css: T + baselineGrid?: number + } + + export function createSystem(config: Options): { El: ( - props: ElProps + props: ElProps[0]> ) => JSX.Element styleSheet: string - baselineGrid: number - plugins: Plugins - theme: Theme - hooks: Hooks - } - - type System = ReturnType< - typeof createSystem - > - - type UnionToIntersection = ( - T extends any ? (x: T) => any : never - ) extends (x: infer R) => any - ? R - : never - - type MergeProperties = { - [K in keyof T | keyof U]: K extends keyof T - ? K extends keyof U - ? T[K] | U[K] - : T[K] - : K extends keyof U - ? U[K] - : never + css: T } - type Props = MergeProperties< - Style, - UnionToIntersection> - > + type SystemStyle = ComponentProps['style'] type BoxProps = { bg?: T['backgroundColor'] @@ -116,11 +84,10 @@ declare module 'brandeur-primitives' { marginBottom?: T['marginBottom'] marginLeft?: T['marginLeft'] } - - export function createBox( - system: System + export function createBox( + system: System ): ( - props: ElProps & BoxProps> + props: ElProps> & BoxProps ) => JSX.Element type GridProps = { @@ -128,33 +95,26 @@ declare module 'brandeur-primitives' { gap?: T['gap'] areas?: T['gridTemplateAreas'] } - export function createGrid( - system: System + export function createGrid( + system: System ): ( - props: ElProps & GridProps> + props: ElProps> & GridProps ) => JSX.Element type ClickButtonProps = { disabled?: HTMLButtonElement['disabled'] type?: HTMLButtonElement['type'] } - type ClickLinkProps = { action: ComponentProps['href'] target?: HTMLAnchorElement['target'] } type ClickProps = ClickButtonProps | ClickLinkProps - - export function createClick< - Hooks extends string, - Theme = {}, - Plugins = [], - T extends ElementType = 'a', - >( - system: System, - linkComponent?: T + export function createClick( + system: System, + linkComponent?: L ): ( - props: ElProps & ClickProps + props: ElProps> & ClickProps ) => JSX.Element type OverlayProps = { @@ -166,16 +126,15 @@ declare module 'brandeur-primitives' { left?: T['left'] inset?: T['inset'] } - export function createOverlay( - system: System + export function createOverlay( + system: System ): ( - props: ElProps & OverlayProps> + props: ElProps> & OverlayProps ) => JSX.Element type Typography = { [variant: string]: Style } - type TextProps = { variant?: keyof Typography color?: T['color'] @@ -185,30 +144,23 @@ declare module 'brandeur-primitives' { size?: T['fontSize'] height?: T['lineHeight'] } - - export function createText< - Typography, - Hooks extends string, - Theme = {}, - Plugins = [], - >( - system: System, + export function createText( + system: System, typography: Typography ): ( - props: ElProps & - TextProps, Typography> + props: ElProps> & TextProps ) => JSX.Element type SpacerProps = { size: T['width'] } - export function createSpacer( - system: System - ): ComponentType>> + export function createSpacer( + system: System + ): ( + props: ElProps> & SpacerProps + ) => JSX.Element - export function createVisuallyHidden< - Hooks extends string, - Theme = {}, - Plugins = [], - >(system: System): ComponentType + export function createVisuallyHidden( + system: System + ): ComponentType } diff --git a/packages/brandeur-primitives/src/createSystem.js b/packages/brandeur-primitives/src/createSystem.js index ce188b0..7198745 100644 --- a/packages/brandeur-primitives/src/createSystem.js +++ b/packages/brandeur-primitives/src/createSystem.js @@ -2,32 +2,12 @@ import { createHooks } from 'brandeur' import createEl from './components/createEl.js' -export default function createSystem({ - hooks, - config, - theme, - keyframes, - fallbacks, - plugins = [], - baselineGrid = 1, -} = {}) { - const [styleSheet, css] = createHooks({ - hooks, - config, - theme, - keyframes, - fallbacks, - plugins, - }) - +export default function createSystem({ css, baselineGrid = 1 } = {}) { const El = createEl(css) return { El, baselineGrid, - styleSheet, - hooks, - plugins, - theme, + css, } } diff --git a/packages/brandeur/index.d.ts b/packages/brandeur/index.d.ts index 0309a16..450fab3 100644 --- a/packages/brandeur/index.d.ts +++ b/packages/brandeur/index.d.ts @@ -4,9 +4,6 @@ declare module 'brandeur' { import { WithHooks } from '@css-hooks/core' export type Style = CSSProperties - export type PluginProperties = T extends (_: infer Arg) => unknown - ? Arg - : Style export type Fallback = { property: string | Array @@ -18,18 +15,17 @@ declare module 'brandeur' { typeof createBaseHooks >[0] - export type Config = { + type Plugin = (style: T) => T + + export type Config = { hooks: HookOptions config?: Object theme?: Theme - plugins?: Plugins + plugins?: Array fallbacks?: Array } - export type Properties = WithHooks< - Hooks, - Style | PluginProperties - > + export type Properties = WithHooks export type Rule = (theme: Theme) => Props export type Rules = @@ -38,14 +34,24 @@ declare module 'brandeur' { | Rule | Array> - type CSSFunction = ( - properties_0: Rules, - ...properties_1: (Rules | undefined)[] + type CSSFunction = ( + properties_0: Rules>, + ...properties_1: (Rules> | undefined)[] ) => CSSProperties - export function createHooks( - config: Config - ): [string, CSSFunction>] + export function createHooks< + T = Style, + Hooks extends Record, + Theme = {}, + >( + config: Config + ): [string, CSSFunction] + + export function fallbackValue( + property: Fallback['property'], + value: Fallback['value'], + match?: Fallback['match'] + ): Fallback } declare module 'fela-plugin-bidi' { @@ -83,12 +89,12 @@ declare module 'fela-plugin-extend' { style: ExtendStyle } - type ExtendStyle = WithHooks & { + export type ExtendStyle = WithHooks & { extend?: Extension | Array> } export default function extend(): ( - style: ExtendStyle + style: ExtendStyle ) => Style }