@intility/bifrost-react-select 4.0.0-alpha.8 → 4.0.0-beta.10
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/CHANGELOG.md +102 -0
- package/dist/Select.d.ts +7 -7
- package/dist/Select.js +107 -104
- package/dist/assets/bfSpinner.d.ts +2 -2
- package/dist/assets/bfSpinner.js +5 -5
- package/dist/overrides/ClearIndicator.internal.js +3 -3
- package/dist/overrides/CustomInput.internal.js +5 -5
- package/dist/overrides/CustomMenuList.internal.js +1 -1
- package/dist/overrides/CustomOption.internal.js +5 -5
- package/dist/overrides/DropdownIndicator.internal.js +3 -3
- package/dist/overrides/LoadingIndicator.internal.js +2 -2
- package/dist/overrides/index.d.ts +6 -6
- package/dist/overrides/index.js +6 -6
- package/package.json +4 -4
- package/src/Select.test.tsx +94 -93
- package/src/Select.tsx +203 -205
- package/src/assets/bfSpinner.ts +15 -15
- package/src/overrides/ClearIndicator.internal.tsx +7 -7
- package/src/overrides/CustomInput.internal.tsx +16 -14
- package/src/overrides/CustomMenuList.internal.tsx +7 -7
- package/src/overrides/CustomOption.internal.tsx +11 -11
- package/src/overrides/DropdownIndicator.internal.tsx +7 -7
- package/src/overrides/LoadingIndicator.internal.tsx +4 -4
- package/src/overrides/index.ts +6 -6
- package/tsconfig.json +1 -1
- package/vitest.config.ts +7 -7
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/src/Select.md +0 -410
- package/src/index.ts +0 -8
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Icon } from
|
|
2
|
-
import { components } from
|
|
3
|
-
import { faXmark } from
|
|
1
|
+
import { Icon } from "@intility/bifrost-react";
|
|
2
|
+
import { components } from "react-select";
|
|
3
|
+
import { faXmark } from "@fortawesome/free-solid-svg-icons/faXmark";
|
|
4
4
|
|
|
5
|
-
const ClearIndicator = props => {
|
|
5
|
+
const ClearIndicator = (props) => {
|
|
6
6
|
return (
|
|
7
7
|
<components.ClearIndicator {...props}>
|
|
8
8
|
<Icon icon={faXmark} />
|
|
9
9
|
</components.ClearIndicator>
|
|
10
|
-
)
|
|
11
|
-
}
|
|
10
|
+
);
|
|
11
|
+
};
|
|
12
12
|
|
|
13
|
-
export default ClearIndicator
|
|
13
|
+
export default ClearIndicator;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { components, Props } from
|
|
1
|
+
import { components, Props } from "react-select";
|
|
2
2
|
|
|
3
|
-
const CustomInput = props => {
|
|
4
|
-
const { required, value } = props.selectProps as Props & {
|
|
3
|
+
const CustomInput = (props) => {
|
|
4
|
+
const { required, value } = props.selectProps as Props & {
|
|
5
|
+
required: boolean;
|
|
6
|
+
};
|
|
5
7
|
const updatedProps = {
|
|
6
8
|
...props,
|
|
7
|
-
autoComplete:
|
|
8
|
-
}
|
|
9
|
+
autoComplete: "noAutocomplete",
|
|
10
|
+
};
|
|
9
11
|
|
|
10
12
|
return (
|
|
11
13
|
<>
|
|
@@ -14,19 +16,19 @@ const CustomInput = props => {
|
|
|
14
16
|
style={{
|
|
15
17
|
opacity: 0,
|
|
16
18
|
height: 0,
|
|
17
|
-
position:
|
|
18
|
-
pointerEvents:
|
|
19
|
+
position: "absolute",
|
|
20
|
+
pointerEvents: "none",
|
|
19
21
|
}}
|
|
20
|
-
onChange={e => e.preventDefault()}
|
|
22
|
+
onChange={(e) => e.preventDefault()}
|
|
21
23
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
value={(value as any)?.label ??
|
|
24
|
+
value={(value as any)?.label ?? ""} // casting to any, because we don't know the type of an option
|
|
23
25
|
tabIndex={-1}
|
|
24
|
-
autoComplete=
|
|
26
|
+
autoComplete="noAutocomplete"
|
|
25
27
|
required={required}
|
|
26
|
-
data-testid=
|
|
28
|
+
data-testid="bf-select-input"
|
|
27
29
|
/>
|
|
28
30
|
</>
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
+
);
|
|
32
|
+
};
|
|
31
33
|
|
|
32
|
-
export default CustomInput
|
|
34
|
+
export default CustomInput;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { components } from
|
|
1
|
+
import { components } from "react-select";
|
|
2
2
|
|
|
3
|
-
const CustomMenuList = props => {
|
|
3
|
+
const CustomMenuList = (props) => {
|
|
4
4
|
return (
|
|
5
5
|
<components.MenuList
|
|
6
|
-
data-testid=
|
|
7
|
-
className=
|
|
6
|
+
data-testid="bf-select-menulist"
|
|
7
|
+
className="bf-scrollbar-small"
|
|
8
8
|
{...props}
|
|
9
9
|
>
|
|
10
10
|
{props.children}
|
|
11
11
|
</components.MenuList>
|
|
12
|
-
)
|
|
13
|
-
}
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
14
|
|
|
15
|
-
export default CustomMenuList
|
|
15
|
+
export default CustomMenuList;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { components } from
|
|
2
|
-
import { faSquare } from
|
|
3
|
-
import { faCheckSquare } from
|
|
4
|
-
import { faCheck } from
|
|
5
|
-
import { Icon } from
|
|
1
|
+
import { components } from "react-select";
|
|
2
|
+
import { faSquare } from "@fortawesome/free-regular-svg-icons/faSquare";
|
|
3
|
+
import { faCheckSquare } from "@fortawesome/free-solid-svg-icons/faCheckSquare";
|
|
4
|
+
import { faCheck } from "@fortawesome/free-solid-svg-icons/faCheck";
|
|
5
|
+
import { Icon } from "@intility/bifrost-react";
|
|
6
6
|
|
|
7
|
-
const CustomOption = props => {
|
|
7
|
+
const CustomOption = (props) => {
|
|
8
8
|
return (
|
|
9
9
|
<components.Option {...props}>
|
|
10
10
|
{props.isMulti && (
|
|
@@ -12,18 +12,18 @@ const CustomOption = props => {
|
|
|
12
12
|
<Icon
|
|
13
13
|
icon={props.isSelected ? faCheckSquare : faSquare}
|
|
14
14
|
fixedWidth
|
|
15
|
-
className=
|
|
15
|
+
className="bf-select-checkbox"
|
|
16
16
|
/>
|
|
17
17
|
</div>
|
|
18
18
|
)}
|
|
19
19
|
{props.children}
|
|
20
20
|
{!props.isMulti && props.isSelected && (
|
|
21
21
|
<div>
|
|
22
|
-
<Icon icon={faCheck} fixedWidth className=
|
|
22
|
+
<Icon icon={faCheck} fixedWidth className="bf-select-selected-icon" />
|
|
23
23
|
</div>
|
|
24
24
|
)}
|
|
25
25
|
</components.Option>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
28
|
|
|
29
|
-
export default CustomOption
|
|
29
|
+
export default CustomOption;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { components } from
|
|
2
|
-
import { faCaretDown } from
|
|
3
|
-
import { Icon } from
|
|
1
|
+
import { components } from "react-select";
|
|
2
|
+
import { faCaretDown } from "@fortawesome/free-solid-svg-icons/faCaretDown";
|
|
3
|
+
import { Icon } from "@intility/bifrost-react";
|
|
4
4
|
|
|
5
|
-
const DropdownIndicator = props => {
|
|
5
|
+
const DropdownIndicator = (props) => {
|
|
6
6
|
return (
|
|
7
7
|
<components.DropdownIndicator {...props}>
|
|
8
8
|
<Icon icon={faCaretDown} />
|
|
9
9
|
</components.DropdownIndicator>
|
|
10
|
-
)
|
|
11
|
-
}
|
|
10
|
+
);
|
|
11
|
+
};
|
|
12
12
|
|
|
13
|
-
export default DropdownIndicator
|
|
13
|
+
export default DropdownIndicator;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Icon } from
|
|
1
|
+
import { Icon } from "@intility/bifrost-react";
|
|
2
2
|
|
|
3
|
-
import bfSpinner from
|
|
3
|
+
import bfSpinner from "../assets/bfSpinner.js";
|
|
4
4
|
|
|
5
5
|
export default function LoadingIndicator() {
|
|
6
6
|
return (
|
|
7
|
-
<Icon icon={bfSpinner} spin fixedWidth className=
|
|
8
|
-
)
|
|
7
|
+
<Icon icon={bfSpinner} spin fixedWidth className="bf-input-loading-icon" />
|
|
8
|
+
);
|
|
9
9
|
}
|
package/src/overrides/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { default as ClearIndicator } from
|
|
2
|
-
export { default as CustomInput } from
|
|
3
|
-
export { default as LoadingIndicator } from
|
|
4
|
-
export { default as CustomMenuList } from
|
|
5
|
-
export { default as DropdownIndicator } from
|
|
6
|
-
export { default as CustomOption } from
|
|
1
|
+
export { default as ClearIndicator } from "./ClearIndicator.internal.js";
|
|
2
|
+
export { default as CustomInput } from "./CustomInput.internal.js";
|
|
3
|
+
export { default as LoadingIndicator } from "./LoadingIndicator.internal.js";
|
|
4
|
+
export { default as CustomMenuList } from "./CustomMenuList.internal.js";
|
|
5
|
+
export { default as DropdownIndicator } from "./DropdownIndicator.internal.js";
|
|
6
|
+
export { default as CustomOption } from "./CustomOption.internal.js";
|
package/tsconfig.json
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
"extends": "../../tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"declaration": true,
|
|
5
|
+
"rootDir": "src",
|
|
5
6
|
"declarationMap": false,
|
|
6
7
|
"isolatedModules": false,
|
|
7
8
|
"noEmit": false,
|
|
8
9
|
"allowJs": false,
|
|
9
10
|
"sourceMap": false,
|
|
10
|
-
"moduleResolution": "Bundler",
|
|
11
11
|
"emitDeclarationOnly": true,
|
|
12
12
|
"outDir": "dist"
|
|
13
13
|
},
|
package/vitest.config.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import react from
|
|
2
|
-
import { defineConfig } from
|
|
1
|
+
import react from "@vitejs/plugin-react-swc";
|
|
2
|
+
import { defineConfig } from "vitest/config";
|
|
3
3
|
|
|
4
4
|
export default defineConfig({
|
|
5
5
|
plugins: [react()],
|
|
6
6
|
test: {
|
|
7
7
|
globals: true,
|
|
8
|
-
environment:
|
|
9
|
-
setupFiles:
|
|
10
|
-
css: true
|
|
11
|
-
}
|
|
12
|
-
})
|
|
8
|
+
environment: "jsdom",
|
|
9
|
+
setupFiles: "../test-setup.ts",
|
|
10
|
+
css: true,
|
|
11
|
+
},
|
|
12
|
+
});
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default, AsyncSelect, CreatableSelect, AsyncCreatableSelect, selectStyles, selectComponents } from './Select';
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default, AsyncSelect, CreatableSelect, AsyncCreatableSelect, selectStyles, selectComponents } from './Select';
|
package/src/Select.md
DELETED
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
<Message header='More props available'>
|
|
2
|
-
This component is a wrapper for react-select. Visit [React Select](https://react-select.com/home) for full documentation.
|
|
3
|
-
|
|
4
|
-
To see all available props, click [here](https://react-select.com/props).
|
|
5
|
-
</Message>
|
|
6
|
-
|
|
7
|
-
### Basic Select
|
|
8
|
-
|
|
9
|
-
```jsx
|
|
10
|
-
const options = [
|
|
11
|
-
{ value: 'Norway', label: 'Norway' },
|
|
12
|
-
{ value: 'Sweden', label: 'Sweden' },
|
|
13
|
-
{ value: 'Denmark', label: 'Denmark' },
|
|
14
|
-
{ value: 'Germany', label: 'Germany' }
|
|
15
|
-
]
|
|
16
|
-
|
|
17
|
-
;<Select
|
|
18
|
-
label='Country'
|
|
19
|
-
placeholder='- Select country -'
|
|
20
|
-
options={options}
|
|
21
|
-
description='Select your country of residence'
|
|
22
|
-
/>
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
You can get and set the currently selected item using `value` and `onChange`.
|
|
26
|
-
|
|
27
|
-
```jsx
|
|
28
|
-
import { useState } from 'react'
|
|
29
|
-
import { Select, Button } from '@intility/bifrost-react'
|
|
30
|
-
|
|
31
|
-
const options = [
|
|
32
|
-
{ value: 'Norway', label: 'Norway' },
|
|
33
|
-
{ value: 'Sweden', label: 'Sweden' },
|
|
34
|
-
{ value: 'Denmark', label: 'Denmark' },
|
|
35
|
-
{ value: 'Germany', label: 'Germany' }
|
|
36
|
-
]
|
|
37
|
-
const [selected, setSelected] = useState(options[2])
|
|
38
|
-
|
|
39
|
-
;<div>
|
|
40
|
-
<Select
|
|
41
|
-
label='Country'
|
|
42
|
-
placeholder='- Select country -'
|
|
43
|
-
description='Select your country of residence'
|
|
44
|
-
options={options}
|
|
45
|
-
value={selected}
|
|
46
|
-
onChange={item => setSelected(item)}
|
|
47
|
-
/>
|
|
48
|
-
<p>Selected item: {selected.label}</p>
|
|
49
|
-
<Button onClick={() => setSelected(options[0])}>Select first option</Button>
|
|
50
|
-
</div>
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### Clearable
|
|
54
|
-
|
|
55
|
-
Use `isClearable` prop for possibility to remove selected option with button.
|
|
56
|
-
|
|
57
|
-
```jsx
|
|
58
|
-
import { useState } from 'react'
|
|
59
|
-
import { Select } from '@intility/bifrost-react'
|
|
60
|
-
|
|
61
|
-
const options = [
|
|
62
|
-
{ value: 'Norway', label: 'Norway' },
|
|
63
|
-
{ value: 'Sweden', label: 'Sweden' },
|
|
64
|
-
{ value: 'Denmark', label: 'Denmark' },
|
|
65
|
-
{ value: 'Germany', label: 'Germany' }
|
|
66
|
-
]
|
|
67
|
-
const [selected, setSelected] = useState()
|
|
68
|
-
|
|
69
|
-
;<Select
|
|
70
|
-
label='Country'
|
|
71
|
-
placeholder='- Select country -'
|
|
72
|
-
options={options}
|
|
73
|
-
onChange={item => setSelected(item)}
|
|
74
|
-
isClearable
|
|
75
|
-
/>
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### Validation
|
|
79
|
-
|
|
80
|
-
`Select` can indicate an alert state based on input. Set `state` prop to `alert` to style it accordingly. Meanwhile, use `feedback` to provide additional information.
|
|
81
|
-
|
|
82
|
-
Use the `required` prop to render `Select` as required. This will add `(required)` text after the label. You can hide this label with `requiredNoLabel`.
|
|
83
|
-
|
|
84
|
-
<Message header='Read more'>
|
|
85
|
-
See usage demo at [Forms example](#/Welcome%20to%20Bifrost/Examples/Forms)
|
|
86
|
-
</Message>
|
|
87
|
-
|
|
88
|
-
```jsx
|
|
89
|
-
import { useState } from 'react'
|
|
90
|
-
import { Select } from '@intility/bifrost-react'
|
|
91
|
-
|
|
92
|
-
const options = [
|
|
93
|
-
{ value: 'Norway', label: 'Norway' },
|
|
94
|
-
{ value: 'Sweden', label: 'Sweden' },
|
|
95
|
-
{ value: 'Denmark', label: 'Denmark' },
|
|
96
|
-
{ value: 'Germany', label: 'Germany' }
|
|
97
|
-
]
|
|
98
|
-
|
|
99
|
-
const [selected, setSelected] = useState()
|
|
100
|
-
|
|
101
|
-
;<Select
|
|
102
|
-
label='Country'
|
|
103
|
-
placeholder='- Select country -'
|
|
104
|
-
description='Select your country of residence'
|
|
105
|
-
options={options}
|
|
106
|
-
onChange={item => setSelected(item)}
|
|
107
|
-
state={selected ? 'default' : 'alert'}
|
|
108
|
-
feedback={selected ? '' : 'Missing value'}
|
|
109
|
-
isClearable
|
|
110
|
-
required
|
|
111
|
-
/>
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Multi Select
|
|
115
|
-
|
|
116
|
-
Using the `isMulti` prop makes it possible to select multiple options.
|
|
117
|
-
|
|
118
|
-
```jsx
|
|
119
|
-
import { useState } from 'react'
|
|
120
|
-
import { Select } from '@intility/bifrost-react'
|
|
121
|
-
|
|
122
|
-
const options = [
|
|
123
|
-
{ value: 'Norway', label: 'Norway' },
|
|
124
|
-
{ value: 'Sweden', label: 'Sweden' },
|
|
125
|
-
{ value: 'Denmark', label: 'Denmark' },
|
|
126
|
-
{ value: 'Finland', label: 'Finland' },
|
|
127
|
-
{ value: 'France', label: 'France' },
|
|
128
|
-
{ value: 'Spain', label: 'Spain' },
|
|
129
|
-
{ value: 'Italy', label: 'Italy' },
|
|
130
|
-
{ value: 'Germany', label: 'Germany' }
|
|
131
|
-
]
|
|
132
|
-
|
|
133
|
-
const [selected, setSelected] = useState([])
|
|
134
|
-
|
|
135
|
-
;<Select
|
|
136
|
-
label='Countries'
|
|
137
|
-
placeholder='- Select countries -'
|
|
138
|
-
description='Select countries you have visited'
|
|
139
|
-
options={options}
|
|
140
|
-
value={selected}
|
|
141
|
-
onChange={items => setSelected(items)}
|
|
142
|
-
isMulti
|
|
143
|
-
/>
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Grouped options
|
|
147
|
-
|
|
148
|
-
To make grouped options with labels you simply need to structure the `options` value a bit different.
|
|
149
|
-
|
|
150
|
-
```jsx
|
|
151
|
-
const options = [
|
|
152
|
-
{
|
|
153
|
-
label: 'Marvel',
|
|
154
|
-
options: [
|
|
155
|
-
{ value: 'Iron Man', label: 'Iron Man' },
|
|
156
|
-
{ value: 'Spider-man', label: 'Spider-man' },
|
|
157
|
-
{ value: 'Star Lord', label: 'Star Lord' }
|
|
158
|
-
]
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
label: 'DC',
|
|
162
|
-
options: [
|
|
163
|
-
{ value: 'Superman', label: 'Superman' },
|
|
164
|
-
{ value: 'Batman', label: 'Batman' },
|
|
165
|
-
{ value: 'The Flash', label: 'The Flash' }
|
|
166
|
-
]
|
|
167
|
-
}
|
|
168
|
-
]
|
|
169
|
-
|
|
170
|
-
;<div className='bfl-autocol'>
|
|
171
|
-
<Select
|
|
172
|
-
label='Superhero'
|
|
173
|
-
placeholder='- Select your hero -'
|
|
174
|
-
options={options}
|
|
175
|
-
/>
|
|
176
|
-
<Select
|
|
177
|
-
label='Superheroes'
|
|
178
|
-
placeholder='- Select multiple heroes -'
|
|
179
|
-
options={options}
|
|
180
|
-
isMulti
|
|
181
|
-
/>
|
|
182
|
-
</div>
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### Disabled
|
|
186
|
-
|
|
187
|
-
Disable a `<Select>` with `isDisabled` prop.
|
|
188
|
-
|
|
189
|
-
You can also disable an option with `isDisabled` property on the option object.
|
|
190
|
-
|
|
191
|
-
```jsx
|
|
192
|
-
const options = [
|
|
193
|
-
{ value: 'Norway', label: 'Norway' },
|
|
194
|
-
{ value: 'Sweden', label: 'Sweden' },
|
|
195
|
-
{ value: 'Denmark', label: 'Denmark', isDisabled: true },
|
|
196
|
-
{ value: 'Germany', label: 'Germany' }
|
|
197
|
-
]
|
|
198
|
-
|
|
199
|
-
;<div className='bfl-autocol'>
|
|
200
|
-
<Select
|
|
201
|
-
label='Disabled select'
|
|
202
|
-
placeholder='- Select country -'
|
|
203
|
-
description='This is a disabled component'
|
|
204
|
-
isDisabled
|
|
205
|
-
/>
|
|
206
|
-
<Select
|
|
207
|
-
label='Disabled option'
|
|
208
|
-
placeholder='- Select country -'
|
|
209
|
-
description='Denmark option is disabled'
|
|
210
|
-
options={options}
|
|
211
|
-
/>
|
|
212
|
-
</div>
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### Loading spinner
|
|
216
|
-
|
|
217
|
-
The `loading` prop displays a loading spinner on the right hand side of the input.
|
|
218
|
-
|
|
219
|
-
```jsx
|
|
220
|
-
const options = [
|
|
221
|
-
{ value: 'Norway', label: 'Norway' },
|
|
222
|
-
{ value: 'Sweden', label: 'Sweden' },
|
|
223
|
-
{ value: 'Denmark', label: 'Denmark' },
|
|
224
|
-
{ value: 'Germany', label: 'Germany' }
|
|
225
|
-
]
|
|
226
|
-
|
|
227
|
-
;<Select
|
|
228
|
-
label='Country'
|
|
229
|
-
placeholder='- Select country -'
|
|
230
|
-
options={options}
|
|
231
|
-
loading
|
|
232
|
-
/>
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
### Hide label
|
|
236
|
-
|
|
237
|
-
The `label` prop is required, but you can hide it with `hideLabel`.
|
|
238
|
-
|
|
239
|
-
```jsx
|
|
240
|
-
const options = [
|
|
241
|
-
{ value: 'Norway', label: 'Norway' },
|
|
242
|
-
{ value: 'Sweden', label: 'Sweden' },
|
|
243
|
-
{ value: 'Denmark', label: 'Denmark' },
|
|
244
|
-
{ value: 'Germany', label: 'Germany' }
|
|
245
|
-
]
|
|
246
|
-
|
|
247
|
-
;<Select
|
|
248
|
-
label='Country'
|
|
249
|
-
hideLabel
|
|
250
|
-
placeholder='- Select country -'
|
|
251
|
-
options={options}
|
|
252
|
-
/>
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
### Async
|
|
256
|
-
|
|
257
|
-
AsyncSelect can be used to load options from a source as the user types.
|
|
258
|
-
|
|
259
|
-
Try type 'No' in the demo below
|
|
260
|
-
|
|
261
|
-
```jsx
|
|
262
|
-
import { useState } from 'react'
|
|
263
|
-
import { AsyncSelect } from '@intility/bifrost-react'
|
|
264
|
-
|
|
265
|
-
const countries = [
|
|
266
|
-
{ value: 'Norway', label: 'Norway' },
|
|
267
|
-
{ value: 'Sweden', label: 'Sweden' },
|
|
268
|
-
{ value: 'Denmark', label: 'Denmark' },
|
|
269
|
-
{ value: 'Germany', label: 'Germany' }
|
|
270
|
-
]
|
|
271
|
-
|
|
272
|
-
const [selected, setSelected] = useState()
|
|
273
|
-
|
|
274
|
-
function getAsyncOptions(inputValue) {
|
|
275
|
-
return new Promise((resolve, reject) => {
|
|
276
|
-
const filtered = countries.filter(c =>
|
|
277
|
-
String(c.label.toLowerCase()).startsWith(inputValue.toLowerCase())
|
|
278
|
-
)
|
|
279
|
-
|
|
280
|
-
resolve(filtered.slice(0, 3))
|
|
281
|
-
})
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
;<AsyncSelect
|
|
285
|
-
label='Country'
|
|
286
|
-
placeholder='- Select country -'
|
|
287
|
-
loadOptions={inputValue => getAsyncOptions(inputValue)}
|
|
288
|
-
onChange={item => setSelected(item)}
|
|
289
|
-
isClearable
|
|
290
|
-
/>
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
### Creatable
|
|
294
|
-
|
|
295
|
-
CreatableSelect can be used to create new options.
|
|
296
|
-
|
|
297
|
-
Try to type 'England' and add the new option to the component
|
|
298
|
-
|
|
299
|
-
```jsx
|
|
300
|
-
import { useState } from 'react'
|
|
301
|
-
import { CreatableSelect } from '@intility/bifrost-react'
|
|
302
|
-
|
|
303
|
-
const countries = [
|
|
304
|
-
{ value: 'Norway', label: 'Norway' },
|
|
305
|
-
{ value: 'Sweden', label: 'Sweden' },
|
|
306
|
-
{ value: 'Denmark', label: 'Denmark' },
|
|
307
|
-
{ value: 'Germany', label: 'Germany' }
|
|
308
|
-
]
|
|
309
|
-
|
|
310
|
-
const [selected, setSelected] = useState()
|
|
311
|
-
const [options, setOptions] = useState(countries)
|
|
312
|
-
|
|
313
|
-
const handleCreate = option => {
|
|
314
|
-
const newOption = {
|
|
315
|
-
value: option,
|
|
316
|
-
label: option
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
setOptions(options => [...options, newOption])
|
|
320
|
-
setSelected(newOption)
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
;<CreatableSelect
|
|
324
|
-
label='Country'
|
|
325
|
-
placeholder='- Select country -'
|
|
326
|
-
options={options}
|
|
327
|
-
value={selected}
|
|
328
|
-
onChange={item => setSelected(item)}
|
|
329
|
-
onCreateOption={option => handleCreate(option)}
|
|
330
|
-
isClearable
|
|
331
|
-
/>
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
### Replace components
|
|
335
|
-
|
|
336
|
-
`react-select` allows you to [replace internal components](https://react-select.com/components) which allows for more advanced use cases.
|
|
337
|
-
|
|
338
|
-
Let's say you have a multi-select, but don't want to display a badge for each selected item, but something like "Selected (4)" instead, you can replace the `ValueContainer` component:
|
|
339
|
-
|
|
340
|
-
```jsx
|
|
341
|
-
import { useState } from 'react'
|
|
342
|
-
import { components } from 'react-select'
|
|
343
|
-
import { Select } from '@intility/bifrost-react'
|
|
344
|
-
|
|
345
|
-
const ValueContainer = ({ children, ...props }) => {
|
|
346
|
-
let [values, input] = children
|
|
347
|
-
|
|
348
|
-
if (Array.isArray(values)) {
|
|
349
|
-
// convert array of values to a string that will get displayed
|
|
350
|
-
values = `Selected (${values.length})`
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
return (
|
|
354
|
-
<components.ValueContainer {...props}>
|
|
355
|
-
{values}
|
|
356
|
-
{input}
|
|
357
|
-
</components.ValueContainer>
|
|
358
|
-
)
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
const options = [
|
|
362
|
-
{ value: 'Norway', label: 'Norway' },
|
|
363
|
-
{ value: 'Sweden', label: 'Sweden' },
|
|
364
|
-
{ value: 'Denmark', label: 'Denmark' },
|
|
365
|
-
{ value: 'Finland', label: 'Finland' },
|
|
366
|
-
{ value: 'France', label: 'France' },
|
|
367
|
-
{ value: 'Spain', label: 'Spain' },
|
|
368
|
-
{ value: 'Italy', label: 'Italy' },
|
|
369
|
-
{ value: 'Germany', label: 'Germany' }
|
|
370
|
-
]
|
|
371
|
-
|
|
372
|
-
const SelectDemo = () => {
|
|
373
|
-
const [selected, setSelected] = useState([])
|
|
374
|
-
|
|
375
|
-
return (
|
|
376
|
-
<Select
|
|
377
|
-
label='Countries'
|
|
378
|
-
placeholder='- Select countries -'
|
|
379
|
-
description='Select countries you have visited'
|
|
380
|
-
options={options}
|
|
381
|
-
value={selected}
|
|
382
|
-
onChange={items => setSelected(items)}
|
|
383
|
-
isMulti
|
|
384
|
-
// pass in the custom override
|
|
385
|
-
components={{
|
|
386
|
-
ValueContainer
|
|
387
|
-
}}
|
|
388
|
-
/>
|
|
389
|
-
)
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
;<SelectDemo />
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
Bifrost replaces the following components internally:
|
|
396
|
-
|
|
397
|
-
- ClearIndicator
|
|
398
|
-
- DropdownIndicator
|
|
399
|
-
- Input
|
|
400
|
-
- LoadingIndicator
|
|
401
|
-
- MenuList
|
|
402
|
-
- Option
|
|
403
|
-
|
|
404
|
-
To use or wrap our components in your own overrides, you can import them from `selectComponents` <Copy text="import { selectComponents } from '@intility/bifrost-react'" />
|
|
405
|
-
|
|
406
|
-
```jsx static
|
|
407
|
-
import { selectComponents } from '@intility/bifrost-react'
|
|
408
|
-
// ...
|
|
409
|
-
;<selectComponents.Option>...</selectComponents.Option>
|
|
410
|
-
```
|