@yamada-ui/react 2.3.0-dev-20261024140900 → 2.3.0-dev-20261024165228
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/components/accordion/accordion.cjs +4 -3
- package/dist/cjs/components/accordion/accordion.cjs.map +1 -1
- package/dist/cjs/components/aspect-ratio/aspect-ratio.cjs +2 -2
- package/dist/cjs/components/aspect-ratio/aspect-ratio.cjs.map +1 -1
- package/dist/cjs/components/button/button.cjs +11 -8
- package/dist/cjs/components/button/button.cjs.map +1 -1
- package/dist/cjs/components/field/field.cjs +4 -3
- package/dist/cjs/components/field/field.cjs.map +1 -1
- package/dist/cjs/components/list/list.cjs +5 -3
- package/dist/cjs/components/list/list.cjs.map +1 -1
- package/dist/cjs/components/native-accordion/native-accordion.cjs +4 -3
- package/dist/cjs/components/native-accordion/native-accordion.cjs.map +1 -1
- package/dist/cjs/components/sidebar/sidebar.cjs +4 -3
- package/dist/cjs/components/sidebar/sidebar.cjs.map +1 -1
- package/dist/cjs/components/slot/slot.cjs +10 -9
- package/dist/cjs/components/slot/slot.cjs.map +1 -1
- package/dist/cjs/components/tree/tree.cjs +5 -3
- package/dist/cjs/components/tree/tree.cjs.map +1 -1
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/utils/children.cjs +22 -9
- package/dist/cjs/utils/children.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +4 -0
- package/dist/esm/components/accordion/accordion.js +5 -4
- package/dist/esm/components/accordion/accordion.js.map +1 -1
- package/dist/esm/components/aspect-ratio/aspect-ratio.js +2 -2
- package/dist/esm/components/aspect-ratio/aspect-ratio.js.map +1 -1
- package/dist/esm/components/button/button.js +11 -8
- package/dist/esm/components/button/button.js.map +1 -1
- package/dist/esm/components/field/field.js +5 -4
- package/dist/esm/components/field/field.js.map +1 -1
- package/dist/esm/components/list/list.js +5 -3
- package/dist/esm/components/list/list.js.map +1 -1
- package/dist/esm/components/native-accordion/native-accordion.js +5 -4
- package/dist/esm/components/native-accordion/native-accordion.js.map +1 -1
- package/dist/esm/components/sidebar/sidebar.js +5 -4
- package/dist/esm/components/sidebar/sidebar.js.map +1 -1
- package/dist/esm/components/slot/slot.js +11 -10
- package/dist/esm/components/slot/slot.js.map +1 -1
- package/dist/esm/components/tree/tree.js +5 -3
- package/dist/esm/components/tree/tree.js.map +1 -1
- package/dist/esm/index.js +4 -2
- package/dist/esm/utils/children.js +22 -11
- package/dist/esm/utils/children.js.map +1 -1
- package/dist/esm/utils/index.js +4 -2
- package/dist/types/components/accordion/accordion.style.d.ts +1 -1
- package/dist/types/components/alert/alert.style.d.ts +1 -1
- package/dist/types/components/autocomplete/autocomplete.style.d.ts +1 -1
- package/dist/types/components/breadcrumb/breadcrumb.style.d.ts +1 -1
- package/dist/types/components/calendar/calendar.style.d.ts +2 -2
- package/dist/types/components/carousel/carousel.style.d.ts +2 -2
- package/dist/types/components/chart/cartesian-chart.style.d.ts +1 -1
- package/dist/types/components/chart/polar-chart.style.d.ts +1 -1
- package/dist/types/components/date-picker/date-picker.style.d.ts +1 -1
- package/dist/types/components/dropzone/dropzone.d.ts +1 -1
- package/dist/types/components/dropzone/dropzone.style.d.ts +1 -1
- package/dist/types/components/field/use-field-props.d.ts +1 -1
- package/dist/types/components/file-button/use-file-button.d.ts +2 -2
- package/dist/types/components/file-input/use-file-input.d.ts +2 -2
- package/dist/types/components/menu/menu.style.d.ts +2 -2
- package/dist/types/components/native-accordion/native-accordion.style.d.ts +2 -2
- package/dist/types/components/progress/use-progress.d.ts +6 -6
- package/dist/types/components/rating/rating.style.d.ts +2 -2
- package/dist/types/components/segmented-control/segmented-control.style.d.ts +2 -2
- package/dist/types/components/select/select.style.d.ts +1 -1
- package/dist/types/components/stat/stat.style.d.ts +2 -2
- package/dist/types/components/steps/steps.style.d.ts +1 -1
- package/dist/types/components/tabs/tabs.style.d.ts +1 -1
- package/dist/types/components/timeline/timeline.d.ts +1 -1
- package/dist/types/components/timeline/timeline.style.d.ts +1 -1
- package/dist/types/components/tree/tree.style.d.ts +1 -1
- package/dist/types/components/tree/use-tree.d.ts +4 -4
- package/dist/types/hooks/use-clickable/index.d.ts +2 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/providers/i18n-provider/i18n-provider.d.ts +1 -1
- package/dist/types/utils/children.d.ts +11 -2
- package/dist/types/utils/index.d.ts +3 -3
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"children.cjs","names":["React","isString","isNumber","isUndefined","isArray","isEmpty"],"sources":["../../../src/utils/children.tsx"],"sourcesContent":["import {\n isArray,\n isEmpty,\n isNumber,\n isString,\n isUndefined,\n} from \"@yamada-ui/utils\"\nimport * as React from \"react\"\n\nexport function getValidChildren(\n children: React.ReactNode,\n): React.ReactElement<any>[] {\n return React.Children.toArray(children).filter((child) =>\n React.isValidElement(child),\n )\n}\n\nexport function useValidChildren(children: React.ReactNode) {\n return React.useMemo(() => getValidChildren(children), [children])\n}\n\nexport function isValidElement(child: any): child is React.ReactNode {\n return React.isValidElement(child) || isString(child) || isNumber(child)\n}\n\nexport function isSomeDisplayName(a: any, b: any): boolean {\n if (isUndefined(a) || isUndefined(b)) return false\n\n if (isArray(a)) {\n if (a.includes(b)) return true\n if (!!b.displayName && a.includes(b.displayName)) return true\n if (!!b.name && a.includes(b.name)) return true\n } else {\n if (a === b) return true\n if (!!a.displayName && !!b.displayName && a.displayName === b.displayName)\n return true\n if (!!a.name && !!b.name && a.name === b.name) return true\n if (!!a.displayName && !!b.name && a.displayName === b.name) return true\n if (!!a.name && !!b.displayName && a.name === b.displayName) return true\n }\n\n return false\n}\n\nexport function isSomeElement(a: any, b: any): boolean {\n if (isUndefined(a) || isUndefined(b)) return false\n if (a === b) return true\n if (isSomeDisplayName(a, b)) return true\n\n a = a._payload?.value\n\n if (isUndefined(a)) return false\n if (isSomeDisplayName(a, b)) return true\n\n return false\n}\n\nexport function findChild<Y = any>(\n children: React.ReactElement[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): React.ReactElement<Y> | undefined {\n const child = children.find((child) =>\n types.some((type) => isSomeElement(child.type, type)),\n )\n\n return child as React.ReactElement<Y> | undefined\n}\n\nexport function useFindChild<Y = any>(\n children: React.ReactElement[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): React.ReactElement<Y> | undefined {\n const typesRef = React.useRef(types)\n\n return React.useMemo(\n () => findChild<Y>(children, ...typesRef.current),\n [children],\n )\n}\n\nexport function findChildren<Y = any, M = any>(\n children: React.ReactElement[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): [React.ReactElement<Y> | undefined, ...React.ReactElement<M>[]] {\n const child = findChild(children, ...types)\n\n if (child)\n return children.sort((a, b) => {\n if (types.some((type) => isSomeElement(a.type, type))) return -1\n else if (types.some((type) => isSomeElement(b.type, type))) return 1\n else return 0\n }) as [React.ReactElement<Y> | undefined, ...React.ReactElement<M>[]]\n else return [undefined, ...(children as React.ReactElement<M>[])]\n}\n\nexport function useFindChildren<Y = any, M = any>(\n children: React.ReactElement<M>[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): [React.ReactElement<Y> | undefined, ...React.ReactElement<M>[]] {\n const typesRef = React.useRef(types)\n\n return React.useMemo(\n () => findChildren<Y, M>(children, ...typesRef.current),\n [children],\n )\n}\n\nexport function includesChildren(\n children: React.ReactElement<any>[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): boolean {\n return children.some((child) => {\n if (types.some((type) => isSomeElement(child.type, type))) return true\n\n const children = getValidChildren(child.props.children)\n\n return children.length ? includesChildren(children, ...types) : false\n })\n}\n\nexport function useIncludesChildren(\n children: React.ReactElement<any>[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): boolean {\n return React.useMemo(\n () => includesChildren(children, ...types),\n [children, types],\n )\n}\n\nexport function omitChildren<Y = any>(\n children: React.ReactElement[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): React.ReactElement<Y>[] {\n return children.filter((child) =>\n types.every((type) => !isSomeElement(child.type, type)),\n ) as React.ReactElement<Y>[]\n}\n\nexport function useOmitChildren<Y = any>(\n children: React.ReactElement<any>[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): React.ReactElement<Y>[] {\n const typesRef = React.useRef(types)\n\n return React.useMemo(\n () => omitChildren<Y>(children, ...typesRef.current),\n [children],\n )\n}\n\nexport function pickChildren<Y = any>(\n children: React.ReactElement[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): React.ReactElement<Y>[] {\n return children.filter((child) =>\n types.some((type) => isSomeElement(child.type, type)),\n ) as React.ReactElement<Y>[]\n}\n\nexport function usePickChildren<Y = any>(\n children: React.ReactElement<any>[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): React.ReactElement<Y>[] {\n const typesRef = React.useRef(types)\n\n return React.useMemo(\n () => pickChildren<Y>(children, ...typesRef.current),\n [children],\n )\n}\n\nexport function splitChildren<Y = any, M = any>(\n children: React.ReactNode,\n ...types: (\n | (React.JSXElementConstructor<any> | string)[]\n | React.JSXElementConstructor<any>\n | string\n )[]\n): [\n React.ReactElement<M>[] | React.ReactNode,\n ...(React.ReactElement<Y>[] | undefined)[],\n] {\n const validChildren = getValidChildren(children)\n\n if (isEmpty(validChildren)) return [children]\n\n const pickedChildren = types.map((types) => {\n if (isArray(types)) {\n const pickedChildren = pickChildren(validChildren, ...types)\n\n return !isEmpty(pickedChildren) ? pickedChildren : undefined\n } else {\n const pickedChildren = pickChildren(validChildren, types)\n\n return !isEmpty(pickedChildren) ? pickedChildren : undefined\n }\n })\n\n const omittedChildren = omitChildren(validChildren, ...types.flat())\n\n return [omittedChildren, ...pickedChildren] as const\n}\n\nexport function useSplitChildren<Y = any, M = any>(\n children: React.ReactNode,\n ...types: (\n | (React.JSXElementConstructor<any> | string)[]\n | React.JSXElementConstructor<any>\n | string\n )[]\n): [\n React.ReactElement<M>[] | React.ReactNode,\n ...(React.ReactElement<Y>[] | undefined)[],\n] {\n const typesRef = React.useRef(types)\n\n return React.useMemo(\n () => splitChildren<Y, M>(children, ...typesRef.current),\n [children],\n )\n}\n\nexport const wrapOrPassProps = <Y extends React.PropsWithChildren>(\n Component: React.FC<Y>,\n nodeOrProps: React.ReactNode | Y,\n additionalProps?: Y,\n) => {\n if (isUndefined(nodeOrProps)) {\n return null\n } else if (isValidElement(nodeOrProps)) {\n additionalProps ??= {} as Y\n additionalProps.children = nodeOrProps\n\n return <Component {...additionalProps} />\n } else {\n return <Component {...additionalProps} {...nodeOrProps} />\n }\n}\n"],"mappings":";;;;;;AASA,SAAgB,iBACd,UAC2B;CAC3B,OAAOA,MAAM,SAAS,QAAQ,QAAQ,CAAC,CAAC,QAAQ,UAC9CA,MAAM,eAAe,KAAK,CAC5B;AACF;AAEA,SAAgB,iBAAiB,UAA2B;CAC1D,OAAOA,MAAM,cAAc,iBAAiB,QAAQ,GAAG,CAAC,QAAQ,CAAC;AACnE;AAEA,SAAgB,eAAe,OAAsC;CACnE,OAAOA,MAAM,eAAe,KAAK,MAAA,GAAKC,iBAAAA,SAAAA,CAAS,KAAK,MAAA,GAAKC,iBAAAA,SAAAA,CAAS,KAAK;AACzE;AAEA,SAAgB,kBAAkB,GAAQ,GAAiB;CACzD,KAAA,GAAIC,iBAAAA,YAAAA,CAAY,CAAC,MAAA,GAAKA,iBAAAA,YAAAA,CAAY,CAAC,GAAG,OAAO;CAE7C,KAAA,GAAIC,iBAAAA,QAAAA,CAAQ,CAAC,GAAG;EACd,IAAI,EAAE,SAAS,CAAC,GAAG,OAAO;EAC1B,IAAI,CAAC,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,GAAG,OAAO;EACzD,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO;CAC7C,OAAO;EACL,IAAI,MAAM,GAAG,OAAO;EACpB,IAAI,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE,eAAe,EAAE,gBAAgB,EAAE,aAC5D,OAAO;EACT,IAAI,CAA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AAAA,CAAQ,aAAa,GAAG,OAAO,CAAC,QAAQ;CAE5C,MAAM,iBAAiB,MAAM,KAAK,UAAU;EAC1C,KAAA,GAAID,iBAAAA,QAAAA,CAAQ,KAAK,GAAG;GAClB,MAAM,iBAAiB,aAAa,eAAe,GAAG,KAAK;GAE3D,OAAO,EAAA,GAACC,iBAAAA,QAAAA,CAAQ,cAAc,IAAI,iBAAiB,KAAA;EACrD,OAAO;GACL,MAAM,iBAAiB,aAAa,eAAe,KAAK;GAExD,OAAO,EAAA,GAACA,iBAAAA,QAAAA,CAAQ,cAAc,IAAI,iBAAiB,KAAA;EACrD;CACF,CAAC;CAID,OAAO,CAFiB,aAAa,eAAe,GAAG,MAAM,KAAK,CAE5C,GAAG,GAAG,cAAc;AAC5C;AAEA,SAAgB,iBACd,UACA,GAAG,OAQH;CACA,MAAM,WAAWL,MAAM,OAAO,KAAK;CAEnC,OAAOA,MAAM,cACL,cAAoB,UAAU,GAAG,SAAS,OAAO,GACvD,CAAC,QAAQ,CACX;AACF;AAEA,MAAa,mBACX,WACA,aACA,oBACG;CACH,KAAA,GAAIG,iBAAAA,YAAAA,CAAY,WAAW,GACzB,OAAO;MACF,IAAI,eAAe,WAAW,GAAG;EACtC,oBAAoB,CAAC;EACrB,gBAAgB,WAAW;EAE3B,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,WAAD,EAAW,GAAI,gBAAkB,CAAA;CAC1C,OACE,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,WAAD;EAAW,GAAI;EAAiB,GAAI;CAAc,CAAA;AAE7D"}
|
|
1
|
+
{"version":3,"file":"children.cjs","names":["isObject","React","isString","isNumber","isUndefined","isArray","isEmpty"],"sources":["../../../src/utils/children.tsx"],"sourcesContent":["import {\n isArray,\n isEmpty,\n isNumber,\n isObject,\n isString,\n isUndefined,\n} from \"@yamada-ui/utils\"\nimport * as React from \"react\"\n\nexport function isLazy(value: unknown): value is {\n $$typeof: symbol\n _payload: unknown\n _init: (payload: unknown) => unknown\n} {\n return (\n isObject(value) &&\n \"$$typeof\" in value &&\n value.$$typeof === Symbol.for(\"react.lazy\")\n )\n}\n\nexport function isValidElement(child: any): child is React.ReactNode {\n return React.isValidElement(child) || isString(child) || isNumber(child)\n}\n\nexport function isSomeDisplayName(a: any, b: any): boolean {\n if (isUndefined(a) || isUndefined(b)) return false\n\n if (isArray(a)) {\n if (a.includes(b)) return true\n if (!!b.displayName && a.includes(b.displayName)) return true\n if (!!b.name && a.includes(b.name)) return true\n } else {\n if (a === b) return true\n if (!!a.displayName && !!b.displayName && a.displayName === b.displayName)\n return true\n if (!!a.name && !!b.name && a.name === b.name) return true\n if (!!a.displayName && !!b.name && a.displayName === b.name) return true\n if (!!a.name && !!b.displayName && a.name === b.displayName) return true\n }\n\n return false\n}\n\nexport function isSomeElement(a: any, b: any): boolean {\n if (isUndefined(a) || isUndefined(b)) return false\n if (a === b) return true\n if (isSomeDisplayName(a, b)) return true\n\n a = a._payload?.value\n\n if (isUndefined(a)) return false\n if (isSomeDisplayName(a, b)) return true\n\n return false\n}\n\nexport function getResolvedChild(value: React.ReactNode): React.ReactNode\nexport function getResolvedChild<Y>(\n value: Y,\n): Y extends { $$typeof: symbol } ? unknown : Y\nexport function getResolvedChild(value: unknown): unknown {\n while (isLazy(value)) {\n const { _init, _payload } = value\n\n value = _init(_payload)\n }\n\n return value\n}\n\nexport function getValidChildren(\n children: React.ReactNode,\n): React.ReactElement<any>[] {\n return React.Children.toArray(children).filter((child) =>\n React.isValidElement(child),\n )\n}\n\nexport function useValidChildren(children: React.ReactNode) {\n return React.useMemo(() => getValidChildren(children), [children])\n}\n\nexport function findChild<Y = any>(\n children: React.ReactElement[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): React.ReactElement<Y> | undefined {\n const child = children.find((child) =>\n types.some((type) => isSomeElement(child.type, type)),\n )\n\n return child as React.ReactElement<Y> | undefined\n}\n\nexport function useFindChild<Y = any>(\n children: React.ReactElement[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): React.ReactElement<Y> | undefined {\n const typesRef = React.useRef(types)\n\n return React.useMemo(\n () => findChild<Y>(children, ...typesRef.current),\n [children],\n )\n}\n\nexport function findChildren<Y = any, M = any>(\n children: React.ReactElement[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): [React.ReactElement<Y> | undefined, ...React.ReactElement<M>[]] {\n const child = findChild(children, ...types)\n\n if (child)\n return children.sort((a, b) => {\n if (types.some((type) => isSomeElement(a.type, type))) return -1\n else if (types.some((type) => isSomeElement(b.type, type))) return 1\n else return 0\n }) as [React.ReactElement<Y> | undefined, ...React.ReactElement<M>[]]\n else return [undefined, ...(children as React.ReactElement<M>[])]\n}\n\nexport function useFindChildren<Y = any, M = any>(\n children: React.ReactElement<M>[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): [React.ReactElement<Y> | undefined, ...React.ReactElement<M>[]] {\n const typesRef = React.useRef(types)\n\n return React.useMemo(\n () => findChildren<Y, M>(children, ...typesRef.current),\n [children],\n )\n}\n\nexport function includesChildren(\n children: React.ReactElement<any>[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): boolean {\n return children.some((child) => {\n if (types.some((type) => isSomeElement(child.type, type))) return true\n\n const children = getValidChildren(child.props.children)\n\n return children.length ? includesChildren(children, ...types) : false\n })\n}\n\nexport function useIncludesChildren(\n children: React.ReactElement<any>[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): boolean {\n return React.useMemo(\n () => includesChildren(children, ...types),\n [children, types],\n )\n}\n\nexport function omitChildren<Y = any>(\n children: React.ReactElement[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): React.ReactElement<Y>[] {\n return children.filter((child) =>\n types.every((type) => !isSomeElement(child.type, type)),\n ) as React.ReactElement<Y>[]\n}\n\nexport function useOmitChildren<Y = any>(\n children: React.ReactElement<any>[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): React.ReactElement<Y>[] {\n const typesRef = React.useRef(types)\n\n return React.useMemo(\n () => omitChildren<Y>(children, ...typesRef.current),\n [children],\n )\n}\n\nexport function pickChildren<Y = any>(\n children: React.ReactElement[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): React.ReactElement<Y>[] {\n return children.filter((child) =>\n types.some((type) => isSomeElement(child.type, type)),\n ) as React.ReactElement<Y>[]\n}\n\nexport function usePickChildren<Y = any>(\n children: React.ReactElement<any>[],\n ...types: (React.JSXElementConstructor<any> | string)[]\n): React.ReactElement<Y>[] {\n const typesRef = React.useRef(types)\n\n return React.useMemo(\n () => pickChildren<Y>(children, ...typesRef.current),\n [children],\n )\n}\n\nexport function splitChildren<Y = any, M = any>(\n children: React.ReactNode,\n ...types: (\n | (React.JSXElementConstructor<any> | string)[]\n | React.JSXElementConstructor<any>\n | string\n )[]\n): [\n React.ReactElement<M>[] | React.ReactNode,\n ...(React.ReactElement<Y>[] | undefined)[],\n] {\n const validChildren = getValidChildren(children)\n\n if (isEmpty(validChildren)) return [children]\n\n const pickedChildren = types.map((types) => {\n if (isArray(types)) {\n const pickedChildren = pickChildren(validChildren, ...types)\n\n return !isEmpty(pickedChildren) ? pickedChildren : undefined\n } else {\n const pickedChildren = pickChildren(validChildren, types)\n\n return !isEmpty(pickedChildren) ? pickedChildren : undefined\n }\n })\n\n const omittedChildren = omitChildren(validChildren, ...types.flat())\n\n return [omittedChildren, ...pickedChildren] as const\n}\n\nexport function useSplitChildren<Y = any, M = any>(\n children: React.ReactNode,\n ...types: (\n | (React.JSXElementConstructor<any> | string)[]\n | React.JSXElementConstructor<any>\n | string\n )[]\n): [\n React.ReactElement<M>[] | React.ReactNode,\n ...(React.ReactElement<Y>[] | undefined)[],\n] {\n const typesRef = React.useRef(types)\n\n return React.useMemo(\n () => splitChildren<Y, M>(children, ...typesRef.current),\n [children],\n )\n}\n\nexport const wrapOrPassProps = <Y extends React.PropsWithChildren>(\n Component: React.FC<Y>,\n nodeOrProps: React.ReactNode | Y,\n additionalProps?: Y,\n) => {\n const resolved = getResolvedChild(nodeOrProps)\n\n if (isUndefined(resolved)) {\n return null\n } else if (isValidElement(resolved)) {\n additionalProps ??= {} as Y\n additionalProps.children = resolved\n\n return <Component {...additionalProps} />\n } else {\n return <Component {...additionalProps} {...(resolved as Y)} />\n }\n}\n"],"mappings":";;;;;;AAUA,SAAgB,OAAO,OAIrB;CACA,QAAA,GACEA,iBAAAA,SAAAA,CAAS,KAAK,KACd,cAAc,SACd,MAAM,aAAa,OAAO,IAAI,YAAY;AAE9C;AAEA,SAAgB,eAAe,OAAsC;CACnE,OAAOC,MAAM,eAAe,KAAK,MAAA,GAAKC,iBAAAA,SAAAA,CAAS,KAAK,MAAA,GAAKC,iBAAAA,SAAAA,CAAS,KAAK;AACzE;AAEA,SAAgB,kBAAkB,GAAQ,GAAiB;CACzD,KAAA,GAAIC,iBAAAA,YAAAA,CAAY,CAAC,MAAA,GAAKA,iBAAAA,YAAAA,CAAY,CAAC,GAAG,OAAO;CAE7C,KAAA,GAAIC,iBAAAA,QAAAA,CAAQ,CAAC,GAAG;EACd,IAAI,EAAE,SAAS,CAAC,GAAG,OAAO;EAC1B,IAAI,CAAC,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,GAAG,OAAO;EACzD,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO;CAC7C,OAAO;EACL,IAAI,MAAM,GAAG,OAAO;EACpB,IAAI,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE,eAAe,EAAE,gBAAgB,EAAE,aAC5D,OAAO;EACT,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO;EACtD,IAAI,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,OAAO;EACpE,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,aAAa,OAAO;CACtE;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AEA,SAAgB,cACd,UACA,GAAG,OAQH;CACA,MAAM,gBAAgB,iBAAiB,QAAQ;CAE/C,KAAA,GAAIK,iBAAAA,QAAAA,CAAQ,aAAa,GAAG,OAAO,CAAC,QAAQ;CAE5C,MAAM,iBAAiB,MAAM,KAAK,UAAU;EAC1C,KAAA,GAAID,iBAAAA,QAAAA,CAAQ,KAAK,GAAG;GAClB,MAAM,iBAAiB,aAAa,eAAe,GAAG,KAAK;GAE3D,OAAO,EAAA,GAACC,iBAAAA,QAAAA,CAAQ,cAAc,IAAI,iBAAiB,KAAA;EACrD,OAAO;GACL,MAAM,iBAAiB,aAAa,eAAe,KAAK;GAExD,OAAO,EAAA,GAACA,iBAAAA,QAAAA,CAAQ,cAAc,IAAI,iBAAiB,KAAA;EACrD;CACF,CAAC;CAID,OAAO,CAFiB,aAAa,eAAe,GAAG,MAAM,KAAK,CAE5C,GAAG,GAAG,cAAc;AAC5C;AAEA,SAAgB,iBACd,UACA,GAAG,OAQH;CACA,MAAM,WAAWL,MAAM,OAAO,KAAK;CAEnC,OAAOA,MAAM,cACL,cAAoB,UAAU,GAAG,SAAS,OAAO,GACvD,CAAC,QAAQ,CACX;AACF;AAEA,MAAa,mBACX,WACA,aACA,oBACG;CACH,MAAM,WAAW,iBAAiB,WAAW;CAE7C,KAAA,GAAIG,iBAAAA,YAAAA,CAAY,QAAQ,GACtB,OAAO;MACF,IAAI,eAAe,QAAQ,GAAG;EACnC,oBAAoB,CAAC;EACrB,gBAAgB,WAAW;EAE3B,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,WAAD,EAAW,GAAI,gBAAkB,CAAA;CAC1C,OACE,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,WAAD;EAAW,GAAI;EAAiB,GAAK;CAAiB,CAAA;AAEjE"}
|
package/dist/cjs/utils/index.cjs
CHANGED
|
@@ -15,9 +15,11 @@ var utils_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
|
15
15
|
findChild: () => require_children.findChild,
|
|
16
16
|
findChildren: () => require_children.findChildren,
|
|
17
17
|
getEventRelatedTarget: () => require_dom.getEventRelatedTarget,
|
|
18
|
+
getResolvedChild: () => require_children.getResolvedChild,
|
|
18
19
|
getValidChildren: () => require_children.getValidChildren,
|
|
19
20
|
includesChildren: () => require_children.includesChildren,
|
|
20
21
|
isComposing: () => require_dom.isComposing,
|
|
22
|
+
isLazy: () => require_children.isLazy,
|
|
21
23
|
isRefObject: () => require_ref.isRefObject,
|
|
22
24
|
isSomeDisplayName: () => require_children.isSomeDisplayName,
|
|
23
25
|
isSomeElement: () => require_children.isSomeElement,
|
|
@@ -53,9 +55,11 @@ exports.createStore = require_store.createStore;
|
|
|
53
55
|
exports.findChild = require_children.findChild;
|
|
54
56
|
exports.findChildren = require_children.findChildren;
|
|
55
57
|
exports.getEventRelatedTarget = require_dom.getEventRelatedTarget;
|
|
58
|
+
exports.getResolvedChild = require_children.getResolvedChild;
|
|
56
59
|
exports.getValidChildren = require_children.getValidChildren;
|
|
57
60
|
exports.includesChildren = require_children.includesChildren;
|
|
58
61
|
exports.isComposing = require_dom.isComposing;
|
|
62
|
+
exports.isLazy = require_children.isLazy;
|
|
59
63
|
exports.isRefObject = require_ref.isRefObject;
|
|
60
64
|
exports.isSomeDisplayName = require_children.isSomeDisplayName;
|
|
61
65
|
exports.isSomeElement = require_children.isSomeElement;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useSplitChildren } from "../../utils/children.js";
|
|
2
|
+
import { getResolvedChild, useSplitChildren } from "../../utils/children.js";
|
|
3
3
|
import { createContext as createContext$1 } from "../../utils/context.js";
|
|
4
4
|
import { utils_exports } from "../../utils/index.js";
|
|
5
5
|
import { styled } from "../../core/system/factory.js";
|
|
@@ -121,11 +121,12 @@ const AccordionIcon = withContext(({ children = /* @__PURE__ */ jsx(ChevronDownI
|
|
|
121
121
|
const { iconHidden } = useComponentContext();
|
|
122
122
|
const { getIconProps } = useAccordionItemContext();
|
|
123
123
|
if (iconHidden) return null;
|
|
124
|
-
|
|
124
|
+
const child = getResolvedChild(children);
|
|
125
|
+
if (isValidElement(child)) return cloneElement(child, getIconProps({
|
|
125
126
|
...rest,
|
|
126
|
-
...
|
|
127
|
+
...child.props
|
|
127
128
|
}));
|
|
128
|
-
return Children.count(
|
|
129
|
+
return Children.count(child) > 1 ? Children.only(null) : null;
|
|
129
130
|
}, "icon")();
|
|
130
131
|
const AccordionPanel = withContext(({ animationOpacity, children, delay, duration, endingHeight, startingHeight, transition, transitionEnd, unmountOnExit, ...rest }) => {
|
|
131
132
|
const { open, getPanelProps } = useAccordionItemContext();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accordion.js","names":["createContext","runIfFn","isString"],"sources":["../../../../src/components/accordion/accordion.tsx"],"sourcesContent":["\"use client\"\n\nimport type { HTMLProps, HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { ReactNodeOrFunction } from \"../../utils\"\nimport type { CollapseProps } from \"../collapse\"\nimport type { WithTransitionProps } from \"../motion\"\nimport type { AccordionStyle } from \"./accordion.style\"\nimport type { UseAccordionItemProps, UseAccordionProps } from \"./use-accordion\"\nimport { Children, cloneElement, isValidElement, useMemo } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { createContext, isString, runIfFn, useSplitChildren } from \"../../utils\"\nimport { Collapse } from \"../collapse\"\nimport { ChevronDownIcon } from \"../icon\"\nimport { accordionStyle } from \"./accordion.style\"\nimport {\n AccordionContext,\n AccordionDescendantsContext,\n AccordionItemContext,\n useAccordion,\n useAccordionItem,\n useAccordionItemContext,\n} from \"./use-accordion\"\n\ninterface AccordionCallBackProps {\n disabled?: boolean\n expanded?: boolean\n}\n\nexport interface AccordionItem extends Omit<AccordionItemProps, \"index\"> {}\n\ninterface ComponentContext extends Pick<\n AccordionRootProps,\n \"icon\" | \"iconHidden\"\n> {}\n\nexport interface AccordionRootProps\n extends\n Omit<HTMLStyledProps, \"onChange\">,\n ThemeProps<AccordionStyle>,\n UseAccordionProps {\n /**\n * The accordion icon for all items to use.\n */\n icon?: ReactNodeOrFunction<AccordionCallBackProps>\n /**\n * If `true`, hide the accordion icon for all items.\n *\n * @default false\n */\n iconHidden?: boolean\n /**\n * If provided, generate elements based on items.\n */\n items?: AccordionItem[]\n}\n\ninterface ItemComponentContext extends Pick<AccordionItemProps, \"icon\"> {}\n\nconst [ItemComponentContext, useItemComponentContext] =\n createContext<ItemComponentContext>({\n name: \"ItemComponentContext\",\n })\n\nconst {\n ComponentContext,\n PropsContext: AccordionPropsContext,\n useComponentContext,\n usePropsContext: useAccordionPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<AccordionRootProps, AccordionStyle, ComponentContext>(\n \"accordion\",\n accordionStyle,\n)\n\nexport { AccordionPropsContext, useAccordionPropsContext }\n\n/**\n * `Accordion` is a component for a list that displays information in an expandable or collapsible manner.\n *\n * @see https://yamada-ui.com/docs/components/accordion\n */\nexport const AccordionRoot = withProvider<\"div\", AccordionRootProps>(\n ({ children, icon, iconHidden, items, ...props }) => {\n const {\n descendants,\n focusedIndex,\n index,\n multiple,\n setFocusedIndex,\n setIndex,\n toggle,\n getRootProps,\n } = useAccordion(props)\n const computedChildren = useMemo(() => {\n if (children) return children\n\n return items?.map((props, index) => (\n <AccordionItem key={index} index={index} {...props} />\n ))\n }, [children, items])\n const context = useMemo(\n () => ({\n focusedIndex,\n index,\n multiple,\n setFocusedIndex,\n setIndex,\n toggle,\n }),\n [focusedIndex, index, multiple, setFocusedIndex, setIndex, toggle],\n )\n const componentContext = useMemo(\n () => ({ icon, iconHidden }),\n [icon, iconHidden],\n )\n\n return (\n <AccordionDescendantsContext value={descendants}>\n <AccordionContext value={context}>\n <ComponentContext value={componentContext}>\n <styled.div {...getRootProps()}>{computedChildren}</styled.div>\n </ComponentContext>\n </AccordionContext>\n </AccordionDescendantsContext>\n )\n },\n \"root\",\n)()\n\nexport interface AccordionItemProps\n extends\n Omit<HTMLStyledProps, \"children\">,\n Omit<UseAccordionItemProps, \"children\"> {\n /**\n * The accordion button to use.\n */\n button?: ReactNodeOrFunction<AccordionCallBackProps>\n /**\n * The accordion children to use.\n */\n children?: ReactNodeOrFunction<AccordionCallBackProps>\n /**\n * The accordion icon to use.\n */\n icon?: ReactNodeOrFunction<AccordionCallBackProps>\n}\n\nexport const AccordionItem = withContext<\"div\", AccordionItemProps>(\n ({ button, children, icon, ...rest }) => {\n const {\n disabled,\n open,\n getButtonProps,\n getIconProps,\n getItemProps,\n getPanelProps,\n } = useAccordionItem(rest)\n const computedChildren = useMemo(\n () => runIfFn(children, { disabled, expanded: open }),\n [children, disabled, open],\n )\n const [omittedChildren, customAccordionButton, customAccordionPanel] =\n useSplitChildren(computedChildren, AccordionButton, AccordionPanel)\n const context = useMemo(\n () => ({\n disabled,\n icon,\n open,\n getButtonProps,\n getIconProps,\n getPanelProps,\n }),\n [disabled, getButtonProps, getPanelProps, getIconProps, icon, open],\n )\n const componentContext = useMemo(() => ({ icon }), [icon])\n\n return (\n <AccordionItemContext value={context}>\n <ItemComponentContext value={componentContext}>\n <styled.div {...getItemProps()}>\n {customAccordionButton ?? (\n <AccordionButton>\n {runIfFn(button, { disabled, expanded: open })}\n </AccordionButton>\n )}\n {customAccordionPanel ?? (\n <AccordionPanel>{omittedChildren}</AccordionPanel>\n )}\n </styled.div>\n </ItemComponentContext>\n </AccordionItemContext>\n )\n },\n \"item\",\n)()\n\nexport interface AccordionButtonProps extends HTMLStyledProps<\"button\"> {\n /**\n * The accordion icon to use.\n */\n icon?: ReactNodeOrFunction<AccordionCallBackProps>\n /**\n * Props the container element.\n */\n containerProps?: HTMLStyledProps\n}\n\nexport const AccordionButton = withContext<\"button\", AccordionButtonProps>(\n ({ children, icon: customIcon, containerProps, ...rest }) => {\n const { icon: rootIcon } = useComponentContext()\n const { icon: itemIcon } = useItemComponentContext()\n const { disabled, open, getButtonProps } = useAccordionItemContext()\n const props = { disabled, expanded: open }\n\n return (\n <styled.h3 {...containerProps}>\n <styled.button {...getButtonProps(rest)}>\n {children}\n\n <AccordionIcon>\n {runIfFn(customIcon, props) ??\n runIfFn(itemIcon, props) ??\n runIfFn(rootIcon, props)}\n </AccordionIcon>\n </styled.button>\n </styled.h3>\n )\n },\n \"button\",\n)()\n\ninterface AccordionIconProps extends HTMLStyledProps<\"svg\"> {}\n\nexport const AccordionIcon = withContext<\"svg\", AccordionIconProps>(\n ({ children = <ChevronDownIcon />, ...rest }) => {\n const { iconHidden } = useComponentContext()\n const { getIconProps } = useAccordionItemContext()\n\n if (iconHidden) return null\n\n if (isValidElement<HTMLProps<\"svg\">>(children))\n return cloneElement(\n children,\n getIconProps({\n ...rest,\n ...children.props,\n }),\n )\n\n return Children.count(children) > 1 ? Children.only(null) : null\n },\n \"icon\",\n)()\n\nexport interface AccordionPanelProps\n extends\n Omit<HTMLStyledProps, \"transition\">,\n Pick<\n CollapseProps,\n | \"animationOpacity\"\n | \"endingHeight\"\n | \"startingHeight\"\n | keyof WithTransitionProps\n > {}\n\nexport const AccordionPanel = withContext<\"div\", AccordionPanelProps>(\n ({\n animationOpacity,\n children,\n delay,\n duration,\n endingHeight,\n startingHeight,\n transition,\n transitionEnd,\n unmountOnExit,\n ...rest\n }) => {\n const { open, getPanelProps } = useAccordionItemContext()\n\n return (\n <Collapse\n {...{\n animationOpacity,\n delay,\n duration,\n endingHeight,\n open,\n startingHeight,\n transition,\n transitionEnd,\n unmountOnExit,\n }}\n >\n <styled.div {...getPanelProps(rest)}>\n {isString(children) ? <styled.p>{children}</styled.p> : children}\n </styled.div>\n </Collapse>\n )\n },\n \"panel\",\n)()\n"],"mappings":";;;;;;;;;;;;;AA0DA,MAAM,CAAC,sBAAsB,2BAC3BA,gBAAoC,EAClC,MAAM,uBACR,CAAC;AAEH,MAAM,EACJ,kBACA,cAAc,uBACd,qBACA,iBAAiB,0BACjB,aACA,iBACE,oBACF,aACA,cACF;;;;;;AASA,MAAa,gBAAgB,cAC1B,EAAE,UAAU,MAAM,YA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SAAS,MAAM,QAAQ,IAAI,IAAI,SAAS,KAAK,IAAI,IAAI;AAC9D,GACA,MACF,CAAC,CAAC;AAaF,MAAa,iBAAiB,aAC3B,EACC,kBACA,UACA,OACA,UACA,cACA,gBACA,YACA,eACA,eACA,GAAG,WACC;CACJ,MAAM,EAAE,MAAM,kBAAkB,wBAAwB;CAExD,OACE,oBAAC,UAAD;EAEI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGF,UAAA,oBAAC,OAAO,KAAR;GAAY,GAAI,cAAc,IAAI;GAC/BC,WAAAA,GAAAA,cAAAA,SAAAA,CAAS,QAAQ,IAAI,oBAAC,OAAO,GAAR,EAAW,SAAmB,CAAA,IAAI;EAC9C,CAAA;CACJ,CAAA;AAEd,GACA,OACF,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"accordion.js","names":["createContext","runIfFn","isString"],"sources":["../../../../src/components/accordion/accordion.tsx"],"sourcesContent":["\"use client\"\n\nimport type { HTMLProps, HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { ReactNodeOrFunction } from \"../../utils\"\nimport type { CollapseProps } from \"../collapse\"\nimport type { WithTransitionProps } from \"../motion\"\nimport type { AccordionStyle } from \"./accordion.style\"\nimport type { UseAccordionItemProps, UseAccordionProps } from \"./use-accordion\"\nimport { Children, cloneElement, isValidElement, useMemo } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport {\n createContext,\n getResolvedChild,\n isString,\n runIfFn,\n useSplitChildren,\n} from \"../../utils\"\nimport { Collapse } from \"../collapse\"\nimport { ChevronDownIcon } from \"../icon\"\nimport { accordionStyle } from \"./accordion.style\"\nimport {\n AccordionContext,\n AccordionDescendantsContext,\n AccordionItemContext,\n useAccordion,\n useAccordionItem,\n useAccordionItemContext,\n} from \"./use-accordion\"\n\ninterface AccordionCallBackProps {\n disabled?: boolean\n expanded?: boolean\n}\n\nexport interface AccordionItem extends Omit<AccordionItemProps, \"index\"> {}\n\ninterface ComponentContext extends Pick<\n AccordionRootProps,\n \"icon\" | \"iconHidden\"\n> {}\n\nexport interface AccordionRootProps\n extends\n Omit<HTMLStyledProps, \"onChange\">,\n ThemeProps<AccordionStyle>,\n UseAccordionProps {\n /**\n * The accordion icon for all items to use.\n */\n icon?: ReactNodeOrFunction<AccordionCallBackProps>\n /**\n * If `true`, hide the accordion icon for all items.\n *\n * @default false\n */\n iconHidden?: boolean\n /**\n * If provided, generate elements based on items.\n */\n items?: AccordionItem[]\n}\n\ninterface ItemComponentContext extends Pick<AccordionItemProps, \"icon\"> {}\n\nconst [ItemComponentContext, useItemComponentContext] =\n createContext<ItemComponentContext>({\n name: \"ItemComponentContext\",\n })\n\nconst {\n ComponentContext,\n PropsContext: AccordionPropsContext,\n useComponentContext,\n usePropsContext: useAccordionPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<AccordionRootProps, AccordionStyle, ComponentContext>(\n \"accordion\",\n accordionStyle,\n)\n\nexport { AccordionPropsContext, useAccordionPropsContext }\n\n/**\n * `Accordion` is a component for a list that displays information in an expandable or collapsible manner.\n *\n * @see https://yamada-ui.com/docs/components/accordion\n */\nexport const AccordionRoot = withProvider<\"div\", AccordionRootProps>(\n ({ children, icon, iconHidden, items, ...props }) => {\n const {\n descendants,\n focusedIndex,\n index,\n multiple,\n setFocusedIndex,\n setIndex,\n toggle,\n getRootProps,\n } = useAccordion(props)\n const computedChildren = useMemo(() => {\n if (children) return children\n\n return items?.map((props, index) => (\n <AccordionItem key={index} index={index} {...props} />\n ))\n }, [children, items])\n const context = useMemo(\n () => ({\n focusedIndex,\n index,\n multiple,\n setFocusedIndex,\n setIndex,\n toggle,\n }),\n [focusedIndex, index, multiple, setFocusedIndex, setIndex, toggle],\n )\n const componentContext = useMemo(\n () => ({ icon, iconHidden }),\n [icon, iconHidden],\n )\n\n return (\n <AccordionDescendantsContext value={descendants}>\n <AccordionContext value={context}>\n <ComponentContext value={componentContext}>\n <styled.div {...getRootProps()}>{computedChildren}</styled.div>\n </ComponentContext>\n </AccordionContext>\n </AccordionDescendantsContext>\n )\n },\n \"root\",\n)()\n\nexport interface AccordionItemProps\n extends\n Omit<HTMLStyledProps, \"children\">,\n Omit<UseAccordionItemProps, \"children\"> {\n /**\n * The accordion button to use.\n */\n button?: ReactNodeOrFunction<AccordionCallBackProps>\n /**\n * The accordion children to use.\n */\n children?: ReactNodeOrFunction<AccordionCallBackProps>\n /**\n * The accordion icon to use.\n */\n icon?: ReactNodeOrFunction<AccordionCallBackProps>\n}\n\nexport const AccordionItem = withContext<\"div\", AccordionItemProps>(\n ({ button, children, icon, ...rest }) => {\n const {\n disabled,\n open,\n getButtonProps,\n getIconProps,\n getItemProps,\n getPanelProps,\n } = useAccordionItem(rest)\n const computedChildren = useMemo(\n () => runIfFn(children, { disabled, expanded: open }),\n [children, disabled, open],\n )\n const [omittedChildren, customAccordionButton, customAccordionPanel] =\n useSplitChildren(computedChildren, AccordionButton, AccordionPanel)\n const context = useMemo(\n () => ({\n disabled,\n icon,\n open,\n getButtonProps,\n getIconProps,\n getPanelProps,\n }),\n [disabled, getButtonProps, getPanelProps, getIconProps, icon, open],\n )\n const componentContext = useMemo(() => ({ icon }), [icon])\n\n return (\n <AccordionItemContext value={context}>\n <ItemComponentContext value={componentContext}>\n <styled.div {...getItemProps()}>\n {customAccordionButton ?? (\n <AccordionButton>\n {runIfFn(button, { disabled, expanded: open })}\n </AccordionButton>\n )}\n {customAccordionPanel ?? (\n <AccordionPanel>{omittedChildren}</AccordionPanel>\n )}\n </styled.div>\n </ItemComponentContext>\n </AccordionItemContext>\n )\n },\n \"item\",\n)()\n\nexport interface AccordionButtonProps extends HTMLStyledProps<\"button\"> {\n /**\n * The accordion icon to use.\n */\n icon?: ReactNodeOrFunction<AccordionCallBackProps>\n /**\n * Props the container element.\n */\n containerProps?: HTMLStyledProps\n}\n\nexport const AccordionButton = withContext<\"button\", AccordionButtonProps>(\n ({ children, icon: customIcon, containerProps, ...rest }) => {\n const { icon: rootIcon } = useComponentContext()\n const { icon: itemIcon } = useItemComponentContext()\n const { disabled, open, getButtonProps } = useAccordionItemContext()\n const props = { disabled, expanded: open }\n\n return (\n <styled.h3 {...containerProps}>\n <styled.button {...getButtonProps(rest)}>\n {children}\n\n <AccordionIcon>\n {runIfFn(customIcon, props) ??\n runIfFn(itemIcon, props) ??\n runIfFn(rootIcon, props)}\n </AccordionIcon>\n </styled.button>\n </styled.h3>\n )\n },\n \"button\",\n)()\n\ninterface AccordionIconProps extends HTMLStyledProps<\"svg\"> {}\n\nexport const AccordionIcon = withContext<\"svg\", AccordionIconProps>(\n ({ children = <ChevronDownIcon />, ...rest }) => {\n const { iconHidden } = useComponentContext()\n const { getIconProps } = useAccordionItemContext()\n\n if (iconHidden) return null\n\n const child = getResolvedChild(children)\n\n if (isValidElement<HTMLProps<\"svg\">>(child))\n return cloneElement(child, getIconProps({ ...rest, ...child.props }))\n\n return Children.count(child) > 1 ? Children.only(null) : null\n },\n \"icon\",\n)()\n\nexport interface AccordionPanelProps\n extends\n Omit<HTMLStyledProps, \"transition\">,\n Pick<\n CollapseProps,\n | \"animationOpacity\"\n | \"endingHeight\"\n | \"startingHeight\"\n | keyof WithTransitionProps\n > {}\n\nexport const AccordionPanel = withContext<\"div\", AccordionPanelProps>(\n ({\n animationOpacity,\n children,\n delay,\n duration,\n endingHeight,\n startingHeight,\n transition,\n transitionEnd,\n unmountOnExit,\n ...rest\n }) => {\n const { open, getPanelProps } = useAccordionItemContext()\n\n return (\n <Collapse\n {...{\n animationOpacity,\n delay,\n duration,\n endingHeight,\n open,\n startingHeight,\n transition,\n transitionEnd,\n unmountOnExit,\n }}\n >\n <styled.div {...getPanelProps(rest)}>\n {isString(children) ? <styled.p>{children}</styled.p> : children}\n </styled.div>\n </Collapse>\n )\n },\n \"panel\",\n)()\n"],"mappings":";;;;;;;;;;;;;AAgEA,MAAM,CAAC,sBAAsB,2BAC3BA,gBAAoC,EAClC,MAAM,uBACR,CAAC;AAEH,MAAM,EACJ,kBACA,cAAc,uBAC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AAM,QAAQ,iBAAiB,QAAQ;CAEvC,IAAI,eAAiC,KAAK,GACxC,OAAO,aAAa,OAAO,aAAa;EAAE,GAAG;EAAM,GAAG,MAAM;CAAM,CAAC,CAAC;CAEtE,OAAO,SAAS,MAAM,KAAK,IAAI,IAAI,SAAS,KAAK,IAAI,IAAI;AAC3D,GACA,MACF,CAAC,CAAC;AAaF,MAAa,iBAAiB,aAC3B,EACC,kBACA,UACA,OACA,UACA,cACA,gBACA,YACA,eACA,eACA,GAAG,WACC;CACJ,MAAM,EAAE,MAAM,kBAAkB,wBAAwB;CAExD,OACE,oBAAC,UAAD;EAEI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGF,UAAA,oBAAC,OAAO,KAAR;GAAY,GAAI,cAAc,IAAI;GAC/BC,WAAAA,GAAAA,cAAAA,SAAAA,CAAS,QAAQ,IAAI,oBAAC,OAAO,GAAR,EAAW,SAAmB,CAAA,IAAI;EAC9C,CAAA;CACJ,CAAA;AAEd,GACA,OACF,CAAC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { getResolvedChild } from "../../utils/children.js";
|
|
2
3
|
import { utils_exports } from "../../utils/index.js";
|
|
3
4
|
import { createComponent } from "../../core/components/create-component.js";
|
|
4
5
|
import { aspectRatioStyle } from "./aspect-ratio.style.js";
|
|
@@ -11,10 +12,9 @@ const { PropsContext: AspectRatioPropsContext, usePropsContext: useAspectRatioPr
|
|
|
11
12
|
* @see https://yamada-ui.com/docs/components/aspect-ratio
|
|
12
13
|
*/
|
|
13
14
|
const AspectRatio = withContext("div")(void 0, ({ children, ratio = 4 / 3, ...rest }) => {
|
|
14
|
-
const child = Children.only(children);
|
|
15
15
|
return {
|
|
16
16
|
...rest,
|
|
17
|
-
children:
|
|
17
|
+
children: Children.only(getResolvedChild(children)),
|
|
18
18
|
_before: {
|
|
19
19
|
display: "block",
|
|
20
20
|
h: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aspect-ratio.js","names":["replaceObject"],"sources":["../../../../src/components/aspect-ratio/aspect-ratio.tsx"],"sourcesContent":["\"use client\"\n\nimport type { HTMLStyledProps, StyleValue } from \"../../core\"\nimport type { AspectRatioStyle } from \"./aspect-ratio.style\"\nimport { Children } from \"react\"\nimport { createComponent } from \"../../core\"\nimport { replaceObject } from \"../../utils\"\nimport { aspectRatioStyle } from \"./aspect-ratio.style\"\n\nexport interface AspectRatioProps extends HTMLStyledProps {\n /**\n * The aspect ratio of the Box.\n *\n * @default '4 / 3'\n */\n ratio?: StyleValue<number>\n}\n\nconst {\n PropsContext: AspectRatioPropsContext,\n usePropsContext: useAspectRatioPropsContext,\n withContext,\n} = createComponent<AspectRatioProps, AspectRatioStyle>(\n \"aspect-ratio\",\n aspectRatioStyle,\n)\n\nexport { AspectRatioPropsContext, useAspectRatioPropsContext }\n\n/**\n * `AspectRatio` is a component for embedding things like videos and maps while maintaining the aspect ratio.\n *\n * @see https://yamada-ui.com/docs/components/aspect-ratio\n */\nexport const AspectRatio = withContext(\"div\")(\n undefined,\n ({ children, ratio = 4 / 3, ...rest }) => {\n
|
|
1
|
+
{"version":3,"file":"aspect-ratio.js","names":["replaceObject"],"sources":["../../../../src/components/aspect-ratio/aspect-ratio.tsx"],"sourcesContent":["\"use client\"\n\nimport type { HTMLStyledProps, StyleValue } from \"../../core\"\nimport type { AspectRatioStyle } from \"./aspect-ratio.style\"\nimport { Children } from \"react\"\nimport { createComponent } from \"../../core\"\nimport { getResolvedChild, replaceObject } from \"../../utils\"\nimport { aspectRatioStyle } from \"./aspect-ratio.style\"\n\nexport interface AspectRatioProps extends HTMLStyledProps {\n /**\n * The aspect ratio of the Box.\n *\n * @default '4 / 3'\n */\n ratio?: StyleValue<number>\n}\n\nconst {\n PropsContext: AspectRatioPropsContext,\n usePropsContext: useAspectRatioPropsContext,\n withContext,\n} = createComponent<AspectRatioProps, AspectRatioStyle>(\n \"aspect-ratio\",\n aspectRatioStyle,\n)\n\nexport { AspectRatioPropsContext, useAspectRatioPropsContext }\n\n/**\n * `AspectRatio` is a component for embedding things like videos and maps while maintaining the aspect ratio.\n *\n * @see https://yamada-ui.com/docs/components/aspect-ratio\n */\nexport const AspectRatio = withContext(\"div\")(\n undefined,\n ({ children, ratio = 4 / 3, ...rest }) => {\n return {\n ...rest,\n children: Children.only(getResolvedChild(children)),\n _before: {\n display: \"block\",\n h: 0,\n pb: replaceObject(ratio, (r) => `${(1 / r) * 100}%`),\n },\n }\n },\n)\n"],"mappings":";;;;;;;AAkBA,MAAM,EACJ,cAAc,yBACd,iBAAiB,4BACjB,gBACE,gBACF,gBACA,gBACF;;;;;;AASA,MAAa,cAAc,YAAY,KAAK,CAAC,CAC3C,KAAA,IACC,EAAE,UAAU,QAAQ,IAAI,GAAG,GAAG,WAAW;CACxC,OAAO;EACL,GAAG;EACH,UAAU,SAAS,KAAK,iBAAiB,QAAQ,CAAC;EAClD,SAAS;GACP,SAAS;GACT,GAAG;GACH,KAAA,GAAIA,cAAAA,cAAAA,CAAc,QAAQ,MAAM,GAAI,IAAI,IAAK,IAAI,EAAE;EACrD;CACF;AACF,CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { getResolvedChild } from "../../utils/children.js";
|
|
2
3
|
import { mergeRefs } from "../../utils/ref.js";
|
|
3
4
|
import { utils_exports } from "../../utils/index.js";
|
|
4
5
|
import { styled } from "../../core/system/factory.js";
|
|
@@ -92,18 +93,19 @@ const ButtonContent = component(({ children }) => {
|
|
|
92
93
|
const ButtonLoading = component((props) => {
|
|
93
94
|
const { loadingIcon, loadingMessage } = useComponentContext();
|
|
94
95
|
const css = useMemo(() => ({ position: loadingMessage ? "relative" : "absolute" }), [loadingMessage]);
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
const child = getResolvedChild(loadingIcon);
|
|
97
|
+
if (isLoadingScheme(child)) {
|
|
98
|
+
const Component = getLoadingComponent(child);
|
|
97
99
|
return /* @__PURE__ */ jsx(Component, {
|
|
98
100
|
color: "currentColor",
|
|
99
101
|
...props,
|
|
100
102
|
css: mergeCSS(css, props.css)
|
|
101
103
|
});
|
|
102
104
|
}
|
|
103
|
-
if (isValidElement(
|
|
105
|
+
if (isValidElement(child)) return cloneElement(child, {
|
|
104
106
|
...props,
|
|
105
|
-
...
|
|
106
|
-
css: mergeCSS(css, props.css,
|
|
107
|
+
...child.props,
|
|
108
|
+
css: mergeCSS(css, props.css, child.props.css)
|
|
107
109
|
});
|
|
108
110
|
return null;
|
|
109
111
|
}, {
|
|
@@ -119,13 +121,14 @@ const ButtonEndLoading = component(ButtonLoading, {
|
|
|
119
121
|
className: getClassName((0, utils_exports.bem)("button", "loading", "end"))
|
|
120
122
|
})();
|
|
121
123
|
const ButtonIcon = component(({ children, ...rest }) => {
|
|
122
|
-
|
|
124
|
+
const child = getResolvedChild(children);
|
|
125
|
+
if (isValidElement(child)) return cloneElement(child, {
|
|
123
126
|
"aria-hidden": true,
|
|
124
127
|
role: "img",
|
|
125
128
|
...rest,
|
|
126
|
-
...
|
|
129
|
+
...child.props
|
|
127
130
|
});
|
|
128
|
-
return Children.count(
|
|
131
|
+
return Children.count(child) > 1 ? Children.only(null) : null;
|
|
129
132
|
}, {
|
|
130
133
|
name: "ButtonIcon",
|
|
131
134
|
className: getClassName((0, utils_exports.bem)("button", "icon"))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.js","names":["dataAttr","bem"],"sources":["../../../../src/components/button/button.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ElementType, PropsWithChildren, ReactNode } from \"react\"\nimport type {\n CSSObject,\n HTMLProps,\n HTMLStyledProps,\n ThemeProps,\n} from \"../../core\"\nimport type { Loading } from \"../loading\"\nimport type { ButtonStyle } from \"./button.style\"\nimport {\n Children,\n cloneElement,\n isValidElement,\n useCallback,\n useMemo,\n useRef,\n} from \"react\"\nimport { createComponent, getClassName, mergeCSS, styled } from \"../../core\"\nimport { bem, dataAttr, mergeRefs } from \"../../utils\"\nimport { getLoadingComponent, isLoadingScheme } from \"../loading\"\nimport { Ripple, useRipple } from \"../ripple\"\nimport { buttonStyle } from \"./button.style\"\n\ninterface ComponentContext extends Pick<\n ButtonProps,\n \"endIcon\" | \"iconProps\" | \"loadingIcon\" | \"loadingMessage\" | \"startIcon\"\n> {}\n\nconst useButtonType = (value?: ElementType) => {\n const buttonRef = useRef(!value)\n\n const ref = useCallback((node: HTMLElement | null) => {\n if (node) buttonRef.current = node.tagName === \"BUTTON\"\n }, [])\n\n const type = buttonRef.current ? \"button\" : undefined\n\n return { ref, type } as const\n}\n\nexport interface ButtonProps\n extends HTMLStyledProps<\"button\">, ThemeProps<ButtonStyle> {\n /**\n * If `true`, the button is represented as active.\n *\n * @default false\n */\n active?: boolean\n /**\n * If `true`, the button is disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * If `true`, disable ripple effects when pressing a element.\n *\n * @default false\n */\n disableRipple?: boolean\n /**\n * The icon to display at the end side of the button.\n */\n endIcon?: ReactNode\n /**\n * If `true`, the loading state of the button is represented.\n *\n * @default false\n */\n loading?: boolean\n /**\n * The icon to display when the button is loading.\n *\n * @default 'oval'\n */\n loadingIcon?: Loading.Scheme | ReactNode\n /**\n * The message to display when the button is loading.\n */\n loadingMessage?: ReactNode\n /**\n * The placement of the loading indicator. Accepts `start` or `end`.\n *\n * @default 'start'\n */\n loadingPlacement?: \"end\" | \"start\"\n /**\n * The icon to display at the start side of the button.\n */\n startIcon?: ReactNode\n /**\n * The type of button. Accepts `button`, `reset`, or `submit`.\n *\n * @default 'button'\n */\n type?: HTMLProps<\"button\">[\"type\"]\n /**\n * The props of the icon element.\n */\n iconProps?: ButtonIconProps\n /**\n * The props of the loading icon element.\n */\n loadingProps?: ButtonLoadingProps\n}\n\nconst {\n component,\n ComponentContext,\n PropsContext: ButtonPropsContext,\n useComponentContext,\n usePropsContext: useButtonPropsContext,\n withContext,\n} = createComponent<ButtonProps, ButtonStyle, ComponentContext>(\n \"button\",\n buttonStyle,\n)\n\nexport { ButtonPropsContext, useButtonPropsContext }\n\n/**\n * `Button` is an interactive component that allows users to perform actions such as submitting forms and toggling modals.\n *\n * @see https://yamada-ui.com/docs/components/button\n */\nexport const Button = withContext<\"button\", ButtonProps>(\n ({\n ref,\n as,\n active,\n children,\n disabled,\n disableRipple,\n endIcon = null,\n loading,\n loadingIcon = \"oval\",\n loadingMessage,\n loadingPlacement = \"start\",\n startIcon = null,\n iconProps,\n loadingProps,\n ...rest\n }) => {\n const trulyDisabled = disabled || loading\n const { ref: buttonRef, type } = useButtonType(as)\n const { onClick, ...rippleProps } = useRipple({\n ...rest,\n disabled: disableRipple || trulyDisabled,\n })\n const startLoading = loading && loadingPlacement === \"start\"\n const endLoading = loading && loadingPlacement === \"end\"\n\n const context = useMemo(\n () => ({ endIcon, loadingIcon, loadingMessage, startIcon, iconProps }),\n [loadingIcon, loadingMessage, startIcon, endIcon, iconProps],\n )\n\n return (\n <ComponentContext value={context}>\n <styled.button\n ref={mergeRefs(ref, buttonRef)}\n as={as}\n type={type}\n data-active={dataAttr(active)}\n data-loading={dataAttr(loading)}\n disabled={trulyDisabled}\n {...rest}\n onClick={onClick}\n >\n {startLoading ? <ButtonStartLoading {...loadingProps} /> : null}\n\n {loading ? (\n loadingMessage || (\n <styled.span opacity={0}>\n <ButtonContent>{children}</ButtonContent>\n </styled.span>\n )\n ) : (\n <ButtonContent>{children}</ButtonContent>\n )}\n\n {endLoading ? <ButtonEndLoading {...loadingProps} /> : null}\n\n <Ripple {...rippleProps} />\n </styled.button>\n </ComponentContext>\n )\n },\n)()\n\nconst ButtonContent = component<\"fragment\", PropsWithChildren>(\n ({ children }) => {\n const { endIcon, startIcon, iconProps } = useComponentContext()\n\n return (\n <>\n {startIcon ? (\n <ButtonStartIcon {...iconProps}>{startIcon}</ButtonStartIcon>\n ) : null}\n {children}\n {endIcon ? (\n <ButtonEndIcon {...iconProps}>{endIcon}</ButtonEndIcon>\n ) : null}\n </>\n )\n },\n { name: \"ButtonContent\", className: getClassName(bem(\"button\", \"content\")) },\n)()\n\ninterface ButtonLoadingProps extends HTMLStyledProps<\"svg\"> {}\n\nconst ButtonLoading = component<\"svg\", ButtonLoadingProps>(\n (props) => {\n const { loadingIcon, loadingMessage } = useComponentContext()\n\n const css = useMemo<CSSObject>(\n () => ({\n position: loadingMessage ? \"relative\" : \"absolute\",\n }),\n [loadingMessage],\n )\n\n if (isLoadingScheme(loadingIcon)) {\n const Component = getLoadingComponent(loadingIcon)\n\n return (\n <Component\n color=\"currentColor\"\n {...props}\n css={mergeCSS(css, props.css)}\n />\n )\n }\n\n if (isValidElement<HTMLStyledProps<\"svg\">>(loadingIcon))\n return cloneElement(loadingIcon, {\n ...props,\n ...loadingIcon.props,\n css: mergeCSS(css, props.css, loadingIcon.props.css),\n })\n\n return null\n },\n { name: \"ButtonLoading\", className: getClassName(bem(\"button\", \"loading\")) },\n)()\n\nconst ButtonStartLoading = component<\"svg\", ButtonLoadingProps>(ButtonLoading, {\n name: \"ButtonStartLoading\",\n className: getClassName(bem(\"button\", \"loading\", \"start\")),\n})()\n\nconst ButtonEndLoading = component<\"svg\", ButtonLoadingProps>(ButtonLoading, {\n name: \"ButtonEndLoading\",\n className: getClassName(bem(\"button\", \"loading\", \"end\")),\n})()\n\ninterface ButtonIconProps extends HTMLStyledProps<\"svg\"> {}\n\nconst ButtonIcon = component<\"svg\", ButtonIconProps>(\n ({ children, ...rest }) => {\n if (isValidElement<HTMLProps<\"svg\">>(children))\n return cloneElement(children, {\n \"aria-hidden\": true,\n role: \"img\",\n ...rest,\n ...children.props,\n })\n\n return Children.count(children) > 1 ? Children.only(null) : null\n },\n { name: \"ButtonIcon\", className: getClassName(bem(\"button\", \"icon\")) },\n)()\n\nconst ButtonStartIcon = component<\"svg\", ButtonIconProps>(ButtonIcon, {\n name: \"ButtonStartIcon\",\n className: getClassName(bem(\"button\", \"icon\", \"start\")),\n})()\n\nconst ButtonEndIcon = component<\"svg\", ButtonIconProps>(ButtonIcon, {\n name: \"ButtonEndIcon\",\n className: getClassName(bem(\"button\", \"icon\", \"end\")),\n})()\n"],"mappings":";;;;;;;;;;;;;;AA8BA,MAAM,iBAAiB,UAAwB;CAC7C,MAAM,YAAY,OAAO,CAAC,KAAK;CAQ/B,OAAO;EAAE,KANG,aAAa,SAA6B;GACpD,IAAI,MAAM,UAAU,UAAU,KAAK,YAAY;EACjD,GAAG,CAAC,CAIO;EAAG,MAFD,UAAU,UAAU,WAAW,KAAA;CAEzB;AACrB;AAoEA,MAAM,EACJ,WACA,kBACA,cAAc,oBACd,qBACA,iBAAiB,uBACjB,gBACE,gBACF,UACA,WACF;;;;;;AASA,MAAa,SAAS,aACnB,EACC,KACA,IACA,QACA,UACA,UACA,eACA,UAAU,MACV,SACA,cAAc,QACd,gBACA,mBAAmB,SACnB,YAAY,MACZ,WACA,cACA,GAAG,WACC;CACJ,MAAM,gBAAgB,YAAY;CAClC,MAAM,EAAE,KAAK,WAAW,SAAS,cAAc,EAAE;CACjD,MAAM,EAAE,SAAS,GAAG,gBAAgB,UAAU;EAC5C,GAAG;EACH,UAAU,iBAAiB;CAC7B,CAAC;CACD,MAAM,eAAe,WAAW,qBAAqB;CACrD,MAAM,aAAa,WAAW,qBAAqB;CAEnD,MAAM,UAAU,eACP;EAAE;EAAS;EAAa;EAAgB;EAAW;CAAU,IACpE;EAAC;EAAa;EAAgB;EAAW;EAAS;CAAS,CAC7D;CAEA,OACE,oBAAC,kBAAD;EAAkB,OAAO;EACvB,UAAA,qBAAC,OAAO,QAAR;GACE,KAAK,UAAU,KAAK,SAAS;GACzB;GACE;GACN,gBAAA,GAAaA,cAAAA,SAAAA,CAAS,MAAM;GAC5B,iBAAA,GAAcA,cAAAA,SAAAA,CAAS,OAAO;GAC9B,UAAU;GACV,GAAI;GACK;GARX,UAAA;IAUG,eAAe,oBAAC,oBAAD,EAAoB,GAAI,aAAe,CAAA,IAAI;IAE1D,UACC,kBACE,oBAAC,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7E,CAAC,CAAC;AAEF,MAAM,qBAAqB,UAAqC,eAAe;CAC7E,MAAM;CACN,WAAW,cAAA,GAAaA,cAAAA,IAAAA,CAAI,UAAU,WAAW,OAAO,CAAC;AAC3D,CAAC,CAAC,CAAC;AAEH,MAAM,mBAAmB,UAAqC,eAAe;CAC3E,MAAM;CACN,WAAW,cAAA,GAAaA,cAAAA,IAAAA,CAAI,UAAU,WAAW,KAAK,CAAC;AACzD,CAAC,CAAC,CAAC;AAIH,MAAM,aAAa,WAChB,EAAE,UAAU,GAAG,WAAW;CACzB,IAAI,eAAiC,QAAQ,GAC3C,OAAO,aAAa,UAAU;EAC5B,eAAe;EACf,MAAM;EACN,GAAG;EACH,GAAG,SAAS;CACd,CAAC;CAEH,OAAO,SAAS,MAAM,QAAQ,IAAI,IAAI,SAAS,KAAK,IAAI,IAAI;AAC9D,GACA;CAAE,MAAM;CAAc,WAAW,cAAA,GAAaA,cAAAA,IAAAA,CAAI,UAAU,MAAM,CAAC;AAAE,CACvE,CAAC,CAAC;AAEF,MAAM,kBAAkB,UAAkC,YAAY;CACpE,MAAM;CACN,WAAW,cAAA,GAAaA,cAAAA,IAAAA,CAAI,UAAU,QAAQ,OAAO,CAAC;AACxD,CAAC,CAAC,CAAC;AAEH,MAAM,gBAAgB,UAAkC,YAAY;CAClE,MAAM;CACN,WAAW,cAAA,GAAaA,cAAAA,IAAAA,CAAI,UAAU,QAAQ,KAAK,CAAC;AACtD,CAAC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"button.js","names":["dataAttr","bem"],"sources":["../../../../src/components/button/button.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ElementType, PropsWithChildren, ReactNode } from \"react\"\nimport type {\n CSSObject,\n HTMLProps,\n HTMLStyledProps,\n ThemeProps,\n} from \"../../core\"\nimport type { Loading } from \"../loading\"\nimport type { ButtonStyle } from \"./button.style\"\nimport {\n Children,\n cloneElement,\n isValidElement,\n useCallback,\n useMemo,\n useRef,\n} from \"react\"\nimport { createComponent, getClassName, mergeCSS, styled } from \"../../core\"\nimport { bem, dataAttr, getResolvedChild, mergeRefs } from \"../../utils\"\nimport { getLoadingComponent, isLoadingScheme } from \"../loading\"\nimport { Ripple, useRipple } from \"../ripple\"\nimport { buttonStyle } from \"./button.style\"\n\ninterface ComponentContext extends Pick<\n ButtonProps,\n \"endIcon\" | \"iconProps\" | \"loadingIcon\" | \"loadingMessage\" | \"startIcon\"\n> {}\n\nconst useButtonType = (value?: ElementType) => {\n const buttonRef = useRef(!value)\n\n const ref = useCallback((node: HTMLElement | null) => {\n if (node) buttonRef.current = node.tagName === \"BUTTON\"\n }, [])\n\n const type = buttonRef.current ? \"button\" : undefined\n\n return { ref, type } as const\n}\n\nexport interface ButtonProps\n extends HTMLStyledProps<\"button\">, ThemeProps<ButtonStyle> {\n /**\n * If `true`, the button is represented as active.\n *\n * @default false\n */\n active?: boolean\n /**\n * If `true`, the button is disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * If `true`, disable ripple effects when pressing a element.\n *\n * @default false\n */\n disableRipple?: boolean\n /**\n * The icon to display at the end side of the button.\n */\n endIcon?: ReactNode\n /**\n * If `true`, the loading state of the button is represented.\n *\n * @default false\n */\n loading?: boolean\n /**\n * The icon to display when the button is loading.\n *\n * @default 'oval'\n */\n loadingIcon?: Loading.Scheme | ReactNode\n /**\n * The message to display when the button is loading.\n */\n loadingMessage?: ReactNode\n /**\n * The placement of the loading indicator. Accepts `start` or `end`.\n *\n * @default 'start'\n */\n loadingPlacement?: \"end\" | \"start\"\n /**\n * The icon to display at the start side of the button.\n */\n startIcon?: ReactNode\n /**\n * The type of button. Accepts `button`, `reset`, or `submit`.\n *\n * @default 'button'\n */\n type?: HTMLProps<\"button\">[\"type\"]\n /**\n * The props of the icon element.\n */\n iconProps?: ButtonIconProps\n /**\n * The props of the loading icon element.\n */\n loadingProps?: ButtonLoadingProps\n}\n\nconst {\n component,\n ComponentContext,\n PropsContext: ButtonPropsContext,\n useComponentContext,\n usePropsContext: useButtonPropsContext,\n withContext,\n} = createComponent<ButtonProps, ButtonStyle, ComponentContext>(\n \"button\",\n buttonStyle,\n)\n\nexport { ButtonPropsContext, useButtonPropsContext }\n\n/**\n * `Button` is an interactive component that allows users to perform actions such as submitting forms and toggling modals.\n *\n * @see https://yamada-ui.com/docs/components/button\n */\nexport const Button = withContext<\"button\", ButtonProps>(\n ({\n ref,\n as,\n active,\n children,\n disabled,\n disableRipple,\n endIcon = null,\n loading,\n loadingIcon = \"oval\",\n loadingMessage,\n loadingPlacement = \"start\",\n startIcon = null,\n iconProps,\n loadingProps,\n ...rest\n }) => {\n const trulyDisabled = disabled || loading\n const { ref: buttonRef, type } = useButtonType(as)\n const { onClick, ...rippleProps } = useRipple({\n ...rest,\n disabled: disableRipple || trulyDisabled,\n })\n const startLoading = loading && loadingPlacement === \"start\"\n const endLoading = loading && loadingPlacement === \"end\"\n\n const context = useMemo(\n () => ({ endIcon, loadingIcon, loadingMessage, startIcon, iconProps }),\n [loadingIcon, loadingMessage, startIcon, endIcon, iconProps],\n )\n\n return (\n <ComponentContext value={context}>\n <styled.button\n ref={mergeRefs(ref, buttonRef)}\n as={as}\n type={type}\n data-active={dataAttr(active)}\n data-loading={dataAttr(loading)}\n disabled={trulyDisabled}\n {...rest}\n onClick={onClick}\n >\n {startLoading ? <ButtonStartLoading {...loadingProps} /> : null}\n\n {loading ? (\n loadingMessage || (\n <styled.span opacity={0}>\n <ButtonContent>{children}</ButtonContent>\n </styled.span>\n )\n ) : (\n <ButtonContent>{children}</ButtonContent>\n )}\n\n {endLoading ? <ButtonEndLoading {...loadingProps} /> : null}\n\n <Ripple {...rippleProps} />\n </styled.button>\n </ComponentContext>\n )\n },\n)()\n\nconst ButtonContent = component<\"fragment\", PropsWithChildren>(\n ({ children }) => {\n const { endIcon, startIcon, iconProps } = useComponentContext()\n\n return (\n <>\n {startIcon ? (\n <ButtonStartIcon {...iconProps}>{startIcon}</ButtonStartIcon>\n ) : null}\n {children}\n {endIcon ? (\n <ButtonEndIcon {...iconProps}>{endIcon}</ButtonEndIcon>\n ) : null}\n </>\n )\n },\n { name: \"ButtonContent\", className: getClassName(bem(\"button\", \"content\")) },\n)()\n\ninterface ButtonLoadingProps extends HTMLStyledProps<\"svg\"> {}\n\nconst ButtonLoading = component<\"svg\", ButtonLoadingProps>(\n (props) => {\n const { loadingIcon, loadingMessage } = useComponentContext()\n const css = useMemo<CSSObject>(\n () => ({\n position: loadingMessage ? \"relative\" : \"absolute\",\n }),\n [loadingMessage],\n )\n const child = getResolvedChild(loadingIcon)\n\n if (isLoadingScheme(child)) {\n const Component = getLoadingComponent(child)\n\n return (\n <Component\n color=\"currentColor\"\n {...props}\n css={mergeCSS(css, props.css)}\n />\n )\n }\n\n if (isValidElement<HTMLStyledProps<\"svg\">>(child))\n return cloneElement(child, {\n ...props,\n ...child.props,\n css: mergeCSS(css, props.css, child.props.css),\n })\n\n return null\n },\n { name: \"ButtonLoading\", className: getClassName(bem(\"button\", \"loading\")) },\n)()\n\nconst ButtonStartLoading = component<\"svg\", ButtonLoadingProps>(ButtonLoading, {\n name: \"ButtonStartLoading\",\n className: getClassName(bem(\"button\", \"loading\", \"start\")),\n})()\n\nconst ButtonEndLoading = component<\"svg\", ButtonLoadingProps>(ButtonLoading, {\n name: \"ButtonEndLoading\",\n className: getClassName(bem(\"button\", \"loading\", \"end\")),\n})()\n\ninterface ButtonIconProps extends HTMLStyledProps<\"svg\"> {}\n\nconst ButtonIcon = component<\"svg\", ButtonIconProps>(\n ({ children, ...rest }) => {\n const child = getResolvedChild(children)\n\n if (isValidElement<HTMLProps<\"svg\">>(child))\n return cloneElement(child, {\n \"aria-hidden\": true,\n role: \"img\",\n ...rest,\n ...child.props,\n })\n\n return Children.count(child) > 1 ? Children.only(null) : null\n },\n { name: \"ButtonIcon\", className: getClassName(bem(\"button\", \"icon\")) },\n)()\n\nconst ButtonStartIcon = component<\"svg\", ButtonIconProps>(ButtonIcon, {\n name: \"ButtonStartIcon\",\n className: getClassName(bem(\"button\", \"icon\", \"start\")),\n})()\n\nconst ButtonEndIcon = component<\"svg\", ButtonIconProps>(ButtonIcon, {\n name: \"ButtonEndIcon\",\n className: getClassName(bem(\"button\", \"icon\", \"end\")),\n})()\n"],"mappings":";;;;;;;;;;;;;;;AA8BA,MAAM,iBAAiB,UAAwB;CAC7C,MAAM,YAAY,OAAO,CAAC,KAAK;CAQ/B,OAAO;EAAE,KANG,aAAa,SAA6B;GACpD,IAAI,MAAM,UAAU,UAAU,KAAK,YAAY;EACjD,GAAG,CAAC,CAIO;EAAG,MAFD,UAAU,UAAU,WAAW,KAAA;CAEzB;AACrB;AAoEA,MAAM,EACJ,WACA,kBACA,cAAc,oBACd,qBACA,iBAAiB,uBACjB,gBACE,gBACF,UACA,WACF;;;;;;AASA,MAAa,SAAS,aACnB,EACC,KACA,IACA,QACA,UACA,UACA,eACA,UAAU,MACV,SACA,cAAc,QACd,gBACA,mBAAmB,SACnB,YAAY,MACZ,WACA,cACA,GAAG,WACC;CACJ,MAAM,gBAAgB,YAAY;CAClC,MAAM,EAAE,KAAK,WAAW,SAAS,cAAc,EAAE;CACjD,MAAM,EAAE,SAAS,GAAG,gBAAgB,UAAU;EAC5C,GAAG;EACH,UAAU,iBAAiB;CAC7B,CAAC;CACD,MAAM,eAAe,WAAW,qBAAqB;CACrD,MAAM,aAAa,WAAW,qBAAqB;CAEnD,MAAM,UAAU,eACP;EAAE;EAAS;EAAa;EAAgB;EAAW;CAAU,IACpE;EAAC;EAAa;EAAgB;EAAW;EAAS;CAAS,CAC7D;CAEA,OACE,oBAAC,kBAAD;EAAkB,OAAO;EACvB,UAAA,qBAAC,OAAO,QAAR;GACE,KAAK,UAAU,KAAK,SAAS;GACzB;GACE;GACN,gBAAA,GAAaA,cAAAA,SAAAA,CAAS,MAAM;GAC5B,iBAAA,GAAcA,cAAAA,SAAAA,CAAS,OAAO;GAC9B,UAAU;GACV,GAAI;GACK;GARX,UAAA;IAUG,eAAe,oBAAC,oBA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AACT,GACA;CAAE,MAAM;CAAiB,WAAW,cAAA,GAAaA,cAAAA,IAAAA,CAAI,UAAU,SAAS,CAAC;AAAE,CAC7E,CAAC,CAAC;AAEF,MAAM,qBAAqB,UAAqC,eAAe;CAC7E,MAAM;CACN,WAAW,cAAA,GAAaA,cAAAA,IAAAA,CAAI,UAAU,WAAW,OAAO,CAAC;AAC3D,CAAC,CAAC,CAAC;AAEH,MAAM,mBAAmB,UAAqC,eAAe;CAC3E,MAAM;CACN,WAAW,cAAA,GAAaA,cAAAA,IAAAA,CAAI,UAAU,WAAW,KAAK,CAAC;AACzD,CAAC,CAAC,CAAC;AAIH,MAAM,aAAa,WAChB,EAAE,UAAU,GAAG,WAAW;CACzB,MAAM,QAAQ,iBAAiB,QAAQ;CAEvC,IAAI,eAAiC,KAAK,GACxC,OAAO,aAAa,OAAO;EACzB,eAAe;EACf,MAAM;EACN,GAAG;EACH,GAAG,MAAM;CACX,CAAC;CAEH,OAAO,SAAS,MAAM,KAAK,IAAI,IAAI,SAAS,KAAK,IAAI,IAAI;AAC3D,GACA;CAAE,MAAM;CAAc,WAAW,cAAA,GAAaA,cAAAA,IAAAA,CAAI,UAAU,MAAM,CAAC;AAAE,CACvE,CAAC,CAAC;AAEF,MAAM,kBAAkB,UAAkC,YAAY;CACpE,MAAM;CACN,WAAW,cAAA,GAAaA,cAAAA,IAAAA,CAAI,UAAU,QAAQ,OAAO,CAAC;AACxD,CAAC,CAAC,CAAC;AAEH,MAAM,gBAAgB,UAAkC,YAAY;CAClE,MAAM;CACN,WAAW,cAAA,GAAaA,cAAAA,IAAAA,CAAI,UAAU,QAAQ,KAAK,CAAC;AACtD,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useSplitChildren } from "../../utils/children.js";
|
|
2
|
+
import { getResolvedChild, useSplitChildren } from "../../utils/children.js";
|
|
3
3
|
import { createContext as createContext$1 } from "../../utils/context.js";
|
|
4
4
|
import { utils_exports } from "../../utils/index.js";
|
|
5
5
|
import { styled } from "../../core/system/factory.js";
|
|
@@ -116,13 +116,14 @@ const FieldLabel = withContext(({ id, htmlFor, children, optionalIndicator = nul
|
|
|
116
116
|
});
|
|
117
117
|
}, "label")();
|
|
118
118
|
const FieldRequiredIndicator = withContext(({ children, ...rest }) => {
|
|
119
|
-
|
|
119
|
+
const child = getResolvedChild(children);
|
|
120
|
+
if (!isValidElement(child)) return /* @__PURE__ */ jsx(styled.span, {
|
|
120
121
|
"aria-hidden": true,
|
|
121
122
|
role: "presentation",
|
|
122
123
|
...rest,
|
|
123
|
-
children:
|
|
124
|
+
children: child || /* @__PURE__ */ jsx(Fragment$1, { children: "*" })
|
|
124
125
|
});
|
|
125
|
-
else return
|
|
126
|
+
else return child;
|
|
126
127
|
}, "requiredIndicator")();
|
|
127
128
|
const FieldHelperMessage = withContext((props) => {
|
|
128
129
|
const { helperMessageId, invalid, replace } = useFieldContext() ?? {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.js","names":["createContext","isObject","dataAttr"],"sources":["../../../../src/components/field/field.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactNode } from \"react\"\nimport type { HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { FieldStyle } from \"./field.style\"\nimport { isValidElement, useId, useMemo, useState } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport {\n createContext,\n dataAttr,\n isObject,\n useSplitChildren,\n} from \"../../utils\"\nimport { useFieldsetContext } from \"../fieldset\"\nimport { useFormContext } from \"../form\"\nimport { fieldStyle } from \"./field.style\"\n\nexport interface FieldContext\n extends FieldProps, Pick<FieldRootProps, \"replace\"> {\n errorMessageId: string\n focused: boolean\n helperMessageId: string\n id: string\n labelId: string\n onBlur: () => void\n onFocus: () => void\n}\n\nconst [FieldContext, useFieldContext] = createContext<FieldContext>({\n name: \"FieldContext\",\n strict: false,\n})\n\nexport { FieldContext, useFieldContext }\n\nexport interface FieldProps {\n /**\n * If `true`, the field will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * If `true`, the field will be invalid.\n *\n * @default false\n */\n invalid?: boolean\n /**\n * If `true`, the field will be readonly.\n *\n * @default false\n */\n readOnly?: boolean\n /**\n * If `true`, the field will be required.\n *\n * @default false\n */\n required?: boolean\n}\n\nexport interface FieldRootProps\n extends\n HTMLStyledProps,\n ThemeProps<FieldStyle>,\n Pick<FieldLabelProps, \"optionalIndicator\" | \"requiredIndicator\">,\n FieldProps {\n /**\n * The field error message to use.\n */\n errorMessage?: ReactNode\n /**\n * The field helper message to use.\n */\n helperMessage?: ReactNode\n /**\n * The field label to use.\n */\n label?: ReactNode\n /**\n * The name of the field.\n */\n name?: string\n /**\n * If `true`, switch between helper message and error message using invalid.\n *\n * @default true\n */\n replace?: boolean\n /**\n * Props the error message component.\n */\n errorMessageProps?: FieldErrorMessageProps\n /**\n * Props the helper message component.\n */\n helperMessageProps?: FieldHelperMessageProps\n /**\n * Props the label component.\n */\n labelProps?: FieldLabelProps\n}\n\nconst {\n PropsContext: FieldPropsContext,\n usePropsContext: useFieldPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<FieldRootProps, FieldStyle>(\"field\", fieldStyle)\n\nexport { FieldPropsContext, useFieldPropsContext }\n\n/**\n * `Field` is a component used to group form elements with label, helper message, error message, etc.\n *\n * @see https://yamada-ui.com/docs/components/field\n */\nexport const FieldRoot = withProvider<\"div\", FieldRootProps>(\n ({\n id,\n name,\n children,\n disabled,\n errorMessage,\n helperMessage,\n invalid,\n label,\n optionalIndicator,\n readOnly,\n replace,\n required,\n requiredIndicator,\n errorMessageProps,\n helperMessageProps,\n labelProps,\n ...rest\n }) => {\n const uuid = useId()\n const labelId = useId()\n const helperMessageId = useId()\n const errorMessageId = useId()\n const formContext = useFormContext()\n const fieldsetContext = useFieldsetContext()\n const [focused, setFocused] = useState<boolean>(false)\n const [\n omittedChildren,\n customLabel,\n customHelperMessage,\n customErrorMessage,\n ] = useSplitChildren(\n children,\n FieldLabel,\n FieldHelperMessage,\n FieldErrorMessage,\n )\n\n id ??= uuid\n optionalIndicator ??= formContext?.optionalIndicator\n requiredIndicator ??= formContext?.requiredIndicator\n\n disabled ??= fieldsetContext?.disabled\n invalid ??= fieldsetContext?.invalid\n readOnly ??= fieldsetContext?.readOnly\n required ??= fieldsetContext?.required\n\n if (name) {\n disabled ??= isObject(formContext?.disabled)\n ? formContext.disabled[name]\n : formContext?.disabled\n invalid ??= isObject(formContext?.invalid)\n ? formContext.invalid[name]\n : formContext?.invalid\n readOnly ??= isObject(formContext?.readOnly)\n ? formContext.readOnly[name]\n : formContext?.readOnly\n required ??= isObject(formContext?.required)\n ? formContext.required[name]\n : formContext?.required\n replace ??= isObject(formContext?.replace)\n ? (formContext.replace[name] ?? true)\n : (formContext?.replace ?? true)\n errorMessage ??= formContext?.errorMessage?.[name]\n helperMessage ??= formContext?.helperMessage?.[name]\n }\n\n const context = useMemo(\n () => ({\n id,\n disabled,\n errorMessageId,\n focused,\n helperMessageId,\n invalid,\n labelId,\n readOnly,\n replace,\n required,\n onBlur: () => setFocused(false),\n onFocus: () => setFocused(true),\n }),\n [\n id,\n disabled,\n labelId,\n focused,\n invalid,\n helperMessageId,\n errorMessageId,\n readOnly,\n replace,\n required,\n ],\n )\n\n return (\n <FieldContext value={context}>\n <styled.div\n data-disabled={dataAttr(disabled)}\n data-focus={dataAttr(focused)}\n data-invalid={dataAttr(invalid)}\n data-readonly={dataAttr(readOnly)}\n role=\"group\"\n {...rest}\n >\n {customLabel ||\n (label ? (\n <FieldLabel\n optionalIndicator={optionalIndicator}\n requiredIndicator={requiredIndicator}\n {...labelProps}\n >\n {label}\n </FieldLabel>\n ) : null)}\n\n {omittedChildren}\n\n {customHelperMessage ||\n (helperMessage ? (\n <FieldHelperMessage {...helperMessageProps}>\n {helperMessage}\n </FieldHelperMessage>\n ) : null)}\n\n {customErrorMessage ||\n (errorMessage ? (\n <FieldErrorMessage {...errorMessageProps}>\n {errorMessage}\n </FieldErrorMessage>\n ) : null)}\n </styled.div>\n </FieldContext>\n )\n },\n \"root\",\n)()\n\nexport interface FieldLabelProps extends HTMLStyledProps<\"label\"> {\n /**\n * The optional indicator to use.\n */\n optionalIndicator?: ReactNode\n /**\n * If `true`, the field will be required.\n *\n * @default false\n */\n required?: boolean\n /**\n * The required indicator to use.\n */\n requiredIndicator?: ReactNode\n}\n\nexport const FieldLabel = withContext<\"label\", FieldLabelProps>(\n ({\n id,\n htmlFor,\n children,\n optionalIndicator = null,\n required,\n requiredIndicator = null,\n ...rest\n }) => {\n const fieldContext = useFieldContext()\n\n id ??= fieldContext?.labelId\n htmlFor ??= fieldContext?.id\n required ??= fieldContext?.required\n\n return (\n <styled.label\n id={id}\n htmlFor={htmlFor}\n data-disabled={dataAttr(fieldContext?.disabled)}\n data-focus={dataAttr(fieldContext?.focused)}\n data-invalid={dataAttr(fieldContext?.invalid)}\n data-readonly={dataAttr(fieldContext?.readOnly)}\n {...rest}\n >\n {children}\n\n {required ? (\n requiredIndicator ? (\n <FieldRequiredIndicator>{requiredIndicator}</FieldRequiredIndicator>\n ) : (\n <FieldRequiredIndicator />\n )\n ) : (\n optionalIndicator\n )}\n </styled.label>\n )\n },\n \"label\",\n)()\n\ninterface FieldRequiredIndicatorProps extends HTMLStyledProps<\"span\"> {}\n\nconst FieldRequiredIndicator = withContext<\"span\", FieldRequiredIndicatorProps>(\n ({ children, ...rest }) => {\n if (!isValidElement(children))\n return (\n <styled.span aria-hidden role=\"presentation\" {...rest}>\n {children ?? <>*</>}\n </styled.span>\n )\n else return children\n },\n \"requiredIndicator\",\n)()\n\nexport interface FieldHelperMessageProps extends HTMLStyledProps<\"span\"> {}\n\nexport const FieldHelperMessage = withContext<\"span\", FieldHelperMessageProps>(\n (props) => {\n const { helperMessageId, invalid, replace } = useFieldContext() ?? {}\n\n return (\n <styled.span\n id={helperMessageId}\n hidden={replace && invalid ? true : false}\n {...props}\n />\n )\n },\n \"helperMessage\",\n)()\n\nexport interface FieldErrorMessageProps extends HTMLStyledProps<\"span\"> {}\n\nexport const FieldErrorMessage = withContext<\"span\", FieldErrorMessageProps>(\n (props) => {\n const { errorMessageId, invalid } = useFieldContext() ?? {}\n\n return (\n <styled.span\n id={errorMessageId}\n aria-live={invalid ? \"polite\" : undefined}\n hidden={!invalid}\n {...props}\n />\n )\n },\n \"errorMessage\",\n)()\n"],"mappings":";;;;;;;;;;;;AA4BA,MAAM,CAAC,cAAc,mBAAmBA,gBAA4B;CAClE,MAAM;CACN,QAAQ;AACV,CAAC;AAyED,MAAM,EACJ,cAAc,mBACd,iBAAiB,sBACjB,aACA,iBACE,oBAAgD,SAAS,UAAU;;;;;;AASvE,MAAa,YAAY,cACtB,EACC,IACA,MACA,UACA,UACA,cACA,eACA,SACA,OACA,mBACA,UACA,SACA,UACA,mBACA,mBACA,oBACA,YACA,GAAG,WACC;CACJ,MAAM,OAAO,MAAM;CACnB,MAAM,UAAU,MAAM;CACtB,MAAM,kBAAkB,MAAM;CAC9B,MAAM,iBAAiB,MAAM;CAC7B,MAAM,cAAc,eAAe;CACnC,MAAM,kBAAkB,mBAAmB;CAC3C,MAAM,CAAC,SAAS,cAAc,SAAkB,KAAK;CACrD,MAAM,CACJ,iBACA,aACA,qBACA,sBACE,iBACF,UACA,YACA,oBACA,iBACF;CAEA,OAAO;CACP,sBAAsB,aAAa;CACnC,sBAAsB,aAAa;CAEnC,aAAa,iBAAiB;CAC9B,YAAY,iBAAiB;CAC7B,aAAa,iBAAiB;CAC9B,aAAa,iBAAiB;CAE9B,IAAI,MAAM;EACR,cAAA,GAAaC,cAAAA,SAAAA,CAAS,aAAa,QAAQ,IACvC,YAAY,SAAS,QACrB,aAAa;EACjB,aAAA,GAAYA,cAAAA,SAAAA,CAAS,aAAa,OAAO,IACrC,YAAY,QAAQ,QACpB,aAAa;EACjB,cAAA,GAAaA,cAAAA,SAAAA,CAAS,aAAa,QAAQ,IACvC,YAAY,SAAS,QACrB,aAAa;EACjB,cA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,SAAAA,CAAS,cAAc,QAAQ;EAC9C,eAAA,GAAYA,cAAAA,SAAAA,CAAS,cAAc,OAAO;EAC1C,iBAAA,GAAcA,cAAAA,SAAAA,CAAS,cAAc,OAAO;EAC5C,kBAAA,GAAeA,cAAAA,SAAAA,CAAS,cAAc,QAAQ;EAC9C,GAAI;EAPN,UAAA,CASG,UAEA,WACC,oBACE,oBAAC,wBAAD,EAAA,UAAyB,kBAA0C,CAAA,IAEnE,oBAAC,wBAAD,CAAyB,CAAA,IAG3B,iBAEU;;AAElB,GACA,OACF,CAAC,CAAC;AAIF,MAAM,yBAAyB,aAC5B,EAAE,UAAU,GAAG,WAAW;CACzB,IAAI,CAAC,eAAe,QAAQ,GAC1B,OACE,oBAAC,OAAO,MAAR;EAAa,eAAA;EAAY,MAAK;EAAe,GAAI;EAC9C,UAAA,YAAY,oBAAA,YAAA,EAAA,UAAE,IAAG,CAAA;CACP,CAAA;MAEZ,OAAO;AACd,GACA,mBACF,CAAC,CAAC;AAIF,MAAa,qBAAqB,aAC/B,UAAU;CACT,MAAM,EAAE,iBAAiB,SAAS,YAAY,gBAAgB,KAAK,CAAC;CAEpE,OACE,oBAAC,OAAO,MAAR;EACE,IAAI;EACJ,QAAQ,WAAW,UAAU,OAAO;EACpC,GAAI;CACL,CAAA;AAEL,GACA,eACF,CAAC,CAAC;AAIF,MAAa,oBAAoB,aAC9B,UAAU;CACT,MAAM,EAAE,gBAAgB,YAAY,gBAAgB,KAAK,CAAC;CAE1D,OACE,oBAAC,OAAO,MAAR;EACE,IAAI;EACJ,aAAW,UAAU,WAAW,KAAA;EAChC,QAAQ,CAAC;EACT,GAAI;CACL,CAAA;AAEL,GACA,cACF,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"field.js","names":["createContext","isObject","dataAttr"],"sources":["../../../../src/components/field/field.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactNode } from \"react\"\nimport type { HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { FieldStyle } from \"./field.style\"\nimport { isValidElement, useId, useMemo, useState } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport {\n createContext,\n dataAttr,\n getResolvedChild,\n isObject,\n useSplitChildren,\n} from \"../../utils\"\nimport { useFieldsetContext } from \"../fieldset\"\nimport { useFormContext } from \"../form\"\nimport { fieldStyle } from \"./field.style\"\n\nexport interface FieldContext\n extends FieldProps, Pick<FieldRootProps, \"replace\"> {\n errorMessageId: string\n focused: boolean\n helperMessageId: string\n id: string\n labelId: string\n onBlur: () => void\n onFocus: () => void\n}\n\nconst [FieldContext, useFieldContext] = createContext<FieldContext>({\n name: \"FieldContext\",\n strict: false,\n})\n\nexport { FieldContext, useFieldContext }\n\nexport interface FieldProps {\n /**\n * If `true`, the field will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * If `true`, the field will be invalid.\n *\n * @default false\n */\n invalid?: boolean\n /**\n * If `true`, the field will be readonly.\n *\n * @default false\n */\n readOnly?: boolean\n /**\n * If `true`, the field will be required.\n *\n * @default false\n */\n required?: boolean\n}\n\nexport interface FieldRootProps\n extends\n HTMLStyledProps,\n ThemeProps<FieldStyle>,\n Pick<FieldLabelProps, \"optionalIndicator\" | \"requiredIndicator\">,\n FieldProps {\n /**\n * The field error message to use.\n */\n errorMessage?: ReactNode\n /**\n * The field helper message to use.\n */\n helperMessage?: ReactNode\n /**\n * The field label to use.\n */\n label?: ReactNode\n /**\n * The name of the field.\n */\n name?: string\n /**\n * If `true`, switch between helper message and error message using invalid.\n *\n * @default true\n */\n replace?: boolean\n /**\n * Props the error message component.\n */\n errorMessageProps?: FieldErrorMessageProps\n /**\n * Props the helper message component.\n */\n helperMessageProps?: FieldHelperMessageProps\n /**\n * Props the label component.\n */\n labelProps?: FieldLabelProps\n}\n\nconst {\n PropsContext: FieldPropsContext,\n usePropsContext: useFieldPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<FieldRootProps, FieldStyle>(\"field\", fieldStyle)\n\nexport { FieldPropsContext, useFieldPropsContext }\n\n/**\n * `Field` is a component used to group form elements with label, helper message, error message, etc.\n *\n * @see https://yamada-ui.com/docs/components/field\n */\nexport const FieldRoot = withProvider<\"div\", FieldRootProps>(\n ({\n id,\n name,\n children,\n disabled,\n errorMessage,\n helperMessage,\n invalid,\n label,\n optionalIndicator,\n readOnly,\n replace,\n required,\n requiredIndicator,\n errorMessageProps,\n helperMessageProps,\n labelProps,\n ...rest\n }) => {\n const uuid = useId()\n const labelId = useId()\n const helperMessageId = useId()\n const errorMessageId = useId()\n const formContext = useFormContext()\n const fieldsetContext = useFieldsetContext()\n const [focused, setFocused] = useState<boolean>(false)\n const [\n omittedChildren,\n customLabel,\n customHelperMessage,\n customErrorMessage,\n ] = useSplitChildren(\n children,\n FieldLabel,\n FieldHelperMessage,\n FieldErrorMessage,\n )\n\n id ??= uuid\n optionalIndicator ??= formContext?.optionalIndicator\n requiredIndicator ??= formContext?.requiredIndicator\n\n disabled ??= fieldsetContext?.disabled\n invalid ??= fieldsetContext?.invalid\n readOnly ??= fieldsetContext?.readOnly\n required ??= fieldsetContext?.required\n\n if (name) {\n disabled ??= isObject(formContext?.disabled)\n ? formContext.disabled[name]\n : formContext?.disabled\n invalid ??= isObject(formContext?.invalid)\n ? formContext.invalid[name]\n : formContext?.invalid\n readOnly ??= isObject(formContext?.readOnly)\n ? formContext.readOnly[name]\n : formContext?.readOnly\n required ??= isObject(formContext?.required)\n ? formContext.required[name]\n : formContext?.required\n replace ??= isObject(formContext?.replace)\n ? (formContext.replace[name] ?? true)\n : (formContext?.replace ?? true)\n errorMessage ??= formContext?.errorMessage?.[name]\n helperMessage ??= formContext?.helperMessage?.[name]\n }\n\n const context = useMemo(\n () => ({\n id,\n disabled,\n errorMessageId,\n focused,\n helperMessageId,\n invalid,\n labelId,\n readOnly,\n replace,\n required,\n onBlur: () => setFocused(false),\n onFocus: () => setFocused(true),\n }),\n [\n id,\n disabled,\n labelId,\n focused,\n invalid,\n helperMessageId,\n errorMessageId,\n readOnly,\n replace,\n required,\n ],\n )\n\n return (\n <FieldContext value={context}>\n <styled.div\n data-disabled={dataAttr(disabled)}\n data-focus={dataAttr(focused)}\n data-invalid={dataAttr(invalid)}\n data-readonly={dataAttr(readOnly)}\n role=\"group\"\n {...rest}\n >\n {customLabel ||\n (label ? (\n <FieldLabel\n optionalIndicator={optionalIndicator}\n requiredIndicator={requiredIndicator}\n {...labelProps}\n >\n {label}\n </FieldLabel>\n ) : null)}\n\n {omittedChildren}\n\n {customHelperMessage ||\n (helperMessage ? (\n <FieldHelperMessage {...helperMessageProps}>\n {helperMessage}\n </FieldHelperMessage>\n ) : null)}\n\n {customErrorMessage ||\n (errorMessage ? (\n <FieldErrorMessage {...errorMessageProps}>\n {errorMessage}\n </FieldErrorMessage>\n ) : null)}\n </styled.div>\n </FieldContext>\n )\n },\n \"root\",\n)()\n\nexport interface FieldLabelProps extends HTMLStyledProps<\"label\"> {\n /**\n * The optional indicator to use.\n */\n optionalIndicator?: ReactNode\n /**\n * If `true`, the field will be required.\n *\n * @default false\n */\n required?: boolean\n /**\n * The required indicator to use.\n */\n requiredIndicator?: ReactNode\n}\n\nexport const FieldLabel = withContext<\"label\", FieldLabelProps>(\n ({\n id,\n htmlFor,\n children,\n optionalIndicator = null,\n required,\n requiredIndicator = null,\n ...rest\n }) => {\n const fieldContext = useFieldContext()\n\n id ??= fieldContext?.labelId\n htmlFor ??= fieldContext?.id\n required ??= fieldContext?.required\n\n return (\n <styled.label\n id={id}\n htmlFor={htmlFor}\n data-disabled={dataAttr(fieldContext?.disabled)}\n data-focus={dataAttr(fieldContext?.focused)}\n data-invalid={dataAttr(fieldContext?.invalid)}\n data-readonly={dataAttr(fieldContext?.readOnly)}\n {...rest}\n >\n {children}\n\n {required ? (\n requiredIndicator ? (\n <FieldRequiredIndicator>{requiredIndicator}</FieldRequiredIndicator>\n ) : (\n <FieldRequiredIndicator />\n )\n ) : (\n optionalIndicator\n )}\n </styled.label>\n )\n },\n \"label\",\n)()\n\ninterface FieldRequiredIndicatorProps extends HTMLStyledProps<\"span\"> {}\n\nconst FieldRequiredIndicator = withContext<\"span\", FieldRequiredIndicatorProps>(\n ({ children, ...rest }) => {\n const child = getResolvedChild(children)\n\n if (!isValidElement(child))\n return (\n <styled.span aria-hidden role=\"presentation\" {...rest}>\n {child || <>*</>}\n </styled.span>\n )\n else return child\n },\n \"requiredIndicator\",\n)()\n\nexport interface FieldHelperMessageProps extends HTMLStyledProps<\"span\"> {}\n\nexport const FieldHelperMessage = withContext<\"span\", FieldHelperMessageProps>(\n (props) => {\n const { helperMessageId, invalid, replace } = useFieldContext() ?? {}\n\n return (\n <styled.span\n id={helperMessageId}\n hidden={replace && invalid ? true : false}\n {...props}\n />\n )\n },\n \"helperMessage\",\n)()\n\nexport interface FieldErrorMessageProps extends HTMLStyledProps<\"span\"> {}\n\nexport const FieldErrorMessage = withContext<\"span\", FieldErrorMessageProps>(\n (props) => {\n const { errorMessageId, invalid } = useFieldContext() ?? {}\n\n return (\n <styled.span\n id={errorMessageId}\n aria-live={invalid ? \"polite\" : undefined}\n hidden={!invalid}\n {...props}\n />\n )\n },\n \"errorMessage\",\n)()\n"],"mappings":";;;;;;;;;;;;AA6BA,MAAM,CAAC,cAAc,mBAAmBA,gBAA4B;CAClE,MAAM;CACN,QAAQ;AACV,CAAC;AAyED,MAAM,EACJ,cAAc,mBACd,iBAAiB,sBACjB,aACA,iBACE,oBAAgD,SAAS,UAAU;;;;;;AASvE,MAAa,YAAY,cACtB,EACC,IACA,MACA,UACA,UACA,cACA,eACA,SACA,OACA,mBACA,UACA,SACA,UACA,mBACA,mBACA,oBACA,YACA,GAAG,WACC;CACJ,MAAM,OAAO,MAAM;CACnB,MAAM,UAAU,MAAM;CACtB,MAAM,kBAAkB,MAAM;CAC9B,MAAM,iBAAiB,MAAM;CAC7B,MAAM,cAAc,eAAe;CACnC,MAAM,kBAAkB,mBAAmB;CAC3C,MAAM,CAAC,SAAS,cAAc,SAAkB,KAAK;CACrD,MAAM,C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AAO,MAAR;EACE,IAAI;EACJ,QAAQ,WAAW,UAAU,OAAO;EACpC,GAAI;CACL,CAAA;AAEL,GACA,eACF,CAAC,CAAC;AAIF,MAAa,oBAAoB,aAC9B,UAAU;CACT,MAAM,EAAE,gBAAgB,YAAY,gBAAgB,KAAK,CAAC;CAE1D,OACE,oBAAC,OAAO,MAAR;EACE,IAAI;EACJ,aAAW,UAAU,WAAW,KAAA;EAChC,QAAQ,CAAC;EACT,GAAI;CACL,CAAA;AAEL,GACA,cACF,CAAC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { getResolvedChild } from "../../utils/children.js";
|
|
2
3
|
import { styled } from "../../core/system/factory.js";
|
|
3
4
|
import { createSlotComponent } from "../../core/components/create-component.js";
|
|
4
5
|
import { listStyle } from "./list.style.js";
|
|
@@ -52,10 +53,11 @@ const ListItem = withContext(({ children, icon, iconProps, ...rest }) => /* @__P
|
|
|
52
53
|
};
|
|
53
54
|
});
|
|
54
55
|
const ListItemIcon = withContext(({ children, ...rest }) => {
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
const child = getResolvedChild(children);
|
|
57
|
+
if (isValidElement(child)) return cloneElement(child, {
|
|
58
|
+
role: "presentation",
|
|
57
59
|
...rest,
|
|
58
|
-
|
|
60
|
+
...child.props
|
|
59
61
|
});
|
|
60
62
|
else return null;
|
|
61
63
|
}, "icon")({ "data-list-icon": "" });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","names":[],"sources":["../../../../src/components/list/list.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactElement } from \"react\"\nimport type {\n CSSProps,\n HTMLProps,\n HTMLStyledProps,\n ThemeProps,\n} from \"../../core\"\nimport type { ListStyle } from \"./list.style\"\nimport { cloneElement, isValidElement, useMemo } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { listStyle } from \"./list.style\"\n\ninterface ComponentContext extends Pick<\n ListRootProps,\n \"iconProps\" | \"itemProps\"\n> {}\n\nexport interface ListItem extends ListItemProps {}\n\nexport interface ListRootProps\n extends HTMLStyledProps<\"ul\">, Omit<ThemeProps<ListStyle>, \"styleType\"> {\n /**\n * If provided, generate elements based on items.\n */\n items?: ListItem[]\n /**\n * The CSS `list-style-position` property.\n */\n stylePosition?: CSSProps[\"listStylePosition\"]\n /**\n * The CSS `list-style-position` property.\n */\n styleType?: CSSProps[\"listStyleType\"]\n /**\n * Props for the icon component.\n */\n iconProps?: ListIconProps\n /**\n * Props for the item component.\n */\n itemProps?: ListItemProps\n}\n\nconst {\n ComponentContext,\n PropsContext: ListPropsContext,\n useComponentContext,\n usePropsContext: useListPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<ListRootProps, ListStyle, ComponentContext>(\n \"list\",\n listStyle,\n)\n\nexport { ListPropsContext, useListPropsContext }\n\n/**\n * `List` is a component for displaying lists. By default, it renders a `ul` element.\n *\n * @see https://yamada-ui.com/docs/components/list\n */\nexport const ListRoot = withProvider<\"ul\", ListRootProps, \"styleType\">(\n ({\n as: asProp,\n children,\n items,\n stylePosition: listStylePosition,\n styleType: listStyleType = \"none\",\n iconProps,\n itemProps,\n ...rest\n }) => {\n const as = asProp ?? (listStyleType == \"decimal\" ? \"ol\" : undefined)\n const computedChildren = useMemo(() => {\n if (children) return children\n\n return items?.map((props, index) => <ListItem key={index} {...props} />)\n }, [children, items])\n const context = useMemo(\n () => ({ iconProps, itemProps }),\n [iconProps, itemProps],\n )\n\n return (\n <ComponentContext value={context}>\n <styled.ul\n as={as}\n listStylePosition={listStylePosition}\n listStyleType={listStyleType}\n role=\"list\"\n {...rest}\n >\n {computedChildren}\n </styled.ul>\n </ComponentContext>\n )\n },\n \"root\",\n { transferProps: [\"styleType\"] },\n)()\n\nexport interface ListItemProps extends HTMLStyledProps<\"li\"> {\n /**\n * The icon to use.\n */\n icon?: ReactElement<any>\n /**\n * Props for the icon component.\n */\n iconProps?: ListIconProps\n}\n\nexport const ListItem = withContext<\"li\", ListItemProps>(\n ({ children, icon, iconProps, ...rest }) => (\n <styled.li {...rest}>\n <ListItemIcon {...iconProps}>{icon}</ListItemIcon>\n\n {children}\n </styled.li>\n ),\n \"item\",\n)((props) => {\n const { iconProps, itemProps } = useComponentContext()\n\n return {\n ...itemProps,\n ...props,\n iconProps: {\n ...iconProps,\n ...itemProps?.iconProps,\n ...props.iconProps,\n },\n }\n})\n\nexport interface ListIconProps extends HTMLStyledProps<\"svg\"> {}\n\nexport const ListItemIcon = withContext<\"svg\", ListIconProps>(\n ({ children, ...rest }) => {\n if (isValidElement<HTMLProps<\"svg\">>(
|
|
1
|
+
{"version":3,"file":"list.js","names":[],"sources":["../../../../src/components/list/list.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactElement } from \"react\"\nimport type {\n CSSProps,\n HTMLProps,\n HTMLStyledProps,\n ThemeProps,\n} from \"../../core\"\nimport type { ListStyle } from \"./list.style\"\nimport { cloneElement, isValidElement, useMemo } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { getResolvedChild } from \"../../utils\"\nimport { listStyle } from \"./list.style\"\n\ninterface ComponentContext extends Pick<\n ListRootProps,\n \"iconProps\" | \"itemProps\"\n> {}\n\nexport interface ListItem extends ListItemProps {}\n\nexport interface ListRootProps\n extends HTMLStyledProps<\"ul\">, Omit<ThemeProps<ListStyle>, \"styleType\"> {\n /**\n * If provided, generate elements based on items.\n */\n items?: ListItem[]\n /**\n * The CSS `list-style-position` property.\n */\n stylePosition?: CSSProps[\"listStylePosition\"]\n /**\n * The CSS `list-style-position` property.\n */\n styleType?: CSSProps[\"listStyleType\"]\n /**\n * Props for the icon component.\n */\n iconProps?: ListIconProps\n /**\n * Props for the item component.\n */\n itemProps?: ListItemProps\n}\n\nconst {\n ComponentContext,\n PropsContext: ListPropsContext,\n useComponentContext,\n usePropsContext: useListPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<ListRootProps, ListStyle, ComponentContext>(\n \"list\",\n listStyle,\n)\n\nexport { ListPropsContext, useListPropsContext }\n\n/**\n * `List` is a component for displaying lists. By default, it renders a `ul` element.\n *\n * @see https://yamada-ui.com/docs/components/list\n */\nexport const ListRoot = withProvider<\"ul\", ListRootProps, \"styleType\">(\n ({\n as: asProp,\n children,\n items,\n stylePosition: listStylePosition,\n styleType: listStyleType = \"none\",\n iconProps,\n itemProps,\n ...rest\n }) => {\n const as = asProp ?? (listStyleType == \"decimal\" ? \"ol\" : undefined)\n const computedChildren = useMemo(() => {\n if (children) return children\n\n return items?.map((props, index) => <ListItem key={index} {...props} />)\n }, [children, items])\n const context = useMemo(\n () => ({ iconProps, itemProps }),\n [iconProps, itemProps],\n )\n\n return (\n <ComponentContext value={context}>\n <styled.ul\n as={as}\n listStylePosition={listStylePosition}\n listStyleType={listStyleType}\n role=\"list\"\n {...rest}\n >\n {computedChildren}\n </styled.ul>\n </ComponentContext>\n )\n },\n \"root\",\n { transferProps: [\"styleType\"] },\n)()\n\nexport interface ListItemProps extends HTMLStyledProps<\"li\"> {\n /**\n * The icon to use.\n */\n icon?: ReactElement<any>\n /**\n * Props for the icon component.\n */\n iconProps?: ListIconProps\n}\n\nexport const ListItem = withContext<\"li\", ListItemProps>(\n ({ children, icon, iconProps, ...rest }) => (\n <styled.li {...rest}>\n <ListItemIcon {...iconProps}>{icon}</ListItemIcon>\n\n {children}\n </styled.li>\n ),\n \"item\",\n)((props) => {\n const { iconProps, itemProps } = useComponentContext()\n\n return {\n ...itemProps,\n ...props,\n iconProps: {\n ...iconProps,\n ...itemProps?.iconProps,\n ...props.iconProps,\n },\n }\n})\n\nexport interface ListIconProps extends HTMLStyledProps<\"svg\"> {}\n\nexport const ListItemIcon = withContext<\"svg\", ListIconProps>(\n ({ children, ...rest }) => {\n const child = getResolvedChild(children)\n\n if (isValidElement<HTMLProps<\"svg\">>(child))\n return cloneElement(child, {\n role: \"presentation\",\n ...rest,\n ...child.props,\n })\n else return null\n },\n \"icon\",\n)({ \"data-list-icon\": \"\" })\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GAAG;EACH,GAAG,MAAM;CACX,CAAC;MACE,OAAO;AACd,GACA,MACF,CAAC,CAAC,EAAE,kBAAkB,GAAG,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useSplitChildren } from "../../utils/children.js";
|
|
2
|
+
import { getResolvedChild, useSplitChildren } from "../../utils/children.js";
|
|
3
3
|
import { createContext as createContext$1 } from "../../utils/context.js";
|
|
4
4
|
import { styled } from "../../core/system/factory.js";
|
|
5
5
|
import { createSlotComponent } from "../../core/components/create-component.js";
|
|
@@ -74,11 +74,12 @@ const NativeAccordionIcon = withContext(({ children = /* @__PURE__ */ jsx(Chevro
|
|
|
74
74
|
const { iconHidden } = useComponentContext();
|
|
75
75
|
const { getIconProps } = useItemComponentContext();
|
|
76
76
|
if (iconHidden) return null;
|
|
77
|
-
|
|
77
|
+
const child = getResolvedChild(children);
|
|
78
|
+
if (isValidElement(child)) return cloneElement(child, getIconProps({
|
|
78
79
|
...rest,
|
|
79
|
-
...
|
|
80
|
+
...child.props
|
|
80
81
|
}));
|
|
81
|
-
return Children.count(
|
|
82
|
+
return Children.count(child) > 1 ? Children.only(null) : null;
|
|
82
83
|
}, "icon")();
|
|
83
84
|
const NativeAccordionPanel = withContext(({ children, ...rest }) => {
|
|
84
85
|
const { getPanelProps } = useItemComponentContext();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-accordion.js","names":["createContext"],"sources":["../../../../src/components/native-accordion/native-accordion.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactNode } from \"react\"\nimport type { HTMLProps, HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { NativeAccordionStyle } from \"./native-accordion.style\"\nimport type {\n UseNativeAccordionItemProps,\n UseNativeAccordionItemReturn,\n UseNativeAccordionProps,\n} from \"./use-native-accordion\"\nimport { Children, cloneElement, isValidElement, useMemo } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { createContext, useSplitChildren } from \"../../utils\"\nimport { ChevronDownIcon } from \"../icon\"\nimport { nativeAccordionStyle } from \"./native-accordion.style\"\nimport {\n NativeAccordionContext,\n useNativeAccordion,\n useNativeAccordionItem,\n} from \"./use-native-accordion\"\n\nexport interface NativeAccordionItem extends NativeAccordionItemProps {}\n\ninterface ComponentContext extends Pick<\n NativeAccordionRootProps,\n \"icon\" | \"iconHidden\"\n> {}\n\nexport interface NativeAccordionRootProps\n extends\n Omit<HTMLStyledProps, \"onChange\">,\n ThemeProps<NativeAccordionStyle>,\n UseNativeAccordionProps {\n /**\n * The accordion icon for all items to use.\n */\n icon?: ReactNode\n /**\n * If `true`, hide the accordion icon for all items.\n *\n * @default false\n */\n iconHidden?: boolean\n /**\n * If provided, generate elements based on items.\n */\n items?: NativeAccordionItem[]\n}\n\ninterface ItemComponentContext\n extends\n Pick<NativeAccordionItemProps, \"icon\">,\n Omit<UseNativeAccordionItemReturn, \"getItemProps\"> {}\n\nconst [ItemComponentContext, useItemComponentContext] =\n createContext<ItemComponentContext>({\n name: \"ItemComponentContext\",\n })\n\nconst {\n ComponentContext,\n PropsContext: NativeAccordionPropsContext,\n useComponentContext,\n usePropsContext: useNativeAccordionPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<\n NativeAccordionRootProps,\n NativeAccordionStyle,\n ComponentContext\n>(\"native-accordion\", nativeAccordionStyle)\n\nexport { NativeAccordionPropsContext, useNativeAccordionPropsContext }\n\n/**\n * `NativeAccordion` is a component for a list that displays information in an expandable or collapsible manner using the native HTML details element.\n *\n * @see https://yamada-ui.com/docs/components/native-accordion\n */\nexport const NativeAccordionRoot = withProvider<\n \"div\",\n NativeAccordionRootProps\n>(({ children, icon, iconHidden, items, ...props }) => {\n const { name, getRootProps } = useNativeAccordion(props)\n const computedChildren = useMemo(() => {\n if (children) return children\n\n return items?.map((props, index) => (\n <NativeAccordionItem key={index} {...props} />\n ))\n }, [children, items])\n const context = useMemo(() => ({ name }), [name])\n const componentContext = useMemo(\n () => ({ icon, iconHidden }),\n [icon, iconHidden],\n )\n\n return (\n <NativeAccordionContext value={context}>\n <ComponentContext value={componentContext}>\n <styled.div {...getRootProps()}>{computedChildren}</styled.div>\n </ComponentContext>\n </NativeAccordionContext>\n )\n}, \"root\")()\n\nexport interface NativeAccordionItemProps\n extends HTMLStyledProps<\"details\">, UseNativeAccordionItemProps {\n /**\n * The accordion button to use.\n */\n button?: ReactNode\n /**\n * The accordion icon to use.\n */\n icon?: ReactNode\n}\n\nexport const NativeAccordionItem = withContext<\n \"details\",\n NativeAccordionItemProps\n>(({ button, children, icon, ...rest }) => {\n const {\n disabled,\n getButtonProps,\n getIconProps,\n getItemProps,\n getPanelProps,\n } = useNativeAccordionItem(rest)\n const [omittedChildren, customAccordionButton, customAccordionPanel] =\n useSplitChildren(children, NativeAccordionButton, NativeAccordionPanel)\n const context = useMemo(\n () => ({\n disabled,\n icon,\n getButtonProps,\n getIconProps,\n getPanelProps,\n }),\n [disabled, getIconProps, getPanelProps, getButtonProps, icon],\n )\n\n return (\n <ItemComponentContext value={context}>\n <styled.details {...getItemProps()}>\n {customAccordionButton ?? (\n <NativeAccordionButton>{button}</NativeAccordionButton>\n )}\n {customAccordionPanel ?? (\n <NativeAccordionPanel>{omittedChildren}</NativeAccordionPanel>\n )}\n </styled.details>\n </ItemComponentContext>\n )\n}, \"item\")()\n\nexport interface NativeAccordionButtonProps extends HTMLStyledProps<\"summary\"> {\n /**\n * The accordion icon to use.\n */\n icon?: ReactNode\n}\n\nexport const NativeAccordionButton = withContext<\n \"summary\",\n NativeAccordionButtonProps\n>(({ children, icon: customIcon, ...rest }) => {\n const { icon: rootIcon } = useComponentContext()\n const { icon: itemIcon, getButtonProps } = useItemComponentContext()\n\n return (\n <styled.summary {...getButtonProps(rest)}>\n {children}\n\n <NativeAccordionIcon>\n {customIcon ?? itemIcon ?? rootIcon}\n </NativeAccordionIcon>\n </styled.summary>\n )\n}, \"button\")()\n\nexport interface NativeAccordionIconProps extends HTMLStyledProps<\"svg\"> {}\n\nexport const NativeAccordionIcon = withContext<\"svg\", NativeAccordionIconProps>(\n ({ children = <ChevronDownIcon />, ...rest }) => {\n const { iconHidden } = useComponentContext()\n const { getIconProps } = useItemComponentContext()\n\n if (iconHidden) return null\n\n if (isValidElement<HTMLProps<\"svg\">>(
|
|
1
|
+
{"version":3,"file":"native-accordion.js","names":["createContext"],"sources":["../../../../src/components/native-accordion/native-accordion.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactNode } from \"react\"\nimport type { HTMLProps, HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { NativeAccordionStyle } from \"./native-accordion.style\"\nimport type {\n UseNativeAccordionItemProps,\n UseNativeAccordionItemReturn,\n UseNativeAccordionProps,\n} from \"./use-native-accordion\"\nimport { Children, cloneElement, isValidElement, useMemo } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { createContext, getResolvedChild, useSplitChildren } from \"../../utils\"\nimport { ChevronDownIcon } from \"../icon\"\nimport { nativeAccordionStyle } from \"./native-accordion.style\"\nimport {\n NativeAccordionContext,\n useNativeAccordion,\n useNativeAccordionItem,\n} from \"./use-native-accordion\"\n\nexport interface NativeAccordionItem extends NativeAccordionItemProps {}\n\ninterface ComponentContext extends Pick<\n NativeAccordionRootProps,\n \"icon\" | \"iconHidden\"\n> {}\n\nexport interface NativeAccordionRootProps\n extends\n Omit<HTMLStyledProps, \"onChange\">,\n ThemeProps<NativeAccordionStyle>,\n UseNativeAccordionProps {\n /**\n * The accordion icon for all items to use.\n */\n icon?: ReactNode\n /**\n * If `true`, hide the accordion icon for all items.\n *\n * @default false\n */\n iconHidden?: boolean\n /**\n * If provided, generate elements based on items.\n */\n items?: NativeAccordionItem[]\n}\n\ninterface ItemComponentContext\n extends\n Pick<NativeAccordionItemProps, \"icon\">,\n Omit<UseNativeAccordionItemReturn, \"getItemProps\"> {}\n\nconst [ItemComponentContext, useItemComponentContext] =\n createContext<ItemComponentContext>({\n name: \"ItemComponentContext\",\n })\n\nconst {\n ComponentContext,\n PropsContext: NativeAccordionPropsContext,\n useComponentContext,\n usePropsContext: useNativeAccordionPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<\n NativeAccordionRootProps,\n NativeAccordionStyle,\n ComponentContext\n>(\"native-accordion\", nativeAccordionStyle)\n\nexport { NativeAccordionPropsContext, useNativeAccordionPropsContext }\n\n/**\n * `NativeAccordion` is a component for a list that displays information in an expandable or collapsible manner using the native HTML details element.\n *\n * @see https://yamada-ui.com/docs/components/native-accordion\n */\nexport const NativeAccordionRoot = withProvider<\n \"div\",\n NativeAccordionRootProps\n>(({ children, icon, iconHidden, items, ...props }) => {\n const { name, getRootProps } = useNativeAccordion(props)\n const computedChildren = useMemo(() => {\n if (children) return children\n\n return items?.map((props, index) => (\n <NativeAccordionItem key={index} {...props} />\n ))\n }, [children, items])\n const context = useMemo(() => ({ name }), [name])\n const componentContext = useMemo(\n () => ({ icon, iconHidden }),\n [icon, iconHidden],\n )\n\n return (\n <NativeAccordionContext value={context}>\n <ComponentContext value={componentContext}>\n <styled.div {...getRootProps()}>{computedChildren}</styled.div>\n </ComponentContext>\n </NativeAccordionContext>\n )\n}, \"root\")()\n\nexport interface NativeAccordionItemProps\n extends HTMLStyledProps<\"details\">, UseNativeAccordionItemProps {\n /**\n * The accordion button to use.\n */\n button?: ReactNode\n /**\n * The accordion icon to use.\n */\n icon?: ReactNode\n}\n\nexport const NativeAccordionItem = withContext<\n \"details\",\n NativeAccordionItemProps\n>(({ button, children, icon, ...rest }) => {\n const {\n disabled,\n getButtonProps,\n getIconProps,\n getItemProps,\n getPanelProps,\n } = useNativeAccordionItem(rest)\n const [omittedChildren, customAccordionButton, customAccordionPanel] =\n useSplitChildren(children, NativeAccordionButton, NativeAccordionPanel)\n const context = useMemo(\n () => ({\n disabled,\n icon,\n getButtonProps,\n getIconProps,\n getPanelProps,\n }),\n [disabled, getIconProps, getPanelProps, getButtonProps, icon],\n )\n\n return (\n <ItemComponentContext value={context}>\n <styled.details {...getItemProps()}>\n {customAccordionButton ?? (\n <NativeAccordionButton>{button}</NativeAccordionButton>\n )}\n {customAccordionPanel ?? (\n <NativeAccordionPanel>{omittedChildren}</NativeAccordionPanel>\n )}\n </styled.details>\n </ItemComponentContext>\n )\n}, \"item\")()\n\nexport interface NativeAccordionButtonProps extends HTMLStyledProps<\"summary\"> {\n /**\n * The accordion icon to use.\n */\n icon?: ReactNode\n}\n\nexport const NativeAccordionButton = withContext<\n \"summary\",\n NativeAccordionButtonProps\n>(({ children, icon: customIcon, ...rest }) => {\n const { icon: rootIcon } = useComponentContext()\n const { icon: itemIcon, getButtonProps } = useItemComponentContext()\n\n return (\n <styled.summary {...getButtonProps(rest)}>\n {children}\n\n <NativeAccordionIcon>\n {customIcon ?? itemIcon ?? rootIcon}\n </NativeAccordionIcon>\n </styled.summary>\n )\n}, \"button\")()\n\nexport interface NativeAccordionIconProps extends HTMLStyledProps<\"svg\"> {}\n\nexport const NativeAccordionIcon = withContext<\"svg\", NativeAccordionIconProps>(\n ({ children = <ChevronDownIcon />, ...rest }) => {\n const { iconHidden } = useComponentContext()\n const { getIconProps } = useItemComponentContext()\n\n if (iconHidden) return null\n\n const child = getResolvedChild(children)\n\n if (isValidElement<HTMLProps<\"svg\">>(child))\n return cloneElement(child, getIconProps({ ...rest, ...child.props }))\n\n return Children.count(child) > 1 ? Children.only(null) : null\n },\n \"icon\",\n)()\n\nexport interface NativeAccordionPanelProps extends HTMLStyledProps {}\n\nexport const NativeAccordionPanel = withContext<\n \"div\",\n NativeAccordionPanelProps\n>(({ children, ...rest }) => {\n const { getPanelProps } = useItemComponentContext()\n\n return (\n <styled.div {...getPanelProps(rest)}>\n <styled.div>{children}</styled.div>\n </styled.div>\n )\n}, \"panel\")()\n"],"mappings":";;;;;;;;;;;AAsDA,MAAM,CAAC,sBAAsB,2BAC3BA,gBAAoC,EAClC,MAAM,uBACR,CAAC;AAEH,MAAM,EACJ,kBACA,cAAc,6BACd,qBACA,iBAAiB,gCACjB,aACA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C,CAAC;AASX,MAAa,wBAAwB,aAGlC,EAAE,UAAU,MAAM,YAAY,GAAG,WAAW;CAC7C,MAAM,EAAE,MAAM,aAAa,oBAAoB;CAC/C,MAAM,EAAE,MAAM,UAAU,mBAAmB,wBAAwB;CAEnE,OACE,qBAAC,OAAO,SAAR;EAAgB,GAAI,eAAe,IAAI;EAAvC,UAAA,CACG,UAED,oBAAC,qBAAD,EAAA,UACG,cAAc,YAAY,SACR,CAAA,CACP;;AAEpB,GAAG,QAAQ,CAAC,CAAC;AAIb,MAAa,sBAAsB,aAChC,EAAE,WAAW,oBAAC,iBAAD,CAAkB,CAAA,GAAG,GAAG,WAAW;CAC/C,MAAM,EAAE,eAAe,oBAAoB;CAC3C,MAAM,EAAE,iBAAiB,wBAAwB;CAEjD,IAAI,YAAY,OAAO;CAEvB,MAAM,QAAQ,iBAAiB,QAAQ;CAEvC,IAAI,eAAiC,KAAK,GACxC,OAAO,aAAa,OAAO,aAAa;EAAE,GAAG;EAAM,GAAG,MAAM;CAAM,CAAC,CAAC;CAEtE,OAAO,SAAS,MAAM,KAAK,IAAI,IAAI,SAAS,KAAK,IAAI,IAAI;AAC3D,GACA,MACF,CAAC,CAAC;AAIF,MAAa,uBAAuB,aAGjC,EAAE,UAAU,GAAG,WAAW;CAC3B,MAAM,EAAE,kBAAkB,wBAAwB;CAElD,OACE,oBAAC,OAAO,KAAR;EAAY,GAAI,cAAc,IAAI;EAChC,UAAA,oBAAC,OAAO,KAAR,EAAa,SAAqB,CAAA;CACxB,CAAA;AAEhB,GAAG,OAAO,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useIncludesChildren, useSplitChildren, useValidChildren } from "../../utils/children.js";
|
|
2
|
+
import { getResolvedChild, useIncludesChildren, useSplitChildren, useValidChildren } from "../../utils/children.js";
|
|
3
3
|
import { createContext as createContext$1 } from "../../utils/context.js";
|
|
4
4
|
import { utils_exports } from "../../utils/index.js";
|
|
5
5
|
import { styled } from "../../core/system/factory.js";
|
|
@@ -626,11 +626,12 @@ const SidebarItemContent = withContext((props) => {
|
|
|
626
626
|
const SidebarItemIndicator = withContext(({ children = /* @__PURE__ */ jsx(ChevronRightIcon, {}), ...rest }) => {
|
|
627
627
|
const { indicatorHidden } = useSidePanelComponentContext();
|
|
628
628
|
if (indicatorHidden) return null;
|
|
629
|
-
|
|
629
|
+
const child = getResolvedChild(children);
|
|
630
|
+
if (isValidElement(child)) return cloneElement(child, {
|
|
630
631
|
...rest,
|
|
631
|
-
...
|
|
632
|
+
...child.props
|
|
632
633
|
});
|
|
633
|
-
return Children.count(
|
|
634
|
+
return Children.count(child) > 1 ? Children.only(null) : null;
|
|
634
635
|
}, "itemIndicator")(void 0, (props) => {
|
|
635
636
|
const { indicatorProps } = useItemComponentContext();
|
|
636
637
|
return mergeProps(indicatorProps, props)();
|