@trackunit/react-form-components 1.8.121 → 1.8.123

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 (31) hide show
  1. package/index.cjs.js +873 -576
  2. package/index.esm.js +863 -572
  3. package/package.json +9 -8
  4. package/src/components/BaseInput/BaseInput.d.ts +1 -5
  5. package/src/components/BaseSelect/BaseSelect.d.ts +2 -5
  6. package/src/components/BaseSelect/BaseSelect.variants.d.ts +26 -16
  7. package/src/components/BaseSelect/CreatableSelect.d.ts +15 -10
  8. package/src/components/BaseSelect/custom-components/CounterTag.d.ts +15 -0
  9. package/src/components/BaseSelect/custom-components/MultiValue.d.ts +18 -0
  10. package/src/components/BaseSelect/{SelectMenuItem → custom-components/SelectMenuItem}/SelectMenuItem.d.ts +3 -3
  11. package/src/components/BaseSelect/index.d.ts +2 -1
  12. package/src/components/BaseSelect/useCreatableSelect.d.ts +10 -0
  13. package/src/components/BaseSelect/useCustomComponents.d.ts +26 -23
  14. package/src/components/BaseSelect/useMultiMeasure.d.ts +27 -0
  15. package/src/components/BaseSelect/useMultiValueOverflow.d.ts +21 -0
  16. package/src/components/BaseSelect/useSelect.d.ts +22 -39
  17. package/src/components/DropZone/DropZone.d.ts +1 -1
  18. package/src/components/FormGroup/FormGroup.d.ts +2 -2
  19. package/src/components/MultiSelectField/FormFieldSelectAdapterMulti.d.ts +21 -18
  20. package/src/components/MultiSelectField/MultiSelectField.d.ts +9 -4
  21. package/src/components/PhoneField/PhoneBaseInput/PhoneBaseInput.d.ts +2 -2
  22. package/src/components/SelectField/CreatableSelectField.d.ts +5 -3
  23. package/src/components/SelectField/FormFieldSelectAdapter.d.ts +14 -10
  24. package/src/components/SelectField/SelectField.d.ts +6 -9
  25. package/src/components/UrlField/UrlBaseInput/UrlBaseInput.d.ts +2 -1
  26. package/src/components/storybook-utils/sharedArgTypes.d.ts +0 -54
  27. package/src/translation.d.ts +2 -2
  28. package/src/types.d.ts +1 -1
  29. package/src/components/BaseSelect/TagWithWidth.d.ts +0 -16
  30. package/src/components/BaseSelect/TagsContainer.d.ts +0 -51
  31. package/src/components/BaseSelect/useCustomStyles.d.ts +0 -20
@@ -1,4 +1,4 @@
1
- import { ReactNode } from "react";
1
+ import { ReactElement, ReactNode } from "react";
2
2
  import { BaseInputProps } from "../../BaseInput";
3
3
  type BaseInputExposedProps = Omit<BaseInputProps, "actions">;
4
4
  export interface PhoneBaseInputProps extends BaseInputExposedProps {
@@ -26,5 +26,5 @@ export interface PhoneBaseInputProps extends BaseInputExposedProps {
26
26
  * @param {string} [fieldSize="medium"] - The size of the input field.
27
27
  * @param {boolean} [disableAction=false] - Whether the action button is disabled or not.
28
28
  */
29
- export declare const PhoneBaseInput: ({ "data-testid": dataTestId, isInvalid, disabled, value, defaultValue, fieldSize, disableAction, onChange, readOnly, onFocus, onBlur, name, ref, ...rest }: PhoneBaseInputProps) => import("react/jsx-runtime").JSX.Element;
29
+ export declare const PhoneBaseInput: ({ "data-testid": dataTestId, isInvalid, disabled, value, defaultValue, fieldSize, disableAction, onChange, readOnly, onFocus, onBlur, name, ref, ...rest }: PhoneBaseInputProps) => ReactElement;
30
30
  export {};
@@ -1,6 +1,8 @@
1
- import { CreatableSelectProps } from "../BaseSelect/CreatableSelect";
1
+ import { ReactElement } from "react";
2
+ import { GroupBase } from "react-select";
3
+ import { CreatableSelectExtraProps } from "../BaseSelect/CreatableSelect";
2
4
  import { BaseOptionType, SelectFieldProps } from "./FormFieldSelectAdapter";
3
- interface CreatableSelectFieldProps extends SelectFieldProps<BaseOptionType>, CreatableSelectProps {
5
+ interface CreatableSelectFieldProps<TOption extends BaseOptionType = BaseOptionType, TIsAsync extends boolean = false> extends SelectFieldProps<TOption, TIsAsync>, CreatableSelectExtraProps<TOption, false, GroupBase<TOption>> {
4
6
  }
5
7
  /**
6
8
  * The CreatableSelectField component is a CreatableSelect component wrapped in the FromGroup component.
@@ -12,7 +14,7 @@ interface CreatableSelectFieldProps extends SelectFieldProps<BaseOptionType>, Cr
12
14
  * @param {SelectFieldProps & CreatableSelectProps} props - The props for the CreatableSelectField component
13
15
  */
14
16
  export declare const CreatableSelectField: {
15
- ({ allowCreateWhileLoading, onCreateOption, ref, ...props }: CreatableSelectFieldProps): import("react/jsx-runtime").JSX.Element;
17
+ <TOption extends BaseOptionType = BaseOptionType, TIsAsync extends boolean = false>({ allowCreateWhileLoading, onCreateOption, ref, ...props }: CreatableSelectFieldProps<TOption, TIsAsync>): ReactElement;
16
18
  displayName: string;
17
19
  };
18
20
  export {};
@@ -1,6 +1,6 @@
1
1
  import { CommonProps } from "@trackunit/react-components";
2
2
  import { MappedOmit } from "@trackunit/shared-utils";
3
- import { FocusEvent, ReactNode, Ref } from "react";
3
+ import { FocusEvent, ReactElement, ReactNode, Ref } from "react";
4
4
  import { GroupBase } from "react-select";
5
5
  import { SelectProps } from "../BaseSelect/useSelect";
6
6
  import { FormGroupProps } from "../FormGroup/FormGroup";
@@ -8,47 +8,51 @@ export type BaseOptionType = {
8
8
  label: string;
9
9
  value: string | number;
10
10
  };
11
- type SelectExposedProps<TOptionType extends BaseOptionType> = MappedOmit<SelectProps<TOptionType, false, false, GroupBase<TOptionType>>, "value" | "label" | "onChange" | "defaultValue" | "onBlur" | "options">;
11
+ type SelectExposedProps<TOption extends BaseOptionType = BaseOptionType, TIsAsync extends boolean = false> = MappedOmit<SelectProps<TOption, TIsAsync, false, GroupBase<TOption>>, "value" | "label" | "onChange" | "defaultValue" | "onBlur" | "options">;
12
12
  type FormGroupExposedProps = Pick<FormGroupProps, "label" | "tip" | "helpText" | "helpAddon" | "isInvalid">;
13
- export type SelectFieldProps<TOptionType extends BaseOptionType> = CommonProps & FormGroupExposedProps & SelectExposedProps<TOptionType> & {
13
+ export type SelectFieldProps<TOption extends BaseOptionType = BaseOptionType, TIsAsync extends boolean = false> = CommonProps & FormGroupExposedProps & SelectExposedProps<TOption, TIsAsync> & {
14
14
  onBlur?: (event: FocusEvent<HTMLInputElement>) => void;
15
15
  /**
16
16
  * The options available for the SelectField.
17
17
  */
18
- options: Array<TOptionType>;
18
+ options: Array<TOption>;
19
19
  /**
20
20
  * The selected value of the SelectField.
21
21
  */
22
- value?: TOptionType["value"];
22
+ value?: TOption["value"];
23
23
  /**
24
24
  * The default selected value of the SelectField.
25
25
  */
26
- defaultValue?: TOptionType["value"];
26
+ defaultValue?: TOption["value"];
27
27
  /**
28
28
  * The onChange handler for the SelectField.
29
29
  */
30
30
  onChange?: (event: {
31
31
  target: {
32
- value?: TOptionType["value"];
32
+ value?: TOption["value"];
33
33
  };
34
34
  }) => void;
35
35
  /**
36
36
  * If a value is set, the field is rendered in its invalid state.
37
37
  */
38
38
  errorMessage?: string;
39
+ /**
40
+ * The htmlFor attribute for the label. If not provided, falls back to id or generates a unique value.
41
+ */
42
+ htmlFor?: string;
39
43
  /**
40
44
  * A ref for the component
41
45
  */
42
46
  ref?: Ref<HTMLSelectElement>;
43
47
  };
44
- interface FormFieldSelectAdapterProps<TOptionType extends BaseOptionType, TIsAsync extends boolean = false, TIsMulti extends boolean = false> extends SelectFieldProps<TOptionType> {
45
- children: (props: SelectProps<TOptionType, TIsAsync, TIsMulti, GroupBase<TOptionType>>) => ReactNode;
48
+ interface FormFieldSelectAdapterProps<TOption extends BaseOptionType = BaseOptionType, TIsAsync extends boolean = false> extends SelectFieldProps<TOption, TIsAsync> {
49
+ children: (props: SelectProps<TOption, TIsAsync, false, GroupBase<TOption>>) => ReactNode;
46
50
  }
47
51
  /**
48
52
  *
49
53
  */
50
54
  export declare const FormFieldSelectAdapter: {
51
- ({ className, "data-testid": dataTestId, helpText, helpAddon, tip, label, isInvalid, errorMessage, name, onBlur, options, value, defaultValue, id, onChange, children, ref, ...rest }: FormFieldSelectAdapterProps<BaseOptionType>): import("react/jsx-runtime").JSX.Element;
55
+ <TOption extends BaseOptionType = BaseOptionType, TIsAsync extends boolean = false>({ className, "data-testid": dataTestId, helpText, helpAddon, tip, label, isInvalid, errorMessage, name, onBlur, options, value, defaultValue, id, htmlFor: htmlForProp, onChange, children, ref, required, ...rest }: FormFieldSelectAdapterProps<TOption, TIsAsync>): ReactElement;
52
56
  displayName: string;
53
57
  };
54
58
  export {};
@@ -1,14 +1,11 @@
1
+ import { ReactElement } from "react";
1
2
  import { BaseOptionType, SelectFieldProps } from "./FormFieldSelectAdapter";
2
3
  /**
3
- * The SelectField component is a Select component wrapped in the FromGroup component.
4
- *
5
- * This means that it can easily be added to any form alongside other Field components.
6
- *
7
- * This is done to make the field compatible with the React-hook-form library.
4
+ * MultiSelect is a custom Select component wrapped in the FormGroup component
8
5
  *
9
6
  * @param {SelectFieldProps} props - The props for the SelectField component
10
7
  */
11
- export declare const SelectField: {
12
- ({ ref, ...props }: SelectFieldProps<BaseOptionType>): import("react/jsx-runtime").JSX.Element;
13
- displayName: string;
14
- };
8
+ export declare function SelectField<TOption extends BaseOptionType, TIsAsync extends boolean = false>({ ref, ...props }: SelectFieldProps<TOption, TIsAsync>): ReactElement;
9
+ export declare namespace SelectField {
10
+ var displayName: string;
11
+ }
@@ -1,3 +1,4 @@
1
+ import { ReactElement } from "react";
1
2
  import { BaseInputProps } from "../../BaseInput";
2
3
  type BaseInputExposedProps = Omit<BaseInputProps, "type">;
3
4
  export interface UrlBaseInputProps extends BaseInputExposedProps {
@@ -16,5 +17,5 @@ export interface UrlBaseInputProps extends BaseInputExposedProps {
16
17
  *
17
18
  * NOTE: If shown with a label, please use the `UrlField` component instead.
18
19
  */
19
- export declare const UrlBaseInput: ({ "data-testid": dataTestId, isInvalid, disabled, fieldSize, disableAction, value, defaultValue, ref, ...rest }: UrlBaseInputProps) => import("react/jsx-runtime").JSX.Element;
20
+ export declare const UrlBaseInput: ({ isInvalid, "data-testid": dataTestId, disabled, fieldSize, disableAction, value, defaultValue, ref, ...rest }: UrlBaseInputProps) => ReactElement;
20
21
  export {};
@@ -91,24 +91,6 @@ export declare const selectMostImportantArgTypes: {
91
91
  };
92
92
  readonly description: "Callback fired when the menu is opened.";
93
93
  };
94
- readonly getOptionLabel: {
95
- readonly control: false;
96
- readonly table: {
97
- readonly type: {
98
- readonly summary: "(option: Option) => string";
99
- };
100
- };
101
- readonly description: "Resolves option data to a string to be displayed as the label for that option.";
102
- };
103
- readonly getOptionValue: {
104
- readonly control: false;
105
- readonly table: {
106
- readonly type: {
107
- readonly summary: "(option: Option) => string";
108
- };
109
- };
110
- readonly description: "Resolves option data to a string to compare options and specify value attributes";
111
- };
112
94
  readonly getOptionLabelDescription: {
113
95
  readonly control: false;
114
96
  readonly table: {
@@ -229,24 +211,6 @@ export declare const selectArgTypes: {
229
211
  };
230
212
  readonly description: "Callback fired when the menu is opened.";
231
213
  };
232
- readonly getOptionLabel: {
233
- readonly control: false;
234
- readonly table: {
235
- readonly type: {
236
- readonly summary: "(option: Option) => string";
237
- };
238
- };
239
- readonly description: "Resolves option data to a string to be displayed as the label for that option.";
240
- };
241
- readonly getOptionValue: {
242
- readonly control: false;
243
- readonly table: {
244
- readonly type: {
245
- readonly summary: "(option: Option) => string";
246
- };
247
- };
248
- readonly description: "Resolves option data to a string to compare options and specify value attributes";
249
- };
250
214
  readonly getOptionLabelDescription: {
251
215
  readonly control: false;
252
216
  readonly table: {
@@ -285,24 +249,6 @@ export declare const fieldSizeArgType: {
285
249
  readonly options: readonly ["small", "medium", "large"];
286
250
  readonly description: "Size of the select field.";
287
251
  };
288
- export declare const getOptionLabelArgType: {
289
- readonly control: false;
290
- readonly table: {
291
- readonly type: {
292
- readonly summary: "(option: Option) => string";
293
- };
294
- };
295
- readonly description: "Resolves option data to a string to be displayed as the label for that option.";
296
- };
297
- export declare const getOptionValueArgType: {
298
- readonly control: false;
299
- readonly table: {
300
- readonly type: {
301
- readonly summary: "(option: Option) => string";
302
- };
303
- };
304
- readonly description: "Resolves option data to a string to compare options and specify value attributes";
305
- };
306
252
  export declare const getOptionLabelDescriptionArgType: {
307
253
  readonly control: false;
308
254
  readonly table: {
@@ -14,8 +14,8 @@ export declare const translations: TranslationResource<TranslationKeys>;
14
14
  /**
15
15
  * Local useTranslation for this specific library
16
16
  */
17
- export declare const useTranslation: () => [TransForLibs<"baseInput.copyAction.toolTip" | "clearIndicator.icon.tooltip.clearAll" | "colorField.error.INVALID_HEX_CODE" | "colorField.error.REQUIRED" | "colorField.tooltip" | "dropzone.input.title" | "dropzone.label.default" | "emailField.error.INVALID_EMAIL" | "emailField.error.REQUIRED" | "field.notEditable.tooltip" | "field.required.asterisk.tooltip" | "numberField.error.GREATER_THAN" | "numberField.error.INVALID_NUMBER" | "numberField.error.LESS_THAN" | "numberField.error.NOT_IN_BETWEEN" | "numberField.error.REQUIRED" | "phoneField.error.INVALID_COUNTRY" | "phoneField.error.INVALID_LENGTH" | "phoneField.error.INVALID_NUMBER" | "phoneField.error.NOT_A_NUMBER" | "phoneField.error.REQUIRED" | "phoneField.error.REQUIRED_COUNTRY" | "phoneField.error.TOO_LONG" | "phoneField.error.TOO_SHORT" | "phoneField.error.undefined" | "schedule.label.active" | "schedule.label.allDay" | "schedule.label.day" | "search.placeholder" | "urlField.error.INVALID_URL" | "urlField.error.REQUIRED">, import("i18next").i18n, boolean] & {
18
- t: TransForLibs<"baseInput.copyAction.toolTip" | "clearIndicator.icon.tooltip.clearAll" | "colorField.error.INVALID_HEX_CODE" | "colorField.error.REQUIRED" | "colorField.tooltip" | "dropzone.input.title" | "dropzone.label.default" | "emailField.error.INVALID_EMAIL" | "emailField.error.REQUIRED" | "field.notEditable.tooltip" | "field.required.asterisk.tooltip" | "numberField.error.GREATER_THAN" | "numberField.error.INVALID_NUMBER" | "numberField.error.LESS_THAN" | "numberField.error.NOT_IN_BETWEEN" | "numberField.error.REQUIRED" | "phoneField.error.INVALID_COUNTRY" | "phoneField.error.INVALID_LENGTH" | "phoneField.error.INVALID_NUMBER" | "phoneField.error.NOT_A_NUMBER" | "phoneField.error.REQUIRED" | "phoneField.error.REQUIRED_COUNTRY" | "phoneField.error.TOO_LONG" | "phoneField.error.TOO_SHORT" | "phoneField.error.undefined" | "schedule.label.active" | "schedule.label.allDay" | "schedule.label.day" | "search.placeholder" | "urlField.error.INVALID_URL" | "urlField.error.REQUIRED">;
17
+ export declare const useTranslation: () => [TransForLibs<"baseInput.copyAction.toolTip" | "clearIndicator.icon.tooltip.clearAll" | "colorField.error.INVALID_HEX_CODE" | "colorField.error.REQUIRED" | "colorField.tooltip" | "dropzone.input.title" | "dropzone.label.default" | "emailField.error.INVALID_EMAIL" | "emailField.error.REQUIRED" | "field.notEditable.tooltip" | "field.required.asterisk.tooltip" | "numberField.error.GREATER_THAN" | "numberField.error.INVALID_NUMBER" | "numberField.error.LESS_THAN" | "numberField.error.NOT_IN_BETWEEN" | "numberField.error.REQUIRED" | "phoneField.error.INVALID_COUNTRY" | "phoneField.error.INVALID_LENGTH" | "phoneField.error.INVALID_NUMBER" | "phoneField.error.NOT_A_NUMBER" | "phoneField.error.REQUIRED" | "phoneField.error.REQUIRED_COUNTRY" | "phoneField.error.TOO_LONG" | "phoneField.error.TOO_SHORT" | "phoneField.error.undefined" | "schedule.label.active" | "schedule.label.allDay" | "schedule.label.day" | "search.placeholder" | "select.loadingMessage" | "select.noOptionsMessage" | "urlField.error.INVALID_URL" | "urlField.error.REQUIRED">, import("i18next").i18n, boolean] & {
18
+ t: TransForLibs<"baseInput.copyAction.toolTip" | "clearIndicator.icon.tooltip.clearAll" | "colorField.error.INVALID_HEX_CODE" | "colorField.error.REQUIRED" | "colorField.tooltip" | "dropzone.input.title" | "dropzone.label.default" | "emailField.error.INVALID_EMAIL" | "emailField.error.REQUIRED" | "field.notEditable.tooltip" | "field.required.asterisk.tooltip" | "numberField.error.GREATER_THAN" | "numberField.error.INVALID_NUMBER" | "numberField.error.LESS_THAN" | "numberField.error.NOT_IN_BETWEEN" | "numberField.error.REQUIRED" | "phoneField.error.INVALID_COUNTRY" | "phoneField.error.INVALID_LENGTH" | "phoneField.error.INVALID_NUMBER" | "phoneField.error.NOT_A_NUMBER" | "phoneField.error.REQUIRED" | "phoneField.error.REQUIRED_COUNTRY" | "phoneField.error.TOO_LONG" | "phoneField.error.TOO_SHORT" | "phoneField.error.undefined" | "schedule.label.active" | "schedule.label.allDay" | "schedule.label.day" | "search.placeholder" | "select.loadingMessage" | "select.noOptionsMessage" | "urlField.error.INVALID_URL" | "urlField.error.REQUIRED">;
19
19
  i18n: import("i18next").i18n;
20
20
  ready: boolean;
21
21
  };
package/src/types.d.ts CHANGED
@@ -1 +1 @@
1
- export type FormComponentSizes = "small" | "medium" | "large" | undefined | null;
1
+ export type FormComponentSizes = "small" | "medium" | "large";
@@ -1,16 +0,0 @@
1
- import { TagProps } from "@trackunit/react-components";
2
- type TagsPropsNoRef = Omit<TagProps, "ref">;
3
- interface TagWithWidthProps extends TagsPropsNoRef {
4
- onWidthKnown?: ({ width }: {
5
- width: number;
6
- }) => void;
7
- }
8
- /**
9
- * Extended Tag component with information about its own width.
10
- * Used in the select component.
11
- *
12
- * @param {TagProps} props - The props for the tag component
13
- * @returns {ReactElement} TagWithWidth component
14
- */
15
- export declare const TagWithWidth: ({ onWidthKnown, children, ...rest }: TagWithWidthProps) => import("react/jsx-runtime").JSX.Element;
16
- export {};
@@ -1,51 +0,0 @@
1
- import { ReactElement, ReactNode } from "react";
2
- interface TagsContainerItem {
3
- /**
4
- * A text value to be passed to tags inside container
5
- */
6
- text: string;
7
- /**
8
- * OnClick handler for a tags
9
- */
10
- onClick: () => void;
11
- /**
12
- * A flag to set tags to readonly mode (without close button)
13
- */
14
- disabled: boolean;
15
- Icon?: ReactNode;
16
- }
17
- interface TagsContainerProps {
18
- /**
19
- * An items to be rendered inside container if they fit available space. If they overlap then the counter will be displayed.
20
- */
21
- items: Array<TagsContainerItem>;
22
- /**
23
- * An css property to set a custom width for container
24
- * Default behavior is to take 100% width of parent element
25
- * You can provide a value with unit (pixels, percents, rem, etc)
26
- *
27
- * @memberof TagsContainerProps
28
- */
29
- width?: string;
30
- /**
31
- * In case you have a gap between items then you can provide it to be used in calculation of available space,
32
- * default value is 5, so if you don't need it then provide 0
33
- *
34
- * @memberof TagsContainerProps
35
- */
36
- itemsGap?: number;
37
- preFix: ReactElement | null;
38
- postFix: ReactElement;
39
- /**
40
- * Is the parent dropdown disabled
41
- */
42
- disabled?: boolean;
43
- }
44
- /**
45
- * TagsContainer component to display tags in limited space when children can't fit space it displays counter
46
- *
47
- * @param {TagsContainerProps} props - The props for the TagContainer
48
- * @returns {ReactElement} TagsContainer
49
- */
50
- export declare const TagsContainer: ({ items, width, itemsGap, postFix, preFix, disabled, }: TagsContainerProps) => import("react/jsx-runtime").JSX.Element;
51
- export {};
@@ -1,20 +0,0 @@
1
- import { RefObject } from "react";
2
- import { GroupBase, StylesConfig } from "react-select";
3
- import { FormComponentSizes } from "../../types";
4
- /**
5
- * @template IsMulti
6
- * @template Group
7
- * @param {RefObject<HTMLDivElement | null>} refContainer react ref to container element
8
- * @param {number | undefined} maxSelectedDisplayCount a number of max display count
9
- * @param {StylesConfig<Option, IsMulti, Group> | undefined} styles a optional object to override styles of react-select
10
- * @returns {StylesConfig<Option, boolean>} styles to override in select
11
- */
12
- export declare const useCustomStyles: <Option, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>>({ refContainer, maxSelectedDisplayCount, styles, disabled, fieldSize, }: {
13
- refContainer: RefObject<HTMLDivElement | null>;
14
- maxSelectedDisplayCount: number | undefined;
15
- styles: StylesConfig<Option, IsMulti, Group> | undefined;
16
- disabled: boolean | undefined;
17
- fieldSize: FormComponentSizes;
18
- }) => {
19
- customStyles: StylesConfig<Option, IsMulti, Group>;
20
- };