@xqmsg/ui-core 0.15.0 → 0.15.2
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/ui-core.cjs.development.js +50 -42
- 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 +50 -42
- package/dist/ui-core.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/input/Input.stories.tsx +44 -68
- package/src/components/input/StackedMultiSelect/index.tsx +4 -4
- package/src/components/input/StackedPilledInput/index.tsx +53 -24
- package/src/components/input/StackedSelect/StackedSelect.tsx +4 -2
package/package.json
CHANGED
|
@@ -99,74 +99,50 @@ const Template: Story<InputProps<StoryFormSchema>> = args => {
|
|
|
99
99
|
|
|
100
100
|
return (
|
|
101
101
|
<Form formHandler={formHandler}>
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
<Input
|
|
148
|
-
{...args}
|
|
149
|
-
name="prop6"
|
|
150
|
-
inputType="checkbox"
|
|
151
|
-
setValue={form.setValue}
|
|
152
|
-
/>{' '}
|
|
153
|
-
<Input
|
|
154
|
-
{...args}
|
|
155
|
-
inputType="multi-select"
|
|
156
|
-
setValue={form.setValue}
|
|
157
|
-
setError={form.setError}
|
|
158
|
-
clearErrors={form.clearErrors}
|
|
159
|
-
isInvalid={!!form.formState.errors['prop5']?.message}
|
|
160
|
-
errorText={form.formState.errors['prop5']?.message}
|
|
161
|
-
name="prop5"
|
|
162
|
-
/>
|
|
163
|
-
<Input
|
|
164
|
-
{...args}
|
|
165
|
-
inputType="select"
|
|
166
|
-
setValue={form.setValue}
|
|
167
|
-
name="prop4"
|
|
168
|
-
/>
|
|
169
|
-
</Box>
|
|
102
|
+
<Input
|
|
103
|
+
{...args}
|
|
104
|
+
inputType="multi-select"
|
|
105
|
+
setValue={form.setValue}
|
|
106
|
+
setError={form.setError}
|
|
107
|
+
clearErrors={form.clearErrors}
|
|
108
|
+
isInvalid={!!form.formState.errors['prop5']?.message}
|
|
109
|
+
errorText={form.formState.errors['prop5']?.message}
|
|
110
|
+
name="prop5"
|
|
111
|
+
/>
|
|
112
|
+
<Input
|
|
113
|
+
{...args}
|
|
114
|
+
inputType="text"
|
|
115
|
+
name="prop3"
|
|
116
|
+
onChange={e => form.setValue('prop3', e.target.value)}
|
|
117
|
+
/>
|
|
118
|
+
<Input
|
|
119
|
+
{...args}
|
|
120
|
+
inputType="textarea"
|
|
121
|
+
name="prop2"
|
|
122
|
+
onChange={e => form.setValue('prop2', e.target.value)}
|
|
123
|
+
/>
|
|
124
|
+
<Input
|
|
125
|
+
{...args}
|
|
126
|
+
name="prop"
|
|
127
|
+
inputType="pilled-text"
|
|
128
|
+
setValue={form.setValue}
|
|
129
|
+
setError={form.setError}
|
|
130
|
+
clearErrors={form.clearErrors}
|
|
131
|
+
isInvalid={!!form.formState.errors['prop']?.message}
|
|
132
|
+
errorText={form.formState.errors['prop']?.message}
|
|
133
|
+
/>
|
|
134
|
+
<Input
|
|
135
|
+
{...args}
|
|
136
|
+
inputType="select"
|
|
137
|
+
setValue={form.setValue}
|
|
138
|
+
name="prop4"
|
|
139
|
+
/>
|
|
140
|
+
<Input
|
|
141
|
+
{...args}
|
|
142
|
+
name="prop6"
|
|
143
|
+
inputType="switch"
|
|
144
|
+
setValue={form.setValue}
|
|
145
|
+
/>
|
|
170
146
|
</Form>
|
|
171
147
|
);
|
|
172
148
|
};
|
|
@@ -52,15 +52,15 @@ const StackedMultiSelect = React.forwardRef<
|
|
|
52
52
|
const [shouldSideScroll, setShouldSideScroll] = useState(false);
|
|
53
53
|
const [position, setPosition] = useState<'top' | 'bottom'>('top');
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
const boundingClientRect = dropdownRef.current?.getBoundingClientRect() as DOMRect;
|
|
55
|
+
const boundingClientRect = dropdownRef.current?.getBoundingClientRect() as DOMRect;
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (window.innerHeight - (boundingClientRect?.y + 240) >= 0) {
|
|
59
59
|
setPosition('top');
|
|
60
60
|
} else {
|
|
61
61
|
setPosition('bottom');
|
|
62
62
|
}
|
|
63
|
-
}, [
|
|
63
|
+
}, [boundingClientRect]);
|
|
64
64
|
|
|
65
65
|
useOutsideClick({
|
|
66
66
|
ref: dropdownRef,
|
|
@@ -37,9 +37,12 @@ const StackedPilledInput = React.forwardRef<
|
|
|
37
37
|
|
|
38
38
|
const [tokenIndex, setTokenIndex] = useState<number | null>(null);
|
|
39
39
|
const [isFocussed, setIsFocussed] = useState(false);
|
|
40
|
-
const [shouldSideScroll, setShouldSideScroll] = useState(false);
|
|
41
40
|
const [localValue, setLocalValue] = useState('');
|
|
42
41
|
|
|
42
|
+
const latestTokenElement = document.getElementById(
|
|
43
|
+
`${name}_token_${lastestFormValueToArray.length - 1}`
|
|
44
|
+
);
|
|
45
|
+
|
|
43
46
|
// gets latest watched form value (common delimited) from RHF state and creates a list
|
|
44
47
|
useEffect(() => {
|
|
45
48
|
if (watchedValue !== undefined && !watchedValue.length) {
|
|
@@ -47,21 +50,19 @@ const StackedPilledInput = React.forwardRef<
|
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
if (watchedValue !== undefined && watchedValue?.length) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
setLatestFormValueToArray(watchedValue.split(',').filter(Boolean));
|
|
54
|
+
|
|
55
|
+
if (latestTokenElement) {
|
|
56
|
+
latestTokenElement.scrollIntoView({
|
|
57
|
+
block: 'end',
|
|
58
|
+
inline: 'center',
|
|
53
59
|
behavior: 'smooth',
|
|
54
60
|
});
|
|
55
|
-
setShouldSideScroll(false);
|
|
56
61
|
}
|
|
57
|
-
|
|
58
|
-
setLatestFormValueToArray(watchedValue.split(',').filter(Boolean));
|
|
59
62
|
}
|
|
60
|
-
}, [
|
|
63
|
+
}, [latestTokenElement, watchedValue]);
|
|
61
64
|
|
|
62
65
|
const onHandleKeyDown = (e: React.KeyboardEvent) => {
|
|
63
|
-
setShouldSideScroll(true);
|
|
64
|
-
|
|
65
66
|
if (
|
|
66
67
|
e.key === ' ' ||
|
|
67
68
|
e.key === 'Enter' ||
|
|
@@ -101,7 +102,7 @@ const StackedPilledInput = React.forwardRef<
|
|
|
101
102
|
|
|
102
103
|
setLocalValue('');
|
|
103
104
|
|
|
104
|
-
setValue(
|
|
105
|
+
return setValue(
|
|
105
106
|
name as string,
|
|
106
107
|
filteredUniqueValues.toString().replace(/\s/g, ''),
|
|
107
108
|
{
|
|
@@ -109,8 +110,6 @@ const StackedPilledInput = React.forwardRef<
|
|
|
109
110
|
shouldDirty: true,
|
|
110
111
|
}
|
|
111
112
|
);
|
|
112
|
-
|
|
113
|
-
return setIsFocussed(false);
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
if (!localValue.trim().length && lastestFormValueToArray.length) {
|
|
@@ -149,7 +148,18 @@ const StackedPilledInput = React.forwardRef<
|
|
|
149
148
|
return setTokenIndex(lastestFormValueToArray.length - 1);
|
|
150
149
|
}
|
|
151
150
|
|
|
152
|
-
|
|
151
|
+
setTokenIndex(prevTokenIndex => (prevTokenIndex as number) - 1);
|
|
152
|
+
|
|
153
|
+
const tokenElement = document.getElementById(
|
|
154
|
+
`${name}_token_${tokenIndex}`
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
if (!tokenElement || !scrollRef.current) return;
|
|
158
|
+
|
|
159
|
+
return scrollRef.current.scrollBy({
|
|
160
|
+
left: -1 * tokenElement.getBoundingClientRect().width,
|
|
161
|
+
behavior: 'smooth',
|
|
162
|
+
});
|
|
153
163
|
}
|
|
154
164
|
|
|
155
165
|
if (e.key === 'ArrowRight') {
|
|
@@ -158,7 +168,18 @@ const StackedPilledInput = React.forwardRef<
|
|
|
158
168
|
if (tokenIndex === lastestFormValueToArray.length - 1) {
|
|
159
169
|
return setTokenIndex(null);
|
|
160
170
|
}
|
|
161
|
-
|
|
171
|
+
setTokenIndex(prevTokenIndex => (prevTokenIndex as number) + 1);
|
|
172
|
+
|
|
173
|
+
const tokenElement = document.getElementById(
|
|
174
|
+
`${name}_token_${tokenIndex}`
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
if (!tokenElement || !scrollRef.current) return;
|
|
178
|
+
|
|
179
|
+
return scrollRef.current.scrollBy({
|
|
180
|
+
left: tokenElement.getBoundingClientRect().width,
|
|
181
|
+
behavior: 'smooth',
|
|
182
|
+
});
|
|
162
183
|
}
|
|
163
184
|
}
|
|
164
185
|
};
|
|
@@ -183,7 +204,7 @@ const StackedPilledInput = React.forwardRef<
|
|
|
183
204
|
const onBlur = () => {
|
|
184
205
|
clearErrors(name);
|
|
185
206
|
|
|
186
|
-
if (localValue.trim()) {
|
|
207
|
+
if (localValue.trim().length) {
|
|
187
208
|
const filteredUniqueValues = Array.from(
|
|
188
209
|
new Set([...lastestFormValueToArray, ...localValue.trim().split(',')])
|
|
189
210
|
);
|
|
@@ -209,7 +230,6 @@ const StackedPilledInput = React.forwardRef<
|
|
|
209
230
|
fontSize="13px"
|
|
210
231
|
border={isFocussed ? '2px solid' : '1px solid'}
|
|
211
232
|
borderColor={isFocussed ? colors.border.focus : colors.border.default}
|
|
212
|
-
py="5px"
|
|
213
233
|
pl="8px"
|
|
214
234
|
borderRadius="4px"
|
|
215
235
|
alignItems="center"
|
|
@@ -225,11 +245,11 @@ const StackedPilledInput = React.forwardRef<
|
|
|
225
245
|
h="26px"
|
|
226
246
|
>
|
|
227
247
|
<Flex
|
|
228
|
-
h="
|
|
248
|
+
h="100%"
|
|
229
249
|
alignItems="center"
|
|
230
|
-
// width="fit-content"
|
|
231
|
-
// maxW="80%"
|
|
232
250
|
overflowX="scroll"
|
|
251
|
+
overflowY="hidden"
|
|
252
|
+
maxWidth={isFocussed ? '80%' : '100%'}
|
|
233
253
|
style={{
|
|
234
254
|
scrollbarWidth: 'none' /* Firefox */,
|
|
235
255
|
msOverflowStyle: 'none',
|
|
@@ -251,8 +271,9 @@ const StackedPilledInput = React.forwardRef<
|
|
|
251
271
|
: 'none'
|
|
252
272
|
}
|
|
253
273
|
borderRadius="full"
|
|
254
|
-
onClick={() => setTokenIndex(index)}
|
|
274
|
+
onClick={() => isFocussed && setTokenIndex(index)}
|
|
255
275
|
width="100%"
|
|
276
|
+
id={`${name}_token_${index}`}
|
|
256
277
|
>
|
|
257
278
|
<Token
|
|
258
279
|
label={label}
|
|
@@ -270,18 +291,26 @@ const StackedPilledInput = React.forwardRef<
|
|
|
270
291
|
</Text>
|
|
271
292
|
)}
|
|
272
293
|
</Flex>
|
|
273
|
-
<Flex flex={1}>
|
|
294
|
+
<Flex flex={1} minWidth={isFocussed ? '20%' : 0}>
|
|
274
295
|
<Input
|
|
275
296
|
onKeyDown={onHandleKeyDown}
|
|
276
297
|
type="text"
|
|
277
298
|
padding={0}
|
|
278
|
-
|
|
299
|
+
alignContent="flex-start"
|
|
300
|
+
float="right"
|
|
279
301
|
border="none"
|
|
280
302
|
height="auto"
|
|
281
303
|
color={tokenIndex !== null ? 'transparent' : colors.label.primary}
|
|
282
304
|
_focus={{ boxShadow: 'none !important' }}
|
|
283
305
|
value={localValue}
|
|
284
|
-
onChange={e =>
|
|
306
|
+
onChange={e =>
|
|
307
|
+
tokenIndex === null &&
|
|
308
|
+
setLocalValue(
|
|
309
|
+
e.target.value.trim().replace(',', '').length
|
|
310
|
+
? e.target.value
|
|
311
|
+
: ''
|
|
312
|
+
)
|
|
313
|
+
}
|
|
285
314
|
ref={inputRef}
|
|
286
315
|
onFocus={() => setIsFocussed(true)}
|
|
287
316
|
onBlur={() => setIsFocussed(false)}
|
|
@@ -39,15 +39,17 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
|
|
|
39
39
|
);
|
|
40
40
|
const [position, setPosition] = useState<'top' | 'bottom'>('top');
|
|
41
41
|
|
|
42
|
+
const boundingClientRect = dropdownRef.current?.getBoundingClientRect() as DOMRect;
|
|
43
|
+
|
|
42
44
|
useEffect(() => {
|
|
43
45
|
const boundingClientRect = dropdownRef.current?.getBoundingClientRect() as DOMRect;
|
|
44
46
|
|
|
45
|
-
if (
|
|
47
|
+
if (window.innerHeight - (boundingClientRect?.y + 240) >= 0) {
|
|
46
48
|
setPosition('top');
|
|
47
49
|
} else {
|
|
48
50
|
setPosition('bottom');
|
|
49
51
|
}
|
|
50
|
-
}, [
|
|
52
|
+
}, [boundingClientRect]);
|
|
51
53
|
|
|
52
54
|
useDidMountEffect(() => {
|
|
53
55
|
setSelectedOption(
|