Skip to content

Commit eef0297

Browse files
authored
feature/UIDS-375 add CreatableSelect into the DS (#382)
Adds CreatableSelect to the DS
1 parent f1cfcb1 commit eef0297

File tree

5 files changed

+250
-4
lines changed

5 files changed

+250
-4
lines changed

spec/__snapshots__/Storyshots.test.js.snap

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4665,6 +4665,120 @@ exports[`Storyshots Design System/Selects/Async Labeled 1`] = `
46654665
</div>
46664666
`;
46674667

4668+
exports[`Storyshots Design System/Selects/Creatable Default 1`] = `
4669+
<div
4670+
style={
4671+
Object {
4672+
"padding": "1rem",
4673+
}
4674+
}
4675+
>
4676+
<div
4677+
className="CreatableSelect css-2b097c-container"
4678+
onKeyDown={[Function]}
4679+
>
4680+
<div
4681+
className=" css-qv254q-control"
4682+
onMouseDown={[Function]}
4683+
onTouchEnd={[Function]}
4684+
>
4685+
<div
4686+
className=" css-g1d714-ValueContainer"
4687+
>
4688+
<div
4689+
className=" css-1wa3eu0-placeholder"
4690+
>
4691+
Select...
4692+
</div>
4693+
<div
4694+
className="css-b8ldur-Input"
4695+
>
4696+
<div
4697+
className=""
4698+
style={
4699+
Object {
4700+
"display": "inline-block",
4701+
}
4702+
}
4703+
>
4704+
<input
4705+
aria-autocomplete="list"
4706+
autoCapitalize="none"
4707+
autoComplete="off"
4708+
autoCorrect="off"
4709+
disabled={false}
4710+
id="react-select-4-input"
4711+
onBlur={[Function]}
4712+
onChange={[Function]}
4713+
onFocus={[Function]}
4714+
spellCheck="false"
4715+
style={
4716+
Object {
4717+
"background": 0,
4718+
"border": 0,
4719+
"boxSizing": "content-box",
4720+
"color": "inherit",
4721+
"fontSize": "inherit",
4722+
"label": "input",
4723+
"opacity": 1,
4724+
"outline": 0,
4725+
"padding": 0,
4726+
"width": "1px",
4727+
}
4728+
}
4729+
tabIndex="0"
4730+
type="text"
4731+
value=""
4732+
/>
4733+
<div
4734+
style={
4735+
Object {
4736+
"height": 0,
4737+
"left": 0,
4738+
"overflow": "scroll",
4739+
"position": "absolute",
4740+
"top": 0,
4741+
"visibility": "hidden",
4742+
"whiteSpace": "pre",
4743+
}
4744+
}
4745+
>
4746+
4747+
</div>
4748+
</div>
4749+
</div>
4750+
</div>
4751+
<div
4752+
className=" css-1hb7zxy-IndicatorsContainer"
4753+
>
4754+
<span
4755+
className=" css-43ykx9-indicatorSeparator"
4756+
/>
4757+
<div
4758+
aria-hidden="true"
4759+
className=" css-fric97-indicatorContainer"
4760+
onMouseDown={[Function]}
4761+
onTouchEnd={[Function]}
4762+
>
4763+
<svg
4764+
aria-hidden="true"
4765+
className="css-6q0nyr-Svg"
4766+
focusable="false"
4767+
height={20}
4768+
viewBox="0 0 20 20"
4769+
width={20}
4770+
>
4771+
<path
4772+
d="M4.516 7.548c0.436-0.446 1.043-0.481 1.576 0l3.908 3.747 3.908-3.747c0.533-0.481 1.141-0.446 1.574 0 0.436 0.445 0.408 1.197 0 1.615-0.406 0.418-4.695 4.502-4.695 4.502-0.217 0.223-0.502 0.335-0.787 0.335s-0.57-0.112-0.789-0.335c0 0-4.287-4.084-4.695-4.502s-0.436-1.17 0-1.615z"
4773+
/>
4774+
</svg>
4775+
</div>
4776+
</div>
4777+
</div>
4778+
</div>
4779+
</div>
4780+
`;
4781+
46684782
exports[`Storyshots Design System/Selects/Single Default 1`] = `
46694783
<div
46704784
style={
@@ -4695,7 +4809,7 @@ exports[`Storyshots Design System/Selects/Single Default 1`] = `
46954809
aria-label="Default select"
46964810
className="css-62g3xt-dummyInput"
46974811
disabled={false}
4698-
id="react-select-4-input"
4812+
id="react-select-5-input"
46994813
onBlur={[Function]}
47004814
onChange={[Function]}
47014815
onFocus={[Function]}
@@ -4772,7 +4886,7 @@ exports[`Storyshots Design System/Selects/Single Labeled 1`] = `
47724886
aria-labelledby="select-label"
47734887
className="css-62g3xt-dummyInput"
47744888
disabled={false}
4775-
id="react-select-7-input"
4889+
id="react-select-8-input"
47764890
onBlur={[Function]}
47774891
onChange={[Function]}
47784892
onFocus={[Function]}
@@ -4842,7 +4956,7 @@ exports[`Storyshots Design System/Selects/Single Loading 1`] = `
48424956
aria-label="Loading select"
48434957
className="css-62g3xt-dummyInput"
48444958
disabled={true}
4845-
id="react-select-6-input"
4959+
id="react-select-7-input"
48464960
onBlur={[Function]}
48474961
onChange={[Function]}
48484962
onFocus={[Function]}
@@ -4925,7 +5039,7 @@ exports[`Storyshots Design System/Selects/Single Searchable 1`] = `
49255039
autoComplete="off"
49265040
autoCorrect="off"
49275041
disabled={false}
4928-
id="react-select-5-input"
5042+
id="react-select-6-input"
49295043
onBlur={[Function]}
49305044
onChange={[Function]}
49315045
onFocus={[Function]}

src/Select/CreatableSelect.jsx

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import React from 'react';
2+
import Creatable from 'react-select/creatable';
3+
import PropTypes from 'prop-types';
4+
5+
import { defaultTheme, defaultStyles, SELECT_SIZES } from './styles';
6+
7+
const CreatableSelect = ({
8+
'aria-label': ariaLabel,
9+
'aria-labelledby': ariaLabelledBy,
10+
className,
11+
defaultValue,
12+
disabled,
13+
getOptionValue,
14+
getOptionLabel,
15+
id,
16+
inputId,
17+
isClearable,
18+
isLoading,
19+
modal,
20+
name,
21+
options,
22+
placeholder,
23+
size,
24+
value,
25+
onChange,
26+
...props
27+
}) => (
28+
<Creatable
29+
{...props}
30+
ariaLabel={ariaLabel}
31+
ariaLabelledBy={ariaLabelledBy}
32+
className={`${className || ''} CreatableSelect`}
33+
defaultValue={defaultValue}
34+
disabled={disabled}
35+
getOptionLabel={getOptionLabel}
36+
getOptionValue={getOptionValue}
37+
id={id}
38+
inputId={inputId}
39+
isClearable={isClearable}
40+
isLoading={isLoading}
41+
menuPortalTarget={modal ? document.body : undefined}
42+
name={name}
43+
options={options}
44+
placeholder={placeholder}
45+
styles={{
46+
...defaultStyles({ size }),
47+
menuPortal: (base) => (
48+
modal ?
49+
base :
50+
{ ...base, zIndex: zStack.zIndexModalBackdrop + 1 }
51+
),
52+
}}
53+
theme={defaultTheme}
54+
value={value}
55+
onChange={onChange}
56+
/>
57+
);
58+
59+
CreatableSelect.propTypes = {
60+
'aria-label': PropTypes.string,
61+
'aria-labelledby': PropTypes.string,
62+
className: PropTypes.string,
63+
defaultValue: PropTypes.object,
64+
disabled: PropTypes.bool,
65+
getOptionLabel: PropTypes.func,
66+
getOptionValue: PropTypes.func,
67+
id: PropTypes.string,
68+
inputId: PropTypes.string,
69+
isClearable: PropTypes.bool,
70+
isLoading: PropTypes.bool,
71+
modal: PropTypes.bool,
72+
name: PropTypes.string,
73+
options: PropTypes.arrayOf(PropTypes.object).isRequired,
74+
placeholder: PropTypes.string,
75+
size: PropTypes.oneOf(Object.values(SELECT_SIZES)),
76+
value: PropTypes.object,
77+
78+
onChange: PropTypes.func.isRequired,
79+
};
80+
81+
CreatableSelect.defaultProps = {
82+
'aria-label': undefined,
83+
'aria-labelledby': undefined,
84+
className: undefined,
85+
defaultValue: undefined,
86+
disabled: false,
87+
getOptionLabel: undefined,
88+
getOptionValue: undefined,
89+
isClearable: false,
90+
id: undefined,
91+
inputId: undefined,
92+
isLoading: undefined,
93+
modal: undefined,
94+
name: undefined,
95+
placeholder: undefined,
96+
size: SELECT_SIZES.SMALL,
97+
value: undefined,
98+
};
99+
100+
export default CreatableSelect;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
3+
import CreatableSelect from 'src/Select/CreatableSelect';
4+
5+
export default {
6+
title: 'Design System/Selects/Creatable',
7+
component: CreatableSelect,
8+
};
9+
10+
const options = [
11+
{ label: 'Red', value: 1 },
12+
{ label: 'Green', value: 2 },
13+
{ label: 'Blue', value: 3 },
14+
];
15+
16+
export const Default = () => {
17+
const handleChange = () => {};
18+
const handleInputChange = () => {};
19+
20+
return (
21+
<CreatableSelect
22+
isClearable
23+
options={options}
24+
onChange={handleChange}
25+
onInputChange={handleInputChange}
26+
/>
27+
);
28+
};

src/Select/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import AsyncSelect from './AsyncSelect';
2+
import CreatableSelect from './CreatableSelect';
23
import SingleSelect from './SingleSelect';
34
import { SELECT_SIZES } from './styles';
45

56
export {
67
AsyncSelect,
8+
CreatableSelect,
79
SELECT_SIZES,
810
SingleSelect,
911
};

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import RadioButton from 'src/RadioButton';
2626
import RadioButtonGroup from 'src/RadioButtonGroup';
2727
import {
2828
AsyncSelect,
29+
CreatableSelect,
2930
SELECT_SIZES,
3031
SingleSelect,
3132
} from 'src/Select';
@@ -60,6 +61,7 @@ export {
6061
COLORS,
6162
CopyToClipboard,
6263
CopyToClipboardButton,
64+
CreatableSelect,
6365
FadeTransition,
6466
Form,
6567
FormControlLabel,

0 commit comments

Comments
 (0)