forked from asyncapi/conference-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.tsx
More file actions
71 lines (66 loc) · 1.75 KB
/
Copy pathselect.tsx
File metadata and controls
71 lines (66 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React, { useState, useEffect, JSX } from 'react';
import Select, { MultiValue, StylesConfig } from 'react-select';
import { SelectOptions } from '../../types/types';
const customStyles: StylesConfig<Partial<SelectOptions>, true> = {
option: (provided, state) => ({
...provided,
color: state.isSelected ? 'white' : 'black',
background: state.isSelected ? '#E50E99' : undefined,
padding: 10,
}),
multiValue: () => ({
whiteSpace: 'nowrap',
overflow: 'hidden',
background: 'white',
textOverflow: 'ellipsis',
width: '150px',
display: 'flex',
}),
control: () => ({
display: 'flex',
padding: '10px',
borderRadius: '5px',
background: '#2e2344',
border: '1px solid #E50E99',
}),
singleValue: (provided, state) => {
const opacity = state.isDisabled ? 0.5 : 1;
const transition = 'opacity 300ms';
const color = 'white';
return { ...provided, opacity, transition, color };
},
};
interface SelectDropDownProps {
options: SelectOptions[];
setValue: (val: string) => void;
multi: undefined;
dataTest: string;
}
function SelectDropdown({
options,
setValue,
multi,
dataTest,
}: SelectDropDownProps): JSX.Element {
const [selectedOption, setSelectedOption] = useState<Partial<SelectOptions>>(
{}
);
useEffect(() => {
if (selectedOption?.value) {
setValue(selectedOption.value);
}
}, [selectedOption]);
return (
<div className="relative inline-block w-full">
<Select
className={`${dataTest || ''}`}
styles={customStyles}
defaultValue={selectedOption}
onChange={(option: any) => setSelectedOption(option as any)}
options={options}
isMulti={multi}
/>
</div>
);
}
export default SelectDropdown;