-
Notifications
You must be signed in to change notification settings - Fork 572
/
Copy pathDropdown.tsx
54 lines (53 loc) · 1.57 KB
/
Dropdown.tsx
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
import { Dropdown } from '@neo4j-ndl/react';
import { DropdownProps, OptionType } from '../types';
import { useMemo } from 'react';
import { capitalize } from '../utils/Utils';
interface ReusableDropdownProps extends DropdownProps {
options: string[];
placeholder?: string;
defaultValue?: string;
children?: React.ReactNode;
view?: 'ContentView' | 'GraphView';
isDisabled: boolean;
}
const DropdownComponent: React.FC<ReusableDropdownProps> = ({
options,
placeholder,
defaultValue,
onSelect,
children,
view,
isDisabled,
}) => {
const handleChange = (selectedOption: OptionType | null | void) => {
onSelect(selectedOption);
};
const allOptions = useMemo(() => options, [options]);
return (
<>
<div className={view === 'ContentView' ? 'w-[150px]' : ''}>
<Dropdown
type='select'
aria-label='A selection dropdown'
selectProps={{
onChange: handleChange,
options: allOptions?.map((option) => ({
label: option.includes('LLM_MODEL_CONFIG_')
? capitalize(option.split('LLM_MODEL_CONFIG_').at(-1) as string)
: capitalize(option),
value: option,
})),
placeholder: placeholder || 'Select an option',
defaultValue: defaultValue ? { label: capitalize(defaultValue), value: defaultValue } : undefined,
menuPlacement: 'auto',
isDisabled: isDisabled,
}}
size='medium'
fluid
/>
{children}
</div>
</>
);
};
export default DropdownComponent;