@skybin-tech/nebula-ui 0.0.29 → 0.0.31

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.
Files changed (133) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -1
  2. package/dist/cjs/components/Accordion/Accordion.cjs.map +1 -1
  3. package/dist/cjs/components/Alert/Alert.cjs.map +1 -1
  4. package/dist/cjs/components/Avatar/Avatar.cjs.map +1 -1
  5. package/dist/cjs/components/Button/Button.cjs.map +1 -1
  6. package/dist/cjs/components/Card/Card.cjs.map +1 -1
  7. package/dist/cjs/components/Checkbox/Checkbox.cjs.map +1 -1
  8. package/dist/cjs/components/DropdownMenu/DropdownMenu.cjs.map +1 -1
  9. package/dist/cjs/components/Form/Checkbox.cjs.map +1 -1
  10. package/dist/cjs/components/Form/Combobox.cjs.map +1 -1
  11. package/dist/cjs/components/Form/CountryPicker.cjs.map +1 -1
  12. package/dist/cjs/components/Form/CountrySelect.cjs.map +1 -1
  13. package/dist/cjs/components/Form/DatePicker.cjs +8 -2
  14. package/dist/cjs/components/Form/DatePicker.cjs.map +1 -1
  15. package/dist/cjs/components/Form/DateTimePicker.cjs +202 -0
  16. package/dist/cjs/components/Form/DateTimePicker.cjs.map +1 -0
  17. package/dist/cjs/components/Form/FieldLayout.cjs.map +1 -1
  18. package/dist/cjs/components/Form/Form.cjs +9 -8
  19. package/dist/cjs/components/Form/Form.cjs.map +1 -1
  20. package/dist/cjs/components/Form/FormSwitch.cjs.map +1 -1
  21. package/dist/cjs/components/Form/PasswordRevealToggle.cjs +21 -0
  22. package/dist/cjs/components/Form/PasswordRevealToggle.cjs.map +1 -0
  23. package/dist/cjs/components/Form/PhoneInput.cjs.map +1 -1
  24. package/dist/cjs/components/Form/Radio.cjs.map +1 -1
  25. package/dist/cjs/components/Form/Select.cjs.map +1 -1
  26. package/dist/cjs/components/Form/TextArea.cjs.map +1 -1
  27. package/dist/cjs/components/Form/TextBox.cjs +29 -14
  28. package/dist/cjs/components/Form/TextBox.cjs.map +1 -1
  29. package/dist/cjs/components/Form/TimePicker.cjs +111 -0
  30. package/dist/cjs/components/Form/TimePicker.cjs.map +1 -0
  31. package/dist/cjs/components/Form/context.cjs +1 -1
  32. package/dist/cjs/components/Form/context.cjs.map +1 -1
  33. package/dist/cjs/components/Form/hooks.cjs.map +1 -1
  34. package/dist/cjs/components/Form/index.cjs +7 -0
  35. package/dist/cjs/components/Form/variants.cjs.map +1 -1
  36. package/dist/cjs/components/Input/Input.cjs +32 -4
  37. package/dist/cjs/components/Input/Input.cjs.map +1 -1
  38. package/dist/cjs/components/Label/Label.cjs.map +1 -1
  39. package/dist/cjs/components/Pagination/Pagination.cjs.map +1 -1
  40. package/dist/cjs/components/Separator/Separator.cjs.map +1 -1
  41. package/dist/cjs/components/Switch/Switch.cjs.map +1 -1
  42. package/dist/cjs/components/Tabs/Tabs.cjs.map +1 -1
  43. package/dist/cjs/components/Textarea/Textarea.cjs.map +1 -1
  44. package/dist/cjs/components/Tooltip/Tooltip.cjs.map +1 -1
  45. package/dist/cjs/hooks/useDebounce.cjs.map +1 -1
  46. package/dist/cjs/hooks/useToggle.cjs.map +1 -1
  47. package/dist/cjs/index.cjs +7 -0
  48. package/dist/cjs/primitives/accordion.cjs.map +1 -1
  49. package/dist/cjs/primitives/alert.cjs.map +1 -1
  50. package/dist/cjs/primitives/badge.cjs.map +1 -1
  51. package/dist/cjs/primitives/breadcrumb.cjs.map +1 -1
  52. package/dist/cjs/primitives/button.cjs.map +1 -1
  53. package/dist/cjs/primitives/checkbox.cjs.map +1 -1
  54. package/dist/cjs/primitives/command.cjs.map +1 -1
  55. package/dist/cjs/primitives/dialog.cjs.map +1 -1
  56. package/dist/cjs/primitives/dropdown-menu.cjs.map +1 -1
  57. package/dist/cjs/primitives/input-otp.cjs.map +1 -1
  58. package/dist/cjs/primitives/label.cjs.map +1 -1
  59. package/dist/cjs/primitives/progress.cjs.map +1 -1
  60. package/dist/cjs/primitives/radio-group.cjs.map +1 -1
  61. package/dist/cjs/primitives/scroll-area.cjs.map +1 -1
  62. package/dist/cjs/primitives/select.cjs.map +1 -1
  63. package/dist/cjs/primitives/sheet.cjs.map +1 -1
  64. package/dist/cjs/primitives/slider.cjs.map +1 -1
  65. package/dist/cjs/primitives/switch.cjs.map +1 -1
  66. package/dist/cjs/primitives/table.cjs.map +1 -1
  67. package/dist/cjs/primitives/toast.cjs.map +1 -1
  68. package/dist/cjs/primitives/toggle.cjs.map +1 -1
  69. package/dist/cjs/utils/cn.cjs.map +1 -1
  70. package/dist/components/Button/Button.js.map +1 -1
  71. package/dist/components/Form/Checkbox.js.map +1 -1
  72. package/dist/components/Form/Combobox.js.map +1 -1
  73. package/dist/components/Form/CountryPicker.js.map +1 -1
  74. package/dist/components/Form/CountrySelect.js.map +1 -1
  75. package/dist/components/Form/DatePicker.d.ts.map +1 -1
  76. package/dist/components/Form/DatePicker.js +9 -3
  77. package/dist/components/Form/DatePicker.js.map +1 -1
  78. package/dist/components/Form/DateTimePicker.d.ts +28 -0
  79. package/dist/components/Form/DateTimePicker.d.ts.map +1 -0
  80. package/dist/components/Form/DateTimePicker.js +202 -0
  81. package/dist/components/Form/DateTimePicker.js.map +1 -0
  82. package/dist/components/Form/FieldLayout.js.map +1 -1
  83. package/dist/components/Form/Form.js +9 -8
  84. package/dist/components/Form/Form.js.map +1 -1
  85. package/dist/components/Form/FormSwitch.js.map +1 -1
  86. package/dist/components/Form/PasswordRevealToggle.d.ts +7 -0
  87. package/dist/components/Form/PasswordRevealToggle.d.ts.map +1 -0
  88. package/dist/components/Form/PasswordRevealToggle.js +21 -0
  89. package/dist/components/Form/PasswordRevealToggle.js.map +1 -0
  90. package/dist/components/Form/PhoneInput.js.map +1 -1
  91. package/dist/components/Form/Radio.js.map +1 -1
  92. package/dist/components/Form/Select.js.map +1 -1
  93. package/dist/components/Form/TextArea.js.map +1 -1
  94. package/dist/components/Form/TextBox.d.ts +5 -0
  95. package/dist/components/Form/TextBox.d.ts.map +1 -1
  96. package/dist/components/Form/TextBox.js +30 -15
  97. package/dist/components/Form/TextBox.js.map +1 -1
  98. package/dist/components/Form/TimePicker.d.ts +14 -0
  99. package/dist/components/Form/TimePicker.d.ts.map +1 -0
  100. package/dist/components/Form/TimePicker.js +111 -0
  101. package/dist/components/Form/TimePicker.js.map +1 -0
  102. package/dist/components/Form/context.d.ts +1 -1
  103. package/dist/components/Form/context.d.ts.map +1 -1
  104. package/dist/components/Form/context.js +1 -1
  105. package/dist/components/Form/context.js.map +1 -1
  106. package/dist/components/Form/index.d.ts +6 -0
  107. package/dist/components/Form/index.d.ts.map +1 -1
  108. package/dist/components/Form/index.js +4 -1
  109. package/dist/components/Input/Input.d.ts +14 -2
  110. package/dist/components/Input/Input.d.ts.map +1 -1
  111. package/dist/components/Input/Input.js +34 -6
  112. package/dist/components/Input/Input.js.map +1 -1
  113. package/dist/components/Pagination/Pagination.js.map +1 -1
  114. package/dist/index.d.ts +2 -2
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +4 -1
  117. package/dist/primitives/accordion.js.map +1 -1
  118. package/dist/primitives/breadcrumb.js.map +1 -1
  119. package/dist/primitives/checkbox.js.map +1 -1
  120. package/dist/primitives/command.js.map +1 -1
  121. package/dist/primitives/dialog.js.map +1 -1
  122. package/dist/primitives/dropdown-menu.js.map +1 -1
  123. package/dist/primitives/input-otp.js.map +1 -1
  124. package/dist/primitives/progress.js.map +1 -1
  125. package/dist/primitives/radio-group.js.map +1 -1
  126. package/dist/primitives/scroll-area.js.map +1 -1
  127. package/dist/primitives/select.js.map +1 -1
  128. package/dist/primitives/sheet.js.map +1 -1
  129. package/dist/primitives/slider.js.map +1 -1
  130. package/dist/primitives/switch.js.map +1 -1
  131. package/dist/primitives/table.js.map +1 -1
  132. package/dist/primitives/toast.js.map +1 -1
  133. package/package.json +22 -22
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DateTimePicker.cjs","names":[],"sources":["../../../../src/components/Form/DateTimePicker.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { useContext, useEffect, useId, useState } from \"react\";\r\nimport { format, startOfDay } from \"date-fns\";\r\nimport { CalendarIcon, Clock } from \"lucide-react\";\r\nimport { useController, useFormContext as useRHFFormContext, type Control, type FieldPath, type FieldValues } from \"react-hook-form\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport { Button } from \"../../primitives/button\";\r\nimport { Calendar } from \"../../primitives/calendar\";\r\nimport { Popover, PopoverContent, PopoverTrigger } from \"../../primitives/popover\";\r\nimport { Separator } from \"../../primitives/separator\";\r\nimport { FormConfigContext, type FieldValidationRules, type FormConfig } from \"./context\";\r\nimport { FieldLayout } from \"./FieldLayout\";\r\nimport { TimePicker } from \"./TimePicker\";\r\n\r\nconst dateTimePickerVariants = cva(\"w-full justify-start text-left font-normal\", {\r\n variants: {\r\n size: {\r\n sm: \"h-8 text-xs\",\r\n md: \"h-10 text-sm\",\r\n lg: \"h-12 text-base\",\r\n },\r\n variant: {\r\n default: \"border-input\",\r\n error: \"border-destructive\",\r\n success: \"border-green-500\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n variant: \"default\",\r\n },\r\n});\r\n\r\nexport interface DateTimePickerProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends VariantProps<typeof dateTimePickerVariants> {\r\n name: TName;\r\n label?: string;\r\n helperText?: string;\r\n showError?: boolean;\r\n error?: string;\r\n fullWidth?: boolean;\r\n placeholder?: string;\r\n disabled?: boolean;\r\n className?: string;\r\n id?: string;\r\n control?: Control<TFieldValues>;\r\n required?: boolean | string;\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n minuteStep?: number;\r\n}\r\n\r\nfunction toValidDate(value: unknown): Date | undefined {\r\n if (!value || value === \"\") {\r\n return undefined;\r\n }\r\n\r\n const date = value instanceof Date ? value : new Date(value as string | number);\r\n if (Number.isNaN(date.getTime())) {\r\n return undefined;\r\n }\r\n\r\n return date;\r\n}\r\n\r\nfunction hasTimePart(date: Date): boolean {\r\n return date.getHours() !== 0 || date.getMinutes() !== 0 || date.getSeconds() !== 0 || date.getMilliseconds() !== 0;\r\n}\r\n\r\nfunction withPreservedTime(nextDay: Date, previous: Date): Date {\r\n const next = new Date(nextDay);\r\n next.setHours(\r\n previous.getHours(),\r\n previous.getMinutes(),\r\n previous.getSeconds(),\r\n previous.getMilliseconds()\r\n );\r\n return next;\r\n}\r\n\r\nfunction isSelectEventTarget(target: EventTarget | null): boolean {\r\n return target instanceof Element && Boolean(target.closest(\"[data-radix-select-content]\"));\r\n}\r\n\r\nexport function DateTimePicker<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>({\r\n name,\r\n label,\r\n helperText,\r\n showError = true,\r\n error: customError,\r\n size,\r\n variant,\r\n fullWidth = true,\r\n placeholder = \"Pick a date\",\r\n disabled,\r\n className,\r\n id: providedId,\r\n control: externalControl,\r\n required,\r\n validate,\r\n minuteStep = 5,\r\n}: DateTimePickerProps<TFieldValues, TName>) {\r\n const generatedId = useId();\r\n const inputId = providedId ?? generatedId;\r\n const [open, setOpen] = useState(false);\r\n const [timeOpen, setTimeOpen] = useState(false);\r\n const [timeSet, setTimeSet] = useState(false);\r\n const formConfigContext = useContext(FormConfigContext);\r\n const formConfig: FormConfig = formConfigContext ?? {};\r\n const rhfContext = useRHFFormContext<TFieldValues>();\r\n const control = externalControl ?? rhfContext?.control;\r\n\r\n const registerFieldValidation = formConfigContext?.registerFieldValidation;\r\n const unregisterFieldValidation = formConfigContext?.unregisterFieldValidation;\r\n\r\n useEffect(() => {\r\n if (registerFieldValidation) {\r\n const rules: FieldValidationRules = {};\r\n if (required !== undefined) rules.required = required;\r\n if (validate !== undefined) rules.validate = validate;\r\n\r\n registerFieldValidation({\r\n name: name as string,\r\n type: \"datetime\",\r\n rules,\r\n });\r\n\r\n return () => {\r\n unregisterFieldValidation?.(name as string);\r\n };\r\n }\r\n }, [\r\n registerFieldValidation,\r\n unregisterFieldValidation,\r\n name,\r\n required,\r\n validate,\r\n ]);\r\n\r\n const { field, fieldState } = useController<TFieldValues, TName>({\r\n name,\r\n control,\r\n });\r\n\r\n const selectedDate = toValidDate(field.value);\r\n\r\n useEffect(() => {\r\n const date = toValidDate(field.value);\r\n if (!date) {\r\n setTimeSet(false);\r\n return;\r\n }\r\n\r\n if (hasTimePart(date)) {\r\n setTimeSet(true);\r\n }\r\n }, [field.value]);\r\n\r\n const fieldError = fieldState.error?.message;\r\n const errorMessage = customError ?? fieldError;\r\n const hasError = !!errorMessage;\r\n const effectiveSize = size ?? formConfig.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? formConfig.disabled;\r\n const effectiveVariant = hasError ? \"error\" : variant;\r\n const displayHasTime = timeSet && !!selectedDate;\r\n\r\n const handleOpenChange = (nextOpen: boolean) => {\r\n setOpen(nextOpen);\r\n if (nextOpen && timeSet) {\r\n setTimeOpen(true);\r\n return;\r\n }\r\n\r\n if (!nextOpen) {\r\n setTimeOpen(false);\r\n }\r\n };\r\n\r\n return (\r\n <FieldLayout\r\n inputId={inputId}\r\n label={label}\r\n required={!!required}\r\n helperText={helperText}\r\n errorMessage={showError ? errorMessage : undefined}\r\n showError={showError}\r\n fullWidth={fullWidth}\r\n formConfig={formConfig}\r\n >\r\n <Popover open={open} onOpenChange={handleOpenChange}>\r\n <PopoverTrigger asChild>\r\n <Button\r\n id={inputId}\r\n type=\"button\"\r\n variant=\"outline\"\r\n disabled={effectiveDisabled}\r\n aria-invalid={hasError}\r\n aria-describedby={\r\n hasError\r\n ? `${inputId}-error`\r\n : helperText\r\n ? `${inputId}-helper`\r\n : undefined\r\n }\r\n className={cn(\r\n dateTimePickerVariants({ size: effectiveSize, variant: effectiveVariant }),\r\n !selectedDate && \"text-muted-foreground\",\r\n className\r\n )}\r\n >\r\n <CalendarIcon className=\"mr-2 h-4 w-4\" />\r\n {selectedDate\r\n ? format(selectedDate, displayHasTime ? \"PPP p\" : \"PPP\")\r\n : placeholder}\r\n </Button>\r\n </PopoverTrigger>\r\n <PopoverContent\r\n className=\"w-auto p-0\"\r\n align=\"start\"\r\n onPointerDownOutside={(event) => {\r\n if (isSelectEventTarget(event.target)) {\r\n event.preventDefault();\r\n }\r\n }}\r\n onFocusOutside={(event) => {\r\n if (isSelectEventTarget(event.target)) {\r\n event.preventDefault();\r\n }\r\n }}\r\n >\r\n <Calendar\r\n mode=\"single\"\r\n selected={selectedDate}\r\n onSelect={(date) => {\r\n if (!date) {\r\n field.onChange(\"\");\r\n setTimeSet(false);\r\n return;\r\n }\r\n\r\n if (selectedDate && timeSet) {\r\n field.onChange(withPreservedTime(date, selectedDate));\r\n setOpen(false);\r\n return;\r\n }\r\n\r\n field.onChange(startOfDay(date));\r\n }}\r\n />\r\n <Separator />\r\n <div className=\"p-3\">\r\n <Button\r\n type=\"button\"\r\n variant=\"ghost\"\r\n disabled={effectiveDisabled}\r\n className=\"h-8 w-full justify-start px-2 font-normal\"\r\n onClick={() => setTimeOpen((current) => !current)}\r\n >\r\n <Clock className=\"mr-2 h-4 w-4\" />\r\n {displayHasTime && selectedDate ? format(selectedDate, \"p\") : \"Add time\"}\r\n </Button>\r\n {timeOpen ? (\r\n <TimePicker\r\n className=\"mt-2\"\r\n value={selectedDate}\r\n minuteStep={minuteStep}\r\n disabled={effectiveDisabled}\r\n onChange={(date) => {\r\n field.onChange(date);\r\n setTimeSet(true);\r\n }}\r\n onClear={() => {\r\n if (selectedDate) {\r\n field.onChange(startOfDay(selectedDate));\r\n }\r\n setTimeSet(false);\r\n }}\r\n />\r\n ) : null}\r\n </div>\r\n </PopoverContent>\r\n </Popover>\r\n </FieldLayout>\r\n );\r\n}\r\n\r\nDateTimePicker.displayName = \"DateTimePicker\";\r\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,IAAM,0BAAA,GAAyB,yB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,UAAA,GAAS,SAAA,WAAA,CAAW,IAAI,CAAC;MACjC;KACD,CAAA;KACD,iBAAA,GAAA,kBAAA,IAAA,CAAC,kBAAA,WAAD,CAAY,CAAA;KACZ,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;MAAK,WAAU;MAAf,UAAA,CACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,eAAA,QAAD;OACE,MAAK;OACL,SAAQ;OACR,UAAU;OACV,WAAU;OACV,eAAe,aAAa,YAAY,CAAC,OAAO;OALlD,UAAA,CAOE,iBAAA,GAAA,kBAAA,IAAA,CAAC,aAAA,OAAD,EAAO,WAAU,eAAgB,CAAA,GAChC,kBAAkB,gBAAA,GAAe,SAAA,OAAA,CAAO,cAAc,GAAG,IAAI,UACxD;MACP,CAAA,GAAA,WACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,mBAAA,YAAD;OACE,WAAU;OACV,OAAO;OACK;OACZ,UAAU;OACV,WAAW,SAAS;QAClB,MAAM,SAAS,IAAI;QACnB,WAAW,IAAI;OACjB;OACA,eAAe;QACb,IAAI,cACF,MAAM,UAAA,GAAS,SAAA,WAAA,CAAW,YAAY,CAAC;QAEzC,WAAW,KAAK;OAClB;MACD,CAAA,IACC,IACD;;IACS;GACT,CAAA,CAAA;;CACE,CAAA;AAEjB;AAEA,eAAe,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"FieldLayout.cjs","names":[],"sources":["../../../../src/components/Form/FieldLayout.tsx"],"sourcesContent":["'use client';\r\n\r\nimport type { ReactNode } from \"react\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport { Label } from \"../../primitives/label\";\r\nimport { labelVariants } from \"./variants\";\r\nimport type { FormConfig } from \"./context\";\r\n\r\nexport interface FieldLayoutProps {\r\n inputId: string;\r\n label?: string;\r\n required?: boolean;\r\n helperText?: string;\r\n errorMessage?: string;\r\n showError?: boolean;\r\n fullWidth?: boolean;\r\n formConfig?: FormConfig;\r\n children: ReactNode;\r\n}\r\n\r\nfunction resolveLabelWidth(labelWidth?: string | number): string | undefined {\r\n if (labelWidth === undefined) {\r\n return undefined;\r\n }\r\n\r\n return typeof labelWidth === \"number\" ? `${labelWidth}px` : labelWidth;\r\n}\r\n\r\nexport function FieldLayout({\r\n inputId,\r\n label,\r\n required,\r\n helperText,\r\n errorMessage,\r\n showError = true,\r\n fullWidth = true,\r\n formConfig = {},\r\n children,\r\n}: FieldLayoutProps) {\r\n const layout = formConfig.layout ?? \"vertical\";\r\n const labelWidth = resolveLabelWidth(formConfig.labelWidth);\r\n const hasError = !!errorMessage;\r\n const showHelper = !!helperText && !hasError;\r\n\r\n const labelNode = label ? (\r\n <Label\r\n htmlFor={inputId}\r\n className={cn(\r\n labelVariants({ required: !!required }),\r\n layout === \"horizontal\" && \"mb-0 shrink-0 pt-2\",\r\n layout === \"inline\" && \"mb-0 shrink-0\"\r\n )}\r\n style={layout === \"horizontal\" && labelWidth ? { width: labelWidth } : undefined}\r\n >\r\n {label}\r\n {formConfig.colon && \":\"}\r\n </Label>\r\n ) : null;\r\n\r\n const messages = (\r\n <>\r\n {showError && hasError && (\r\n <p\r\n id={`${inputId}-error`}\r\n className=\"text-sm text-destructive\"\r\n role=\"alert\"\r\n >\r\n {errorMessage}\r\n </p>\r\n )}\r\n\r\n {showHelper && (\r\n <p\r\n id={`${inputId}-helper`}\r\n className=\"text-sm text-muted-foreground\"\r\n >\r\n {helperText}\r\n </p>\r\n )}\r\n </>\r\n );\r\n\r\n if (layout === \"horizontal\") {\r\n return (\r\n <div className={cn(\"space-y-1.5\", fullWidth && \"w-full\")}>\r\n <div className=\"flex items-start gap-4\">\r\n {labelNode}\r\n <div className=\"min-w-0 flex-1 space-y-1.5\">\r\n {children}\r\n {messages}\r\n </div>\r\n </div>\r\n </div>\r\n );\r\n }\r\n\r\n if (layout === \"inline\") {\r\n return (\r\n <div className={cn(\"space-y-1.5\", fullWidth && \"w-full\")}>\r\n <div className=\"flex flex-wrap items-center gap-3\">\r\n {labelNode}\r\n <div className=\"min-w-0 flex-1\">{children}</div>\r\n </div>\r\n {messages}\r\n </div>\r\n );\r\n }\r\n\r\n return (\r\n <div className={cn(\"space-y-1.5\", fullWidth && \"w-full\")}>\r\n {labelNode}\r\n {children}\r\n {messages}\r\n </div>\r\n );\r\n}\r\n"],"mappings":";;;;;;;AAoBA,SAAS,kBAAkB,YAAkD;CAC3E,IAAI,eAAe,KAAA,GACjB;CAGF,OAAO,OAAO,eAAe,WAAW,GAAG,WAAW,MAAM;AAC9D;AAEA,SAAgB,YAAY,EAC1B,SACA,OACA,UACA,YACA,cACA,YAAY,MACZ,YAAY,MACZ,aAAa,CAAC,GACd,YACmB;CACnB,MAAM,SAAS,WAAW,UAAU;CACpC,MAAM,aAAa,kBAAkB,WAAW,UAAU;CAC1D,MAAM,WAAW,CAAC,CAAC;CACnB,MAAM,aAAa,CAAC,CAAC,cAAc,CAAC;CAEpC,MAAM,YAAY,QAChB,iBAAA,GAAA,kBAAA,KAAA,CAAC,cAAA,OAAD;EACE,SAAS;EACT,WAAW,WAAA,GACT,iBAAA,cAAc,EAAE,UAAU,CAAC,CAAC,SAAS,CAAC,GACtC,WAAW,gBAAgB,sBAC3B,WAAW,YAAY,eACzB;EACA,OAAO,WAAW,gBAAgB,aAAa,EAAE,OAAO,WAAW,IAAI,KAAA;YAPzE,CASG,OACA,WAAW,SAAS,GAChB;MACL;CAEJ,MAAM,WACJ,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA,CACG,aAAa,YACZ,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;EACE,IAAI,GAAG,QAAQ;EACf,WAAU;EACV,MAAK;YAEJ;CACA,CAAA,GAGJ,cACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;EACE,IAAI,GAAG,QAAQ;EACf,WAAU;YAET;CACA,CAAA,CAEL,EAAA,CAAA;CAGJ,IAAI,WAAW,cACb,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EAAK,WAAW,WAAA,GAAG,eAAe,aAAa,QAAQ;YACrD,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;GAAK,WAAU;aAAf,CACG,WACD,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;IAAK,WAAU;cAAf,CACG,UACA,QACE;KACF;;CACF,CAAA;CAIT,IAAI,WAAW,UACb,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAW,WAAA,GAAG,eAAe,aAAa,QAAQ;YAAvD,CACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;GAAK,WAAU;aAAf,CACG,WACD,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IAAkB;GAAc,CAAA,CAC5C;MACJ,QACE;;CAIT,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAW,WAAA,GAAG,eAAe,aAAa,QAAQ;YAAvD;GACG;GACA;GACA;EACE;;AAET"}
1
+ {"version":3,"file":"FieldLayout.cjs","names":[],"sources":["../../../../src/components/Form/FieldLayout.tsx"],"sourcesContent":["'use client';\r\n\r\nimport type { ReactNode } from \"react\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport { Label } from \"../../primitives/label\";\r\nimport { labelVariants } from \"./variants\";\r\nimport type { FormConfig } from \"./context\";\r\n\r\nexport interface FieldLayoutProps {\r\n inputId: string;\r\n label?: string;\r\n required?: boolean;\r\n helperText?: string;\r\n errorMessage?: string;\r\n showError?: boolean;\r\n fullWidth?: boolean;\r\n formConfig?: FormConfig;\r\n children: ReactNode;\r\n}\r\n\r\nfunction resolveLabelWidth(labelWidth?: string | number): string | undefined {\r\n if (labelWidth === undefined) {\r\n return undefined;\r\n }\r\n\r\n return typeof labelWidth === \"number\" ? `${labelWidth}px` : labelWidth;\r\n}\r\n\r\nexport function FieldLayout({\r\n inputId,\r\n label,\r\n required,\r\n helperText,\r\n errorMessage,\r\n showError = true,\r\n fullWidth = true,\r\n formConfig = {},\r\n children,\r\n}: FieldLayoutProps) {\r\n const layout = formConfig.layout ?? \"vertical\";\r\n const labelWidth = resolveLabelWidth(formConfig.labelWidth);\r\n const hasError = !!errorMessage;\r\n const showHelper = !!helperText && !hasError;\r\n\r\n const labelNode = label ? (\r\n <Label\r\n htmlFor={inputId}\r\n className={cn(\r\n labelVariants({ required: !!required }),\r\n layout === \"horizontal\" && \"mb-0 shrink-0 pt-2\",\r\n layout === \"inline\" && \"mb-0 shrink-0\"\r\n )}\r\n style={layout === \"horizontal\" && labelWidth ? { width: labelWidth } : undefined}\r\n >\r\n {label}\r\n {formConfig.colon && \":\"}\r\n </Label>\r\n ) : null;\r\n\r\n const messages = (\r\n <>\r\n {showError && hasError && (\r\n <p\r\n id={`${inputId}-error`}\r\n className=\"text-sm text-destructive\"\r\n role=\"alert\"\r\n >\r\n {errorMessage}\r\n </p>\r\n )}\r\n\r\n {showHelper && (\r\n <p\r\n id={`${inputId}-helper`}\r\n className=\"text-sm text-muted-foreground\"\r\n >\r\n {helperText}\r\n </p>\r\n )}\r\n </>\r\n );\r\n\r\n if (layout === \"horizontal\") {\r\n return (\r\n <div className={cn(\"space-y-1.5\", fullWidth && \"w-full\")}>\r\n <div className=\"flex items-start gap-4\">\r\n {labelNode}\r\n <div className=\"min-w-0 flex-1 space-y-1.5\">\r\n {children}\r\n {messages}\r\n </div>\r\n </div>\r\n </div>\r\n );\r\n }\r\n\r\n if (layout === \"inline\") {\r\n return (\r\n <div className={cn(\"space-y-1.5\", fullWidth && \"w-full\")}>\r\n <div className=\"flex flex-wrap items-center gap-3\">\r\n {labelNode}\r\n <div className=\"min-w-0 flex-1\">{children}</div>\r\n </div>\r\n {messages}\r\n </div>\r\n );\r\n }\r\n\r\n return (\r\n <div className={cn(\"space-y-1.5\", fullWidth && \"w-full\")}>\r\n {labelNode}\r\n {children}\r\n {messages}\r\n </div>\r\n );\r\n}\r\n"],"mappings":";;;;;;;AAoBA,SAAS,kBAAkB,YAAkD;CAC3E,I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E;GACF,CAAA,CAAA;;CACF,CAAA;CAIT,IAAI,WAAW,UACb,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAW,WAAA,GAAG,eAAe,aAAa,QAAQ;EAAvD,UAAA,CACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACG,WACD,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IAAkB;GAAc,CAAA,CAC5C;EACJ,CAAA,GAAA,QACE;;CAIT,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAW,WAAA,GAAG,eAAe,aAAa,QAAQ;EAAvD,UAAA;GACG;GACA;GACA;EACE;;AAET"}
@@ -41,15 +41,16 @@ function Form({ schema: baseSchema, defaultValues, values, onSubmit, onError, co
41
41
  const mode = modeProp ?? (mergedConfig.validateOnChange ? "onChange" : mergedConfig.validateOnBlur !== false ? "onBlur" : "onSubmit");
42
42
  const reValidateMode = reValidateModeProp ?? (mergedConfig.validateOnChange ? "onChange" : "onBlur");
43
43
  const { registerFieldValidation, unregisterFieldValidation, getValidationSchema } = require_context.useFieldValidationRegistry();
44
+ const dynamicResolver = (0, react.useCallback)(async (vals, context, options) => {
45
+ if (customResolver) return customResolver(vals, context, options);
46
+ const fieldSchema = getValidationSchema();
47
+ let finalSchema;
48
+ if (baseSchema instanceof zod.z.ZodObject) finalSchema = baseSchema.merge(fieldSchema);
49
+ else finalSchema = baseSchema ?? fieldSchema;
50
+ return (0, _hookform_resolvers_zod.zodResolver)(finalSchema)(vals, context, options);
51
+ }, [baseSchema, customResolver]);
44
52
  const internalForm = (0, react_hook_form.useForm)({
45
- resolver: (0, react.useCallback)(async (vals, context, options) => {
46
- if (customResolver) return customResolver(vals, context, options);
47
- const fieldSchema = getValidationSchema();
48
- let finalSchema;
49
- if (baseSchema instanceof zod.z.ZodObject) finalSchema = baseSchema.merge(fieldSchema);
50
- else finalSchema = baseSchema ?? fieldSchema;
51
- return (0, _hookform_resolvers_zod.zodResolver)(finalSchema)(vals, context, options);
52
- }, [baseSchema, customResolver]),
53
+ resolver: dynamicResolver,
53
54
  defaultValues,
54
55
  values,
55
56
  mode,
@@ -1 +1 @@
1
- {"version":3,"file":"Form.cjs","names":[],"sources":["../../../../src/components/Form/Form.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { useCallback, useMemo, type ReactNode } from \"react\";\r\nimport {\r\n useForm,\r\n FormProvider as RHFFormProvider,\r\n type UseFormReturn,\r\n type FieldValues,\r\n type UseFormProps,\r\n type SubmitHandler,\r\n type SubmitErrorHandler,\r\n type Resolver,\r\n type Path,\r\n} from \"react-hook-form\";\r\nimport { zodResolver } from \"@hookform/resolvers/zod\";\r\nimport { z } from \"zod\";\r\nimport { \r\n FormConfigContext, \r\n defaultFormConfig, \r\n useFieldValidationRegistry,\r\n type FormConfig, \r\n type FormContextValue \r\n} from \"./context\";\r\n\r\n/**\r\n * Props for the Form component\r\n */\r\nexport interface FormProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TContext = unknown\r\n> extends Omit<React.FormHTMLAttributes<HTMLFormElement>, \"onSubmit\" | \"onError\"> {\r\n /** Base Zod schema for validation (will be extended by field props) */\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n schema?: z.ZodType<TFieldValues, any, any>;\r\n /** Default values for the form */\r\n defaultValues?: UseFormProps<TFieldValues, TContext>[\"defaultValues\"];\r\n /** Values to reset the form to */\r\n values?: UseFormProps<TFieldValues, TContext>[\"values\"];\r\n /** Submit handler */\r\n onSubmit?: SubmitHandler<TFieldValues>;\r\n /** Error handler */\r\n onError?: SubmitErrorHandler<TFieldValues>;\r\n /** Form configuration */\r\n config?: FormConfig;\r\n /** Children */\r\n children?: ReactNode;\r\n /** External form instance (for controlled forms) */\r\n form?: UseFormReturn<TFieldValues>;\r\n /** Validation mode */\r\n mode?: UseFormProps<TFieldValues, TContext>[\"mode\"];\r\n /** Revalidation mode */\r\n reValidateMode?: UseFormProps<TFieldValues, TContext>[\"reValidateMode\"];\r\n /** Custom resolver (overrides schema) */\r\n resolver?: Resolver<TFieldValues>;\r\n}\r\n\r\n/**\r\n * Form component that provides form context and validation\r\n * \r\n * Child components like TextBox can register their validation rules automatically.\r\n * \r\n * @example\r\n * ```tsx\r\n * // Validation is automatically built from component props\r\n * <Form onSubmit={handleSubmit} defaultValues={{ username: \"\", email: \"\" }}>\r\n * <TextBox name=\"username\" label=\"Username\" required minLength={3} maxLength={50} />\r\n * <TextBox name=\"email\" label=\"Email\" type=\"email\" required email />\r\n * <Button type=\"submit\">Submit</Button>\r\n * </Form>\r\n * \r\n * // Or with a base schema that gets extended\r\n * const baseSchema = z.object({\r\n * username: z.string(),\r\n * email: z.string(),\r\n * });\r\n * \r\n * <Form schema={baseSchema} onSubmit={handleSubmit}>\r\n * <TextBox name=\"username\" required minLength={3} /> // Adds required + minLength\r\n * <TextBox name=\"email\" required email /> // Adds required + email validation\r\n * </Form>\r\n * ```\r\n */\r\nexport function Form<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TContext = unknown\r\n>({\r\n schema: baseSchema,\r\n defaultValues,\r\n values,\r\n onSubmit,\r\n onError,\r\n config,\r\n children,\r\n form: externalForm,\r\n mode: modeProp,\r\n reValidateMode: reValidateModeProp,\r\n resolver: customResolver,\r\n ...formProps\r\n}: FormProps<TFieldValues, TContext>) {\r\n const mergedConfig = { ...defaultFormConfig, ...config };\r\n\r\n const mode =\r\n modeProp ??\r\n (mergedConfig.validateOnChange\r\n ? \"onChange\"\r\n : mergedConfig.validateOnBlur !== false\r\n ? \"onBlur\"\r\n : \"onSubmit\");\r\n\r\n const reValidateMode =\r\n reValidateModeProp ??\r\n (mergedConfig.validateOnChange ? \"onChange\" : \"onBlur\");\r\n\r\n const {\r\n registerFieldValidation,\r\n unregisterFieldValidation,\r\n getValidationSchema,\r\n } = useFieldValidationRegistry();\r\n\r\n // Stable resolver that reads from fieldsRef at validation time — no re-renders\r\n // needed on field registration, and no race condition with useEffect timing.\r\n const dynamicResolver = useCallback<Resolver<TFieldValues>>(\r\n async (vals, context, options) => {\r\n if (customResolver) {\r\n return customResolver(vals, context, options);\r\n }\r\n const fieldSchema = getValidationSchema();\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n let finalSchema: z.ZodType<any, any, any>;\r\n if (baseSchema instanceof z.ZodObject) {\r\n finalSchema = baseSchema.merge(fieldSchema);\r\n } else {\r\n finalSchema = baseSchema ?? fieldSchema;\r\n }\r\n return zodResolver(finalSchema)(vals, context, options);\r\n },\r\n // getValidationSchema reads a ref — always current, intentionally omitted.\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n [baseSchema, customResolver]\r\n );\r\n\r\n const internalForm = useForm<TFieldValues>({\r\n resolver: dynamicResolver,\r\n defaultValues,\r\n values,\r\n mode,\r\n reValidateMode,\r\n });\r\n\r\n const form = externalForm ?? internalForm;\r\n\r\n // Trigger validation for a specific field\r\n const triggerValidation = useCallback(async (name: string) => {\r\n return form.trigger(name as Path<TFieldValues>);\r\n }, [form]);\r\n\r\n const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {\r\n e.preventDefault();\r\n if (onSubmit) {\r\n form.handleSubmit(onSubmit, onError)(e);\r\n }\r\n };\r\n\r\n const contextValue = useMemo<FormContextValue<TFieldValues>>(\r\n () => ({\r\n form,\r\n registerFieldValidation,\r\n unregisterFieldValidation,\r\n getValidationSchema,\r\n triggerValidation,\r\n showInlineErrors: mergedConfig.showInlineErrors,\r\n validateOnBlur: mergedConfig.validateOnBlur,\r\n validateOnChange: mergedConfig.validateOnChange,\r\n size: mergedConfig.size,\r\n layout: mergedConfig.layout,\r\n labelWidth: mergedConfig.labelWidth,\r\n disabled: mergedConfig.disabled,\r\n colon: mergedConfig.colon,\r\n }),\r\n [\r\n form,\r\n registerFieldValidation,\r\n unregisterFieldValidation,\r\n getValidationSchema,\r\n triggerValidation,\r\n mergedConfig.showInlineErrors,\r\n mergedConfig.validateOnBlur,\r\n mergedConfig.validateOnChange,\r\n mergedConfig.size,\r\n mergedConfig.layout,\r\n mergedConfig.labelWidth,\r\n mergedConfig.disabled,\r\n mergedConfig.colon,\r\n ]\r\n );\r\n\r\n return (\r\n <FormConfigContext.Provider value={contextValue as FormContextValue}>\r\n <RHFFormProvider {...form}>\r\n <form\r\n {...formProps}\r\n onSubmit={handleSubmit}\r\n noValidate\r\n >\r\n {children}\r\n </form>\r\n </RHFFormProvider>\r\n </FormConfigContext.Provider>\r\n );\r\n}\r\n\r\nForm.displayName = \"Form\";\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,KAGd,EACA,QAAQ,YACR,eACA,QACA,UACA,SACA,QACA,UACA,MAAM,cACN,MAAM,UACN,gBAAgB,oBAChB,UAAU,gBACV,GAAG,aACiC;CACpC,MAAM,eAAe;EAAE,GAAG,gBAAA;EAAmB,GAAG;CAAO;CAEvD,MAAM,OACJ,aACC,aAAa,mBACV,aACA,aAAa,mBAAmB,QAC9B,WACA;CAER,MAAM,iBACJ,uBACC,aAAa,mBAAmB,aAAa;CAEhD,MAAM,EACJ,yBACA,2BACA,wBACE,gBAAA,2BAA2B;CAwB/B,MAAM,gBAAA,GAAA,gBAAA,QAAA,CAAqC;EACzC,WAAA,GAAA,MAAA,YAAA,CApBA,OAAO,MAAM,SAAS,YAAY;GAChC,IAAI,gBACF,OAAO,eAAe,MAAM,SAAS,OAAO;GAE9C,MAAM,cAAc,oBAAoB;GAExC,IAAI;GACJ,IAAI,sBAAsB,IAAA,EAAE,WAC1B,cAAc,WAAW,MAAM,WAAW;QAE1C,cAAc,cAAc;GAE9B,QAAA,GAAA,wBAAA,YAAA,CAAmB,WAAW,CAAC,CAAC,MAAM,SAAS,OAAO;EACxD,GAGA,CAAC,YAAY,cAAc,CAIjB;EACV;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,OAAO,gBAAgB;CAG7B,MAAM,qBAAA,GAAA,MAAA,YAAA,CAAgC,OAAO,SAAiB;EAC5D,OAAO,KAAK,QAAQ,IAA0B;CAChD,GAAG,CAAC,IAAI,CAAC;CAET,MAAM,gBAAgB,MAAwC;EAC5D,EAAE,eAAe;EACjB,IAAI,UACF,KAAK,aAAa,UAAU,OAAO,CAAC,CAAC,CAAC;CAE1C;CAEA,MAAM,gBAAA,GAAA,MAAA,QAAA,QACG;EACL;EACA;EACA;EACA;EACA;EACA,kBAAkB,aAAa;EAC/B,gBAAgB,aAAa;EAC7B,kBAAkB,aAAa;EAC/B,MAAM,aAAa;EACnB,QAAQ,aAAa;EACrB,YAAY,aAAa;EACzB,UAAU,aAAa;EACvB,OAAO,aAAa;CACtB,IACA;EACE;EACA;EACA;EACA;EACA;EACA,aAAa;EACb,aAAa;EACb,aAAa;EACb,aAAa;EACb,aAAa;EACb,aAAa;EACb,aAAa;EACb,aAAa;CACf,CACF;CAEA,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAA,kBAAkB,UAAnB;EAA4B,OAAO;YACjC,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAA,cAAD;GAAiB,GAAI;aACnB,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;IACE,GAAI;IACJ,UAAU;IACV,YAAA;IAEC;GACG,CAAA;EACS,CAAA;CACS,CAAA;AAEhC;AAEA,KAAK,cAAc"}
1
+ {"version":3,"file":"Form.cjs","names":[],"sources":["../../../../src/components/Form/Form.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { useCallback, useMemo, type ReactNode } from \"react\";\r\nimport {\r\n useForm,\r\n FormProvider as RHFFormProvider,\r\n type UseFormReturn,\r\n type FieldValues,\r\n type UseFormProps,\r\n type SubmitHandler,\r\n type SubmitErrorHandler,\r\n type Resolver,\r\n type Path,\r\n} from \"react-hook-form\";\r\nimport { zodResolver } from \"@hookform/resolvers/zod\";\r\nimport { z } from \"zod\";\r\nimport { \r\n FormConfigContext, \r\n defaultFormConfig, \r\n useFieldValidationRegistry,\r\n type FormConfig, \r\n type FormContextValue \r\n} from \"./context\";\r\n\r\n/**\r\n * Props for the Form component\r\n */\r\nexport interface FormProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TContext = unknown\r\n> extends Omit<React.FormHTMLAttributes<HTMLFormElement>, \"onSubmit\" | \"onError\"> {\r\n /** Base Zod schema for validation (will be extended by field props) */\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n schema?: z.ZodType<TFieldValues, any, any>;\r\n /** Default values for the form */\r\n defaultValues?: UseFormProps<TFieldValues, TContext>[\"defaultValues\"];\r\n /** Values to reset the form to */\r\n values?: UseFormProps<TFieldValues, TContext>[\"values\"];\r\n /** Submit handler */\r\n onSubmit?: SubmitHandler<TFieldValues>;\r\n /** Error handler */\r\n onError?: SubmitErrorHandler<TFieldValues>;\r\n /** Form configuration */\r\n config?: FormConfig;\r\n /** Children */\r\n children?: ReactNode;\r\n /** External form instance (for controlled forms) */\r\n form?: UseFormReturn<TFieldValues>;\r\n /** Validation mode */\r\n mode?: UseFormProps<TFieldValues, TContext>[\"mode\"];\r\n /** Revalidation mode */\r\n reValidateMode?: UseFormProps<TFieldValues, TContext>[\"reValidateMode\"];\r\n /** Custom resolver (overrides schema) */\r\n resolver?: Resolver<TFieldValues>;\r\n}\r\n\r\n/**\r\n * Form component that provides form context and validation\r\n * \r\n * Child components like TextBox can register their validation rules automatically.\r\n * \r\n * @example\r\n * ```tsx\r\n * // Validation is automatically built from component props\r\n * <Form onSubmit={handleSubmit} defaultValues={{ username: \"\", email: \"\" }}>\r\n * <TextBox name=\"username\" label=\"Username\" required minLength={3} maxLength={50} />\r\n * <TextBox name=\"email\" label=\"Email\" type=\"email\" required email />\r\n * <Button type=\"submit\">Submit</Button>\r\n * </Form>\r\n * \r\n * // Or with a base schema that gets extended\r\n * const baseSchema = z.object({\r\n * username: z.string(),\r\n * email: z.string(),\r\n * });\r\n * \r\n * <Form schema={baseSchema} onSubmit={handleSubmit}>\r\n * <TextBox name=\"username\" required minLength={3} /> // Adds required + minLength\r\n * <TextBox name=\"email\" required email /> // Adds required + email validation\r\n * </Form>\r\n * ```\r\n */\r\nexport function Form<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TContext = unknown\r\n>({\r\n schema: baseSchema,\r\n defaultValues,\r\n values,\r\n onSubmit,\r\n onError,\r\n config,\r\n children,\r\n form: externalForm,\r\n mode: modeProp,\r\n reValidateMode: reValidateModeProp,\r\n resolver: customResolver,\r\n ...formProps\r\n}: FormProps<TFieldValues, TContext>) {\r\n const mergedConfig = { ...defaultFormConfig, ...config };\r\n\r\n const mode =\r\n modeProp ??\r\n (mergedConfig.validateOnChange\r\n ? \"onChange\"\r\n : mergedConfig.validateOnBlur !== false\r\n ? \"onBlur\"\r\n : \"onSubmit\");\r\n\r\n const reValidateMode =\r\n reValidateModeProp ??\r\n (mergedConfig.validateOnChange ? \"onChange\" : \"onBlur\");\r\n\r\n const {\r\n registerFieldValidation,\r\n unregisterFieldValidation,\r\n getValidationSchema,\r\n } = useFieldValidationRegistry();\r\n\r\n // Stable resolver that reads from fieldsRef at validation time — no re-renders\r\n // needed on field registration, and no race condition with useEffect timing.\r\n const dynamicResolver = useCallback<Resolver<TFieldValues>>(\r\n async (vals, context, options) => {\r\n if (customResolver) {\r\n return customResolver(vals, context, options);\r\n }\r\n const fieldSchema = getValidationSchema();\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n let finalSchema: z.ZodType<any, any, any>;\r\n if (baseSchema instanceof z.ZodObject) {\r\n finalSchema = baseSchema.merge(fieldSchema);\r\n } else {\r\n finalSchema = baseSchema ?? fieldSchema;\r\n }\r\n return zodResolver(finalSchema)(vals, context, options);\r\n },\r\n // getValidationSchema reads a ref — always current, intentionally omitted.\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n [baseSchema, customResolver]\r\n );\r\n\r\n const internalForm = useForm<TFieldValues>({\r\n resolver: dynamicResolver,\r\n defaultValues,\r\n values,\r\n mode,\r\n reValidateMode,\r\n });\r\n\r\n const form = externalForm ?? internalForm;\r\n\r\n // Trigger validation for a specific field\r\n const triggerValidation = useCallback(async (name: string) => {\r\n return form.trigger(name as Path<TFieldValues>);\r\n }, [form]);\r\n\r\n const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {\r\n e.preventDefault();\r\n if (onSubmit) {\r\n form.handleSubmit(onSubmit, onError)(e);\r\n }\r\n };\r\n\r\n const contextValue = useMemo<FormContextValue<TFieldValues>>(\r\n () => ({\r\n form,\r\n registerFieldValidation,\r\n unregisterFieldValidation,\r\n getValidationSchema,\r\n triggerValidation,\r\n showInlineErrors: mergedConfig.showInlineErrors,\r\n validateOnBlur: mergedConfig.validateOnBlur,\r\n validateOnChange: mergedConfig.validateOnChange,\r\n size: mergedConfig.size,\r\n layout: mergedConfig.layout,\r\n labelWidth: mergedConfig.labelWidth,\r\n disabled: mergedConfig.disabled,\r\n colon: mergedConfig.colon,\r\n }),\r\n [\r\n form,\r\n registerFieldValidation,\r\n unregisterFieldValidation,\r\n getValidationSchema,\r\n triggerValidation,\r\n mergedConfig.showInlineErrors,\r\n mergedConfig.validateOnBlur,\r\n mergedConfig.validateOnChange,\r\n mergedConfig.size,\r\n mergedConfig.layout,\r\n mergedConfig.labelWidth,\r\n mergedConfig.disabled,\r\n mergedConfig.colon,\r\n ]\r\n );\r\n\r\n return (\r\n <FormConfigContext.Provider value={contextValue as FormContextValue}>\r\n <RHFFormProvider {...form}>\r\n <form\r\n {...formProps}\r\n onSubmit={handleSubmit}\r\n noValidate\r\n >\r\n {children}\r\n </form>\r\n </RHFFormProvider>\r\n </FormConfigContext.Provider>\r\n );\r\n}\r\n\r\nForm.displayName = \"Form\";\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,KAGd,EACA,QAAQ,YACR,eACA,QACA,UACA,SACA,QACA,UACA,MAAM,cACN,MAAM,UACN,gBAAgB,oBAChB,UAAU,gBACV,GAAG,aACiC;CACpC,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aAAa;EACb,aAAa;EACb,aAAa;CACf,CACF;CAEA,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAA,kBAAkB,UAAnB;EAA4B,OAAO;EACjC,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAA,cAAD;GAAiB,GAAI;GACnB,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;IACE,GAAI;IACJ,UAAU;IACV,YAAA;IAEC;GACG,CAAA;EACS,CAAA;CACS,CAAA;AAEhC;AAEA,KAAK,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"FormSwitch.cjs","names":[],"sources":["../../../../src/components/Form/FormSwitch.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { forwardRef, useId, useContext, useEffect } from \"react\";\r\nimport type { ReactNode, ComponentPropsWithoutRef } from \"react\";\r\nimport { useController, useFormContext as useRHFFormContext, type FieldValues, type FieldPath, type Control } from \"react-hook-form\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport { FormConfigContext, type FormConfig, type FieldValidationRules } from \"../Form/context\";\r\nimport { Switch as ShadcnSwitch } from \"../../primitives/switch\";\r\nimport { Label } from \"../../primitives/label\";\r\nimport type * as SwitchPrimitives from \"@radix-ui/react-switch\";\r\n\r\nconst switchSizeVariants = cva(\r\n \"\",\r\n {\r\n variants: {\r\n size: {\r\n sm: \"h-5 w-9\",\r\n md: \"h-6 w-11\",\r\n lg: \"h-7 w-14\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n },\r\n }\r\n);\r\n\r\nconst labelVariants = cva(\r\n \"text-sm font-medium cursor-pointer select-none\",\r\n {\r\n variants: {\r\n disabled: {\r\n true: \"cursor-not-allowed opacity-50\",\r\n false: \"\",\r\n },\r\n },\r\n defaultVariants: {\r\n disabled: false,\r\n },\r\n }\r\n);\r\n\r\nexport interface FormSwitchProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends Omit<ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>, \"name\" | \"checked\" | \"onCheckedChange\" | \"required\">,\r\n VariantProps<typeof switchSizeVariants> {\r\n /** Field name - required for form integration */\r\n name: TName;\r\n /** Label text for the switch */\r\n label?: ReactNode;\r\n /** Helper text displayed below the switch */\r\n helperText?: string;\r\n /** Whether to show the error message */\r\n showError?: boolean;\r\n /** Custom error message (overrides form error) */\r\n error?: string;\r\n /** External control (for use outside Form) */\r\n control?: Control<TFieldValues>;\r\n /** Text to show when checked */\r\n checkedText?: ReactNode;\r\n /** Text to show when unchecked */\r\n uncheckedText?: ReactNode;\r\n\r\n // Validation props\r\n /** Field is required (must be on) */\r\n required?: boolean | string;\r\n /** Custom validation function */\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n}\r\n\r\n/**\r\n * Switch component with form integration\r\n *\r\n * This is a wrapper around the shadcn/ui Switch primitive that adds:\r\n * - Form integration with react-hook-form\r\n * - Automatic validation registration\r\n * - Label, helper text, and error message support\r\n * - Checked/unchecked text display\r\n *\r\n * @example\r\n * ```tsx\r\n * // Inside a Form component\r\n * <FormSwitch name=\"notifications\" label=\"Enable notifications\" />\r\n * <FormSwitch name=\"terms\" label=\"Accept terms\" required=\"You must accept the terms\" />\r\n * <FormSwitch name=\"darkMode\" label=\"Dark mode\" checkedText=\"On\" uncheckedText=\"Off\" />\r\n * ```\r\n */\r\nfunction FormSwitchInner<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(\r\n {\r\n name,\r\n label,\r\n helperText,\r\n showError = true,\r\n error: customError,\r\n size,\r\n className,\r\n disabled,\r\n id: providedId,\r\n control: externalControl,\r\n checkedText,\r\n uncheckedText,\r\n // Validation props\r\n required,\r\n validate,\r\n ...props\r\n }: FormSwitchProps<TFieldValues, TName>,\r\n ref: React.ForwardedRef<React.ElementRef<typeof SwitchPrimitives.Root>>\r\n) {\r\n const generatedId = useId();\r\n const inputId = providedId ?? generatedId;\r\n\r\n // Try to get form context\r\n const formConfigContext = useContext(FormConfigContext);\r\n const formConfig: FormConfig = formConfigContext ?? {};\r\n\r\n // Get form context from react-hook-form\r\n const rhfContext = useRHFFormContext<TFieldValues>();\r\n const control = externalControl ?? rhfContext?.control;\r\n\r\n // Register validation rules with the form\r\n useEffect(() => {\r\n if (formConfigContext?.registerFieldValidation) {\r\n const rules: FieldValidationRules = {};\r\n\r\n if (required !== undefined) rules.required = required;\r\n if (validate !== undefined) rules.validate = validate;\r\n\r\n formConfigContext.registerFieldValidation({\r\n name: name as string,\r\n type: \"boolean\",\r\n rules,\r\n });\r\n\r\n return () => {\r\n formConfigContext.unregisterFieldValidation(name as string);\r\n };\r\n }\r\n }, [formConfigContext, name, required, validate]);\r\n\r\n // Use controller for form integration\r\n const { field, fieldState } = useController<TFieldValues, TName>({\r\n name,\r\n control,\r\n });\r\n\r\n const fieldError = fieldState.error?.message;\r\n const errorMessage = customError ?? fieldError;\r\n const hasError = !!errorMessage;\r\n\r\n // Merge sizes - prop takes precedence over form config\r\n const effectiveSize = size ?? formConfig.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? formConfig.disabled;\r\n const isChecked = field.value ?? false;\r\n\r\n return (\r\n <div className=\"space-y-1.5\">\r\n <div className=\"flex items-center gap-3\">\r\n <ShadcnSwitch\r\n {...props}\r\n ref={ref}\r\n id={inputId}\r\n checked={isChecked}\r\n onCheckedChange={(checked) => field.onChange(checked)}\r\n disabled={effectiveDisabled}\r\n aria-labelledby={label ? `${inputId}-label` : undefined}\r\n className={cn(\r\n switchSizeVariants({ size: effectiveSize }),\r\n className\r\n )}\r\n />\r\n\r\n {(checkedText || uncheckedText) && (\r\n <span className=\"text-sm text-muted-foreground\">\r\n {isChecked ? checkedText : uncheckedText}\r\n </span>\r\n )}\r\n\r\n {label && (\r\n <Label\r\n id={`${inputId}-label`}\r\n htmlFor={inputId}\r\n className={labelVariants({ disabled: effectiveDisabled })}\r\n >\r\n {label}\r\n </Label>\r\n )}\r\n </div>\r\n\r\n {showError && hasError && (\r\n <p className=\"text-sm text-destructive\" role=\"alert\">\r\n {errorMessage}\r\n </p>\r\n )}\r\n\r\n {helperText && !hasError && (\r\n <p className=\"text-sm text-muted-foreground\">\r\n {helperText}\r\n </p>\r\n )}\r\n </div>\r\n );\r\n}\r\n\r\nexport const FormSwitch = forwardRef(FormSwitchInner) as <\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(\r\n props: FormSwitchProps<TFieldValues, TName> & { ref?: React.ForwardedRef<React.ElementRef<typeof SwitchPrimitives.Root>> }\r\n) => React.ReactElement;\r\n\r\n(FormSwitch as React.FC).displayName = \"FormSwitch\";\r\n"],"mappings":";;;;;;;;;;;AAYA,IAAM,sBAAA,GAAA,yBAAA,IAAA,CACJ,IACA;CACE,UAAU,EACR,MAAM;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;CACN,EACF;CACA,iBAAiB,EACf,MAAM,KACR;AACF,CACF;AAEA,IAAM,iBAAA,GAAA,yBAAA,IAAA,CACJ,kDACA;CACE,UAAU,EACR,UAAU;EACR,MAAM;EACN,OAAO;CACT,EACF;CACA,iBAAiB,EACf,UAAU,MACZ;AACF,CACF;;;;;;;;;;;;;;;;;;AAgDA,SAAS,gBAIP,EACE,MACA,OACA,YACA,YAAY,MACZ,OAAO,aACP,MACA,WACA,UACA,IAAI,YACJ,SAAS,iBACT,aACA,eAEA,UACA,UACA,GAAG,SAEL,KACA;CACA,MAAM,eAAA,GAAA,MAAA,MAAA,CAAoB;CAC1B,MAAM,UAAU,cAAc;CAG9B,MAAM,qBAAA,GAAA,MAAA,WAAA,CAA+B,gBAAA,iBAAiB;CACtD,MAAM,aAAyB,qBAAqB,CAAC;CAGrD,MAAM,cAAA,GAAA,gBAAA,eAAA,CAA6C;CACnD,MAAM,UAAU,mBAAmB,Y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;gBAEvD;KACI,CAAA;IAEN;;GAEJ,aAAa,YACZ,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;IAAG,WAAU;IAA2B,MAAK;cAC1C;GACA,CAAA;GAGJ,cAAc,CAAC,YACd,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;IAAG,WAAU;cACV;GACA,CAAA;EAEF;;AAET;AAEA,IAAa,cAAA,GAAA,MAAA,WAAA,CAAwB,eAAe;AAOpD,WAAyB,cAAc"}
1
+ {"version":3,"file":"FormSwitch.cjs","names":[],"sources":["../../../../src/components/Form/FormSwitch.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { forwardRef, useId, useContext, useEffect } from \"react\";\r\nimport type { ReactNode, ComponentPropsWithoutRef } from \"react\";\r\nimport { useController, useFormContext as useRHFFormContext, type FieldValues, type FieldPath, type Control } from \"react-hook-form\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport { FormConfigContext, type FormConfig, type FieldValidationRules } from \"../Form/context\";\r\nimport { Switch as ShadcnSwitch } from \"../../primitives/switch\";\r\nimport { Label } from \"../../primitives/label\";\r\nimport type * as SwitchPrimitives from \"@radix-ui/react-switch\";\r\n\r\nconst switchSizeVariants = cva(\r\n \"\",\r\n {\r\n variants: {\r\n size: {\r\n sm: \"h-5 w-9\",\r\n md: \"h-6 w-11\",\r\n lg: \"h-7 w-14\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n },\r\n }\r\n);\r\n\r\nconst labelVariants = cva(\r\n \"text-sm font-medium cursor-pointer select-none\",\r\n {\r\n variants: {\r\n disabled: {\r\n true: \"cursor-not-allowed opacity-50\",\r\n false: \"\",\r\n },\r\n },\r\n defaultVariants: {\r\n disabled: false,\r\n },\r\n }\r\n);\r\n\r\nexport interface FormSwitchProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends Omit<ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>, \"name\" | \"checked\" | \"onCheckedChange\" | \"required\">,\r\n VariantProps<typeof switchSizeVariants> {\r\n /** Field name - required for form integration */\r\n name: TName;\r\n /** Label text for the switch */\r\n label?: ReactNode;\r\n /** Helper text displayed below the switch */\r\n helperText?: string;\r\n /** Whether to show the error message */\r\n showError?: boolean;\r\n /** Custom error message (overrides form error) */\r\n error?: string;\r\n /** External control (for use outside Form) */\r\n control?: Control<TFieldValues>;\r\n /** Text to show when checked */\r\n checkedText?: ReactNode;\r\n /** Text to show when unchecked */\r\n uncheckedText?: ReactNode;\r\n\r\n // Validation props\r\n /** Field is required (must be on) */\r\n required?: boolean | string;\r\n /** Custom validation function */\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n}\r\n\r\n/**\r\n * Switch component with form integration\r\n *\r\n * This is a wrapper around the shadcn/ui Switch primitive that adds:\r\n * - Form integration with react-hook-form\r\n * - Automatic validation registration\r\n * - Label, helper text, and error message support\r\n * - Checked/unchecked text display\r\n *\r\n * @example\r\n * ```tsx\r\n * // Inside a Form component\r\n * <FormSwitch name=\"notifications\" label=\"Enable notifications\" />\r\n * <FormSwitch name=\"terms\" label=\"Accept terms\" required=\"You must accept the terms\" />\r\n * <FormSwitch name=\"darkMode\" label=\"Dark mode\" checkedText=\"On\" uncheckedText=\"Off\" />\r\n * ```\r\n */\r\nfunction FormSwitchInner<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(\r\n {\r\n name,\r\n label,\r\n helperText,\r\n showError = true,\r\n error: customError,\r\n size,\r\n className,\r\n disabled,\r\n id: providedId,\r\n control: externalControl,\r\n checkedText,\r\n uncheckedText,\r\n // Validation props\r\n required,\r\n validate,\r\n ...props\r\n }: FormSwitchProps<TFieldValues, TName>,\r\n ref: React.ForwardedRef<React.ElementRef<typeof SwitchPrimitives.Root>>\r\n) {\r\n const generatedId = useId();\r\n const inputId = providedId ?? generatedId;\r\n\r\n // Try to get form context\r\n const formConfigContext = useContext(FormConfigContext);\r\n const formConfig: FormConfig = formConfigContext ?? {};\r\n\r\n // Get form context from react-hook-form\r\n const rhfContext = useRHFFormContext<TFieldValues>();\r\n const control = externalControl ?? rhfContext?.control;\r\n\r\n // Register validation rules with the form\r\n useEffect(() => {\r\n if (formConfigContext?.registerFieldValidation) {\r\n const rules: FieldValidationRules = {};\r\n\r\n if (required !== undefined) rules.required = required;\r\n if (validate !== undefined) rules.validate = validate;\r\n\r\n formConfigContext.registerFieldValidation({\r\n name: name as string,\r\n type: \"boolean\",\r\n rules,\r\n });\r\n\r\n return () => {\r\n formConfigContext.unregisterFieldValidation(name as string);\r\n };\r\n }\r\n }, [formConfigContext, name, required, validate]);\r\n\r\n // Use controller for form integration\r\n const { field, fieldState } = useController<TFieldValues, TName>({\r\n name,\r\n control,\r\n });\r\n\r\n const fieldError = fieldState.error?.message;\r\n const errorMessage = customError ?? fieldError;\r\n const hasError = !!errorMessage;\r\n\r\n // Merge sizes - prop takes precedence over form config\r\n const effectiveSize = size ?? formConfig.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? formConfig.disabled;\r\n const isChecked = field.value ?? false;\r\n\r\n return (\r\n <div className=\"space-y-1.5\">\r\n <div className=\"flex items-center gap-3\">\r\n <ShadcnSwitch\r\n {...props}\r\n ref={ref}\r\n id={inputId}\r\n checked={isChecked}\r\n onCheckedChange={(checked) => field.onChange(checked)}\r\n disabled={effectiveDisabled}\r\n aria-labelledby={label ? `${inputId}-label` : undefined}\r\n className={cn(\r\n switchSizeVariants({ size: effectiveSize }),\r\n className\r\n )}\r\n />\r\n\r\n {(checkedText || uncheckedText) && (\r\n <span className=\"text-sm text-muted-foreground\">\r\n {isChecked ? checkedText : uncheckedText}\r\n </span>\r\n )}\r\n\r\n {label && (\r\n <Label\r\n id={`${inputId}-label`}\r\n htmlFor={inputId}\r\n className={labelVariants({ disabled: effectiveDisabled })}\r\n >\r\n {label}\r\n </Label>\r\n )}\r\n </div>\r\n\r\n {showError && hasError && (\r\n <p className=\"text-sm text-destructive\" role=\"alert\">\r\n {errorMessage}\r\n </p>\r\n )}\r\n\r\n {helperText && !hasError && (\r\n <p className=\"text-sm text-muted-foreground\">\r\n {helperText}\r\n </p>\r\n )}\r\n </div>\r\n );\r\n}\r\n\r\nexport const FormSwitch = forwardRef(FormSwitchInner) as <\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(\r\n props: FormSwitchProps<TFieldValues, TName> & { ref?: React.ForwardedRef<React.ElementRef<typeof SwitchPrimitives.Root>> }\r\n) => React.ReactElement;\r\n\r\n(FormSwitch as React.FC).displayName = \"FormSwitch\";\r\n"],"mappings":";;;;;;;;;;;AAYA,IAAM,sBAAA,GAAqB,yBAAA,IAAA,CACzB,IACA;CACE,UAAU,EACR,MAAM;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;CACN,EACF;CACA,iBAAiB,EACf,MAAM,KACR;AACF,CACF;AAEA,IAAM,iBAAA,GAAgB,yBAAA,IAAA,CACpB,kDACA;CACE,UAAU,EACR,UAAU;EACR,MAAM;EACN,OAAO;CACT,EACF;CACA,iBAAiB,EACf,UAAU,MACZ;AACF,CACF;;;;;;;;;;;;;;;;;;AAgDA,SAAS,gBAIP,EACE,MACA,OACA,YACA,YAAY,MACZ,OAAO,aACP,MACA,WACA,UACA,IAAI,YACJ,SAAS,iBACT,aACA,eAEA,UACA,UACA,GAAG,SAEL,KACA;CACA,MAAM,eAAA,GAAc,MAAA,MAAA,CAAM;CAC1B,MAAM,UAAU,cAAc;CAG9B,MAAM,qBAAA,GAAoB,MAAA,WAAA,CAAW,gBAAA,iBAAiB;CACtD,MAAM,aAAyB,qBAAqB,CAAC;CAGrD,MAAM,cAAA,GAAa,gBAAA,eAAA,CAAgC;CACnD,MAAM,UAAU,mBAAmB,YAAY;CAG/C,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd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;;GAEJ,aAAa,YACZ,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;IAAG,WAAU;IAA2B,MAAK;IAC1C,UAAA;GACA,CAAA;GAGJ,cAAc,CAAC,YACd,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;IAAG,WAAU;IACV,UAAA;GACA,CAAA;EAEF;;AAET;AAEA,IAAa,cAAA,GAAa,MAAA,WAAA,CAAW,eAAe;AAOpD,WAAyB,cAAc"}
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ "use client";
3
+ let react_jsx_runtime = require("react/jsx-runtime");
4
+ let lucide_react = require("lucide-react");
5
+ //#region src/components/Form/PasswordRevealToggle.tsx
6
+ function PasswordRevealToggle({ visible, onToggle, disabled = false }) {
7
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
8
+ type: "button",
9
+ onClick: onToggle,
10
+ disabled,
11
+ className: "text-muted-foreground hover:text-foreground transition-colors disabled:pointer-events-none disabled:opacity-50",
12
+ tabIndex: -1,
13
+ "aria-label": visible ? "Hide password" : "Show password",
14
+ "aria-pressed": visible,
15
+ children: visible ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.EyeOff, { className: "h-4 w-4" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Eye, { className: "h-4 w-4" })
16
+ });
17
+ }
18
+ //#endregion
19
+ exports.PasswordRevealToggle = PasswordRevealToggle;
20
+
21
+ //# sourceMappingURL=PasswordRevealToggle.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PasswordRevealToggle.cjs","names":[],"sources":["../../../../src/components/Form/PasswordRevealToggle.tsx"],"sourcesContent":["\"use client\";\n\nimport { Eye, EyeOff } from \"lucide-react\";\n\nexport interface PasswordRevealToggleProps {\n\tvisible: boolean;\n\tonToggle: () => void;\n\tdisabled?: boolean;\n}\n\nexport function PasswordRevealToggle({\n\tvisible,\n\tonToggle,\n\tdisabled = false,\n}: PasswordRevealToggleProps) {\n\treturn (\n\t\t<button\n\t\t\ttype=\"button\"\n\t\t\tonClick={onToggle}\n\t\t\tdisabled={disabled}\n\t\t\tclassName=\"text-muted-foreground hover:text-foreground transition-colors disabled:pointer-events-none disabled:opacity-50\"\n\t\t\ttabIndex={-1}\n\t\t\taria-label={visible ? \"Hide password\" : \"Show password\"}\n\t\t\taria-pressed={visible}\n\t\t>\n\t\t\t{visible ? <EyeOff className=\"h-4 w-4\" /> : <Eye className=\"h-4 w-4\" />}\n\t\t</button>\n\t);\n}\n"],"mappings":";;;;;AAUA,SAAgB,qBAAqB,EACpC,SACA,UACA,WAAW,SACkB;CAC7B,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;EACC,MAAK;EACL,SAAS;EACC;EACV,WAAU;EACV,UAAU;EACV,cAAY,UAAU,kBAAkB;EACxC,gBAAc;EAEb,UAAA,UAAU,iBAAA,GAAA,kBAAA,IAAA,CAAC,aAAA,QAAD,EAAQ,WAAU,UAAW,CAAA,IAAI,iBAAA,GAAA,kBAAA,IAAA,CAAC,aAAA,KAAD,EAAK,WAAU,UAAW,CAAA;CAC/D,CAAA;AAEV"}
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneInput.cjs","names":[],"sources":["../../../../src/components/Form/PhoneInput.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { useContext, useEffect, useId, useMemo, useState } from \"react\";\r\nimport { useController, useFormContext as useRHFFormContext, type Control, type FieldPath, type FieldValues } from \"react-hook-form\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport {\r\n formatE164,\r\n getCountryDialCode,\r\n parseE164,\r\n} from \"../../data/countries\";\r\nimport { TextBoxPrimitive } from \"../../primitives/textbox\";\r\nimport { FormConfigContext, type FieldValidationRules, type FormConfig } from \"./context\";\r\nimport { FieldLayout } from \"./FieldLayout\";\r\nimport { CountryPicker } from \"./CountryPicker\";\r\n\r\nconst phoneInputVariants = cva(\"\", {\r\n variants: {\r\n size: {\r\n sm: \"h-8 text-xs\",\r\n md: \"h-10 text-sm\",\r\n lg: \"h-12 text-base\",\r\n },\r\n variant: {\r\n default: \"border-input focus-within:ring-ring\",\r\n error: \"border-destructive focus-within:ring-destructive\",\r\n success: \"border-green-500 focus-within:ring-green-500\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n variant: \"default\",\r\n },\r\n});\r\n\r\ntype ValidationRule<T> = T | { value: T; message: string };\r\n\r\nexport interface PhoneInputProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends VariantProps<typeof phoneInputVariants> {\r\n name: TName;\r\n label?: string;\r\n helperText?: string;\r\n showError?: boolean;\r\n error?: string;\r\n fullWidth?: boolean;\r\n placeholder?: string;\r\n disabled?: boolean;\r\n className?: string;\r\n id?: string;\r\n control?: Control<TFieldValues>;\r\n defaultCountry?: string;\r\n priorityCountries?: string[];\r\n /** Field is required (`true` or custom error message string) */\r\n required?: boolean | string;\r\n /** Minimum national number length */\r\n minLength?: ValidationRule<number>;\r\n /** Maximum national number length */\r\n maxLength?: ValidationRule<number>;\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n}\r\n\r\nfunction getValidationRuleValue<T>(\r\n rule: ValidationRule<T> | undefined,\r\n defaultMessage: string\r\n): { value: T; message: string } | null {\r\n if (rule === undefined) {\r\n return null;\r\n }\r\n\r\n if (typeof rule === \"object\" && rule !== null && \"value\" in rule) {\r\n return rule as { value: T; message: string };\r\n }\r\n\r\n return { value: rule as T, message: defaultMessage };\r\n}\r\n\r\nfunction buildPhoneValidate(\r\n required: boolean | string | undefined,\r\n minLength: ValidationRule<number> | undefined,\r\n maxLength: ValidationRule<number> | undefined,\r\n validate: PhoneInputProps[\"validate\"]\r\n) {\r\n const requiredMessage =\r\n typeof required === \"string\" ? required : \"This field is required\";\r\n\r\n return async (value: unknown) => {\r\n const parsed = parseE164(String(value ?? \"\"));\r\n const nationalNumber = parsed?.nationalNumber ?? \"\";\r\n\r\n if (required !== undefined && !nationalNumber) {\r\n return requiredMessage;\r\n }\r\n\r\n const minLengthRule = getValidationRuleValue(\r\n minLength,\r\n `Minimum ${typeof minLength === \"number\" ? minLength : minLength?.value} digits required`\r\n );\r\n if (minLengthRule && nationalNumber.length < minLengthRule.value) {\r\n return minLengthRule.message;\r\n }\r\n\r\n const maxLengthRule = getValidationRuleValue(\r\n maxLength,\r\n `Maximum ${typeof maxLength === \"number\" ? maxLength : maxLength?.value} digits allowed`\r\n );\r\n if (maxLengthRule && nationalNumber.length > maxLengthRule.value) {\r\n return maxLengthRule.message;\r\n }\r\n\r\n if (validate) {\r\n return validate(value);\r\n }\r\n\r\n return true;\r\n };\r\n}\r\n\r\nexport function PhoneInput<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>({\r\n name,\r\n label,\r\n helperText,\r\n showError = true,\r\n error: customError,\r\n size,\r\n variant,\r\n fullWidth = true,\r\n placeholder = \"Mobile number\",\r\n disabled,\r\n className,\r\n id: providedId,\r\n control: externalControl,\r\n defaultCountry = \"IN\",\r\n priorityCountries,\r\n required,\r\n minLength,\r\n maxLength,\r\n validate,\r\n}: PhoneInputProps<TFieldValues, TName>) {\r\n const generatedId = useId();\r\n const inputId = providedId ?? generatedId;\r\n const formConfigContext = useContext(FormConfigContext);\r\n const formConfig: FormConfig = formConfigContext ?? {};\r\n const rhfContext = useRHFFormContext<TFieldValues>();\r\n const control = externalControl ?? rhfContext?.control;\r\n\r\n const registerFieldValidation = formConfigContext?.registerFieldValidation;\r\n const unregisterFieldValidation = formConfigContext?.unregisterFieldValidation;\r\n\r\n useEffect(() => {\r\n if (registerFieldValidation) {\r\n const rules: FieldValidationRules = {};\r\n if (required !== undefined) rules.required = required;\r\n\r\n if (\r\n required !== undefined ||\r\n minLength !== undefined ||\r\n maxLength !== undefined ||\r\n validate !== undefined\r\n ) {\r\n rules.validate = buildPhoneValidate(required, minLength, maxLength, validate);\r\n }\r\n\r\n registerFieldValidation({\r\n name: name as string,\r\n type: \"string\",\r\n rules,\r\n });\r\n\r\n return () => {\r\n unregisterFieldValidation?.(name as string);\r\n };\r\n }\r\n }, [\r\n registerFieldValidation,\r\n unregisterFieldValidation,\r\n name,\r\n required,\r\n minLength,\r\n maxLength,\r\n validate,\r\n ]);\r\n\r\n const { field, fieldState } = useController<TFieldValues, TName>({\r\n name,\r\n control,\r\n });\r\n\r\n const parsedValue = useMemo(() => parseE164(field.value ?? \"\"), [field.value]);\r\n const [countryCode, setCountryCode] = useState(\r\n parsedValue?.countryCode ?? defaultCountry\r\n );\r\n const [nationalNumber, setNationalNumber] = useState(parsedValue?.nationalNumber ?? \"\");\r\n\r\n useEffect(() => {\r\n const parsed = parseE164(field.value ?? \"\");\r\n if (parsed) {\r\n setCountryCode(parsed.countryCode);\r\n setNationalNumber(parsed.nationalNumber);\r\n return;\r\n }\r\n\r\n if (!field.value) {\r\n setCountryCode(defaultCountry);\r\n setNationalNumber(\"\");\r\n }\r\n }, [field.value, defaultCountry]);\r\n\r\n const fieldError = fieldState.error?.message;\r\n const errorMessage = customError ?? fieldError;\r\n const hasError = !!errorMessage;\r\n const effectiveSize = size ?? formConfig.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? formConfig.disabled;\r\n const effectiveVariant = hasError ? \"error\" : variant;\r\n const dialCode = getCountryDialCode(countryCode);\r\n\r\n const updateValue = (nextCountryCode: string, nextNationalNumber: string) => {\r\n setCountryCode(nextCountryCode);\r\n setNationalNumber(nextNationalNumber);\r\n field.onChange(formatE164(nextCountryCode, nextNationalNumber));\r\n };\r\n\r\n return (\r\n <FieldLayout\r\n inputId={inputId}\r\n label={label}\r\n required={!!required}\r\n helperText={helperText}\r\n errorMessage={showError ? errorMessage : undefined}\r\n showError={showError}\r\n fullWidth={fullWidth}\r\n formConfig={formConfig}\r\n >\r\n <div\r\n className={cn(\r\n \"flex items-stretch overflow-hidden rounded-md border bg-background focus-within:ring-2 focus-within:ring-offset-2\",\r\n phoneInputVariants({ size: effectiveSize, variant: effectiveVariant }),\r\n className\r\n )}\r\n >\r\n <CountryPicker\r\n compact\r\n value={countryCode}\r\n onValueChange={(value) => updateValue(value, nationalNumber)}\r\n disabled={effectiveDisabled}\r\n priorityCountries={priorityCountries}\r\n required={!!required}\r\n aria-invalid={hasError}\r\n aria-describedby={\r\n hasError\r\n ? `${inputId}-error`\r\n : helperText\r\n ? `${inputId}-helper`\r\n : undefined\r\n }\r\n />\r\n\r\n <div className=\"flex items-center border-l px-3 text-sm text-muted-foreground\">\r\n {dialCode}\r\n </div>\r\n\r\n <TextBoxPrimitive\r\n id={inputId}\r\n type=\"tel\"\r\n inputMode=\"numeric\"\r\n autoComplete=\"tel-national\"\r\n value={nationalNumber}\r\n onChange={(event) => {\r\n const digits = event.target.value.replace(/\\D/g, \"\");\r\n updateValue(countryCode, digits);\r\n }}\r\n placeholder={placeholder}\r\n disabled={effectiveDisabled}\r\n aria-required={!!required}\r\n aria-invalid={hasError}\r\n aria-describedby={\r\n hasError\r\n ? `${inputId}-error`\r\n : helperText\r\n ? `${inputId}-helper`\r\n : undefined\r\n }\r\n className={cn(\r\n \"h-full min-w-0 flex-1 border-0 bg-transparent px-3 shadow-none focus-visible:ring-0 focus-visible:ring-offset-0\"\r\n )}\r\n />\r\n </div>\r\n </FieldLayout>\r\n );\r\n}\r\n\r\nPhoneInput.displayName = \"PhoneInput\";\r\n"],"mappings":";;;;;;;;;;;;;AAgBA,IAAM,sBAAA,GAAA,yBAAA,IAAA,CAAyB,IAAI;CACjC,UAAU;EACR,MAAM;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;EACN;EACA,SAAS;GACP,SAAS;GACT,OAAO;GACP,SAAS;EACX;CACF;CACA,iBAAiB;EACf,MAAM;EACN,SAAS;CACX;AACF,CAAC;AA8BD,SAAS,uBACP,MACA,gBACsC;CACtC,IAAI,SAAS,KAAA,GACX,OAAO;CAGT,I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B,kBAAkB;EACpC,MAAM,SAAS,kBAAA,WAAW,iBAAiB,kBAAkB,CAAC;CAChE;CAEA,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,oBAAA,aAAD;EACW;EACF;EACP,UAAU,CAAC,CAAC;EACA;EACZ,cAAc,YAAY,eAAe,KAAA;EAC9B;EACA;EACC;YAEZ,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;GACE,WAAW,WAAA,GACT,qHACA,mBAAmB;IAAE,MAAM;IAAe,SAAS;GAAiB,CAAC,GACrE,SACF;aALF;IAOE,iBAAA,GAAA,kBAAA,IAAA,CAAC,sBAAA,eAAD;KACE,SAAA;KACA,OAAO;KACP,gBAAgB,UAAU,YAAY,OAAO,cAAc;KAC3D,UAAU;KACS;KACnB,UAAU,CAAC,CAAC;KACZ,gBAAc;KACd,oBACE,WACI,GAAG,QAAQ,UACX,aACE,GAAG,QAAQ,WACX,KAAA;IAET,CAAA;IAED,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;KAAK,WAAU;eACZ;IACE,CAAA;IAEL,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAA,kBAAD;KACE,IAAI;KACJ,MAAK;KACL,WAAU;KACV,cAAa;KACb,OAAO;KACP,WAAW,UAAU;MACnB,MAAM,SAAS,MAAM,OAAO,MAAM,QAAQ,OAAO,EAAE;MACnD,YAAY,aAAa,MAAM;KACjC;KACa;KACb,UAAU;KACV,iBAAe,CAAC,CAAC;KACjB,gBAAc;KACd,oBACE,WACI,GAAG,QAAQ,UACX,aACE,GAAG,QAAQ,WACX,KAAA;KAER,WAAW,WAAA,GACT,iHACF;IACD,CAAA;GACE;;CACM,CAAA;AAEjB;AAEA,WAAW,cAAc"}
1
+ {"version":3,"file":"PhoneInput.cjs","names":[],"sources":["../../../../src/components/Form/PhoneInput.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { useContext, useEffect, useId, useMemo, useState } from \"react\";\r\nimport { useController, useFormContext as useRHFFormContext, type Control, type FieldPath, type FieldValues } from \"react-hook-form\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport {\r\n formatE164,\r\n getCountryDialCode,\r\n parseE164,\r\n} from \"../../data/countries\";\r\nimport { TextBoxPrimitive } from \"../../primitives/textbox\";\r\nimport { FormConfigContext, type FieldValidationRules, type FormConfig } from \"./context\";\r\nimport { FieldLayout } from \"./FieldLayout\";\r\nimport { CountryPicker } from \"./CountryPicker\";\r\n\r\nconst phoneInputVariants = cva(\"\", {\r\n variants: {\r\n size: {\r\n sm: \"h-8 text-xs\",\r\n md: \"h-10 text-sm\",\r\n lg: \"h-12 text-base\",\r\n },\r\n variant: {\r\n default: \"border-input focus-within:ring-ring\",\r\n error: \"border-destructive focus-within:ring-destructive\",\r\n success: \"border-green-500 focus-within:ring-green-500\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n variant: \"default\",\r\n },\r\n});\r\n\r\ntype ValidationRule<T> = T | { value: T; message: string };\r\n\r\nexport interface PhoneInputProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends VariantProps<typeof phoneInputVariants> {\r\n name: TName;\r\n label?: string;\r\n helperText?: string;\r\n showError?: boolean;\r\n error?: string;\r\n fullWidth?: boolean;\r\n placeholder?: string;\r\n disabled?: boolean;\r\n className?: string;\r\n id?: string;\r\n control?: Control<TFieldValues>;\r\n defaultCountry?: string;\r\n priorityCountries?: string[];\r\n /** Field is required (`true` or custom error message string) */\r\n required?: boolean | string;\r\n /** Minimum national number length */\r\n minLength?: ValidationRule<number>;\r\n /** Maximum national number length */\r\n maxLength?: ValidationRule<number>;\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n}\r\n\r\nfunction getValidationRuleValue<T>(\r\n rule: ValidationRule<T> | undefined,\r\n defaultMessage: string\r\n): { value: T; message: string } | null {\r\n if (rule === undefined) {\r\n return null;\r\n }\r\n\r\n if (typeof rule === \"object\" && rule !== null && \"value\" in rule) {\r\n return rule as { value: T; message: string };\r\n }\r\n\r\n return { value: rule as T, message: defaultMessage };\r\n}\r\n\r\nfunction buildPhoneValidate(\r\n required: boolean | string | undefined,\r\n minLength: ValidationRule<number> | undefined,\r\n maxLength: ValidationRule<number> | undefined,\r\n validate: PhoneInputProps[\"validate\"]\r\n) {\r\n const requiredMessage =\r\n typeof required === \"string\" ? required : \"This field is required\";\r\n\r\n return async (value: unknown) => {\r\n const parsed = parseE164(String(value ?? \"\"));\r\n const nationalNumber = parsed?.nationalNumber ?? \"\";\r\n\r\n if (required !== undefined && !nationalNumber) {\r\n return requiredMessage;\r\n }\r\n\r\n const minLengthRule = getValidationRuleValue(\r\n minLength,\r\n `Minimum ${typeof minLength === \"number\" ? minLength : minLength?.value} digits required`\r\n );\r\n if (minLengthRule && nationalNumber.length < minLengthRule.value) {\r\n return minLengthRule.message;\r\n }\r\n\r\n const maxLengthRule = getValidationRuleValue(\r\n maxLength,\r\n `Maximum ${typeof maxLength === \"number\" ? maxLength : maxLength?.value} digits allowed`\r\n );\r\n if (maxLengthRule && nationalNumber.length > maxLengthRule.value) {\r\n return maxLengthRule.message;\r\n }\r\n\r\n if (validate) {\r\n return validate(value);\r\n }\r\n\r\n return true;\r\n };\r\n}\r\n\r\nexport function PhoneInput<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>({\r\n name,\r\n label,\r\n helperText,\r\n showError = true,\r\n error: customError,\r\n size,\r\n variant,\r\n fullWidth = true,\r\n placeholder = \"Mobile number\",\r\n disabled,\r\n className,\r\n id: providedId,\r\n control: externalControl,\r\n defaultCountry = \"IN\",\r\n priorityCountries,\r\n required,\r\n minLength,\r\n maxLength,\r\n validate,\r\n}: PhoneInputProps<TFieldValues, TName>) {\r\n const generatedId = useId();\r\n const inputId = providedId ?? generatedId;\r\n const formConfigContext = useContext(FormConfigContext);\r\n const formConfig: FormConfig = formConfigContext ?? {};\r\n const rhfContext = useRHFFormContext<TFieldValues>();\r\n const control = externalControl ?? rhfContext?.control;\r\n\r\n const registerFieldValidation = formConfigContext?.registerFieldValidation;\r\n const unregisterFieldValidation = formConfigContext?.unregisterFieldValidation;\r\n\r\n useEffect(() => {\r\n if (registerFieldValidation) {\r\n const rules: FieldValidationRules = {};\r\n if (required !== undefined) rules.required = required;\r\n\r\n if (\r\n required !== undefined ||\r\n minLength !== undefined ||\r\n maxLength !== undefined ||\r\n validate !== undefined\r\n ) {\r\n rules.validate = buildPhoneValidate(required, minLength, maxLength, validate);\r\n }\r\n\r\n registerFieldValidation({\r\n name: name as string,\r\n type: \"string\",\r\n rules,\r\n });\r\n\r\n return () => {\r\n unregisterFieldValidation?.(name as string);\r\n };\r\n }\r\n }, [\r\n registerFieldValidation,\r\n unregisterFieldValidation,\r\n name,\r\n required,\r\n minLength,\r\n maxLength,\r\n validate,\r\n ]);\r\n\r\n const { field, fieldState } = useController<TFieldValues, TName>({\r\n name,\r\n control,\r\n });\r\n\r\n const parsedValue = useMemo(() => parseE164(field.value ?? \"\"), [field.value]);\r\n const [countryCode, setCountryCode] = useState(\r\n parsedValue?.countryCode ?? defaultCountry\r\n );\r\n const [nationalNumber, setNationalNumber] = useState(parsedValue?.nationalNumber ?? \"\");\r\n\r\n useEffect(() => {\r\n const parsed = parseE164(field.value ?? \"\");\r\n if (parsed) {\r\n setCountryCode(parsed.countryCode);\r\n setNationalNumber(parsed.nationalNumber);\r\n return;\r\n }\r\n\r\n if (!field.value) {\r\n setCountryCode(defaultCountry);\r\n setNationalNumber(\"\");\r\n }\r\n }, [field.value, defaultCountry]);\r\n\r\n const fieldError = fieldState.error?.message;\r\n const errorMessage = customError ?? fieldError;\r\n const hasError = !!errorMessage;\r\n const effectiveSize = size ?? formConfig.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? formConfig.disabled;\r\n const effectiveVariant = hasError ? \"error\" : variant;\r\n const dialCode = getCountryDialCode(countryCode);\r\n\r\n const updateValue = (nextCountryCode: string, nextNationalNumber: string) => {\r\n setCountryCode(nextCountryCode);\r\n setNationalNumber(nextNationalNumber);\r\n field.onChange(formatE164(nextCountryCode, nextNationalNumber));\r\n };\r\n\r\n return (\r\n <FieldLayout\r\n inputId={inputId}\r\n label={label}\r\n required={!!required}\r\n helperText={helperText}\r\n errorMessage={showError ? errorMessage : undefined}\r\n showError={showError}\r\n fullWidth={fullWidth}\r\n formConfig={formConfig}\r\n >\r\n <div\r\n className={cn(\r\n \"flex items-stretch overflow-hidden rounded-md border bg-background focus-within:ring-2 focus-within:ring-offset-2\",\r\n phoneInputVariants({ size: effectiveSize, variant: effectiveVariant }),\r\n className\r\n )}\r\n >\r\n <CountryPicker\r\n compact\r\n value={countryCode}\r\n onValueChange={(value) => updateValue(value, nationalNumber)}\r\n disabled={effectiveDisabled}\r\n priorityCountries={priorityCountries}\r\n required={!!required}\r\n aria-invalid={hasError}\r\n aria-describedby={\r\n hasError\r\n ? `${inputId}-error`\r\n : helperText\r\n ? `${inputId}-helper`\r\n : undefined\r\n }\r\n />\r\n\r\n <div className=\"flex items-center border-l px-3 text-sm text-muted-foreground\">\r\n {dialCode}\r\n </div>\r\n\r\n <TextBoxPrimitive\r\n id={inputId}\r\n type=\"tel\"\r\n inputMode=\"numeric\"\r\n autoComplete=\"tel-national\"\r\n value={nationalNumber}\r\n onChange={(event) => {\r\n const digits = event.target.value.replace(/\\D/g, \"\");\r\n updateValue(countryCode, digits);\r\n }}\r\n placeholder={placeholder}\r\n disabled={effectiveDisabled}\r\n aria-required={!!required}\r\n aria-invalid={hasError}\r\n aria-describedby={\r\n hasError\r\n ? `${inputId}-error`\r\n : helperText\r\n ? `${inputId}-helper`\r\n : undefined\r\n }\r\n className={cn(\r\n \"h-full min-w-0 flex-1 border-0 bg-transparent px-3 shadow-none focus-visible:ring-0 focus-visible:ring-offset-0\"\r\n )}\r\n />\r\n </div>\r\n </FieldLayout>\r\n );\r\n}\r\n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KACjC;KACa;KACb,UAAU;KACV,iBAAe,CAAC,CAAC;KACjB,gBAAc;KACd,oBACE,WACI,GAAG,QAAQ,UACX,aACE,GAAG,QAAQ,WACX,KAAA;KAER,WAAW,WAAA,GACT,iHACF;IACD,CAAA;GACE;;CACM,CAAA;AAEjB;AAEA,WAAW,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"Radio.cjs","names":[],"sources":["../../../../src/components/Form/Radio.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { forwardRef, useId, useContext, createContext, useEffect } from \"react\";\r\nimport type { ReactNode, ComponentPropsWithoutRef } from \"react\";\r\nimport { useController, useFormContext as useRHFFormContext, type FieldValues, type FieldPath, type Control } from \"react-hook-form\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport { FormConfigContext, type FormConfig, type FieldValidationRules } from \"../Form/context\";\r\nimport { RadioGroup as ShadcnRadioGroup, RadioGroupItem as ShadcnRadioGroupItem } from \"../../primitives/radio-group\";\r\nimport { Label } from \"../../primitives/label\";\r\nimport type * as RadioGroupPrimitive from \"@radix-ui/react-radio-group\";\r\n\r\nconst radioSizeVariants = cva(\r\n \"\",\r\n {\r\n variants: {\r\n size: {\r\n sm: \"h-4 w-4\",\r\n md: \"h-5 w-5\",\r\n lg: \"h-6 w-6\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n },\r\n }\r\n);\r\n\r\nconst labelVariants = cva(\r\n \"text-sm font-medium cursor-pointer select-none\",\r\n {\r\n variants: {\r\n disabled: {\r\n true: \"cursor-not-allowed opacity-50\",\r\n false: \"\",\r\n },\r\n },\r\n defaultVariants: {\r\n disabled: false,\r\n },\r\n }\r\n);\r\n\r\n// Radio Group Context\r\ninterface RadioGroupContextValue {\r\n name: string;\r\n value: string | number | undefined;\r\n onChange: (value: string | number) => void;\r\n disabled?: boolean;\r\n size?: \"sm\" | \"md\" | \"lg\";\r\n}\r\n\r\nconst RadioGroupContext = createContext<RadioGroupContextValue | null>(null);\r\n\r\nexport interface RadioOption {\r\n label: ReactNode;\r\n value: string | number;\r\n disabled?: boolean;\r\n}\r\n\r\nexport interface RadioGroupProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends VariantProps<typeof radioSizeVariants> {\r\n /** Field name - required for form integration */\r\n name: TName;\r\n /** Label text for the radio group */\r\n label?: string;\r\n /** Helper text displayed below the radio group */\r\n helperText?: string;\r\n /** Whether to show the error message */\r\n showError?: boolean;\r\n /** Custom error message (overrides form error) */\r\n error?: string;\r\n /** Options for the radio group */\r\n options?: RadioOption[];\r\n /** Layout direction */\r\n direction?: \"horizontal\" | \"vertical\";\r\n /** External control (for use outside Form) */\r\n control?: Control<TFieldValues>;\r\n /** Children (alternative to options prop) */\r\n children?: ReactNode;\r\n /** Disabled state */\r\n disabled?: boolean;\r\n /** Additional class name */\r\n className?: string;\r\n /** Variant style */\r\n variant?: \"default\" | \"error\";\r\n \r\n // Validation props\r\n /** Field is required */\r\n required?: boolean | string;\r\n /** Custom validation function */\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n}\r\n\r\n/**\r\n * RadioGroup component with form integration\r\n * \r\n * This is a wrapper around the shadcn/ui RadioGroup primitive that adds:\r\n * - Form integration with react-hook-form\r\n * - Automatic validation registration\r\n * - Label, helper text, and error message support\r\n * \r\n * @example\r\n * ```tsx\r\n * // Inside a Form component\r\n * <RadioGroup \r\n * name=\"gender\" \r\n * label=\"Gender\"\r\n * required\r\n * options={[\r\n * { label: \"Male\", value: \"male\" },\r\n * { label: \"Female\", value: \"female\" },\r\n * { label: \"Other\", value: \"other\" },\r\n * ]} \r\n * />\r\n * ```\r\n */\r\nexport function RadioGroup<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>({\r\n name,\r\n label,\r\n helperText,\r\n showError = true,\r\n error: customError,\r\n size,\r\n variant,\r\n options = [],\r\n direction = \"vertical\",\r\n control: externalControl,\r\n children,\r\n disabled,\r\n className,\r\n // Validation props\r\n required,\r\n validate,\r\n}: RadioGroupProps<TFieldValues, TName>) {\r\n const generatedId = useId();\r\n \r\n // Try to get form context\r\n const formConfigContext = useContext(FormConfigContext);\r\n const formConfig: FormConfig = formConfigContext ?? {};\r\n \r\n // Get form context from react-hook-form\r\n const rhfContext = useRHFFormContext<TFieldValues>();\r\n const control = externalControl ?? rhfContext?.control;\r\n\r\n // Register validation rules with the form\r\n useEffect(() => {\r\n if (formConfigContext?.registerFieldValidation) {\r\n const rules: FieldValidationRules = {};\r\n \r\n if (required !== undefined) rules.required = required;\r\n if (validate !== undefined) rules.validate = validate;\r\n\r\n formConfigContext.registerFieldValidation({\r\n name: name as string,\r\n type: \"string\",\r\n rules,\r\n });\r\n\r\n return () => {\r\n formConfigContext.unregisterFieldValidation(name as string);\r\n };\r\n }\r\n }, [formConfigContext, name, required, validate]);\r\n\r\n // Use controller for form integration\r\n const { field, fieldState } = useController<TFieldValues, TName>({\r\n name,\r\n control,\r\n });\r\n\r\n const fieldError = fieldState.error?.message;\r\n const errorMessage = customError ?? fieldError;\r\n const hasError = !!errorMessage;\r\n \r\n // Merge sizes - prop takes precedence over form config\r\n const effectiveSize = size ?? formConfig.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? formConfig.disabled;\r\n const effectiveVariant = hasError ? \"error\" : variant;\r\n\r\n const contextValue: RadioGroupContextValue = {\r\n name: name as string,\r\n value: field.value,\r\n onChange: field.onChange,\r\n disabled: effectiveDisabled,\r\n size: effectiveSize,\r\n };\r\n\r\n return (\r\n <div className={cn(\"space-y-2\", className)}>\r\n {label && (\r\n <Label className={cn(\r\n \"block\",\r\n required && \"after:content-['*'] after:ml-0.5 after:text-destructive\"\r\n )}>\r\n {label}\r\n {formConfig.colon && \":\"}\r\n </Label>\r\n )}\r\n \r\n <RadioGroupContext.Provider value={contextValue}>\r\n <ShadcnRadioGroup\r\n value={field.value?.toString()}\r\n onValueChange={(value) => field.onChange(value)}\r\n disabled={effectiveDisabled}\r\n aria-labelledby={label ? `${generatedId}-label` : undefined}\r\n className={cn(\r\n direction === \"horizontal\" && \"flex flex-row gap-4\",\r\n direction === \"vertical\" && \"flex flex-col gap-2\"\r\n )}\r\n >\r\n {children ?? options.map((option) => (\r\n <RadioItem\r\n key={option.value}\r\n value={option.value}\r\n disabled={option.disabled}\r\n size={effectiveSize}\r\n variant={effectiveVariant}\r\n >\r\n {option.label}\r\n </RadioItem>\r\n ))}\r\n </ShadcnRadioGroup>\r\n </RadioGroupContext.Provider>\r\n\r\n {showError && hasError && (\r\n <p className=\"text-sm text-destructive\" role=\"alert\">\r\n {errorMessage}\r\n </p>\r\n )}\r\n \r\n {helperText && !hasError && (\r\n <p className=\"text-sm text-muted-foreground\">\r\n {helperText}\r\n </p>\r\n )}\r\n </div>\r\n );\r\n}\r\n\r\nRadioGroup.displayName = \"RadioGroup\";\r\n\r\nexport interface RadioItemProps extends Omit<ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>, \"value\">,\r\n VariantProps<typeof radioSizeVariants> {\r\n /** Value for this radio option */\r\n value: string | number;\r\n /** Label for this radio option */\r\n children?: ReactNode;\r\n /** Variant style */\r\n variant?: \"default\" | \"error\";\r\n}\r\n\r\n/**\r\n * RadioItem component - must be used within RadioGroup\r\n * \r\n * This is a wrapper around the shadcn/ui RadioGroupItem primitive\r\n */\r\nfunction RadioItemInner(\r\n {\r\n value,\r\n children,\r\n size,\r\n variant,\r\n className,\r\n disabled,\r\n id: providedId,\r\n ...props\r\n }: RadioItemProps,\r\n ref: React.ForwardedRef<React.ElementRef<typeof RadioGroupPrimitive.Item>>\r\n) {\r\n const generatedId = useId();\r\n const inputId = providedId ?? generatedId;\r\n \r\n const groupContext = useContext(RadioGroupContext);\r\n \r\n const effectiveSize = size ?? groupContext?.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? groupContext?.disabled;\r\n\r\n return (\r\n <div className=\"flex items-center gap-2\">\r\n <ShadcnRadioGroupItem\r\n {...props}\r\n ref={ref}\r\n id={inputId}\r\n value={value.toString()}\r\n disabled={effectiveDisabled}\r\n className={cn(\r\n radioSizeVariants({ size: effectiveSize }),\r\n variant === \"error\" && \"border-destructive\",\r\n className\r\n )}\r\n />\r\n \r\n {children && (\r\n <Label\r\n htmlFor={inputId}\r\n className={labelVariants({ disabled: effectiveDisabled })}\r\n >\r\n {children}\r\n </Label>\r\n )}\r\n </div>\r\n );\r\n}\r\n\r\nexport const RadioItem = forwardRef(RadioItemInner);\r\nRadioItem.displayName = \"RadioItem\";\r\n"],"mappings":";;;;;;;;;;;AAYA,IAAM,qBAAA,GAAA,yBAAA,IAAA,CACJ,IACA;CACE,UAAU,EACR,MAAM;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;CACN,EACF;CACA,iBAAiB,EACf,MAAM,KACR;AACF,CACF;AAEA,IAAM,iBAAA,GAAA,yBAAA,IAAA,CACJ,kDACA;CACE,UAAU,EACR,UAAU;EACR,MAAM;EACN,OAAO;CACT,EACF;CACA,iBAAiB,EACf,UAAU,MACZ;AACF,CACF;AAWA,IAAM,qBAAA,GAAA,MAAA,cAAA,CAAiE,IAAI;;;;;;;;;;;;;;;;;;;;;;;;AAmE3E,SAAgB,WAGd,EACA,MACA,OACA,YACA,YAAY,MACZ,OAAO,aACP,MACA,SACA,UAAU,CAAC,GACX,YAAY,YACZ,SAAS,iBACT,UACA,UACA,WAEA,UACA,YACuC;CACvC,MAAM,eAAA,GAAA,MAAA,MAAA,CAAoB;CAG1B,MAAM,qBAAA,GAAA,MAAA,WAAA,CAA+B,gBAAA,iBAAiB;CACtD,MAAM,aAAyB,qBAAqB,CAAC;CAGrD,MAAM,cAAA,GAAA,gBAAA,eAAA,CAA6C;CACnD,MAAM,UAAU,mBAAmB,YAAY;CAG/C,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,IAAI,mBAAmB,yBAAyB;GAC9C,MA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AO,OAAO;MACd,UAAU,OAAO;MACjB,MAAM;MACN,SAAS;gBAER,OAAO;KACC,GAPJ,OAAO,KAOH,CACZ;IACe,CAAA;GACQ,CAAA;GAE3B,aAAa,YACZ,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;IAAG,WAAU;IAA2B,MAAK;cAC1C;GACA,CAAA;GAGJ,cAAc,CAAC,YACd,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;IAAG,WAAU;cACV;GACA,CAAA;EAEF;;AAET;AAEA,WAAW,cAAc;;;;;;AAiBzB,SAAS,eACP,EACE,OACA,UACA,MACA,SACA,WACA,UACA,IAAI,YACJ,GAAG,SAEL,KACA;CACA,MAAM,eAAA,GAAA,MAAA,MAAA,CAAoB;CAC1B,MAAM,UAAU,cAAc;CAE9B,MAAM,gBAAA,GAAA,MAAA,WAAA,CAA0B,iBAAiB;CAEjD,MAAM,gBAAgB,QAAQ,cAAc,QAAQ;CACpD,MAAM,oBAAoB,YAAY,cAAc;CAEpD,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAU;YAAf,CACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,oBAAA,gBAAD;GACE,GAAI;GACC;GACL,IAAI;GACJ,OAAO,MAAM,SAAS;GACtB,UAAU;GACV,WAAW,WAAA,GACT,kBAAkB,EAAE,MAAM,cAAc,CAAC,GACzC,YAAY,WAAW,sBACvB,SACF;EACD,CAAA,GAEA,YACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,cAAA,OAAD;GACE,SAAS;GACT,WAAW,cAAc,EAAE,UAAU,kBAAkB,CAAC;GAEvD;EACI,CAAA,CAEN;;AAET;AAEA,IAAa,aAAA,GAAA,MAAA,WAAA,CAAuB,cAAc;AAClD,UAAU,cAAc"}
1
+ {"version":3,"file":"Radio.cjs","names":[],"sources":["../../../../src/components/Form/Radio.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { forwardRef, useId, useContext, createContext, useEffect } from \"react\";\r\nimport type { ReactNode, ComponentPropsWithoutRef } from \"react\";\r\nimport { useController, useFormContext as useRHFFormContext, type FieldValues, type FieldPath, type Control } from \"react-hook-form\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport { FormConfigContext, type FormConfig, type FieldValidationRules } from \"../Form/context\";\r\nimport { RadioGroup as ShadcnRadioGroup, RadioGroupItem as ShadcnRadioGroupItem } from \"../../primitives/radio-group\";\r\nimport { Label } from \"../../primitives/label\";\r\nimport type * as RadioGroupPrimitive from \"@radix-ui/react-radio-group\";\r\n\r\nconst radioSizeVariants = cva(\r\n \"\",\r\n {\r\n variants: {\r\n size: {\r\n sm: \"h-4 w-4\",\r\n md: \"h-5 w-5\",\r\n lg: \"h-6 w-6\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n },\r\n }\r\n);\r\n\r\nconst labelVariants = cva(\r\n \"text-sm font-medium cursor-pointer select-none\",\r\n {\r\n variants: {\r\n disabled: {\r\n true: \"cursor-not-allowed opacity-50\",\r\n false: \"\",\r\n },\r\n },\r\n defaultVariants: {\r\n disabled: false,\r\n },\r\n }\r\n);\r\n\r\n// Radio Group Context\r\ninterface RadioGroupContextValue {\r\n name: string;\r\n value: string | number | undefined;\r\n onChange: (value: string | number) => void;\r\n disabled?: boolean;\r\n size?: \"sm\" | \"md\" | \"lg\";\r\n}\r\n\r\nconst RadioGroupContext = createContext<RadioGroupContextValue | null>(null);\r\n\r\nexport interface RadioOption {\r\n label: ReactNode;\r\n value: string | number;\r\n disabled?: boolean;\r\n}\r\n\r\nexport interface RadioGroupProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends VariantProps<typeof radioSizeVariants> {\r\n /** Field name - required for form integration */\r\n name: TName;\r\n /** Label text for the radio group */\r\n label?: string;\r\n /** Helper text displayed below the radio group */\r\n helperText?: string;\r\n /** Whether to show the error message */\r\n showError?: boolean;\r\n /** Custom error message (overrides form error) */\r\n error?: string;\r\n /** Options for the radio group */\r\n options?: RadioOption[];\r\n /** Layout direction */\r\n direction?: \"horizontal\" | \"vertical\";\r\n /** External control (for use outside Form) */\r\n control?: Control<TFieldValues>;\r\n /** Children (alternative to options prop) */\r\n children?: ReactNode;\r\n /** Disabled state */\r\n disabled?: boolean;\r\n /** Additional class name */\r\n className?: string;\r\n /** Variant style */\r\n variant?: \"default\" | \"error\";\r\n \r\n // Validation props\r\n /** Field is required */\r\n required?: boolean | string;\r\n /** Custom validation function */\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n}\r\n\r\n/**\r\n * RadioGroup component with form integration\r\n * \r\n * This is a wrapper around the shadcn/ui RadioGroup primitive that adds:\r\n * - Form integration with react-hook-form\r\n * - Automatic validation registration\r\n * - Label, helper text, and error message support\r\n * \r\n * @example\r\n * ```tsx\r\n * // Inside a Form component\r\n * <RadioGroup \r\n * name=\"gender\" \r\n * label=\"Gender\"\r\n * required\r\n * options={[\r\n * { label: \"Male\", value: \"male\" },\r\n * { label: \"Female\", value: \"female\" },\r\n * { label: \"Other\", value: \"other\" },\r\n * ]} \r\n * />\r\n * ```\r\n */\r\nexport function RadioGroup<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>({\r\n name,\r\n label,\r\n helperText,\r\n showError = true,\r\n error: customError,\r\n size,\r\n variant,\r\n options = [],\r\n direction = \"vertical\",\r\n control: externalControl,\r\n children,\r\n disabled,\r\n className,\r\n // Validation props\r\n required,\r\n validate,\r\n}: RadioGroupProps<TFieldValues, TName>) {\r\n const generatedId = useId();\r\n \r\n // Try to get form context\r\n const formConfigContext = useContext(FormConfigContext);\r\n const formConfig: FormConfig = formConfigContext ?? {};\r\n \r\n // Get form context from react-hook-form\r\n const rhfContext = useRHFFormContext<TFieldValues>();\r\n const control = externalControl ?? rhfContext?.control;\r\n\r\n // Register validation rules with the form\r\n useEffect(() => {\r\n if (formConfigContext?.registerFieldValidation) {\r\n const rules: FieldValidationRules = {};\r\n \r\n if (required !== undefined) rules.required = required;\r\n if (validate !== undefined) rules.validate = validate;\r\n\r\n formConfigContext.registerFieldValidation({\r\n name: name as string,\r\n type: \"string\",\r\n rules,\r\n });\r\n\r\n return () => {\r\n formConfigContext.unregisterFieldValidation(name as string);\r\n };\r\n }\r\n }, [formConfigContext, name, required, validate]);\r\n\r\n // Use controller for form integration\r\n const { field, fieldState } = useController<TFieldValues, TName>({\r\n name,\r\n control,\r\n });\r\n\r\n const fieldError = fieldState.error?.message;\r\n const errorMessage = customError ?? fieldError;\r\n const hasError = !!errorMessage;\r\n \r\n // Merge sizes - prop takes precedence over form config\r\n const effectiveSize = size ?? formConfig.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? formConfig.disabled;\r\n const effectiveVariant = hasError ? \"error\" : variant;\r\n\r\n const contextValue: RadioGroupContextValue = {\r\n name: name as string,\r\n value: field.value,\r\n onChange: field.onChange,\r\n disabled: effectiveDisabled,\r\n size: effectiveSize,\r\n };\r\n\r\n return (\r\n <div className={cn(\"space-y-2\", className)}>\r\n {label && (\r\n <Label className={cn(\r\n \"block\",\r\n required && \"after:content-['*'] after:ml-0.5 after:text-destructive\"\r\n )}>\r\n {label}\r\n {formConfig.colon && \":\"}\r\n </Label>\r\n )}\r\n \r\n <RadioGroupContext.Provider value={contextValue}>\r\n <ShadcnRadioGroup\r\n value={field.value?.toString()}\r\n onValueChange={(value) => field.onChange(value)}\r\n disabled={effectiveDisabled}\r\n aria-labelledby={label ? `${generatedId}-label` : undefined}\r\n className={cn(\r\n direction === \"horizontal\" && \"flex flex-row gap-4\",\r\n direction === \"vertical\" && \"flex flex-col gap-2\"\r\n )}\r\n >\r\n {children ?? options.map((option) => (\r\n <RadioItem\r\n key={option.value}\r\n value={option.value}\r\n disabled={option.disabled}\r\n size={effectiveSize}\r\n variant={effectiveVariant}\r\n >\r\n {option.label}\r\n </RadioItem>\r\n ))}\r\n </ShadcnRadioGroup>\r\n </RadioGroupContext.Provider>\r\n\r\n {showError && hasError && (\r\n <p className=\"text-sm text-destructive\" role=\"alert\">\r\n {errorMessage}\r\n </p>\r\n )}\r\n \r\n {helperText && !hasError && (\r\n <p className=\"text-sm text-muted-foreground\">\r\n {helperText}\r\n </p>\r\n )}\r\n </div>\r\n );\r\n}\r\n\r\nRadioGroup.displayName = \"RadioGroup\";\r\n\r\nexport interface RadioItemProps extends Omit<ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>, \"value\">,\r\n VariantProps<typeof radioSizeVariants> {\r\n /** Value for this radio option */\r\n value: string | number;\r\n /** Label for this radio option */\r\n children?: ReactNode;\r\n /** Variant style */\r\n variant?: \"default\" | \"error\";\r\n}\r\n\r\n/**\r\n * RadioItem component - must be used within RadioGroup\r\n * \r\n * This is a wrapper around the shadcn/ui RadioGroupItem primitive\r\n */\r\nfunction RadioItemInner(\r\n {\r\n value,\r\n children,\r\n size,\r\n variant,\r\n className,\r\n disabled,\r\n id: providedId,\r\n ...props\r\n }: RadioItemProps,\r\n ref: React.ForwardedRef<React.ElementRef<typeof RadioGroupPrimitive.Item>>\r\n) {\r\n const generatedId = useId();\r\n const inputId = providedId ?? generatedId;\r\n \r\n const groupContext = useContext(RadioGroupContext);\r\n \r\n const effectiveSize = size ?? groupContext?.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? groupContext?.disabled;\r\n\r\n return (\r\n <div className=\"flex items-center gap-2\">\r\n <ShadcnRadioGroupItem\r\n {...props}\r\n ref={ref}\r\n id={inputId}\r\n value={value.toString()}\r\n disabled={effectiveDisabled}\r\n className={cn(\r\n radioSizeVariants({ size: effectiveSize }),\r\n variant === \"error\" && \"border-destructive\",\r\n className\r\n )}\r\n />\r\n \r\n {children && (\r\n <Label\r\n htmlFor={inputId}\r\n className={labelVariants({ disabled: effectiveDisabled })}\r\n >\r\n {children}\r\n </Label>\r\n )}\r\n </div>\r\n );\r\n}\r\n\r\nexport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CAAA;EAEF;;AAET;AAEA,WAAW,cAAc;;;;;;AAiBzB,SAAS,eACP,EACE,OACA,UACA,MACA,SACA,WACA,UACA,IAAI,YACJ,GAAG,SAEL,KACA;CACA,MAAM,eAAA,GAAc,MAAA,MAAA,CAAM;CAC1B,MAAM,UAAU,cAAc;CAE9B,MAAM,gBAAA,GAAe,MAAA,WAAA,CAAW,iBAAiB;CAEjD,MAAM,gBAAgB,QAAQ,cAAc,QAAQ;CACpD,MAAM,oBAAoB,YAAY,cAAc;CAEpD,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,oBAAA,gBAAD;GACE,GAAI;GACC;GACL,IAAI;GACJ,OAAO,MAAM,SAAS;GACtB,UAAU;GACV,WAAW,WAAA,GACT,kBAAkB,EAAE,MAAM,cAAc,CAAC,GACzC,YAAY,WAAW,sBACvB,SACF;EACD,CAAA,GAEA,YACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,cAAA,OAAD;GACE,SAAS;GACT,WAAW,cAAc,EAAE,UAAU,kBAAkB,CAAC;GAEvD;EACI,CAAA,CAEN;;AAET;AAEA,IAAa,aAAA,GAAY,MAAA,WAAA,CAAW,cAAc;AAClD,UAAU,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"Select.cjs","names":[],"sources":["../../../../src/components/Form/Select.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { useId, useContext, useEffect } from \"react\";\r\nimport type { ReactNode } from \"react\";\r\nimport { useController, useFormContext as useRHFFormContext, type FieldValues, type FieldPath, type Control } from \"react-hook-form\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport { FormConfigContext, type FormConfig, type FieldValidationRules } from \"../Form/context\";\r\nimport { FieldLayout } from \"./FieldLayout\";\r\nimport {\r\n Select as ShadcnSelect,\r\n SelectContent,\r\n SelectItem,\r\n SelectTrigger,\r\n SelectValue,\r\n} from \"../../primitives/select\";\r\n\r\nconst selectSizeVariants = cva(\r\n \"\",\r\n {\r\n variants: {\r\n size: {\r\n sm: \"h-8 text-xs\",\r\n md: \"h-10 text-sm\",\r\n lg: \"h-12 text-base\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n },\r\n }\r\n);\r\n\r\nexport interface SelectOption {\r\n label: string;\r\n value: string | number;\r\n disabled?: boolean;\r\n}\r\n\r\nexport interface SelectProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends VariantProps<typeof selectSizeVariants> {\r\n /** Field name - required for form integration */\r\n name: TName;\r\n /** Label text for the select */\r\n label?: string;\r\n /** Helper text displayed below the select */\r\n helperText?: string;\r\n /** Whether to show the error message */\r\n showError?: boolean;\r\n /** Custom error message (overrides form error) */\r\n error?: string;\r\n /** Whether the select should take full width */\r\n fullWidth?: boolean;\r\n /** Options for the select */\r\n options?: SelectOption[];\r\n /** Placeholder text */\r\n placeholder?: string;\r\n /** Allow clear selection */\r\n allowClear?: boolean;\r\n /** External control (for use outside Form) */\r\n control?: Control<TFieldValues>;\r\n /** Children (alternative to options prop) */\r\n children?: ReactNode;\r\n /** Disabled state */\r\n disabled?: boolean;\r\n /** Additional class name */\r\n className?: string;\r\n /** ID for the select */\r\n id?: string;\r\n /** Variant style */\r\n variant?: \"default\" | \"error\" | \"success\";\r\n \r\n // Validation props\r\n /** Field is required */\r\n required?: boolean | string;\r\n /** Custom validation function */\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n}\r\n\r\n/**\r\n * Select component with form integration\r\n * \r\n * This is a wrapper around the shadcn/ui Select primitive that adds:\r\n * - Form integration with react-hook-form\r\n * - Automatic validation registration\r\n * - Label, helper text, and error message support\r\n * \r\n * @example\r\n * ```tsx\r\n * // Inside a Form component\r\n * <Select \r\n * name=\"country\" \r\n * label=\"Country\" \r\n * required\r\n * options={[\r\n * { label: \"USA\", value: \"us\" },\r\n * { label: \"Canada\", value: \"ca\" },\r\n * ]} \r\n * />\r\n * ```\r\n */\r\nexport function Select<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>({\r\n name,\r\n label,\r\n helperText,\r\n showError = true,\r\n error: customError,\r\n size,\r\n variant,\r\n fullWidth = true,\r\n className,\r\n disabled,\r\n options = [],\r\n placeholder,\r\n allowClear,\r\n id: providedId,\r\n control: externalControl,\r\n children,\r\n // Validation props\r\n required,\r\n validate,\r\n}: SelectProps<TFieldValues, TName>) {\r\n const generatedId = useId();\r\n const inputId = providedId ?? generatedId;\r\n \r\n // Try to get form context\r\n const formConfigContext = useContext(FormConfigContext);\r\n const formConfig: FormConfig = formConfigContext ?? {};\r\n \r\n // Get form context from react-hook-form\r\n const rhfContext = useRHFFormContext<TFieldValues>();\r\n const control = externalControl ?? rhfContext?.control;\r\n\r\n // Register validation rules with the form\r\n useEffect(() => {\r\n if (formConfigContext?.registerFieldValidation) {\r\n const rules: FieldValidationRules = {};\r\n \r\n if (required !== undefined) rules.required = required;\r\n if (validate !== undefined) rules.validate = validate;\r\n\r\n formConfigContext.registerFieldValidation({\r\n name: name as string,\r\n type: \"string\",\r\n rules,\r\n });\r\n\r\n return () => {\r\n formConfigContext.unregisterFieldValidation(name as string);\r\n };\r\n }\r\n }, [formConfigContext, name, required, validate]);\r\n\r\n // Use controller for form integration\r\n const { field, fieldState } = useController<TFieldValues, TName>({\r\n name,\r\n control,\r\n });\r\n\r\n const fieldError = fieldState.error?.message;\r\n const errorMessage = customError ?? fieldError;\r\n const hasError = !!errorMessage;\r\n \r\n // Merge sizes - prop takes precedence over form config\r\n const effectiveSize = size ?? formConfig.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? formConfig.disabled;\r\n \r\n // Determine variant based on error state\r\n const effectiveVariant = hasError ? \"error\" : variant;\r\n\r\n return (\r\n <FieldLayout\r\n inputId={inputId}\r\n label={label}\r\n required={!!required}\r\n helperText={helperText}\r\n errorMessage={showError ? errorMessage : undefined}\r\n showError={showError}\r\n fullWidth={fullWidth}\r\n formConfig={formConfig}\r\n >\r\n <ShadcnSelect\r\n value={field.value?.toString() ?? \"\"}\r\n onValueChange={(value) => {\r\n if (value === \"\" && allowClear) {\r\n field.onChange(\"\");\r\n } else {\r\n field.onChange(value);\r\n }\r\n }}\r\n disabled={effectiveDisabled}\r\n >\r\n <SelectTrigger\r\n id={inputId}\r\n aria-invalid={hasError}\r\n aria-describedby={\r\n hasError\r\n ? `${inputId}-error`\r\n : helperText\r\n ? `${inputId}-helper`\r\n : undefined\r\n }\r\n className={cn(\r\n selectSizeVariants({ size: effectiveSize }),\r\n effectiveVariant === \"error\" && \"border-destructive focus:ring-destructive\",\r\n effectiveVariant === \"success\" && \"border-green-500 focus:ring-green-500\",\r\n className\r\n )}\r\n >\r\n <SelectValue placeholder={placeholder} />\r\n </SelectTrigger>\r\n <SelectContent>\r\n {allowClear && field.value && (\r\n <SelectItem value=\"\">\r\n <span className=\"text-muted-foreground\">Clear selection</span>\r\n </SelectItem>\r\n )}\r\n {children ?? options.map((option) => (\r\n <SelectItem\r\n key={option.value}\r\n value={option.value.toString()}\r\n disabled={option.disabled}\r\n >\r\n {option.label}\r\n </SelectItem>\r\n ))}\r\n </SelectContent>\r\n </ShadcnSelect>\r\n </FieldLayout>\r\n );\r\n}\r\n\r\nSelect.displayName = \"Select\";\r\n"],"mappings":";;;;;;;;;;;AAiBA,IAAM,sBAAA,GAAA,yBAAA,IAAA,CACJ,IACA;CACE,UAAU,EACR,MAAM;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;CACN,EACF;CACA,iBAAiB,EACf,MAAM,KACR;AACF,CACF;;;;;;;;;;;;;;;;;;;;;;;AAwEA,SAAgB,OAGd,EACA,MACA,OACA,YACA,YAAY,MACZ,OAAO,aACP,MACA,SACA,YAAY,MACZ,WACA,UACA,UAAU,CAAC,GACX,aACA,YACA,I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,CAWE,iBAAA,GAAA,kBAAA,IAAA,CAAC,eAAA,eAAD;IACE,IAAI;IACJ,gBAAc;IACd,oBACE,WACI,GAAG,QAAQ,UACX,aACE,GAAG,QAAQ,WACX,KAAA;IAER,WAAW,WAAA,GACT,mBAAmB,EAAE,MAAM,cAAc,CAAC,GAC1C,qBAAqB,WAAW,6CAChC,qBAAqB,aAAa,yCAClC,SACF;cAEA,iBAAA,GAAA,kBAAA,IAAA,CAAC,eAAA,aAAD,EAA0B,YAAc,CAAA;GAC3B,CAAA,GACf,iBAAA,GAAA,kBAAA,KAAA,CAAC,eAAA,eAAD,EAAA,UAAA,CACG,cAAc,MAAM,SACnB,iBAAA,GAAA,kBAAA,IAAA,CAAC,eAAA,YAAD;IAAY,OAAM;cAChB,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;KAAM,WAAU;eAAwB;IAAqB,CAAA;GACnD,CAAA,GAEb,YAAY,QAAQ,KAAK,WACxB,iBAAA,GAAA,kBAAA,IAAA,CAAC,eAAA,YAAD;IAEE,OAAO,OAAO,MAAM,SAAS;IAC7B,UAAU,OAAO;cAEhB,OAAO;GACE,GALL,OAAO,KAKF,CACb,CACY,EAAA,CAAA,CACH;;CACH,CAAA;AAEjB;AAEA,OAAO,cAAc"}
1
+ {"version":3,"file":"Select.cjs","names":[],"sources":["../../../../src/components/Form/Select.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { useId, useContext, useEffect } from \"react\";\r\nimport type { ReactNode } from \"react\";\r\nimport { useController, useFormContext as useRHFFormContext, type FieldValues, type FieldPath, type Control } from \"react-hook-form\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport { FormConfigContext, type FormConfig, type FieldValidationRules } from \"../Form/context\";\r\nimport { FieldLayout } from \"./FieldLayout\";\r\nimport {\r\n Select as ShadcnSelect,\r\n SelectContent,\r\n SelectItem,\r\n SelectTrigger,\r\n SelectValue,\r\n} from \"../../primitives/select\";\r\n\r\nconst selectSizeVariants = cva(\r\n \"\",\r\n {\r\n variants: {\r\n size: {\r\n sm: \"h-8 text-xs\",\r\n md: \"h-10 text-sm\",\r\n lg: \"h-12 text-base\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n },\r\n }\r\n);\r\n\r\nexport interface SelectOption {\r\n label: string;\r\n value: string | number;\r\n disabled?: boolean;\r\n}\r\n\r\nexport interface SelectProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends VariantProps<typeof selectSizeVariants> {\r\n /** Field name - required for form integration */\r\n name: TName;\r\n /** Label text for the select */\r\n label?: string;\r\n /** Helper text displayed below the select */\r\n helperText?: string;\r\n /** Whether to show the error message */\r\n showError?: boolean;\r\n /** Custom error message (overrides form error) */\r\n error?: string;\r\n /** Whether the select should take full width */\r\n fullWidth?: boolean;\r\n /** Options for the select */\r\n options?: SelectOption[];\r\n /** Placeholder text */\r\n placeholder?: string;\r\n /** Allow clear selection */\r\n allowClear?: boolean;\r\n /** External control (for use outside Form) */\r\n control?: Control<TFieldValues>;\r\n /** Children (alternative to options prop) */\r\n children?: ReactNode;\r\n /** Disabled state */\r\n disabled?: boolean;\r\n /** Additional class name */\r\n className?: string;\r\n /** ID for the select */\r\n id?: string;\r\n /** Variant style */\r\n variant?: \"default\" | \"error\" | \"success\";\r\n \r\n // Validation props\r\n /** Field is required */\r\n required?: boolean | string;\r\n /** Custom validation function */\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n}\r\n\r\n/**\r\n * Select component with form integration\r\n * \r\n * This is a wrapper around the shadcn/ui Select primitive that adds:\r\n * - Form integration with react-hook-form\r\n * - Automatic validation registration\r\n * - Label, helper text, and error message support\r\n * \r\n * @example\r\n * ```tsx\r\n * // Inside a Form component\r\n * <Select \r\n * name=\"country\" \r\n * label=\"Country\" \r\n * required\r\n * options={[\r\n * { label: \"USA\", value: \"us\" },\r\n * { label: \"Canada\", value: \"ca\" },\r\n * ]} \r\n * />\r\n * ```\r\n */\r\nexport function Select<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>({\r\n name,\r\n label,\r\n helperText,\r\n showError = true,\r\n error: customError,\r\n size,\r\n variant,\r\n fullWidth = true,\r\n className,\r\n disabled,\r\n options = [],\r\n placeholder,\r\n allowClear,\r\n id: providedId,\r\n control: externalControl,\r\n children,\r\n // Validation props\r\n required,\r\n validate,\r\n}: SelectProps<TFieldValues, TName>) {\r\n const generatedId = useId();\r\n const inputId = providedId ?? generatedId;\r\n \r\n // Try to get form context\r\n const formConfigContext = useContext(FormConfigContext);\r\n const formConfig: FormConfig = formConfigContext ?? {};\r\n \r\n // Get form context from react-hook-form\r\n const rhfContext = useRHFFormContext<TFieldValues>();\r\n const control = externalControl ?? rhfContext?.control;\r\n\r\n // Register validation rules with the form\r\n useEffect(() => {\r\n if (formConfigContext?.registerFieldValidation) {\r\n const rules: FieldValidationRules = {};\r\n \r\n if (required !== undefined) rules.required = required;\r\n if (validate !== undefined) rules.validate = validate;\r\n\r\n formConfigContext.registerFieldValidation({\r\n name: name as string,\r\n type: \"string\",\r\n rules,\r\n });\r\n\r\n return () => {\r\n formConfigContext.unregisterFieldValidation(name as string);\r\n };\r\n }\r\n }, [formConfigContext, name, required, validate]);\r\n\r\n // Use controller for form integration\r\n const { field, fieldState } = useController<TFieldValues, TName>({\r\n name,\r\n control,\r\n });\r\n\r\n const fieldError = fieldState.error?.message;\r\n const errorMessage = customError ?? fieldError;\r\n const hasError = !!errorMessage;\r\n \r\n // Merge sizes - prop takes precedence over form config\r\n const effectiveSize = size ?? formConfig.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? formConfig.disabled;\r\n \r\n // Determine variant based on error state\r\n const effectiveVariant = hasError ? \"error\" : variant;\r\n\r\n return (\r\n <FieldLayout\r\n inputId={inputId}\r\n label={label}\r\n required={!!required}\r\n helperText={helperText}\r\n errorMessage={showError ? errorMessage : undefined}\r\n showError={showError}\r\n fullWidth={fullWidth}\r\n formConfig={formConfig}\r\n >\r\n <ShadcnSelect\r\n value={field.value?.toString() ?? \"\"}\r\n onValueChange={(value) => {\r\n if (value === \"\" && allowClear) {\r\n field.onChange(\"\");\r\n } else {\r\n field.onChange(value);\r\n }\r\n }}\r\n disabled={effectiveDisabled}\r\n >\r\n <SelectTrigger\r\n id={inputId}\r\n aria-invalid={hasError}\r\n aria-describedby={\r\n hasError\r\n ? `${inputId}-error`\r\n : helperText\r\n ? `${inputId}-helper`\r\n : undefined\r\n }\r\n className={cn(\r\n selectSizeVariants({ size: effectiveSize }),\r\n effectiveVariant === \"error\" && \"border-destructive focus:ring-destructive\",\r\n effectiveVariant === \"success\" && \"border-green-500 focus:ring-green-500\",\r\n className\r\n )}\r\n >\r\n <SelectValue placeholder={placeholder} />\r\n </SelectTrigger>\r\n <SelectContent>\r\n {allowClear && field.value && (\r\n <SelectItem value=\"\">\r\n <span className=\"text-muted-foreground\">Clear selection</span>\r\n </SelectItem>\r\n )}\r\n {children ?? options.map((option) => (\r\n <SelectItem\r\n key={option.value}\r\n value={option.value.toString()}\r\n disabled={option.disabled}\r\n >\r\n {option.label}\r\n </SelectItem>\r\n ))}\r\n </SelectContent>\r\n </ShadcnSelect>\r\n </FieldLayout>\r\n );\r\n}\r\n\r\nSelect.displayName = \"Select\";\r\n"],"mappings":";;;;;;;;;;;AAiBA,IAAM,sBAAA,GAAqB,yBAAA,IAAA,CACzB,IACA;CACE,UAAU,EACR,MAAM;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;CACN,EACF;CACA,iBAAiB,EACf,MAAM,KACR;AACF,CACF;;;;;;;;;;;;;;;;;;;;;;;AAwEA,SAAgB,OAGd,EACA,MACA,OACA,YACA,YAAY,MACZ,OAAO,aACP,MACA,SACA,YAAY,MACZ,WACA,UACA,UAAU,CAAC,GACX,aACA,YACA,IAAI,YACJ,SAAS,iBACT,UAEA,UACA,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BAAA,IAAA,CAAC,eAAA,eAAD;IACE,IAAI;IACJ,gBAAc;IACd,oBACE,WACI,GAAG,QAAQ,UACX,aACE,GAAG,QAAQ,WACX,KAAA;IAER,WAAW,WAAA,GACT,mBAAmB,EAAE,MAAM,cAAc,CAAC,GAC1C,qBAAqB,WAAW,6CAChC,qBAAqB,aAAa,yCAClC,SACF;IAEA,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,eAAA,aAAD,EAA0B,YAAc,CAAA;GAC3B,CAAA,GACf,iBAAA,GAAA,kBAAA,KAAA,CAAC,eAAA,eAAD,EAAA,UAAA,CACG,cAAc,MAAM,SACnB,iBAAA,GAAA,kBAAA,IAAA,CAAC,eAAA,YAAD;IAAY,OAAM;IAChB,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;KAAM,WAAU;KAAwB,UAAA;IAAqB,CAAA;GACnD,CAAA,GAEb,YAAY,QAAQ,KAAK,WACxB,iBAAA,GAAA,kBAAA,IAAA,CAAC,eAAA,YAAD;IAEE,OAAO,OAAO,MAAM,SAAS;IAC7B,UAAU,OAAO;IAEhB,UAAA,OAAO;GACE,GALL,OAAO,KAKF,CACb,CACY,EAAA,CAAA,CACH;;CACH,CAAA;AAEjB;AAEA,OAAO,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"TextArea.cjs","names":[],"sources":["../../../../src/components/Form/TextArea.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { forwardRef, useId, useContext, useEffect } from \"react\";\r\nimport type { TextareaHTMLAttributes } from \"react\";\r\nimport { useController, useFormContext as useRHFFormContext, type FieldValues, type FieldPath, type Control } from \"react-hook-form\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport { FormConfigContext, type FormConfig, type FieldValidationRules } from \"../Form/context\";\r\nimport { labelVariants } from \"./variants\";\r\nimport { Textarea } from \"../../primitives/textarea\";\r\nimport { Label } from \"../../primitives/label\";\r\n\r\nconst textAreaSizeVariants = cva(\r\n \"\",\r\n {\r\n variants: {\r\n size: {\r\n sm: \"text-xs px-2 py-1.5 min-h-[60px]\",\r\n md: \"text-sm px-3 py-2 min-h-[80px]\",\r\n lg: \"text-base px-4 py-3 min-h-[100px]\",\r\n },\r\n variant: {\r\n default: \"border-input focus-visible:ring-ring\",\r\n error: \"border-destructive focus-visible:ring-destructive\",\r\n success: \"border-green-500 focus-visible:ring-green-500\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n variant: \"default\",\r\n },\r\n }\r\n);\r\n\r\n/**\r\n * Validation rule with optional custom message\r\n */\r\ntype ValidationRule<T> = T | { value: T; message: string };\r\n\r\nexport interface TextAreaProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, \"name\" | \"required\" | \"minLength\" | \"maxLength\">,\r\n VariantProps<typeof textAreaSizeVariants> {\r\n /** Field name - required for form integration */\r\n name: TName;\r\n /** Label text for the textarea */\r\n label?: string;\r\n /** Helper text displayed below the textarea */\r\n helperText?: string;\r\n /** Whether to show the error message */\r\n showError?: boolean;\r\n /** Custom error message (overrides form error) */\r\n error?: string;\r\n /** Whether the textarea should take full width */\r\n fullWidth?: boolean;\r\n /** Show character count */\r\n showCount?: boolean;\r\n /** Maximum character count (for display) */\r\n maxCount?: number;\r\n /** External control (for use outside Form) */\r\n control?: Control<TFieldValues>;\r\n \r\n // Validation props\r\n /** Field is required */\r\n required?: boolean | string;\r\n /** Minimum length */\r\n minLength?: ValidationRule<number>;\r\n /** Maximum length */\r\n maxLength?: ValidationRule<number>;\r\n /** Custom validation function */\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n}\r\n\r\n/**\r\n * TextArea component with form integration\r\n * \r\n * This is a wrapper around the shadcn/ui Textarea primitive that adds:\r\n * - Form integration with react-hook-form\r\n * - Automatic validation registration\r\n * - Label, helper text, and error message support\r\n * - Character count display\r\n * \r\n * @example\r\n * ```tsx\r\n * // Inside a Form component\r\n * <TextArea name=\"description\" label=\"Description\" required minLength={10} />\r\n * <TextArea name=\"bio\" label=\"Bio\" showCount maxCount={500} maxLength={500} />\r\n * ```\r\n */\r\nfunction TextAreaInner<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(\r\n {\r\n name,\r\n label,\r\n helperText,\r\n showError = true,\r\n error: customError,\r\n size,\r\n variant,\r\n fullWidth = true,\r\n className,\r\n disabled,\r\n showCount,\r\n maxCount,\r\n id: providedId,\r\n control: externalControl,\r\n // Validation props\r\n required,\r\n minLength,\r\n maxLength,\r\n validate,\r\n ...props\r\n }: TextAreaProps<TFieldValues, TName>,\r\n ref: React.ForwardedRef<HTMLTextAreaElement>\r\n) {\r\n const generatedId = useId();\r\n const inputId = providedId ?? generatedId;\r\n \r\n // Try to get form context\r\n const formConfigContext = useContext(FormConfigContext);\r\n const formConfig: FormConfig = formConfigContext ?? {};\r\n \r\n // Get form context from react-hook-form\r\n const rhfContext = useRHFFormContext<TFieldValues>();\r\n const control = externalControl ?? rhfContext?.control;\r\n\r\n // Register validation rules with the form\r\n useEffect(() => {\r\n if (formConfigContext?.registerFieldValidation) {\r\n const rules: FieldValidationRules = {};\r\n \r\n if (required !== undefined) rules.required = required;\r\n if (minLength !== undefined) rules.minLength = minLength;\r\n if (maxLength !== undefined) rules.maxLength = maxLength;\r\n if (validate !== undefined) rules.validate = validate;\r\n\r\n formConfigContext.registerFieldValidation({\r\n name: name as string,\r\n type: \"string\",\r\n rules,\r\n });\r\n\r\n return () => {\r\n formConfigContext.unregisterFieldValidation(name as string);\r\n };\r\n }\r\n }, [formConfigContext, name, required, minLength, maxLength, validate]);\r\n\r\n // Use controller for form integration\r\n const { field, fieldState } = useController<TFieldValues, TName>({\r\n name,\r\n control,\r\n });\r\n\r\n const fieldError = fieldState.error?.message;\r\n const errorMessage = customError ?? fieldError;\r\n const hasError = !!errorMessage;\r\n \r\n // Merge sizes - prop takes precedence over form config\r\n const effectiveSize = size ?? formConfig.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? formConfig.disabled;\r\n \r\n // Determine variant based on error state\r\n const effectiveVariant = hasError ? \"error\" : variant;\r\n\r\n const currentLength = typeof field.value === \"string\" ? field.value.length : 0;\r\n \r\n // Get maxLength value for HTML attribute\r\n const maxLengthValue = maxCount ?? (typeof maxLength === \"number\" ? maxLength : (maxLength as { value: number })?.value);\r\n\r\n return (\r\n <div className={cn(\"space-y-1.5\", fullWidth && \"w-full\")}>\r\n {label && (\r\n <Label\r\n htmlFor={inputId}\r\n className={labelVariants({ required: !!required })}\r\n >\r\n {label}\r\n {formConfig.colon && \":\"}\r\n </Label>\r\n )}\r\n \r\n <div className=\"relative\">\r\n <Textarea\r\n {...props}\r\n {...field}\r\n ref={(node) => {\r\n if (typeof ref === \"function\") {\r\n ref(node);\r\n } else if (ref) {\r\n ref.current = node;\r\n }\r\n field.ref(node);\r\n }}\r\n id={inputId}\r\n disabled={effectiveDisabled}\r\n maxLength={maxLengthValue}\r\n aria-invalid={hasError}\r\n aria-describedby={\r\n hasError\r\n ? `${inputId}-error`\r\n : helperText\r\n ? `${inputId}-helper`\r\n : undefined\r\n }\r\n className={cn(\r\n textAreaSizeVariants({ size: effectiveSize, variant: effectiveVariant }),\r\n showCount && \"pb-6\",\r\n className\r\n )}\r\n />\r\n \r\n {showCount && (\r\n <div className=\"absolute bottom-2 right-2 text-xs text-muted-foreground\">\r\n {currentLength}{maxCount ? `/${maxCount}` : \"\"}\r\n </div>\r\n )}\r\n </div>\r\n\r\n {showError && hasError && (\r\n <p\r\n id={`${inputId}-error`}\r\n className=\"text-sm text-destructive\"\r\n role=\"alert\"\r\n >\r\n {errorMessage}\r\n </p>\r\n )}\r\n \r\n {helperText && !hasError && (\r\n <p\r\n id={`${inputId}-helper`}\r\n className=\"text-sm text-muted-foreground\"\r\n >\r\n {helperText}\r\n </p>\r\n )}\r\n </div>\r\n );\r\n}\r\n\r\n// Use forwardRef with generic support\r\nexport const TextArea = forwardRef(TextAreaInner) as <\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(\r\n props: TextAreaProps<TFieldValues, TName> & { ref?: React.ForwardedRef<HTMLTextAreaElement> }\r\n) => React.ReactElement;\r\n\r\n(TextArea as React.FC).displayName = \"TextArea\";\r\n"],"mappings":";;;;;;;;;;;;AAYA,IAAM,wBAAA,GAAA,yBAAA,IAAA,CACJ,IACA;CACE,UAAU;EACR,MAAM;GACJ,IAAI;GACJ,IAAI;GACJ,IAAI;EACN;EACA,SAAS;GACP,SAAS;GACT,OAAO;GACP,SAAS;EACX;CACF;CACA,iBAAiB;EACf,MAAM;EACN,SAAS;CACX;AACF,CACF;;;;;;;;;;;;;;;;;AA0DA,SAAS,cAIP,EACE,MACA,OACA,YACA,YAAY,MACZ,OAAO,aACP,MACA,SACA,YAAY,MACZ,WACA,UACA,WACA,UACA,IAAI,YACJ,SAAS,iBAET,UACA,WACA,WACA,UACA,GAAG,SAEL,KACA;CACA,MAAM,eAAA,GAAA,MAAA,MAAA,CAAoB;CAC1B,MAAM,UAAU,cAAc;CAG9B,MAAM,qBAAA,GAAA,MAAA,WAAA,CAA+B,gBAAA,iBAAiB;CACtD,MAAM,aAAyB,qBAAqB,CAAC;CAGrD,MAAM,cAAA,GAAA,gBAAA,eAAA,CAA6C;CACnD,MAAM,UAAU,mBAAmB,YAAY;CAG/C,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,IAAI,mBAAmB,yBAAyB;GAC9C,MAAM,QAA8B,CAAC;GAErC,IAAI,aAAa,KAAA,GAAW,MAAM,WAAW;GAC7C,IAAI,cAAc,KAAA,GAAW,MAAM,YAAY;GAC/C,IAAI,cAAc,KAAA,GAAW,MAAM,YAAY;GAC/C,IAAI,aAAa,KAAA,GAAW,MAAM,WAAW;GAE7C,kBAA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;KAAiB,CAAC,GACvE,aAAa,QACb,SACF;IACD,CAAA,GAEA,aACC,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;KAAK,WAAU;eAAf,CACG,eAAe,WAAW,IAAI,aAAa,EACzC;MAEJ;;GAEJ,aAAa,YACZ,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;IACE,IAAI,GAAG,QAAQ;IACf,WAAU;IACV,MAAK;cAEJ;GACA,CAAA;GAGJ,cAAc,CAAC,YACd,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;IACE,IAAI,GAAG,QAAQ;IACf,WAAU;cAET;GACA,CAAA;EAEF;;AAET;AAGA,IAAa,YAAA,GAAA,MAAA,WAAA,CAAsB,aAAa;AAOhD,SAAuB,cAAc"}
1
+ {"version":3,"file":"TextArea.cjs","names":[],"sources":["../../../../src/components/Form/TextArea.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { forwardRef, useId, useContext, useEffect } from \"react\";\r\nimport type { TextareaHTMLAttributes } from \"react\";\r\nimport { useController, useFormContext as useRHFFormContext, type FieldValues, type FieldPath, type Control } from \"react-hook-form\";\r\nimport { cva, type VariantProps } from \"class-variance-authority\";\r\nimport { cn } from \"../../utils/cn\";\r\nimport { FormConfigContext, type FormConfig, type FieldValidationRules } from \"../Form/context\";\r\nimport { labelVariants } from \"./variants\";\r\nimport { Textarea } from \"../../primitives/textarea\";\r\nimport { Label } from \"../../primitives/label\";\r\n\r\nconst textAreaSizeVariants = cva(\r\n \"\",\r\n {\r\n variants: {\r\n size: {\r\n sm: \"text-xs px-2 py-1.5 min-h-[60px]\",\r\n md: \"text-sm px-3 py-2 min-h-[80px]\",\r\n lg: \"text-base px-4 py-3 min-h-[100px]\",\r\n },\r\n variant: {\r\n default: \"border-input focus-visible:ring-ring\",\r\n error: \"border-destructive focus-visible:ring-destructive\",\r\n success: \"border-green-500 focus-visible:ring-green-500\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n variant: \"default\",\r\n },\r\n }\r\n);\r\n\r\n/**\r\n * Validation rule with optional custom message\r\n */\r\ntype ValidationRule<T> = T | { value: T; message: string };\r\n\r\nexport interface TextAreaProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, \"name\" | \"required\" | \"minLength\" | \"maxLength\">,\r\n VariantProps<typeof textAreaSizeVariants> {\r\n /** Field name - required for form integration */\r\n name: TName;\r\n /** Label text for the textarea */\r\n label?: string;\r\n /** Helper text displayed below the textarea */\r\n helperText?: string;\r\n /** Whether to show the error message */\r\n showError?: boolean;\r\n /** Custom error message (overrides form error) */\r\n error?: string;\r\n /** Whether the textarea should take full width */\r\n fullWidth?: boolean;\r\n /** Show character count */\r\n showCount?: boolean;\r\n /** Maximum character count (for display) */\r\n maxCount?: number;\r\n /** External control (for use outside Form) */\r\n control?: Control<TFieldValues>;\r\n \r\n // Validation props\r\n /** Field is required */\r\n required?: boolean | string;\r\n /** Minimum length */\r\n minLength?: ValidationRule<number>;\r\n /** Maximum length */\r\n maxLength?: ValidationRule<number>;\r\n /** Custom validation function */\r\n validate?: (value: unknown) => boolean | string | Promise<boolean | string>;\r\n}\r\n\r\n/**\r\n * TextArea component with form integration\r\n * \r\n * This is a wrapper around the shadcn/ui Textarea primitive that adds:\r\n * - Form integration with react-hook-form\r\n * - Automatic validation registration\r\n * - Label, helper text, and error message support\r\n * - Character count display\r\n * \r\n * @example\r\n * ```tsx\r\n * // Inside a Form component\r\n * <TextArea name=\"description\" label=\"Description\" required minLength={10} />\r\n * <TextArea name=\"bio\" label=\"Bio\" showCount maxCount={500} maxLength={500} />\r\n * ```\r\n */\r\nfunction TextAreaInner<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(\r\n {\r\n name,\r\n label,\r\n helperText,\r\n showError = true,\r\n error: customError,\r\n size,\r\n variant,\r\n fullWidth = true,\r\n className,\r\n disabled,\r\n showCount,\r\n maxCount,\r\n id: providedId,\r\n control: externalControl,\r\n // Validation props\r\n required,\r\n minLength,\r\n maxLength,\r\n validate,\r\n ...props\r\n }: TextAreaProps<TFieldValues, TName>,\r\n ref: React.ForwardedRef<HTMLTextAreaElement>\r\n) {\r\n const generatedId = useId();\r\n const inputId = providedId ?? generatedId;\r\n \r\n // Try to get form context\r\n const formConfigContext = useContext(FormConfigContext);\r\n const formConfig: FormConfig = formConfigContext ?? {};\r\n \r\n // Get form context from react-hook-form\r\n const rhfContext = useRHFFormContext<TFieldValues>();\r\n const control = externalControl ?? rhfContext?.control;\r\n\r\n // Register validation rules with the form\r\n useEffect(() => {\r\n if (formConfigContext?.registerFieldValidation) {\r\n const rules: FieldValidationRules = {};\r\n \r\n if (required !== undefined) rules.required = required;\r\n if (minLength !== undefined) rules.minLength = minLength;\r\n if (maxLength !== undefined) rules.maxLength = maxLength;\r\n if (validate !== undefined) rules.validate = validate;\r\n\r\n formConfigContext.registerFieldValidation({\r\n name: name as string,\r\n type: \"string\",\r\n rules,\r\n });\r\n\r\n return () => {\r\n formConfigContext.unregisterFieldValidation(name as string);\r\n };\r\n }\r\n }, [formConfigContext, name, required, minLength, maxLength, validate]);\r\n\r\n // Use controller for form integration\r\n const { field, fieldState } = useController<TFieldValues, TName>({\r\n name,\r\n control,\r\n });\r\n\r\n const fieldError = fieldState.error?.message;\r\n const errorMessage = customError ?? fieldError;\r\n const hasError = !!errorMessage;\r\n \r\n // Merge sizes - prop takes precedence over form config\r\n const effectiveSize = size ?? formConfig.size ?? \"md\";\r\n const effectiveDisabled = disabled ?? formConfig.disabled;\r\n \r\n // Determine variant based on error state\r\n const effectiveVariant = hasError ? \"error\" : variant;\r\n\r\n const currentLength = typeof field.value === \"string\" ? field.value.length : 0;\r\n \r\n // Get maxLength value for HTML attribute\r\n const maxLengthValue = maxCount ?? (typeof maxLength === \"number\" ? maxLength : (maxLength as { value: number })?.value);\r\n\r\n return (\r\n <div className={cn(\"space-y-1.5\", fullWidth && \"w-full\")}>\r\n {label && (\r\n <Label\r\n htmlFor={inputId}\r\n className={labelVariants({ required: !!required })}\r\n >\r\n {label}\r\n {formConfig.colon && \":\"}\r\n </Label>\r\n )}\r\n \r\n <div className=\"relative\">\r\n <Textarea\r\n {...props}\r\n {...field}\r\n ref={(node) => {\r\n if (typeof ref === \"function\") {\r\n ref(node);\r\n } else if (ref) {\r\n ref.current = node;\r\n }\r\n field.ref(node);\r\n }}\r\n id={inputId}\r\n disabled={effectiveDisabled}\r\n maxLength={maxLengthValue}\r\n aria-invalid={hasError}\r\n aria-describedby={\r\n hasError\r\n ? `${inputId}-error`\r\n : helperText\r\n ? `${inputId}-helper`\r\n : undefined\r\n }\r\n className={cn(\r\n textAreaSizeVariants({ size: effectiveSize, variant: effectiveVariant }),\r\n showCount && \"pb-6\",\r\n className\r\n )}\r\n />\r\n \r\n {showCount && (\r\n <div className=\"absolute bottom-2 right-2 text-xs text-muted-foreground\">\r\n {currentLength}{maxCount ? `/${maxCount}` : \"\"}\r\n </div>\r\n )}\r\n </div>\r\n\r\n {showError && hasError && (\r\n <p\r\n id={`${inputId}-error`}\r\n className=\"text-sm text-destructive\"\r\n role=\"alert\"\r\n >\r\n {errorMessage}\r\n </p>\r\n )}\r\n \r\n {helperText && !hasError && (\r\n <p\r\n id={`${inputId}-helper`}\r\n className=\"text-sm text-muted-foreground\"\r\n >\r\n {helperText}\r\n </p>\r\n )}\r\n </div>\r\n );\r\n}\r\n\r\n// Use forwardRef with generic support\r\nexport const TextArea = forwardRef(TextAreaInner) as <\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(\r\n props: TextAreaProps<TFieldValues, TName> & { ref?: React.ForwardedRef<HTMLTextAreaElement> }\r\n) => React.ReactElement;\r\n\r\n(TextArea as React.FC).displayName = \"TextArea\";\r\n"],"mappings":";;;;;;;;;;;;AAYA,I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J,cAAc,CAAC,YACd,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;IACE,IAAI,GAAG,QAAQ;IACf,WAAU;IAET,UAAA;GACA,CAAA;EAEF;;AAET;AAGA,IAAa,YAAA,GAAW,MAAA,WAAA,CAAW,aAAa;AAOhD,SAAuB,cAAc"}
@@ -3,6 +3,7 @@
3
3
  const require_cn = require("../../utils/cn.cjs");
4
4
  const require_context = require("./context.cjs");
5
5
  const require_FieldLayout = require("./FieldLayout.cjs");
6
+ const require_PasswordRevealToggle = require("./PasswordRevealToggle.cjs");
6
7
  const require_textbox = require("../../primitives/textbox.cjs");
7
8
  let react = require("react");
8
9
  let class_variance_authority = require("class-variance-authority");
@@ -37,6 +38,7 @@ var textBoxVariants = (0, class_variance_authority.cva)("", {
37
38
  * - Label, helper text, and error message support
38
39
  * - Prefix/suffix elements
39
40
  * - Clear button functionality
41
+ * - Built-in password reveal toggle when `type="password"`
40
42
  *
41
43
  * @example
42
44
  * ```tsx
@@ -44,14 +46,18 @@ var textBoxVariants = (0, class_variance_authority.cva)("", {
44
46
  * <Form onSubmit={handleSubmit} defaultValues={{ username: "", email: "" }}>
45
47
  * <TextBox name="username" label="Username" required minLength={3} maxLength={50} />
46
48
  * <TextBox name="email" label="Email" type="email" required email />
49
+ * <TextBox name="password" label="Password" type="password" required />
47
50
  * <TextBox name="website" label="Website" url />
48
51
  * <Button type="submit">Submit</Button>
49
52
  * </Form>
50
53
  * ```
51
54
  */
52
- function TextBoxInner({ name, label, helperText, showError = true, error: customError, size, variant, fullWidth = true, className, disabled, prefix, suffix, allowClear, onClear, id: providedId, control: externalControl, required, minLength, maxLength, minValue, maxValue, pattern, email, url, validate, ...props }, ref) {
55
+ function TextBoxInner({ name, label, helperText, showError = true, error: customError, size, variant, fullWidth = true, className, disabled, prefix, suffix, allowClear, onClear, passwordToggle, id: providedId, control: externalControl, required, minLength, maxLength, minValue, maxValue, pattern, email, url, validate, ...props }, ref) {
53
56
  const generatedId = (0, react.useId)();
54
57
  const inputId = providedId ?? generatedId;
58
+ const [passwordVisible, setPasswordVisible] = (0, react.useState)(false);
59
+ const showPasswordToggle = props.type === "password" && passwordToggle !== false;
60
+ const resolvedType = showPasswordToggle && passwordVisible ? "text" : props.type;
55
61
  const formConfigContext = (0, react.useContext)(require_context.FormConfigContext);
56
62
  const formConfig = formConfigContext ?? {};
57
63
  const rhfContext = (0, react_hook_form.useFormContext)();
@@ -137,6 +143,7 @@ function TextBoxInner({ name, label, helperText, showError = true, error: custom
137
143
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_textbox.TextBoxPrimitive, {
138
144
  ...props,
139
145
  ...field,
146
+ type: resolvedType,
140
147
  ref: (node) => {
141
148
  if (typeof ref === "function") ref(node);
142
149
  else if (ref) ref.current = node;
@@ -149,21 +156,29 @@ function TextBoxInner({ name, label, helperText, showError = true, error: custom
149
156
  className: require_cn.cn(textBoxVariants({
150
157
  size: effectiveSize,
151
158
  variant: effectiveVariant
152
- }), prefix && "pl-10", (suffix || allowClear) && "pr-10", className)
159
+ }), prefix && "pl-10", (suffix || allowClear || showPasswordToggle) && "pr-10", className)
153
160
  }),
154
- (suffix || allowClear && field.value) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
161
+ (suffix || allowClear && field.value || showPasswordToggle) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
155
162
  className: "absolute right-3 top-1/2 -translate-y-1/2 flex items-center gap-1",
156
- children: [allowClear && field.value && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
157
- type: "button",
158
- onClick: handleClear,
159
- className: "text-muted-foreground hover:text-foreground transition-colors",
160
- tabIndex: -1,
161
- "aria-label": "Clear",
162
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, { className: "h-4 w-4" })
163
- }), suffix && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
164
- className: "text-muted-foreground",
165
- children: suffix
166
- })]
163
+ children: [
164
+ allowClear && field.value && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
165
+ type: "button",
166
+ onClick: handleClear,
167
+ className: "text-muted-foreground hover:text-foreground transition-colors",
168
+ tabIndex: -1,
169
+ "aria-label": "Clear",
170
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, { className: "h-4 w-4" })
171
+ }),
172
+ showPasswordToggle && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PasswordRevealToggle.PasswordRevealToggle, {
173
+ visible: passwordVisible,
174
+ onToggle: () => setPasswordVisible((visible) => !visible),
175
+ disabled: effectiveDisabled
176
+ }),
177
+ suffix && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
178
+ className: "text-muted-foreground",
179
+ children: suffix
180
+ })
181
+ ]
167
182
  })
168
183
  ]
169
184
  })