@timeax/form-palette 0.0.1

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 (109) hide show
  1. package/.scaffold-cache.json +537 -0
  2. package/package.json +42 -0
  3. package/src/.scaffold-cache.json +544 -0
  4. package/src/adapters/axios.ts +117 -0
  5. package/src/adapters/index.ts +91 -0
  6. package/src/adapters/inertia.ts +187 -0
  7. package/src/core/adapter-registry.ts +87 -0
  8. package/src/core/bound/bind-host.ts +14 -0
  9. package/src/core/bound/observe-bound-field.ts +172 -0
  10. package/src/core/bound/wait-for-bound-field.ts +57 -0
  11. package/src/core/context.ts +23 -0
  12. package/src/core/core-provider.tsx +818 -0
  13. package/src/core/core-root.tsx +72 -0
  14. package/src/core/core-shell.tsx +44 -0
  15. package/src/core/errors/error-strip.tsx +71 -0
  16. package/src/core/errors/index.ts +2 -0
  17. package/src/core/errors/map-error-bag.ts +51 -0
  18. package/src/core/errors/map-zod.ts +39 -0
  19. package/src/core/hooks/use-button.ts +220 -0
  20. package/src/core/hooks/use-core-context.ts +20 -0
  21. package/src/core/hooks/use-core-utility.ts +0 -0
  22. package/src/core/hooks/use-core.ts +13 -0
  23. package/src/core/hooks/use-field.ts +497 -0
  24. package/src/core/hooks/use-optional-field.ts +28 -0
  25. package/src/core/index.ts +0 -0
  26. package/src/core/registry/binder-registry.ts +82 -0
  27. package/src/core/registry/field-registry.ts +187 -0
  28. package/src/core/test.tsx +17 -0
  29. package/src/global.d.ts +14 -0
  30. package/src/index.ts +68 -0
  31. package/src/input/index.ts +4 -0
  32. package/src/input/input-field.tsx +854 -0
  33. package/src/input/input-layout-graph.ts +230 -0
  34. package/src/input/input-props.ts +190 -0
  35. package/src/lib/get-global-countries.ts +87 -0
  36. package/src/lib/utils.ts +6 -0
  37. package/src/presets/index.ts +0 -0
  38. package/src/presets/shadcn-preset.ts +0 -0
  39. package/src/presets/shadcn-variants/checkbox.tsx +849 -0
  40. package/src/presets/shadcn-variants/chips.tsx +756 -0
  41. package/src/presets/shadcn-variants/color.tsx +284 -0
  42. package/src/presets/shadcn-variants/custom.tsx +227 -0
  43. package/src/presets/shadcn-variants/date.tsx +796 -0
  44. package/src/presets/shadcn-variants/file.tsx +764 -0
  45. package/src/presets/shadcn-variants/keyvalue.tsx +556 -0
  46. package/src/presets/shadcn-variants/multiselect.tsx +1132 -0
  47. package/src/presets/shadcn-variants/number.tsx +176 -0
  48. package/src/presets/shadcn-variants/password.tsx +737 -0
  49. package/src/presets/shadcn-variants/phone.tsx +628 -0
  50. package/src/presets/shadcn-variants/radio.tsx +578 -0
  51. package/src/presets/shadcn-variants/select.tsx +956 -0
  52. package/src/presets/shadcn-variants/slider.tsx +622 -0
  53. package/src/presets/shadcn-variants/text.tsx +343 -0
  54. package/src/presets/shadcn-variants/textarea.tsx +66 -0
  55. package/src/presets/shadcn-variants/toggle.tsx +218 -0
  56. package/src/presets/shadcn-variants/treeselect.tsx +784 -0
  57. package/src/presets/ui/badge.tsx +46 -0
  58. package/src/presets/ui/button.tsx +60 -0
  59. package/src/presets/ui/calendar.tsx +214 -0
  60. package/src/presets/ui/checkbox.tsx +115 -0
  61. package/src/presets/ui/custom.tsx +0 -0
  62. package/src/presets/ui/dialog.tsx +141 -0
  63. package/src/presets/ui/field.tsx +246 -0
  64. package/src/presets/ui/input-mask.tsx +739 -0
  65. package/src/presets/ui/input-otp.tsx +77 -0
  66. package/src/presets/ui/input.tsx +1011 -0
  67. package/src/presets/ui/label.tsx +22 -0
  68. package/src/presets/ui/number.tsx +1370 -0
  69. package/src/presets/ui/popover.tsx +46 -0
  70. package/src/presets/ui/radio-group.tsx +43 -0
  71. package/src/presets/ui/scroll-area.tsx +56 -0
  72. package/src/presets/ui/select.tsx +190 -0
  73. package/src/presets/ui/separator.tsx +28 -0
  74. package/src/presets/ui/slider.tsx +61 -0
  75. package/src/presets/ui/switch.tsx +32 -0
  76. package/src/presets/ui/textarea.tsx +634 -0
  77. package/src/presets/ui/time-dropdowns.tsx +350 -0
  78. package/src/schema/adapter.ts +217 -0
  79. package/src/schema/core.ts +429 -0
  80. package/src/schema/field-map.ts +0 -0
  81. package/src/schema/field.ts +224 -0
  82. package/src/schema/index.ts +0 -0
  83. package/src/schema/input-field.ts +260 -0
  84. package/src/schema/presets.ts +0 -0
  85. package/src/schema/variant.ts +216 -0
  86. package/src/variants/core/checkbox.tsx +54 -0
  87. package/src/variants/core/chips.tsx +22 -0
  88. package/src/variants/core/color.tsx +16 -0
  89. package/src/variants/core/custom.tsx +18 -0
  90. package/src/variants/core/date.tsx +25 -0
  91. package/src/variants/core/file.tsx +9 -0
  92. package/src/variants/core/keyvalue.tsx +12 -0
  93. package/src/variants/core/multiselect.tsx +28 -0
  94. package/src/variants/core/number.tsx +115 -0
  95. package/src/variants/core/password.tsx +35 -0
  96. package/src/variants/core/phone.tsx +16 -0
  97. package/src/variants/core/radio.tsx +38 -0
  98. package/src/variants/core/select.tsx +15 -0
  99. package/src/variants/core/slider.tsx +55 -0
  100. package/src/variants/core/text.tsx +114 -0
  101. package/src/variants/core/textarea.tsx +22 -0
  102. package/src/variants/core/toggle.tsx +50 -0
  103. package/src/variants/core/treeselect.tsx +11 -0
  104. package/src/variants/helpers/selection-summary.tsx +236 -0
  105. package/src/variants/index.ts +75 -0
  106. package/src/variants/registry.ts +38 -0
  107. package/src/variants/select-shared.ts +0 -0
  108. package/src/variants/shared.ts +126 -0
  109. package/tsconfig.json +14 -0
@@ -0,0 +1,260 @@
1
+ // src/schema/input-field.ts
2
+
3
+ import type { FieldSize, FieldDensity } from "@/variants/shared";
4
+
5
+ /**
6
+ * Result type for validation hooks.
7
+ *
8
+ * Used by:
9
+ * - variant modules (`validate`)
10
+ * - per-field `onValidate` (InputField)
11
+ */
12
+ export type ValidateResult =
13
+ | boolean // false = invalid, true = OK
14
+ | string // one error message
15
+ | string[] // multiple messages (first is used for display)
16
+ | null
17
+ | void; // null/void treated as "OK"
18
+
19
+ /**
20
+ * Placement of the main label relative to the field control.
21
+ *
22
+ * This is a macro layout decision: where the label block lives
23
+ * compared to the input/control block.
24
+ */
25
+ export type LabelPlacement = "top" | "left" | "right" | "hidden";
26
+
27
+ /**
28
+ * Shared placement for helper slots relative to their *root*.
29
+ *
30
+ * Example:
31
+ * - "above" → above the label root or input root
32
+ * - "below" → below the label root or input root
33
+ * - "left" → left of the label root or input root
34
+ * - "right" → right of the label root or input root
35
+ * - "hidden" → not rendered
36
+ */
37
+ export type SlotPlacement = "left" | "right" | "above" | "below" | "hidden";
38
+
39
+ /**
40
+ * Placement of the sublabel relative to its root block.
41
+ */
42
+ export type SublabelPlacement = SlotPlacement;
43
+
44
+ /**
45
+ * Placement for the longer description block.
46
+ */
47
+ export type DescriptionPlacement = SlotPlacement;
48
+
49
+ /**
50
+ * Placement for helper text (typically small, subtle text).
51
+ */
52
+ export type HelpTextPlacement = SlotPlacement;
53
+
54
+ /**
55
+ * Placement for explicit error text (visual error copy).
56
+ */
57
+ export type ErrorTextPlacement = SlotPlacement;
58
+
59
+ /**
60
+ * Registry of all logical "slots" a field can render.
61
+ *
62
+ * Hosts can extend this via declaration merging, e.g.:
63
+ *
64
+ * declare module "@/schema/input-field" {
65
+ * interface FieldSlots {
66
+ * charCounter: true;
67
+ * }
68
+ * }
69
+ */
70
+ export interface FieldSlots {
71
+ /** The main label text. */
72
+ label: true;
73
+ /** Optional smaller label text. */
74
+ sublabel: true;
75
+ /** Longer, usually multi-line description. */
76
+ description: true;
77
+ /** Small helper text, usually subtle. */
78
+ helpText: true;
79
+ /** Error text (validation message) when present. */
80
+ errorText: true;
81
+ /** The actual control/input element. */
82
+ input: true;
83
+ /**tags */
84
+ tags: true;
85
+ }
86
+
87
+ /**
88
+ * Registry of logical "roots" / anchor blocks.
89
+ *
90
+ * Other slots are positioned relative to one of these.
91
+ */
92
+ export interface FieldRoots {
93
+ /** Label root block. */
94
+ label: true;
95
+ /** Input/control root block. */
96
+ input: true;
97
+ }
98
+
99
+ export type FieldSlotId = keyof FieldSlots;
100
+ export type FieldRootId = keyof FieldRoots;
101
+
102
+ /**
103
+ * Map of which root each *non-root* slot belongs to.
104
+ *
105
+ * Example:
106
+ * relativeRoots: {
107
+ * sublabel: "label",
108
+ * description: "input",
109
+ * helpText: "input",
110
+ * errorText: "input",
111
+ * }
112
+ */
113
+ export type RelativeRootsMap = Partial<
114
+ Record<
115
+ Exclude<FieldSlotId, FieldRootId>, // non-root slots only
116
+ FieldRootId
117
+ >
118
+ >;
119
+
120
+ /**
121
+ * Relative ordering of *non-root* slots per root.
122
+ *
123
+ * This is *not* about placement; it only decides "who comes first"
124
+ * when multiple slots share the same:
125
+ * - root (label/input), and
126
+ * - placement (above/below/left/right)
127
+ *
128
+ * Example:
129
+ * ordering: {
130
+ * input: ["errorText", "description", "helpText"],
131
+ * }
132
+ *
133
+ * If description and helpText are both "below" the input, then the
134
+ * above config means:
135
+ * - errorText (below input) first,
136
+ * - then description (below input),
137
+ * - then helpText (below input).
138
+ */
139
+ export type FieldOrdering = Partial<
140
+ Record<FieldRootId, Exclude<FieldSlotId, FieldRootId>[]>
141
+ >;
142
+
143
+ /**
144
+ * Layout defaults for a field/variant.
145
+ *
146
+ * Variants can provide these as defaults; InputField merges them
147
+ * with per-field overrides.
148
+ *
149
+ * The high-level placement props remain the main public API.
150
+ * `relativeRoots` and `ordering` provide a lower-level layout graph
151
+ * that InputField can use to render slots relative to "label" or
152
+ * "input" in a predictable order.
153
+ */
154
+ export interface FieldLayoutConfig {
155
+ /**
156
+ * Where to render the main label relative to the control.
157
+ */
158
+ labelPlacement?: LabelPlacement;
159
+
160
+ /**
161
+ * Where to render the sublabel relative to its root.
162
+ */
163
+ sublabelPlacement?: SublabelPlacement;
164
+
165
+ /**
166
+ * Where to render the description block relative to its root.
167
+ */
168
+ descriptionPlacement?: DescriptionPlacement;
169
+
170
+ /**
171
+ * Where to render helper text relative to its root.
172
+ */
173
+ helpTextPlacement?: HelpTextPlacement;
174
+
175
+ /**
176
+ * Where to render error text (if any) relative to its root.
177
+ */
178
+ errorTextPlacement?: ErrorTextPlacement;
179
+
180
+ /**Where to render the tags (if any) relative to ites root */
181
+ tagPlacement?: SlotPlacement;
182
+ /**
183
+ * Hint that the field should render inline with other controls.
184
+ */
185
+ inline?: boolean;
186
+
187
+ /**
188
+ * Hint that the field should stretch to the full available width.
189
+ */
190
+ fullWidth?: boolean;
191
+
192
+ /**
193
+ * Optional default size/density hints.
194
+ *
195
+ * These are advisory; variants/presets may override them.
196
+ */
197
+ defaultSize?: FieldSize;
198
+ defaultDensity?: FieldDensity;
199
+
200
+ /**
201
+ * Which root each non-root slot is attached to.
202
+ *
203
+ * If omitted, InputField can infer reasonable defaults, e.g.:
204
+ * - sublabel → "label"
205
+ * - description → "input"
206
+ * - helpText → "input"
207
+ * - errorText → "input"
208
+ */
209
+ relativeRoots?: RelativeRootsMap;
210
+
211
+ /**
212
+ * Relative ordering of non-root slots per root.
213
+ *
214
+ * Used only when multiple slots share the same
215
+ * root + placement combination.
216
+ */
217
+ ordering?: FieldOrdering;
218
+ }
219
+
220
+ /**
221
+ * Effective layout for a field after merging:
222
+ * - variant defaults, and
223
+ * - per-field overrides.
224
+ */
225
+ export interface EffectiveFieldLayout extends FieldLayoutConfig {
226
+ /**
227
+ * Concrete size/density after merging defaults + overrides.
228
+ */
229
+ size?: FieldSize;
230
+ density?: FieldDensity;
231
+ }
232
+
233
+ /**
234
+ * Context passed to a variant's layout resolver.
235
+ *
236
+ * - `defaults`: layout defaults defined by the variant module.
237
+ * - `overrides`: only the layout keys explicitly set on <InputField />.
238
+ * - `props`: the raw <InputField /> props for this field.
239
+ *
240
+ * The resolver MUST respect host overrides: if a key is present in
241
+ * `overrides`, it should not change it.
242
+ */
243
+ export interface LayoutResolveContext<T = unknown> {
244
+ defaults: FieldLayoutConfig;
245
+ overrides: Partial<FieldLayoutConfig>;
246
+ props: T;
247
+ }
248
+
249
+ /**
250
+ * Variant-level layout resolver.
251
+ *
252
+ * This allows variants to implement mapping rules such as:
253
+ * - "if labelPlacement is left ⇒ inline=true, error below, etc."
254
+ * while still allowing host overrides to win.
255
+ *
256
+ * Variants may also fill in `relativeRoots` and `ordering` to define
257
+ * how slots are attached to "label" vs "input" and in what relative
258
+ * order they should render.
259
+ */
260
+ export type LayoutResolver<T = unknown> = (ctx: LayoutResolveContext<T>) => FieldLayoutConfig;
File without changes
@@ -0,0 +1,216 @@
1
+ // src/schema/variant.ts
2
+
3
+ import type { ComponentType } from "react";
4
+
5
+ import type { Dict, CoreContext } from "@/schema/core";
6
+ import type { Field } from "@/schema/field";
7
+ import type {
8
+ FieldLayoutConfig,
9
+ LayoutResolver,
10
+ ValidateResult,
11
+ } from "@/schema/input-field";
12
+ import type { VariantBaseProps } from "@/variants/shared";
13
+ import { TextVariantProps } from "@/variants/core/text";
14
+ import { ShadcnNumberVariantProps } from "@/presets/shadcn-variants/number";
15
+ import { ShadcnPhoneVariantProps } from "@/presets/shadcn-variants/phone";
16
+ import { ShadcnColorVariantProps } from "@/presets/shadcn-variants/color";
17
+ import { ShadcnPasswordVariantProps } from "@/presets/shadcn-variants/password";
18
+ import {
19
+ DateVariantProps,
20
+ ShadcnDateVariantProps,
21
+ } from "@/presets/shadcn-variants/date";
22
+ import { ShadcnChipsVariantProps } from "@/presets/shadcn-variants/chips";
23
+ import { ShadcnTextareaVariantProps } from "@/presets/shadcn-variants/textarea";
24
+ import { ShadcnToggleVariantProps } from "@/presets/shadcn-variants/toggle";
25
+ import { RadioItem, ShadcnRadioVariantProps } from "@/presets/shadcn-variants/radio";
26
+ import { CheckboxVariantPublicValue, ShadcnCheckboxUiProps, ShadcnCheckboxVariantProps, ShadcnCheckboxVariantPublicProps } from "@/presets/shadcn-variants/checkbox";
27
+ import { ShadcnSelectVariantProps } from "@/presets/shadcn-variants/select";
28
+ import { ShadcnMultiSelectVariantProps } from "@/presets/shadcn-variants/multiselect";
29
+ import { SliderValue } from "@/variants/core/slider";
30
+ import { ShadcnSliderVariantProps } from "@/presets/shadcn-variants/slider";
31
+ import { KeyValueMap, ShadcnKeyValueVariantProps } from "@/presets/shadcn-variants/keyvalue";
32
+ import { ShadcnCustomVariantProps } from "@/presets/shadcn-variants/custom";
33
+ import { ShadcnTreeSelectVariantProps } from "@/presets/shadcn-variants/treeselect";
34
+ import { FileLike, ShadcnFileVariantProps } from "@/presets/shadcn-variants/file";
35
+ import { ShadcnTextVariantProps } from "@/presets/shadcn-variants/text";
36
+ import { SelectVariantProps } from "@/variants/core/select";
37
+
38
+ /**
39
+ * Helper type for a single variant registry entry.
40
+ *
41
+ * Keeps the shape consistent and easy to extend via declaration merging.
42
+ */
43
+ export interface VariantEntry<TValue, TProps> {
44
+ value: TValue;
45
+ props: TProps;
46
+ }
47
+
48
+ /**
49
+ * Base type-level variant registry.
50
+ *
51
+ * This is the **canonical mapping** used by:
52
+ * - InputFieldProps<K>
53
+ * - VariantModule<K>
54
+ *
55
+ * Hosts & presets extend it via declaration merging:
56
+ *
57
+ * declare module "@/schema/variant" {
58
+ * interface Variants {
59
+ * select: VariantEntry<SelectValuePublic, SelectPropsPublic>;
60
+ * }
61
+ * }
62
+ */
63
+ export interface Variants<H = unknown> {
64
+ /**
65
+ * Built-in "text" variant.
66
+ *
67
+ * Shadcn-based implementation lives in presets/shadcn-variants/text.tsx
68
+ */
69
+ text: VariantEntry<string | undefined, ShadcnTextVariantProps>;
70
+
71
+ /**
72
+ * Example scalar variant.
73
+ *
74
+ * You can repurpose this for "custom" or drop it later.
75
+ */
76
+ number: VariantEntry<number | undefined, ShadcnNumberVariantProps>;
77
+
78
+ phone: VariantEntry<string | number | undefined, ShadcnPhoneVariantProps>;
79
+ color: VariantEntry<string | undefined, ShadcnColorVariantProps>;
80
+ password: VariantEntry<string | undefined, ShadcnPasswordVariantProps>;
81
+
82
+ // Date is modeled as string for now (ISO/whatever your preset uses)
83
+ date: VariantEntry<string | undefined, ShadcnDateVariantProps>;
84
+
85
+ chips: VariantEntry<string[] | undefined, ShadcnChipsVariantProps>;
86
+ textarea: VariantEntry<string | undefined, ShadcnTextareaVariantProps>;
87
+ toggle: VariantEntry<boolean | undefined, ShadcnToggleVariantProps>;
88
+
89
+ radio: VariantEntry<unknown | undefined, ShadcnRadioVariantProps<unknown, RadioItem<unknown>>>
90
+ checkbox: VariantEntry<CheckboxVariantPublicValue, ShadcnCheckboxVariantPublicProps>
91
+ select: VariantEntry<string | number | undefined, SelectVariantProps>
92
+ 'multi-select': VariantEntry<Array<string | number> | undefined, ShadcnMultiSelectVariantProps>,
93
+ slider: VariantEntry<SliderValue, ShadcnSliderVariantProps>
94
+ keyvalue: VariantEntry<KeyValueMap | undefined, ShadcnKeyValueVariantProps>
95
+ custom: VariantEntry<unknown | undefined, ShadcnCustomVariantProps>,
96
+ treeselect: VariantEntry<string | number | undefined, ShadcnTreeSelectVariantProps>,
97
+ file: VariantEntry<FileLike, ShadcnFileVariantProps>
98
+ }
99
+
100
+
101
+
102
+ /**
103
+ * Union of all variant keys.
104
+ */
105
+ export type VariantKey = keyof Variants;
106
+
107
+ /**
108
+ * Value type for a given variant key.
109
+ *
110
+ * Strongly drives autocomplete:
111
+ * - InputFieldProps<"text"> → TValue = string | undefined
112
+ */
113
+ export type VariantValueFor<K extends VariantKey, H = unknown> = Variants<H>[K]["value"];
114
+
115
+ /**
116
+ * Props type for a given variant key.
117
+ *
118
+ * Strongly drives autocomplete:
119
+ * - InputFieldProps<"text"> → props = TextVariantProps
120
+ */
121
+ export type VariantPropsFor<K extends VariantKey, H = unknown> = Variants<H>[K]["props"];
122
+
123
+ /**
124
+ * Signature for variant-level validation functions.
125
+ */
126
+ export type VariantValidateFn<TValue, TProps> = (
127
+ value: TValue | undefined,
128
+ ctx: {
129
+ required?: boolean;
130
+ props: TProps;
131
+ field: Field;
132
+ form: CoreContext<Dict>;
133
+ }
134
+ ) => ValidateResult;
135
+
136
+ /**
137
+ * Layout defaults for a variant.
138
+ *
139
+ * This extends FieldLayoutConfig, so it automatically includes:
140
+ * - placement props (labelPlacement, descriptionPlacement, etc.)
141
+ * - layout hints (inline, fullWidth, defaultSize/density)
142
+ * - layout graph (relativeRoots, ordering)
143
+ */
144
+ export interface VariantLayoutDefaults extends FieldLayoutConfig { }
145
+
146
+ /**
147
+ * Runtime module definition for a variant.
148
+ *
149
+ * IMPORTANT:
150
+ * - This is **tied directly** to the registry:
151
+ * TValue = VariantValueFor<K>
152
+ * TProps = VariantPropsFor<K>
153
+ *
154
+ * So if you change the entry in `Variants`, both:
155
+ * - <InputField variant="..." /> props
156
+ * - The Variant component in the module
157
+ * will see the updated types and IntelliSense matches everywhere.
158
+ *
159
+ * - For complex variants (select/multiselect):
160
+ * you model the relationship via unions in `Variants["select"]`.
161
+ */
162
+ export interface VariantModule<K extends VariantKey = VariantKey> {
163
+ /**
164
+ * Unique key for this variant, e.g. "text", "number", "select".
165
+ */
166
+ variant: K;
167
+
168
+ /**
169
+ * React component that renders the control.
170
+ *
171
+ * It receives:
172
+ * - VariantBaseProps<VariantValueFor<K>>
173
+ * - VariantPropsFor<K>
174
+ */
175
+ Variant: ComponentType<
176
+ VariantBaseProps<VariantValueFor<K>> & VariantPropsFor<K>
177
+ >;
178
+
179
+ /**
180
+ * Optional validation logic specific to this variant.
181
+ */
182
+ validate?: VariantValidateFn<
183
+ VariantValueFor<K>,
184
+ VariantPropsFor<K>
185
+ >;
186
+
187
+ /**
188
+ * Optional default layout hints for this variant.
189
+ */
190
+ defaults?: {
191
+ layout?: VariantLayoutDefaults;
192
+ };
193
+
194
+ /**
195
+ * Optional smart layout resolver.
196
+ *
197
+ * Must respect host overrides.
198
+ */
199
+ resolveLayout?: LayoutResolver<VariantPropsFor<K>>;
200
+
201
+ /**
202
+ * Optional metadata, useful for docs/inspectors.
203
+ */
204
+ meta?: {
205
+ label?: string;
206
+ description?: string;
207
+ tags?: string[];
208
+ };
209
+ }
210
+
211
+ /**
212
+ * Convenience alias when you want to be explicit:
213
+ *
214
+ * const textModule: VariantModuleFor<"text"> = { ... }
215
+ */
216
+ export type VariantModuleFor<K extends VariantKey> = VariantModule<K>;
@@ -0,0 +1,54 @@
1
+ // src/variants/core/checkbox.ts
2
+
3
+ import type { VariantModuleFor } from "@/schema/variant";
4
+ import { ShadcnCheckboxVariant } from "@/presets/shadcn-variants/checkbox";
5
+ import type {
6
+ ShadcnCheckboxVariantPublicProps,
7
+ CheckboxVariantPublicValue,
8
+ } from "@/presets/shadcn-variants/checkbox";
9
+ import type { VariantBaseProps } from "@/variants/shared";
10
+ import { toggleLayoutDefaults } from "./toggle";
11
+
12
+ /**
13
+ * Public props type you can import elsewhere:
14
+ *
15
+ * import type { CheckboxVariantProps } from "@/variants/core/checkbox";
16
+ */
17
+ export type CheckboxVariantProps = ShadcnCheckboxVariantPublicProps;
18
+
19
+ /**
20
+ * Concrete Variant component type, if you need it:
21
+ *
22
+ * VariantBaseProps<CheckboxVariantPublicValue> & CheckboxVariantProps
23
+ */
24
+ type CheckboxVariantComponentProps =
25
+ VariantBaseProps<CheckboxVariantPublicValue> & CheckboxVariantProps;
26
+
27
+ /**
28
+ * Runtime module for the "checkbox" variant.
29
+ *
30
+ * This wires the Shadcn preset into the core registry with sensible defaults.
31
+ */
32
+ export const checkboxModule: VariantModuleFor<"checkbox"> = {
33
+ variant: "checkbox",
34
+
35
+ // ShadcnCheckboxVariant is generic; we fix it to the public aliases
36
+ // via this cast. At call sites you'll still get strong typing because
37
+ // the registry types know the concrete value/props.
38
+ Variant: ShadcnCheckboxVariant as unknown as React.ComponentType<CheckboxVariantComponentProps>,
39
+
40
+ resolveLayout({ props }) {
41
+ if (props.single) {
42
+ return toggleLayoutDefaults
43
+ }
44
+
45
+ return {};
46
+ },
47
+
48
+ meta: {
49
+ label: "Checkbox",
50
+ description:
51
+ "Single or group checkboxes with optional per-item tri-state support.",
52
+ tags: ["checkbox", "group", "boolean", "tri-state"],
53
+ },
54
+ };
@@ -0,0 +1,22 @@
1
+ import ShadcnChipsVariant from "@/presets/shadcn-variants/chips";
2
+ import { VariantModuleFor } from "@/schema/variant";
3
+
4
+
5
+ export const chipVariant: VariantModuleFor<"chips"> = {
6
+ variant: "chips",
7
+ Variant: ShadcnChipsVariant as any,
8
+ // Optional layout defaults – tweak as you like
9
+ defaults: {
10
+ layout: {
11
+ fullWidth: true,
12
+ // You can set defaultSize/defaultDensity here if you want:
13
+ // defaultSize: "md",
14
+ // defaultDensity: "normal",
15
+ },
16
+ },
17
+ meta: {
18
+ label: "Chips",
19
+ description: "Chips input allowing multiple selections.",
20
+ tags: ["chips", "multi-select", "tags"],
21
+ },
22
+ }
@@ -0,0 +1,16 @@
1
+ // ———————————————————————————————
2
+ // VariantModule wiring
3
+
4
+ import { ShadcnColorVariant } from "@/presets/shadcn-variants/color";
5
+ import { VariantModule } from "@/schema/variant";
6
+
7
+ // ———————————————————————————————
8
+ export const ColorVariantModule: VariantModule<"color"> = {
9
+ variant: "color",
10
+ Variant: ShadcnColorVariant,
11
+ meta: {
12
+ label: "Phone",
13
+ description: "Phone number input with country code and masking.",
14
+ tags: ["phone", "tel", "contact"],
15
+ },
16
+ };
@@ -0,0 +1,18 @@
1
+ // src/variants/core/custom.tsx
2
+
3
+ import type { VariantModule } from "@/schema/variant";
4
+ import { ShadcnCustomVariant } from "@/presets/shadcn-variants/custom";
5
+
6
+ /**
7
+ * Core "custom" variant module.
8
+ *
9
+ * - Delegates all UI to ShadcnCustomVariant.
10
+ * - No layout defaults, no built-in validation.
11
+ * - Consumers can override layout via InputField props if needed.
12
+ */
13
+ export const customVariant: VariantModule<"custom"> = {
14
+ variant: "custom",
15
+ Variant: ShadcnCustomVariant,
16
+ };
17
+
18
+ export default customVariant;
@@ -0,0 +1,25 @@
1
+ import ShadcnDateVariant from "@/presets/shadcn-variants/date";
2
+ import { VariantModuleFor } from "@/schema/variant";
3
+
4
+
5
+ export const dateVariant: VariantModuleFor<"date"> = {
6
+ variant: "date",
7
+ Variant: ShadcnDateVariant as any,
8
+
9
+ // Optional layout defaults – tweak as you like
10
+ defaults: {
11
+ layout: {
12
+ fullWidth: true,
13
+ // You can set defaultSize/defaultDensity here if you want:
14
+ // defaultSize: "md",
15
+ // defaultDensity: "normal",
16
+ },
17
+ },
18
+
19
+ meta: {
20
+ label: "Date",
21
+ description:
22
+ "Date input with calendar picker.",
23
+ tags: ["date", "calendar", "picker"],
24
+ },
25
+ }
@@ -0,0 +1,9 @@
1
+ import ShadcnFileVariant from "@/presets/shadcn-variants/file";
2
+ import { VariantModule } from "@/schema/variant";
3
+
4
+
5
+
6
+ export const fileManagerModule: VariantModule<'file'> = {
7
+ Variant: ShadcnFileVariant as any,
8
+ variant: 'file'
9
+ }
@@ -0,0 +1,12 @@
1
+ import ShadcnKeyValueVariant from "@/presets/shadcn-variants/keyvalue";
2
+ import { VariantModule } from "@/schema/variant";
3
+
4
+
5
+ export const keyValueModule: VariantModule<'keyvalue'> = {
6
+ variant: 'keyvalue',
7
+ Variant: ShadcnKeyValueVariant,
8
+
9
+ meta: {
10
+ label: ''
11
+ }
12
+ }
@@ -0,0 +1,28 @@
1
+
2
+
3
+ // src/variants/multi-select.ts
4
+
5
+ import type { VariantModule } from "@/schema/variant";
6
+ import {
7
+ ShadcnMultiSelectVariant,
8
+ type ShadcnMultiSelectVariantProps,
9
+ } from "@/presets/shadcn-variants/multiselect";
10
+
11
+ export type MultiSelectValue = (string | number)[] | undefined;
12
+
13
+
14
+ /**
15
+ * Variant module for "multi-select".
16
+ *
17
+ * No defaults / layout overrides here — layout is driven by InputField +
18
+ * host overrides, same as your other variants.
19
+ */
20
+ export const multiSelectVariantModule: VariantModule<"multi-select"> = {
21
+ variant: "multi-select",
22
+ Variant: ShadcnMultiSelectVariant,
23
+ meta: {
24
+
25
+ }
26
+ };
27
+
28
+ export default multiSelectVariantModule;