@itaptec/form_components 0.0.1-beta.31

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/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # README #
2
+
3
+ This README would normally document whatever steps are necessary to get your application up and running.
4
+
5
+ ### What is this repository for? ###
6
+
7
+ * Quick summary
8
+ * Version
9
+ * [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
10
+
11
+ ### How do I get set up? ###
12
+
13
+ * Summary of set up
14
+ * Configuration
15
+ * Dependencies
16
+ * Database configuration
17
+ * How to run tests
18
+ * Deployment instructions
19
+
20
+ ### Contribution guidelines ###
21
+
22
+ * Writing tests
23
+ * Code review
24
+ * Other guidelines
25
+
26
+ ### Who do I talk to? ###
27
+
28
+ * Repo owner or admin
29
+ * Other community or team contact
package/dist/index.css ADDED
@@ -0,0 +1,16 @@
1
+ /* src/components/forms/date-pickers/styles/ControlledDateRangePicker.css */
2
+ @media (max-width: 600px) {
3
+ .rdrMonths {
4
+ flex-direction: column;
5
+ }
6
+ .rdrMonth {
7
+ width: 100%;
8
+ }
9
+ .rdrDateRangePickerWrapper {
10
+ flex-direction: column-reverse;
11
+ }
12
+ .rdrDefinedRangesWrapper {
13
+ width: 100% !important;
14
+ }
15
+ }
16
+ /*# sourceMappingURL=index.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/forms/date-pickers/styles/ControlledDateRangePicker.css"],"sourcesContent":["@media (max-width: 600px) {\r\n .rdrMonths {\r\n flex-direction: column;\r\n }\r\n\r\n .rdrMonth {\r\n width: 100%;\r\n }\r\n\r\n .rdrDateRangePickerWrapper {\r\n flex-direction: column-reverse;\r\n }\r\n\r\n .rdrDefinedRangesWrapper {\r\n width: 100% !important;\r\n }\r\n}"],"mappings":";AAAA,QAAO,WAAY;AACf,GAAC;AACG,oBAAgB;AACpB;AAEA,GAAC;AACG,WAAO;AACX;AAEA,GAAC;AACG,oBAAgB;AACpB;AAEA,GAAC;AACG,WAAO;AACX;AACJ;","names":[]}
@@ -0,0 +1,163 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ButtonProps, ButtonGroupProps, PopoverProps, MenuListProps, StandardTextFieldProps, AutocompleteProps, TextFieldProps, ChipProps, ToggleButtonProps, ToggleButtonGroupProps } from '@mui/material';
3
+ import React$1, { ComponentType } from 'react';
4
+ import { FieldValues, ControllerProps, Control, Path } from 'react-hook-form';
5
+ import { useIMask } from 'react-imask';
6
+ import { DateRangeProps } from 'react-date-range';
7
+
8
+ interface ItaptecButtonProps<TPromise = void> extends Omit<ButtonProps, "onClick"> {
9
+ onClick?: ((event: React$1.MouseEvent) => void) | ((event: React$1.MouseEvent) => Promise<TPromise>);
10
+ }
11
+ declare function ItaptecButton({ startIcon, color, onClick, ...rest }: ItaptecButtonProps): react_jsx_runtime.JSX.Element;
12
+
13
+ type SelectionOption = {
14
+ value: number;
15
+ label: string;
16
+ icon?: React.ReactNode;
17
+ };
18
+
19
+ /**
20
+ * Props for the SplitButton component.
21
+ * @template TOption - The type of the options that the SplitButton can display.
22
+ */
23
+ type SplitButtonProps<TOption extends SelectionOption> = {
24
+ /**
25
+ * Can be:
26
+ * - An array of options.
27
+ * - A function that returns an array of options.
28
+ * - A function that returns a Promise that resolves to an array of options.
29
+ */
30
+ loadOptions: (() => Promise<TOption[]>) | (() => TOption[]) | TOption[];
31
+ /**
32
+ * A function that is called when an option is selected, or a Promise that resolves when the function is done.
33
+ * @param selected - The selected option.
34
+ */
35
+ onClick: ((event: React$1.MouseEvent, selected: TOption) => void) | ((event: React$1.MouseEvent, selected: TOption) => Promise<void>);
36
+ ButtonGroupProps?: Omit<ButtonGroupProps, "onClick">;
37
+ /**
38
+ * Props del popover.
39
+ *
40
+ * Por defecto el menú de opciones se despliega respecto al botón de dropdown,
41
+ * alineado a la derecha, hacia abajo. Se puede jugar con esto en:
42
+ * https://mui.com/material-ui/react-popover/#anchor-playground
43
+ */
44
+ PopoverProps?: Omit<PopoverProps, "ref" | "anchorEl" | "open" | "onClose">;
45
+ MenuListProps?: MenuListProps;
46
+ };
47
+ declare function SplitButton<TOption extends SelectionOption>(props: SplitButtonProps<TOption>): react_jsx_runtime.JSX.Element;
48
+
49
+ type ControlledTextFieldProps<TForm extends FieldValues> = Required<Pick<ControllerProps<TForm>, "control" | "name">> & StandardTextFieldProps & {
50
+ ControllerProps?: Omit<ControllerProps<TForm>, "control" | "name" | "render">;
51
+ mask?: Parameters<typeof useIMask>["0"];
52
+ debounce?: boolean;
53
+ debounceTime?: number;
54
+ };
55
+ declare function ControlledTextField<TForm extends FieldValues = FieldValues>({ control, name, mask, ControllerProps, debounce, debounceTime, ...rest }: ControlledTextFieldProps<TForm>): react_jsx_runtime.JSX.Element;
56
+
57
+ /**
58
+ * ControlledDateRangePickerProps interface
59
+ *
60
+ * @template T - A generic parameter that extends FieldValues from react-hook-form
61
+ *
62
+ * @property {Control<T>} control - The control object from react-hook-form
63
+ * @property {Path<T>} startDateName - The field name for the start date
64
+ * @property {Path<T>} endDateName - The field name for the end date
65
+ * @property {string} [label] - An optional label for the date range picker
66
+ * @property {(date: Date | string | null) => string} [dateFormatter] - An optional function to format the date. If provided, it will be used instead of the default formatter (dd/MM/yyyy)
67
+ *
68
+ */
69
+ interface ControlledDateRangePickerProps<T extends FieldValues> extends DateRangeProps {
70
+ control: Control<T>;
71
+ startDateName: Path<T>;
72
+ endDateName: Path<T>;
73
+ label?: string;
74
+ dateFormatter?: (date: Date | string | null) => string;
75
+ }
76
+ /**
77
+ * ControlledDateRangePicker component to be used in react-hook-form forms
78
+ *
79
+ * @template T - A generic parameter that extends FieldValues from react-hook-form
80
+ *
81
+ * @param {ControlledDateRangePickerProps<T>} props - The props that define the ControlledDateRangePicker component
82
+ */
83
+ declare const ControlledDateRangePicker: <T extends FieldValues>({ control, startDateName, endDateName, label, dateFormatter }: ControlledDateRangePickerProps<T>) => react_jsx_runtime.JSX.Element;
84
+
85
+ /**
86
+ * Props for the SplitButton component.
87
+ * @template TOption - The type of the options.
88
+ */
89
+ type ControlledSelectProps<TOption extends SelectionOption, TForm extends FieldValues> = Required<Pick<ControllerProps<TForm>, "control" | "name">> & Omit<AutocompleteProps<TOption, false, undefined, false>, "options" | "renderInput"> & {
90
+ /**
91
+ * Can be:
92
+ * - An array of options.
93
+ * - A function that returns an array of options.
94
+ * - A function that returns a Promise that resolves to an array of options.
95
+ */
96
+ getOptions: TOption[] | (() => TOption[]) | (() => Promise<TOption[]>);
97
+ searchable?: boolean;
98
+ } & Pick<TextFieldProps, "required" | "label" | "variant" | "size">;
99
+ declare function ControlledSelect<TOption extends SelectionOption, TForm extends FieldValues>(props: ControlledSelectProps<TOption, TForm>): react_jsx_runtime.JSX.Element;
100
+
101
+ /**
102
+ * Props for the SplitButton component.
103
+ * @template TOption - The type of the options.
104
+ */
105
+ type ControlledMultiselectProps<TOption extends SelectionOption, TForm extends FieldValues> = Required<Pick<ControllerProps<TForm>, "control" | "name">> & Omit<AutocompleteProps<TOption, true, undefined, false>, "options" | "renderInput"> & {
106
+ /**
107
+ * Can be:
108
+ * - An array of options.
109
+ * - A function that returns an array of options.
110
+ * - A function that returns a Promise that resolves to an array of options.
111
+ */
112
+ getOptions: TOption[] | (() => TOption[]) | (() => Promise<TOption[]>);
113
+ TagComponent?: ComponentType<ChipProps & {
114
+ value: TOption;
115
+ }>;
116
+ searchable?: boolean;
117
+ } & Pick<TextFieldProps, "required" | "label" | "variant" | "size">;
118
+ declare function ControlledMultiselect<TOption extends SelectionOption, TForm extends FieldValues>(props: ControlledMultiselectProps<TOption, TForm>): react_jsx_runtime.JSX.Element;
119
+
120
+ type ItecToggleButtonGroupProps<TOption extends SelectionOption> = {
121
+ options: TOption[];
122
+ onChange: (value: number | null) => void;
123
+ renderOption?: (value: TOption) => React$1.ReactNode;
124
+ toggleButtonProps?: Omit<ToggleButtonProps, "value" | "key"> | ((value: TOption) => Omit<ToggleButtonProps, "value" | "key">);
125
+ value: number | undefined;
126
+ } & Omit<ToggleButtonGroupProps, "onChange">;
127
+ declare function ItecToggleButtonGroup<TOption extends SelectionOption>(props: ItecToggleButtonGroupProps<TOption>): react_jsx_runtime.JSX.Element;
128
+
129
+ type ControlledToggleButtonGroupProps<TOption extends SelectionOption, TForm extends FieldValues> = Required<Pick<ControllerProps<TForm>, "control" | "name">> & {
130
+ /**
131
+ * TODO: async options
132
+ */
133
+ /**
134
+ * At least one value must be selected at all times.
135
+ */
136
+ enforceValueSet?: boolean;
137
+ helperText?: string;
138
+ label?: string;
139
+ } & Omit<ItecToggleButtonGroupProps<TOption>, "onChange" | "value">;
140
+ declare function ControlledToggleButtonGroup<TOption extends SelectionOption, TForm extends FieldValues>(props: ControlledToggleButtonGroupProps<TOption, TForm>): react_jsx_runtime.JSX.Element;
141
+
142
+ type ItecToggleButtonGroupMultipleProps<TOption extends SelectionOption> = {
143
+ options: TOption[];
144
+ onChange: (value: number[]) => void;
145
+ renderOption?: (value: TOption) => React$1.ReactNode;
146
+ toggleButtonProps?: Omit<ToggleButtonProps, "value" | "key"> | ((value: TOption) => Omit<ToggleButtonProps, "value" | "key">);
147
+ value: number[] | undefined;
148
+ } & Omit<ToggleButtonGroupProps, "onChange">;
149
+
150
+ type ControlledToggleButtonGroupMultipleProps<TOption extends SelectionOption, TForm extends FieldValues> = Required<Pick<ControllerProps<TForm>, "control" | "name">> & {
151
+ /**
152
+ * TODO: async options
153
+ */
154
+ /**
155
+ * At least one value must be selected at all times.
156
+ */
157
+ enforceValueSet?: boolean;
158
+ helperText?: string;
159
+ label?: string;
160
+ } & Omit<ItecToggleButtonGroupMultipleProps<TOption>, "onChange" | "value">;
161
+ declare function ControlledToggleButtonGroupMultiple<TOption extends SelectionOption, TForm extends FieldValues>(props: ControlledToggleButtonGroupMultipleProps<TOption, TForm>): react_jsx_runtime.JSX.Element;
162
+
163
+ export { ItaptecButton as Button, type ItaptecButtonProps as ButtonProps, ControlledDateRangePicker, type ControlledDateRangePickerProps, ItecToggleButtonGroup, type ItecToggleButtonGroupProps, ControlledMultiselect as Multiselect, type ControlledMultiselectProps as MultiselectProps, ControlledSelect as Select, type ControlledSelectProps as SelectProps, type SelectionOption, SplitButton, type SplitButtonProps, ControlledTextField as TextField, type ControlledTextFieldProps as TextFieldProps, ControlledToggleButtonGroup as ToggleButtonGroup, ControlledToggleButtonGroupMultiple as ToggleButtonGroupMultiple, type ControlledToggleButtonGroupMultipleProps as ToggleButtonGroupMultipleProps, type ControlledToggleButtonGroupProps as ToggleButtonGroupProps };
@@ -0,0 +1,163 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ButtonProps, ButtonGroupProps, PopoverProps, MenuListProps, StandardTextFieldProps, AutocompleteProps, TextFieldProps, ChipProps, ToggleButtonProps, ToggleButtonGroupProps } from '@mui/material';
3
+ import React$1, { ComponentType } from 'react';
4
+ import { FieldValues, ControllerProps, Control, Path } from 'react-hook-form';
5
+ import { useIMask } from 'react-imask';
6
+ import { DateRangeProps } from 'react-date-range';
7
+
8
+ interface ItaptecButtonProps<TPromise = void> extends Omit<ButtonProps, "onClick"> {
9
+ onClick?: ((event: React$1.MouseEvent) => void) | ((event: React$1.MouseEvent) => Promise<TPromise>);
10
+ }
11
+ declare function ItaptecButton({ startIcon, color, onClick, ...rest }: ItaptecButtonProps): react_jsx_runtime.JSX.Element;
12
+
13
+ type SelectionOption = {
14
+ value: number;
15
+ label: string;
16
+ icon?: React.ReactNode;
17
+ };
18
+
19
+ /**
20
+ * Props for the SplitButton component.
21
+ * @template TOption - The type of the options that the SplitButton can display.
22
+ */
23
+ type SplitButtonProps<TOption extends SelectionOption> = {
24
+ /**
25
+ * Can be:
26
+ * - An array of options.
27
+ * - A function that returns an array of options.
28
+ * - A function that returns a Promise that resolves to an array of options.
29
+ */
30
+ loadOptions: (() => Promise<TOption[]>) | (() => TOption[]) | TOption[];
31
+ /**
32
+ * A function that is called when an option is selected, or a Promise that resolves when the function is done.
33
+ * @param selected - The selected option.
34
+ */
35
+ onClick: ((event: React$1.MouseEvent, selected: TOption) => void) | ((event: React$1.MouseEvent, selected: TOption) => Promise<void>);
36
+ ButtonGroupProps?: Omit<ButtonGroupProps, "onClick">;
37
+ /**
38
+ * Props del popover.
39
+ *
40
+ * Por defecto el menú de opciones se despliega respecto al botón de dropdown,
41
+ * alineado a la derecha, hacia abajo. Se puede jugar con esto en:
42
+ * https://mui.com/material-ui/react-popover/#anchor-playground
43
+ */
44
+ PopoverProps?: Omit<PopoverProps, "ref" | "anchorEl" | "open" | "onClose">;
45
+ MenuListProps?: MenuListProps;
46
+ };
47
+ declare function SplitButton<TOption extends SelectionOption>(props: SplitButtonProps<TOption>): react_jsx_runtime.JSX.Element;
48
+
49
+ type ControlledTextFieldProps<TForm extends FieldValues> = Required<Pick<ControllerProps<TForm>, "control" | "name">> & StandardTextFieldProps & {
50
+ ControllerProps?: Omit<ControllerProps<TForm>, "control" | "name" | "render">;
51
+ mask?: Parameters<typeof useIMask>["0"];
52
+ debounce?: boolean;
53
+ debounceTime?: number;
54
+ };
55
+ declare function ControlledTextField<TForm extends FieldValues = FieldValues>({ control, name, mask, ControllerProps, debounce, debounceTime, ...rest }: ControlledTextFieldProps<TForm>): react_jsx_runtime.JSX.Element;
56
+
57
+ /**
58
+ * ControlledDateRangePickerProps interface
59
+ *
60
+ * @template T - A generic parameter that extends FieldValues from react-hook-form
61
+ *
62
+ * @property {Control<T>} control - The control object from react-hook-form
63
+ * @property {Path<T>} startDateName - The field name for the start date
64
+ * @property {Path<T>} endDateName - The field name for the end date
65
+ * @property {string} [label] - An optional label for the date range picker
66
+ * @property {(date: Date | string | null) => string} [dateFormatter] - An optional function to format the date. If provided, it will be used instead of the default formatter (dd/MM/yyyy)
67
+ *
68
+ */
69
+ interface ControlledDateRangePickerProps<T extends FieldValues> extends DateRangeProps {
70
+ control: Control<T>;
71
+ startDateName: Path<T>;
72
+ endDateName: Path<T>;
73
+ label?: string;
74
+ dateFormatter?: (date: Date | string | null) => string;
75
+ }
76
+ /**
77
+ * ControlledDateRangePicker component to be used in react-hook-form forms
78
+ *
79
+ * @template T - A generic parameter that extends FieldValues from react-hook-form
80
+ *
81
+ * @param {ControlledDateRangePickerProps<T>} props - The props that define the ControlledDateRangePicker component
82
+ */
83
+ declare const ControlledDateRangePicker: <T extends FieldValues>({ control, startDateName, endDateName, label, dateFormatter }: ControlledDateRangePickerProps<T>) => react_jsx_runtime.JSX.Element;
84
+
85
+ /**
86
+ * Props for the SplitButton component.
87
+ * @template TOption - The type of the options.
88
+ */
89
+ type ControlledSelectProps<TOption extends SelectionOption, TForm extends FieldValues> = Required<Pick<ControllerProps<TForm>, "control" | "name">> & Omit<AutocompleteProps<TOption, false, undefined, false>, "options" | "renderInput"> & {
90
+ /**
91
+ * Can be:
92
+ * - An array of options.
93
+ * - A function that returns an array of options.
94
+ * - A function that returns a Promise that resolves to an array of options.
95
+ */
96
+ getOptions: TOption[] | (() => TOption[]) | (() => Promise<TOption[]>);
97
+ searchable?: boolean;
98
+ } & Pick<TextFieldProps, "required" | "label" | "variant" | "size">;
99
+ declare function ControlledSelect<TOption extends SelectionOption, TForm extends FieldValues>(props: ControlledSelectProps<TOption, TForm>): react_jsx_runtime.JSX.Element;
100
+
101
+ /**
102
+ * Props for the SplitButton component.
103
+ * @template TOption - The type of the options.
104
+ */
105
+ type ControlledMultiselectProps<TOption extends SelectionOption, TForm extends FieldValues> = Required<Pick<ControllerProps<TForm>, "control" | "name">> & Omit<AutocompleteProps<TOption, true, undefined, false>, "options" | "renderInput"> & {
106
+ /**
107
+ * Can be:
108
+ * - An array of options.
109
+ * - A function that returns an array of options.
110
+ * - A function that returns a Promise that resolves to an array of options.
111
+ */
112
+ getOptions: TOption[] | (() => TOption[]) | (() => Promise<TOption[]>);
113
+ TagComponent?: ComponentType<ChipProps & {
114
+ value: TOption;
115
+ }>;
116
+ searchable?: boolean;
117
+ } & Pick<TextFieldProps, "required" | "label" | "variant" | "size">;
118
+ declare function ControlledMultiselect<TOption extends SelectionOption, TForm extends FieldValues>(props: ControlledMultiselectProps<TOption, TForm>): react_jsx_runtime.JSX.Element;
119
+
120
+ type ItecToggleButtonGroupProps<TOption extends SelectionOption> = {
121
+ options: TOption[];
122
+ onChange: (value: number | null) => void;
123
+ renderOption?: (value: TOption) => React$1.ReactNode;
124
+ toggleButtonProps?: Omit<ToggleButtonProps, "value" | "key"> | ((value: TOption) => Omit<ToggleButtonProps, "value" | "key">);
125
+ value: number | undefined;
126
+ } & Omit<ToggleButtonGroupProps, "onChange">;
127
+ declare function ItecToggleButtonGroup<TOption extends SelectionOption>(props: ItecToggleButtonGroupProps<TOption>): react_jsx_runtime.JSX.Element;
128
+
129
+ type ControlledToggleButtonGroupProps<TOption extends SelectionOption, TForm extends FieldValues> = Required<Pick<ControllerProps<TForm>, "control" | "name">> & {
130
+ /**
131
+ * TODO: async options
132
+ */
133
+ /**
134
+ * At least one value must be selected at all times.
135
+ */
136
+ enforceValueSet?: boolean;
137
+ helperText?: string;
138
+ label?: string;
139
+ } & Omit<ItecToggleButtonGroupProps<TOption>, "onChange" | "value">;
140
+ declare function ControlledToggleButtonGroup<TOption extends SelectionOption, TForm extends FieldValues>(props: ControlledToggleButtonGroupProps<TOption, TForm>): react_jsx_runtime.JSX.Element;
141
+
142
+ type ItecToggleButtonGroupMultipleProps<TOption extends SelectionOption> = {
143
+ options: TOption[];
144
+ onChange: (value: number[]) => void;
145
+ renderOption?: (value: TOption) => React$1.ReactNode;
146
+ toggleButtonProps?: Omit<ToggleButtonProps, "value" | "key"> | ((value: TOption) => Omit<ToggleButtonProps, "value" | "key">);
147
+ value: number[] | undefined;
148
+ } & Omit<ToggleButtonGroupProps, "onChange">;
149
+
150
+ type ControlledToggleButtonGroupMultipleProps<TOption extends SelectionOption, TForm extends FieldValues> = Required<Pick<ControllerProps<TForm>, "control" | "name">> & {
151
+ /**
152
+ * TODO: async options
153
+ */
154
+ /**
155
+ * At least one value must be selected at all times.
156
+ */
157
+ enforceValueSet?: boolean;
158
+ helperText?: string;
159
+ label?: string;
160
+ } & Omit<ItecToggleButtonGroupMultipleProps<TOption>, "onChange" | "value">;
161
+ declare function ControlledToggleButtonGroupMultiple<TOption extends SelectionOption, TForm extends FieldValues>(props: ControlledToggleButtonGroupMultipleProps<TOption, TForm>): react_jsx_runtime.JSX.Element;
162
+
163
+ export { ItaptecButton as Button, type ItaptecButtonProps as ButtonProps, ControlledDateRangePicker, type ControlledDateRangePickerProps, ItecToggleButtonGroup, type ItecToggleButtonGroupProps, ControlledMultiselect as Multiselect, type ControlledMultiselectProps as MultiselectProps, ControlledSelect as Select, type ControlledSelectProps as SelectProps, type SelectionOption, SplitButton, type SplitButtonProps, ControlledTextField as TextField, type ControlledTextFieldProps as TextFieldProps, ControlledToggleButtonGroup as ToggleButtonGroup, ControlledToggleButtonGroupMultiple as ToggleButtonGroupMultiple, type ControlledToggleButtonGroupMultipleProps as ToggleButtonGroupMultipleProps, type ControlledToggleButtonGroupProps as ToggleButtonGroupProps };