@invana/forms 0.0.31 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React$1 from 'react';
2
2
  import * as react_hook_form from 'react-hook-form';
3
- import { FieldValues, FieldPath, ControllerProps, Control, UseFormReturn } from 'react-hook-form';
3
+ import { FieldValues, FieldPath, ControllerProps, RegisterOptions, Control, UseFormReturn } from 'react-hook-form';
4
4
  export { Control, DefaultValues, FieldValues, Mode, SubmitHandler, UseFormReturn } from 'react-hook-form';
5
5
  import * as LabelPrimitive from '@radix-ui/react-label';
6
6
  import * as SelectPrimitive from '@radix-ui/react-select';
@@ -74,6 +74,10 @@ type FieldConfig = {
74
74
  label: string;
75
75
  value: string;
76
76
  }[];
77
+ /**
78
+ * Bounds of a `number` field. With both, it is a slider beside its number;
79
+ * without, a typed number input that can carry a `unit` and an `aside`.
80
+ */
77
81
  min?: number;
78
82
  max?: number;
79
83
  step?: number;
@@ -102,6 +106,16 @@ type FieldConfig = {
102
106
  defaultValue?: string | number | boolean | string[];
103
107
  /** Number of visible rows for `textarea` fields. */
104
108
  rows?: number;
109
+ /**
110
+ * Unit drawn at the end of a `text` or `number` input — `%`, `d`, `kg/ha`.
111
+ * Display only; the value stays the bare number or text.
112
+ */
113
+ unit?: string;
114
+ /**
115
+ * A short note drawn at the end of a `text` or `number` input, after the
116
+ * unit — `quoted 14 d` beside an observed lead time. Display only.
117
+ */
118
+ aside?: string;
105
119
  /**
106
120
  * How many grid columns the field spans on `md+` screens. Defaults to `1`.
107
121
  * The grid is two columns by default (see `ObjectField`'s `columns`), so
@@ -127,6 +141,11 @@ type FieldConfig = {
127
141
  * "active" chip in an inspector row). See {@link FieldBadge}.
128
142
  */
129
143
  badge?: FieldBadge;
144
+ /**
145
+ * Validation, as react-hook-form's rules — `validate: (v) => v > 0 || 'Must
146
+ * be above 0'`. The message shows under the field.
147
+ */
148
+ rules?: Omit<RegisterOptions<FieldValues>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
130
149
  };
131
150
  type RowConfig = {
132
151
  id: string;
@@ -150,8 +169,9 @@ type GroupConfig = {
150
169
  /** Show the automatic field-count badge. Defaults to `true`. */
151
170
  showCount?: boolean;
152
171
  };
153
- interface ObjectFieldProps {
154
- control: Control<any>;
172
+ interface ObjectFieldProps<T extends FieldValues = FieldValues> {
173
+ /** `form.control` of the consumer's `useForm`, typed or not. */
174
+ control: Control<T>;
155
175
  name: string;
156
176
  fields: FieldConfig[];
157
177
  rowConfig?: RowConfig[];
@@ -166,6 +186,19 @@ interface ObjectFieldProps {
166
186
  * Below `md` the grid always collapses to a single column.
167
187
  */
168
188
  columns?: number;
189
+ /**
190
+ * What the columns answer to. `viewport` (the default) is the grid of a
191
+ * page: `columns` wide from `md` up. `container` is a form inside a card or
192
+ * a chat turn, which is narrow on any screen: two columns once the form
193
+ * itself is 280px wide, one below, and a lone last field takes the row.
194
+ */
195
+ fit?: 'viewport' | 'container';
196
+ /**
197
+ * How a field's `group` is drawn. `accordion` (the default) folds each
198
+ * group under a header with its count — a settings panel. `section` sets
199
+ * each under a small caps label and keeps it open — a short form in a card.
200
+ */
201
+ groupAs?: 'accordion' | 'section';
169
202
  }
170
203
 
171
204
  type AnyValue = any;
@@ -194,6 +227,10 @@ interface BaseFieldProps {
194
227
  orientation?: FieldOrientation;
195
228
  /** Wrap a `switch` boolean in a bordered, padded box. Defaults to `false`. */
196
229
  boxed?: boolean;
230
+ /** Unit at the end of a text or number input. */
231
+ unit?: string;
232
+ /** Note at the end of a text or number input, after the unit. */
233
+ aside?: string;
197
234
  }
198
235
  declare const InputField: React$1.FC<BaseFieldProps>;
199
236
  declare const PasswordField: React$1.FC<BaseFieldProps>;
@@ -205,19 +242,7 @@ declare const CheckboxGroupField: React$1.FC<BaseFieldProps>;
205
242
  declare const ColorField: React$1.FC<BaseFieldProps>;
206
243
  declare const NumberField: React$1.FC<BaseFieldProps>;
207
244
  declare const IconField: React$1.FC<BaseFieldProps>;
208
- declare const Field: {
209
- Input: React$1.FC<BaseFieldProps>;
210
- Password: React$1.FC<BaseFieldProps>;
211
- Textarea: React$1.FC<BaseFieldProps>;
212
- Boolean: React$1.FC<BaseFieldProps>;
213
- Radio: React$1.FC<BaseFieldProps>;
214
- CheckboxGroup: React$1.FC<BaseFieldProps>;
215
- Color: React$1.FC<BaseFieldProps>;
216
- Number: React$1.FC<BaseFieldProps>;
217
- Select: React$1.FC<BaseFieldProps>;
218
- Icon: React$1.FC<BaseFieldProps>;
219
- };
220
- declare const ObjectField: React$1.FC<ObjectFieldProps>;
245
+ declare const ObjectField: <T extends FieldValues = FieldValues>({ control, name, fields, rowConfig, groupConfig, labelPosition, size, columns, fit, groupAs, }: ObjectFieldProps<T>) => React$1.JSX.Element;
221
246
  interface FormFieldExtensions {
222
247
  ObjectField: typeof ObjectField;
223
248
  Input: typeof InputField;
@@ -300,13 +325,14 @@ interface IconInputProps {
300
325
  declare const IconInput: React$1.FC<IconInputProps>;
301
326
 
302
327
  /**
303
- * `sm` (26px) is the application field — a property editor, a settings row, a
304
- * form inside a 420px panel. `default` (40px) stays the form-page size.
328
+ * The control scale: `sm` (26px) is the application field — a property
329
+ * editor, a settings row, a form inside a 420px panel; `default` (32px) a
330
+ * standalone form or dialog; `lg` (40px) a form page.
305
331
  *
306
332
  * Named `inputSize` because `size` is already an `<input>` attribute meaning
307
333
  * "how many characters wide", and shadowing it would silently drop that.
308
334
  */
309
- type InputSize = "default" | "sm";
335
+ type InputSize = "sm" | "default" | "lg";
310
336
  declare const Input: React$1.ForwardRefExoticComponent<Omit<React$1.ClassAttributes<HTMLInputElement> & React$1.InputHTMLAttributes<HTMLInputElement> & {
311
337
  inputSize?: InputSize;
312
338
  }, "ref"> & React$1.RefAttributes<HTMLInputElement>>;
@@ -332,8 +358,8 @@ declare const Select: React$1.FC<SelectPrimitive.SelectProps>;
332
358
  declare const SelectGroup: React$1.ForwardRefExoticComponent<SelectPrimitive.SelectGroupProps & React$1.RefAttributes<HTMLDivElement>>;
333
359
  declare const SelectValue: React$1.ForwardRefExoticComponent<SelectPrimitive.SelectValueProps & React$1.RefAttributes<HTMLSpanElement>>;
334
360
  declare const SelectTrigger: React$1.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectTriggerProps & React$1.RefAttributes<HTMLButtonElement>, "ref"> & {
335
- /** Matches `Input`'s `inputSize` — `sm` is the 26px application field. */
336
- triggerSize?: "default" | "sm";
361
+ /** Matches `Input`'s `inputSize` — the control scale, `sm` 26 / `default` 32 / `lg` 40. */
362
+ triggerSize?: "sm" | "default" | "lg";
337
363
  } & React$1.RefAttributes<HTMLButtonElement>>;
338
364
  declare const SelectScrollUpButton: React$1.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectScrollUpButtonProps & React$1.RefAttributes<HTMLDivElement>, "ref"> & React$1.RefAttributes<HTMLDivElement>>;
339
365
  declare const SelectScrollDownButton: React$1.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectScrollDownButtonProps & React$1.RefAttributes<HTMLDivElement>, "ref"> & React$1.RefAttributes<HTMLDivElement>>;
@@ -358,6 +384,10 @@ declare function FieldLegend({ className, variant, ...props }: React.ComponentPr
358
384
  variant?: "legend" | "label";
359
385
  }): React$1.JSX.Element;
360
386
  declare function FieldGroup({ className, ...props }: React.ComponentProps<"div">): React$1.JSX.Element;
387
+ declare const fieldVariants: (props?: ({
388
+ orientation?: "horizontal" | "vertical" | "responsive" | null | undefined;
389
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
390
+ declare function Field({ className, orientation, ...props }: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>): React$1.JSX.Element;
361
391
  declare function FieldContent({ className, ...props }: React.ComponentProps<"div">): React$1.JSX.Element;
362
392
  declare function FieldLabel({ className, ...props }: React.ComponentProps<typeof Label>): React$1.JSX.Element;
363
393
  declare function FieldTitle({ className, ...props }: React.ComponentProps<"div">): React$1.JSX.Element;
@@ -428,7 +458,7 @@ interface ParamRowProps extends Omit<React$1.HTMLAttributes<HTMLDivElement>, "on
428
458
  */
429
459
  declare const ParamRow: React$1.ForwardRefExoticComponent<ParamRowProps & React$1.RefAttributes<HTMLDivElement>>;
430
460
 
431
- declare function InputGroup({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
461
+ declare function InputGroup({ className, id, "aria-describedby": describedBy, "aria-invalid": invalid, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
432
462
  declare const inputGroupAddonVariants: (props?: ({
433
463
  align?: "inline-end" | "inline-start" | "block-end" | "block-start" | null | undefined;
434
464
  } & class_variance_authority_types.ClassProp) | undefined) => string;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React$1 from 'react';
2
2
  import * as react_hook_form from 'react-hook-form';
3
- import { FieldValues, FieldPath, ControllerProps, Control, UseFormReturn } from 'react-hook-form';
3
+ import { FieldValues, FieldPath, ControllerProps, RegisterOptions, Control, UseFormReturn } from 'react-hook-form';
4
4
  export { Control, DefaultValues, FieldValues, Mode, SubmitHandler, UseFormReturn } from 'react-hook-form';
5
5
  import * as LabelPrimitive from '@radix-ui/react-label';
6
6
  import * as SelectPrimitive from '@radix-ui/react-select';
@@ -74,6 +74,10 @@ type FieldConfig = {
74
74
  label: string;
75
75
  value: string;
76
76
  }[];
77
+ /**
78
+ * Bounds of a `number` field. With both, it is a slider beside its number;
79
+ * without, a typed number input that can carry a `unit` and an `aside`.
80
+ */
77
81
  min?: number;
78
82
  max?: number;
79
83
  step?: number;
@@ -102,6 +106,16 @@ type FieldConfig = {
102
106
  defaultValue?: string | number | boolean | string[];
103
107
  /** Number of visible rows for `textarea` fields. */
104
108
  rows?: number;
109
+ /**
110
+ * Unit drawn at the end of a `text` or `number` input — `%`, `d`, `kg/ha`.
111
+ * Display only; the value stays the bare number or text.
112
+ */
113
+ unit?: string;
114
+ /**
115
+ * A short note drawn at the end of a `text` or `number` input, after the
116
+ * unit — `quoted 14 d` beside an observed lead time. Display only.
117
+ */
118
+ aside?: string;
105
119
  /**
106
120
  * How many grid columns the field spans on `md+` screens. Defaults to `1`.
107
121
  * The grid is two columns by default (see `ObjectField`'s `columns`), so
@@ -127,6 +141,11 @@ type FieldConfig = {
127
141
  * "active" chip in an inspector row). See {@link FieldBadge}.
128
142
  */
129
143
  badge?: FieldBadge;
144
+ /**
145
+ * Validation, as react-hook-form's rules — `validate: (v) => v > 0 || 'Must
146
+ * be above 0'`. The message shows under the field.
147
+ */
148
+ rules?: Omit<RegisterOptions<FieldValues>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
130
149
  };
131
150
  type RowConfig = {
132
151
  id: string;
@@ -150,8 +169,9 @@ type GroupConfig = {
150
169
  /** Show the automatic field-count badge. Defaults to `true`. */
151
170
  showCount?: boolean;
152
171
  };
153
- interface ObjectFieldProps {
154
- control: Control<any>;
172
+ interface ObjectFieldProps<T extends FieldValues = FieldValues> {
173
+ /** `form.control` of the consumer's `useForm`, typed or not. */
174
+ control: Control<T>;
155
175
  name: string;
156
176
  fields: FieldConfig[];
157
177
  rowConfig?: RowConfig[];
@@ -166,6 +186,19 @@ interface ObjectFieldProps {
166
186
  * Below `md` the grid always collapses to a single column.
167
187
  */
168
188
  columns?: number;
189
+ /**
190
+ * What the columns answer to. `viewport` (the default) is the grid of a
191
+ * page: `columns` wide from `md` up. `container` is a form inside a card or
192
+ * a chat turn, which is narrow on any screen: two columns once the form
193
+ * itself is 280px wide, one below, and a lone last field takes the row.
194
+ */
195
+ fit?: 'viewport' | 'container';
196
+ /**
197
+ * How a field's `group` is drawn. `accordion` (the default) folds each
198
+ * group under a header with its count — a settings panel. `section` sets
199
+ * each under a small caps label and keeps it open — a short form in a card.
200
+ */
201
+ groupAs?: 'accordion' | 'section';
169
202
  }
170
203
 
171
204
  type AnyValue = any;
@@ -194,6 +227,10 @@ interface BaseFieldProps {
194
227
  orientation?: FieldOrientation;
195
228
  /** Wrap a `switch` boolean in a bordered, padded box. Defaults to `false`. */
196
229
  boxed?: boolean;
230
+ /** Unit at the end of a text or number input. */
231
+ unit?: string;
232
+ /** Note at the end of a text or number input, after the unit. */
233
+ aside?: string;
197
234
  }
198
235
  declare const InputField: React$1.FC<BaseFieldProps>;
199
236
  declare const PasswordField: React$1.FC<BaseFieldProps>;
@@ -205,19 +242,7 @@ declare const CheckboxGroupField: React$1.FC<BaseFieldProps>;
205
242
  declare const ColorField: React$1.FC<BaseFieldProps>;
206
243
  declare const NumberField: React$1.FC<BaseFieldProps>;
207
244
  declare const IconField: React$1.FC<BaseFieldProps>;
208
- declare const Field: {
209
- Input: React$1.FC<BaseFieldProps>;
210
- Password: React$1.FC<BaseFieldProps>;
211
- Textarea: React$1.FC<BaseFieldProps>;
212
- Boolean: React$1.FC<BaseFieldProps>;
213
- Radio: React$1.FC<BaseFieldProps>;
214
- CheckboxGroup: React$1.FC<BaseFieldProps>;
215
- Color: React$1.FC<BaseFieldProps>;
216
- Number: React$1.FC<BaseFieldProps>;
217
- Select: React$1.FC<BaseFieldProps>;
218
- Icon: React$1.FC<BaseFieldProps>;
219
- };
220
- declare const ObjectField: React$1.FC<ObjectFieldProps>;
245
+ declare const ObjectField: <T extends FieldValues = FieldValues>({ control, name, fields, rowConfig, groupConfig, labelPosition, size, columns, fit, groupAs, }: ObjectFieldProps<T>) => React$1.JSX.Element;
221
246
  interface FormFieldExtensions {
222
247
  ObjectField: typeof ObjectField;
223
248
  Input: typeof InputField;
@@ -300,13 +325,14 @@ interface IconInputProps {
300
325
  declare const IconInput: React$1.FC<IconInputProps>;
301
326
 
302
327
  /**
303
- * `sm` (26px) is the application field — a property editor, a settings row, a
304
- * form inside a 420px panel. `default` (40px) stays the form-page size.
328
+ * The control scale: `sm` (26px) is the application field — a property
329
+ * editor, a settings row, a form inside a 420px panel; `default` (32px) a
330
+ * standalone form or dialog; `lg` (40px) a form page.
305
331
  *
306
332
  * Named `inputSize` because `size` is already an `<input>` attribute meaning
307
333
  * "how many characters wide", and shadowing it would silently drop that.
308
334
  */
309
- type InputSize = "default" | "sm";
335
+ type InputSize = "sm" | "default" | "lg";
310
336
  declare const Input: React$1.ForwardRefExoticComponent<Omit<React$1.ClassAttributes<HTMLInputElement> & React$1.InputHTMLAttributes<HTMLInputElement> & {
311
337
  inputSize?: InputSize;
312
338
  }, "ref"> & React$1.RefAttributes<HTMLInputElement>>;
@@ -332,8 +358,8 @@ declare const Select: React$1.FC<SelectPrimitive.SelectProps>;
332
358
  declare const SelectGroup: React$1.ForwardRefExoticComponent<SelectPrimitive.SelectGroupProps & React$1.RefAttributes<HTMLDivElement>>;
333
359
  declare const SelectValue: React$1.ForwardRefExoticComponent<SelectPrimitive.SelectValueProps & React$1.RefAttributes<HTMLSpanElement>>;
334
360
  declare const SelectTrigger: React$1.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectTriggerProps & React$1.RefAttributes<HTMLButtonElement>, "ref"> & {
335
- /** Matches `Input`'s `inputSize` — `sm` is the 26px application field. */
336
- triggerSize?: "default" | "sm";
361
+ /** Matches `Input`'s `inputSize` — the control scale, `sm` 26 / `default` 32 / `lg` 40. */
362
+ triggerSize?: "sm" | "default" | "lg";
337
363
  } & React$1.RefAttributes<HTMLButtonElement>>;
338
364
  declare const SelectScrollUpButton: React$1.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectScrollUpButtonProps & React$1.RefAttributes<HTMLDivElement>, "ref"> & React$1.RefAttributes<HTMLDivElement>>;
339
365
  declare const SelectScrollDownButton: React$1.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectScrollDownButtonProps & React$1.RefAttributes<HTMLDivElement>, "ref"> & React$1.RefAttributes<HTMLDivElement>>;
@@ -358,6 +384,10 @@ declare function FieldLegend({ className, variant, ...props }: React.ComponentPr
358
384
  variant?: "legend" | "label";
359
385
  }): React$1.JSX.Element;
360
386
  declare function FieldGroup({ className, ...props }: React.ComponentProps<"div">): React$1.JSX.Element;
387
+ declare const fieldVariants: (props?: ({
388
+ orientation?: "horizontal" | "vertical" | "responsive" | null | undefined;
389
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
390
+ declare function Field({ className, orientation, ...props }: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>): React$1.JSX.Element;
361
391
  declare function FieldContent({ className, ...props }: React.ComponentProps<"div">): React$1.JSX.Element;
362
392
  declare function FieldLabel({ className, ...props }: React.ComponentProps<typeof Label>): React$1.JSX.Element;
363
393
  declare function FieldTitle({ className, ...props }: React.ComponentProps<"div">): React$1.JSX.Element;
@@ -428,7 +458,7 @@ interface ParamRowProps extends Omit<React$1.HTMLAttributes<HTMLDivElement>, "on
428
458
  */
429
459
  declare const ParamRow: React$1.ForwardRefExoticComponent<ParamRowProps & React$1.RefAttributes<HTMLDivElement>>;
430
460
 
431
- declare function InputGroup({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
461
+ declare function InputGroup({ className, id, "aria-describedby": describedBy, "aria-invalid": invalid, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
432
462
  declare const inputGroupAddonVariants: (props?: ({
433
463
  align?: "inline-end" | "inline-start" | "block-end" | "block-start" | null | undefined;
434
464
  } & class_variance_authority_types.ClassProp) | undefined) => string;