@fuf-stack/uniform 2.0.0-next.1 → 2.0.0-next.4
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 +47 -27
- package/dist/Checkboxes/index.d.mts.map +1 -1
- package/dist/Checkboxes/index.mjs +26 -25
- package/dist/Checkboxes/index.mjs.map +1 -1
- package/dist/DatePicker/index.d.mts +63 -86
- package/dist/DatePicker/index.d.mts.map +1 -1
- package/dist/DatePicker/index.mjs +43 -49
- 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 +25 -37
- 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 +14 -25
- 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/FieldHelper-B1DWl7eu.mjs +38 -0
- package/dist/FieldHelper-B1DWl7eu.mjs.map +1 -0
- package/dist/FieldLabel-DMTqq0Jj.mjs +29 -0
- package/dist/FieldLabel-DMTqq0Jj.mjs.map +1 -0
- package/dist/{FieldLayout-BLW5S-Jm.mjs → FieldLayout-C9MEBZAC.mjs} +11 -19
- package/dist/FieldLayout-C9MEBZAC.mjs.map +1 -0
- 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-BuLvuRyi.mjs} +5 -7
- package/dist/FieldValidationError-BuLvuRyi.mjs.map +1 -0
- 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 +610 -393
- package/dist/Input/index.d.mts.map +1 -1
- package/dist/Input/index.mjs +24 -31
- package/dist/Input/index.mjs.map +1 -1
- package/dist/RadioBoxes/index.d.mts +247 -2227
- package/dist/RadioBoxes/index.d.mts.map +1 -1
- package/dist/RadioBoxes/index.mjs +25 -37
- package/dist/RadioBoxes/index.mjs.map +1 -1
- package/dist/RadioTabs/index.d.mts +599 -289
- package/dist/RadioTabs/index.d.mts.map +1 -1
- package/dist/RadioTabs/index.mjs +24 -27
- package/dist/RadioTabs/index.mjs.map +1 -1
- package/dist/Radios/index.d.mts +164 -2077
- package/dist/Radios/index.d.mts.map +1 -1
- package/dist/Radios/index.mjs +12 -23
- package/dist/Radios/index.mjs.map +1 -1
- package/dist/Select/index.d.mts +809 -484
- package/dist/Select/index.d.mts.map +1 -1
- package/dist/Select/index.mjs +69 -54
- package/dist/Select/index.mjs.map +1 -1
- package/dist/Slider/index.d.mts +657 -281
- package/dist/Slider/index.d.mts.map +1 -1
- package/dist/Slider/index.mjs +42 -42
- 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 +25 -32
- package/dist/Switch/index.mjs.map +1 -1
- package/dist/Switch-aBYStBoY.d.mts +990 -0
- package/dist/Switch-aBYStBoY.d.mts.map +1 -0
- package/dist/SwitchBox/index.d.mts +606 -201
- package/dist/SwitchBox/index.d.mts.map +1 -1
- package/dist/SwitchBox/index.mjs +29 -33
- package/dist/SwitchBox/index.mjs.map +1 -1
- package/dist/TextArea/index.d.mts +565 -185
- package/dist/TextArea/index.d.mts.map +1 -1
- package/dist/TextArea/index.mjs +18 -23
- package/dist/TextArea/index.mjs.map +1 -1
- package/dist/Time/index.d.mts +60 -44
- package/dist/Time/index.d.mts.map +1 -1
- package/dist/Time/index.mjs +27 -36
- package/dist/Time/index.mjs.map +1 -1
- package/dist/fieldHelperVariants-ClP8taiS.mjs +20 -0
- package/dist/fieldHelperVariants-ClP8taiS.mjs.map +1 -0
- package/dist/fieldLabelVariants-C4ZqECec.mjs +13 -0
- package/dist/fieldLabelVariants-C4ZqECec.mjs.map +1 -0
- package/dist/{FieldDescription-C4l0HKGL.mjs → fieldProps-DWfz2jSO.mjs} +5 -17
- package/dist/fieldProps-DWfz2jSO.mjs.map +1 -0
- 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/{Switch-CvPO8IF9.d.mts → partials/FieldHelper/index.d.mts} +309 -361
- package/dist/partials/FieldHelper/index.d.mts.map +1 -0
- package/dist/partials/FieldHelper/index.mjs +7 -0
- package/dist/partials/FieldHelper/index.mjs.map +1 -0
- package/dist/partials/FieldLabel/index.d.mts +160 -0
- package/dist/partials/FieldLabel/index.d.mts.map +1 -0
- package/dist/partials/FieldLabel/index.mjs +7 -0
- package/dist/partials/FieldLabel/index.mjs.map +1 -0
- package/dist/partials/FieldValidationError/index.d.mts +13 -15
- package/dist/partials/FieldValidationError/index.d.mts.map +1 -1
- package/dist/partials/FieldValidationError/index.mjs +1 -1
- package/dist/{radioControlVariants-Cm6WufWo.mjs → radioControlVariants-CbtG5U4_.mjs} +28 -25
- package/dist/radioControlVariants-CbtG5U4_.mjs.map +1 -0
- package/dist/{switchVariants-BaQw2DA7.mjs → switchVariants-0Xa7TQYg.mjs} +8 -11
- package/dist/switchVariants-0Xa7TQYg.mjs.map +1 -0
- package/dist/{timeVariants-B9HDfNYt.mjs → timeVariants-Bkt4iwXx.mjs} +14 -12
- package/dist/timeVariants-Bkt4iwXx.mjs.map +1 -0
- 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/dist/{FieldLabel-DKzqkuY1.mjs → useUniformField-TTNPTsVn.mjs} +15 -37
- package/dist/useUniformField-TTNPTsVn.mjs.map +1 -0
- package/package.json +10 -7
- package/dist/FieldDescription-C4l0HKGL.mjs.map +0 -1
- package/dist/FieldLabel-DKzqkuY1.mjs.map +0 -1
- package/dist/FieldLayout-BLW5S-Jm.mjs.map +0 -1
- package/dist/FieldValidationError-DgkCL3cC.mjs.map +0 -1
- package/dist/FormContext-CsFiNvuJ.d.mts +0 -19
- package/dist/FormContext-CsFiNvuJ.d.mts.map +0 -1
- package/dist/Switch-CvPO8IF9.d.mts.map +0 -1
- package/dist/index-BS8IoBOn.d.mts.map +0 -1
- package/dist/radioControlVariants-Cm6WufWo.mjs.map +0 -1
- package/dist/switchVariants-BaQw2DA7.mjs.map +0 -1
- package/dist/timeVariants-B9HDfNYt.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,QAAQ;EAC7B,IAAI,iBAAiB,KAAA,GACnB,OAAO;EAGT,IAAI,iBAAiB,MACnB,OAAO;EAGT,IAAI,OAAO,iBAAiB,YAAY,iBAAiB,MACvD,OAAO,mBAAmB,YAAuC;EAEnE,OAAO;CACT,CAAC;AACL;;;;;AAMA,MAAa,yBACX,QACA,YACY;CACZ,IAAI,CAAC,UAAU,CAAC,SACd,OAAO;CAGT,OAAO,OAAO,KAAK,MAAM,CAAC,CACvB,QAAQ,QAAQ;EAEf,OAAO,QAAQ;CACjB,CAAC,CAAC,CACD,MAAM,QAAQ;EACb,MAAM,aAAa,OAAO;EAC1B,MAAM,eAAe,QAAQ;EAG7B,IAAI,eAAe,KAAA,KAAa,iBAAiB,KAAA,GAC/C,OAAO;EAIT,IAAI,MAAM,QAAQ,UAAU,GAE1B,OAAO,CAAC,CAAC;EAIX,IAAI,OAAO,eAAe,YAAY,eAAe,MACnD,OAAO,sBACL,YACA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IACV;CACW,CAAA;AAErB;;;;AChEA,MAAM,oBAAoB,EACxB,OACA,UACA,gBAC2B;CAC3B,MAAM,EAAE,WAAW,OAAO,KAAK,SAAS,OAAO,UAAU,WAAW;CAEpE,MAAM,UAAU,WAAW;CAG3B,MAAM,kBAAkB,CAAC,CAAC,OAAO;CAGjC,MAAM,WAAW,QAAQ,QAAQ,mBAAmB,EAAE,QAAQ,CAAC;CAC/D,MAAM,aAAa,QAAQ,qBAAqB,UAAU,WAAW,MAAM;CAE3E,OACE,qBAAC,OAAD;EACE,oBAAkB,kBAAkB,IAAI,QAAQ,KAAA;EAChD,cAAY,CAAC,QAAQ,YAAY,KAAA;EACjC,mBAAiB,QAAQ,IAAI,QAAQ,KAAA;EACrC,WAAW,WAAW;EACtB,kBAAe;EACf,MAAK;EANP,UAAA;GASG,QACC,oBAAC,YAAD;IACE,cAAY;IACZ,IAAG;IACH,WAAW,WAAW;IACtB,IAAI,IAAI;IACE;IACV,MAAK;IAEJ,UAAA;GACS,CAAA,IACV;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"}
|
|
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\nimport { fieldHelperVariants } from '../../partials/FieldHelper/fieldHelperVariants';\n\n// own recipe identity, so styling can target FieldCard errors separately\nconst fieldCardValidationErrorVariants = tv({ extend: fieldHelperVariants });\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,QAAQ;EAC7B,IAAI,iBAAiB,KAAA,GACnB,OAAO;EAGT,IAAI,iBAAiB,MACnB,OAAO;EAGT,IAAI,OAAO,iBAAiB,YAAY,iBAAiB,MACvD,OAAO,mBAAmB,YAAuC;EAEnE,OAAO;CACT,CAAC;AACL;;;;;AAMA,MAAa,yBACX,QACA,YACY;CACZ,IAAI,CAAC,UAAU,CAAC,SACd,OAAO;CAGT,OAAO,OAAO,KAAK,MAAM,CAAC,CACvB,QAAQ,QAAQ;EAEf,OAAO,QAAQ;CACjB,CAAC,CAAC,CACD,MAAM,QAAQ;EACb,MAAM,aAAa,OAAO;EAC1B,MAAM,eAAe,QAAQ;EAG7B,IAAI,eAAe,KAAA,KAAa,iBAAiB,KAAA,GAC/C,OAAO;EAIT,IAAI,MAAM,QAAQ,UAAU,GAE1B,OAAO,CAAC,CAAC;EAIX,IAAI,OAAO,eAAe,YAAY,eAAe,MACnD,OAA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;;;AChEA,MAAM,oBAAoB,EACxB,OACA,UACA,gBAC2B;CAC3B,MAAM,EAAE,WAAW,OAAO,KAAK,SAAS,OAAO,UAAU,WAAW;CAEpE,MAAM,UAAU,WAAW;CAG3B,MAAM,kBAAkB,CAAC,CAAC,OAAO;CAGjC,MAAM,WAAW,QAAQ,QAAQ,mBAAmB,EAAE,QAAQ,CAAC;CAC/D,MAAM,aAAa,QAAQ,qBAAqB,UAAU,WAAW,MAAM;CAE3E,OACE,qBAAC,OAAD;EACE,oBAAkB,kBAAkB,IAAI,QAAQ,KAAA;EAChD,cAAY,CAAC,QAAQ,YAAY,KAAA;EACjC,mBAAiB,QAAQ,IAAI,QAAQ,KAAA;EACrC,WAAW,WAAW;EACtB,kBAAe;EACf,MAAK;EANP,UAAA;GASG,QACC,oBAAC,YAAD;IACE,cAAY;IACZ,IAAG;IACH,WAAW,WAAW;IACtB,IAAI,IAAI;IACE;IACV,MAAK;IAEJ,UAAA;GACS,CAAA,IACV;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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
// src/partials/FieldDescription/FieldDescription.tsx
|
|
3
|
+
/** Help text associated with a field through its description ID */
|
|
4
|
+
const FieldDescription = ({ children, ...props }) => {
|
|
5
|
+
if (!children) return null;
|
|
6
|
+
return /* @__PURE__ */ jsx("div", {
|
|
7
|
+
"data-slot": "description",
|
|
8
|
+
...props,
|
|
9
|
+
children
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
// src/partials/FieldHelper/FieldHelper.tsx
|
|
13
|
+
/**
|
|
14
|
+
* Help text and validation messages below a field
|
|
15
|
+
*
|
|
16
|
+
* Renders nothing without help text or visible validation. The IDs match the
|
|
17
|
+
* control's aria-describedby associations.
|
|
18
|
+
*/
|
|
19
|
+
const FieldHelper = ({ className = {}, description = void 0, errorMessage = void 0, ids, invalid }) => {
|
|
20
|
+
if (!description && !invalid) return null;
|
|
21
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
22
|
+
className: className.helperWrapper,
|
|
23
|
+
"data-slot": "helper-wrapper",
|
|
24
|
+
children: [/* @__PURE__ */ jsx(FieldDescription, {
|
|
25
|
+
className: className.description,
|
|
26
|
+
id: ids.description,
|
|
27
|
+
children: description
|
|
28
|
+
}), invalid ? /* @__PURE__ */ jsx("div", {
|
|
29
|
+
className: className.errorMessage,
|
|
30
|
+
"data-slot": "error-message",
|
|
31
|
+
id: ids.error,
|
|
32
|
+
children: errorMessage
|
|
33
|
+
}) : null]
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export { FieldDescription as n, FieldHelper as t };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=FieldHelper-B1DWl7eu.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldHelper-B1DWl7eu.mjs","names":[],"sources":["../src/partials/FieldDescription/FieldDescription.tsx","../src/partials/FieldHelper/FieldHelper.tsx"],"sourcesContent":["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","import type { ReactNode } from 'react';\nimport type { FieldIds } from '../types';\n\nimport FieldDescription from '../FieldDescription/FieldDescription';\n\ntype ClassName = Partial<\n Record<'description' | 'errorMessage' | 'helperWrapper', string>\n>;\n\nexport interface FieldHelperProps {\n /** CSS class name */\n className?: ClassName;\n /** Help text */\n description?: ReactNode;\n /** Rendered validation messages */\n errorMessage?: ReactNode;\n /** IDs of the help text and validation message */\n ids: Pick<FieldIds, 'description' | 'error'>;\n /** Shows the validation message */\n invalid: boolean;\n}\n\n/**\n * Help text and validation messages below a field\n *\n * Renders nothing without help text or visible validation. The IDs match the\n * control's aria-describedby associations.\n */\nconst FieldHelper = ({\n className = {},\n description = undefined,\n errorMessage = undefined,\n ids,\n invalid,\n}: FieldHelperProps) => {\n if (!description && !invalid) {\n return null;\n }\n\n return (\n <div className={className.helperWrapper} data-slot=\"helper-wrapper\">\n <FieldDescription className={className.description} id={ids.description}>\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 );\n};\n\nexport default FieldHelper;\n"],"mappings":";;;AAUA,MAAM,oBAAoB,EAAE,UAAU,GAAG,YAAmC;CAC1E,IAAI,CAAC,UACH,OAAO;CAGT,OACE,oBAAC,OAAD;EAAK,aAAU;EAAc,GAAI;EAC9B;CACE,CAAA;AAET;;;;;;;;ACQA,MAAM,eAAe,EACnB,YAAY,CAAC,GACb,cAAc,KAAA,GACd,eAAe,KAAA,GACf,KACA,cACsB;CACtB,IAAI,CAAC,eAAe,CAAC,SACnB,OAAO;CAGT,OACE,qBAAC,OAAD;EAAK,WAAW,UAAU;EAAe,aAAU;EAAnD,UAAA,CACE,oBAAC,kBAAD;GAAkB,WAAW,UAAU;GAAa,IAAI,IAAI;GACzD,UAAA;EACe,CAAA,GACjB,UACC,oBAAC,OAAD;GACE,WAAW,UAAU;GACrB,aAAU;GACV,IAAI,IAAI;GAEP,UAAA;EACE,CAAA,IACH,IACD;;AAET"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
// src/partials/FieldLabel/FieldLabel.tsx
|
|
3
|
+
/**
|
|
4
|
+
* Shared field label and required indicator
|
|
5
|
+
*
|
|
6
|
+
* Uses a native label by default, with span/div hosts for nested labels and
|
|
7
|
+
* headings, or React Aria Label for fields that supply label context
|
|
8
|
+
*
|
|
9
|
+
* @see https://react-aria.adobe.com/TextField
|
|
10
|
+
* @see https://react-aria.adobe.com/CheckboxGroup
|
|
11
|
+
*/
|
|
12
|
+
const FieldLabel = ({ as: Component = "label", children, className = void 0, htmlFor = void 0, id = void 0, required = false, requiredClassName = "ml-0.5 text-danger", ...props }) => {
|
|
13
|
+
if (!children) return null;
|
|
14
|
+
return /* @__PURE__ */ jsxs(Component, {
|
|
15
|
+
...props,
|
|
16
|
+
className,
|
|
17
|
+
"data-slot": "label",
|
|
18
|
+
htmlFor,
|
|
19
|
+
id,
|
|
20
|
+
children: [children, required ? /* @__PURE__ */ jsx("span", {
|
|
21
|
+
"aria-hidden": true,
|
|
22
|
+
className: requiredClassName,
|
|
23
|
+
children: "*"
|
|
24
|
+
}) : null]
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
export { FieldLabel as t };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=FieldLabel-DMTqq0Jj.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldLabel-DMTqq0Jj.mjs","names":[],"sources":["../src/partials/FieldLabel/FieldLabel.tsx"],"sourcesContent":["import type { HTMLAttributes, ReactNode } from 'react';\nimport type { Label as AriaLabel } from 'react-aria-components';\n\nexport interface 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":";;;;;;;;;;;AAgCA,MAAM,cAAc,EAClB,IAAI,YAAY,SAChB,UACA,YAAY,KAAA,GACZ,UAAU,KAAA,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 FieldHelper } from "./FieldHelper-B1DWl7eu.mjs";
|
|
2
|
+
import { t as FieldLabel } from "./FieldLabel-DMTqq0Jj.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
|
*
|
|
@@ -23,24 +23,16 @@ const FieldLayout = ({ baseAs = void 0, baseProps = void 0, children, className,
|
|
|
23
23
|
children: label
|
|
24
24
|
}),
|
|
25
25
|
children,
|
|
26
|
-
|
|
27
|
-
className
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}), invalid ? /* @__PURE__ */ jsx("div", {
|
|
34
|
-
className: className.errorMessage,
|
|
35
|
-
"data-slot": "error-message",
|
|
36
|
-
id: ids.error,
|
|
37
|
-
children: errorMessage
|
|
38
|
-
}) : null]
|
|
39
|
-
}) : null
|
|
26
|
+
/* @__PURE__ */ jsx(FieldHelper, {
|
|
27
|
+
className,
|
|
28
|
+
description,
|
|
29
|
+
errorMessage,
|
|
30
|
+
ids,
|
|
31
|
+
invalid
|
|
32
|
+
})
|
|
40
33
|
]
|
|
41
34
|
});
|
|
42
35
|
};
|
|
43
|
-
//#endregion
|
|
44
36
|
export { FieldLayout as t };
|
|
45
37
|
|
|
46
|
-
//# sourceMappingURL=FieldLayout-
|
|
38
|
+
//# sourceMappingURL=FieldLayout-C9MEBZAC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldLayout-C9MEBZAC.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 FieldHelper from '../FieldHelper/FieldHelper';\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 <FieldHelper\n className={className}\n description={description}\n errorMessage={errorMessage}\n ids={ids}\n invalid={invalid}\n />\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;GAGD,oBAAC,aAAD;IACa;IACE;IACC;IACT;IACI;GACV,CAAA;EACG;;AAEV"}
|