@fuf-stack/uniform 2.0.0-next.1 → 2.0.0-next.3
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/Checkboxes/index.d.mts +57 -37
- package/dist/Checkboxes/index.d.mts.map +1 -1
- package/dist/Checkboxes/index.mjs +19 -20
- package/dist/Checkboxes/index.mjs.map +1 -1
- package/dist/DatePicker/index.d.mts +71 -31
- package/dist/DatePicker/index.d.mts.map +1 -1
- package/dist/DatePicker/index.mjs +31 -29
- package/dist/DatePicker/index.mjs.map +1 -1
- package/dist/FieldArray/index.d.mts +8 -16
- package/dist/FieldArray/index.d.mts.map +1 -1
- package/dist/FieldArray/index.mjs +18 -32
- package/dist/FieldArray/index.mjs.map +1 -1
- package/dist/FieldCard/index.d.mts +0 -4
- package/dist/FieldCard/index.d.mts.map +1 -1
- package/dist/FieldCard/index.mjs +11 -19
- package/dist/FieldCard/index.mjs.map +1 -1
- package/dist/{FieldCopyTestIdButton-DV0tkdh2.mjs → FieldCopyTestIdButton-D3_jZYJ1.mjs} +3 -5
- package/dist/{FieldCopyTestIdButton-DV0tkdh2.mjs.map → FieldCopyTestIdButton-D3_jZYJ1.mjs.map} +1 -1
- package/dist/{FieldDescription-C4l0HKGL.mjs → FieldDescription-X_0s1Lhu.mjs} +5 -6
- package/dist/FieldDescription-X_0s1Lhu.mjs.map +1 -0
- package/dist/{FieldLabel-DKzqkuY1.mjs → FieldLabel-DrNWJIVh.mjs} +15 -12
- package/dist/FieldLabel-DrNWJIVh.mjs.map +1 -0
- package/dist/{FieldLayout-BLW5S-Jm.mjs → FieldLayout-DcvQU0zN.mjs} +4 -5
- package/dist/{FieldLayout-BLW5S-Jm.mjs.map → FieldLayout-DcvQU0zN.mjs.map} +1 -1
- package/dist/FieldReset/index.d.mts +420 -0
- package/dist/FieldReset/index.d.mts.map +1 -0
- package/dist/FieldReset/index.mjs +258 -0
- package/dist/FieldReset/index.mjs.map +1 -0
- package/dist/{FieldValidationError-DgkCL3cC.mjs → FieldValidationError-iAayfTEw.mjs} +3 -5
- package/dist/{FieldValidationError-DgkCL3cC.mjs.map → FieldValidationError-iAayfTEw.mjs.map} +1 -1
- package/dist/Form/index.d.mts +12 -14
- package/dist/Form/index.d.mts.map +1 -1
- package/dist/Form/index.mjs +7 -10
- package/dist/Form/index.mjs.map +1 -1
- package/dist/FormContext-BnNJYZOo.d.mts +124 -0
- package/dist/FormContext-BnNJYZOo.d.mts.map +1 -0
- package/dist/{FormContext-CHctWFAP.mjs → FormContext-PXkVlBdU.mjs} +5 -9
- package/dist/{FormContext-CHctWFAP.mjs.map → FormContext-PXkVlBdU.mjs.map} +1 -1
- package/dist/Grid/index.d.mts +0 -2
- package/dist/Grid/index.d.mts.map +1 -1
- package/dist/Grid/index.mjs +1 -1
- package/dist/{Grid-DfcZeuib.mjs → Grid-DBL29Kwb.mjs} +3 -5
- package/dist/{Grid-DfcZeuib.mjs.map → Grid-DBL29Kwb.mjs.map} +1 -1
- package/dist/Input/index.d.mts +167 -115
- package/dist/Input/index.d.mts.map +1 -1
- package/dist/Input/index.mjs +20 -24
- package/dist/Input/index.mjs.map +1 -1
- package/dist/RadioBoxes/index.d.mts +226 -2222
- package/dist/RadioBoxes/index.d.mts.map +1 -1
- package/dist/RadioBoxes/index.mjs +24 -28
- package/dist/RadioBoxes/index.mjs.map +1 -1
- package/dist/RadioTabs/index.d.mts +121 -66
- package/dist/RadioTabs/index.d.mts.map +1 -1
- package/dist/RadioTabs/index.mjs +16 -19
- package/dist/RadioTabs/index.mjs.map +1 -1
- package/dist/Radios/index.d.mts +140 -2056
- package/dist/Radios/index.d.mts.map +1 -1
- package/dist/Radios/index.mjs +11 -14
- package/dist/Radios/index.mjs.map +1 -1
- package/dist/Select/index.d.mts +154 -21
- package/dist/Select/index.d.mts.map +1 -1
- package/dist/Select/index.mjs +65 -49
- package/dist/Select/index.mjs.map +1 -1
- package/dist/Slider/index.d.mts +143 -77
- package/dist/Slider/index.d.mts.map +1 -1
- package/dist/Slider/index.mjs +26 -18
- package/dist/Slider/index.mjs.map +1 -1
- package/dist/SubmitButton/index.d.mts +0 -2
- package/dist/SubmitButton/index.d.mts.map +1 -1
- package/dist/SubmitButton/index.mjs +2 -4
- package/dist/SubmitButton/index.mjs.map +1 -1
- package/dist/Switch/index.d.mts +1 -1
- package/dist/Switch/index.mjs +16 -18
- package/dist/Switch/index.mjs.map +1 -1
- package/dist/{Switch-CvPO8IF9.d.mts → Switch-Db2dpGz7.d.mts} +115 -68
- package/dist/{Switch-CvPO8IF9.d.mts.map → Switch-Db2dpGz7.d.mts.map} +1 -1
- package/dist/SwitchBox/index.d.mts +169 -126
- package/dist/SwitchBox/index.d.mts.map +1 -1
- package/dist/SwitchBox/index.mjs +18 -18
- package/dist/SwitchBox/index.mjs.map +1 -1
- package/dist/TextArea/index.d.mts +100 -57
- package/dist/TextArea/index.d.mts.map +1 -1
- package/dist/TextArea/index.mjs +14 -16
- package/dist/TextArea/index.mjs.map +1 -1
- package/dist/Time/index.d.mts +44 -28
- package/dist/Time/index.d.mts.map +1 -1
- package/dist/Time/index.mjs +13 -17
- package/dist/Time/index.mjs.map +1 -1
- package/dist/helpers/index.d.mts +0 -6
- package/dist/helpers/index.d.mts.map +1 -1
- package/dist/helpers/index.mjs +3 -6
- package/dist/helpers/index.mjs.map +1 -1
- package/dist/hooks/useClientValidation/index.d.mts +0 -2
- package/dist/hooks/useClientValidation/index.d.mts.map +1 -1
- package/dist/hooks/useClientValidation/index.mjs +3 -5
- package/dist/hooks/useController/index.d.mts +0 -2
- package/dist/hooks/useController/index.d.mts.map +1 -1
- package/dist/hooks/useController/index.mjs +2 -3
- package/dist/hooks/useFormContext/index.d.mts +31 -52
- package/dist/hooks/useFormContext/index.d.mts.map +1 -1
- package/dist/hooks/useFormContext/index.mjs +2 -3
- package/dist/hooks/useInputValueDebounce/index.d.mts +0 -2
- package/dist/hooks/useInputValueDebounce/index.d.mts.map +1 -1
- package/dist/hooks/useInputValueDebounce/index.mjs +3 -5
- package/dist/hooks/useInputValueTransform/index.d.mts +1 -1
- package/dist/hooks/useInputValueTransform/index.mjs +2 -3
- package/dist/hooks/useWatchFormReset/index.d.mts +0 -2
- package/dist/hooks/useWatchFormReset/index.d.mts.map +1 -1
- package/dist/hooks/useWatchFormReset/index.mjs +3 -5
- package/dist/hooks/useWatchUserChange/index.d.mts +0 -2
- package/dist/hooks/useWatchUserChange/index.d.mts.map +1 -1
- package/dist/hooks/useWatchUserChange/index.mjs +3 -5
- package/dist/{index-BS8IoBOn.d.mts → index-cevZBrIN.d.mts} +1 -3
- package/dist/index-cevZBrIN.d.mts.map +1 -0
- package/dist/partials/FieldCopyTestIdButton/index.d.mts +0 -2
- package/dist/partials/FieldCopyTestIdButton/index.d.mts.map +1 -1
- package/dist/partials/FieldCopyTestIdButton/index.mjs +1 -1
- package/dist/partials/FieldValidationError/index.d.mts +11 -13
- package/dist/partials/FieldValidationError/index.d.mts.map +1 -1
- package/dist/partials/FieldValidationError/index.mjs +1 -1
- package/dist/{radioControlVariants-Cm6WufWo.mjs → radioControlVariants-BYRfaD6y.mjs} +24 -25
- package/dist/radioControlVariants-BYRfaD6y.mjs.map +1 -0
- package/dist/{switchVariants-BaQw2DA7.mjs → switchVariants-D16b2VaT.mjs} +4 -4
- package/dist/{switchVariants-BaQw2DA7.mjs.map → switchVariants-D16b2VaT.mjs.map} +1 -1
- package/dist/{timeVariants-B9HDfNYt.mjs → timeVariants-CtXyNKmW.mjs} +3 -3
- package/dist/{timeVariants-B9HDfNYt.mjs.map → timeVariants-CtXyNKmW.mjs.map} +1 -1
- package/dist/{useController-BCFeZbBZ.mjs → useController-JtIeurpw.mjs} +3 -4
- package/dist/{useController-BCFeZbBZ.mjs.map → useController-JtIeurpw.mjs.map} +1 -1
- package/dist/{useFormContext-BPjJjNnM.mjs → useFormContext-piqnN2L-.mjs} +3 -4
- package/dist/useFormContext-piqnN2L-.mjs.map +1 -0
- package/dist/{useInputValueTransform-Mw8YEOXT.mjs → useInputValueTransform-CXWWFhy_.mjs} +2 -3
- package/dist/{useInputValueTransform-Mw8YEOXT.mjs.map → useInputValueTransform-CXWWFhy_.mjs.map} +1 -1
- package/package.json +8 -7
- package/dist/FieldDescription-C4l0HKGL.mjs.map +0 -1
- package/dist/FieldLabel-DKzqkuY1.mjs.map +0 -1
- package/dist/FormContext-CsFiNvuJ.d.mts +0 -19
- package/dist/FormContext-CsFiNvuJ.d.mts.map +0 -1
- package/dist/index-BS8IoBOn.d.mts.map +0 -1
- package/dist/radioControlVariants-Cm6WufWo.mjs.map +0 -1
- package/dist/useFormContext-BPjJjNnM.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/FieldCard/fieldCardValidation.ts","../../src/FieldCard/hooks/useFieldCardValidation.ts","../../src/FieldCard/fieldCardVariants.ts","../../src/FieldCard/subcomponents/fieldCardValidationErrorVariants.ts","../../src/FieldCard/subcomponents/FieldCardValidationError.tsx","../../src/FieldCard/subcomponents/FieldCardControl.tsx","../../src/FieldCard/FieldCard.tsx","../../src/FieldCard/index.ts"],"sourcesContent":["/**\n * Recursively checks if any child field has an error (regardless of touched state).\n * Returns true if at least one child has an error.\n */\nexport const hasAnyChildErrors = (\n errors: Record<string, unknown> | undefined,\n): boolean => {\n if (!errors) {\n return false;\n }\n\n return Object.keys(errors)\n .filter((key) => {\n return key !== '_errors';\n })\n .some((key) => {\n const errorValue = errors[key];\n if (errorValue === undefined) {\n return false;\n }\n // If errorValue is an array, it's a leaf field error\n if (Array.isArray(errorValue)) {\n return true;\n }\n // Recursively check nested objects\n if (typeof errorValue === 'object' && errorValue !== null) {\n return hasAnyChildErrors(errorValue as Record<string, unknown>);\n }\n return false;\n });\n};\n\n/**\n * Recursively checks if any child field is touched.\n * Returns true if at least one child is touched.\n */\nexport const hasAnyChildTouched = (\n touched: Record<string, unknown> | undefined,\n): boolean => {\n if (!touched) {\n return false;\n }\n\n return Object.keys(touched)\n .filter((key) => {\n return key !== '_errors';\n })\n .some((key) => {\n const touchedValue = touched[key];\n if (touchedValue === undefined) {\n return false;\n }\n // If touchedValue is truthy (boolean true), field is touched\n if (touchedValue === true) {\n return true;\n }\n // Recursively check nested objects\n if (typeof touchedValue === 'object' && touchedValue !== null) {\n return hasAnyChildTouched(touchedValue as Record<string, unknown>);\n }\n return false;\n });\n};\n\n/**\n * Recursively checks if any child field with an error is also touched.\n * Returns true if at least one touched child has an error.\n */\nexport const hasVisibleChildErrors = (\n errors: Record<string, unknown> | undefined,\n touched: Record<string, unknown> | undefined,\n): boolean => {\n if (!errors || !touched) {\n return false;\n }\n\n return Object.keys(errors)\n .filter((key) => {\n // Skip object-level errors (_errors) - those are handled separately\n return key !== '_errors';\n })\n .some((key) => {\n const errorValue = errors[key];\n const touchedValue = touched[key];\n\n // If this key doesn't exist in both errors and touched, skip\n if (errorValue === undefined || touchedValue === undefined) {\n return false;\n }\n\n // If errorValue is an array, it's a leaf field error\n if (Array.isArray(errorValue)) {\n // touchedValue being truthy means the field is touched\n return !!touchedValue;\n }\n\n // Recursively check nested objects\n if (typeof errorValue === 'object' && errorValue !== null) {\n return hasVisibleChildErrors(\n errorValue as Record<string, unknown>,\n touchedValue as Record<string, unknown>,\n );\n }\n\n return false;\n });\n};\n\n/** Reads nested child touched state for a dotted field path */\nexport const getNestedValue = (\n obj: Record<string, unknown> | undefined,\n path: string,\n): Record<string, unknown> | undefined => {\n if (!obj) {\n return undefined;\n }\n const keys = path.split('.');\n let current: unknown = obj;\n keys.every((key) => {\n if (current && typeof current === 'object') {\n current = (current as Record<string, unknown>)[key];\n return true;\n }\n current = undefined;\n return false;\n });\n return current as Record<string, unknown> | undefined;\n};\n","import type { UniformField } from '../../hooks/useUniformField/types';\n\nimport { useDebounce } from '@fuf-stack/pixels';\n\nimport {\n checkFieldIsRequired,\n useFormContext,\n} from '../../hooks/useFormContext';\nimport {\n getNestedValue,\n hasAnyChildErrors,\n hasAnyChildTouched,\n hasVisibleChildErrors,\n} from '../fieldCardValidation';\n\n/**\n * Derives the card's required and invalid states from its nested fields\n *\n * A card groups independently registered inputs, so its own field state does\n * not tell us whether a child is required or which child errors are visible\n * Required state comes from registered descendants and their validation schema\n *\n * Child errors become visible after that child is touched or the form is submitted\n * Object-level errors follow child interaction or submission when no child errors\n * exist, so they do not reveal untouched child failures early\n *\n * Debounces invalid-state changes to prevent flickering during validation updates\n */\nconst useFieldCardValidation = (\n field: Pick<UniformField, 'error' | 'name'>,\n) => {\n const { error, name } = field;\n\n const {\n control,\n formState: { touchedFields, submitCount },\n validation,\n } = useFormContext();\n\n // inspect registered children for required fields\n const validationInstance = validation?.baseInstance ?? validation?.instance;\n const registeredFields: string[] = Array.from(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (control as any)._names?.mount ?? [],\n );\n const childFieldPrefix = `${name}.`;\n const isRequired = validationInstance\n ? registeredFields\n .filter((f) => {\n return f.startsWith(childFieldPrefix);\n })\n .some((f) => {\n return checkFieldIsRequired(\n validationInstance,\n f.split('.').filter((k) => {\n return k !== '';\n }),\n );\n })\n : false;\n\n // resolve touched state for nested children\n const fieldTouched = getNestedValue(touchedFields, name);\n\n // retain object-level errors alongside child errors\n // @ts-expect-error - error._errors exists but not typed\n const hasObjectErrors = !!error?._errors;\n\n const errorRecord = error as unknown as Record<string, unknown>;\n\n const hasChildErrors = hasAnyChildErrors(errorRecord);\n const isAnyChildTouched = hasAnyChildTouched(fieldTouched);\n\n // reveal child errors after interaction or submission\n const rawShowInvalid =\n (hasChildErrors &&\n (hasVisibleChildErrors(errorRecord, fieldTouched) || submitCount > 0)) ||\n (hasObjectErrors &&\n !hasChildErrors &&\n (isAnyChildTouched || submitCount > 0));\n\n // prevent flickering during rapid validation updates\n const showInvalid = useDebounce(rawShowInvalid, 200);\n\n return { invalid: showInvalid, required: isRequired };\n};\n\nexport default useFieldCardValidation;\n","import type { TVClassName } from '@fuf-stack/pixel-utils';\n\nimport { tv } from '@fuf-stack/pixel-utils';\n\nexport const fieldCardVariants = tv({\n slots: {\n /** base class for the field card wrapper */\n base: [\n // base styles\n 'overflow-hidden rounded-small border bg-content1',\n // animate border color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the content */\n content: [\n // same as p-3 of Card component\n 'p-3',\n // default grid for form components (see Grid component)\n 'grid gap-4',\n ],\n /** class for the error footer wrapper */\n errorFooter: [\n 'border-t',\n // force helper to be visible and add padding (pt-1 to compensate for inner content's top padding)\n 'block px-3 pb-2 pt-1',\n // animate border color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the error text (empty base, color controlled by variant) */\n errorText: [],\n /** class for the label/header */\n label: [\n // keep the label in normal flow at full width\n 'pointer-events-auto! static! z-auto! block! w-full!',\n // reset any transforms or translations\n 'translate-x-0! translate-y-0! transform-none!',\n // card header styling - use text-medium (16px) for proper header size\n 'rounded-t-small border-b p-3 font-semibold text-medium',\n // animate border and text color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n },\n variants: {\n invalid: {\n false: {\n base: 'border-divider',\n errorFooter: 'border-divider',\n errorText: '!text-foreground-500 text-tiny',\n label: 'border-divider text-foreground',\n },\n true: {\n base: 'border-danger-200',\n errorFooter: 'border-danger-200',\n errorText: '!text-danger text-tiny',\n label: 'border-danger-200 text-danger',\n },\n },\n },\n defaultVariants: {\n invalid: false,\n },\n});\n\nexport type ClassName = TVClassName<typeof fieldCardVariants>;\n","import { tv } from '@fuf-stack/pixel-utils';\n\nconst fieldCardValidationErrorVariants = tv({\n slots: {\n /** Container for card-level validation messages */\n errorMessage: 'text-danger text-tiny',\n /** Footer containing card-level validation */\n helperWrapper: 'relative flex flex-col gap-1.5 p-0',\n },\n});\n\nexport default fieldCardValidationErrorVariants;\n","import type { FieldError } from 'react-hook-form';\n\nimport {\n AnimatePresence,\n motion,\n useReducedMotion,\n} from '@fuf-stack/pixel-motion';\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport FieldValidationError from '../../partials/FieldValidationError/FieldValidationError';\nimport fieldCardValidationErrorVariants from './fieldCardValidationErrorVariants';\n\nexport interface FieldCardValidationErrorProps {\n /** CSS class name */\n className?: string;\n /** Error object from parent FieldCard (passed directly to avoid duplicate hook calls) */\n error?: FieldError[] | undefined;\n /** Optional error association ID supplied by the owning group. */\n errorId: string;\n /** CSS class name for the error text (controls color based on invalid state) */\n errorTextClassName?: string;\n /** HTML data-testid attribute for e2e tests */\n testId: string;\n}\n\n/**\n * Renders validation errors in the footer of a FieldCard component.\n *\n * This component handles displaying field-level validation errors with proper\n * accessibility attributes and animates them in/out using Framer Motion.\n *\n * Note: Object-level errors (_errors) are always shown when they exist,\n * but the danger styling is controlled by the parent FieldCard based on\n * whether child fields have been touched.\n */\nconst FieldCardValidationError = ({\n className = undefined,\n error = undefined,\n errorTextClassName = undefined,\n errorId,\n testId,\n}: FieldCardValidationErrorProps) => {\n const styling = useStyling();\n const disableAnimation = useReducedMotion();\n\n // classNames from slots\n const variants = styling.resolve(fieldCardValidationErrorVariants);\n const classNames = styling.variantsToClassNames(variants, {\n errorMessage: errorTextClassName,\n helperWrapper: className,\n });\n\n // show object-level errors whenever they exist\n const objectErrors = (error as unknown as { _errors?: FieldError[] })\n ?._errors;\n const hasErrors = !!objectErrors;\n\n return (\n <AnimatePresence initial={!disableAnimation}>\n {hasErrors ? (\n <motion.div\n key=\"field-card-errors\"\n animate={\n disableAnimation ? undefined : { opacity: 1, height: 'auto' }\n }\n exit={disableAnimation ? undefined : { opacity: 0, height: 0 }}\n initial={disableAnimation ? false : { height: 0, opacity: 0 }}\n style={{ overflow: 'hidden' }}\n transition={{ duration: 0.4, ease: 'circOut' }}\n >\n <div className={classNames.helperWrapper} data-slot=\"helper-wrapper\">\n <FieldValidationError\n className={{ wrapper: classNames.errorMessage }}\n error={objectErrors}\n id={errorId}\n testId={testId}\n />\n </div>\n </motion.div>\n ) : null}\n </AnimatePresence>\n );\n};\n\nexport default FieldCardValidationError;\n","import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { FieldCardProps } from '../FieldCard';\n\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport FieldLabel from '../../partials/FieldLabel/FieldLabel';\nimport { fieldCardVariants } from '../fieldCardVariants';\nimport FieldCardValidationError from './FieldCardValidationError';\n\ninterface FieldCardControlProps extends Pick<\n FieldCardProps,\n 'children' | 'className'\n> {\n /** Bound field values, interactions and metadata */\n field: UniformField;\n}\n\n/** Card presentation with an accessible heading, content and animated error footer */\nconst FieldCardControl = ({\n field,\n children,\n className,\n}: FieldCardControlProps) => {\n const { ariaLabel, error, ids, invalid, label, required, testId } = field;\n\n const styling = useStyling();\n\n // @ts-expect-error - object-level errors include an _errors property\n const hasObjectErrors = !!error?._errors;\n\n // classNames from slots\n const variants = styling.resolve(fieldCardVariants, { invalid });\n const classNames = styling.variantsToClassNames(variants, className, 'base');\n\n return (\n <div\n aria-describedby={hasObjectErrors ? ids.error : undefined}\n aria-label={!label ? ariaLabel : undefined}\n aria-labelledby={label ? ids.label : undefined}\n className={classNames.base}\n data-component=\"field-card\"\n role=\"group\"\n >\n {/* card header with label */}\n {label ? (\n <FieldLabel\n aria-level={3}\n as=\"div\"\n className={classNames.label}\n id={ids.label}\n required={required}\n role=\"heading\"\n >\n {label}\n </FieldLabel>\n ) : null}\n\n {/* card content */}\n <div className={classNames.content}>{children}</div>\n\n {/* card footer with object-level validation messages */}\n <FieldCardValidationError\n className={classNames.errorFooter}\n error={error}\n errorId={ids.error}\n errorTextClassName={classNames.errorText}\n testId={testId}\n />\n </div>\n );\n};\n\nexport default FieldCardControl;\n","import type { ReactNode } from 'react';\nimport type { ClassName } from './fieldCardVariants';\n\nimport useUniformField from '../hooks/useUniformField/useUniformField';\nimport useFieldCardValidation from './hooks/useFieldCardValidation';\nimport FieldCardControl from './subcomponents/FieldCardControl';\n\nexport { fieldCardVariants } from './fieldCardVariants';\nexport {\n hasAnyChildErrors,\n hasAnyChildTouched,\n hasVisibleChildErrors,\n} from './fieldCardValidation';\n\nexport interface FieldCardProps {\n /** Content to render inside the card */\n children: ReactNode;\n /** CSS class name */\n className?: ClassName;\n /** Field label */\n label: ReactNode;\n /** Field name */\n name: string;\n /** HTML data-testid attribute for e2e tests */\n testId?: string;\n}\n\n/**\n * Groups related form fields in a card with a heading and validation footer\n *\n * Renders nested fields in the body and object-level validation messages in the\n * footer. Individual fields retain their own validation messages\n *\n * The card's required indicator reflects its nested fields, and its danger\n * outline follows child interaction and form submission\n */\nconst FieldCard = ({\n children,\n className: _className = undefined,\n name,\n ...uniformFieldProps\n}: FieldCardProps) => {\n const { field } = useUniformField({\n ...uniformFieldProps,\n name,\n });\n\n const validation = useFieldCardValidation(field);\n\n return (\n <FieldCardControl\n className={_className}\n field={{ ...field, ...validation }}\n >\n {children}\n </FieldCardControl>\n );\n};\n\nexport default FieldCard;\n","import FieldCard from './FieldCard';\n\nexport type { FieldCardProps } from './FieldCard';\n\nexport { fieldCardVariants } from './FieldCard';\n\nexport default FieldCard;\n"],"mappings":";;;;;;;;;;;;;AAIA,MAAa,qBACX,WACY;CACZ,IAAI,CAAC,QACH,OAAO;CAGT,OAAO,OAAO,KAAK,MAAM,CAAC,CACvB,QAAQ,QAAQ;EACf,OAAO,QAAQ;CACjB,CAAC,CAAC,CACD,MAAM,QAAQ;EACb,MAAM,aAAa,OAAO;EAC1B,IAAI,eAAe,KAAA,GACjB,OAAO;EAGT,IAAI,MAAM,QAAQ,UAAU,GAC1B,OAAO;EAGT,IAAI,OAAO,eAAe,YAAY,eAAe,MACnD,OAAO,kBAAkB,UAAqC;EAEhE,OAAO;CACT,CAAC;AACL;;;;;AAMA,MAAa,sBACX,YACY;CACZ,IAAI,CAAC,SACH,OAAO;CAGT,OAAO,OAAO,KAAK,OAAO,CAAC,CACxB,QAAQ,QAAQ;EACf,OAAO,QAAQ;CACjB,CAAC,CAAC,CACD,MAAM,QAAQ;EACb,MAAM,eAAe,Q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AAD;IAAK,WAAW,WAAW;IAAU;GAAc,CAAA;GAGnD,oBAAC,0BAAD;IACE,WAAW,WAAW;IACf;IACP,SAAS,IAAI;IACb,oBAAoB,WAAW;IACvB;GACT,CAAA;EACE;;AAET;;;;;;;;;;;;AClCA,MAAM,aAAa,EACjB,UACA,WAAW,aAAa,KAAA,GACxB,MACA,GAAG,wBACiB;CACpB,MAAM,EAAE,UAAU,gBAAgB;EAChC,GAAG;EACH;CACF,CAAC;CAED,MAAM,aAAa,uBAAuB,KAAK;CAE/C,OACE,oBAAC,kBAAD;EACE,WAAW;EACX,OAAO;GAAE,GAAG;GAAO,GAAG;EAAW;EAEhC;CACe,CAAA;AAEtB;;;ACnDA,IAAA,oBAAe"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/FieldCard/fieldCardValidation.ts","../../src/FieldCard/hooks/useFieldCardValidation.ts","../../src/FieldCard/fieldCardVariants.ts","../../src/FieldCard/subcomponents/fieldCardValidationErrorVariants.ts","../../src/FieldCard/subcomponents/FieldCardValidationError.tsx","../../src/FieldCard/subcomponents/FieldCardControl.tsx","../../src/FieldCard/FieldCard.tsx","../../src/FieldCard/index.ts"],"sourcesContent":["/**\n * Recursively checks if any child field has an error (regardless of touched state).\n * Returns true if at least one child has an error.\n */\nexport const hasAnyChildErrors = (\n errors: Record<string, unknown> | undefined,\n): boolean => {\n if (!errors) {\n return false;\n }\n\n return Object.keys(errors)\n .filter((key) => {\n return key !== '_errors';\n })\n .some((key) => {\n const errorValue = errors[key];\n if (errorValue === undefined) {\n return false;\n }\n // If errorValue is an array, it's a leaf field error\n if (Array.isArray(errorValue)) {\n return true;\n }\n // Recursively check nested objects\n if (typeof errorValue === 'object' && errorValue !== null) {\n return hasAnyChildErrors(errorValue as Record<string, unknown>);\n }\n return false;\n });\n};\n\n/**\n * Recursively checks if any child field is touched.\n * Returns true if at least one child is touched.\n */\nexport const hasAnyChildTouched = (\n touched: Record<string, unknown> | undefined,\n): boolean => {\n if (!touched) {\n return false;\n }\n\n return Object.keys(touched)\n .filter((key) => {\n return key !== '_errors';\n })\n .some((key) => {\n const touchedValue = touched[key];\n if (touchedValue === undefined) {\n return false;\n }\n // If touchedValue is truthy (boolean true), field is touched\n if (touchedValue === true) {\n return true;\n }\n // Recursively check nested objects\n if (typeof touchedValue === 'object' && touchedValue !== null) {\n return hasAnyChildTouched(touchedValue as Record<string, unknown>);\n }\n return false;\n });\n};\n\n/**\n * Recursively checks if any child field with an error is also touched.\n * Returns true if at least one touched child has an error.\n */\nexport const hasVisibleChildErrors = (\n errors: Record<string, unknown> | undefined,\n touched: Record<string, unknown> | undefined,\n): boolean => {\n if (!errors || !touched) {\n return false;\n }\n\n return Object.keys(errors)\n .filter((key) => {\n // Skip object-level errors (_errors) - those are handled separately\n return key !== '_errors';\n })\n .some((key) => {\n const errorValue = errors[key];\n const touchedValue = touched[key];\n\n // If this key doesn't exist in both errors and touched, skip\n if (errorValue === undefined || touchedValue === undefined) {\n return false;\n }\n\n // If errorValue is an array, it's a leaf field error\n if (Array.isArray(errorValue)) {\n // touchedValue being truthy means the field is touched\n return !!touchedValue;\n }\n\n // Recursively check nested objects\n if (typeof errorValue === 'object' && errorValue !== null) {\n return hasVisibleChildErrors(\n errorValue as Record<string, unknown>,\n touchedValue as Record<string, unknown>,\n );\n }\n\n return false;\n });\n};\n\n/** Reads nested child touched state for a dotted field path */\nexport const getNestedValue = (\n obj: Record<string, unknown> | undefined,\n path: string,\n): Record<string, unknown> | undefined => {\n if (!obj) {\n return undefined;\n }\n const keys = path.split('.');\n let current: unknown = obj;\n keys.every((key) => {\n if (current && typeof current === 'object') {\n current = (current as Record<string, unknown>)[key];\n return true;\n }\n current = undefined;\n return false;\n });\n return current as Record<string, unknown> | undefined;\n};\n","import type { UniformField } from '../../hooks/useUniformField/types';\n\nimport { useDebounce } from '@fuf-stack/pixels';\n\nimport {\n checkFieldIsRequired,\n useFormContext,\n} from '../../hooks/useFormContext';\nimport {\n getNestedValue,\n hasAnyChildErrors,\n hasAnyChildTouched,\n hasVisibleChildErrors,\n} from '../fieldCardValidation';\n\n/**\n * Derives the card's required and invalid states from its nested fields\n *\n * A card groups independently registered inputs, so its own field state does\n * not tell us whether a child is required or which child errors are visible\n * Required state comes from registered descendants and their validation schema\n *\n * Child errors become visible after that child is touched or the form is submitted\n * Object-level errors follow child interaction or submission when no child errors\n * exist, so they do not reveal untouched child failures early\n *\n * Debounces invalid-state changes to prevent flickering during validation updates\n */\nconst useFieldCardValidation = (\n field: Pick<UniformField, 'error' | 'name'>,\n) => {\n const { error, name } = field;\n\n const {\n control,\n formState: { touchedFields, submitCount },\n validation,\n } = useFormContext();\n\n // inspect registered children for required fields\n const validationInstance = validation?.baseInstance ?? validation?.instance;\n const registeredFields: string[] = Array.from(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (control as any)._names?.mount ?? [],\n );\n const childFieldPrefix = `${name}.`;\n const isRequired = validationInstance\n ? registeredFields\n .filter((f) => {\n return f.startsWith(childFieldPrefix);\n })\n .some((f) => {\n return checkFieldIsRequired(\n validationInstance,\n f.split('.').filter((k) => {\n return k !== '';\n }),\n );\n })\n : false;\n\n // resolve touched state for nested children\n const fieldTouched = getNestedValue(touchedFields, name);\n\n // retain object-level errors alongside child errors\n // @ts-expect-error - error._errors exists but not typed\n const hasObjectErrors = !!error?._errors;\n\n const errorRecord = error as unknown as Record<string, unknown>;\n\n const hasChildErrors = hasAnyChildErrors(errorRecord);\n const isAnyChildTouched = hasAnyChildTouched(fieldTouched);\n\n // reveal child errors after interaction or submission\n const rawShowInvalid =\n (hasChildErrors &&\n (hasVisibleChildErrors(errorRecord, fieldTouched) || submitCount > 0)) ||\n (hasObjectErrors &&\n !hasChildErrors &&\n (isAnyChildTouched || submitCount > 0));\n\n // prevent flickering during rapid validation updates\n const showInvalid = useDebounce(rawShowInvalid, 200);\n\n return { invalid: showInvalid, required: isRequired };\n};\n\nexport default useFieldCardValidation;\n","import type { TVClassName } from '@fuf-stack/pixel-utils';\n\nimport { tv } from '@fuf-stack/pixel-utils';\n\nexport const fieldCardVariants = tv({\n slots: {\n /** base class for the field card wrapper */\n base: [\n // base styles\n 'overflow-hidden rounded-small border bg-content1',\n // animate border color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the content */\n content: [\n // same as p-3 of Card component\n 'p-3',\n // default grid for form components (see Grid component)\n 'grid gap-4',\n ],\n /** class for the error footer wrapper */\n errorFooter: [\n 'border-t',\n // force helper to be visible and add padding (pt-1 to compensate for inner content's top padding)\n 'block px-3 pb-2 pt-1',\n // animate border color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the error text (empty base, color controlled by variant) */\n errorText: [],\n /** class for the label/header */\n label: [\n // keep the label in normal flow at full width\n 'pointer-events-auto! static! z-auto! block! w-full!',\n // reset any transforms or translations\n 'translate-x-0! translate-y-0! transform-none!',\n // card header styling - use text-medium (16px) for proper header size\n 'rounded-t-small border-b p-3 font-semibold text-medium',\n // animate border and text color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n },\n variants: {\n invalid: {\n false: {\n base: 'border-divider',\n errorFooter: 'border-divider',\n errorText: '!text-foreground-500 text-tiny',\n label: 'border-divider text-foreground',\n },\n true: {\n base: 'border-danger-200',\n errorFooter: 'border-danger-200',\n errorText: '!text-danger text-tiny',\n label: 'border-danger-200 text-danger',\n },\n },\n },\n defaultVariants: {\n invalid: false,\n },\n});\n\nexport type ClassName = TVClassName<typeof fieldCardVariants>;\n","import { tv } from '@fuf-stack/pixel-utils';\n\nconst fieldCardValidationErrorVariants = tv({\n slots: {\n /** Container for card-level validation messages */\n errorMessage: 'text-danger text-tiny',\n /** Footer containing card-level validation */\n helperWrapper: 'relative flex flex-col gap-1.5 p-0',\n },\n});\n\nexport default fieldCardValidationErrorVariants;\n","import type { FieldError } from 'react-hook-form';\n\nimport {\n AnimatePresence,\n motion,\n useReducedMotion,\n} from '@fuf-stack/pixel-motion';\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport FieldValidationError from '../../partials/FieldValidationError/FieldValidationError';\nimport fieldCardValidationErrorVariants from './fieldCardValidationErrorVariants';\n\nexport interface FieldCardValidationErrorProps {\n /** CSS class name */\n className?: string;\n /** Error object from parent FieldCard (passed directly to avoid duplicate hook calls) */\n error?: FieldError[] | undefined;\n /** Optional error association ID supplied by the owning group. */\n errorId: string;\n /** CSS class name for the error text (controls color based on invalid state) */\n errorTextClassName?: string;\n /** HTML data-testid attribute for e2e tests */\n testId: string;\n}\n\n/**\n * Renders validation errors in the footer of a FieldCard component.\n *\n * This component handles displaying field-level validation errors with proper\n * accessibility attributes and animates them in/out using Framer Motion.\n *\n * Note: Object-level errors (_errors) are always shown when they exist,\n * but the danger styling is controlled by the parent FieldCard based on\n * whether child fields have been touched.\n */\nconst FieldCardValidationError = ({\n className = undefined,\n error = undefined,\n errorTextClassName = undefined,\n errorId,\n testId,\n}: FieldCardValidationErrorProps) => {\n const styling = useStyling();\n const disableAnimation = useReducedMotion();\n\n // classNames from slots\n const variants = styling.resolve(fieldCardValidationErrorVariants);\n const classNames = styling.variantsToClassNames(variants, {\n errorMessage: errorTextClassName,\n helperWrapper: className,\n });\n\n // show object-level errors whenever they exist\n const objectErrors = (error as unknown as { _errors?: FieldError[] })\n ?._errors;\n const hasErrors = !!objectErrors;\n\n return (\n <AnimatePresence initial={!disableAnimation}>\n {hasErrors ? (\n <motion.div\n key=\"field-card-errors\"\n animate={\n disableAnimation ? undefined : { opacity: 1, height: 'auto' }\n }\n exit={disableAnimation ? undefined : { opacity: 0, height: 0 }}\n initial={disableAnimation ? false : { height: 0, opacity: 0 }}\n style={{ overflow: 'hidden' }}\n transition={{ duration: 0.4, ease: 'circOut' }}\n >\n <div className={classNames.helperWrapper} data-slot=\"helper-wrapper\">\n <FieldValidationError\n className={{ wrapper: classNames.errorMessage }}\n error={objectErrors}\n id={errorId}\n testId={testId}\n />\n </div>\n </motion.div>\n ) : null}\n </AnimatePresence>\n );\n};\n\nexport default FieldCardValidationError;\n","import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { FieldCardProps } from '../FieldCard';\n\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport FieldLabel from '../../partials/FieldLabel/FieldLabel';\nimport { fieldCardVariants } from '../fieldCardVariants';\nimport FieldCardValidationError from './FieldCardValidationError';\n\ninterface FieldCardControlProps extends Pick<\n FieldCardProps,\n 'children' | 'className'\n> {\n /** Bound field values, interactions and metadata */\n field: UniformField;\n}\n\n/** Card presentation with an accessible heading, content and animated error footer */\nconst FieldCardControl = ({\n field,\n children,\n className,\n}: FieldCardControlProps) => {\n const { ariaLabel, error, ids, invalid, label, required, testId } = field;\n\n const styling = useStyling();\n\n // @ts-expect-error - object-level errors include an _errors property\n const hasObjectErrors = !!error?._errors;\n\n // classNames from slots\n const variants = styling.resolve(fieldCardVariants, { invalid });\n const classNames = styling.variantsToClassNames(variants, className, 'base');\n\n return (\n <div\n aria-describedby={hasObjectErrors ? ids.error : undefined}\n aria-label={!label ? ariaLabel : undefined}\n aria-labelledby={label ? ids.label : undefined}\n className={classNames.base}\n data-component=\"field-card\"\n role=\"group\"\n >\n {/* card header with label */}\n {label ? (\n <FieldLabel\n aria-level={3}\n as=\"div\"\n className={classNames.label}\n id={ids.label}\n required={required}\n role=\"heading\"\n >\n {label}\n </FieldLabel>\n ) : null}\n\n {/* card content */}\n <div className={classNames.content}>{children}</div>\n\n {/* card footer with object-level validation messages */}\n <FieldCardValidationError\n className={classNames.errorFooter}\n error={error}\n errorId={ids.error}\n errorTextClassName={classNames.errorText}\n testId={testId}\n />\n </div>\n );\n};\n\nexport default FieldCardControl;\n","import type { ReactNode } from 'react';\nimport type { ClassName } from './fieldCardVariants';\n\nimport useUniformField from '../hooks/useUniformField/useUniformField';\nimport useFieldCardValidation from './hooks/useFieldCardValidation';\nimport FieldCardControl from './subcomponents/FieldCardControl';\n\nexport { fieldCardVariants } from './fieldCardVariants';\nexport {\n hasAnyChildErrors,\n hasAnyChildTouched,\n hasVisibleChildErrors,\n} from './fieldCardValidation';\n\nexport interface FieldCardProps {\n /** Content to render inside the card */\n children: ReactNode;\n /** CSS class name */\n className?: ClassName;\n /** Field label */\n label: ReactNode;\n /** Field name */\n name: string;\n /** HTML data-testid attribute for e2e tests */\n testId?: string;\n}\n\n/**\n * Groups related form fields in a card with a heading and validation footer\n *\n * Renders nested fields in the body and object-level validation messages in the\n * footer. Individual fields retain their own validation messages\n *\n * The card's required indicator reflects its nested fields, and its danger\n * outline follows child interaction and form submission\n */\nconst FieldCard = ({\n children,\n className: _className = undefined,\n name,\n ...uniformFieldProps\n}: FieldCardProps) => {\n const { field } = useUniformField({\n ...uniformFieldProps,\n name,\n });\n\n const validation = useFieldCardValidation(field);\n\n return (\n <FieldCardControl\n className={_className}\n field={{ ...field, ...validation }}\n >\n {children}\n </FieldCardControl>\n );\n};\n\nexport default FieldCard;\n","import FieldCard from './FieldCard';\n\nexport type { FieldCardProps } from './FieldCard';\n\nexport { fieldCardVariants } from './FieldCard';\n\nexport default FieldCard;\n"],"mappings":";;;;;;;;;;;;;AAIA,MAAa,qBACX,WACY;CACZ,IAAI,CAAC,QACH,OAAO;CAGT,OAAO,OAAO,KAAK,MAAM,CAAC,CACvB,QAAQ,QAAQ;EACf,OAAO,QAAQ;CACjB,CAAC,CAAC,CACD,MAAM,QAAQ;EACb,MAAM,aAAa,OAAO;EAC1B,IAAI,eAAe,KAAA,GACjB,OAAO;EAGT,IAAI,MAAM,QAAQ,UAAU,GAC1B,OAAO;EAGT,IAAI,OAAO,eAAe,YAAY,eAAe,MACnD,OAAO,kBAAkB,UAAqC;EAEhE,OAAO;CACT,CAAC;AACL;;;;;AAMA,MAAa,sBACX,YACY;CACZ,IAAI,CAAC,SACH,OAAO;CAGT,OAAO,OAAO,KAAK,OAAO,CAAC,CACxB,QAAQ,QAAQ;EACf,OAAO,QAAQ;CACjB,CAAC,CAAC,CACD,MAAM,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ACV;GAGJ,oBAAC,OAAD;IAAK,WAAW,WAAW;IAAU;GAAc,CAAA;GAGnD,oBAAC,0BAAD;IACE,WAAW,WAAW;IACf;IACP,SAAS,IAAI;IACb,oBAAoB,WAAW;IACvB;GACT,CAAA;EACE;;AAET;;;;;;;;;;;AClCA,MAAM,aAAa,EACjB,UACA,WAAW,aAAa,KAAA,GACxB,MACA,GAAG,wBACiB;CACpB,MAAM,EAAE,UAAU,gBAAgB;EAChC,GAAG;EACH;CACF,CAAC;CAED,MAAM,aAAa,uBAAuB,KAAK;CAE/C,OACE,oBAAC,kBAAD;EACE,WAAW;EACX,OAAO;GAAE,GAAG;GAAO,GAAG;EAAW;EAEhC;CACe,CAAA;AAEtB;;ACnDA,IAAA,oBAAe"}
|
|
@@ -2,7 +2,7 @@ import { Button } from "@fuf-stack/pixels";
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { FaBullseye } from "react-icons/fa6";
|
|
4
4
|
import { useStyling } from "@fuf-stack/pixels/StylingProvider";
|
|
5
|
-
|
|
5
|
+
// src/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.tsx
|
|
6
6
|
const FieldCopyTestIdButton = ({ className = void 0, testId }) => {
|
|
7
7
|
const { cn } = useStyling();
|
|
8
8
|
const copyToClipboard = () => {
|
|
@@ -19,10 +19,8 @@ const FieldCopyTestIdButton = ({ className = void 0, testId }) => {
|
|
|
19
19
|
variant: "light"
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
//#region src/partials/FieldCopyTestIdButton/index.ts
|
|
22
|
+
// src/partials/FieldCopyTestIdButton/index.ts
|
|
24
23
|
var FieldCopyTestIdButton_default = FieldCopyTestIdButton;
|
|
25
|
-
//#endregion
|
|
26
24
|
export { FieldCopyTestIdButton_default as t };
|
|
27
25
|
|
|
28
|
-
//# sourceMappingURL=FieldCopyTestIdButton-
|
|
26
|
+
//# sourceMappingURL=FieldCopyTestIdButton-D3_jZYJ1.mjs.map
|
package/dist/{FieldCopyTestIdButton-DV0tkdh2.mjs.map → FieldCopyTestIdButton-D3_jZYJ1.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldCopyTestIdButton-
|
|
1
|
+
{"version":3,"file":"FieldCopyTestIdButton-D3_jZYJ1.mjs","names":[],"sources":["../src/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.tsx","../src/partials/FieldCopyTestIdButton/index.ts"],"sourcesContent":["import { FaBullseye } from 'react-icons/fa6';\n\nimport { Button } from '@fuf-stack/pixels';\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nexport interface FieldCopyTestIdButtonProps {\n /** CSS class name */\n className?: string;\n /** HTML data-testid attribute used in e2e tests */\n testId: string;\n}\n\nconst FieldCopyTestIdButton = ({\n className = undefined,\n testId,\n}: FieldCopyTestIdButtonProps) => {\n const { cn } = useStyling();\n const copyToClipboard = () => {\n // This component runs in the browser; the Node compatibility rule cannot\n // distinguish the DOM Clipboard API from Node's global navigator.\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n navigator.clipboard.writeText(testId).catch((err) => {\n console.error('Error copying TestId to clipboard', err);\n });\n };\n\n return (\n <Button\n className={cn(className, 'pointer-events-auto')}\n dataComponent=\"field-copy-test-id-button\"\n icon={<FaBullseye />}\n onClick={copyToClipboard}\n size=\"sm\"\n variant=\"light\"\n />\n );\n};\nexport default FieldCopyTestIdButton;\n","import FieldCopyTestIdButton from './FieldCopyTestIdButton';\n\nexport type { FieldCopyTestIdButtonProps } from './FieldCopyTestIdButton';\n\nexport default FieldCopyTestIdButton;\n"],"mappings":";;;;;AAYA,MAAM,yBAAyB,EAC7B,YAAY,KAAA,GACZ,aACgC;CAChC,MAAM,EAAE,OAAO,WAAW;CAC1B,MAAM,wBAAwB;EAI5B,UAAU,UAAU,UAAU,MAAM,CAAC,CAAC,OAAO,QAAQ;GACnD,QAAQ,MAAM,qCAAqC,GAAG;EACxD,CAAC;CACH;CAEA,OACE,oBAAC,QAAD;EACE,WAAW,GAAG,WAAW,qBAAqB;EAC9C,eAAc;EACd,MAAM,oBAAC,YAAD,CAAa,CAAA;EACnB,SAAS;EACT,MAAK;EACL,SAAQ;CACT,CAAA;AAEL;;AChCA,IAAA,gCAAe"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
|
|
2
|
+
// src/helpers/fieldProps/fieldProps.ts
|
|
3
3
|
/** Shared styling attributes for field state, inactive flags are omitted */
|
|
4
|
-
const getFieldDataAttributes = ({ disabled, invalid, required }) => {
|
|
4
|
+
const getFieldDataAttributes = ({ disabled, invalid, readOnly, required }) => {
|
|
5
5
|
return {
|
|
6
6
|
"data-disabled": disabled ? true : void 0,
|
|
7
7
|
"data-invalid": invalid ? true : void 0,
|
|
8
|
+
"data-readonly": readOnly ? true : void 0,
|
|
8
9
|
"data-required": required ? true : void 0
|
|
9
10
|
};
|
|
10
11
|
};
|
|
@@ -19,8 +20,7 @@ const getFieldControlProps = ({ ariaLabel, customAriaLabel, description, hasErro
|
|
|
19
20
|
"aria-required": required || void 0
|
|
20
21
|
};
|
|
21
22
|
};
|
|
22
|
-
|
|
23
|
-
//#region src/partials/FieldDescription/FieldDescription.tsx
|
|
23
|
+
// src/partials/FieldDescription/FieldDescription.tsx
|
|
24
24
|
/** Help text associated with a field through its description ID */
|
|
25
25
|
const FieldDescription = ({ children, ...props }) => {
|
|
26
26
|
if (!children) return null;
|
|
@@ -30,7 +30,6 @@ const FieldDescription = ({ children, ...props }) => {
|
|
|
30
30
|
children
|
|
31
31
|
});
|
|
32
32
|
};
|
|
33
|
-
//#endregion
|
|
34
33
|
export { getFieldControlProps as n, getFieldDataAttributes as r, FieldDescription as t };
|
|
35
34
|
|
|
36
|
-
//# sourceMappingURL=FieldDescription-
|
|
35
|
+
//# sourceMappingURL=FieldDescription-X_0s1Lhu.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldDescription-X_0s1Lhu.mjs","names":[],"sources":["../src/helpers/fieldProps/fieldProps.ts","../src/partials/FieldDescription/FieldDescription.tsx"],"sourcesContent":["import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { FieldControlProps } from '../../partials/types';\n\ninterface FieldDataState {\n /** Disables interaction with the field */\n disabled?: boolean;\n /** Marks visible validation failure */\n invalid?: boolean;\n /** Prevents changes to the field */\n readOnly?: boolean;\n /** Marks a required field */\n required?: boolean;\n}\n\n/** Shared styling attributes for field state, inactive flags are omitted */\nexport const getFieldDataAttributes = ({\n disabled,\n invalid,\n readOnly,\n required,\n}: FieldDataState) => {\n return {\n 'data-disabled': disabled ? true : undefined,\n 'data-invalid': invalid ? true : undefined,\n 'data-readonly': readOnly ? true : undefined,\n 'data-required': required ? true : undefined,\n };\n};\n\n/** Field metadata needed to associate an editable control with its content */\ntype FieldControlState = Pick<\n UniformField,\n | 'ariaLabel'\n | 'customAriaLabel'\n | 'description'\n | 'hasErrors'\n | 'hasLabel'\n | 'ids'\n | 'invalid'\n | 'required'\n>;\n\n/** ID and ARIA associations for the editable control or selection group */\nexport const getFieldControlProps = ({\n ariaLabel,\n customAriaLabel,\n description,\n hasErrors,\n hasLabel,\n ids,\n invalid,\n required,\n}: FieldControlState): FieldControlProps => {\n return {\n id: ids.control,\n 'aria-label': customAriaLabel ?? (!hasLabel ? ariaLabel : undefined),\n 'aria-labelledby': !customAriaLabel && hasLabel ? ids.label : undefined,\n 'aria-describedby':\n [\n description ? ids.description : undefined,\n invalid && hasErrors ? ids.error : undefined,\n ]\n .filter(Boolean)\n .join(' ') || undefined,\n 'aria-invalid': invalid || undefined,\n 'aria-required': required || undefined,\n };\n};\n","import type { HTMLAttributes, ReactNode } from 'react';\n\ninterface FieldDescriptionProps extends HTMLAttributes<HTMLDivElement> {\n /** Help text */\n children: ReactNode;\n /** CSS class name */\n className?: string;\n}\n\n/** Help text associated with a field through its description ID */\nconst FieldDescription = ({ children, ...props }: FieldDescriptionProps) => {\n if (!children) {\n return null;\n }\n\n return (\n <div data-slot=\"description\" {...props}>\n {children}\n </div>\n );\n};\n\nexport default FieldDescription;\n"],"mappings":";;;AAeA,MAAa,0BAA0B,EACrC,UACA,SACA,UACA,eACoB;CACpB,OAAO;EACL,iBAAiB,WAAW,OAAO,KAAA;EACnC,gBAAgB,UAAU,OAAO,KAAA;EACjC,iBAAiB,WAAW,OAAO,KAAA;EACnC,iBAAiB,WAAW,OAAO,KAAA;CACrC;AACF;;AAgBA,MAAa,wBAAwB,EACnC,WACA,iBACA,aACA,WACA,UACA,KACA,SACA,eAC0C;CAC1C,OAAO;EACL,IAAI,IAAI;EACR,cAAc,oBAAoB,CAAC,WAAW,YAAY,KAAA;EAC1D,mBAAmB,CAAC,mBAAmB,WAAW,IAAI,QAAQ,KAAA;EAC9D,oBACE,CACE,cAAc,IAAI,cAAc,KAAA,GAChC,WAAW,YAAY,IAAI,QAAQ,KAAA,CACrC,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,KAAK,KAAA;EAClB,gBAAgB,WAAW,KAAA;EAC3B,iBAAiB,YAAY,KAAA;CAC/B;AACF;;;ACzDA,MAAM,oBAAoB,EAAE,UAAU,GAAG,YAAmC;CAC1E,IAAI,CAAC,UACH,OAAO;CAGT,OACE,oBAAC,OAAD;EAAK,aAAU;EAAc,GAAI;EAC9B;CACE,CAAA;AAET"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { a as useSensitiveField } from "./FormContext-
|
|
1
|
+
import { a as useSensitiveField } from "./FormContext-PXkVlBdU.mjs";
|
|
2
2
|
import { flattenFieldErrors, isValueEmpty } from "./helpers/index.mjs";
|
|
3
|
-
import { t as FieldCopyTestIdButton_default } from "./FieldCopyTestIdButton-
|
|
4
|
-
import { t as FieldValidationError_default } from "./FieldValidationError-
|
|
5
|
-
import { t as useController } from "./useController-
|
|
6
|
-
import { n as useFormContext } from "./useFormContext-
|
|
7
|
-
import { t as useInputValueTransform } from "./useInputValueTransform-
|
|
3
|
+
import { t as FieldCopyTestIdButton_default } from "./FieldCopyTestIdButton-D3_jZYJ1.mjs";
|
|
4
|
+
import { t as FieldValidationError_default } from "./FieldValidationError-iAayfTEw.mjs";
|
|
5
|
+
import { t as useController } from "./useController-JtIeurpw.mjs";
|
|
6
|
+
import { n as useFormContext } from "./useFormContext-piqnN2L-.mjs";
|
|
7
|
+
import { t as useInputValueTransform } from "./useInputValueTransform-CXWWFhy_.mjs";
|
|
8
8
|
import React from "react";
|
|
9
9
|
import { useDebounce } from "@fuf-stack/pixels";
|
|
10
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
-
|
|
11
|
+
// src/hooks/useUniformField/useUniformField.tsx
|
|
12
12
|
/**
|
|
13
13
|
* Binds a form field's value, interactions, validation and label metadata
|
|
14
14
|
*
|
|
@@ -23,9 +23,13 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
23
23
|
* messages and label content, including the test ID action in debug mode
|
|
24
24
|
* Stable IDs and accessible-name metadata support associations in controls
|
|
25
25
|
* Form operations remain separate from the field bundle
|
|
26
|
+
*
|
|
27
|
+
* Only `disabled` reaches the form controller, so disabled values are omitted
|
|
28
|
+
* from validation and submission. Read-only fields stay registered, controls
|
|
29
|
+
* prevent changes while their value is still validated and submitted
|
|
26
30
|
*/
|
|
27
31
|
const useUniformField = (params) => {
|
|
28
|
-
const { name, ariaLabel: customAriaLabel, disabled = false, description, isArrayValue = false, testId: explicitTestId, label, placeholder, sensitive = false, type, transform } = params;
|
|
32
|
+
const { name, ariaLabel: customAriaLabel, disabled = false, description, isArrayValue = false, testId: explicitTestId, label, placeholder, readOnly = false, sensitive = false, type, transform } = params;
|
|
29
33
|
useSensitiveField(name, type === "password" || sensitive);
|
|
30
34
|
const associationId = React.useId();
|
|
31
35
|
const ids = {
|
|
@@ -83,6 +87,7 @@ const useUniformField = (params) => {
|
|
|
83
87
|
name: controllerField.name,
|
|
84
88
|
onBlur,
|
|
85
89
|
onChange: transformedOnChange,
|
|
90
|
+
readOnly,
|
|
86
91
|
ref,
|
|
87
92
|
required,
|
|
88
93
|
testId,
|
|
@@ -93,8 +98,7 @@ const useUniformField = (params) => {
|
|
|
93
98
|
resetField
|
|
94
99
|
};
|
|
95
100
|
};
|
|
96
|
-
|
|
97
|
-
//#region src/partials/FieldLabel/FieldLabel.tsx
|
|
101
|
+
// src/partials/FieldLabel/FieldLabel.tsx
|
|
98
102
|
/**
|
|
99
103
|
* Shared field label and required indicator
|
|
100
104
|
*
|
|
@@ -119,7 +123,6 @@ const FieldLabel = ({ as: Component = "label", children, className = void 0, htm
|
|
|
119
123
|
}) : null]
|
|
120
124
|
});
|
|
121
125
|
};
|
|
122
|
-
//#endregion
|
|
123
126
|
export { useUniformField as n, FieldLabel as t };
|
|
124
127
|
|
|
125
|
-
//# sourceMappingURL=FieldLabel-
|
|
128
|
+
//# sourceMappingURL=FieldLabel-DrNWJIVh.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldLabel-DrNWJIVh.mjs","names":["FieldCopyTestIdButton","FieldValidationError"],"sources":["../src/hooks/useUniformField/useUniformField.tsx","../src/partials/FieldLabel/FieldLabel.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { FieldValues } from 'react-hook-form';\nimport type { UniformFieldState, UseUniformFieldParams } from './types';\n\nimport React from 'react';\n\nimport { useDebounce } from '@fuf-stack/pixels';\n\nimport { useSensitiveField } from '../../Form/subcomponents/SensitiveFields';\nimport { flattenFieldErrors, isValueEmpty } from '../../helpers';\nimport FieldCopyTestIdButton from '../../partials/FieldCopyTestIdButton';\nimport FieldValidationError from '../../partials/FieldValidationError';\nimport { useController } from '../useController/useController';\nimport { useFormContext } from '../useFormContext/useFormContext';\nimport { useInputValueTransform } from '../useInputValueTransform/useInputValueTransform';\n\n/**\n * Binds a form field's value, interactions, validation and label metadata\n *\n * Converts stored values for display and edited values back to form values\n * through `transform`, with automatic number conversion for numeric inputs\n *\n * Reveals validation errors after editing a nonempty value, blur or submission,\n * keeping pristine fields quiet. Debounces invalid-state changes to avoid\n * flickering during validation updates\n *\n * Returns a bound `field` with callbacks, a focus ref, rendered validation\n * messages and label content, including the test ID action in debug mode\n * Stable IDs and accessible-name metadata support associations in controls\n * Form operations remain separate from the field bundle\n *\n * Only `disabled` reaches the form controller, so disabled values are omitted\n * from validation and submission. Read-only fields stay registered, controls\n * prevent changes while their value is still validated and submitted\n */\nconst useUniformField = <\n TFieldValues extends FieldValues = FieldValues,\n TDisplay = unknown,\n>(\n params: UseUniformFieldParams<TFieldValues, TDisplay>,\n): UniformFieldState<TFieldValues, TDisplay> => {\n // field configuration\n const {\n name,\n ariaLabel: customAriaLabel,\n disabled = false,\n description,\n isArrayValue = false,\n testId: explicitTestId,\n label,\n placeholder,\n readOnly = false,\n sensitive = false,\n type,\n transform,\n } = params;\n\n // revealing a password never changes its diagnostic redaction\n useSensitiveField(name, type === 'password' || sensitive);\n\n // stable associations between the control, label and messages\n const associationId = React.useId();\n const ids = {\n control: `uniform-${associationId}`,\n label: `uniform-${associationId}-label`,\n description: `uniform-${associationId}-description`,\n error: `uniform-${associationId}-error`,\n };\n\n // form operations and submission state\n const {\n control,\n debugMode,\n formState: { submitCount },\n formReset,\n getFieldState,\n getValues,\n resetField,\n } = useFormContext<TFieldValues>();\n\n // validation and interaction state\n const {\n error: rawError,\n invalid: rawInvalid,\n isDirty,\n isTouched,\n required,\n testId,\n } = getFieldState(name, explicitTestId);\n\n // register the field and connect its value and callbacks\n const { field: controllerField } = useController<TFieldValues>({\n control,\n disabled,\n name,\n });\n\n const {\n onChange: fieldOnChange,\n value: fieldValue,\n disabled: isDisabled,\n onBlur,\n ref,\n } = controllerField;\n\n // convert between stored form values and displayed values\n const { toDisplayValue, toFormValue } = useInputValueTransform<TDisplay>({\n transform,\n type,\n });\n\n const transformedValue = toDisplayValue(fieldValue);\n const transformedOnChange = (eventOrValue: TDisplay | React.ChangeEvent) => {\n // accept native events as well as direct values\n const displayValue =\n (eventOrValue as React.ChangeEvent<HTMLInputElement>)?.target?.value ??\n eventOrValue;\n const formValue = toFormValue(displayValue as TDisplay);\n fieldOnChange(formValue);\n };\n\n const defaultValue = (getValues() as Record<string, unknown>)?.[\n name as string\n ];\n\n // show errors after editing a nonempty value, blur or submission\n const hasValue = !isValueEmpty(fieldValue);\n const showInvalid =\n rawInvalid && ((isDirty && hasValue) || isTouched || submitCount > 0);\n\n // allow validation messages to finish their exit animation\n const invalid = useDebounce(showInvalid, 200);\n\n // include the test ID action when debugging fields\n const showTestIdCopyButton = debugMode === 'debug-testids';\n const labelNode: ReactNode | null =\n !!label || showTestIdCopyButton ? (\n <>\n {label !== false ? label : null}\n {showTestIdCopyButton ? (\n <FieldCopyTestIdButton testId={testId} />\n ) : null}\n </>\n ) : null;\n\n // preserve nested errors for groups, flatten messages for rendering\n const error = isArrayValue ? flattenFieldErrors(rawError) : rawError;\n const normalizedError = flattenFieldErrors(rawError);\n const errorMessage = (\n <FieldValidationError error={normalizedError} testId={testId} />\n );\n\n // prefer a visible label, use placeholder text only when the field has no label\n const fallbackLabel = !label && placeholder?.trim() ? placeholder : name;\n const ariaLabel =\n customAriaLabel ??\n (label && typeof label === 'string' ? label : fallbackLabel);\n\n // collect the bound field without exposing controller internals\n const field = {\n ariaLabel,\n customAriaLabel,\n defaultValue,\n description,\n disabled: isDisabled,\n error,\n errorMessage,\n hasErrors: normalizedError.length > 0,\n hasLabel: !!label,\n ids,\n invalid,\n label: labelNode,\n name: controllerField.name,\n onBlur,\n onChange: transformedOnChange,\n readOnly,\n ref,\n required,\n testId,\n value: transformedValue,\n };\n\n return {\n control,\n debugMode,\n field,\n formReset,\n getValues,\n resetField,\n };\n};\n\nexport default useUniformField;\n","import type { HTMLAttributes, ReactNode } from 'react';\nimport type { Label as AriaLabel } from 'react-aria-components';\n\ninterface FieldLabelProps extends Pick<\n HTMLAttributes<HTMLElement>,\n 'aria-level' | 'role'\n> {\n /** Label element, React Aria Label preserves the surrounding field context */\n as?: 'label' | 'div' | 'span' | typeof AriaLabel;\n /** Label content */\n children: ReactNode;\n /** CSS class name */\n className?: string;\n /** ID of the labeled control */\n htmlFor?: string;\n /** Label ID */\n id?: string;\n /** Shows the required indicator */\n required?: boolean;\n /** Required indicator CSS class name */\n requiredClassName?: string;\n}\n\n/**\n * Shared field label and required indicator\n *\n * Uses a native label by default, with span/div hosts for nested labels and\n * headings, or React Aria Label for fields that supply label context\n *\n * @see https://react-aria.adobe.com/TextField\n * @see https://react-aria.adobe.com/CheckboxGroup\n */\nconst FieldLabel = ({\n as: Component = 'label',\n children,\n className = undefined,\n htmlFor = undefined,\n id = undefined,\n required = false,\n requiredClassName = 'ml-0.5 text-danger',\n ...props\n}: FieldLabelProps) => {\n if (!children) {\n return null;\n }\n\n return (\n <Component\n {...props}\n className={className}\n data-slot=\"label\"\n htmlFor={htmlFor}\n id={id}\n >\n {children}\n {required ? (\n <span aria-hidden className={requiredClassName}>\n *\n </span>\n ) : null}\n </Component>\n );\n};\n\nexport default FieldLabel;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,mBAIJ,WAC8C;CAE9C,MAAM,EACJ,MACA,WAAW,iBACX,WAAW,OACX,aACA,eAAe,OACf,QAAQ,gBACR,OACA,aACA,WAAW,OACX,YAAY,OACZ,MACA,cACE;CAGJ,kBAAkB,MAAM,SAAS,cAAc,SAAS;CAGxD,MAAM,gBAAgB,MAAM,MAAM;CAClC,MAAM,MAAM;EACV,SAAS,WAAW;EACpB,OAAO,WAAW,cAAc;EAChC,aAAa,WAAW,cAAc;EACtC,OAAO,WAAW,cAAc;CAClC;CAGA,MAAM,EACJ,SACA,WACA,WAAW,EAAE,eACb,WACA,eACA,WACA,eACE,eAA6B;CAGjC,MAAM,EACJ,OAAO,UACP,SAAS,YACT,SACA,WACA,UACA,WACE,cAAc,MAAM,cAAc;CAGtC,MAAM,EAAE,OAAO,oBAAoB,cAA4B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AAA,GACV,KAAK,KAAA,GACL,WAAW,OACX,oBAAoB,sBACpB,GAAG,YACkB;CACrB,IAAI,CAAC,UACH,OAAO;CAGT,OACE,qBAAC,WAAD;EACE,GAAI;EACO;EACX,aAAU;EACD;EACL;EALN,UAAA,CAOG,UACA,WACC,oBAAC,QAAD;GAAM,eAAA;GAAY,WAAW;GAAmB,UAAA;EAE1C,CAAA,IACJ,IACK;;AAEf"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { t as
|
|
1
|
+
import { t as FieldDescription } from "./FieldDescription-X_0s1Lhu.mjs";
|
|
2
|
+
import { t as FieldLabel } from "./FieldLabel-DrNWJIVh.mjs";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
-
|
|
4
|
+
// src/partials/FieldLayout/FieldLayout.tsx
|
|
5
5
|
/**
|
|
6
6
|
* Default arrangement of a field label, editable content and supporting messages
|
|
7
7
|
*
|
|
@@ -40,7 +40,6 @@ const FieldLayout = ({ baseAs = void 0, baseProps = void 0, children, className,
|
|
|
40
40
|
]
|
|
41
41
|
});
|
|
42
42
|
};
|
|
43
|
-
//#endregion
|
|
44
43
|
export { FieldLayout as t };
|
|
45
44
|
|
|
46
|
-
//# sourceMappingURL=FieldLayout-
|
|
45
|
+
//# sourceMappingURL=FieldLayout-DcvQU0zN.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldLayout-
|
|
1
|
+
{"version":3,"file":"FieldLayout-DcvQU0zN.mjs","names":[],"sources":["../src/partials/FieldLayout/FieldLayout.tsx"],"sourcesContent":["import type {\n ComponentProps,\n ComponentPropsWithRef,\n ElementType,\n ReactNode,\n} from 'react';\nimport type { FieldIds } from '../types';\n\nimport FieldDescription from '../FieldDescription/FieldDescription';\nimport FieldLabel from '../FieldLabel/FieldLabel';\n\ntype ClassName = Partial<\n Record<\n 'base' | 'description' | 'errorMessage' | 'helperWrapper' | 'label',\n string\n >\n>;\n\ntype BaseProps<TBase extends ElementType> = Omit<\n ComponentPropsWithRef<TBase>,\n 'children' | 'className' | 'dangerouslySetInnerHTML'\n> &\n Record<`data-${string}`, string | number | boolean | undefined>;\n\n// require the configuration when the base has props the layout cannot supply\ntype BaseConfiguration<TBase extends ElementType> =\n Record<never, never> extends BaseProps<TBase>\n ? { baseProps?: BaseProps<TBase> }\n : { baseProps: BaseProps<TBase> };\n\ninterface FieldLayoutProps<TBase extends ElementType> {\n /** Component or element used for the base slot */\n baseAs?: TBase;\n /** Attributes, interactions and ref for the base element */\n baseProps?: BaseProps<NoInfer<TBase>>;\n /** Editable field content */\n children: ReactNode;\n /** CSS class name */\n className: ClassName;\n /** Help text */\n description?: ReactNode;\n /** Rendered validation messages */\n errorMessage: ReactNode;\n /** IDs shared with the editable control */\n ids: FieldIds;\n /** Shows the validation message */\n invalid: boolean;\n /** Field label */\n label?: ReactNode;\n /** Label element, use React Aria Label inside group engines */\n labelAs?: ComponentProps<typeof FieldLabel>['as'];\n /** Shows the required indicator */\n required?: boolean;\n}\n\n/**\n * Default arrangement of a field label, editable content and supporting messages\n *\n * Renders the base component around the label, content and messages\n * Receives IDs, resolved classes and validation state\n */\nconst FieldLayout = <TBase extends ElementType = 'div'>({\n baseAs = undefined,\n baseProps = undefined,\n children,\n className,\n description = undefined,\n errorMessage,\n ids,\n invalid,\n label = undefined,\n labelAs = 'label',\n required = false,\n}: FieldLayoutProps<TBase> & BaseConfiguration<NoInfer<TBase>>) => {\n const Base = baseAs ?? 'div';\n\n return (\n <Base {...baseProps} className={className.base} data-slot=\"base\">\n {/* field label */}\n <FieldLabel\n as={labelAs}\n className={className.label}\n htmlFor={labelAs === 'label' ? ids.control : undefined}\n id={ids.label}\n required={required}\n >\n {label}\n </FieldLabel>\n\n {/* editable content */}\n {children}\n\n {/* help text and validation messages */}\n {description || invalid ? (\n <div className={className.helperWrapper} data-slot=\"helper-wrapper\">\n <FieldDescription\n className={className.description}\n id={ids.description}\n >\n {description}\n </FieldDescription>\n {invalid ? (\n <div\n className={className.errorMessage}\n data-slot=\"error-message\"\n id={ids.error}\n >\n {errorMessage}\n </div>\n ) : null}\n </div>\n ) : null}\n </Base>\n );\n};\n\nexport default FieldLayout;\n"],"mappings":";;;;;;;;;;AA6DA,MAAM,eAAkD,EACtD,SAAS,KAAA,GACT,YAAY,KAAA,GACZ,UACA,WACA,cAAc,KAAA,GACd,cACA,KACA,SACA,QAAQ,KAAA,GACR,UAAU,SACV,WAAW,YACsD;CAGjE,OACE,qBAHW,UAAU,OAGrB;EAAM,GAAI;EAAW,WAAW,UAAU;EAAM,aAAU;EAA1D,UAAA;GAEE,oBAAC,YAAD;IACE,IAAI;IACJ,WAAW,UAAU;IACrB,SAAS,YAAY,UAAU,IAAI,UAAU,KAAA;IAC7C,IAAI,IAAI;IACE;IAET,UAAA;GACS,CAAA;GAGX;GAGA,eAAe,UACd,qBAAC,OAAD;IAAK,WAAW,UAAU;IAAe,aAAU;IAAnD,UAAA,CACE,oBAAC,kBAAD;KACE,WAAW,UAAU;KACrB,IAAI,IAAI;KAEP,UAAA;IACe,CAAA,GACjB,UACC,oBAAC,OAAD;KACE,WAAW,UAAU;KACrB,aAAU;KACV,IAAI,IAAI;KAEP,UAAA;IACE,CAAA,IACH,IACD;GACH,CAAA,IAAA;EACA;;AAEV"}
|