@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
@@ -1 +1 @@
1
- {"version":3,"file":"FormSwitch.js","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,qBAAqB,IACzB,IACA;CACE,UAAU,EACR,MAAM;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;CACN,EACF;CACA,iBAAiB,EACf,MAAM,KACR;AACF,CACF;AAEA,IAAM,gBAAgB,IACpB,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,cAAc,MAAM;CAC1B,MAAM,UAAU,cAAc;CAG9B,MAAM,oBAAoB,WAAW,iBAAiB;CACtD,MAAM,aAAyB,qBAAqB,CAAC;CAGrD,MAAM,aAAa,eAAgC;CACnD,MAAM,UAAU,mBAAmB,YAAY;CAG/C,gBAAgB;EACd,IAAI,mBAAmB,yBAAyB;GAC9C,MAAM,QAA8B,CAAC;GAErC,IAAI,aAAa,KAAA,GAAW,MAAM,WAAW;GAC7C,IAAI,aAAa,KAAA,GAAW,MAAM,WAAW;GAE7C,kBAAkB,wBAAwB;IAClC;IACN,MAAM;IACN;GACF,CAAC;GAED,aAAa;IACX,kBAAkB,0BAA0B,IAAc;GAC5D;EACF;CACF,GAAG;EAAC;EAAmB;EAAM;EAAU;CAAQ,CAAC;CAGhD,MAAM,EAAE,OAAO,eAAe,cAAmC;EAC/D;EACA;CACF,CAAC;CAED,MAAM,aAAa,WAAW,OAAO;CACrC,MAAM,eAAe,eAAe;CACpC,MAAM,WAAW,CAAC,CAAC;CAGnB,MAAM,gBAAgB,QAAQ,WAAW,QAAQ;CACjD,MAAM,oBAAoB,YAAY,WAAW;CACjD,MAAM,YAAY,MAAM,SAAS;CAEjC,OACE,qBAAC,OAAD;EAAK,WAAU;YAAf;GACE,qBAAC,OAAD;IAAK,WAAU;cAAf;KACE,oBAAC,QAAD;MACE,GAAI;MACC;MACL,IAAI;MACJ,SAAS;MACT,kBAAkB,YAAY,MAAM,SAAS,OAAO;MACpD,UAAU;MACV,mBAAiB,QAAQ,GAAG,QAAQ,UAAU,KAAA;MAC9C,WAAW,GACT,mBAAmB,EAAE,MAAM,cAAc,CAAC,GAC1C,SACF;KACD,CAAA;MAEC,eAAe,kBACf,oBAAC,QAAD;MAAM,WAAU;gBACb,YAAY,cAAc;KACvB,CAAA;KAGP,SACC,oBAAC,OAAD;MACE,IAAI,GAAG,QAAQ;MACf,SAAS;MACT,WAAW,cAAc,EAAE,UAAU,kBAAkB,CAAC;gBAEvD;KACI,CAAA;IAEN;;GAEJ,aAAa,YACZ,oBAAC,KAAD;IAAG,WAAU;IAA2B,MAAK;cAC1C;GACA,CAAA;GAGJ,cAAc,CAAC,YACd,oBAAC,KAAD;IAAG,WAAU;cACV;GACA,CAAA;EAEF;;AAET;AAEA,IAAa,aAAa,WAAW,eAAe;AAOpD,WAAyB,cAAc"}
1
+ {"version":3,"file":"FormSwitch.js","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,qBAAqB,IACzB,IACA;CACE,UAAU,EACR,MAAM;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;CACN,EACF;CACA,iBAAiB,EACf,MAAM,KACR;AACF,CACF;AAEA,IAAM,gBAAgB,IACpB,kDACA;CACE,UAAU,EACR,UAAU;EACR,MAAM;EACN,OAAO;CACT,EACF;CACA,iBAAiB,EACf,UAAU,MACZ;AACF,CACF;;;;;;;;;;;;;;;;;;AAg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MACb,UAAA,YAAY,cAAc;KACvB,CAAA;KAGP,SACC,oBAAC,OAAD;MACE,IAAI,GAAG,QAAQ;MACf,SAAS;MACT,WAAW,cAAc,EAAE,UAAU,kBAAkB,CAAC;MAEvD,UAAA;KACI,CAAA;IAEN;;GAEJ,aAAa,YACZ,oBAAC,KAAD;IAAG,WAAU;IAA2B,MAAK;IAC1C,UAAA;GACA,CAAA;GAGJ,cAAc,CAAC,YACd,oBAAC,KAAD;IAAG,WAAU;IACV,UAAA;GACA,CAAA;EAEF;;AAET;AAEA,IAAa,aAAa,WAAW,eAAe;AAOpD,WAAyB,cAAc"}
@@ -0,0 +1,7 @@
1
+ export interface PasswordRevealToggleProps {
2
+ visible: boolean;
3
+ onToggle: () => void;
4
+ disabled?: boolean;
5
+ }
6
+ export declare function PasswordRevealToggle({ visible, onToggle, disabled, }: PasswordRevealToggleProps): import("react").JSX.Element;
7
+ //# sourceMappingURL=PasswordRevealToggle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PasswordRevealToggle.d.ts","sourceRoot":"","sources":["../../../src/components/Form/PasswordRevealToggle.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,yBAAyB;IACzC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,oBAAoB,CAAC,EACpC,OAAO,EACP,QAAQ,EACR,QAAgB,GAChB,EAAE,yBAAyB,+BAc3B"}
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ "use client";
3
+ import { jsx } from "react/jsx-runtime";
4
+ import { Eye, EyeOff } from "lucide-react";
5
+ //#region src/components/Form/PasswordRevealToggle.tsx
6
+ function PasswordRevealToggle({ visible, onToggle, disabled = false }) {
7
+ return /* @__PURE__ */ 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__ */ jsx(EyeOff, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(Eye, { className: "h-4 w-4" })
16
+ });
17
+ }
18
+ //#endregion
19
+ export { PasswordRevealToggle };
20
+
21
+ //# sourceMappingURL=PasswordRevealToggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PasswordRevealToggle.js","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,oBAAC,UAAD;EACC,MAAK;EACL,SAAS;EACC;EACV,WAAU;EACV,UAAU;EACV,cAAY,UAAU,kBAAkB;EACxC,gBAAc;EAEb,UAAA,UAAU,oBAAC,QAAD,EAAQ,WAAU,UAAW,CAAA,IAAI,oBAAC,KAAD,EAAK,WAAU,UAAW,CAAA;CAC/D,CAAA;AAEV"}
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneInput.js","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,qBAAqB,IAAI,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,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,WAAW,MAC1D,OAAO;CAGT,OAAO;EAAE,OAAO;EAAW,SAAS;CAAe;AACrD;AAEA,SAAS,mBACP,UACA,WACA,WACA,UACA;CACA,MAAM,kBACJ,OAAO,aAAa,WAAW,WAAW;CAE5C,OAAO,OAAO,UAAmB;EAE/B,MAAM,iBADS,UAAU,OAAO,SAAS,EAAE,CACpB,CAAA,EAAQ,kBAAkB;EAEjD,IAAI,aAAa,KAAA,KAAa,CAAC,gBAC7B,OAAO;EAGT,MAAM,gBAAgB,uBACpB,WACA,WAAW,OAAO,cAAc,WAAW,YAAY,WAAW,MAAM,iBAC1E;EACA,IAAI,iBAAiB,eAAe,SAAS,cAAc,OACzD,OAAO,cAAc;EAGvB,MAAM,gBAAgB,uBACpB,WACA,WAAW,OAAO,cAAc,WAAW,YAAY,WAAW,MAAM,gBAC1E;EACA,IAAI,iBAAiB,eAAe,SAAS,cAAc,OACzD,OAAO,cAAc;EAGvB,IAAI,UACF,OAAO,SAAS,KAAK;EAGvB,OAAO;CACT;AACF;AAEA,SAAgB,WAGd,EACA,MACA,OACA,YACA,YAAY,MACZ,OAAO,aACP,MACA,SACA,YAAY,MACZ,cAAc,iBACd,UACA,WACA,I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eAAe;CACpC,MAAM,WAAW,CAAC,CAAC;CACnB,MAAM,gBAAgB,QAAQ,WAAW,QAAQ;CACjD,MAAM,oBAAoB,YAAY,WAAW;CACjD,MAAM,mBAAmB,WAAW,UAAU;CAC9C,MAAM,WAAW,mBAAmB,WAAW;CAE/C,MAAM,eAAe,iBAAyB,uBAA+B;EAC3E,eAAe,eAAe;EAC9B,kBAAkB,kBAAkB;EACpC,MAAM,SAAS,WAAW,iBAAiB,kBAAkB,CAAC;CAChE;CAEA,OACE,oBAAC,aAAD;EACW;EACF;EACP,UAAU,CAAC,CAAC;EACA;EACZ,cAAc,YAAY,eAAe,KAAA;EAC9B;EACA;EACC;YAEZ,qBAAC,OAAD;GACE,WAAW,GACT,qHACA,mBAAmB;IAAE,MAAM;IAAe,SAAS;GAAiB,CAAC,GACrE,SACF;aALF;IAOE,oBAAC,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,oBAAC,OAAD;KAAK,WAAU;eACZ;IACE,CAAA;IAEL,oBAAC,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,GACT,iHACF;IACD,CAAA;GACE;;CACM,CAAA;AAEjB;AAEA,WAAW,cAAc"}
1
+ {"version":3,"file":"PhoneInput.js","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,qBAAqB,IAAI,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,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,WAAW,MAC1D,OAAO;CAGT,OAAO;EAAE,OAAO;EAAW,SAAS;CAAe;AACrD;AAEA,SAAS,mBACP,UACA,WACA,WACA,UACA;CACA,MAAM,kBACJ,OAAO,aAAa,WAAW,WAAW;CAE5C,OAAO,OAAO,UAAmB;EAE/B,MAAM,iBADS,UAAU,OAAO,SAAS,EAAE,CACpB,CAAA,EAAQ,kBAAkB;EAEjD,IAAI,aAAa,KAAA,KAAa,CAAC,gBAC7B,OAAO;EAGT,MAAM,gBAAgB,uBACpB,WACA,WAAW,OAAO,cAAc,WAAW,YAAY,WAAW,MAAM,iBAC1E;EACA,IAAI,iBAAiB,eAAe,SAAS,cAAc,OACzD,OAAO,cAAc;EAGvB,MAAM,gBAAgB,uBACpB,WACA,WAAW,OAAO,cAAc,WAAW,YAAY,WAAW,MAAM,gBAC1E;EACA,IAAI,iBAAiB,eAAe,SAAS,cAAc,OACzD,OAAO,cAAc;EAGvB,IAAI,UACF,OAAO,SAAS,KAAK;EAGvB,OAAO;CACT;AACF;AAEA,SAAgB,WAGd,EACA,MACA,OACA,YACA,YAAY,MACZ,OAAO,aACP,MACA,SACA,YAAY,MACZ,cAAc,iBACd,UACA,WACA,IAAI,YACJ,SAAS,iBACT,iBAAiB,MACjB,mBACA,UACA,WAC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AAgB,QAAQ,WAAW,QAAQ;CACjD,MAAM,oBAAoB,YAAY,WAAW;CACjD,MAAM,mBAAmB,WAAW,UAAU;CAC9C,MAAM,WAAW,mBAAmB,WAAW;CAE/C,MAAM,eAAe,iBAAyB,uBAA+B;EAC3E,eAAe,eAAe;EAC9B,kBAAkB,kBAAkB;EACpC,MAAM,SAAS,WAAW,iBAAiB,kBAAkB,CAAC;CAChE;CAEA,OACE,oBAAC,aAAD;EACW;EACF;EACP,UAAU,CAAC,CAAC;EACA;EACZ,cAAc,YAAY,eAAe,KAAA;EAC9B;EACA;EACC;EAEZ,UAAA,qBAAC,OAAD;GACE,WAAW,GACT,qHACA,mBAAmB;IAAE,MAAM;IAAe,SAAS;GAAiB,CAAC,GACrE,SACF;GALF,UAAA;IAOE,oBAAC,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,oBAAC,OAAD;KAAK,WAAU;KACZ,UAAA;IACE,CAAA;IAEL,oBAAC,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,GACT,iHACF;IACD,CAAA;GACE;;CACM,CAAA;AAEjB;AAEA,WAAW,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"Radio.js","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,oBAAoB,IACxB,IACA;CACE,UAAU,EACR,MAAM;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;CACN,EACF;CACA,iBAAiB,EACf,MAAM,KACR;AACF,CACF;AAEA,IAAM,gBAAgB,IACpB,kDACA;CACE,UAAU,EACR,UAAU;EACR,MAAM;EACN,OAAO;CACT,EACF;CACA,iBAAiB,EACf,UAAU,MACZ;AACF,CACF;AAWA,IAAM,oBAAoB,cAA6C,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,cAAc,MAAM;CAG1B,MAAM,oBAAoB,WAAW,iBAAiB;CACtD,MAAM,aAAyB,qBAAqB,CAAC;CAGrD,MAAM,aAAa,eAAgC;CACnD,MAAM,UAAU,mBAAmB,YAAY;CAG/C,gBAAgB;EACd,IAAI,mBAAmB,yBAAyB;GAC9C,MAAM,QAA8B,CAAC;GAErC,IAAI,aAAa,KAAA,GAAW,MAAM,WAAW;GAC7C,IAAI,aAAa,KAAA,GAAW,MAAM,WAAW;GAE7C,kBAAkB,wBAAwB;IAClC;IACN,MAAM;IACN;GACF,CAAC;GAED,aAAa;IACX,kBAAkB,0BAA0B,IAAc;GAC5D;EACF;CACF,GAAG;EAAC;EAAmB;EAAM;EAAU;CAAQ,CAAC;CAGhD,MAAM,EAAE,OAAO,eAAe,cAAmC;EAC/D;EACA;CACF,CAAC;CAED,MAAM,aAAa,WAAW,OAAO;CACrC,MAAM,eAAe,eAAe;CACpC,MAAM,WAAW,CAAC,CAAC;CAGnB,MAAM,gBAAgB,QAAQ,WAAW,QAAQ;CACjD,MAAM,oBAAoB,YA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B,UAAU;GACV,WAAW,GACT,kBAAkB,EAAE,MAAM,cAAc,CAAC,GACzC,YAAY,WAAW,sBACvB,SACF;EACD,CAAA,GAEA,YACC,oBAAC,OAAD;GACE,SAAS;GACT,WAAW,cAAc,EAAE,UAAU,kBAAkB,CAAC;GAEvD;EACI,CAAA,CAEN;;AAET;AAEA,IAAa,YAAY,WAAW,cAAc;AAClD,UAAU,cAAc"}
1
+ {"version":3,"file":"Radio.js","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,oBAAoB,IACxB,IACA;CACE,UAAU,EACR,MAAM;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;CACN,EACF;CACA,iBAAiB,EACf,MAAM,KACR;AACF,CACF;AAEA,IAAM,gBAAgB,IACpB,kDACA;CACE,UAAU,EACR,UAAU;EACR,MAAM;EACN,OAAO;CACT,EACF;CACA,iBAAiB,EACf,UAAU,MACZ;AACF,CACF;AAWA,IAAM,oBAAoB,cAA6C,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,cAAc,MAAM;CAG1B,MAAM,oBAAoB,WAAW,iBAAiB;CACtD,MAAM,aAAyB,qBAAqB,CAAC;CAGrD,MAAM,aAAa,eAAgC;CACnD,MAAM,UAAU,mBAAmB,YAAY;CAG/C,gBAAgB;EACd,IAAI,mBAAmB,yBAAyB;GAC9C,MAAM,QAA8B,CAAC;GAErC,IAAI,aAAa,KAAA,GAAW,MAAM,WAAW;GAC7C,IAAI,aAAa,KAAA,GAAW,MAAM,WAAW;GA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A;GACA,CAAA;EAEF;;AAET;AAEA,WAAW,cAAc;;;;;;AAiBzB,SAAS,eACP,EACE,OACA,UACA,MACA,SACA,WACA,UACA,IAAI,YACJ,GAAG,SAEL,KACA;CACA,MAAM,cAAc,MAAM;CAC1B,MAAM,UAAU,cAAc;CAE9B,MAAM,eAAe,WAAW,iBAAiB;CAEjD,MAAM,gBAAgB,QAAQ,cAAc,QAAQ;CACpD,MAAM,oBAAoB,YAAY,cAAc;CAEpD,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACE,oBAAC,gBAAD;GACE,GAAI;GACC;GACL,IAAI;GACJ,OAAO,MAAM,SAAS;GACtB,UAAU;GACV,WAAW,GACT,kBAAkB,EAAE,MAAM,cAAc,CAAC,GACzC,YAAY,WAAW,sBACvB,SACF;EACD,CAAA,GAEA,YACC,oBAAC,OAAD;GACE,SAAS;GACT,WAAW,cAAc,EAAE,UAAU,kBAAkB,CAAC;GAEvD;EACI,CAAA,CAEN;;AAET;AAEA,IAAa,YAAY,WAAW,cAAc;AAClD,UAAU,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"Select.js","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,qBAAqB,IACzB,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,YACmC;CACnC,MAAM,cAAc,MAAM;CAC1B,MAAM,UAAU,cAAc;CAG9B,MAAM,oBAAoB,WAAW,iBAAiB;CACtD,MAAM,aAAyB,qBAAqB,CAAC;CAGrD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OAAM;cAChB,oBAAC,QAAD;KAAM,WAAU;eAAwB;IAAqB,CAAA;GACnD,CAAA,GAEb,YAAY,QAAQ,KAAK,WACxB,oBAAC,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.js","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,qBAAqB,IACzB,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,YACmC;CACnC,MAAM,cAAc,MAAM;CAC1B,MAAM,UAAU,cAAc;CAG9B,MAAM,oBAAoB,WAAW,iBAAiB;CACtD,MAAM,aAAyB,qBAAqB,CAAC;CAGrD,MAAM,aAAa,eAAgC;CACnD,MAAM,UAAU,mBAAmB,YAAY;CAG/C,gBAAgB;EACd,IAAI,mBAAmB,yBAAyB;GAC9C,MAAM,QAA8B,CAAC;GAErC,IAAI,aAAa,KAAA,GAAW,MAAM,WAAW;GAC7C,IAAI,aAAa,KAAA,GAAW,MAAM,WAAW;GAE7C,kBAAkB,wBAAwB;IAClC;IACN,MAAM;IACN;GACF,CAAC;GAED,aAAa;IACX,kBAAkB,0BAA0B,IAAc;GAC5D;EACF;CACF,GAAG;EAAC;EAAmB;EAAM;EAAU;CAAQ,CAAC;CAGhD,MAAM,EAAE,OAAO,eAAe,cAAmC;EAC/D;EACA;CACF,CAAC;CAED,MAAM,aAAa,WAAW,OAAO;CACrC,MAAM,eAAe,eAAe;CACpC,MAAM,WAAW,CAAC,CAAC;CAGnB,MAAM,gBAAgB,QAAQ,WAAW,QAAQ;CACjD,MAAM,oBAAoB,YAAY,WAAW;CAGjD,MAAM,mBAAmB,WAAW,UAAU;CAE9C,OACE,oBAAC,aAAD;EACW;EACF;EACP,UAAU,CAAC,CAAC;EACA;EACZ,cAAc,YAAY,eAAe,KAAA;EAC9B;EACA;EACC;EAEZ,UAAA,qBAAC,UAAD;GACE,OAAO,MAAM,OAAO,SAAS,KAAK;GAClC,gBAAgB,UAAU;IACxB,IAAI,UAAU,MAAM,YAClB,MAAM,SAAS,EAAE;SAEjB,MAAM,SAAS,KAAK;GAExB;GACA,UAAU;GATZ,UAAA,CAWE,oBAAC,eAAD;IACE,IAAI;IACJ,gBAAc;IACd,oBACE,WACI,GAAG,QAAQ,UACX,aACE,GAAG,QAAQ,WACX,KAAA;IAER,WAAW,GACT,mBAAmB,EAAE,MAAM,cAAc,CAAC,GAC1C,qBAAqB,WAAW,6CAChC,qBAAqB,aAAa,yCAClC,SACF;IAEA,UAAA,oBAAC,aAAD,EAA0B,YAAc,CAAA;GAC3B,CAAA,GACf,qBAAC,eAAD,EAAA,UAAA,CACG,cAAc,MAAM,SACnB,oBAAC,YAAD;IAAY,OAAM;IAChB,UAAA,oBAAC,QAAD;KAAM,WAAU;KAAwB,UAAA;IAAqB,CAAA;GACnD,CAAA,GAEb,YAAY,QAAQ,KAAK,WACxB,oBAAC,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.js","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,uBAAuB,IAC3B,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,cAAc,MAAM;CAC1B,MAAM,UAAU,cAAc;CAG9B,MAAM,oBAAoB,WAAW,iBAAiB;CACtD,MAAM,aAAyB,qBAAqB,CAAC;CAGrD,MAAM,aAAa,eAAgC;CACnD,MAAM,UAAU,mBAAmB,YAAY;CAG/C,gBAAgB;EACd,IAAI,mBAAm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,QAAQ,WACX,KAAA;KAEN,WAAW,GACT,qBAAqB;MAAE,MAAM;MAAe,SAAS;KAAiB,CAAC,GACvE,aAAa,QACb,SACF;IACD,CAAA,GAEA,aACC,qBAAC,OAAD;KAAK,WAAU;eAAf,CACG,eAAe,WAAW,IAAI,aAAa,EACzC;MAEJ;;GAEJ,aAAa,YACZ,oBAAC,KAAD;IACE,IAAI,GAAG,QAAQ;IACf,WAAU;IACV,MAAK;cAEJ;GACA,CAAA;GAGJ,cAAc,CAAC,YACd,oBAAC,KAAD;IACE,IAAI,GAAG,QAAQ;IACf,WAAU;cAET;GACA,CAAA;EAEF;;AAET;AAGA,IAAa,WAAW,WAAW,aAAa;AAOhD,SAAuB,cAAc"}
1
+ {"version":3,"file":"TextArea.js","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,uBAAuB,IAC3B,IACA;CACE,U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MAAM,SAAS;CAG7E,MAAM,iBAAiB,aAAa,OAAO,cAAc,WAAW,YAAa,WAAiC;CAElH,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,eAAe,aAAa,QAAQ;EAAvD,UAAA;GACG,SACC,qBAAC,OAAD;IACE,SAAS;IACT,WAAW,cAAc,EAAE,UAAU,CAAC,CAAC,SAAS,CAAC;IAFnD,UAAA,CAIG,OACA,WAAW,SAAS,GAChB;;GAGT,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,oBAAC,UAAD;KACE,GAAI;KACJ,GAAI;KACJ,MAAM,SAAS;MACb,IAAI,OAAO,QAAQ,YACjB,IAAI,IAAI;WACH,IAAI,KACT,IAAI,UAAU;MAEhB,MAAM,IAAI,IAAI;KAChB;KACA,IAAI;KACJ,UAAU;KACV,WAAW;KACX,gBAAc;KACd,oBACE,WACI,GAAG,QAAQ,UACX,aACA,GAAG,QAAQ,WACX,KAAA;KAEN,WAAW,GACT,qBAAqB;MAAE,MAAM;MAAe,SAAS;KAAiB,CAAC,GACvE,aAAa,QACb,SACF;IACD,CAAA,GAEA,aACC,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACG,eAAe,WAAW,IAAI,aAAa,EACzC;IAEJ,CAAA,CAAA;;GAEJ,aAAa,YACZ,oBAAC,KAAD;IACE,IAAI,GAAG,QAAQ;IACf,WAAU;IACV,MAAK;IAEJ,UAAA;GACA,CAAA;GAGJ,cAAc,CAAC,YACd,oBAAC,KAAD;IACE,IAAI,GAAG,QAAQ;IACf,WAAU;IAET,UAAA;GACA,CAAA;EAEF;;AAET;AAGA,IAAa,WAAW,WAAW,aAAa;AAOhD,SAAuB,cAAc"}
@@ -33,6 +33,11 @@ export interface TextBoxProps<TFieldValues extends FieldValues = FieldValues, TN
33
33
  allowClear?: boolean;
34
34
  /** Callback when clear is clicked */
35
35
  onClear?: () => void;
36
+ /**
37
+ * Show an eye toggle for password fields.
38
+ * Defaults to true when `type="password"`.
39
+ */
40
+ passwordToggle?: boolean;
36
41
  /** External control (for use outside Form) */
37
42
  control?: Control<TFieldValues>;
38
43
  /** Field is required */
@@ -1 +1 @@
1
- {"version":3,"file":"TextBox.d.ts","sourceRoot":"","sources":["../../../src/components/Form/TextBox.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAsD,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACrI,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAOlE,QAAA,MAAM,eAAe;;;8EAoBpB,CAAC;AAEF;;GAEG;AACH,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3D,MAAM,WAAW,YAAY,CAC3B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,KAAK,SAAS,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,CAC/D,SAAQ,IAAI,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC,EAClI,YAAY,CAAC,OAAO,eAAe,CAAC;IACtC,iDAAiD;IACjD,IAAI,EAAE,KAAK,CAAC;IACZ,+BAA+B;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,qBAAqB;IACrB,MAAM,CAAC,EAAE,SAAS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figContext } from "./context.js";
5
5
  import { FieldLayout } from "./FieldLayout.js";
6
+ import { PasswordRevealToggle } from "./PasswordRevealToggle.js";
6
7
  import { TextBoxPrimitive } from "../../primitives/textbox.js";
7
- import { forwardRef, useContext, useEffect, useId } from "react";
8
+ import { forwardRef, useContext, useEffect, useId, useState } from "react";
8
9
  import { cva } from "class-variance-authority";
9
10
  import { jsx, jsxs } from "react/jsx-runtime";
10
11
  import { useController, useFormContext } from "react-hook-form";
@@ -37,6 +38,7 @@ var textBoxVariants = 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 = 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 = useId();
54
57
  const inputId = providedId ?? generatedId;
58
+ const [passwordVisible, setPasswordVisible] = useState(false);
59
+ const showPasswordToggle = props.type === "password" && passwordToggle !== false;
60
+ const resolvedType = showPasswordToggle && passwordVisible ? "text" : props.type;
55
61
  const formConfigContext = useContext(FormConfigContext);
56
62
  const formConfig = formConfigContext ?? {};
57
63
  const rhfContext = useFormContext();
@@ -137,6 +143,7 @@ function TextBoxInner({ name, label, helperText, showError = true, error: custom
137
143
  /* @__PURE__ */ jsx(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: 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__ */ jsxs("div", {
161
+ (suffix || allowClear && field.value || showPasswordToggle) && /* @__PURE__ */ 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__ */ 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__ */ jsx(X, { className: "h-4 w-4" })
163
- }), suffix && /* @__PURE__ */ jsx("span", {
164
- className: "text-muted-foreground",
165
- children: suffix
166
- })]
163
+ children: [
164
+ allowClear && field.value && /* @__PURE__ */ 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__ */ jsx(X, { className: "h-4 w-4" })
171
+ }),
172
+ showPasswordToggle && /* @__PURE__ */ jsx(PasswordRevealToggle, {
173
+ visible: passwordVisible,
174
+ onToggle: () => setPasswordVisible((visible) => !visible),
175
+ disabled: effectiveDisabled
176
+ }),
177
+ suffix && /* @__PURE__ */ jsx("span", {
178
+ className: "text-muted-foreground",
179
+ children: suffix
180
+ })
181
+ ]
167
182
  })
168
183
  ]
169
184
  })
@@ -1 +1 @@
1
- {"version":3,"file":"TextBox.js","names":[],"sources":["../../../src/components/Form/TextBox.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { forwardRef, useId, useContext, useEffect } from \"react\";\r\nimport type { InputHTMLAttributes, 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 { TextBoxPrimitive } from \"../../primitives/textbox\";\r\nimport { X } from \"lucide-react\";\r\n\r\nconst textBoxVariants = cva(\r\n \"\",\r\n {\r\n variants: {\r\n size: {\r\n sm: \"h-8 text-xs px-2\",\r\n md: \"h-10 text-sm px-3\",\r\n lg: \"h-12 text-base px-4\",\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 TextBoxProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends Omit<InputHTMLAttributes<HTMLInputElement>, \"size\" | \"name\" | \"prefix\" | \"pattern\" | \"required\" | \"minLength\" | \"maxLength\">,\r\n VariantProps<typeof textBoxVariants> {\r\n /** Field name - required for form integration */\r\n name: TName;\r\n /** Label text for the input */\r\n label?: string;\r\n /** Helper text displayed below the input */\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 input should take full width */\r\n fullWidth?: boolean;\r\n /** Prefix element */\r\n prefix?: ReactNode;\r\n /** Suffix element */\r\n suffix?: ReactNode;\r\n /** Allow clear button */\r\n allowClear?: boolean;\r\n /** Callback when clear is clicked */\r\n onClear?: () => void;\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 for strings */\r\n minLength?: ValidationRule<number>;\r\n /** Maximum length for strings */\r\n maxLength?: ValidationRule<number>;\r\n /** Minimum value for numbers */\r\n minValue?: ValidationRule<number>;\r\n /** Maximum value for numbers */\r\n maxValue?: ValidationRule<number>;\r\n /** Regex pattern for validation */\r\n pattern?: ValidationRule<RegExp>;\r\n /** Email validation */\r\n email?: boolean | string;\r\n /** URL validation */\r\n url?: 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 * TextBox component with form integration and automatic validation registration\r\n * \r\n * This is a wrapper around the shadcn/ui Input 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 * - Prefix/suffix elements\r\n * - Clear button functionality\r\n * \r\n * @example\r\n * ```tsx\r\n * // Inside a Form component - validation is automatically registered\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 * <TextBox name=\"website\" label=\"Website\" url />\r\n * <Button type=\"submit\">Submit</Button>\r\n * </Form>\r\n * ```\r\n */\r\nfunction TextBoxInner<\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 prefix,\r\n suffix,\r\n allowClear,\r\n onClear,\r\n id: providedId,\r\n control: externalControl,\r\n // Validation props\r\n required,\r\n minLength,\r\n maxLength,\r\n minValue,\r\n maxValue,\r\n pattern,\r\n email,\r\n url,\r\n validate,\r\n ...props\r\n }: TextBoxProps<TFieldValues, TName>,\r\n ref: React.ForwardedRef<HTMLInputElement>\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 // Destructure stable function references so the effect doesn't depend on the\r\n // context object identity (which changes every render due to inline construction).\r\n const registerFieldValidation = formConfigContext?.registerFieldValidation;\r\n const unregisterFieldValidation = formConfigContext?.unregisterFieldValidation;\r\n\r\n // Register validation rules with the form\r\n useEffect(() => {\r\n if (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 (minValue !== undefined) rules.min = minValue;\r\n if (maxValue !== undefined) rules.max = maxValue;\r\n if (pattern !== undefined) rules.pattern = pattern;\r\n if (email !== undefined) rules.email = email;\r\n if (url !== undefined) rules.url = url;\r\n if (validate !== undefined) rules.validate = validate;\r\n\r\n // Determine field type and auto-infer rules from input type\r\n const inputType = props.type ?? \"text\";\r\n let fieldType: \"string\" | \"number\" | \"date\" = \"string\";\r\n\r\n if (inputType === \"number\") {\r\n fieldType = \"number\";\r\n } else if (inputType === \"date\") {\r\n fieldType = \"date\";\r\n } else if (inputType === \"email\" && rules.email === undefined) {\r\n rules.email = true;\r\n } else if (inputType === \"url\" && rules.url === undefined) {\r\n rules.url = true;\r\n } else if (inputType === \"tel\" && rules.pattern === undefined) {\r\n rules.pattern = { value: /^\\+?[\\d\\s\\-().]{7,}$/, message: \"Invalid phone number\" };\r\n }\r\n\r\n registerFieldValidation({\r\n name: name as string,\r\n type: fieldType,\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 minValue,\r\n maxValue,\r\n pattern,\r\n email,\r\n url,\r\n validate,\r\n props.type,\r\n ]);\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 handleClear = () => {\r\n field.onChange(\"\");\r\n onClear?.();\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 className=\"relative\">\r\n {prefix && (\r\n <div className=\"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground\">\r\n {prefix}\r\n </div>\r\n )}\r\n\r\n <TextBoxPrimitive\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 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 textBoxVariants({ size: effectiveSize, variant: effectiveVariant }),\r\n prefix && \"pl-10\",\r\n (suffix || allowClear) && \"pr-10\",\r\n className\r\n )}\r\n />\r\n\r\n {(suffix || (allowClear && field.value)) && (\r\n <div className=\"absolute right-3 top-1/2 -translate-y-1/2 flex items-center gap-1\">\r\n {allowClear && field.value && (\r\n <button\r\n type=\"button\"\r\n onClick={handleClear}\r\n className=\"text-muted-foreground hover:text-foreground transition-colors\"\r\n tabIndex={-1}\r\n aria-label=\"Clear\"\r\n >\r\n <X className=\"h-4 w-4\" />\r\n </button>\r\n )}\r\n {suffix && (\r\n <span className=\"text-muted-foreground\">{suffix}</span>\r\n )}\r\n </div>\r\n )}\r\n </div>\r\n </FieldLayout>\r\n );\r\n}\r\n\r\n// Use forwardRef with generic support\r\nexport const TextBox = forwardRef(TextBoxInner) as <\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(\r\n props: TextBoxProps<TFieldValues, TName> & { ref?: React.ForwardedRef<HTMLInputElement> }\r\n) => React.ReactElement;\r\n\r\n(TextBox as React.FC).displayName = \"TextBox\";\r\n"],"mappings":";;;;;;;;;;;;AAYA,IAAM,kBAAkB,IACtB,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;;;;;;;;;;;;;;;;;;;;;;AA6EA,SAAS,aAIP,EACE,MACA,OACA,YACA,YAAY,MACZ,OAAO,aACP,MACA,SACA,YAAY,MACZ,WACA,UACA,QACA,QACA,YACA,SACA,IAAI,YACJ,SAAS,iBAET,UACA,WACA,WACA,UACA,UACA,SACA,OACA,KACA,UACA,GAAG,SAEL,KACA;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../../src/components/Form/TextBox.tsx"],"sourcesContent":["'use client';\r\n\r\nimport { forwardRef, useId, useContext, useEffect, useState } from \"react\";\r\nimport type { InputHTMLAttributes, 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 { PasswordRevealToggle } from \"./PasswordRevealToggle\";\r\nimport { TextBoxPrimitive } from \"../../primitives/textbox\";\r\nimport { X } from \"lucide-react\";\r\n\r\nconst textBoxVariants = cva(\r\n \"\",\r\n {\r\n variants: {\r\n size: {\r\n sm: \"h-8 text-xs px-2\",\r\n md: \"h-10 text-sm px-3\",\r\n lg: \"h-12 text-base px-4\",\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 TextBoxProps<\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n> extends Omit<InputHTMLAttributes<HTMLInputElement>, \"size\" | \"name\" | \"prefix\" | \"pattern\" | \"required\" | \"minLength\" | \"maxLength\">,\r\n VariantProps<typeof textBoxVariants> {\r\n /** Field name - required for form integration */\r\n name: TName;\r\n /** Label text for the input */\r\n label?: string;\r\n /** Helper text displayed below the input */\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 input should take full width */\r\n fullWidth?: boolean;\r\n /** Prefix element */\r\n prefix?: ReactNode;\r\n /** Suffix element */\r\n suffix?: ReactNode;\r\n /** Allow clear button */\r\n allowClear?: boolean;\r\n /** Callback when clear is clicked */\r\n onClear?: () => void;\r\n /**\r\n * Show an eye toggle for password fields.\r\n * Defaults to true when `type=\"password\"`.\r\n */\r\n passwordToggle?: boolean;\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 for strings */\r\n minLength?: ValidationRule<number>;\r\n /** Maximum length for strings */\r\n maxLength?: ValidationRule<number>;\r\n /** Minimum value for numbers */\r\n minValue?: ValidationRule<number>;\r\n /** Maximum value for numbers */\r\n maxValue?: ValidationRule<number>;\r\n /** Regex pattern for validation */\r\n pattern?: ValidationRule<RegExp>;\r\n /** Email validation */\r\n email?: boolean | string;\r\n /** URL validation */\r\n url?: 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 * TextBox component with form integration and automatic validation registration\r\n * \r\n * This is a wrapper around the shadcn/ui Input 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 * - Prefix/suffix elements\r\n * - Clear button functionality\r\n * - Built-in password reveal toggle when `type=\"password\"`\r\n * \r\n * @example\r\n * ```tsx\r\n * // Inside a Form component - validation is automatically registered\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 * <TextBox name=\"password\" label=\"Password\" type=\"password\" required />\r\n * <TextBox name=\"website\" label=\"Website\" url />\r\n * <Button type=\"submit\">Submit</Button>\r\n * </Form>\r\n * ```\r\n */\r\nfunction TextBoxInner<\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 prefix,\r\n suffix,\r\n allowClear,\r\n onClear,\r\n passwordToggle,\r\n id: providedId,\r\n control: externalControl,\r\n // Validation props\r\n required,\r\n minLength,\r\n maxLength,\r\n minValue,\r\n maxValue,\r\n pattern,\r\n email,\r\n url,\r\n validate,\r\n ...props\r\n }: TextBoxProps<TFieldValues, TName>,\r\n ref: React.ForwardedRef<HTMLInputElement>\r\n) {\r\n const generatedId = useId();\r\n const inputId = providedId ?? generatedId;\r\n const [passwordVisible, setPasswordVisible] = useState(false);\r\n const isPasswordType = props.type === \"password\";\r\n const showPasswordToggle = isPasswordType && passwordToggle !== false;\r\n const resolvedType = showPasswordToggle && passwordVisible ? \"text\" : props.type;\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 // Destructure stable function references so the effect doesn't depend on the\r\n // context object identity (which changes every render due to inline construction).\r\n const registerFieldValidation = formConfigContext?.registerFieldValidation;\r\n const unregisterFieldValidation = formConfigContext?.unregisterFieldValidation;\r\n\r\n // Register validation rules with the form\r\n useEffect(() => {\r\n if (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 (minValue !== undefined) rules.min = minValue;\r\n if (maxValue !== undefined) rules.max = maxValue;\r\n if (pattern !== undefined) rules.pattern = pattern;\r\n if (email !== undefined) rules.email = email;\r\n if (url !== undefined) rules.url = url;\r\n if (validate !== undefined) rules.validate = validate;\r\n\r\n // Determine field type and auto-infer rules from input type\r\n const inputType = props.type ?? \"text\";\r\n let fieldType: \"string\" | \"number\" | \"date\" = \"string\";\r\n\r\n if (inputType === \"number\") {\r\n fieldType = \"number\";\r\n } else if (inputType === \"date\") {\r\n fieldType = \"date\";\r\n } else if (inputType === \"email\" && rules.email === undefined) {\r\n rules.email = true;\r\n } else if (inputType === \"url\" && rules.url === undefined) {\r\n rules.url = true;\r\n } else if (inputType === \"tel\" && rules.pattern === undefined) {\r\n rules.pattern = { value: /^\\+?[\\d\\s\\-().]{7,}$/, message: \"Invalid phone number\" };\r\n }\r\n\r\n registerFieldValidation({\r\n name: name as string,\r\n type: fieldType,\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 minValue,\r\n maxValue,\r\n pattern,\r\n email,\r\n url,\r\n validate,\r\n props.type,\r\n ]);\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 handleClear = () => {\r\n field.onChange(\"\");\r\n onClear?.();\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 className=\"relative\">\r\n {prefix && (\r\n <div className=\"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground\">\r\n {prefix}\r\n </div>\r\n )}\r\n\r\n <TextBoxPrimitive\r\n {...props}\r\n {...field}\r\n type={resolvedType}\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 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 textBoxVariants({ size: effectiveSize, variant: effectiveVariant }),\r\n prefix && \"pl-10\",\r\n (suffix || allowClear || showPasswordToggle) && \"pr-10\",\r\n className\r\n )}\r\n />\r\n\r\n {(suffix || (allowClear && field.value) || showPasswordToggle) && (\r\n <div className=\"absolute right-3 top-1/2 -translate-y-1/2 flex items-center gap-1\">\r\n {allowClear && field.value && (\r\n <button\r\n type=\"button\"\r\n onClick={handleClear}\r\n className=\"text-muted-foreground hover:text-foreground transition-colors\"\r\n tabIndex={-1}\r\n aria-label=\"Clear\"\r\n >\r\n <X className=\"h-4 w-4\" />\r\n </button>\r\n )}\r\n {showPasswordToggle && (\r\n <PasswordRevealToggle\r\n visible={passwordVisible}\r\n onToggle={() => setPasswordVisible((visible) => !visible)}\r\n disabled={effectiveDisabled}\r\n />\r\n )}\r\n {suffix && (\r\n <span className=\"text-muted-foreground\">{suffix}</span>\r\n )}\r\n </div>\r\n )}\r\n </div>\r\n </FieldLayout>\r\n );\r\n}\r\n\r\n// Use forwardRef with generic support\r\nexport const TextBox = forwardRef(TextBoxInner) as <\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\r\n>(\r\n props: TextBoxProps<TFieldValues, TName> & { ref?: React.ForwardedRef<HTMLInputElement> }\r\n) => React.ReactElement;\r\n\r\n(TextBox as React.FC).displayName = \"TextBox\";\r\n"],"mappings":";;;;;;;;;;;;;AAaA,IAAM,kBAAkB,IACtB,IACA;CACE,UA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ACE,WACI,GAAG,QAAQ,UACX,aACE,GAAG,QAAQ,WACX,KAAA;KAER,WAAW,GACT,gBAAgB;MAAE,MAAM;MAAe,SAAS;KAAiB,CAAC,GAClE,UAAU,UACT,UAAU,cAAc,uBAAuB,SAChD,SACF;IACD,CAAA;KAEC,UAAW,cAAc,MAAM,SAAU,uBACzC,qBAAC,OAAD;KAAK,WAAU;KAAf,UAAA;MACG,cAAc,MAAM,SACnB,oBAAC,UAAD;OACE,MAAK;OACL,SAAS;OACT,WAAU;OACV,UAAU;OACV,cAAW;OAEX,UAAA,oBAAC,GAAD,EAAG,WAAU,UAAW,CAAA;MAClB,CAAA;MAET,sBACC,oBAAC,sBAAD;OACE,SAAS;OACT,gBAAgB,oBAAoB,YAAY,CAAC,OAAO;OACxD,UAAU;MACX,CAAA;MAEF,UACC,oBAAC,QAAD;OAAM,WAAU;OAAyB,UAAA;MAAa,CAAA;KAErD;;GAEJ;;CACM,CAAA;AAEjB;AAGA,IAAa,UAAU,WAAW,YAAY;AAO9C,QAAsB,cAAc"}
@@ -0,0 +1,14 @@
1
+ export type DayPeriod = "AM" | "PM";
2
+ export interface TimePickerProps {
3
+ value?: Date;
4
+ onChange: (date: Date) => void;
5
+ onClear?: () => void;
6
+ minuteStep?: number;
7
+ disabled?: boolean;
8
+ className?: string;
9
+ }
10
+ export declare function TimePicker({ value, onChange, onClear, minuteStep, disabled, className, }: TimePickerProps): import("react").JSX.Element;
11
+ export declare namespace TimePicker {
12
+ var displayName: string;
13
+ }
14
+ //# sourceMappingURL=TimePicker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimePicker.d.ts","sourceRoot":"","sources":["../../../src/components/Form/TimePicker.tsx"],"names":[],"mappings":"AAaA,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;AAEpC,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAuCD,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,QAAQ,EACR,OAAO,EACP,UAAc,EACd,QAAQ,EACR,SAAS,GACV,EAAE,eAAe,+BAoFjB;yBA3Fe,UAAU"}