@xqmsg/ui-core 0.25.0 → 0.25.1

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,5 +1,5 @@
1
1
  {
2
- "version": "0.25.0",
2
+ "version": "0.25.1",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -14,9 +14,9 @@ export const Close: React.FC<CloseProps> = ({ boxSize, onClick }) => {
14
14
  <CloseIcon
15
15
  width={boxSize}
16
16
  height={boxSize}
17
- flexBasis={boxSize}
18
17
  onClick={onClick}
19
18
  cursor="pointer"
19
+ style={{ flexBasis: boxSize, cursor: 'pointer' }}
20
20
  />
21
21
  );
22
22
  };
@@ -150,19 +150,58 @@ const StackedPilledInput = React.forwardRef<
150
150
  });
151
151
  }
152
152
 
153
- if (!localValue.trim().length && lastestFormValueToArray.length) {
154
- if (e.key === 'Backspace' && tokenIndex !== null) {
155
- setLocalValue(
156
- lastestFormValueToArray[tokenIndex].substring(
157
- 0,
158
- lastestFormValueToArray[tokenIndex].length
159
- )
160
- );
153
+ if (e.key === 'Backspace') {
154
+ // If input is empty and there are tokens
155
+ if (!localValue.length && lastestFormValueToArray.length) {
156
+ // If a token is selected, move it to input
157
+ if (tokenIndex !== null) {
158
+ setLocalValue(
159
+ lastestFormValueToArray[tokenIndex].substring(
160
+ 0,
161
+ lastestFormValueToArray[tokenIndex].length
162
+ )
163
+ );
164
+
165
+ const filteredUniqueValues = Array.from(
166
+ new Set(
167
+ [...lastestFormValueToArray].filter(
168
+ value => value !== lastestFormValueToArray[tokenIndex]
169
+ )
170
+ )
171
+ );
172
+
173
+ setValue(name as string, filteredUniqueValues.toString(), {
174
+ shouldValidate: true,
175
+ shouldDirty: true,
176
+ });
177
+
178
+ return setTokenIndex(null);
179
+ } else {
180
+ // No token selected, move last token to input
181
+ const lastToken =
182
+ lastestFormValueToArray[lastestFormValueToArray.length - 1];
183
+ setLocalValue(lastToken);
184
+
185
+ const filteredUniqueValues = lastestFormValueToArray.slice(0, -1);
161
186
 
187
+ setValue(name as string, filteredUniqueValues.toString(), {
188
+ shouldValidate: true,
189
+ shouldDirty: true,
190
+ });
191
+
192
+ e.preventDefault();
193
+ return;
194
+ }
195
+ }
196
+ }
197
+
198
+ if (e.key === 'Delete') {
199
+ // If a token is selected, remove it completely
200
+ if (tokenIndex !== null && lastestFormValueToArray.length) {
162
201
  const filteredUniqueValues = Array.from(
163
202
  new Set(
164
203
  [...lastestFormValueToArray].filter(
165
- value => value !== lastestFormValueToArray[tokenIndex]
204
+ (_, index) => index !== tokenIndex
166
205
  )
167
206
  )
168
207
  );
@@ -172,9 +211,13 @@ const StackedPilledInput = React.forwardRef<
172
211
  shouldDirty: true,
173
212
  });
174
213
 
175
- return setTokenIndex(null);
214
+ setTokenIndex(null);
215
+ e.preventDefault();
216
+ return;
176
217
  }
218
+ }
177
219
 
220
+ if (!localValue.trim().length && lastestFormValueToArray.length) {
178
221
  if (e.key === 'ArrowLeft') {
179
222
  if (tokenIndex === 0) return;
180
223
 
@@ -312,29 +355,37 @@ const StackedPilledInput = React.forwardRef<
312
355
  },
313
356
  }}
314
357
  ref={scrollRef}
315
- zIndex={99}
316
358
  onKeyDown={onHandleKeyDown}
317
359
  >
318
360
  {lastestFormValueToArray.length
319
361
  ? lastestFormValueToArray.map((label, index) => (
320
362
  <Box
321
363
  key={index}
322
- mr="4px"
364
+ mr="2px"
323
365
  border={
324
366
  tokenIndex === index
325
367
  ? `1px solid ${colors.border.focus}`
326
368
  : 'none'
327
369
  }
328
- borderRadius="full"
329
- onClick={() => setTokenIndex(index)}
370
+ borderRadius="md"
371
+ onClick={e => {
372
+ e.stopPropagation();
373
+ // Don't change selection if clicking on already selected token
374
+ if (tokenIndex === index) {
375
+ return;
376
+ }
377
+ setTokenIndex(index);
378
+ }}
330
379
  width={scrollMode ? '100%' : 'auto'}
331
380
  maxWidth={'100%'}
332
381
  id={`${name}_token_${index}`}
382
+ cursor="default"
333
383
  >
334
384
  <Token
335
385
  maxWidth={'100%'}
336
386
  label={label}
337
- showClose={!isFocussed || tokenIndex === index}
387
+ showClose={true}
388
+ isSelected={tokenIndex === index}
338
389
  onDelete={(e: any) => {
339
390
  e.stopPropagation();
340
391
  e.preventDefault();
@@ -350,6 +401,7 @@ const StackedPilledInput = React.forwardRef<
350
401
  <Text
351
402
  color={colors.label.secondary.light}
352
403
  fontSize={isMobile ? '17px' : '13px'}
404
+ pointerEvents="none"
353
405
  >
354
406
  {placeholder}
355
407
  </Text>
@@ -373,10 +425,6 @@ const StackedPilledInput = React.forwardRef<
373
425
  onChange={handleOnChange}
374
426
  ref={inputRef}
375
427
  onFocus={() => setIsFocussed(true)}
376
- onBlur={() => {
377
- setIsFocussed(false);
378
- return setTokenIndex(null);
379
- }}
380
428
  placeholder={
381
429
  isMobile && label && lastestFormValueToArray.length === 0
382
430
  ? (label as string)
@@ -11,6 +11,7 @@ export interface TokenProps {
11
11
  truncateLength?: number;
12
12
  showClose?: boolean;
13
13
  maxWidth?: string | number;
14
+ isSelected?: boolean;
14
15
  }
15
16
 
16
17
  // For v1 we are truncating the label at 15 characters to avoid overflow
@@ -21,28 +22,35 @@ const Token: React.FC<TokenProps> = ({
21
22
  truncateLength = 15,
22
23
  showClose = true,
23
24
  maxWidth = 'auto',
25
+ isSelected = false,
24
26
  }) => {
27
+ // in pixels
28
+ const closeBoxSize = isMobile ? 20 : 15;
29
+ const closeBoxGap = isMobile ? 4 : 2;
30
+ const closeBoxPadding = closeBoxSize + closeBoxGap;
25
31
  return (
26
32
  <Flex
27
33
  key={label}
28
- borderRadius={'full'}
34
+ borderRadius={'md'}
29
35
  backgroundColor="#7676801F"
30
36
  alignItems="center"
31
37
  width="fit-content"
32
38
  w="auto"
33
39
  maxWidth={maxWidth}
34
- h={isMobile ? '18px' : '16px'}
35
- pl="6px"
36
- pr="2px"
40
+ h={'18px'}
41
+ px="4px"
37
42
  py="2px"
43
+ pr={showClose ? closeBoxPadding : '4px'}
38
44
  position="relative"
45
+ cursor="default"
39
46
  >
40
47
  <Text
41
48
  whiteSpace="nowrap"
42
49
  wordBreak="break-word"
43
50
  color={colors.label.primary.light}
44
51
  fontSize={isMobile ? '17px' : '13px'}
45
- pr="4px"
52
+ lineHeight={isMobile ? '17px' : '13px'}
53
+ pr="2px"
46
54
  maxWidth={maxWidth}
47
55
  overflow="hidden"
48
56
  textOverflow="ellipsis"
@@ -53,7 +61,18 @@ const Token: React.FC<TokenProps> = ({
53
61
  })}
54
62
  </Text>
55
63
  {showClose && (
56
- <Close boxSize={isMobile ? '17px' : '11px'} onClick={onDelete} />
64
+ <Flex
65
+ height="100%"
66
+ position="absolute"
67
+ top={0}
68
+ bottom={0}
69
+ right={0}
70
+ justifyContent="center"
71
+ alignItems="center"
72
+ cursor={isSelected ? 'default' : 'pointer'}
73
+ >
74
+ <Close boxSize={`${closeBoxSize}px`} onClick={onDelete} />
75
+ </Flex>
57
76
  )}
58
77
  </Flex>
59
78
  );