@trackunit/react-form-components 0.0.305 → 0.0.308

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "0.0.305",
3
+ "version": "0.0.308",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -1,38 +1,39 @@
1
- import React from "react";
1
+ /// <reference types="react" />
2
2
  import { GroupBase } from "react-select";
3
3
  import { SelectProps } from "./useSelect";
4
- interface CreateableSelectProps<Option, IsAsync extends boolean = false, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>> extends SelectProps<Option, IsAsync, IsMulti, Group> {
5
- /**
6
- * To hide the label.
7
- */
8
- hideLabel?: boolean;
9
- /**
10
- * Description for the select component.
11
- */
12
- description?: string;
13
- /**
14
- * Whether the component is invalid.
15
- */
16
- isInvalid?: boolean;
17
- /**
18
- * Info of the select component.
19
- */
20
- info?: React.ReactNode;
21
- /**
22
- * Error of the select component.
23
- */
24
- error?: React.ReactNode;
25
- /**
26
- * Size of the component.
27
- */
28
- size?: SelectSize;
4
+ export interface CreatableSelectOption<TValue extends string | number> {
5
+ label: string;
6
+ value: TValue;
7
+ disabled?: boolean;
29
8
  }
30
- export type SelectSize = "small" | "default";
9
+ export type CreatableSelectProps = {
10
+ allowCreateWhileLoading?: boolean;
11
+ onCreateOption?: (inputValue: string) => void;
12
+ };
31
13
  /**
32
- * The CreatableSelect component.
14
+ * CreatableSelects are input components used to choose a value from a set.
33
15
  *
34
- * @param {CreateableSelectProps} props - The props for the CreatableSelect component
16
+ * @param {CreatableSelectProps} props - The props for the CreatableSelect component
35
17
  * @returns {JSX.Element} CreatableSelect component
36
18
  */
37
- export declare const CreatableSelect: <Option, IsAsync extends boolean = false, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>>(props: CreateableSelectProps<Option, IsAsync, IsMulti, Group>) => JSX.Element;
38
- export {};
19
+ export declare const CreatableSelect: {
20
+ <Option, IsAsync extends boolean = false, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>>(props: import("dist/libs/react/components/src").CommonProps & Omit<import("react-select/dist/declarations/src/Select").PublicBaseSelectProps<Option, IsMulti, Group>, "inputValue" | "menuIsOpen" | "onChange" | "onInputChange" | "onMenuOpen" | "onMenuClose" | "value"> & Partial<import("react-select/dist/declarations/src/Select").PublicBaseSelectProps<Option, IsMulti, Group>> & import("react-select/dist/declarations/src/useStateManager").StateManagerAdditionalProps<Option> & {
21
+ prefix?: JSX.Element | undefined;
22
+ placeholder?: string | undefined;
23
+ disabled?: boolean | undefined;
24
+ readOnly?: boolean | undefined;
25
+ id?: string | undefined;
26
+ async?: import("./useSelect").AsyncSelect<Option, Group> | undefined;
27
+ dropdownIcon?: JSX.Element | undefined;
28
+ label?: string | undefined;
29
+ maxMenuHeight?: number | undefined;
30
+ hasError?: boolean | undefined;
31
+ isLoading?: boolean | undefined;
32
+ maxSelectedDisplayCount?: number | undefined;
33
+ onMenuOpen?: (() => void) | undefined;
34
+ isClearable?: boolean | undefined;
35
+ isSearchable?: boolean | undefined;
36
+ isAsync?: IsAsync | undefined;
37
+ } & CreatableSelectProps): JSX.Element;
38
+ displayName: string;
39
+ };
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import { GroupBase } from "react-select";
3
3
  import { SelectProps } from "./useSelect";
4
- export interface SelectOption<T extends string | number> {
4
+ export interface SelectOption<TValue extends string | number> {
5
5
  label: string;
6
- value: T;
6
+ value: TValue;
7
7
  disabled?: boolean;
8
8
  }
9
9
  /**
@@ -7,7 +7,7 @@ export interface AsyncSelect<Option, Group extends GroupBase<Option> = GroupBase
7
7
  defaultOptions: OptionsOrGroups<Option, Group> | undefined;
8
8
  cacheOptions: boolean;
9
9
  }
10
- export interface SelectProps<Option, IsAsync extends boolean, IsMulti extends boolean, GroupType extends GroupBase<Option>> extends CommonProps, Props<Option, IsMulti, GroupType> {
10
+ export type SelectProps<Option, IsAsync extends boolean, IsMulti extends boolean, GroupType extends GroupBase<Option>> = CommonProps & Props<Option, IsMulti, GroupType> & {
11
11
  /**
12
12
  * An React element to render before the text in the select.
13
13
  * This is typically used to render an icon.
@@ -113,7 +113,7 @@ export interface SelectProps<Option, IsAsync extends boolean, IsMulti extends bo
113
113
  * @memberof SelectProps
114
114
  */
115
115
  isAsync?: IsAsync;
116
- }
116
+ };
117
117
  interface IUseSelect<Option, IsMulti extends boolean = false, Group extends GroupBase<Option> = GroupBase<Option>> {
118
118
  customStyles: StylesConfig<Option, IsMulti, Group>;
119
119
  customComponents: Partial<SelectComponents<Option, IsMulti, Group>>;
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { CreatableSelectProps } from "../Select/CreatableSelect";
3
+ import { BaseOptionType, SelectFieldProps } from "./FormFieldSelectAdapter";
4
+ /**
5
+ * The CreatableSelectField component is a CreatableSelect component wrapped in the FromGroup component.
6
+ *
7
+ * This means that it can easily be added to any form alongside other Field components.
8
+ *
9
+ * This is done to make the field compatible with the React-hook-form library.
10
+ *
11
+ * @param {SelectFieldProps & CreatableSelectProps} props - The props for the CreatableSelectField component
12
+ * @returns {JSX.Element} CreatableSelectField component
13
+ */
14
+ export declare const CreatableSelectField: ({ allowCreateWhileLoading, onCreateOption, ...props }: SelectFieldProps<BaseOptionType> & CreatableSelectProps) => JSX.Element;
@@ -0,0 +1,44 @@
1
+ /// <reference types="react" />
2
+ import { CommonProps } from "@trackunit/react-components";
3
+ import { MappedOmit } from "@trackunit/shared-utils";
4
+ import { GroupBase } from "react-select";
5
+ import { FormGroupProps } from "../FormGroup/FormGroup";
6
+ import { SelectProps } from "../Select/useSelect";
7
+ export type BaseOptionType = {
8
+ label: string;
9
+ value: string | number;
10
+ };
11
+ type SelectExposedProps<TOptionType extends BaseOptionType> = MappedOmit<SelectProps<TOptionType, false, false, GroupBase<TOptionType>>, "value" | "label" | "onChange" | "defaultValue" | "onBlur" | "options">;
12
+ type FormGroupExposedProps = Pick<FormGroupProps, "label" | "tip" | "helpText" | "helpAddon" | "isInvalid">;
13
+ export type SelectFieldProps<TOptionType extends BaseOptionType> = CommonProps & FormGroupExposedProps & SelectExposedProps<TOptionType> & {
14
+ onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
15
+ /**
16
+ * The options available for the SelectField.
17
+ */
18
+ options: TOptionType[];
19
+ /**
20
+ * The selected value of the SelectField.
21
+ */
22
+ value?: TOptionType["value"];
23
+ /**
24
+ * The default selected value of the SelectField.
25
+ */
26
+ defaultValue?: TOptionType["value"];
27
+ /**
28
+ * The onChange handler for the SelectField.
29
+ */
30
+ onChange?: (event: {
31
+ target: {
32
+ value?: TOptionType["value"];
33
+ };
34
+ }) => void;
35
+ /**
36
+ * If a value is set, the field is rendered in its invalid state.
37
+ */
38
+ errorMessage?: string;
39
+ };
40
+ interface FormFieldSelectAdapterProps<TOptionType extends BaseOptionType, IsAsync extends boolean = false, IsMulti extends boolean = false> extends SelectFieldProps<TOptionType> {
41
+ children: (props: SelectProps<TOptionType, IsAsync, IsMulti, GroupBase<TOptionType>>) => JSX.Element;
42
+ }
43
+ export declare const FormFieldSelectAdapter: import("react").ForwardRefExoticComponent<FormFieldSelectAdapterProps<BaseOptionType, false, false> & import("react").RefAttributes<HTMLSelectElement>>;
44
+ export {};
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import { BaseOptionType, SelectFieldProps } from "./FormFieldSelectAdapter";
3
+ /**
4
+ * The SelectField component is a Select component wrapped in the FromGroup component.
5
+ *
6
+ * This means that it can easily be added to any form alongside other Field components.
7
+ *
8
+ * This is done to make the field compatible with the React-hook-form library.
9
+ *
10
+ * @param {SelectFieldProps} props - The props for the SelectField component
11
+ * @returns {JSX.Element} SelectField component
12
+ */
13
+ export declare const SelectField: (props: SelectFieldProps<BaseOptionType>) => JSX.Element;
package/src/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from "./SelectField/SelectField";
2
1
  export * from "./components/ActionButton";
3
2
  export * from "./components/BaseInput";
4
3
  export * from "./components/Checkbox";
@@ -23,6 +22,8 @@ export * from "./components/Schedule/Schedule";
23
22
  export * from "./components/Schedule/ScheduleParser";
24
23
  export * from "./components/Search";
25
24
  export * from "./components/Select";
25
+ export * from "./components/SelectField/CreatableSelectField";
26
+ export * from "./components/SelectField/SelectField";
26
27
  export * from "./components/TextArea";
27
28
  export * from "./components/TextAreaField";
28
29
  export * from "./components/TextField";
@@ -1,50 +0,0 @@
1
- /// <reference types="react" />
2
- import { CommonProps } from "@trackunit/react-components";
3
- import { GroupBase } from "react-select";
4
- import { FormGroupProps } from "../components/FormGroup/FormGroup";
5
- import { SelectProps } from "../components/Select/useSelect";
6
- export type BaseOptionType = {
7
- label: string;
8
- value: string | number;
9
- };
10
- type SelectExposedProps<TOptionType extends BaseOptionType> = Omit<SelectProps<TOptionType, false, false, GroupBase<TOptionType>>, "value" | "label" | "onChange" | "defaultValue" | "onBlur">;
11
- type FormGroupExposedProps = Pick<FormGroupProps, "label" | "tip" | "helpText" | "helpAddon" | "isInvalid">;
12
- export interface SelectFieldProps<TOptionType extends BaseOptionType> extends CommonProps, FormGroupExposedProps, SelectExposedProps<TOptionType> {
13
- onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
14
- /**
15
- * The options available for the SelectField.
16
- */
17
- options: TOptionType[];
18
- /**
19
- * The selected value of the SelectField.
20
- */
21
- value?: TOptionType["value"];
22
- /**
23
- * The default selected value of the SelectField.
24
- */
25
- defaultValue?: TOptionType["value"];
26
- /**
27
- * The onChange handler for the SelectField.
28
- */
29
- onChange?: (event: {
30
- target: {
31
- value?: TOptionType["value"];
32
- };
33
- }) => void;
34
- /**
35
- * If a value is set, the field is rendered in its invalid state.
36
- */
37
- errorMessage?: string;
38
- }
39
- /**
40
- * The SelectField component is a Select component wrapped in the FromGroup component.
41
- *
42
- * This means that it can easily be added to any form alongside other Field components.
43
- *
44
- * This is done to make the field compatible with the React-hook-form library.
45
- *
46
- * @param {SelectFieldProps} props - The props for the SelectField component
47
- * @returns {JSX.Element} SelectField component
48
- */
49
- export declare const SelectField: import("react").ForwardRefExoticComponent<SelectFieldProps<BaseOptionType> & import("react").RefAttributes<HTMLSelectElement>>;
50
- export {};