@xqmsg/ui-core 0.9.2 → 0.10.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.
- package/dist/components/input/InputTypes.d.ts +5 -3
- package/dist/components/input/StackedInput/StackedInput.d.ts +0 -3
- package/dist/components/input/StackedMultiSelect/index.d.ts +1 -1
- package/dist/components/input/StackedSelect/StackedSelect.d.ts +7 -3
- package/dist/components/input/components/dropdown/index.d.ts +10 -0
- package/dist/components/input/components/label/index.d.ts +9 -0
- package/dist/components/input/components/token/Token.stories.d.ts +5 -0
- package/dist/components/input/components/token/index.d.ts +7 -0
- package/dist/components/input/index.d.ts +1 -3
- package/dist/theme/components/form-error.d.ts +3 -3
- package/dist/theme/components/form-label.d.ts +4 -6
- package/dist/theme/components/form.d.ts +3 -3
- package/dist/theme/components/input.d.ts +32 -161
- package/dist/theme/components/select.d.ts +27 -153
- package/dist/theme/components/textarea.d.ts +10 -117
- package/dist/theme/foundations/colors.d.ts +30 -0
- package/dist/ui-core.cjs.development.js +455 -490
- package/dist/ui-core.cjs.development.js.map +1 -1
- package/dist/ui-core.cjs.production.min.js +1 -1
- package/dist/ui-core.cjs.production.min.js.map +1 -1
- package/dist/ui-core.esm.js +459 -494
- package/dist/ui-core.esm.js.map +1 -1
- package/package.json +5 -3
- package/src/components/input/Input.stories.tsx +28 -12
- package/src/components/input/InputTypes.ts +7 -1
- package/src/components/input/StackedInput/StackedInput.tsx +3 -15
- package/src/components/input/StackedMultiSelect/components/MultiValue/index.tsx +2 -2
- package/src/components/input/StackedMultiSelect/index.tsx +89 -93
- package/src/components/input/StackedPilledInput/index.tsx +145 -56
- package/src/components/input/StackedSelect/StackedSelect.tsx +63 -20
- package/src/components/input/StackedSelect/assets/svg/subtract.svg +3 -0
- package/src/components/input/components/dropdown/index.tsx +79 -0
- package/src/components/input/components/label/index.tsx +24 -0
- package/src/components/input/components/token/Token.stories.tsx +22 -0
- package/src/components/input/components/token/assets/svg/close.svg +3 -0
- package/src/components/input/components/token/index.tsx +37 -0
- package/src/components/input/index.tsx +8 -20
- package/src/theme/components/alert.ts +4 -4
- package/src/theme/components/form-error.ts +11 -14
- package/src/theme/components/form-label.ts +8 -8
- package/src/theme/components/form.ts +10 -13
- package/src/theme/components/input.ts +17 -191
- package/src/theme/components/select.ts +5 -10
- package/src/theme/components/textarea.ts +2 -38
- package/src/theme/foundations/colors.ts +17 -1
- package/dist/components/input/components/InputTag/index.d.ts +0 -7
- package/src/components/input/components/InputTag/index.tsx +0 -24
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { Box, Flex, Input } from '@chakra-ui/react';
|
|
2
|
+
import { Box, Flex, Input, Text, useOutsideClick } from '@chakra-ui/react';
|
|
3
3
|
import { InputFieldProps } from '../InputTypes';
|
|
4
4
|
import {
|
|
5
5
|
Control,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
useWatch,
|
|
9
9
|
} from 'react-hook-form';
|
|
10
10
|
import colors from '../../../theme/foundations/colors';
|
|
11
|
-
import
|
|
11
|
+
import Token from '../components/token';
|
|
12
12
|
|
|
13
13
|
export interface StackedPilledInputProps extends InputFieldProps {
|
|
14
14
|
setValue: UseFormSetValue<FieldValues>;
|
|
@@ -21,15 +21,17 @@ export interface StackedPilledInputProps extends InputFieldProps {
|
|
|
21
21
|
const StackedPilledInput = React.forwardRef<
|
|
22
22
|
HTMLInputElement,
|
|
23
23
|
StackedPilledInputProps
|
|
24
|
-
>(({ name, setValue, control }, _ref) => {
|
|
24
|
+
>(({ name, setValue, control, placeholder, disabled }, _ref) => {
|
|
25
25
|
const watchedValue = useWatch({ control, name: name as string });
|
|
26
26
|
const [lastestFormValueToArray, setLatestFormValueToArray] = useState<
|
|
27
27
|
string[]
|
|
28
28
|
>([]);
|
|
29
29
|
|
|
30
30
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
31
|
+
const inputWrapperRef = useRef(null);
|
|
31
32
|
|
|
32
|
-
const [
|
|
33
|
+
const [tokenIndex, setTokenIndex] = useState<number | null>(null);
|
|
34
|
+
const [isFocussed, setIsFocussed] = useState(false);
|
|
33
35
|
|
|
34
36
|
const [localValue, setLocalValue] = useState('');
|
|
35
37
|
|
|
@@ -44,17 +46,34 @@ const StackedPilledInput = React.forwardRef<
|
|
|
44
46
|
}
|
|
45
47
|
}, [watchedValue]);
|
|
46
48
|
|
|
47
|
-
// ensures after value addition that the input field is wiped
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (localValue === ' ' || localValue.trim() === ',') {
|
|
50
|
-
setLocalValue('');
|
|
51
|
-
}
|
|
52
|
-
}, [localValue]);
|
|
53
|
-
|
|
54
49
|
const onHandleKeyDown = (e: React.KeyboardEvent) => {
|
|
55
50
|
if (e.key === ' ' || e.key === 'Enter' || e.key === ',') {
|
|
56
|
-
if (
|
|
57
|
-
|
|
51
|
+
if (
|
|
52
|
+
e.key === 'Enter' &&
|
|
53
|
+
!localValue.trim().length &&
|
|
54
|
+
tokenIndex !== null
|
|
55
|
+
) {
|
|
56
|
+
setLocalValue(lastestFormValueToArray[tokenIndex]);
|
|
57
|
+
|
|
58
|
+
const filteredUniqueValues = Array.from(
|
|
59
|
+
new Set(
|
|
60
|
+
lastestFormValueToArray.filter(
|
|
61
|
+
(value) => value !== lastestFormValueToArray[tokenIndex]
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
setValue(
|
|
67
|
+
name as string,
|
|
68
|
+
filteredUniqueValues.toString().replace(/\s/g, ''),
|
|
69
|
+
{
|
|
70
|
+
shouldValidate: true,
|
|
71
|
+
shouldDirty: true,
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return setTokenIndex(null);
|
|
76
|
+
}
|
|
58
77
|
|
|
59
78
|
const filteredUniqueValues = Array.from(
|
|
60
79
|
new Set([...lastestFormValueToArray, ...localValue.trim().split(',')])
|
|
@@ -71,6 +90,59 @@ const StackedPilledInput = React.forwardRef<
|
|
|
71
90
|
}
|
|
72
91
|
);
|
|
73
92
|
}
|
|
93
|
+
|
|
94
|
+
if (!localValue.trim().length && lastestFormValueToArray.length) {
|
|
95
|
+
if (e.key === 'Backspace' && tokenIndex !== null) {
|
|
96
|
+
setLocalValue(
|
|
97
|
+
lastestFormValueToArray[tokenIndex].substring(
|
|
98
|
+
0,
|
|
99
|
+
lastestFormValueToArray[tokenIndex].length
|
|
100
|
+
)
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const filteredUniqueValues = Array.from(
|
|
104
|
+
new Set(
|
|
105
|
+
[...lastestFormValueToArray].filter(
|
|
106
|
+
(value) => value !== lastestFormValueToArray[tokenIndex]
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
setValue(
|
|
112
|
+
name as string,
|
|
113
|
+
filteredUniqueValues.toString().replace(/\s/g, ''),
|
|
114
|
+
{
|
|
115
|
+
shouldValidate: true,
|
|
116
|
+
shouldDirty: true,
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
return setTokenIndex(null);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (e.key === 'ArrowLeft') {
|
|
124
|
+
if (tokenIndex === 0) return;
|
|
125
|
+
|
|
126
|
+
if (!tokenIndex) {
|
|
127
|
+
return setTokenIndex(lastestFormValueToArray.length - 1);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return setTokenIndex(
|
|
131
|
+
(prevTokenIndex) => (prevTokenIndex as number) - 1
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (e.key === 'ArrowRight') {
|
|
136
|
+
if (tokenIndex === null) return;
|
|
137
|
+
|
|
138
|
+
if (tokenIndex === lastestFormValueToArray.length - 1) {
|
|
139
|
+
return setTokenIndex(null);
|
|
140
|
+
}
|
|
141
|
+
return setTokenIndex(
|
|
142
|
+
(prevTokenIndex) => (prevTokenIndex as number) + 1
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
74
146
|
};
|
|
75
147
|
|
|
76
148
|
const onRemoveTag = (index: number) => {
|
|
@@ -106,63 +178,80 @@ const StackedPilledInput = React.forwardRef<
|
|
|
106
178
|
);
|
|
107
179
|
setLocalValue('');
|
|
108
180
|
}
|
|
109
|
-
|
|
181
|
+
setIsFocussed(false);
|
|
110
182
|
};
|
|
111
183
|
|
|
184
|
+
useOutsideClick({ ref: inputWrapperRef, handler: onBlur });
|
|
185
|
+
|
|
112
186
|
return (
|
|
113
|
-
<
|
|
114
|
-
<
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
187
|
+
<Box position="relative">
|
|
188
|
+
<Flex
|
|
189
|
+
fontSize="13px"
|
|
190
|
+
border={isFocussed ? '2px solid' : '1px solid'}
|
|
191
|
+
borderColor={isFocussed ? colors.border.focus : colors.border.default}
|
|
192
|
+
py="5px"
|
|
193
|
+
pl="8px"
|
|
194
|
+
borderRadius="4px"
|
|
195
|
+
alignItems="center"
|
|
196
|
+
justifyContent="space-between"
|
|
197
|
+
onClick={() => {
|
|
198
|
+
if (!disabled) {
|
|
199
|
+
inputRef.current?.focus();
|
|
200
|
+
}
|
|
201
|
+
}}
|
|
202
|
+
bg={disabled ? colors.fill.light : '#ffffff'}
|
|
203
|
+
cursor={disabled ? 'not-allowed' : 'pointer'}
|
|
204
|
+
ref={inputWrapperRef}
|
|
118
205
|
>
|
|
119
|
-
<Flex
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
206
|
+
<Flex height="28px" alignItems="center" width="fit-content">
|
|
207
|
+
{lastestFormValueToArray.length ? (
|
|
208
|
+
lastestFormValueToArray.map((label, index) => (
|
|
209
|
+
<Box
|
|
210
|
+
mr="4px"
|
|
211
|
+
border={
|
|
212
|
+
tokenIndex === index
|
|
213
|
+
? `2px solid ${colors.border.focus}`
|
|
214
|
+
: 'none'
|
|
215
|
+
}
|
|
216
|
+
borderRadius="full"
|
|
217
|
+
onClick={() => setTokenIndex(index)}
|
|
218
|
+
>
|
|
219
|
+
<Token
|
|
220
|
+
label={label}
|
|
221
|
+
onDelete={(e: any) => {
|
|
222
|
+
e.stopPropagation();
|
|
223
|
+
e.preventDefault();
|
|
224
|
+
onRemoveTag(index);
|
|
225
|
+
}}
|
|
226
|
+
/>
|
|
227
|
+
</Box>
|
|
228
|
+
))
|
|
229
|
+
) : (
|
|
230
|
+
<Text color={colors.label.secondary.light} fontSize="13px">
|
|
231
|
+
{placeholder}
|
|
232
|
+
</Text>
|
|
233
|
+
)}
|
|
234
|
+
</Flex>
|
|
235
|
+
<Flex flex={1}>
|
|
149
236
|
<Input
|
|
150
237
|
onKeyDown={onHandleKeyDown}
|
|
151
238
|
type="text"
|
|
152
|
-
padding={
|
|
153
|
-
height={isInputFocused ? '46px' : '0px'}
|
|
239
|
+
padding={0}
|
|
154
240
|
width="100%"
|
|
155
241
|
border="none"
|
|
242
|
+
height="26px"
|
|
243
|
+
color={tokenIndex !== null ? 'transparent' : colors.label.primary}
|
|
156
244
|
_focus={{ boxShadow: 'none !important' }}
|
|
157
245
|
value={localValue}
|
|
158
|
-
|
|
159
|
-
|
|
246
|
+
onChange={(e) =>
|
|
247
|
+
tokenIndex === null && setLocalValue(e.target.value)
|
|
248
|
+
}
|
|
160
249
|
ref={inputRef}
|
|
161
|
-
onFocus={() =>
|
|
250
|
+
onFocus={() => setIsFocussed(true)}
|
|
162
251
|
/>
|
|
163
252
|
</Flex>
|
|
164
|
-
</
|
|
165
|
-
</
|
|
253
|
+
</Flex>
|
|
254
|
+
</Box>
|
|
166
255
|
);
|
|
167
256
|
});
|
|
168
257
|
|
|
@@ -1,31 +1,74 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import React, { useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Box,
|
|
4
|
+
Image,
|
|
5
|
+
Input,
|
|
6
|
+
InputGroup,
|
|
7
|
+
InputRightElement,
|
|
8
|
+
useOutsideClick,
|
|
9
|
+
} from '@chakra-ui/react';
|
|
10
|
+
import { FieldOptions } from '../InputTypes';
|
|
11
|
+
import { StackedInputProps } from '../StackedInput/StackedInput';
|
|
12
|
+
import colors from 'src/theme/foundations/colors';
|
|
13
|
+
import { UseFormSetValue, FieldValues, Control } from 'react-hook-form';
|
|
14
|
+
import SubtractIcon from './assets/svg/subtract.svg';
|
|
15
|
+
import { Dropdown } from '../components/dropdown';
|
|
4
16
|
|
|
5
|
-
export interface StackedSelectProps extends
|
|
17
|
+
export interface StackedSelectProps extends StackedInputProps {
|
|
6
18
|
options: FieldOptions;
|
|
19
|
+
setValue: UseFormSetValue<FieldValues>;
|
|
20
|
+
control: Control<FieldValues, any>;
|
|
7
21
|
}
|
|
8
22
|
|
|
9
23
|
/**
|
|
10
24
|
* A functional React component utilized to render the `StackedSelect` component.
|
|
11
25
|
*/
|
|
12
|
-
const StackedSelect = React.forwardRef<
|
|
13
|
-
({ isRequired, options, onChange, ...props }, _ref) => {
|
|
26
|
+
const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
|
|
27
|
+
({ isRequired, options, name, setValue, onChange, ...props }, _ref) => {
|
|
28
|
+
const dropdownRef = useRef(null);
|
|
29
|
+
const [isFocussed, setIsFocussed] = useState(false);
|
|
30
|
+
const [selectedOption, setSelectedOption] = useState('');
|
|
31
|
+
|
|
32
|
+
useOutsideClick({ ref: dropdownRef, handler: () => setIsFocussed(false) });
|
|
33
|
+
|
|
34
|
+
const handleOnSelectItem = (option: {
|
|
35
|
+
label: string;
|
|
36
|
+
value: string;
|
|
37
|
+
sortValue: number;
|
|
38
|
+
}) => {
|
|
39
|
+
setValue(name as string, option.value);
|
|
40
|
+
setSelectedOption(option.label);
|
|
41
|
+
setIsFocussed(false);
|
|
42
|
+
};
|
|
43
|
+
|
|
14
44
|
return (
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
<Box ref={dropdownRef} position="relative">
|
|
46
|
+
<InputGroup>
|
|
47
|
+
<Input
|
|
48
|
+
isRequired={isRequired}
|
|
49
|
+
{...props}
|
|
50
|
+
ref={_ref}
|
|
51
|
+
onClick={() => setIsFocussed(!isFocussed)}
|
|
52
|
+
cursor="pointer"
|
|
53
|
+
color="transparent"
|
|
54
|
+
fontSize="13px"
|
|
55
|
+
textShadow={`0 0 0 ${colors.label.primary.light}`}
|
|
56
|
+
value={selectedOption}
|
|
57
|
+
/>
|
|
58
|
+
<InputRightElement
|
|
59
|
+
cursor="pointer"
|
|
60
|
+
onClick={() => setIsFocussed(!isFocussed)}
|
|
61
|
+
>
|
|
62
|
+
<Image src={SubtractIcon} alt="subtract" boxSize="16px" />
|
|
63
|
+
</InputRightElement>
|
|
64
|
+
</InputGroup>
|
|
65
|
+
{isFocussed && (
|
|
66
|
+
<Dropdown
|
|
67
|
+
onSelectItem={(option) => handleOnSelectItem(option)}
|
|
68
|
+
options={options}
|
|
69
|
+
/>
|
|
70
|
+
)}
|
|
71
|
+
</Box>
|
|
29
72
|
);
|
|
30
73
|
}
|
|
31
74
|
);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M2 12C0.89543 12 -3.91405e-08 11.1046 -8.74228e-08 10L-4.37114e-07 2C-4.85396e-07 0.895431 0.89543 -3.91405e-08 2 -8.74228e-08L10 -4.37114e-07C11.1046 -4.85396e-07 12 0.89543 12 2L12 10C12 11.1046 11.1046 12 10 12L2 12ZM6 2.5C6.13261 2.5 6.25979 2.55268 6.35355 2.64645L7.85355 4.14645C8.04881 4.34171 8.04881 4.65829 7.85355 4.85355C7.65829 5.04882 7.34171 5.04882 7.14645 4.85355L6 3.70711L4.85355 4.85355C4.65829 5.04882 4.34171 5.04882 4.14645 4.85355C3.95118 4.65829 3.95118 4.34171 4.14645 4.14645L5.64645 2.64645C5.74021 2.55268 5.86739 2.5 6 2.5ZM5.64645 9.35355C5.74021 9.44732 5.86739 9.5 6 9.5C6.13261 9.5 6.25978 9.44732 6.35355 9.35355L7.85355 7.85355C8.04882 7.65829 8.04882 7.34171 7.85355 7.14645C7.65829 6.95118 7.34171 6.95118 7.14645 7.14645L6 8.29289L4.85355 7.14645C4.65829 6.95118 4.34171 6.95118 4.14645 7.14645C3.95118 7.34171 3.95118 7.65829 4.14645 7.85355L5.64645 9.35355Z" fill="#0082FF"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { Box } from '@chakra-ui/react';
|
|
3
|
+
import colors from 'src/theme/foundations/colors';
|
|
4
|
+
import { FieldOption, FieldOptions } from '../../InputTypes';
|
|
5
|
+
|
|
6
|
+
export interface DropdownProps {
|
|
7
|
+
onSelectItem: (option: FieldOption) => void;
|
|
8
|
+
options: FieldOptions;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A functional React component utilized to render the `Dropdown` component
|
|
13
|
+
*/
|
|
14
|
+
export const Dropdown: React.FC<DropdownProps> = ({
|
|
15
|
+
onSelectItem,
|
|
16
|
+
options,
|
|
17
|
+
}) => {
|
|
18
|
+
const DropdownContent = useMemo(() => {
|
|
19
|
+
return options.map((option, idx) => (
|
|
20
|
+
<>
|
|
21
|
+
{option.value === 'section_header' &&
|
|
22
|
+
options[idx + 1] &&
|
|
23
|
+
options[idx + 1].value !== 'section_header' && (
|
|
24
|
+
<Box
|
|
25
|
+
color={colors.label.secondary.light}
|
|
26
|
+
fontSize="13px"
|
|
27
|
+
fontWeight="bold"
|
|
28
|
+
px="8px"
|
|
29
|
+
>
|
|
30
|
+
{idx > 0 && (
|
|
31
|
+
<Box
|
|
32
|
+
my="3px"
|
|
33
|
+
borderTop="2px solid"
|
|
34
|
+
borderColor={colors.border.default}
|
|
35
|
+
/>
|
|
36
|
+
)}
|
|
37
|
+
{option.label}
|
|
38
|
+
</Box>
|
|
39
|
+
)}
|
|
40
|
+
{option.value !== 'section_header' && (
|
|
41
|
+
<Box
|
|
42
|
+
cursor="pointer"
|
|
43
|
+
borderRadius="inherit"
|
|
44
|
+
onClick={() => onSelectItem(option)}
|
|
45
|
+
key={option.value}
|
|
46
|
+
fontSize="13px"
|
|
47
|
+
px="8px"
|
|
48
|
+
py="4px"
|
|
49
|
+
color={colors.label.primary.light}
|
|
50
|
+
_hover={{
|
|
51
|
+
color: colors.label.primary.dark,
|
|
52
|
+
bg: colors.fill.blue,
|
|
53
|
+
borderRadius: '4px',
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
{option.label}
|
|
57
|
+
</Box>
|
|
58
|
+
)}
|
|
59
|
+
</>
|
|
60
|
+
));
|
|
61
|
+
}, [onSelectItem, options]);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Box
|
|
65
|
+
bg={colors.fill.light}
|
|
66
|
+
backdropFilter="blur(64px)"
|
|
67
|
+
borderRadius="4px"
|
|
68
|
+
mt="3px"
|
|
69
|
+
maxH="320px"
|
|
70
|
+
overflowY="auto"
|
|
71
|
+
px="8px"
|
|
72
|
+
py="4px"
|
|
73
|
+
position="absolute"
|
|
74
|
+
width="100%"
|
|
75
|
+
>
|
|
76
|
+
{DropdownContent}
|
|
77
|
+
</Box>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, FormLabel } from '@chakra-ui/react';
|
|
3
|
+
import colors from 'src/theme/foundations/colors';
|
|
4
|
+
|
|
5
|
+
export interface LabelProps {
|
|
6
|
+
label: string;
|
|
7
|
+
isRequired?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A functional React component utilized to render the `Label` component
|
|
12
|
+
*/
|
|
13
|
+
export const Label: React.FC<LabelProps> = ({ isRequired, label }) => {
|
|
14
|
+
return (
|
|
15
|
+
<FormLabel>
|
|
16
|
+
{label}
|
|
17
|
+
{isRequired && (
|
|
18
|
+
<Box ml={1} color={colors.label.error}>
|
|
19
|
+
*
|
|
20
|
+
</Box>
|
|
21
|
+
)}
|
|
22
|
+
</FormLabel>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Meta, Story } from '@storybook/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Token, { TokenProps } from '.';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<TokenProps> = {
|
|
6
|
+
title: 'Token example',
|
|
7
|
+
component: Token,
|
|
8
|
+
argTypes: {},
|
|
9
|
+
parameters: {
|
|
10
|
+
controls: { expanded: true },
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
const Template: Story<TokenProps> = (args) => (
|
|
16
|
+
<Token {...args} onDelete={() => null} />
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const Default = Template.bind({});
|
|
20
|
+
Default.args = {
|
|
21
|
+
label: 'Label',
|
|
22
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="56" height="56" viewBox="0 0 56 56" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M27.9995 56C43.4635 56 55.9995 43.464 55.9995 28C55.9995 12.536 43.4635 0 27.9995 0C12.5355 0 -0.000488281 12.536 -0.000488281 28C-0.000488281 43.464 12.5355 56 27.9995 56ZM21.9807 18.2688C20.9555 17.2437 19.2935 17.2437 18.2684 18.2688C17.2432 19.294 17.2432 20.956 18.2684 21.9812L24.2872 28L18.2684 34.0188C17.2432 35.044 17.2432 36.706 18.2684 37.7312C19.2935 38.7563 20.9555 38.7563 21.9807 37.7312L27.9995 31.7123L34.0184 37.7312C35.0435 38.7563 36.7055 38.7563 37.7307 37.7312C38.7558 36.706 38.7558 35.044 37.7307 34.0188L31.7118 28L37.7307 21.9812C38.7558 20.956 38.7558 19.294 37.7307 18.2688C36.7055 17.2437 35.0435 17.2437 34.0184 18.2688L27.9995 24.2877L21.9807 18.2688Z" fill="#3C3C43" fill-opacity="0.6"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Flex, Image, Text } from '@chakra-ui/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import colors from 'src/theme/foundations/colors';
|
|
4
|
+
import CloseIcon from './assets/svg/close.svg';
|
|
5
|
+
|
|
6
|
+
export interface TokenProps {
|
|
7
|
+
label: any;
|
|
8
|
+
onDelete: any;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const Token: React.FC<TokenProps> = ({ label, onDelete }) => {
|
|
12
|
+
return (
|
|
13
|
+
<Flex
|
|
14
|
+
key={label}
|
|
15
|
+
borderRadius="full"
|
|
16
|
+
backgroundColor="#7676801F"
|
|
17
|
+
alignItems="center"
|
|
18
|
+
width="fit-content"
|
|
19
|
+
pl="8px"
|
|
20
|
+
pr="4px"
|
|
21
|
+
py="2px"
|
|
22
|
+
>
|
|
23
|
+
<Text color={colors.label.primary.light} fontSize="13px">
|
|
24
|
+
{label}
|
|
25
|
+
</Text>
|
|
26
|
+
<Image
|
|
27
|
+
pl="4px"
|
|
28
|
+
boxSize="16px"
|
|
29
|
+
src={CloseIcon}
|
|
30
|
+
onClick={onDelete}
|
|
31
|
+
cursor="pointer"
|
|
32
|
+
/>
|
|
33
|
+
</Flex>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default Token;
|
|
@@ -6,11 +6,9 @@ import StackedSelect from './StackedSelect/StackedSelect';
|
|
|
6
6
|
import StackedTextarea from './StackedTextarea/StackedTextarea';
|
|
7
7
|
import { FieldOptions, ValidationProps, InputType } from './InputTypes';
|
|
8
8
|
import {
|
|
9
|
-
Box,
|
|
10
9
|
FormControl,
|
|
11
10
|
FormErrorMessage,
|
|
12
11
|
FormHelperText,
|
|
13
|
-
FormLabel,
|
|
14
12
|
} from '@chakra-ui/react';
|
|
15
13
|
import {
|
|
16
14
|
Control,
|
|
@@ -24,6 +22,7 @@ import {
|
|
|
24
22
|
import StackedMultiSelect from './StackedMultiSelect';
|
|
25
23
|
import StackedPilledInput from './StackedPilledInput';
|
|
26
24
|
import StackedSwitch from './StackedSwitch';
|
|
25
|
+
import { Label } from './components/label';
|
|
27
26
|
|
|
28
27
|
export interface InputProps<T extends FieldValues> extends ValidationProps {
|
|
29
28
|
inputType: InputType;
|
|
@@ -36,8 +35,7 @@ export interface InputProps<T extends FieldValues> extends ValidationProps {
|
|
|
36
35
|
options?: FieldOptions;
|
|
37
36
|
maxLength?: number;
|
|
38
37
|
helperText?: React.ReactNode;
|
|
39
|
-
|
|
40
|
-
rightElement?: React.ReactNode;
|
|
38
|
+
|
|
41
39
|
control?: Control<T, any>;
|
|
42
40
|
onChange?: (args?: any) => void;
|
|
43
41
|
disabled?: boolean;
|
|
@@ -56,8 +54,7 @@ export function Input<T extends FieldValues>({
|
|
|
56
54
|
placeholder,
|
|
57
55
|
name,
|
|
58
56
|
helperText,
|
|
59
|
-
|
|
60
|
-
rightElement,
|
|
57
|
+
|
|
61
58
|
options,
|
|
62
59
|
isInvalid,
|
|
63
60
|
errorText,
|
|
@@ -87,8 +84,6 @@ export function Input<T extends FieldValues>({
|
|
|
87
84
|
placeholder={placeholder}
|
|
88
85
|
maxLength={maxLength}
|
|
89
86
|
isRequired={isRequired}
|
|
90
|
-
leftElement={leftElement}
|
|
91
|
-
rightElement={rightElement}
|
|
92
87
|
isInvalid={isInvalid}
|
|
93
88
|
onChange={onChange}
|
|
94
89
|
onBlur={onBlur}
|
|
@@ -124,9 +119,12 @@ export function Input<T extends FieldValues>({
|
|
|
124
119
|
options={options as FieldOptions}
|
|
125
120
|
onChange={onChange}
|
|
126
121
|
onBlur={onBlur}
|
|
122
|
+
setValue={setValue as UseFormSetValue<FieldValues>}
|
|
123
|
+
control={control as Control<FieldValues, any>}
|
|
127
124
|
ref={ref}
|
|
128
125
|
disabled={disabled}
|
|
129
126
|
value={value}
|
|
127
|
+
placeholder={placeholder}
|
|
130
128
|
/>
|
|
131
129
|
);
|
|
132
130
|
case 'textarea':
|
|
@@ -176,6 +174,7 @@ export function Input<T extends FieldValues>({
|
|
|
176
174
|
value={value}
|
|
177
175
|
setValue={setValue as UseFormSetValue<FieldValues>}
|
|
178
176
|
control={control as Control<FieldValues, any>}
|
|
177
|
+
placeholder={placeholder}
|
|
179
178
|
/>
|
|
180
179
|
);
|
|
181
180
|
case 'pilled-text':
|
|
@@ -220,12 +219,10 @@ export function Input<T extends FieldValues>({
|
|
|
220
219
|
inputType,
|
|
221
220
|
isInvalid,
|
|
222
221
|
isRequired,
|
|
223
|
-
leftElement,
|
|
224
222
|
maxLength,
|
|
225
223
|
name,
|
|
226
224
|
options,
|
|
227
225
|
placeholder,
|
|
228
|
-
rightElement,
|
|
229
226
|
setValue,
|
|
230
227
|
]
|
|
231
228
|
);
|
|
@@ -243,16 +240,7 @@ export function Input<T extends FieldValues>({
|
|
|
243
240
|
position="relative"
|
|
244
241
|
py={label ? 6 : 0}
|
|
245
242
|
>
|
|
246
|
-
{label &&
|
|
247
|
-
<FormLabel position="absolute" top={0} display="flex">
|
|
248
|
-
{label}
|
|
249
|
-
{isRequired && (
|
|
250
|
-
<Box ml={1} color="red.500">
|
|
251
|
-
*
|
|
252
|
-
</Box>
|
|
253
|
-
)}
|
|
254
|
-
</FormLabel>
|
|
255
|
-
)}
|
|
243
|
+
{label && <Label label={label} isRequired={isRequired} />}
|
|
256
244
|
{selectedInputField(
|
|
257
245
|
onChange ? onChange : fieldOnChange,
|
|
258
246
|
onBlur,
|
|
@@ -19,25 +19,25 @@ const baseStyle = {
|
|
|
19
19
|
|
|
20
20
|
function variantPositive() {
|
|
21
21
|
return {
|
|
22
|
-
container: { bg:
|
|
22
|
+
container: { bg: colors.fill.positive },
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function variantWarning() {
|
|
27
27
|
return {
|
|
28
|
-
container: { bg:
|
|
28
|
+
container: { bg: colors.fill.warning },
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function variantError() {
|
|
33
33
|
return {
|
|
34
|
-
container: { bg:
|
|
34
|
+
container: { bg: colors.fill.error },
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function variantNeutral() {
|
|
39
39
|
return {
|
|
40
|
-
container: { bg:
|
|
40
|
+
container: { bg: colors.fill.light },
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
|