@takaro/lib-components 0.0.1 → 0.0.5
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 +5 -6
- package/src/components/actions/Button/index.tsx +68 -70
- package/src/components/actions/Button/style.ts +1 -1
- package/src/components/actions/ContextMenu/Group.tsx +1 -1
- package/src/components/actions/ContextMenu/MenuItem.tsx +4 -1
- package/src/components/actions/ContextMenu/index.tsx +11 -12
- package/src/components/actions/Dropdown/DropdownMenu.tsx +5 -2
- package/src/components/actions/Dropdown/DropdownTrigger.tsx +55 -57
- package/src/components/actions/Dropdown/useDropdown.tsx +1 -1
- package/src/components/actions/IconButton/index.tsx +11 -10
- package/src/components/actions/IconButton/style.ts +5 -2
- package/src/components/actions/ToggleButton/ToggleButton.tsx +26 -28
- package/src/components/actions/ToggleButton/ToggleButtonGroup.tsx +3 -8
- package/src/components/actions/ToggleButton/style.ts +5 -7
- package/src/components/charts/AreaChart/index.tsx +7 -8
- package/src/components/charts/BarChart/index.tsx +4 -4
- package/src/components/charts/GeoMercator/index.tsx +1 -1
- package/src/components/charts/Heatmap/index.tsx +3 -4
- package/src/components/charts/LineChart/index.tsx +3 -3
- package/src/components/charts/PieChart/index.tsx +1 -1
- package/src/components/charts/RadarChart/index.tsx +1 -1
- package/src/components/charts/RadialBarChart/index.tsx +1 -1
- package/src/components/charts/index.tsx +3 -0
- package/src/components/data/Avatar/index.tsx +7 -3
- package/src/components/data/Avatar/style.ts +2 -2
- package/src/components/data/Chip/index.tsx +39 -41
- package/src/components/data/Chip/style.ts +3 -2
- package/src/components/data/Console/Console.tsx +14 -12
- package/src/components/data/CopyId/index.tsx +3 -2
- package/src/components/data/Drawer/Drawer.stories.tsx +3 -5
- package/src/components/data/Drawer/DrawerContent.tsx +1 -1
- package/src/components/data/Drawer/DrawerHeading.tsx +30 -29
- package/src/components/data/Drawer/useDrawer.tsx +1 -1
- package/src/components/data/InfiniteScroll/index.tsx +37 -36
- package/src/components/data/Table/Table.stories.tsx +6 -2
- package/src/components/data/Table/index.tsx +63 -44
- package/src/components/data/Table/style.ts +3 -2
- package/src/components/data/Table/subcomponents/ColumnHeader/ColumnSettings.tsx +22 -19
- package/src/components/data/Table/subcomponents/ColumnHeader/index.tsx +3 -3
- package/src/components/data/Table/subcomponents/ColumnHeader/style.ts +2 -1
- package/src/components/data/Table/subcomponents/Filter/field.tsx +2 -3
- package/src/components/data/Table/subcomponents/Filter/index.tsx +6 -10
- package/src/components/data/Table/subcomponents/Pagination/{index.tsx → PagePicker.tsx} +7 -7
- package/src/components/data/Table/subcomponents/Pagination/PageSizeSelect.tsx +37 -0
- package/src/components/data/Table/subcomponents/Pagination/style.ts +1 -1
- package/src/components/dialogs/Dialog/Dialog.stories.tsx +1 -2
- package/src/components/dialogs/Dialog/DialogBody.tsx +18 -17
- package/src/components/dialogs/Dialog/DialogContent.tsx +30 -28
- package/src/components/dialogs/Dialog/DialogHeading.tsx +1 -1
- package/src/components/dialogs/Dialog/useDialog.tsx +1 -1
- package/src/components/feedback/Alert/index.tsx +74 -73
- package/src/components/feedback/NotificationBanner/NotificationBanner.test.tsx +1 -1
- package/src/components/feedback/NotificationBanner/index.tsx +1 -1
- package/src/components/feedback/Popover/PopoverContent.tsx +4 -1
- package/src/components/feedback/Popover/PopoverTrigger.tsx +33 -31
- package/src/components/feedback/Popover/usePopover.tsx +1 -1
- package/src/components/feedback/ProgressBar/index.tsx +1 -1
- package/src/components/feedback/QuestionTooltip/index.tsx +1 -2
- package/src/components/feedback/Tooltip/TooltipContent.tsx +4 -1
- package/src/components/feedback/Tooltip/TooltipTrigger.tsx +3 -3
- package/src/components/feedback/Tooltip/useTooltip.tsx +1 -1
- package/src/components/feedback/snacks/CookieConsent/index.tsx +5 -2
- package/src/components/feedback/snacks/Default/index.tsx +51 -50
- package/src/components/feedback/snacks/Drawer/index.tsx +22 -21
- package/src/components/feedback/snacks/NetworkDetector/index.tsx +35 -31
- package/src/components/inputs/CheckBox/Controlled.tsx +2 -3
- package/src/components/inputs/CheckBox/Generic.tsx +18 -72
- package/src/components/inputs/CheckBox/style.ts +40 -97
- package/src/components/inputs/CodeField/CodeField.stories.tsx +4 -5
- package/src/components/inputs/CodeField/index.tsx +1 -0
- package/src/components/inputs/Date/DatePicker/DatePicker.stories.tsx +2 -3
- package/src/components/inputs/Date/DatePicker/Generic.tsx +20 -10
- package/src/components/inputs/Date/DateRangePicker/Context.tsx +12 -1
- package/src/components/inputs/Date/DateRangePicker/Controlled.tsx +74 -0
- package/src/components/inputs/Date/DateRangePicker/DateRangePicker.stories.tsx +11 -6
- package/src/components/inputs/Date/DateRangePicker/DateSelector/Absolute.tsx +3 -3
- package/src/components/inputs/Date/DateRangePicker/DateSelector/Relative.tsx +1 -1
- package/src/components/inputs/Date/DateRangePicker/DateSelector/index.tsx +1 -1
- package/src/components/inputs/Date/DateRangePicker/{index.tsx → Generic.tsx} +43 -11
- package/src/components/inputs/Date/DateRangePicker/QuickSelect/index.tsx +1 -1
- package/src/components/inputs/Date/DateRangePicker/style.ts +19 -5
- package/src/components/inputs/Date/subcomponents/Calendar/index.tsx +1 -1
- package/src/components/inputs/Date/subcomponents/RelativePicker/index.tsx +1 -1
- package/src/components/inputs/DurationField/Generic.tsx +149 -152
- package/src/components/inputs/FileField/FileField.stories.tsx +6 -6
- package/src/components/inputs/FileField/Generic.tsx +101 -99
- package/src/components/inputs/InputProps.ts +0 -2
- package/src/components/inputs/RadioGroup/Controlled.tsx +1 -2
- package/src/components/inputs/RadioGroup/RadioGroup.stories.tsx +6 -4
- package/src/components/inputs/RadioGroup/RadioItem.tsx +54 -53
- package/src/components/inputs/Slider/Generic.tsx +1 -1
- package/src/components/inputs/Slider/Slider.stories.tsx +1 -1
- package/src/components/inputs/Slider/handle.tsx +1 -0
- package/src/components/inputs/Switch/Controlled.tsx +1 -2
- package/src/components/inputs/Switch/Generic.tsx +18 -45
- package/src/components/inputs/Switch/Switch.stories.tsx +2 -4
- package/src/components/inputs/Switch/style.ts +44 -38
- package/src/components/inputs/TagField/Generic.tsx +109 -109
- package/src/components/inputs/TextAreaField/Generic.tsx +41 -39
- package/src/components/inputs/TextAreaField/TextAreaField.stories.tsx +2 -3
- package/src/components/inputs/TextField/Generic.tsx +81 -79
- package/src/components/inputs/TextField/TextField.stories.tsx +3 -4
- package/src/components/inputs/index.ts +3 -2
- package/src/components/inputs/layout/Description.tsx +1 -2
- package/src/components/inputs/layout/InputWrapper.ts +2 -2
- package/src/components/inputs/selects/SelectField/Controlled.tsx +1 -2
- package/src/components/inputs/selects/SelectField/Generic/FilterInput.tsx +4 -1
- package/src/components/inputs/selects/SelectField/SelectField.stories.tsx +9 -10
- package/src/components/inputs/selects/SelectQueryField/Generic/index.tsx +200 -197
- package/src/components/inputs/selects/SelectQueryField/SelectQueryField.stories.tsx +1 -1
- package/src/components/inputs/selects/SubComponents/Option.tsx +3 -3
- package/src/components/inputs/selects/SubComponents/OptionGroup.tsx +1 -1
- package/src/components/inputs/selects/SubComponents/style.ts +18 -4
- package/src/components/inputs/selects/index.tsx +5 -2
- package/src/components/inputs/selects/sharedStyle.ts +1 -0
- package/src/components/navigation/HorizontalNav/index.tsx +5 -32
- package/src/components/navigation/HorizontalNav/style.ts +11 -26
- package/src/components/navigation/IconNav/index.tsx +1 -1
- package/src/components/navigation/Steppers/SlimStepper/index.tsx +1 -1
- package/src/components/navigation/Steppers/SlimStepper/style.ts +1 -2
- package/src/components/navigation/Steppers/Stepper/index.tsx +1 -1
- package/src/components/navigation/Steppers/context.tsx +2 -2
- package/src/components/navigation/Tabs/Content.tsx +4 -1
- package/src/components/navigation/Tabs/Trigger.tsx +24 -23
- package/src/components/navigation/index.ts +1 -1
- package/src/components/other/ActionMenu/ActionMenu.stories.tsx +1 -2
- package/src/components/other/ActionMenu/index.tsx +30 -29
- package/src/components/other/Collapsible/CollapsibleTrigger.tsx +8 -4
- package/src/components/other/Company/index.tsx +25 -26
- package/src/components/other/Empty/Empty.stories.tsx +1 -1
- package/src/components/other/Empty/index.tsx +1 -3
- package/src/components/other/PermissionsGuard/index.tsx +2 -2
- package/src/components/visual/Card/index.tsx +4 -1
- package/src/errors/base.ts +4 -1
- package/src/errors/errors.ts +19 -2
- package/src/helpers/getSnackbarProvider.tsx +3 -3
- package/src/helpers/regexprs.ts +1 -0
- package/src/hooks/useFocus.tsx +3 -1
- package/src/hooks/useOnScreen.ts +1 -1
- package/src/hooks/useTableActions.ts +10 -5
- package/src/styled/GlobalStyle.ts +2 -1
- package/src/styled/zIndex.ts +1 -1
- package/src/test/testUtils.tsx +3 -0
- package/src/components/data/Table/subcomponents/index.ts +0 -4
|
@@ -22,117 +22,117 @@ export interface TagFieldProps {
|
|
|
22
22
|
// these are props that should only be available on the generic version.
|
|
23
23
|
export type GenericTagFieldProps = TagFieldProps & GenericInputPropsFunctionHandlers<string[], HTMLInputElement>;
|
|
24
24
|
|
|
25
|
-
export const GenericTagField = forwardRef<HTMLDivElement, GenericTagFieldProps>(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
25
|
+
export const GenericTagField = forwardRef<HTMLDivElement, GenericTagFieldProps>(function GenericTagField(
|
|
26
|
+
{
|
|
27
|
+
onRemoved,
|
|
28
|
+
separators = [],
|
|
29
|
+
name,
|
|
30
|
+
readOnly,
|
|
31
|
+
placeholder,
|
|
32
|
+
// TODO: tagValidationSchema,
|
|
33
|
+
disableBackspaceRemove,
|
|
34
|
+
value = [],
|
|
35
|
+
onKeyUp,
|
|
36
|
+
allowDuplicates = false,
|
|
37
|
+
isEditOnRemove,
|
|
38
|
+
disabled = false,
|
|
39
|
+
onBlur = () => {},
|
|
40
|
+
onFocus = () => {},
|
|
41
|
+
onChange,
|
|
42
|
+
required,
|
|
43
|
+
hasDescription,
|
|
44
|
+
},
|
|
45
|
+
ref,
|
|
46
|
+
) {
|
|
47
|
+
const combinedSeparators = [...defaultSeparators, ...separators];
|
|
48
|
+
const [tags, setTags] = useState<string[]>(Array.isArray(value) ? value : []);
|
|
49
|
+
|
|
50
|
+
useDidUpdateEffect(() => {
|
|
51
|
+
onChange(tags);
|
|
52
|
+
}, [tags]);
|
|
53
|
+
|
|
54
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
55
|
+
e.stopPropagation();
|
|
56
|
+
const text = e.currentTarget.value;
|
|
57
|
+
|
|
58
|
+
// handle tag removing
|
|
59
|
+
if (!text && !disableBackspaceRemove && tags.length && e.key === 'Backspace') {
|
|
60
|
+
e.currentTarget.value = isEditOnRemove ? `${tags.at(-1)} ` : '';
|
|
61
|
+
setTags([...tags.slice(0, -1)]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// handle new tag confirmation
|
|
65
|
+
if (text && combinedSeparators.includes(e.key)) {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
|
|
68
|
+
// TODO: check tag validation logic
|
|
69
|
+
// if (tagValidationSchema && tagValidationSchema.parse(tags)) return;
|
|
70
|
+
|
|
71
|
+
if (tags.includes(text) && !allowDuplicates) {
|
|
72
|
+
// should not add duplicate tags
|
|
73
|
+
return;
|
|
63
74
|
}
|
|
64
75
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
event.preventDefault();
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return (
|
|
110
|
-
<TagsContainer aria-labelledby={name} ref={ref}>
|
|
111
|
-
{tags.map((tag) => (
|
|
112
|
-
<Tag
|
|
113
|
-
key={tag}
|
|
114
|
-
label={tag}
|
|
115
|
-
onDelete={() => onTagDelete(tag)}
|
|
116
|
-
disabled={disabled}
|
|
117
|
-
readOnly={readOnly}
|
|
118
|
-
color="secondary"
|
|
119
|
-
/>
|
|
120
|
-
))}
|
|
121
|
-
<input
|
|
122
|
-
type="text"
|
|
123
|
-
name={name}
|
|
124
|
-
placeholder={placeholder}
|
|
76
|
+
setTags([...tags, text]);
|
|
77
|
+
|
|
78
|
+
// clear input field
|
|
79
|
+
e.currentTarget.value = '';
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
// remove duplicates from tag list when allowDuplicates is set to false
|
|
85
|
+
if (!allowDuplicates) {
|
|
86
|
+
setTags([...new Set(tags)]);
|
|
87
|
+
}
|
|
88
|
+
}, [allowDuplicates]);
|
|
89
|
+
|
|
90
|
+
const onTagDelete = (text: string) => {
|
|
91
|
+
setTags(tags.filter((tag) => tag !== text));
|
|
92
|
+
if (onRemoved) {
|
|
93
|
+
onRemoved(text);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const handleOnPaste = (event: ClipboardEvent<HTMLInputElement>) => {
|
|
98
|
+
const pasteText = event.clipboardData.getData('text');
|
|
99
|
+
if (pasteText.length < 1) return;
|
|
100
|
+
|
|
101
|
+
const pasteTags = splitPaste({
|
|
102
|
+
text: pasteText,
|
|
103
|
+
tags,
|
|
104
|
+
separators: combinedSeparators,
|
|
105
|
+
});
|
|
106
|
+
setTags([...tags, ...pasteTags]);
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<TagsContainer aria-labelledby={name} ref={ref}>
|
|
112
|
+
{tags.map((tag) => (
|
|
113
|
+
<Tag
|
|
114
|
+
key={tag}
|
|
115
|
+
label={tag}
|
|
116
|
+
onDelete={() => onTagDelete(tag)}
|
|
125
117
|
disabled={disabled}
|
|
126
|
-
onKeyDown={handleKeyDown}
|
|
127
|
-
onKeyUp={onKeyUp}
|
|
128
118
|
readOnly={readOnly}
|
|
129
|
-
|
|
130
|
-
onPaste={handleOnPaste}
|
|
131
|
-
onFocus={onFocus}
|
|
132
|
-
aria-describedby={setAriaDescribedBy(name, hasDescription)}
|
|
133
|
-
aria-required={required}
|
|
119
|
+
color="secondary"
|
|
134
120
|
/>
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
121
|
+
))}
|
|
122
|
+
<input
|
|
123
|
+
type="text"
|
|
124
|
+
name={name}
|
|
125
|
+
placeholder={placeholder}
|
|
126
|
+
disabled={disabled}
|
|
127
|
+
onKeyDown={handleKeyDown}
|
|
128
|
+
onKeyUp={onKeyUp}
|
|
129
|
+
readOnly={readOnly}
|
|
130
|
+
onBlur={onBlur}
|
|
131
|
+
onPaste={handleOnPaste}
|
|
132
|
+
onFocus={onFocus}
|
|
133
|
+
aria-describedby={setAriaDescribedBy(name, hasDescription)}
|
|
134
|
+
aria-required={required}
|
|
135
|
+
/>
|
|
136
|
+
</TagsContainer>
|
|
137
|
+
);
|
|
138
|
+
});
|
|
@@ -12,45 +12,47 @@ export interface TextAreaFieldProps {
|
|
|
12
12
|
export type GenericTextAreaFieldProps = TextAreaFieldProps & GenericInputProps<string, HTMLTextAreaElement>;
|
|
13
13
|
|
|
14
14
|
const defaultsApplier = defaultInputPropsFactory<TextAreaFieldProps & GenericInputProps<string, HTMLTextAreaElement>>(
|
|
15
|
-
defaultInputProps
|
|
15
|
+
defaultInputProps,
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
-
export const GenericTextAreaField = forwardRef<HTMLTextAreaElement, GenericTextAreaFieldProps>(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
export const GenericTextAreaField = forwardRef<HTMLTextAreaElement, GenericTextAreaFieldProps>(
|
|
19
|
+
function GenericTextAreaField(props, ref) {
|
|
20
|
+
const {
|
|
21
|
+
disabled,
|
|
22
|
+
required,
|
|
23
|
+
onBlur = () => {},
|
|
24
|
+
placeholder,
|
|
25
|
+
onChange,
|
|
26
|
+
onFocus = () => {},
|
|
27
|
+
name,
|
|
28
|
+
rows = 4,
|
|
29
|
+
hasError,
|
|
30
|
+
hasDescription,
|
|
31
|
+
value,
|
|
32
|
+
readOnly,
|
|
33
|
+
id,
|
|
34
|
+
} = defaultsApplier(props);
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
36
|
+
return (
|
|
37
|
+
<TextAreaContainer>
|
|
38
|
+
<TextArea
|
|
39
|
+
hasError={hasError}
|
|
40
|
+
id={id}
|
|
41
|
+
name={name}
|
|
42
|
+
onChange={onChange}
|
|
43
|
+
onBlur={onBlur}
|
|
44
|
+
onFocus={onFocus}
|
|
45
|
+
placeholder={placeholder}
|
|
46
|
+
readOnly={readOnly}
|
|
47
|
+
role="presentation"
|
|
48
|
+
disabled={disabled}
|
|
49
|
+
ref={ref}
|
|
50
|
+
value={value}
|
|
51
|
+
rows={rows}
|
|
52
|
+
aria-required={required}
|
|
53
|
+
aria-describedby={setAriaDescribedBy(name, hasDescription)}
|
|
54
|
+
/>
|
|
55
|
+
</TextAreaContainer>
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useState } from 'react';
|
|
1
|
+
import React, { useState } from 'react';
|
|
3
2
|
import { Meta, StoryFn } from '@storybook/react';
|
|
4
3
|
import { styled } from '../../../styled';
|
|
5
4
|
import { TextAreaField, TextAreaFieldProps, Button } from '../../../components';
|
|
@@ -31,7 +30,7 @@ export default {
|
|
|
31
30
|
} as Meta<TextAreaFieldProps>;
|
|
32
31
|
|
|
33
32
|
const validationSchema = z.object({
|
|
34
|
-
name: z.string().min(6)
|
|
33
|
+
name: z.string().min(6),
|
|
35
34
|
});
|
|
36
35
|
|
|
37
36
|
type FormFields = { name: string };
|
|
@@ -27,87 +27,89 @@ export type GenericTextFieldProps = GenericInputProps<string, HTMLInputElement>
|
|
|
27
27
|
|
|
28
28
|
const defaultsApplier = defaultInputPropsFactory<GenericTextFieldProps>(defaultInputProps);
|
|
29
29
|
|
|
30
|
-
export const GenericTextField = forwardRef<HTMLInputElement, GenericTextFieldProps>(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
30
|
+
export const GenericTextField = forwardRef<HTMLInputElement, GenericTextFieldProps>(
|
|
31
|
+
function GenericTextField(props, ref) {
|
|
32
|
+
const {
|
|
33
|
+
onChange,
|
|
34
|
+
onBlur = () => {},
|
|
35
|
+
onFocus = () => {},
|
|
36
|
+
name,
|
|
37
|
+
disabled,
|
|
38
|
+
required,
|
|
39
|
+
readOnly,
|
|
40
|
+
hasError,
|
|
41
|
+
placeholder,
|
|
42
|
+
icon,
|
|
43
|
+
type = 'text',
|
|
44
|
+
prefix,
|
|
45
|
+
suffix,
|
|
46
|
+
value,
|
|
47
|
+
id,
|
|
48
|
+
hasDescription,
|
|
49
|
+
} = defaultsApplier(props);
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
const [showPassword, setShowPassword] = useState(false);
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const handleOnChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
54
|
+
// not a perfect solution, but works for now
|
|
55
|
+
if (type === 'number') {
|
|
56
|
+
if (isNumber(e.target.value) || e.target.value === '-') {
|
|
57
|
+
onChange(e);
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
56
60
|
onChange(e);
|
|
57
61
|
}
|
|
58
|
-
}
|
|
59
|
-
onChange(e);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
+
};
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
64
|
+
return (
|
|
65
|
+
<InputContainer>
|
|
66
|
+
{prefix && <PrefixContainer hasError={hasError}>{prefix}</PrefixContainer>}
|
|
67
|
+
{icon && cloneElement(icon, { size: 18, className: 'icon' })}
|
|
68
|
+
<Input
|
|
69
|
+
autoCapitalize="off"
|
|
70
|
+
autoComplete={type === 'password' ? 'new-password' : 'off'}
|
|
71
|
+
hasError={hasError}
|
|
72
|
+
hasIcon={!!icon}
|
|
73
|
+
hasPrefix={!!prefix}
|
|
74
|
+
hasSuffix={!!suffix}
|
|
75
|
+
isPassword={type === 'password'}
|
|
76
|
+
id={id}
|
|
77
|
+
name={name}
|
|
78
|
+
onChange={handleOnChange}
|
|
79
|
+
onBlur={onBlur}
|
|
80
|
+
onFocus={onFocus}
|
|
81
|
+
placeholder={placeholder}
|
|
82
|
+
disabled={disabled}
|
|
83
|
+
readOnly={readOnly}
|
|
84
|
+
role="presentation"
|
|
85
|
+
inputMode={getInputMode(type)}
|
|
86
|
+
type={getFieldType(type, showPassword)}
|
|
87
|
+
ref={ref}
|
|
88
|
+
value={value}
|
|
89
|
+
aria-readonly={readOnly}
|
|
90
|
+
aria-required={required}
|
|
91
|
+
aria-describedby={setAriaDescribedBy(name, hasDescription)}
|
|
92
|
+
/>
|
|
93
|
+
{type === 'password' &&
|
|
94
|
+
(showPassword ? (
|
|
95
|
+
<HidePasswordIcon
|
|
96
|
+
className="password-icon"
|
|
97
|
+
onClick={() => {
|
|
98
|
+
setShowPassword(false);
|
|
99
|
+
}}
|
|
100
|
+
size={18}
|
|
101
|
+
/>
|
|
102
|
+
) : (
|
|
103
|
+
<ShowPasswordIcon
|
|
104
|
+
className="password-icon"
|
|
105
|
+
onClick={() => {
|
|
106
|
+
setShowPassword(true);
|
|
107
|
+
}}
|
|
108
|
+
size={18}
|
|
109
|
+
/>
|
|
110
|
+
))}
|
|
111
|
+
{suffix && <SuffixContainer hasError={hasError}>{suffix}</SuffixContainer>}
|
|
112
|
+
</InputContainer>
|
|
113
|
+
);
|
|
114
|
+
},
|
|
115
|
+
);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useState } from 'react';
|
|
1
|
+
import React, { useState } from 'react';
|
|
3
2
|
import { Meta, StoryFn } from '@storybook/react';
|
|
4
3
|
import { styled } from '../../../styled';
|
|
5
4
|
import { TextField, TextFieldProps, Button } from '../../../components';
|
|
@@ -38,11 +37,11 @@ export default {
|
|
|
38
37
|
} as Meta<TextFieldProps>;
|
|
39
38
|
|
|
40
39
|
const validationSchema = z.object({
|
|
41
|
-
name: z.string().min(6
|
|
40
|
+
name: z.string().min(6, 'Name must be at least 6 characters'),
|
|
42
41
|
});
|
|
43
42
|
type FormFields = { name: string };
|
|
44
43
|
|
|
45
|
-
export const
|
|
44
|
+
export const OnChange: StoryFn<TextFieldProps> = (args) => {
|
|
46
45
|
const { control } = useForm({ mode: 'onChange' });
|
|
47
46
|
const TextFieldValue = useWatch({ name: args.name, control });
|
|
48
47
|
|
|
@@ -55,8 +55,9 @@ export { ErrorMessage } from './layout/ErrorMessage';
|
|
|
55
55
|
export { InputWrapper } from './layout/InputWrapper';
|
|
56
56
|
export { Description } from './layout/Description';
|
|
57
57
|
|
|
58
|
-
export { DateRangePicker } from './Date/DateRangePicker';
|
|
59
|
-
export type { DateRangePickerProps } from './Date/DateRangePicker';
|
|
58
|
+
export { ControlledDateRangePicker as DateRangePicker } from './Date/DateRangePicker/Controlled';
|
|
59
|
+
export type { DateRangePickerProps } from './Date/DateRangePicker/Generic';
|
|
60
|
+
export { GenericDateRangePicker as UnControlledDateRangePicker } from './Date/DateRangePicker/Generic';
|
|
60
61
|
|
|
61
62
|
export { ControlledDurationField as DurationField } from './DurationField/Controlled';
|
|
62
63
|
export type { ControlledDurationFieldProps as DurationFieldProps } from './DurationField/Controlled';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { styled } from '../../../styled';
|
|
2
2
|
|
|
3
|
-
export const InputWrapper = styled.div
|
|
3
|
+
export const InputWrapper = styled.div`
|
|
4
4
|
width: 100%;
|
|
5
|
-
margin-bottom: ${({ theme
|
|
5
|
+
margin-bottom: ${({ theme }) => theme.spacing[2]};
|
|
6
6
|
`;
|
|
@@ -32,7 +32,6 @@ export const ControlledSelectField: FC<ControlledSelectFieldProps> & SubComponen
|
|
|
32
32
|
enableFilter,
|
|
33
33
|
inPortal,
|
|
34
34
|
canClear,
|
|
35
|
-
hasMargin = true,
|
|
36
35
|
} = defaultsApplier(props);
|
|
37
36
|
|
|
38
37
|
const {
|
|
@@ -81,7 +80,7 @@ export const ControlledSelectField: FC<ControlledSelectFieldProps> & SubComponen
|
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
return (
|
|
84
|
-
<InputWrapper
|
|
83
|
+
<InputWrapper>
|
|
85
84
|
<Container>
|
|
86
85
|
{label && (
|
|
87
86
|
<Label
|
|
@@ -19,7 +19,10 @@ interface FilterInputProps {
|
|
|
19
19
|
onFilterChange: (value: string) => void;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export const FilterInput = forwardRef<HTMLInputElement, FilterInputProps>((
|
|
22
|
+
export const FilterInput = forwardRef<HTMLInputElement, FilterInputProps>(function FilterInput(
|
|
23
|
+
{ selectName, onFilterChange },
|
|
24
|
+
ref,
|
|
25
|
+
) {
|
|
23
26
|
const [inputValue, setInputValue] = useState<string>('');
|
|
24
27
|
const onChangeHandler = (value: string) => {
|
|
25
28
|
setInputValue(value);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { Meta, StoryFn } from '@storybook/react';
|
|
3
|
-
import { useMemo, useState } from 'react';
|
|
2
|
+
import React, { useMemo, useState } from 'react';
|
|
4
3
|
import { Button, SelectField, SelectFieldProps } from '../../../../components';
|
|
5
4
|
import { SubmitHandler, useForm, useWatch } from 'react-hook-form';
|
|
6
5
|
import { styled } from '../../../../styled';
|
|
@@ -34,7 +33,7 @@ const OptionIcon = styled.img`
|
|
|
34
33
|
color: transparent;
|
|
35
34
|
`;
|
|
36
35
|
|
|
37
|
-
export const
|
|
36
|
+
export const OnChange: StoryFn<SelectFieldProps & ExtraStoryProps> = (args) => {
|
|
38
37
|
const { control } = useForm();
|
|
39
38
|
const selectValue = useWatch({ control, name: 'film' });
|
|
40
39
|
|
|
@@ -88,7 +87,7 @@ export const OnSubmit: StoryFn<SelectFieldProps> = (args) => {
|
|
|
88
87
|
z.object({
|
|
89
88
|
film: z.enum(['not-sure-how-this-works', ...films.map((film) => film.name)]),
|
|
90
89
|
}),
|
|
91
|
-
[]
|
|
90
|
+
[],
|
|
92
91
|
);
|
|
93
92
|
|
|
94
93
|
const { control, handleSubmit } = useForm<FormFields>({
|
|
@@ -151,7 +150,7 @@ export const MultiSelect: StoryFn<SelectFieldProps> = (args) => {
|
|
|
151
150
|
z.object({
|
|
152
151
|
film: z.string().array(),
|
|
153
152
|
}),
|
|
154
|
-
[]
|
|
153
|
+
[],
|
|
155
154
|
);
|
|
156
155
|
|
|
157
156
|
const { control, handleSubmit } = useForm<FormFields>({
|
|
@@ -182,11 +181,11 @@ export const MultiSelect: StoryFn<SelectFieldProps> = (args) => {
|
|
|
182
181
|
{selectedFilms.length === 0
|
|
183
182
|
? 'Select...'
|
|
184
183
|
: selectedFilms.length <= 3
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
184
|
+
? selectedFilms.map((film) => film.name).join(', ')
|
|
185
|
+
: `${selectedFilms
|
|
186
|
+
.slice(0, 3)
|
|
187
|
+
.map((film) => film.name)
|
|
188
|
+
.join(', ')} and ${selectedFilms.length - 3} more`}
|
|
190
189
|
</div>
|
|
191
190
|
);
|
|
192
191
|
}}
|