@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 7.15 kB
Source Map (JSON)
{"version":3,"file":"fieldset.cjs","names":["createContext","createSlotComponent","fieldsetStyle","useSplitChildren","styled"],"sources":["../../../../src/components/fieldset/fieldset.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactNode } from \"react\"\nimport type { HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport type { FieldsetStyle } from \"./fieldset.style\"\nimport { useId, useMemo } from \"react\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { createContext, dataAttr, useSplitChildren } from \"../../utils\"\nimport { fieldsetStyle } from \"./fieldset.style\"\n\ninterface FieldsetContext\n extends Pick<\n FieldsetRootProps,\n \"disabled\" | \"invalid\" | \"readOnly\" | \"required\"\n > {\n id?: string\n}\n\nconst [FieldsetContext, useFieldsetContext] = createContext<FieldsetContext>({\n name: \"FieldsetContext\",\n strict: false,\n})\n\nexport { FieldsetContext, useFieldsetContext }\n\nexport interface FieldsetRootProps\n extends HTMLStyledProps<\"fieldset\">,\n ThemeProps<FieldsetStyle>,\n FieldProps {\n /**\n * The fieldset error message to use.\n */\n errorMessage?: ReactNode\n /**\n * The fieldset helper message to use.\n */\n helperMessage?: ReactNode\n /**\n * The fieldset legend to use.\n */\n legend?: ReactNode\n /**\n * Props the content component.\n */\n contentProps?: FieldsetContentProps\n /**\n * Props the error message component.\n */\n errorMessageProps?: FieldsetErrorMessageProps\n /**\n * Props the header component.\n */\n headerProps?: FieldsetHeaderProps\n /**\n * Props the helper message component.\n */\n helperMessageProps?: FieldsetHelperMessageProps\n /**\n * Props the legend component.\n */\n legendProps?: FieldsetLegendProps\n}\n\nconst {\n PropsContext: FieldsetPropsContext,\n usePropsContext: useFieldsetPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<FieldsetRootProps, FieldsetStyle, FieldsetContext>(\n \"fieldset\",\n fieldsetStyle,\n)\n\nexport { FieldsetPropsContext, useFieldsetPropsContext }\n\n/**\n * `Fieldset` is a component used to group multiple controls.\n *\n * @see https://yamada-ui.com/docs/components/fieldset\n */\nexport const FieldsetRoot = withProvider<\"fieldset\", FieldsetRootProps>(\n ({\n id,\n children,\n disabled,\n errorMessage,\n helperMessage,\n invalid,\n legend,\n readOnly,\n required,\n contentProps,\n errorMessageProps,\n headerProps,\n helperMessageProps,\n legendProps,\n ...rest\n }) => {\n const uuid = useId()\n const [\n omittedChildren,\n customLegend,\n customHeader,\n customContent,\n customHelperMessage,\n customErrorMessage,\n ] = useSplitChildren(\n children,\n FieldsetLegend,\n FieldsetHeader,\n FieldsetContent,\n FieldsetHelperMessage,\n FieldsetErrorMessage,\n )\n\n id ??= uuid\n\n const context = useMemo(\n () => ({\n id,\n disabled,\n invalid,\n readOnly,\n required,\n }),\n [id, disabled, invalid, readOnly, required],\n )\n\n return (\n <FieldsetContext value={context}>\n <styled.fieldset {...rest}>\n {customHeader || (\n <FieldsetHeader {...headerProps}>\n {customLegend ||\n (legend ? (\n <FieldsetLegend {...legendProps}>{legend}</FieldsetLegend>\n ) : null)}\n\n {customHelperMessage ||\n (helperMessage ? (\n <FieldsetHelperMessage {...helperMessageProps}>\n {helperMessage}\n </FieldsetHelperMessage>\n ) : null)}\n </FieldsetHeader>\n )}\n\n {customContent || (\n <FieldsetContent {...contentProps}>\n {omittedChildren}\n </FieldsetContent>\n )}\n\n {customErrorMessage ||\n (errorMessage ? (\n <FieldsetErrorMessage {...errorMessageProps}>\n {errorMessage}\n </FieldsetErrorMessage>\n ) : null)}\n </styled.fieldset>\n </FieldsetContext>\n )\n },\n \"root\",\n)()\n\nexport interface FieldsetLegendProps extends HTMLStyledProps<\"legend\"> {}\n\nexport const FieldsetLegend = withContext<\"legend\", FieldsetLegendProps>(\n \"legend\",\n \"legend\",\n)(undefined, (props) => {\n const { id, disabled, invalid } = useFieldsetContext() ?? {}\n\n return {\n id,\n \"data-disabled\": dataAttr(disabled),\n \"data-invalid\": dataAttr(invalid),\n ...props,\n }\n})\n\nexport interface FieldsetHeaderProps extends HTMLStyledProps {}\n\nexport const FieldsetHeader = withContext<\"div\", FieldsetHeaderProps>(\n \"div\",\n \"header\",\n)()\n\nexport interface FieldsetContentProps extends HTMLStyledProps {}\n\nexport const FieldsetContent = withContext<\"div\", FieldsetContentProps>(\n \"div\",\n \"content\",\n)()\n\nexport interface FieldsetHelperMessageProps extends HTMLStyledProps<\"span\"> {}\n\nexport const FieldsetHelperMessage = withContext<\n \"span\",\n FieldsetHelperMessageProps\n>(\"span\", \"helperMessage\")(undefined, (props) => {\n const { id } = useFieldsetContext() ?? {}\n\n return { \"aria-describedby\": id, ...props }\n})\n\nexport interface FieldsetErrorMessageProps extends HTMLStyledProps<\"span\"> {}\n\nexport const FieldsetErrorMessage = withContext<\n \"span\",\n FieldsetErrorMessageProps\n>((props) => {\n const { invalid } = useFieldsetContext() ?? {}\n\n return (\n <styled.span\n aria-live={invalid ? \"polite\" : undefined}\n hidden={!invalid}\n {...props}\n />\n )\n}, \"errorMessage\")()\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,MAAM,CAAC,iBAAiB,sBAAsBA,8BAA+B;CAC3E,MAAM;CACN,QAAQ;CACT,CAAC;AA0CF,MAAM,EACJ,cAAc,sBACd,iBAAiB,yBACjB,aACA,iBACEC,6CACF,YACAC,qCACD;;;;;;AASD,MAAa,eAAe,cACzB,EACC,IACA,UACA,UACA,cACA,eACA,SACA,QACA,UACA,UACA,cACA,mBACA,aACA,oBACA,YACA,GAAG,WACC;CACJ,MAAM,yBAAc;CACpB,MAAM,CACJ,iBACA,cACA,cACA,eACA,qBACA,sBACEC,kCACF,UACA,gBACA,gBACA,iBACA,uBACA,qBACD;AAED,QAAO;AAaP,QACE,2CAAC;EAAgB,iCAXV;GACL;GACA;GACA;GACA;GACA;GACD,GACD;GAAC;GAAI;GAAU;GAAS;GAAU;GAAS,CAC5C;YAIG,4CAACC,uBAAO;GAAS,GAAI;;IAClB,gBACC,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