@yamada-ui/react 2.3.0-dev-20261027072316 → 2.3.0-dev-20261027074222
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core/components/create-component.cjs +1 -1
- package/dist/cjs/core/components/create-component.cjs.map +1 -1
- package/dist/esm/core/components/create-component.js +1 -1
- package/dist/esm/core/components/create-component.js.map +1 -1
- package/dist/types/components/chart/polar-chart.style.d.ts +1 -1
- package/package.json +2 -2
|
@@ -49,7 +49,7 @@ function createComponent(name, style) {
|
|
|
49
49
|
function useClassName(name, className) {
|
|
50
50
|
const system = require_system_provider.useSystem();
|
|
51
51
|
className = (0, require_utils_index.utils_exports.runIfFn)(className, system);
|
|
52
|
-
className ??= require_utils.getClassName(name
|
|
52
|
+
className ??= defaultClassName ?? require_utils.getClassName(name)(system);
|
|
53
53
|
return className;
|
|
54
54
|
}
|
|
55
55
|
function useComponentProps(props, { className, withContext = true, transferProps } = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-component.cjs","names":["Fragment","styled","getDisplayName","createContext","useSystem","getClassName","mergeProps","useComponentStyle","chainProps","getSlotClassName","useComponentSlotStyle","mergeSlotCSS"],"sources":["../../../../src/core/components/create-component.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, FunctionComponent } from \"react\"\nimport type { AnyString, Dict, Merge } from \"../../utils\"\nimport type { CSSObject, CSSSlotObject } from \"../css\"\nimport type {\n ComponentSlotStyle,\n ComponentStyle,\n StyledOptions,\n System,\n WithoutThemeProps,\n} from \"../system\"\nimport type {\n As,\n DOMElement,\n HTMLStyledProps,\n Component as OriginalComponent,\n} from \"./index.type\"\nimport { Fragment } from \"react\"\nimport {\n createContext,\n cx,\n isArray,\n isFunction,\n isObject,\n isString,\n runIfFn,\n toArray,\n toCamelCase,\n toPascalCase,\n} from \"../../utils\"\nimport { styled, useSystem } from \"../system\"\nimport { chainProps, mergeProps } from \"./props\"\nimport {\n getSlotClassName,\n mergeSlotCSS,\n useComponentSlotStyle,\n useComponentStyle,\n} from \"./use-component-style\"\nimport { getClassName, getDisplayName } from \"./utils\"\n\ntype AsWithFragment = \"fragment\" | As\ntype ClassName = ((system: System) => string) | string\n\ntype Component<\n Y extends AsWithFragment = AsWithFragment,\n M extends object = {},\n> = Y extends \"fragment\"\n ? FunctionComponent<M>\n : OriginalComponent<Exclude<Y, \"fragment\">, M>\n\nexport type ComponentSlotName<\n Y extends ComponentSlotStyle | ComponentStyle = ComponentSlotStyle,\n> = AnyString | Extract<keyof NonNullable<Y[\"base\"]>, string>\n\nexport type ComponentSlot<Y extends string> =\n | [Y, Y]\n | Y\n | { name: string; slot: [Y, Y] | Y }\n\nexport type InitialProps<Y extends Dict = Dict> =\n | ((props: Y) => any)\n | Partial<Y>\nexport type SuperProps<Y extends Dict = Dict> = ((props: Y) => any) | Y\n\nexport type SuperWithoutThemeProps<\n Y extends Dict = Dict,\n M extends Dict = Dict,\n D extends keyof Y = keyof Y,\n> = ((props: WithoutThemeProps<Y, M, D>) => any) | WithoutThemeProps<Y, M, D>\n\nexport interface UseComponentPropsOptions<\n Y extends number | string | symbol = string,\n> {\n className?: ClassName\n withContext?: boolean\n transferProps?: Y[]\n}\n\nexport interface ComponentOptions extends Omit<StyledOptions, \"transferProps\"> {\n className?: ClassName\n shouldStyleProps?: boolean\n}\n\ninterface classNameOptions<Y extends string = string> {\n className?: ClassName\n slot?: ComponentSlot<Y>\n}\n\nexport interface ComponentWithContextOptions<\n Y extends number | string | symbol = string,\n>\n extends ComponentOptions, UseComponentPropsOptions<Y> {}\n\nfunction createProxyComponent<\n Y extends AsWithFragment = \"div\",\n M extends Dict = Dict,\n>(el: FC<M> | Y, { shouldStyleProps, ...options }: ComponentOptions = {}) {\n options.shouldForwardProp ??= isFunction(el)\n shouldStyleProps ??= !isFunction(el)\n\n if (el === \"fragment\") el = Fragment\n\n if (shouldStyleProps || isString(el)) {\n const ProxyComponent = styled(el as As, options)\n\n ProxyComponent.displayName = \"ProxyComponent\"\n\n return ProxyComponent\n } else {\n el.displayName ??= \"ProxyComponent\"\n\n return el as FC<M>\n }\n}\n\nfunction withDisplayName<\n Y extends AsWithFragment = AsWithFragment,\n M extends object = {},\n>(Component: FC<M>, displayName: string) {\n Object.defineProperty(Component, \"name\", { value: displayName })\n Object.defineProperty(Component, \"displayName\", { value: displayName })\n\n return Component as Component<Y, M>\n}\n\nfunction getSlotKey<Y extends string>(slot?: ComponentSlot<Y>) {\n if (!slot) return \"unknown\"\n\n if (isArray(slot) || !isObject(slot))\n return toCamelCase(toArray(slot).join(\"-\"))\n else return toCamelCase(slot.name)\n}\n\nfunction getSlotName<Y extends string>(slot?: ComponentSlot<Y>) {\n if (!slot) return \"\"\n\n if (isArray(slot))\n return slot.map((value) => toPascalCase(value as string)).join(\"\")\n else if (isObject(slot)) return toPascalCase(slot.name)\n else return toPascalCase(slot)\n}\n\nexport function createComponent<\n Y extends object = {},\n M extends ComponentStyle = Dict,\n D extends Dict = Dict,\n>(name: string, style?: M) {\n const defaultClassName = style?.className\n const defaultDisplayName = getDisplayName(name)\n const [ComponentContext, useComponentContext] = createContext<D>({\n name: `${defaultDisplayName}Context`,\n })\n const [PropsContext, usePropsContext] = createContext<Partial<Y>>({\n name: `${defaultDisplayName}PropsContext`,\n strict: false,\n })\n\n function useClassName(name?: string, className?: ClassName) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= getClassName(name, defaultClassName)(system)\n\n return className\n }\n\n function useComponentProps<H extends Y = Y, R extends keyof H = keyof H>(\n props: H,\n {\n className,\n withContext = true,\n transferProps,\n }: UseComponentPropsOptions<R> = {},\n ) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= defaultClassName\n className ??= getClassName(name)(system)\n\n const contextProps = usePropsContext() ?? {}\n const mergedProps = withContext\n ? (mergeProps(contextProps, props)() as H)\n : props\n const [, rest] = useComponentStyle(mergedProps, {\n name,\n className,\n style,\n transferProps,\n })\n\n return rest\n }\n\n function component<D extends AsWithFragment = \"div\", H extends Dict = Y>(\n el: D | FC<H>,\n { name, className, ...options }: ComponentOptions = {},\n ) {\n const displayName = getDisplayName(name, defaultDisplayName)\n const ProxyComponent = createProxyComponent(el, options)\n\n return function (\n initialProps?: InitialProps<H>,\n ...superProps: SuperProps<H>[]\n ) {\n return withDisplayName<D, H>((props) => {\n className = useClassName(name, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = chainProps<any>(...superProps)()(computedProps)\n\n return (\n <ProxyComponent\n {...mergedProps}\n className={cx(className, mergedProps.className)}\n />\n )\n }, displayName)\n }\n }\n\n function withContext<\n D extends AsWithFragment = \"div\",\n H extends Y = Y,\n R extends keyof H = keyof H,\n >(\n el: D | FC<WithoutThemeProps<H, M, R>>,\n {\n name,\n className,\n withContext,\n transferProps,\n ...options\n }: ComponentWithContextOptions<R> = {},\n ) {\n const displayName = getDisplayName(name, defaultDisplayName)\n const ProxyComponent = createProxyComponent(el, options)\n\n return function (\n initialProps?: InitialProps<H>,\n ...superProps: SuperWithoutThemeProps<H, M, R>[]\n ) {\n return withDisplayName<D, H>((props) => {\n className = useClassName(name, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = useComponentProps(computedProps, {\n className,\n withContext,\n transferProps,\n })\n const rest = chainProps<any>(...toArray(superProps))()(mergedProps)\n\n return <ProxyComponent {...rest} />\n }, displayName)\n }\n }\n\n return {\n component,\n ComponentContext,\n PropsContext,\n useComponentContext,\n usePropsContext,\n withContext,\n useComponentProps,\n }\n}\n\nexport function createSlotComponent<\n Y extends object = {},\n M extends ComponentSlotStyle = Dict,\n D extends Dict = Dict,\n>(rootName: string, style?: M) {\n const rootClassName = style?.className\n const rootDisplayName = getDisplayName(rootName)\n const classNameMap = new Map<string, classNameOptions>()\n const [StyleContext, useStyleContext] = createContext<\n CSSSlotObject<ComponentSlotName<M>>\n >({\n name: `${rootDisplayName}StyleContext`,\n })\n const [ComponentContext, useComponentContext] = createContext<D>({\n name: `${rootDisplayName}Context`,\n })\n const [PropsContext, usePropsContext] = createContext<Partial<Y>>({\n name: `${rootDisplayName}PropsContext`,\n strict: false,\n })\n\n function useClassName(\n slot?: ComponentSlot<ComponentSlotName<M>>,\n className?: ClassName,\n ) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= getSlotClassName(\n rootClassName ?? getClassName(rootName)(system),\n slot,\n )\n\n return className\n }\n\n function useClassNames() {\n const system = useSystem()\n const entries = classNameMap.entries().map(([key, { className, slot }]) => {\n className = runIfFn(className, system)\n className ??= getSlotClassName(\n rootClassName ?? getClassName(rootName)(system),\n slot,\n )\n\n return [key, className]\n })\n\n return Object.fromEntries(\n entries.filter(([_, className]) => className),\n ) as { [key: string]: string }\n }\n\n function useRootComponentProps<\n Y extends Dict = {},\n R extends keyof Y = keyof Y,\n >(\n props: Y,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n {\n className,\n withContext = true,\n transferProps,\n }: UseComponentPropsOptions<R> = {},\n ): [\n CSSSlotObject,\n Merge<WithoutThemeProps<Y, M, R>, { css?: CSSObject | CSSObject[] }>,\n ] {\n className = useClassName(slot, className)\n\n const contextProps = usePropsContext() ?? {}\n const mergedProps = withContext\n ? (mergeProps(contextProps, props)() as Y)\n : props\n const [css, rest] = useComponentSlotStyle(mergedProps, {\n name: rootName,\n className,\n style,\n slot,\n transferProps,\n })\n\n return [css, rest]\n }\n\n function useSlotComponentProps<Y extends Dict = {}>(\n props: Y,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n { className }: Omit<UseComponentPropsOptions, \"transferProps\"> = {},\n ) {\n className = useClassName(slot, className)\n\n const style = useStyleContext()\n\n return {\n ...props,\n className: cx(className, props.className),\n css: mergeSlotCSS(slot, style, props.css),\n }\n }\n\n function component<H extends AsWithFragment = \"div\", R extends Dict = Dict>(\n el: FC<R> | H,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n { name, className, ...options }: ComponentOptions = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperProps<R>[]\n ) {\n return withDisplayName<H, R>((props) => {\n className = useClassName(slot, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = chainProps(...superProps)()(computedProps)\n\n return (\n <ProxyComponent\n {...mergedProps}\n className={cx(className, mergedProps.className)}\n />\n )\n }, displayName)\n }\n }\n\n function withProvider<\n H extends AsWithFragment = \"div\",\n R extends Y = Y,\n T extends keyof R = keyof R,\n >(\n el: FC<WithoutThemeProps<R, M, T>> | H,\n slot: ComponentSlot<ComponentSlotName<M>> = \"root\",\n {\n name,\n className,\n withContext,\n transferProps,\n ...options\n }: ComponentWithContextOptions<T> = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperWithoutThemeProps<R, M, T>[]\n ) {\n return withDisplayName<H, R>((props) => {\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const [context, mergedProps] = useRootComponentProps(\n computedProps,\n slot,\n {\n className,\n withContext,\n transferProps,\n },\n )\n const rest = chainProps<any>(...superProps)()(mergedProps)\n\n return (\n <StyleContext value={context}>\n <ProxyComponent {...rest} />\n </StyleContext>\n )\n }, displayName)\n }\n }\n\n function withContext<\n H extends AsWithFragment = \"div\",\n R extends Dict = H extends DOMElement ? HTMLStyledProps<H> : Dict,\n >(\n el: FC<R> | H,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n {\n name,\n className,\n withContext,\n ...options\n }: Omit<ComponentWithContextOptions, \"transferProps\"> = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperProps<R>[]\n ) {\n return withDisplayName<H, R>((props) => {\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = useSlotComponentProps(computedProps, slot, {\n className,\n withContext,\n })\n const rest = chainProps(...superProps)()(mergedProps)\n\n return <ProxyComponent {...rest} />\n }, displayName)\n }\n }\n\n return {\n component,\n ComponentContext,\n PropsContext,\n StyleContext,\n useClassNames,\n useComponentContext,\n usePropsContext,\n useStyleContext,\n withContext,\n withProvider,\n useRootComponentProps,\n useSlotComponentProps,\n }\n}\n"],"mappings":";;;;;;;;;;;AA8FA,SAAS,qBAGP,IAAe,EAAE,kBAAkB,GAAG,YAA8B,CAAC,GAAG;CACxE,QAAQ,uBAAA,GAAA,oBAAA,cAAsB,WAAA,CAAW,EAAE;CAC3C,qBAAqB,EAAA,GAAA,oBAAA,cAAC,WAAA,CAAW,EAAE;CAEnC,IAAI,OAAO,YAAY,KAAKA,MAAAA;CAE5B,IAAI,qBAAA,GAAA,oBAAA,cAAoB,SAAA,CAAS,EAAE,GAAG;EACpC,MAAM,iBAAiBC,gBAAAA,OAAO,IAAU,OAAO;EAE/C,eAAe,cAAc;EAE7B,OAAO;CACT,OAAO;EACL,GAAG,gBAAgB;EAEnB,OAAO;CACT;AACF;AAEA,SAAS,gBAGP,WAAkB,aAAqB;CACvC,OAAO,eAAe,WAAW,QAAQ,EAAE,OAAO,YAAY,CAAC;CAC/D,OAAO,eAAe,WAAW,eAAe,EAAE,OAAO,YAAY,CAAC;CAEtE,OAAO;AACT;A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,MAAM,iBAAiB,qBAAqB,IAAI,OAAO;EACvD,MAAM,UAAU,WAAW,IAAI;EAC/B,MAAM,WAAW,YAAY,IAAI;EACjC,MAAM,cAAcN,cAAAA,eAAe,MAAM,GAAG,kBAAkB,UAAU;EAExE,aAAa,IAAI,SAAS;GAAE;GAAW;EAAK,CAAC;EAE7C,OAAO,SACL,cACA,GAAG,YACH;GACA,OAAO,iBAAuB,UAAU;IAItC,MAAM,cAAc,uBAAA,GAAA,oBAAA,cAHE,WAAA,CAAW,YAAY,IACzC,aAAa,KAAK,IAClBI,cAAAA,WAAW,gBAAgB,CAAC,GAAG,KAAK,CAAC,CAAC,GACe,MAAM;KAC7D;KACA;IACF,CAAC;IACD,MAAM,OAAOE,cAAAA,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,WAAW;IAEpD,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAD,EAAgB,GAAI,KAAO,CAAA;GACpC,GAAG,WAAW;EAChB;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"create-component.cjs","names":["Fragment","styled","getDisplayName","createContext","useSystem","getClassName","mergeProps","useComponentStyle","chainProps","getSlotClassName","useComponentSlotStyle","mergeSlotCSS"],"sources":["../../../../src/core/components/create-component.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, FunctionComponent } from \"react\"\nimport type { AnyString, Dict, Merge } from \"../../utils\"\nimport type { CSSObject, CSSSlotObject } from \"../css\"\nimport type {\n ComponentSlotStyle,\n ComponentStyle,\n StyledOptions,\n System,\n WithoutThemeProps,\n} from \"../system\"\nimport type {\n As,\n DOMElement,\n HTMLStyledProps,\n Component as OriginalComponent,\n} from \"./index.type\"\nimport { Fragment } from \"react\"\nimport {\n createContext,\n cx,\n isArray,\n isFunction,\n isObject,\n isString,\n runIfFn,\n toArray,\n toCamelCase,\n toPascalCase,\n} from \"../../utils\"\nimport { styled, useSystem } from \"../system\"\nimport { chainProps, mergeProps } from \"./props\"\nimport {\n getSlotClassName,\n mergeSlotCSS,\n useComponentSlotStyle,\n useComponentStyle,\n} from \"./use-component-style\"\nimport { getClassName, getDisplayName } from \"./utils\"\n\ntype AsWithFragment = \"fragment\" | As\ntype ClassName = ((system: System) => string) | string\n\ntype Component<\n Y extends AsWithFragment = AsWithFragment,\n M extends object = {},\n> = Y extends \"fragment\"\n ? FunctionComponent<M>\n : OriginalComponent<Exclude<Y, \"fragment\">, M>\n\nexport type ComponentSlotName<\n Y extends ComponentSlotStyle | ComponentStyle = ComponentSlotStyle,\n> = AnyString | Extract<keyof NonNullable<Y[\"base\"]>, string>\n\nexport type ComponentSlot<Y extends string> =\n | [Y, Y]\n | Y\n | { name: string; slot: [Y, Y] | Y }\n\nexport type InitialProps<Y extends Dict = Dict> =\n | ((props: Y) => any)\n | Partial<Y>\nexport type SuperProps<Y extends Dict = Dict> = ((props: Y) => any) | Y\n\nexport type SuperWithoutThemeProps<\n Y extends Dict = Dict,\n M extends Dict = Dict,\n D extends keyof Y = keyof Y,\n> = ((props: WithoutThemeProps<Y, M, D>) => any) | WithoutThemeProps<Y, M, D>\n\nexport interface UseComponentPropsOptions<\n Y extends number | string | symbol = string,\n> {\n className?: ClassName\n withContext?: boolean\n transferProps?: Y[]\n}\n\nexport interface ComponentOptions extends Omit<StyledOptions, \"transferProps\"> {\n className?: ClassName\n shouldStyleProps?: boolean\n}\n\ninterface classNameOptions<Y extends string = string> {\n className?: ClassName\n slot?: ComponentSlot<Y>\n}\n\nexport interface ComponentWithContextOptions<\n Y extends number | string | symbol = string,\n>\n extends ComponentOptions, UseComponentPropsOptions<Y> {}\n\nfunction createProxyComponent<\n Y extends AsWithFragment = \"div\",\n M extends Dict = Dict,\n>(el: FC<M> | Y, { shouldStyleProps, ...options }: ComponentOptions = {}) {\n options.shouldForwardProp ??= isFunction(el)\n shouldStyleProps ??= !isFunction(el)\n\n if (el === \"fragment\") el = Fragment\n\n if (shouldStyleProps || isString(el)) {\n const ProxyComponent = styled(el as As, options)\n\n ProxyComponent.displayName = \"ProxyComponent\"\n\n return ProxyComponent\n } else {\n el.displayName ??= \"ProxyComponent\"\n\n return el as FC<M>\n }\n}\n\nfunction withDisplayName<\n Y extends AsWithFragment = AsWithFragment,\n M extends object = {},\n>(Component: FC<M>, displayName: string) {\n Object.defineProperty(Component, \"name\", { value: displayName })\n Object.defineProperty(Component, \"displayName\", { value: displayName })\n\n return Component as Component<Y, M>\n}\n\nfunction getSlotKey<Y extends string>(slot?: ComponentSlot<Y>) {\n if (!slot) return \"unknown\"\n\n if (isArray(slot) || !isObject(slot))\n return toCamelCase(toArray(slot).join(\"-\"))\n else return toCamelCase(slot.name)\n}\n\nfunction getSlotName<Y extends string>(slot?: ComponentSlot<Y>) {\n if (!slot) return \"\"\n\n if (isArray(slot))\n return slot.map((value) => toPascalCase(value as string)).join(\"\")\n else if (isObject(slot)) return toPascalCase(slot.name)\n else return toPascalCase(slot)\n}\n\nexport function createComponent<\n Y extends object = {},\n M extends ComponentStyle = Dict,\n D extends Dict = Dict,\n>(name: string, style?: M) {\n const defaultClassName = style?.className\n const defaultDisplayName = getDisplayName(name)\n const [ComponentContext, useComponentContext] = createContext<D>({\n name: `${defaultDisplayName}Context`,\n })\n const [PropsContext, usePropsContext] = createContext<Partial<Y>>({\n name: `${defaultDisplayName}PropsContext`,\n strict: false,\n })\n\n function useClassName(name?: string, className?: ClassName) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= defaultClassName ?? getClassName(name)(system)\n\n return className\n }\n\n function useComponentProps<H extends Y = Y, R extends keyof H = keyof H>(\n props: H,\n {\n className,\n withContext = true,\n transferProps,\n }: UseComponentPropsOptions<R> = {},\n ) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= defaultClassName\n className ??= getClassName(name)(system)\n\n const contextProps = usePropsContext() ?? {}\n const mergedProps = withContext\n ? (mergeProps(contextProps, props)() as H)\n : props\n const [, rest] = useComponentStyle(mergedProps, {\n name,\n className,\n style,\n transferProps,\n })\n\n return rest\n }\n\n function component<D extends AsWithFragment = \"div\", H extends Dict = Y>(\n el: D | FC<H>,\n { name, className, ...options }: ComponentOptions = {},\n ) {\n const displayName = getDisplayName(name, defaultDisplayName)\n const ProxyComponent = createProxyComponent(el, options)\n\n return function (\n initialProps?: InitialProps<H>,\n ...superProps: SuperProps<H>[]\n ) {\n return withDisplayName<D, H>((props) => {\n className = useClassName(name, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = chainProps<any>(...superProps)()(computedProps)\n\n return (\n <ProxyComponent\n {...mergedProps}\n className={cx(className, mergedProps.className)}\n />\n )\n }, displayName)\n }\n }\n\n function withContext<\n D extends AsWithFragment = \"div\",\n H extends Y = Y,\n R extends keyof H = keyof H,\n >(\n el: D | FC<WithoutThemeProps<H, M, R>>,\n {\n name,\n className,\n withContext,\n transferProps,\n ...options\n }: ComponentWithContextOptions<R> = {},\n ) {\n const displayName = getDisplayName(name, defaultDisplayName)\n const ProxyComponent = createProxyComponent(el, options)\n\n return function (\n initialProps?: InitialProps<H>,\n ...superProps: SuperWithoutThemeProps<H, M, R>[]\n ) {\n return withDisplayName<D, H>((props) => {\n className = useClassName(name, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = useComponentProps(computedProps, {\n className,\n withContext,\n transferProps,\n })\n const rest = chainProps<any>(...toArray(superProps))()(mergedProps)\n\n return <ProxyComponent {...rest} />\n }, displayName)\n }\n }\n\n return {\n component,\n ComponentContext,\n PropsContext,\n useComponentContext,\n usePropsContext,\n withContext,\n useComponentProps,\n }\n}\n\nexport function createSlotComponent<\n Y extends object = {},\n M extends ComponentSlotStyle = Dict,\n D extends Dict = Dict,\n>(rootName: string, style?: M) {\n const rootClassName = style?.className\n const rootDisplayName = getDisplayName(rootName)\n const classNameMap = new Map<string, classNameOptions>()\n const [StyleContext, useStyleContext] = createContext<\n CSSSlotObject<ComponentSlotName<M>>\n >({\n name: `${rootDisplayName}StyleContext`,\n })\n const [ComponentContext, useComponentContext] = createContext<D>({\n name: `${rootDisplayName}Context`,\n })\n const [PropsContext, usePropsContext] = createContext<Partial<Y>>({\n name: `${rootDisplayName}PropsContext`,\n strict: false,\n })\n\n function useClassName(\n slot?: ComponentSlot<ComponentSlotName<M>>,\n className?: ClassName,\n ) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= getSlotClassName(\n rootClassName ?? getClassName(rootName)(system),\n slot,\n )\n\n return className\n }\n\n function useClassNames() {\n const system = useSystem()\n const entries = classNameMap.entries().map(([key, { className, slot }]) => {\n className = runIfFn(className, system)\n className ??= getSlotClassName(\n rootClassName ?? getClassName(rootName)(system),\n slot,\n )\n\n return [key, className]\n })\n\n return Object.fromEntries(\n entries.filter(([_, className]) => className),\n ) as { [key: string]: string }\n }\n\n function useRootComponentProps<\n Y extends Dict = {},\n R extends keyof Y = keyof Y,\n >(\n props: Y,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n {\n className,\n withContext = true,\n transferProps,\n }: UseComponentPropsOptions<R> = {},\n ): [\n CSSSlotObject,\n Merge<WithoutThemeProps<Y, M, R>, { css?: CSSObject | CSSObject[] }>,\n ] {\n className = useClassName(slot, className)\n\n const contextProps = usePropsContext() ?? {}\n const mergedProps = withContext\n ? (mergeProps(contextProps, props)() as Y)\n : props\n const [css, rest] = useComponentSlotStyle(mergedProps, {\n name: rootName,\n className,\n style,\n slot,\n transferProps,\n })\n\n return [css, rest]\n }\n\n function useSlotComponentProps<Y extends Dict = {}>(\n props: Y,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n { className }: Omit<UseComponentPropsOptions, \"transferProps\"> = {},\n ) {\n className = useClassName(slot, className)\n\n const style = useStyleContext()\n\n return {\n ...props,\n className: cx(className, props.className),\n css: mergeSlotCSS(slot, style, props.css),\n }\n }\n\n function component<H extends AsWithFragment = \"div\", R extends Dict = Dict>(\n el: FC<R> | H,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n { name, className, ...options }: ComponentOptions = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperProps<R>[]\n ) {\n return withDisplayName<H, R>((props) => {\n className = useClassName(slot, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = chainProps(...superProps)()(computedProps)\n\n return (\n <ProxyComponent\n {...mergedProps}\n className={cx(className, mergedProps.className)}\n />\n )\n }, displayName)\n }\n }\n\n function withProvider<\n H extends AsWithFragment = \"div\",\n R extends Y = Y,\n T extends keyof R = keyof R,\n >(\n el: FC<WithoutThemeProps<R, M, T>> | H,\n slot: ComponentSlot<ComponentSlotName<M>> = \"root\",\n {\n name,\n className,\n withContext,\n transferProps,\n ...options\n }: ComponentWithContextOptions<T> = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperWithoutThemeProps<R, M, T>[]\n ) {\n return withDisplayName<H, R>((props) => {\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const [context, mergedProps] = useRootComponentProps(\n computedProps,\n slot,\n {\n className,\n withContext,\n transferProps,\n },\n )\n const rest = chainProps<any>(...superProps)()(mergedProps)\n\n return (\n <StyleContext value={context}>\n <ProxyComponent {...rest} />\n </StyleContext>\n )\n }, displayName)\n }\n }\n\n function withContext<\n H extends AsWithFragment = \"div\",\n R extends Dict = H extends DOMElement ? HTMLStyledProps<H> : Dict,\n >(\n el: FC<R> | H,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n {\n name,\n className,\n withContext,\n ...options\n }: Omit<ComponentWithContextOptions, \"transferProps\"> = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperProps<R>[]\n ) {\n return withDisplayName<H, R>((props) => {\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = useSlotComponentProps(computedProps, slot, {\n className,\n withContext,\n })\n const rest = chainProps(...superProps)()(mergedProps)\n\n return <ProxyComponent {...rest} />\n }, displayName)\n }\n }\n\n return {\n component,\n ComponentContext,\n PropsContext,\n StyleContext,\n useClassNames,\n useComponentContext,\n usePropsContext,\n useStyleContext,\n withContext,\n withProvider,\n useRootComponentProps,\n useSlotComponentProps,\n }\n}\n"],"mappings":";;;;;;;;;;;AA8FA,SAAS,qBAGP,IAAe,EAAE,kBAAkB,GAAG,YAA8B,CAAC,GAAG;CACxE,QAAQ,uBAAA,GAAA,oBAAA,cAAsB,WAAA,CAAW,EAAE;CAC3C,qBAAqB,EAAA,GAAA,oBAAA,cAAC,WAAA,CAAW,EAAE;CAEnC,IAAI,OAAO,YAAY,KAAKA,MAAAA;CAE5B,IAAI,qBAAA,GAAA,oBAAA,cAAoB,SAAA,CAAS,EAAE,GAAG;EACpC,MAAM,iBAAiBC,gBAAAA,OAAO,IAAU,OAAO;EAE/C,eAAe,cAAc;EAE7B,OAAO;CACT,OAAO;EACL,GAAG,gBAAgB;EAEnB,OAAO;CACT;AACF;AAEA,SAAS,gBAGP,WAAkB,aAAqB;CACvC,OAAO,eAAe,WAAW,QAAQ,EAAE,OAAO,YAAY,CAAC;CAC/D,OA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S,YAIP,IACA,MACA,EACE,MACA,WACA,aACA,GAAG,YACmD,CAAC,GACzD;EACA,MAAM,iBAAiB,qBAAqB,IAAI,OAAO;EACvD,MAAM,UAAU,WAAW,IAAI;EAC/B,MAAM,WAAW,YAAY,IAAI;EACjC,MAAM,cAAcN,cAAAA,eAAe,MAAM,GAAG,kBAAkB,UAAU;EAExE,aAAa,IAAI,SAAS;GAAE;GAAW;EAAK,CAAC;EAE7C,OAAO,SACL,cACA,GAAG,YACH;GACA,OAAO,iBAAuB,UAAU;IAItC,MAAM,cAAc,uBAAA,GAAA,oBAAA,cAHE,WAAA,CAAW,YAAY,IACzC,aAAa,KAAK,IAClBI,cAAAA,WAAW,gBAAgB,CAAC,GAAG,KAAK,CAAC,CAAC,GACe,MAAM;KAC7D;KACA;IACF,CAAC;IACD,MAAM,OAAOE,cAAAA,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,WAAW;IAEpD,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAD,EAAgB,GAAI,KAAO,CAAA;GACpC,GAAG,WAAW;EAChB;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -49,7 +49,7 @@ function createComponent(name, style) {
|
|
|
49
49
|
function useClassName(name, className) {
|
|
50
50
|
const system = useSystem();
|
|
51
51
|
className = (0, utils_exports.runIfFn)(className, system);
|
|
52
|
-
className ??= getClassName(name
|
|
52
|
+
className ??= defaultClassName ?? getClassName(name)(system);
|
|
53
53
|
return className;
|
|
54
54
|
}
|
|
55
55
|
function useComponentProps(props, { className, withContext = true, transferProps } = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-component.js","names":["isFunction","isString","isArray","isObject","toCamelCase","toArray","toPascalCase","createContext","runIfFn","cx"],"sources":["../../../../src/core/components/create-component.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, FunctionComponent } from \"react\"\nimport type { AnyString, Dict, Merge } from \"../../utils\"\nimport type { CSSObject, CSSSlotObject } from \"../css\"\nimport type {\n ComponentSlotStyle,\n ComponentStyle,\n StyledOptions,\n System,\n WithoutThemeProps,\n} from \"../system\"\nimport type {\n As,\n DOMElement,\n HTMLStyledProps,\n Component as OriginalComponent,\n} from \"./index.type\"\nimport { Fragment } from \"react\"\nimport {\n createContext,\n cx,\n isArray,\n isFunction,\n isObject,\n isString,\n runIfFn,\n toArray,\n toCamelCase,\n toPascalCase,\n} from \"../../utils\"\nimport { styled, useSystem } from \"../system\"\nimport { chainProps, mergeProps } from \"./props\"\nimport {\n getSlotClassName,\n mergeSlotCSS,\n useComponentSlotStyle,\n useComponentStyle,\n} from \"./use-component-style\"\nimport { getClassName, getDisplayName } from \"./utils\"\n\ntype AsWithFragment = \"fragment\" | As\ntype ClassName = ((system: System) => string) | string\n\ntype Component<\n Y extends AsWithFragment = AsWithFragment,\n M extends object = {},\n> = Y extends \"fragment\"\n ? FunctionComponent<M>\n : OriginalComponent<Exclude<Y, \"fragment\">, M>\n\nexport type ComponentSlotName<\n Y extends ComponentSlotStyle | ComponentStyle = ComponentSlotStyle,\n> = AnyString | Extract<keyof NonNullable<Y[\"base\"]>, string>\n\nexport type ComponentSlot<Y extends string> =\n | [Y, Y]\n | Y\n | { name: string; slot: [Y, Y] | Y }\n\nexport type InitialProps<Y extends Dict = Dict> =\n | ((props: Y) => any)\n | Partial<Y>\nexport type SuperProps<Y extends Dict = Dict> = ((props: Y) => any) | Y\n\nexport type SuperWithoutThemeProps<\n Y extends Dict = Dict,\n M extends Dict = Dict,\n D extends keyof Y = keyof Y,\n> = ((props: WithoutThemeProps<Y, M, D>) => any) | WithoutThemeProps<Y, M, D>\n\nexport interface UseComponentPropsOptions<\n Y extends number | string | symbol = string,\n> {\n className?: ClassName\n withContext?: boolean\n transferProps?: Y[]\n}\n\nexport interface ComponentOptions extends Omit<StyledOptions, \"transferProps\"> {\n className?: ClassName\n shouldStyleProps?: boolean\n}\n\ninterface classNameOptions<Y extends string = string> {\n className?: ClassName\n slot?: ComponentSlot<Y>\n}\n\nexport interface ComponentWithContextOptions<\n Y extends number | string | symbol = string,\n>\n extends ComponentOptions, UseComponentPropsOptions<Y> {}\n\nfunction createProxyComponent<\n Y extends AsWithFragment = \"div\",\n M extends Dict = Dict,\n>(el: FC<M> | Y, { shouldStyleProps, ...options }: ComponentOptions = {}) {\n options.shouldForwardProp ??= isFunction(el)\n shouldStyleProps ??= !isFunction(el)\n\n if (el === \"fragment\") el = Fragment\n\n if (shouldStyleProps || isString(el)) {\n const ProxyComponent = styled(el as As, options)\n\n ProxyComponent.displayName = \"ProxyComponent\"\n\n return ProxyComponent\n } else {\n el.displayName ??= \"ProxyComponent\"\n\n return el as FC<M>\n }\n}\n\nfunction withDisplayName<\n Y extends AsWithFragment = AsWithFragment,\n M extends object = {},\n>(Component: FC<M>, displayName: string) {\n Object.defineProperty(Component, \"name\", { value: displayName })\n Object.defineProperty(Component, \"displayName\", { value: displayName })\n\n return Component as Component<Y, M>\n}\n\nfunction getSlotKey<Y extends string>(slot?: ComponentSlot<Y>) {\n if (!slot) return \"unknown\"\n\n if (isArray(slot) || !isObject(slot))\n return toCamelCase(toArray(slot).join(\"-\"))\n else return toCamelCase(slot.name)\n}\n\nfunction getSlotName<Y extends string>(slot?: ComponentSlot<Y>) {\n if (!slot) return \"\"\n\n if (isArray(slot))\n return slot.map((value) => toPascalCase(value as string)).join(\"\")\n else if (isObject(slot)) return toPascalCase(slot.name)\n else return toPascalCase(slot)\n}\n\nexport function createComponent<\n Y extends object = {},\n M extends ComponentStyle = Dict,\n D extends Dict = Dict,\n>(name: string, style?: M) {\n const defaultClassName = style?.className\n const defaultDisplayName = getDisplayName(name)\n const [ComponentContext, useComponentContext] = createContext<D>({\n name: `${defaultDisplayName}Context`,\n })\n const [PropsContext, usePropsContext] = createContext<Partial<Y>>({\n name: `${defaultDisplayName}PropsContext`,\n strict: false,\n })\n\n function useClassName(name?: string, className?: ClassName) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= getClassName(name, defaultClassName)(system)\n\n return className\n }\n\n function useComponentProps<H extends Y = Y, R extends keyof H = keyof H>(\n props: H,\n {\n className,\n withContext = true,\n transferProps,\n }: UseComponentPropsOptions<R> = {},\n ) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= defaultClassName\n className ??= getClassName(name)(system)\n\n const contextProps = usePropsContext() ?? {}\n const mergedProps = withContext\n ? (mergeProps(contextProps, props)() as H)\n : props\n const [, rest] = useComponentStyle(mergedProps, {\n name,\n className,\n style,\n transferProps,\n })\n\n return rest\n }\n\n function component<D extends AsWithFragment = \"div\", H extends Dict = Y>(\n el: D | FC<H>,\n { name, className, ...options }: ComponentOptions = {},\n ) {\n const displayName = getDisplayName(name, defaultDisplayName)\n const ProxyComponent = createProxyComponent(el, options)\n\n return function (\n initialProps?: InitialProps<H>,\n ...superProps: SuperProps<H>[]\n ) {\n return withDisplayName<D, H>((props) => {\n className = useClassName(name, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = chainProps<any>(...superProps)()(computedProps)\n\n return (\n <ProxyComponent\n {...mergedProps}\n className={cx(className, mergedProps.className)}\n />\n )\n }, displayName)\n }\n }\n\n function withContext<\n D extends AsWithFragment = \"div\",\n H extends Y = Y,\n R extends keyof H = keyof H,\n >(\n el: D | FC<WithoutThemeProps<H, M, R>>,\n {\n name,\n className,\n withContext,\n transferProps,\n ...options\n }: ComponentWithContextOptions<R> = {},\n ) {\n const displayName = getDisplayName(name, defaultDisplayName)\n const ProxyComponent = createProxyComponent(el, options)\n\n return function (\n initialProps?: InitialProps<H>,\n ...superProps: SuperWithoutThemeProps<H, M, R>[]\n ) {\n return withDisplayName<D, H>((props) => {\n className = useClassName(name, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = useComponentProps(computedProps, {\n className,\n withContext,\n transferProps,\n })\n const rest = chainProps<any>(...toArray(superProps))()(mergedProps)\n\n return <ProxyComponent {...rest} />\n }, displayName)\n }\n }\n\n return {\n component,\n ComponentContext,\n PropsContext,\n useComponentContext,\n usePropsContext,\n withContext,\n useComponentProps,\n }\n}\n\nexport function createSlotComponent<\n Y extends object = {},\n M extends ComponentSlotStyle = Dict,\n D extends Dict = Dict,\n>(rootName: string, style?: M) {\n const rootClassName = style?.className\n const rootDisplayName = getDisplayName(rootName)\n const classNameMap = new Map<string, classNameOptions>()\n const [StyleContext, useStyleContext] = createContext<\n CSSSlotObject<ComponentSlotName<M>>\n >({\n name: `${rootDisplayName}StyleContext`,\n })\n const [ComponentContext, useComponentContext] = createContext<D>({\n name: `${rootDisplayName}Context`,\n })\n const [PropsContext, usePropsContext] = createContext<Partial<Y>>({\n name: `${rootDisplayName}PropsContext`,\n strict: false,\n })\n\n function useClassName(\n slot?: ComponentSlot<ComponentSlotName<M>>,\n className?: ClassName,\n ) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= getSlotClassName(\n rootClassName ?? getClassName(rootName)(system),\n slot,\n )\n\n return className\n }\n\n function useClassNames() {\n const system = useSystem()\n const entries = classNameMap.entries().map(([key, { className, slot }]) => {\n className = runIfFn(className, system)\n className ??= getSlotClassName(\n rootClassName ?? getClassName(rootName)(system),\n slot,\n )\n\n return [key, className]\n })\n\n return Object.fromEntries(\n entries.filter(([_, className]) => className),\n ) as { [key: string]: string }\n }\n\n function useRootComponentProps<\n Y extends Dict = {},\n R extends keyof Y = keyof Y,\n >(\n props: Y,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n {\n className,\n withContext = true,\n transferProps,\n }: UseComponentPropsOptions<R> = {},\n ): [\n CSSSlotObject,\n Merge<WithoutThemeProps<Y, M, R>, { css?: CSSObject | CSSObject[] }>,\n ] {\n className = useClassName(slot, className)\n\n const contextProps = usePropsContext() ?? {}\n const mergedProps = withContext\n ? (mergeProps(contextProps, props)() as Y)\n : props\n const [css, rest] = useComponentSlotStyle(mergedProps, {\n name: rootName,\n className,\n style,\n slot,\n transferProps,\n })\n\n return [css, rest]\n }\n\n function useSlotComponentProps<Y extends Dict = {}>(\n props: Y,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n { className }: Omit<UseComponentPropsOptions, \"transferProps\"> = {},\n ) {\n className = useClassName(slot, className)\n\n const style = useStyleContext()\n\n return {\n ...props,\n className: cx(className, props.className),\n css: mergeSlotCSS(slot, style, props.css),\n }\n }\n\n function component<H extends AsWithFragment = \"div\", R extends Dict = Dict>(\n el: FC<R> | H,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n { name, className, ...options }: ComponentOptions = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperProps<R>[]\n ) {\n return withDisplayName<H, R>((props) => {\n className = useClassName(slot, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = chainProps(...superProps)()(computedProps)\n\n return (\n <ProxyComponent\n {...mergedProps}\n className={cx(className, mergedProps.className)}\n />\n )\n }, displayName)\n }\n }\n\n function withProvider<\n H extends AsWithFragment = \"div\",\n R extends Y = Y,\n T extends keyof R = keyof R,\n >(\n el: FC<WithoutThemeProps<R, M, T>> | H,\n slot: ComponentSlot<ComponentSlotName<M>> = \"root\",\n {\n name,\n className,\n withContext,\n transferProps,\n ...options\n }: ComponentWithContextOptions<T> = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperWithoutThemeProps<R, M, T>[]\n ) {\n return withDisplayName<H, R>((props) => {\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const [context, mergedProps] = useRootComponentProps(\n computedProps,\n slot,\n {\n className,\n withContext,\n transferProps,\n },\n )\n const rest = chainProps<any>(...superProps)()(mergedProps)\n\n return (\n <StyleContext value={context}>\n <ProxyComponent {...rest} />\n </StyleContext>\n )\n }, displayName)\n }\n }\n\n function withContext<\n H extends AsWithFragment = \"div\",\n R extends Dict = H extends DOMElement ? HTMLStyledProps<H> : Dict,\n >(\n el: FC<R> | H,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n {\n name,\n className,\n withContext,\n ...options\n }: Omit<ComponentWithContextOptions, \"transferProps\"> = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperProps<R>[]\n ) {\n return withDisplayName<H, R>((props) => {\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = useSlotComponentProps(computedProps, slot, {\n className,\n withContext,\n })\n const rest = chainProps(...superProps)()(mergedProps)\n\n return <ProxyComponent {...rest} />\n }, displayName)\n }\n }\n\n return {\n component,\n ComponentContext,\n PropsContext,\n StyleContext,\n useClassNames,\n useComponentContext,\n usePropsContext,\n useStyleContext,\n withContext,\n withProvider,\n useRootComponentProps,\n useSlotComponentProps,\n }\n}\n"],"mappings":";;;;;;;;;;;AA8FA,SAAS,qBAGP,IAAe,EAAE,kBAAkB,GAAG,YAA8B,CAAC,GAAG;CACxE,QAAQ,uBAAA,GAAsBA,cAAAA,WAAAA,CAAW,EAAE;CAC3C,qBAAqB,EAAA,GAACA,cAAAA,WAAAA,CAAW,EAAE;CAEnC,IAAI,OAAO,YAAY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AkB,UAAU;EAExE,aAAa,IAAI,SAAS;GAAE;GAAW;EAAK,CAAC;EAE7C,OAAO,SACL,cACA,GAAG,YACH;GACA,OAAO,iBAAuB,UAAU;IAItC,MAAM,cAAc,uBAAA,GAHEA,cAAAA,WAAAA,CAAW,YAAY,IACzC,aAAa,KAAK,IAClB,WAAW,gBAAgB,CAAC,GAAG,KAAK,CAAC,CAAC,GACe,MAAM;KAC7D;KACA;IACF,CAAC;IACD,MAAM,OAAO,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,WAAW;IAEpD,OAAO,oBAAC,gBAAD,EAAgB,GAAI,KAAO,CAAA;GACpC,GAAG,WAAW;EAChB;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"create-component.js","names":["isFunction","isString","isArray","isObject","toCamelCase","toArray","toPascalCase","createContext","runIfFn","cx"],"sources":["../../../../src/core/components/create-component.tsx"],"sourcesContent":["\"use client\"\n\nimport type { FC, FunctionComponent } from \"react\"\nimport type { AnyString, Dict, Merge } from \"../../utils\"\nimport type { CSSObject, CSSSlotObject } from \"../css\"\nimport type {\n ComponentSlotStyle,\n ComponentStyle,\n StyledOptions,\n System,\n WithoutThemeProps,\n} from \"../system\"\nimport type {\n As,\n DOMElement,\n HTMLStyledProps,\n Component as OriginalComponent,\n} from \"./index.type\"\nimport { Fragment } from \"react\"\nimport {\n createContext,\n cx,\n isArray,\n isFunction,\n isObject,\n isString,\n runIfFn,\n toArray,\n toCamelCase,\n toPascalCase,\n} from \"../../utils\"\nimport { styled, useSystem } from \"../system\"\nimport { chainProps, mergeProps } from \"./props\"\nimport {\n getSlotClassName,\n mergeSlotCSS,\n useComponentSlotStyle,\n useComponentStyle,\n} from \"./use-component-style\"\nimport { getClassName, getDisplayName } from \"./utils\"\n\ntype AsWithFragment = \"fragment\" | As\ntype ClassName = ((system: System) => string) | string\n\ntype Component<\n Y extends AsWithFragment = AsWithFragment,\n M extends object = {},\n> = Y extends \"fragment\"\n ? FunctionComponent<M>\n : OriginalComponent<Exclude<Y, \"fragment\">, M>\n\nexport type ComponentSlotName<\n Y extends ComponentSlotStyle | ComponentStyle = ComponentSlotStyle,\n> = AnyString | Extract<keyof NonNullable<Y[\"base\"]>, string>\n\nexport type ComponentSlot<Y extends string> =\n | [Y, Y]\n | Y\n | { name: string; slot: [Y, Y] | Y }\n\nexport type InitialProps<Y extends Dict = Dict> =\n | ((props: Y) => any)\n | Partial<Y>\nexport type SuperProps<Y extends Dict = Dict> = ((props: Y) => any) | Y\n\nexport type SuperWithoutThemeProps<\n Y extends Dict = Dict,\n M extends Dict = Dict,\n D extends keyof Y = keyof Y,\n> = ((props: WithoutThemeProps<Y, M, D>) => any) | WithoutThemeProps<Y, M, D>\n\nexport interface UseComponentPropsOptions<\n Y extends number | string | symbol = string,\n> {\n className?: ClassName\n withContext?: boolean\n transferProps?: Y[]\n}\n\nexport interface ComponentOptions extends Omit<StyledOptions, \"transferProps\"> {\n className?: ClassName\n shouldStyleProps?: boolean\n}\n\ninterface classNameOptions<Y extends string = string> {\n className?: ClassName\n slot?: ComponentSlot<Y>\n}\n\nexport interface ComponentWithContextOptions<\n Y extends number | string | symbol = string,\n>\n extends ComponentOptions, UseComponentPropsOptions<Y> {}\n\nfunction createProxyComponent<\n Y extends AsWithFragment = \"div\",\n M extends Dict = Dict,\n>(el: FC<M> | Y, { shouldStyleProps, ...options }: ComponentOptions = {}) {\n options.shouldForwardProp ??= isFunction(el)\n shouldStyleProps ??= !isFunction(el)\n\n if (el === \"fragment\") el = Fragment\n\n if (shouldStyleProps || isString(el)) {\n const ProxyComponent = styled(el as As, options)\n\n ProxyComponent.displayName = \"ProxyComponent\"\n\n return ProxyComponent\n } else {\n el.displayName ??= \"ProxyComponent\"\n\n return el as FC<M>\n }\n}\n\nfunction withDisplayName<\n Y extends AsWithFragment = AsWithFragment,\n M extends object = {},\n>(Component: FC<M>, displayName: string) {\n Object.defineProperty(Component, \"name\", { value: displayName })\n Object.defineProperty(Component, \"displayName\", { value: displayName })\n\n return Component as Component<Y, M>\n}\n\nfunction getSlotKey<Y extends string>(slot?: ComponentSlot<Y>) {\n if (!slot) return \"unknown\"\n\n if (isArray(slot) || !isObject(slot))\n return toCamelCase(toArray(slot).join(\"-\"))\n else return toCamelCase(slot.name)\n}\n\nfunction getSlotName<Y extends string>(slot?: ComponentSlot<Y>) {\n if (!slot) return \"\"\n\n if (isArray(slot))\n return slot.map((value) => toPascalCase(value as string)).join(\"\")\n else if (isObject(slot)) return toPascalCase(slot.name)\n else return toPascalCase(slot)\n}\n\nexport function createComponent<\n Y extends object = {},\n M extends ComponentStyle = Dict,\n D extends Dict = Dict,\n>(name: string, style?: M) {\n const defaultClassName = style?.className\n const defaultDisplayName = getDisplayName(name)\n const [ComponentContext, useComponentContext] = createContext<D>({\n name: `${defaultDisplayName}Context`,\n })\n const [PropsContext, usePropsContext] = createContext<Partial<Y>>({\n name: `${defaultDisplayName}PropsContext`,\n strict: false,\n })\n\n function useClassName(name?: string, className?: ClassName) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= defaultClassName ?? getClassName(name)(system)\n\n return className\n }\n\n function useComponentProps<H extends Y = Y, R extends keyof H = keyof H>(\n props: H,\n {\n className,\n withContext = true,\n transferProps,\n }: UseComponentPropsOptions<R> = {},\n ) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= defaultClassName\n className ??= getClassName(name)(system)\n\n const contextProps = usePropsContext() ?? {}\n const mergedProps = withContext\n ? (mergeProps(contextProps, props)() as H)\n : props\n const [, rest] = useComponentStyle(mergedProps, {\n name,\n className,\n style,\n transferProps,\n })\n\n return rest\n }\n\n function component<D extends AsWithFragment = \"div\", H extends Dict = Y>(\n el: D | FC<H>,\n { name, className, ...options }: ComponentOptions = {},\n ) {\n const displayName = getDisplayName(name, defaultDisplayName)\n const ProxyComponent = createProxyComponent(el, options)\n\n return function (\n initialProps?: InitialProps<H>,\n ...superProps: SuperProps<H>[]\n ) {\n return withDisplayName<D, H>((props) => {\n className = useClassName(name, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = chainProps<any>(...superProps)()(computedProps)\n\n return (\n <ProxyComponent\n {...mergedProps}\n className={cx(className, mergedProps.className)}\n />\n )\n }, displayName)\n }\n }\n\n function withContext<\n D extends AsWithFragment = \"div\",\n H extends Y = Y,\n R extends keyof H = keyof H,\n >(\n el: D | FC<WithoutThemeProps<H, M, R>>,\n {\n name,\n className,\n withContext,\n transferProps,\n ...options\n }: ComponentWithContextOptions<R> = {},\n ) {\n const displayName = getDisplayName(name, defaultDisplayName)\n const ProxyComponent = createProxyComponent(el, options)\n\n return function (\n initialProps?: InitialProps<H>,\n ...superProps: SuperWithoutThemeProps<H, M, R>[]\n ) {\n return withDisplayName<D, H>((props) => {\n className = useClassName(name, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = useComponentProps(computedProps, {\n className,\n withContext,\n transferProps,\n })\n const rest = chainProps<any>(...toArray(superProps))()(mergedProps)\n\n return <ProxyComponent {...rest} />\n }, displayName)\n }\n }\n\n return {\n component,\n ComponentContext,\n PropsContext,\n useComponentContext,\n usePropsContext,\n withContext,\n useComponentProps,\n }\n}\n\nexport function createSlotComponent<\n Y extends object = {},\n M extends ComponentSlotStyle = Dict,\n D extends Dict = Dict,\n>(rootName: string, style?: M) {\n const rootClassName = style?.className\n const rootDisplayName = getDisplayName(rootName)\n const classNameMap = new Map<string, classNameOptions>()\n const [StyleContext, useStyleContext] = createContext<\n CSSSlotObject<ComponentSlotName<M>>\n >({\n name: `${rootDisplayName}StyleContext`,\n })\n const [ComponentContext, useComponentContext] = createContext<D>({\n name: `${rootDisplayName}Context`,\n })\n const [PropsContext, usePropsContext] = createContext<Partial<Y>>({\n name: `${rootDisplayName}PropsContext`,\n strict: false,\n })\n\n function useClassName(\n slot?: ComponentSlot<ComponentSlotName<M>>,\n className?: ClassName,\n ) {\n const system = useSystem()\n\n className = runIfFn(className, system)\n className ??= getSlotClassName(\n rootClassName ?? getClassName(rootName)(system),\n slot,\n )\n\n return className\n }\n\n function useClassNames() {\n const system = useSystem()\n const entries = classNameMap.entries().map(([key, { className, slot }]) => {\n className = runIfFn(className, system)\n className ??= getSlotClassName(\n rootClassName ?? getClassName(rootName)(system),\n slot,\n )\n\n return [key, className]\n })\n\n return Object.fromEntries(\n entries.filter(([_, className]) => className),\n ) as { [key: string]: string }\n }\n\n function useRootComponentProps<\n Y extends Dict = {},\n R extends keyof Y = keyof Y,\n >(\n props: Y,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n {\n className,\n withContext = true,\n transferProps,\n }: UseComponentPropsOptions<R> = {},\n ): [\n CSSSlotObject,\n Merge<WithoutThemeProps<Y, M, R>, { css?: CSSObject | CSSObject[] }>,\n ] {\n className = useClassName(slot, className)\n\n const contextProps = usePropsContext() ?? {}\n const mergedProps = withContext\n ? (mergeProps(contextProps, props)() as Y)\n : props\n const [css, rest] = useComponentSlotStyle(mergedProps, {\n name: rootName,\n className,\n style,\n slot,\n transferProps,\n })\n\n return [css, rest]\n }\n\n function useSlotComponentProps<Y extends Dict = {}>(\n props: Y,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n { className }: Omit<UseComponentPropsOptions, \"transferProps\"> = {},\n ) {\n className = useClassName(slot, className)\n\n const style = useStyleContext()\n\n return {\n ...props,\n className: cx(className, props.className),\n css: mergeSlotCSS(slot, style, props.css),\n }\n }\n\n function component<H extends AsWithFragment = \"div\", R extends Dict = Dict>(\n el: FC<R> | H,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n { name, className, ...options }: ComponentOptions = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperProps<R>[]\n ) {\n return withDisplayName<H, R>((props) => {\n className = useClassName(slot, className)\n\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = chainProps(...superProps)()(computedProps)\n\n return (\n <ProxyComponent\n {...mergedProps}\n className={cx(className, mergedProps.className)}\n />\n )\n }, displayName)\n }\n }\n\n function withProvider<\n H extends AsWithFragment = \"div\",\n R extends Y = Y,\n T extends keyof R = keyof R,\n >(\n el: FC<WithoutThemeProps<R, M, T>> | H,\n slot: ComponentSlot<ComponentSlotName<M>> = \"root\",\n {\n name,\n className,\n withContext,\n transferProps,\n ...options\n }: ComponentWithContextOptions<T> = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperWithoutThemeProps<R, M, T>[]\n ) {\n return withDisplayName<H, R>((props) => {\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const [context, mergedProps] = useRootComponentProps(\n computedProps,\n slot,\n {\n className,\n withContext,\n transferProps,\n },\n )\n const rest = chainProps<any>(...superProps)()(mergedProps)\n\n return (\n <StyleContext value={context}>\n <ProxyComponent {...rest} />\n </StyleContext>\n )\n }, displayName)\n }\n }\n\n function withContext<\n H extends AsWithFragment = \"div\",\n R extends Dict = H extends DOMElement ? HTMLStyledProps<H> : Dict,\n >(\n el: FC<R> | H,\n slot?: ComponentSlot<ComponentSlotName<M>>,\n {\n name,\n className,\n withContext,\n ...options\n }: Omit<ComponentWithContextOptions, \"transferProps\"> = {},\n ) {\n const ProxyComponent = createProxyComponent(el, options)\n const slotKey = getSlotKey(slot)\n const slotName = getSlotName(slot)\n const displayName = getDisplayName(name, `${rootDisplayName}${slotName}`)\n\n classNameMap.set(slotKey, { className, slot })\n\n return function (\n initialProps?: InitialProps<R>,\n ...superProps: SuperProps<R>[]\n ) {\n return withDisplayName<H, R>((props) => {\n const computedProps = isFunction(initialProps)\n ? initialProps(props)\n : mergeProps(initialProps ?? {}, props)()\n const mergedProps = useSlotComponentProps(computedProps, slot, {\n className,\n withContext,\n })\n const rest = chainProps(...superProps)()(mergedProps)\n\n return <ProxyComponent {...rest} />\n }, displayName)\n }\n }\n\n return {\n component,\n ComponentContext,\n PropsContext,\n StyleContext,\n useClassNames,\n useComponentContext,\n usePropsContext,\n useStyleContext,\n withContext,\n withProvider,\n useRootComponentProps,\n useSlotComponentProps,\n }\n}\n"],"mappings":";;;;;;;;;;;AA8FA,SAAS,qBAGP,IAAe,EAAE,kBAAkB,GAAG,YAA8B,CAAC,GAAG;CACxE,QAAQ,uBAAA,GAAsBA,cAAAA,WAAAA,CAAW,EAAE;CAC3C,qBAAqB,EAAA,GAACA,cAAAA,WAAAA,CAAW,EAAE;CAEnC,IAAI,OAAO,YAAY,KAAK;CAE5B,IAAI,qBAAA,GAAoBC,cAAAA,SAAAA,CAAS,EAAE,GAAG;EACpC,MAAM,iBAAiB,OAAO,IAAU,OAAO;EAE/C,eAAe,cAAc;EAE7B,OAAO;CACT,OAAO;EACL,GAAG,gBAAgB;EAEnB,OAAO;CACT;AACF;AAEA,SAAS,gBAGP,WAAkB,aAAqB;CACvC,OAAO,eAAe,WAAW,QAAQ,EAAE,OAAO,YAAY,CAAC;CAC/D,OAAO,eAAe,WAAW,eAAe,EAAE,OAAO,YAAY,CAAC;CAEtE,OAAO;AACT;AAEA,SAAS,WAA6B,MAAyB;CAC7D,IAAI,CAAC,MAAM,OAAO;CAElB,KAAA,GAAIC,cAAAA,QAAAA,CAAQ,IAAI,KAAK,EAAA,GAACC,cAAAA,SAAAA,CAAS,IAAI,GACjC,QAAA,GAAOC,cAAAA,YAAAA,EAAAA,GAAYC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../core/system/index.type.js";
|
|
|
2
2
|
import { CSSModifierObject, CSSPropObject, CSSSlotObject } from "../../core/css/index.type.js";
|
|
3
3
|
import "../../index.js";
|
|
4
4
|
//#region src/components/chart/polar-chart.style.d.ts
|
|
5
|
-
export declare const polarChartStyle: ComponentSlotStyle<"label" | "grid" | "dot" | "root" | "labelList" | "activeDot" | "
|
|
5
|
+
export declare const polarChartStyle: ComponentSlotStyle<"label" | "grid" | "dot" | "root" | "labelList" | "activeDot" | "angleAxis" | "angleAxisLabel" | "angleAxisLine" | "angleAxisTick" | "angleAxisTickLine" | "labelLine" | "pie" | "radar" | "radial" | "radialBackground" | "radiusAxis" | "radiusAxisLabel" | "radiusAxisLine" | "radiusAxisTick" | "radiusAxisTickLine" | "sector", CSSPropObject<CSSSlotObject<"label" | "grid" | "dot" | "root" | "labelList" | "activeDot" | "angleAxis" | "angleAxisLabel" | "angleAxisLine" | "angleAxisTick" | "angleAxisTickLine" | "labelLine" | "pie" | "radar" | "radial" | "radialBackground" | "radiusAxis" | "radiusAxisLabel" | "radiusAxisLine" | "radiusAxisTick" | "radiusAxisTickLine" | "sector">>, CSSModifierObject<CSSSlotObject<"label" | "grid" | "dot" | "root" | "labelList" | "activeDot" | "angleAxis" | "angleAxisLabel" | "angleAxisLine" | "angleAxisTick" | "angleAxisTickLine" | "labelLine" | "pie" | "radar" | "radial" | "radialBackground" | "radiusAxis" | "radiusAxisLabel" | "radiusAxisLine" | "radiusAxisTick" | "radiusAxisTickLine" | "sector">>, CSSModifierObject<CSSSlotObject<"label" | "grid" | "dot" | "root" | "labelList" | "activeDot" | "angleAxis" | "angleAxisLabel" | "angleAxisLine" | "angleAxisTick" | "angleAxisTickLine" | "labelLine" | "pie" | "radar" | "radial" | "radialBackground" | "radiusAxis" | "radiusAxisLabel" | "radiusAxisLine" | "radiusAxisTick" | "radiusAxisTickLine" | "sector">>>;
|
|
6
6
|
export type PolarChartStyle = typeof polarChartStyle;
|
|
7
7
|
//#endregion
|
|
8
8
|
//# sourceMappingURL=polar-chart.style.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yamada-ui/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.3.0-dev-
|
|
4
|
+
"version": "2.3.0-dev-20261027074222",
|
|
5
5
|
"description": "React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"yamada",
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
"@emotion/utils": "^1.4.2",
|
|
127
127
|
"@floating-ui/react-dom": "^2.1.9",
|
|
128
128
|
"@tanstack/react-table": "^8.21.3",
|
|
129
|
-
"@yamada-ui/utils": "2.2.0-dev-
|
|
129
|
+
"@yamada-ui/utils": "2.2.0-dev-20261027074222",
|
|
130
130
|
"copy-to-clipboard": "3.3.3",
|
|
131
131
|
"csstype": "^3.2.3",
|
|
132
132
|
"dayjs": "^1.11.23",
|