@ttoss/ui 4.0.1 → 4.0.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/esm/index.js +29 -5
- package/dist/index.d.mts +14 -6
- package/dist/index.d.ts +14 -6
- package/dist/index.js +29 -5
- package/package.json +4 -4
- package/src/components/Select.tsx +42 -7
package/dist/esm/index.js
CHANGED
|
@@ -360,7 +360,8 @@ var ValueContainer = ({
|
|
|
360
360
|
}) => {
|
|
361
361
|
const {
|
|
362
362
|
leadingIcon,
|
|
363
|
-
trailingIcon
|
|
363
|
+
trailingIcon,
|
|
364
|
+
isSearchable
|
|
364
365
|
} = props.selectProps;
|
|
365
366
|
const hasError = props.selectProps["aria-invalid"] === "true";
|
|
366
367
|
const trailingIconColor = (() => {
|
|
@@ -369,12 +370,18 @@ var ValueContainer = ({
|
|
|
369
370
|
}
|
|
370
371
|
return "text";
|
|
371
372
|
})();
|
|
373
|
+
const finalLeadingIcon = (() => {
|
|
374
|
+
if (!isSearchable) {
|
|
375
|
+
return leadingIcon;
|
|
376
|
+
}
|
|
377
|
+
return leadingIcon || "search";
|
|
378
|
+
})();
|
|
372
379
|
return /* @__PURE__ */jsxs6(Flex, {
|
|
373
380
|
sx: {
|
|
374
381
|
gap: "lg",
|
|
375
382
|
flex: 1
|
|
376
383
|
},
|
|
377
|
-
children: [
|
|
384
|
+
children: [finalLeadingIcon && /* @__PURE__ */jsx7(Text, {
|
|
378
385
|
sx: {
|
|
379
386
|
alignSelf: "center",
|
|
380
387
|
pointerEvents: "none",
|
|
@@ -382,7 +389,7 @@ var ValueContainer = ({
|
|
|
382
389
|
fontSize: "base"
|
|
383
390
|
},
|
|
384
391
|
children: /* @__PURE__ */jsx7(Icon5, {
|
|
385
|
-
icon:
|
|
392
|
+
icon: finalLeadingIcon
|
|
386
393
|
})
|
|
387
394
|
}), /* @__PURE__ */jsx7(Flex, {
|
|
388
395
|
sx: {
|
|
@@ -408,6 +415,12 @@ var ValueContainer = ({
|
|
|
408
415
|
var Select = /*#__PURE__*/React4.forwardRef(({
|
|
409
416
|
...props
|
|
410
417
|
}, ref) => {
|
|
418
|
+
const value = props.options?.find(option => {
|
|
419
|
+
if ("value" in option) {
|
|
420
|
+
return option.value === props.value;
|
|
421
|
+
}
|
|
422
|
+
return false;
|
|
423
|
+
});
|
|
411
424
|
return /* @__PURE__ */jsx7(ReactSelect, {
|
|
412
425
|
ref,
|
|
413
426
|
components: {
|
|
@@ -416,11 +429,22 @@ var Select = /*#__PURE__*/React4.forwardRef(({
|
|
|
416
429
|
IndicatorsContainer,
|
|
417
430
|
Placeholder,
|
|
418
431
|
SelectContainer,
|
|
419
|
-
ValueContainer
|
|
420
|
-
...props.components
|
|
432
|
+
ValueContainer
|
|
421
433
|
},
|
|
422
434
|
isDisabled: props.disabled,
|
|
423
435
|
...props,
|
|
436
|
+
value,
|
|
437
|
+
onChange: value2 => {
|
|
438
|
+
props.onChange?.(value2?.value);
|
|
439
|
+
},
|
|
440
|
+
styles: {
|
|
441
|
+
input: baseStyles => {
|
|
442
|
+
return {
|
|
443
|
+
...baseStyles,
|
|
444
|
+
position: "absolute"
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
},
|
|
424
448
|
classNamePrefix: "react-select"
|
|
425
449
|
});
|
|
426
450
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -6,9 +6,6 @@ export { Keyframes, keyframes } from '@emotion/react';
|
|
|
6
6
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
import { IconType } from '@ttoss/react-icons';
|
|
9
|
-
import * as react_select_dist_declarations_src_useStateManager from 'react-select/dist/declarations/src/useStateManager';
|
|
10
|
-
import * as react_select_dist_declarations_src_Select from 'react-select/dist/declarations/src/Select';
|
|
11
|
-
import * as react_select from 'react-select';
|
|
12
9
|
import { Props } from 'react-select';
|
|
13
10
|
|
|
14
11
|
type ThemeProviderProps = {
|
|
@@ -54,16 +51,25 @@ type LinkProps = LinkProps$1 & {
|
|
|
54
51
|
};
|
|
55
52
|
declare const Link: React.ForwardRefExoticComponent<Omit<LinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
56
53
|
|
|
54
|
+
/**
|
|
55
|
+
* We're using React Select component to build ttoss Select.
|
|
56
|
+
* More info about React Select: https://react-select.com/home
|
|
57
|
+
* ttoss Figma: https://www.figma.com/file/VrB76VkH4hKCDUe9iYhpYu/_Component-%2F-Forms-%2F-Select?type=design&mode=design&t=ZBIeOpqcvQn3yq2t-0
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
type SelectOptionValue = string;
|
|
57
61
|
type SelectOption = {
|
|
58
62
|
label: string;
|
|
59
|
-
value:
|
|
63
|
+
value: SelectOptionValue;
|
|
60
64
|
};
|
|
61
65
|
type SelectOptions = SelectOption[];
|
|
62
66
|
/**
|
|
63
67
|
* TODO: remove this when we accept multi select.
|
|
64
68
|
*/
|
|
65
69
|
type IsMulti = false;
|
|
66
|
-
type SelectProps = Props<SelectOption, IsMulti> & SxProp & {
|
|
70
|
+
type SelectProps = Omit<Props<SelectOption, IsMulti>, 'styles' | 'value' | 'onChange' | 'components'> & SxProp & {
|
|
71
|
+
value?: SelectOptionValue;
|
|
72
|
+
onChange?: (value: SelectOptionValue | undefined) => void;
|
|
67
73
|
disabled?: boolean;
|
|
68
74
|
leadingIcon?: IconType;
|
|
69
75
|
trailingIcon?: IconType;
|
|
@@ -71,7 +77,9 @@ type SelectProps = Props<SelectOption, IsMulti> & SxProp & {
|
|
|
71
77
|
/**
|
|
72
78
|
* https://react-select.com/home
|
|
73
79
|
*/
|
|
74
|
-
declare const Select: React.ForwardRefExoticComponent<Omit<
|
|
80
|
+
declare const Select: React.ForwardRefExoticComponent<Omit<Props<SelectOption, false>, "styles" | "onChange" | "value" | "components"> & SxProp & {
|
|
81
|
+
value?: string | undefined;
|
|
82
|
+
onChange?: ((value: SelectOptionValue | undefined) => void) | undefined;
|
|
75
83
|
disabled?: boolean | undefined;
|
|
76
84
|
leadingIcon?: IconType | undefined;
|
|
77
85
|
trailingIcon?: IconType | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,9 +6,6 @@ export { Keyframes, keyframes } from '@emotion/react';
|
|
|
6
6
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
import { IconType } from '@ttoss/react-icons';
|
|
9
|
-
import * as react_select_dist_declarations_src_useStateManager from 'react-select/dist/declarations/src/useStateManager';
|
|
10
|
-
import * as react_select_dist_declarations_src_Select from 'react-select/dist/declarations/src/Select';
|
|
11
|
-
import * as react_select from 'react-select';
|
|
12
9
|
import { Props } from 'react-select';
|
|
13
10
|
|
|
14
11
|
type ThemeProviderProps = {
|
|
@@ -54,16 +51,25 @@ type LinkProps = LinkProps$1 & {
|
|
|
54
51
|
};
|
|
55
52
|
declare const Link: React.ForwardRefExoticComponent<Omit<LinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
56
53
|
|
|
54
|
+
/**
|
|
55
|
+
* We're using React Select component to build ttoss Select.
|
|
56
|
+
* More info about React Select: https://react-select.com/home
|
|
57
|
+
* ttoss Figma: https://www.figma.com/file/VrB76VkH4hKCDUe9iYhpYu/_Component-%2F-Forms-%2F-Select?type=design&mode=design&t=ZBIeOpqcvQn3yq2t-0
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
type SelectOptionValue = string;
|
|
57
61
|
type SelectOption = {
|
|
58
62
|
label: string;
|
|
59
|
-
value:
|
|
63
|
+
value: SelectOptionValue;
|
|
60
64
|
};
|
|
61
65
|
type SelectOptions = SelectOption[];
|
|
62
66
|
/**
|
|
63
67
|
* TODO: remove this when we accept multi select.
|
|
64
68
|
*/
|
|
65
69
|
type IsMulti = false;
|
|
66
|
-
type SelectProps = Props<SelectOption, IsMulti> & SxProp & {
|
|
70
|
+
type SelectProps = Omit<Props<SelectOption, IsMulti>, 'styles' | 'value' | 'onChange' | 'components'> & SxProp & {
|
|
71
|
+
value?: SelectOptionValue;
|
|
72
|
+
onChange?: (value: SelectOptionValue | undefined) => void;
|
|
67
73
|
disabled?: boolean;
|
|
68
74
|
leadingIcon?: IconType;
|
|
69
75
|
trailingIcon?: IconType;
|
|
@@ -71,7 +77,9 @@ type SelectProps = Props<SelectOption, IsMulti> & SxProp & {
|
|
|
71
77
|
/**
|
|
72
78
|
* https://react-select.com/home
|
|
73
79
|
*/
|
|
74
|
-
declare const Select: React.ForwardRefExoticComponent<Omit<
|
|
80
|
+
declare const Select: React.ForwardRefExoticComponent<Omit<Props<SelectOption, false>, "styles" | "onChange" | "value" | "components"> & SxProp & {
|
|
81
|
+
value?: string | undefined;
|
|
82
|
+
onChange?: ((value: SelectOptionValue | undefined) => void) | undefined;
|
|
75
83
|
disabled?: boolean | undefined;
|
|
76
84
|
leadingIcon?: IconType | undefined;
|
|
77
85
|
trailingIcon?: IconType | undefined;
|
package/dist/index.js
CHANGED
|
@@ -436,7 +436,8 @@ var ValueContainer = ({
|
|
|
436
436
|
}) => {
|
|
437
437
|
const {
|
|
438
438
|
leadingIcon,
|
|
439
|
-
trailingIcon
|
|
439
|
+
trailingIcon,
|
|
440
|
+
isSearchable
|
|
440
441
|
} = props.selectProps;
|
|
441
442
|
const hasError = props.selectProps["aria-invalid"] === "true";
|
|
442
443
|
const trailingIconColor = (() => {
|
|
@@ -445,12 +446,18 @@ var ValueContainer = ({
|
|
|
445
446
|
}
|
|
446
447
|
return "text";
|
|
447
448
|
})();
|
|
449
|
+
const finalLeadingIcon = (() => {
|
|
450
|
+
if (!isSearchable) {
|
|
451
|
+
return leadingIcon;
|
|
452
|
+
}
|
|
453
|
+
return leadingIcon || "search";
|
|
454
|
+
})();
|
|
448
455
|
return /* @__PURE__ */(0, import_jsx_runtime7.jsxs)(import_theme_ui8.Flex, {
|
|
449
456
|
sx: {
|
|
450
457
|
gap: "lg",
|
|
451
458
|
flex: 1
|
|
452
459
|
},
|
|
453
|
-
children: [
|
|
460
|
+
children: [finalLeadingIcon && /* @__PURE__ */(0, import_jsx_runtime7.jsx)(import_theme_ui16.Text, {
|
|
454
461
|
sx: {
|
|
455
462
|
alignSelf: "center",
|
|
456
463
|
pointerEvents: "none",
|
|
@@ -458,7 +465,7 @@ var ValueContainer = ({
|
|
|
458
465
|
fontSize: "base"
|
|
459
466
|
},
|
|
460
467
|
children: /* @__PURE__ */(0, import_jsx_runtime7.jsx)(import_react_icons5.Icon, {
|
|
461
|
-
icon:
|
|
468
|
+
icon: finalLeadingIcon
|
|
462
469
|
})
|
|
463
470
|
}), /* @__PURE__ */(0, import_jsx_runtime7.jsx)(import_theme_ui8.Flex, {
|
|
464
471
|
sx: {
|
|
@@ -484,6 +491,12 @@ var ValueContainer = ({
|
|
|
484
491
|
var Select = React4.forwardRef(({
|
|
485
492
|
...props
|
|
486
493
|
}, ref) => {
|
|
494
|
+
const value = props.options?.find(option => {
|
|
495
|
+
if ("value" in option) {
|
|
496
|
+
return option.value === props.value;
|
|
497
|
+
}
|
|
498
|
+
return false;
|
|
499
|
+
});
|
|
487
500
|
return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(import_react_select.default, {
|
|
488
501
|
ref,
|
|
489
502
|
components: {
|
|
@@ -492,11 +505,22 @@ var Select = React4.forwardRef(({
|
|
|
492
505
|
IndicatorsContainer,
|
|
493
506
|
Placeholder,
|
|
494
507
|
SelectContainer,
|
|
495
|
-
ValueContainer
|
|
496
|
-
...props.components
|
|
508
|
+
ValueContainer
|
|
497
509
|
},
|
|
498
510
|
isDisabled: props.disabled,
|
|
499
511
|
...props,
|
|
512
|
+
value,
|
|
513
|
+
onChange: value2 => {
|
|
514
|
+
props.onChange?.(value2?.value);
|
|
515
|
+
},
|
|
516
|
+
styles: {
|
|
517
|
+
input: baseStyles => {
|
|
518
|
+
return {
|
|
519
|
+
...baseStyles,
|
|
520
|
+
position: "absolute"
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
},
|
|
500
524
|
classNamePrefix: "react-select"
|
|
501
525
|
});
|
|
502
526
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/ui",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Primitive layout, typographic, and other components for styling applications.",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"@theme-ui/match-media": "^0.16.1",
|
|
24
24
|
"react-select": "^5.8.0",
|
|
25
25
|
"theme-ui": "^0.16.1",
|
|
26
|
-
"@ttoss/theme": "^1.6.
|
|
26
|
+
"@ttoss/theme": "^1.6.8"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@emotion/react": "^11",
|
|
30
30
|
"react": ">=16.8.0",
|
|
31
|
-
"@ttoss/react-icons": "^0.2.
|
|
31
|
+
"@ttoss/react-icons": "^0.2.3"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@emotion/react": "^11.11.1",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"react": "^18.2.0",
|
|
40
40
|
"tsup": "^8.0.1",
|
|
41
41
|
"@ttoss/config": "^1.31.1",
|
|
42
|
-
"@ttoss/react-icons": "^0.2.
|
|
42
|
+
"@ttoss/react-icons": "^0.2.3",
|
|
43
43
|
"@ttoss/test-utils": "^2.0.0"
|
|
44
44
|
},
|
|
45
45
|
"keywords": [
|
|
@@ -18,9 +18,11 @@ import ReactSelect, {
|
|
|
18
18
|
components,
|
|
19
19
|
} from 'react-select';
|
|
20
20
|
|
|
21
|
+
type SelectOptionValue = string;
|
|
22
|
+
|
|
21
23
|
export type SelectOption = {
|
|
22
24
|
label: string;
|
|
23
|
-
value:
|
|
25
|
+
value: SelectOptionValue;
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
export type SelectOptions = SelectOption[];
|
|
@@ -30,8 +32,13 @@ export type SelectOptions = SelectOption[];
|
|
|
30
32
|
*/
|
|
31
33
|
type IsMulti = false;
|
|
32
34
|
|
|
33
|
-
export type SelectProps =
|
|
35
|
+
export type SelectProps = Omit<
|
|
36
|
+
ReactSelectProps<SelectOption, IsMulti>,
|
|
37
|
+
'styles' | 'value' | 'onChange' | 'components'
|
|
38
|
+
> &
|
|
34
39
|
SxProp & {
|
|
40
|
+
value?: SelectOptionValue;
|
|
41
|
+
onChange?: (value: SelectOptionValue | undefined) => void;
|
|
35
42
|
disabled?: boolean;
|
|
36
43
|
leadingIcon?: IconType;
|
|
37
44
|
trailingIcon?: IconType;
|
|
@@ -142,7 +149,7 @@ const SelectContainer = ({
|
|
|
142
149
|
children,
|
|
143
150
|
...props
|
|
144
151
|
}: ContainerProps<SelectOption, IsMulti>) => {
|
|
145
|
-
const { sx, css } = props.selectProps as SelectProps;
|
|
152
|
+
const { sx, css } = props.selectProps as unknown as SelectProps;
|
|
146
153
|
|
|
147
154
|
return (
|
|
148
155
|
<Box sx={sx} css={css}>
|
|
@@ -158,7 +165,8 @@ const ValueContainer = ({
|
|
|
158
165
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
159
166
|
...props
|
|
160
167
|
}: ValueContainerProps<SelectOption, IsMulti>) => {
|
|
161
|
-
const { leadingIcon, trailingIcon } =
|
|
168
|
+
const { leadingIcon, trailingIcon, isSearchable } =
|
|
169
|
+
props.selectProps as unknown as SelectProps;
|
|
162
170
|
|
|
163
171
|
const hasError = props.selectProps['aria-invalid'] === 'true';
|
|
164
172
|
|
|
@@ -170,6 +178,14 @@ const ValueContainer = ({
|
|
|
170
178
|
return 'text';
|
|
171
179
|
})();
|
|
172
180
|
|
|
181
|
+
const finalLeadingIcon = (() => {
|
|
182
|
+
if (!isSearchable) {
|
|
183
|
+
return leadingIcon;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return leadingIcon || 'search';
|
|
187
|
+
})();
|
|
188
|
+
|
|
173
189
|
return (
|
|
174
190
|
<Flex
|
|
175
191
|
sx={{
|
|
@@ -177,7 +193,7 @@ const ValueContainer = ({
|
|
|
177
193
|
flex: 1,
|
|
178
194
|
}}
|
|
179
195
|
>
|
|
180
|
-
{
|
|
196
|
+
{finalLeadingIcon && (
|
|
181
197
|
<Text
|
|
182
198
|
sx={{
|
|
183
199
|
alignSelf: 'center',
|
|
@@ -186,7 +202,7 @@ const ValueContainer = ({
|
|
|
186
202
|
fontSize: 'base',
|
|
187
203
|
}}
|
|
188
204
|
>
|
|
189
|
-
<Icon icon={
|
|
205
|
+
<Icon icon={finalLeadingIcon} />
|
|
190
206
|
</Text>
|
|
191
207
|
)}
|
|
192
208
|
<Flex
|
|
@@ -221,6 +237,14 @@ const ValueContainer = ({
|
|
|
221
237
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
222
238
|
export const Select = React.forwardRef<any, SelectProps>(
|
|
223
239
|
({ ...props }, ref) => {
|
|
240
|
+
const value = props.options?.find((option) => {
|
|
241
|
+
if ('value' in option) {
|
|
242
|
+
return option.value === props.value;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return false;
|
|
246
|
+
}) as SelectOption | undefined;
|
|
247
|
+
|
|
224
248
|
return (
|
|
225
249
|
<ReactSelect<SelectOption, IsMulti>
|
|
226
250
|
ref={ref}
|
|
@@ -234,10 +258,21 @@ export const Select = React.forwardRef<any, SelectProps>(
|
|
|
234
258
|
Placeholder,
|
|
235
259
|
SelectContainer,
|
|
236
260
|
ValueContainer,
|
|
237
|
-
...props.components,
|
|
238
261
|
}}
|
|
239
262
|
isDisabled={props.disabled}
|
|
240
263
|
{...props}
|
|
264
|
+
value={value}
|
|
265
|
+
onChange={(value) => {
|
|
266
|
+
props.onChange?.(value?.value);
|
|
267
|
+
}}
|
|
268
|
+
styles={{
|
|
269
|
+
input: (baseStyles) => {
|
|
270
|
+
return {
|
|
271
|
+
...baseStyles,
|
|
272
|
+
position: 'absolute',
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
}}
|
|
241
276
|
/**
|
|
242
277
|
* https://react-select.com/styles#the-classnameprefix-prop
|
|
243
278
|
*/
|