@ostack.tech/ui 0.13.1 → 0.14.0

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 (70) hide show
  1. package/dist/chunks/{en-DtnihkTA.js → en-BiTLo8i1.js} +30 -1
  2. package/dist/chunks/en-BiTLo8i1.js.map +1 -0
  3. package/dist/locales/en-GB.js +1 -1
  4. package/dist/locales/en-US.js +1 -1
  5. package/dist/locales/fr-FR.js +29 -0
  6. package/dist/locales/fr-FR.js.map +1 -1
  7. package/dist/locales/pt-PT.js +29 -0
  8. package/dist/locales/pt-PT.js.map +1 -1
  9. package/dist/ostack-ui.css +6 -1
  10. package/dist/ostack-ui.js +1875 -622
  11. package/dist/ostack-ui.js.map +1 -1
  12. package/dist/types/components/Calendar/Calendar.d.ts +3 -3
  13. package/dist/types/components/Calendar/calendarUtils.d.ts +4 -0
  14. package/dist/types/components/Checkbox/Checkbox.d.ts +13 -1
  15. package/dist/types/components/CheckboxGroup/CheckboxGroup.d.ts +13 -1
  16. package/dist/types/components/CheckboxGroup/CheckboxGroupContext.d.ts +2 -1
  17. package/dist/types/components/CommandMenu/CommandMenu.d.ts +5 -3
  18. package/dist/types/components/Control/Control.d.ts +162 -0
  19. package/dist/types/components/Control/ControlContext.d.ts +13 -0
  20. package/dist/types/components/Control/ControlWithContainerRef.d.ts +14 -0
  21. package/dist/types/components/Control/controlUtils.d.ts +4 -0
  22. package/dist/types/components/Control/index.d.ts +4 -0
  23. package/dist/types/components/ControlAddon/ControlAddon.d.ts +1 -1
  24. package/dist/types/components/ControlCode/ControlCode.d.ts +1 -1
  25. package/dist/types/components/DataTable/DataTableFilter.d.ts +2 -3
  26. package/dist/types/components/DateInput/DateInput.d.ts +37 -7
  27. package/dist/types/components/DateRangeInput/DateRangeInput.d.ts +35 -9
  28. package/dist/types/components/Field/Field.d.ts +3 -13
  29. package/dist/types/components/Field/FieldContext.d.ts +7 -2
  30. package/dist/types/components/Field/index.d.ts +1 -1
  31. package/dist/types/components/Form/Form.d.ts +155 -0
  32. package/dist/types/components/Form/FormContext.d.ts +85 -0
  33. package/dist/types/components/Form/FormError.d.ts +28 -0
  34. package/dist/types/components/Form/FormReset.d.ts +7 -0
  35. package/dist/types/components/Form/FormState.d.ts +30 -0
  36. package/dist/types/components/Form/FormSubmit.d.ts +7 -0
  37. package/dist/types/components/Form/HiddenFormControl.d.ts +8 -0
  38. package/dist/types/components/Form/formUtils.d.ts +10 -0
  39. package/dist/types/components/Form/index.d.ts +6 -0
  40. package/dist/types/components/Form/useRegisterFormControl.d.ts +15 -0
  41. package/dist/types/components/Form/useResetControlOnFormReset.d.ts +2 -0
  42. package/dist/types/components/Input/Input.d.ts +22 -106
  43. package/dist/types/components/Input/index.d.ts +0 -1
  44. package/dist/types/components/NumericInput/NumericInput.d.ts +16 -15
  45. package/dist/types/components/NumericInput/numericInputUtils.d.ts +24 -0
  46. package/dist/types/components/Output/Output.d.ts +3 -3
  47. package/dist/types/components/RadioGroup/Radio.d.ts +1 -1
  48. package/dist/types/components/RadioGroup/RadioGroup.d.ts +17 -4
  49. package/dist/types/components/Select/Select.d.ts +17 -27
  50. package/dist/types/components/Select/SelectContext.d.ts +1 -1
  51. package/dist/types/components/Select/SelectNative.d.ts +2 -1
  52. package/dist/types/components/Stepper/Step.d.ts +1 -1
  53. package/dist/types/components/Table/Table.d.ts +1 -1
  54. package/dist/types/components/Table/TableCell.d.ts +1 -1
  55. package/dist/types/components/Table/TableContext.d.ts +1 -1
  56. package/dist/types/components/Tabs/Tab.d.ts +1 -1
  57. package/dist/types/components/Tabs/TabsContext.d.ts +1 -1
  58. package/dist/types/components/TextArea/TextArea.d.ts +14 -3
  59. package/dist/types/index.d.ts +2 -1
  60. package/dist/types/providers/LocalizationProvider/LocalizationObject.d.ts +2 -0
  61. package/dist/types/utils/setNativeProperty.d.ts +1 -1
  62. package/dist/types/utils/useConstant.d.ts +1 -1
  63. package/dist/types/utils/validationUtils.d.ts +4 -0
  64. package/package.json +5 -5
  65. package/scss/components/Dialog/_Dialog.scss +1 -1
  66. package/scss/components/Form/_Form.scss +6 -0
  67. package/scss/index.scss +1 -0
  68. package/dist/chunks/en-DtnihkTA.js.map +0 -1
  69. package/dist/types/components/Input/InputWithContainerRef.d.ts +0 -14
  70. package/dist/types/utils/control.d.ts +0 -23
@@ -1,7 +1,7 @@
1
1
  import { ComponentPropsWithRef, RefObject } from 'react';
2
2
  import { DayPickerProps } from 'react-day-picker';
3
3
  import { IconButton } from '../IconButton';
4
- import { Select } from '../Select';
4
+ import { SelectSingleProps } from '../Select';
5
5
  /** Mode for selecting calendar dates. */
6
6
  export type CalendarSelectionMode = "none" | "single" | "multiple" | "range" | "range-start" | "range-end";
7
7
  /** Accepted range of dates from a start date to an end date. */
@@ -81,9 +81,9 @@ export interface CalendarPropsBase<TValue extends Date | Date[] | DateRange | nu
81
81
  /** Properties to pass to the next button component. */
82
82
  nextButtonProps?: ComponentPropsWithRef<typeof IconButton<"button">>;
83
83
  /** Properties to pass to the month select component. */
84
- monthSelectProps?: Omit<ComponentPropsWithRef<typeof Select>, "multiple" | "defaultValue" | "value">;
84
+ monthSelectProps?: Omit<SelectSingleProps, "defaultValue" | "value">;
85
85
  /** Properties to pass to the year select component. */
86
- yearSelectProps?: Omit<ComponentPropsWithRef<typeof Select>, "multiple" | "defaultValue" | "value">;
86
+ yearSelectProps?: Omit<SelectSingleProps, "defaultValue" | "value">;
87
87
  }
88
88
  /** Properties of the calendar component in none selection mode. */
89
89
  export interface CalendarNoneSelectionProps extends CalendarPropsBase<never> {
@@ -0,0 +1,4 @@
1
+ /** Converts a value to a valid date or `null`. */
2
+ export declare function toValidDate(value: string | Date | null | undefined): Date | null;
3
+ export declare function calcMinAllowedDate(minDate: string | Date | null | undefined, minMonth: string | Date | null | undefined, minYear: number | undefined): Date | undefined;
4
+ export declare function calcMaxAllowedDate(maxDate: string | Date | null | undefined, maxMonth: string | Date | null | undefined, maxYear: number | undefined): Date | undefined;
@@ -1,7 +1,9 @@
1
1
  import { Checkbox as CheckboxPrimitive } from 'radix-ui';
2
2
  import { ComponentPropsWithoutRef, ComponentPropsWithRef, FocusEvent, ReactNode } from 'react';
3
- import { ControlStatus, ControlVariant } from '../../utils/control.ts';
3
+ import { ControlStatus, ControlVariant } from '../Control';
4
4
  import { ControlCode } from '../ControlCode';
5
+ import { FormValidationMode } from '../Form';
6
+ import { FormControlValidateFn } from '../Form/useRegisterFormControl.ts';
5
7
  import { Icon } from '../Icon';
6
8
  import { Label } from '../Label';
7
9
  import { Spinner } from '../Spinner';
@@ -58,6 +60,16 @@ export interface CheckboxProps extends Omit<ComponentPropsWithoutRef<typeof Chec
58
60
  * with the control.
59
61
  */
60
62
  onBlurToOutside?: (event: FocusEvent) => void;
63
+ /**
64
+ * Custom validation function meant to validate the control when it is part of
65
+ * a `Form`.
66
+ */
67
+ validate?: FormControlValidateFn<CheckboxChecked>;
68
+ /**
69
+ * Specifies when the control should be validated. Defaults to the value
70
+ * specified in the `Form`.
71
+ */
72
+ validationMode?: FormValidationMode;
61
73
  /** Properties to pass to the root component. */
62
74
  rootProps?: ComponentPropsWithRef<"div">;
63
75
  /** Properties to pass to the container component. */
@@ -1,6 +1,8 @@
1
1
  import { ComponentPropsWithoutRef, ComponentPropsWithRef, FocusEvent, ReactNode } from 'react';
2
- import { ControlStatus, ControlVariant } from '../../utils/control.ts';
2
+ import { ControlStatus, ControlVariant } from '../Control';
3
3
  import { ControlCode } from '../ControlCode';
4
+ import { FormValidationMode } from '../Form';
5
+ import { FormControlValidateFn } from '../Form/useRegisterFormControl.ts';
4
6
  import { Spinner } from '../Spinner';
5
7
  /** Properties of the checkbox group component. */
6
8
  export interface CheckboxGroupProps extends ComponentPropsWithoutRef<"div"> {
@@ -73,6 +75,16 @@ export interface CheckboxGroupProps extends ComponentPropsWithoutRef<"div"> {
73
75
  * with the control.
74
76
  */
75
77
  onBlurToOutside?: (event: FocusEvent) => void;
78
+ /**
79
+ * Custom validation function meant to validate the control when it is part of
80
+ * a `Form`.
81
+ */
82
+ validate?: FormControlValidateFn<string[]>;
83
+ /**
84
+ * Specifies when the control should be validated. Defaults to the value
85
+ * specified in the `Form`.
86
+ */
87
+ validationMode?: FormValidationMode;
76
88
  /** Properties to pass to the code component. */
77
89
  codeProps?: ComponentPropsWithRef<typeof ControlCode>;
78
90
  /** Properties to pass to the container component. */
@@ -26,9 +26,10 @@ export declare const CheckboxGroupContext: import('react').Context<CheckboxGroup
26
26
  /** Options for the `useCreateCheckboxGroupContext` hook. */
27
27
  export interface UseCreateCheckboxGroupContextOptions extends Omit<CheckboxGroupContextValue, "store">, Pick<CheckboxGroupProps, "defaultValue" | "value" | "onValueChange"> {
28
28
  checkboxGroupRef: RefObject<HTMLDivElement | null>;
29
+ formOnChange: (value: string[]) => void;
29
30
  }
30
31
  /** Hook which creates the checkbox group's store. */
31
- export declare function useCreateCheckboxGroupContext({ defaultValue, value, onValueChange, name, required, loadingDescriptionId, errorMessageIds, descriptionIds, checkboxGroupRef, }: UseCreateCheckboxGroupContextOptions): {
32
+ export declare function useCreateCheckboxGroupContext({ defaultValue, value, onValueChange, formOnChange, name, required, loadingDescriptionId, errorMessageIds, descriptionIds, checkboxGroupRef, }: UseCreateCheckboxGroupContextOptions): {
32
33
  name: string | undefined;
33
34
  required: boolean | undefined;
34
35
  loadingDescriptionId: string | undefined;
@@ -1,7 +1,7 @@
1
- import { ComponentPropsWithoutRef, ComponentPropsWithRef, ReactNode } from 'react';
1
+ import { ComponentPropsWithoutRef, ComponentPropsWithRef, ReactNode, Ref } from 'react';
2
2
  import { ControlAddon } from '../ControlAddon';
3
3
  import { Icon } from '../Icon';
4
- import { Input } from '../Input';
4
+ import { InputNonFileProps } from '../Input';
5
5
  import { MenuList, MenuListIconPlacement, MenuListVariant } from '../MenuList';
6
6
  import { Spinner } from '../Spinner';
7
7
  import { Command as CommandPrimitive } from './cmdk';
@@ -45,7 +45,9 @@ export interface CommandMenuProps extends ComponentPropsWithoutRef<typeof Comman
45
45
  /** Message to display when no items were found. */
46
46
  emptyMessage?: ReactNode;
47
47
  /** Properties to pass to the search `Input` component. */
48
- searchProps?: Omit<ComponentPropsWithRef<typeof Input>, "asChild" | "variant" | "status" | "code" | "defaultValue" | "value" | "onValueChange" | "startAdornment" | "endAdornment" | "showClearButton">;
48
+ searchProps?: Omit<InputNonFileProps, "asChild" | "variant" | "status" | "code" | "defaultValue" | "value" | "onValueChange" | "startAdornment" | "endAdornment" | "showClearButton"> & {
49
+ ref?: Ref<HTMLInputElement>;
50
+ };
49
51
  /** Properties to pass to the search adornment `ControlAddon` component. */
50
52
  searchAdornmentProps?: ComponentPropsWithRef<typeof ControlAddon>;
51
53
  /** Properties to pass to the search `Icon` component. */
@@ -0,0 +1,162 @@
1
+ import { ComponentPropsWithoutRef, ComponentPropsWithRef, CSSProperties, ElementType, FocusEvent, ReactNode } from 'react';
2
+ import { Responsive } from '../../utils/useResponsiveValues.ts';
3
+ import { CloseButton } from '../CloseButton';
4
+ import { ControlAddon } from '../ControlAddon';
5
+ import { Spinner } from '../Spinner';
6
+ /** Accepted control types. */
7
+ export type ControlType = "color" | "date" | "datetime-local" | "email" | "file" | "hidden" | "month" | "number" | "password" | "search" | "tel" | "text" | "time" | "url" | "week";
8
+ /** Possible status of a control. */
9
+ export type ControlStatus = "valid" | "invalid" | "warned";
10
+ /**
11
+ * Style variants of a control.
12
+ *
13
+ * The `cell` variant should be used to display controls within table cells.
14
+ */
15
+ export type ControlVariant = "default" | "cell";
16
+ /** Accepted values for "show clear button". */
17
+ export type ControlShowClearButton = boolean | "auto";
18
+ /** Base properties of the control component. */
19
+ type ControlPropsBase<TElem extends ElementType, TValue, TAcceptedValue = TValue> = Omit<ComponentPropsWithoutRef<TElem>, "children" | "type" | "multiple" | "defaultValue" | "value"> & {
20
+ /**
21
+ * Change the component to the HTML tag or custom component of the only child.
22
+ * This will merge the original component props with the props of the supplied
23
+ * element/component and change the underlying DOM node.
24
+ */
25
+ asChild?: boolean;
26
+ children?: ReactNode;
27
+ /** Default value of the control. */
28
+ defaultValue?: TAcceptedValue;
29
+ /** Value of the control. */
30
+ value?: TAcceptedValue;
31
+ /**
32
+ * Function called whenever the value changes.
33
+ *
34
+ * @param value New value.
35
+ */
36
+ onValueChange?: (value: TValue) => void;
37
+ /** Whether the control is required. */
38
+ required?: boolean;
39
+ /** Whether the control is disabled. */
40
+ disabled?: boolean;
41
+ /** Whether the control should be rendered as read-only. */
42
+ readOnly?: boolean;
43
+ /**
44
+ * Control's style variant. Defaults to the default variant unless when
45
+ * rendering inside a table cell (in which it defaults to `"cell"`).
46
+ */
47
+ variant?: ControlVariant;
48
+ /** Sets the status of the control. */
49
+ status?: ControlStatus;
50
+ /** Control code. */
51
+ code?: ReactNode;
52
+ /**
53
+ * Renders the control in a **loading** state.
54
+ *
55
+ * When `true`, the control is “soft-disabled”: it looks disabled and ignores
56
+ * user interaction but remains focusable. By default, a spinner is shown
57
+ * (_i.e._, `showSpinner` is set to `true` unless overridden).
58
+ *
59
+ * The control's accessible description while loading can be controlled via
60
+ * `loadingDescription`.
61
+ *
62
+ * To only show a spinner without “soft-disabling” the control, set
63
+ * `showSpinner` instead.
64
+ *
65
+ * @default false
66
+ */
67
+ loading?: boolean;
68
+ /** Accessible description of the control when it is in a “loading” state. */
69
+ loadingDescription?: ReactNode;
70
+ /**
71
+ * Whether to show a spinner in the control.
72
+ *
73
+ * Defaults to the value of the `loading` property. In most cases, prefer
74
+ * `loading`, which also “soft-disables” the control.
75
+ *
76
+ * Use `showSpinner` when you want a spinner **without** “soft-disabling” the
77
+ * control. To “soft-disable” **without** a spinner, set `loading` to `true`
78
+ * and `showSpinner` to `false`.
79
+ *
80
+ * @default loading
81
+ */
82
+ showSpinner?: boolean;
83
+ /** Sets the control's text align. */
84
+ align?: Responsive<CSSProperties["textAlign"]>;
85
+ /** Control's start adornment. */
86
+ startAdornment?: ReactNode;
87
+ /** Control's end adornment. */
88
+ endAdornment?: ReactNode;
89
+ /**
90
+ * Whether to show a button to clear the control when it has content. Defaults
91
+ * to `"auto"` when `type="search"`, `false` otherwise.
92
+ */
93
+ showClearButton?: ControlShowClearButton;
94
+ /** Label of the clear button announced to assistive technologies. */
95
+ clearButtonLabel?: string;
96
+ /**
97
+ * Accessible description for how to clear the control when the clear button
98
+ * is visible.
99
+ *
100
+ * This field should be provided when adding extra keybinds to clear the
101
+ * control (_e.g._ the control is a file input and pressing Backspace/Delete
102
+ * clears it).
103
+ */
104
+ clearDescription?: ReactNode;
105
+ /**
106
+ * Function called when the focus moves out of the control as a whole.
107
+ *
108
+ * This is useful when there is a need to know when the user stops interacting
109
+ * with the control.
110
+ */
111
+ onBlurToOutside?: (event: FocusEvent) => void;
112
+ /** Properties to pass to the root component. */
113
+ rootProps?: ComponentPropsWithRef<"div">;
114
+ /** Properties to pass to the code component. */
115
+ codeProps?: Omit<ComponentPropsWithRef<typeof ControlAddon>, "status">;
116
+ /** Properties to pass to the container component. */
117
+ containerProps?: ComponentPropsWithRef<"div">;
118
+ /** Properties to pass to the clear button component. */
119
+ clearButtonProps?: ComponentPropsWithRef<typeof CloseButton>;
120
+ /** Properties to pass to the spinner component. */
121
+ spinnerProps?: Omit<ComponentPropsWithRef<typeof Spinner>, "size">;
122
+ };
123
+ /** Base properties of a single file input control. */
124
+ export interface ControlFileInputSingleProps extends ControlPropsBase<"input", File | null, never> {
125
+ type: "file";
126
+ multiple?: false;
127
+ }
128
+ /** Base properties of a multiple file input control. */
129
+ export interface ControlFileInputMultipleProps extends ControlPropsBase<"input", File[], never> {
130
+ type: "file";
131
+ multiple: true;
132
+ }
133
+ /** Base properties of a non-file input control. */
134
+ export interface ControlNonFileInputProps extends ControlPropsBase<"input", string, string | number> {
135
+ type?: Exclude<ControlType, "file">;
136
+ multiple?: boolean;
137
+ }
138
+ /** Base properties of a single select control. */
139
+ export interface ControlSelectSingleProps extends ControlPropsBase<"select", string, string | number> {
140
+ type?: never;
141
+ multiple?: false;
142
+ }
143
+ /** Base properties of a multiple select control. */
144
+ export interface ControlSelectMultipleProps extends ControlPropsBase<"select", string[]> {
145
+ type?: never;
146
+ multiple: true;
147
+ }
148
+ /** Base properties of a textarea control. */
149
+ export interface ControlTextAreaProps extends ControlPropsBase<"textarea", string, string | number> {
150
+ type?: never;
151
+ multiple?: never;
152
+ }
153
+ /** Base properties of an output control. */
154
+ export interface ControlOutputProps extends ControlPropsBase<"output", never> {
155
+ type?: never;
156
+ multiple?: never;
157
+ }
158
+ /** Properties of the control component. */
159
+ export type ControlProps = ControlFileInputSingleProps | ControlFileInputMultipleProps | ControlNonFileInputProps | ControlSelectSingleProps | ControlSelectMultipleProps | ControlTextAreaProps | ControlOutputProps;
160
+ /** Form control. */
161
+ export declare const Control: import('react').ForwardRefExoticComponent<ControlProps & import('react').RefAttributes<HTMLElement>>;
162
+ export {};
@@ -0,0 +1,13 @@
1
+ import { ControlStatus, ControlVariant } from './Control.tsx';
2
+ /** Value of the control context. */
3
+ export interface ControlContextValue {
4
+ variant?: ControlVariant;
5
+ status?: ControlStatus;
6
+ disabled?: boolean;
7
+ softDisabled?: boolean;
8
+ readOnly?: boolean;
9
+ }
10
+ /** Control context. */
11
+ export declare const ControlContext: import('react').Context<ControlContextValue | null>;
12
+ /** Hook providing access to the control context. */
13
+ export declare function useControlContext(): ControlContextValue | null;
@@ -0,0 +1,14 @@
1
+ import { ComponentRef, Ref } from 'react';
2
+ import { Control, ControlProps } from './Control.tsx';
3
+ /**
4
+ * Utility control component whose `ref` is passed to the control's container.
5
+ * Use `controlRef` to provide the control's ref instead.
6
+ *
7
+ * This component is useful when using a control component as a trigger for
8
+ * popovers/menus, and we wish to align said popover/menu against the control's
9
+ * container (since popovers/menus align themselves based on the element
10
+ * referenced by their trigger).
11
+ */
12
+ export declare const ControlWithContainerRef: import('react').ForwardRefExoticComponent<(ControlProps & {
13
+ controlRef?: Ref<ComponentRef<typeof Control>>;
14
+ }) & import('react').RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,4 @@
1
+ import { AccentColor } from '../../utils/accent.ts';
2
+ import { ControlStatus } from './Control.tsx';
3
+ /** Transforms a control status into a colour accent. */
4
+ export declare function controlStatusToAccent(status?: ControlStatus, defaultAccent?: AccentColor): AccentColor | undefined;
@@ -0,0 +1,4 @@
1
+ export * from './Control.tsx';
2
+ export * from './ControlContext.ts';
3
+ export * from './controlUtils.ts';
4
+ export * from './ControlWithContainerRef.tsx';
@@ -1,5 +1,5 @@
1
1
  import { ComponentPropsWithoutRef } from 'react';
2
- import { ControlStatus, ControlVariant } from '../../utils/control.ts';
2
+ import { ControlStatus, ControlVariant } from '../Control';
3
3
  /** Properties of the control addon component. */
4
4
  export interface ControlAddonProps extends ComponentPropsWithoutRef<"div"> {
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { ComponentPropsWithoutRef, ReactNode } from 'react';
2
- import { ControlStatus, ControlVariant } from '../../utils/control.ts';
2
+ import { ControlStatus, ControlVariant } from '../Control';
3
3
  /** Properties of the control's code component. */
4
4
  export interface ControlCodeProps extends ComponentPropsWithoutRef<"div"> {
5
5
  /**
@@ -1,7 +1,6 @@
1
- import { ComponentPropsWithoutRef } from 'react';
2
- import { Input } from '../Input';
1
+ import { InputNonFileProps } from '../Input';
3
2
  /** Properties of the data table filter component. */
4
- export interface DataTableFilterProps extends Omit<ComponentPropsWithoutRef<typeof Input>, "defaultValue" | "value"> {
3
+ export interface DataTableFilterProps extends Omit<InputNonFileProps, "defaultValue" | "value"> {
5
4
  /**
6
5
  * Whether the component should preferably be aligned to the right. This only
7
6
  * has an effect when the component is nested directly under the `DataTable`.
@@ -1,9 +1,11 @@
1
- import { ComponentPropsWithoutRef, ComponentPropsWithRef, ReactNode } from 'react';
1
+ import { ComponentPropsWithRef, ReactNode } from 'react';
2
2
  import { Calendar } from '../Calendar';
3
- import { Input } from '../Input';
3
+ import { ControlNonFileInputProps } from '../Control';
4
+ import { FormValidationMode } from '../Form';
5
+ import { FormControlValidateFn } from '../Form/useRegisterFormControl.ts';
4
6
  import { PopoverContent } from '../Popover';
5
7
  /** Properties of the date input component. */
6
- export interface DateInputProps extends Omit<ComponentPropsWithoutRef<typeof Input>, "defaultValue" | "value" | "onValueChange"> {
8
+ export interface DateInputProps extends Omit<ControlNonFileInputProps, "defaultValue" | "value" | "onValueChange"> {
7
9
  /** Date input's default value. */
8
10
  defaultValue?: string | Date | null;
9
11
  /** Date input's controlled value. */
@@ -14,13 +16,29 @@ export interface DateInputProps extends Omit<ComponentPropsWithoutRef<typeof Inp
14
16
  * @param valueRepresentations Different representations of the date value.
15
17
  */
16
18
  onValueChange?: (valueRepresentations: DateValueRepresentations) => void;
17
- /** Minimum date allowed. */
19
+ /**
20
+ * Minimum date allowed. When a string it provided, it should represent the
21
+ * date in the ISO 8601 format, _i.e._ `"2020-01-01"` should be provided
22
+ * instead of a formatted `"01/01/2020"`.
23
+ */
18
24
  minDate?: string | Date | null;
19
- /** Maximum date allowed. */
25
+ /**
26
+ * Maximum date allowed. When a string it provided, it should represent the
27
+ * date in the ISO 8601 format, _i.e._ `"2020-01-01"` should be provided
28
+ * instead of a formatted `"01/01/2020"`.
29
+ */
20
30
  maxDate?: string | Date | null;
21
- /** Minimum month allowed. */
31
+ /**
32
+ * Minimum month allowed. When a string it provided, it should represent the
33
+ * date in the ISO 8601 format, _i.e._ `"2020-01"` should be provided instead
34
+ * of a formatted `"01/2020"`.
35
+ */
22
36
  minMonth?: string | Date | null;
23
- /** Maximum month allowed. */
37
+ /**
38
+ * Maximum month allowed. When a string it provided, it should represent the
39
+ * date in the ISO 8601 format, _i.e._ `"2020-01"` should be provided instead
40
+ * of a formatted `"01/2020"`.
41
+ */
24
42
  maxMonth?: string | Date | null;
25
43
  /** Minimum year allowed. */
26
44
  minYear?: number;
@@ -42,6 +60,16 @@ export interface DateInputProps extends Omit<ComponentPropsWithoutRef<typeof Inp
42
60
  formatDescription?: ReactNode;
43
61
  /** Description of the selected date, announced to assistive technologies. */
44
62
  selectedDateDescription?: (date: string) => ReactNode;
63
+ /**
64
+ * Custom validation function meant to validate the control when it is part of
65
+ * a `Form`.
66
+ */
67
+ validate?: FormControlValidateFn<string | null>;
68
+ /**
69
+ * Specifies when the control should be validated. Defaults to the value
70
+ * specified in the `Form`.
71
+ */
72
+ validationMode?: FormValidationMode;
45
73
  /** Label of the button that opens the input's calendar. */
46
74
  calendarButtonLabel?: ReactNode;
47
75
  /** Function called whenever the popover's open state changes. */
@@ -55,6 +83,8 @@ export interface DateInputProps extends Omit<ComponentPropsWithoutRef<typeof Inp
55
83
  export interface DateValueRepresentations {
56
84
  /** Date value as a formatted string. */
57
85
  formattedValue: string;
86
+ /** Date value as an ISO 8601 string. */
87
+ stringValue: string | null;
58
88
  /** Date value as a date. */
59
89
  dateValue: Date | null;
60
90
  }
@@ -1,19 +1,31 @@
1
1
  import { ComponentPropsWithoutRef, ComponentPropsWithRef, CSSProperties, FocusEvent, ReactNode } from 'react';
2
- import { ControlStatus, ControlVariant } from '../../utils/control.ts';
3
2
  import { Responsive } from '../../utils/useResponsiveValues.ts';
4
3
  import { Calendar, DateRange } from '../Calendar';
5
4
  import { CloseButton } from '../CloseButton';
5
+ import { ControlShowClearButton, ControlStatus, ControlVariant } from '../Control';
6
6
  import { ControlCode } from '../ControlCode';
7
- import { ShowClearButton } from '../Input';
7
+ import { FormValidationMode } from '../Form';
8
+ import { FormControlValidateFn } from '../Form/useRegisterFormControl.ts';
8
9
  import { PopoverAnchor, PopoverContent } from '../Popover';
9
10
  import { Spinner } from '../Spinner';
10
- /** Date-range using strings as dates. */
11
- export interface StringRange {
11
+ /** Date-range using formatted strings as dates. */
12
+ export interface FormattedRange {
13
+ /** Start of the date-range. */
12
14
  start: string;
15
+ /** End of the date-range. */
13
16
  end: string;
14
17
  }
18
+ /** Date-range using ISO 8601 strings as dates. */
19
+ export interface StringRange {
20
+ /** Start of the date-range. */
21
+ start: string | null;
22
+ /** End of the date-range. */
23
+ end: string | null;
24
+ }
15
25
  /** Properties of the date-range input component. */
16
26
  export interface DateRangeInputProps extends Omit<ComponentPropsWithoutRef<"div">, "defaultValue"> {
27
+ /** Name of the control. Both inputs will share the same name. */
28
+ name?: string;
17
29
  /**
18
30
  * Date-range input's style variant. Defaults to the default variant unless
19
31
  * when rendering inside a table cell (in which it defaults to `"cell"`).
@@ -24,9 +36,9 @@ export interface DateRangeInputProps extends Omit<ComponentPropsWithoutRef<"div"
24
36
  /** Date-range input code. */
25
37
  code?: ReactNode;
26
38
  /** Default date-range value. */
27
- defaultValue?: DateRange | StringRange;
39
+ defaultValue?: DateRange | FormattedRange;
28
40
  /** Date-range value. */
29
- value?: DateRange | StringRange;
41
+ value?: DateRange | FormattedRange;
30
42
  /**
31
43
  * Function called whenever the value of the date-range input changes.
32
44
  *
@@ -120,7 +132,7 @@ export interface DateRangeInputProps extends Omit<ComponentPropsWithoutRef<"div"
120
132
  *
121
133
  * @default true
122
134
  */
123
- showClearButtons?: ShowClearButton;
135
+ showClearButtons?: ControlShowClearButton;
124
136
  /** Label of the clear buttons announced to assistive technologies. */
125
137
  clearButtonsLabel?: string;
126
138
  /**
@@ -153,7 +165,17 @@ export interface DateRangeInputProps extends Omit<ComponentPropsWithoutRef<"div"
153
165
  * Prefix used when announcing the selected date-range to assistive
154
166
  * technologies.
155
167
  */
156
- selectedDateRangeDescription?: (dateRange: StringRange) => ReactNode;
168
+ selectedDateRangeDescription?: (dateRange: FormattedRange) => ReactNode;
169
+ /**
170
+ * Custom validation function meant to validate the control when it is part of
171
+ * a `Form`.
172
+ */
173
+ validate?: FormControlValidateFn<StringRange | null>;
174
+ /**
175
+ * Specifies when the control should be validated. Defaults to the value
176
+ * specified in the `Form`.
177
+ */
178
+ validationMode?: FormValidationMode;
157
179
  /** Label of the button that opens the input's calendar. */
158
180
  calendarButtonLabel?: ReactNode;
159
181
  /** Placeholder for both start and end inputs. */
@@ -171,6 +193,8 @@ export interface DateRangeInputProps extends Omit<ComponentPropsWithoutRef<"div"
171
193
  * with the control.
172
194
  */
173
195
  onBlurToOutside?: (event: FocusEvent) => void;
196
+ /** Form attribute of the inputs. */
197
+ form?: string;
174
198
  /** Properties to pass to the code component. */
175
199
  codeProps?: ComponentPropsWithRef<typeof ControlCode>;
176
200
  /** Properties to pass to the popover anchor component. */
@@ -197,7 +221,9 @@ export interface DateRangeInputProps extends Omit<ComponentPropsWithoutRef<"div"
197
221
  /** Representations of the date-range value. */
198
222
  export interface DateRangeValueRepresentations {
199
223
  /** Date-range value as formatted strings. */
200
- formattedValue: StringRange;
224
+ formattedValue: FormattedRange;
225
+ /** Date-range value as ISO 8601 strings. */
226
+ stringValue: StringRange;
201
227
  /** Date-range value as dates. */
202
228
  dateValue: DateRange;
203
229
  }
@@ -16,19 +16,9 @@ export interface FieldProps extends ComponentPropsWithoutRef<"div"> {
16
16
  * guidance or descriptions, and `Feedback` to display error, warning, or
17
17
  * success messages.
18
18
  *
19
- * It supports the following form controls:
20
- *
21
- * - `Checkbox`
22
- * - `CheckboxGroup`
23
- * - `DataTable`
24
- * - `DateInput`
25
- * - `DateRangeInput`
26
- * - `NumericInput`
27
- * - `Input`
28
- * - `RadioGroup`
29
- * - `Select`
30
- * - `Table`
31
- * - `TextArea`
19
+ * It supports the following form controls: `Checkbox`, `CheckboxGroup`,
20
+ * `DataTable`, `DateInput`, `DateRangeInput`, `NumericInput`, `Input`,
21
+ * `RadioGroup`, `Select`, `Table`, `TextArea`.
32
22
  *
33
23
  * Example usage:
34
24
  *
@@ -1,9 +1,10 @@
1
1
  import { ReactNode } from 'react';
2
- import { ControlStatus } from '../../utils/control.ts';
2
+ import { ControlStatus } from '../Control';
3
3
  /** Value of the field context. */
4
4
  export type FieldContextValue = FieldStore;
5
5
  /** State of the field. */
6
6
  export interface FieldState {
7
+ controlName?: string;
7
8
  controlId?: string;
8
9
  controlTagName?: string;
9
10
  controlFocused: boolean;
@@ -45,6 +46,8 @@ export declare function useCreateFieldContext(): Omit<import('zustand').StoreApi
45
46
  } | undefined): () => void;
46
47
  };
47
48
  };
49
+ /** Hook exposing the field control's name. */
50
+ export declare function useFieldControlName(): string | undefined;
48
51
  /** Hook exposing the field control's id. */
49
52
  export declare function useFieldControlId(): string | undefined;
50
53
  /** Hook exposing the field control's tag name. */
@@ -64,11 +67,13 @@ export declare function useFieldDescriptionIds(): string[] | undefined;
64
67
  /** Hook exposing the field's error message ids. */
65
68
  export declare function useFieldErrorMessageIds(): string[] | undefined;
66
69
  /** Hook that makes a field aware of its control's information. */
67
- export declare function useSetFieldControl(controlId: string | undefined, controlTagName: string | undefined, controlCodeId: string | undefined, controlHasCode?: boolean | undefined, controlRequired?: boolean | undefined, controlStatus?: ControlStatus | undefined): {
70
+ export declare function useRegisterFieldControl(controlId: string | undefined, controlTagName: string | undefined, controlCodeId: string | undefined, controlHasCode?: boolean | undefined, controlRequired?: boolean | undefined, controlStatus?: ControlStatus | undefined): {
68
71
  generatedId: string;
69
72
  controlId: string;
70
73
  codeId: string | undefined;
71
74
  };
75
+ /** Hook which register's a control's name into its field. */
76
+ export declare function useRegisterFieldName(name: string | undefined): void;
72
77
  /**
73
78
  * Hook which returns a function that can be used to set the focus status of the
74
79
  * field's control.
@@ -1,3 +1,3 @@
1
1
  export * from './Field.tsx';
2
- export { type FieldActions, useFieldControlFocused, useFieldControlId, useFieldControlRequired, useFieldControlTagName, useFieldDescriptionIds, useFieldErrorMessageIds, useFieldLabel, useFieldLabelId, useOnFieldLabelChange, useSetFieldControl, useSetFieldControlFocused, useSetFieldFeedback, useSetFieldHelperText, useSetFieldLabel, } from './FieldContext.ts';
2
+ export { type FieldActions, useFieldControlFocused, useFieldControlId, useFieldControlRequired, useFieldControlTagName, useFieldDescriptionIds, useFieldErrorMessageIds, useFieldLabel, useFieldLabelId, useOnFieldLabelChange, useRegisterFieldControl, useSetFieldControlFocused, useSetFieldFeedback, useSetFieldHelperText, useSetFieldLabel, } from './FieldContext.ts';
3
3
  export * from './FieldProvider.tsx';