-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
51 lines (45 loc) · 1.3 KB
/
index.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
import React, { useState } from 'react'
import { MenuListItemType, MIcon } from '@mexit/core'
import { Group } from '../../Style/Layouts'
import { ItemLabel, Menu, MenuItem } from '../FloatingElements'
import { IconDisplay } from '../IconDisplay'
import { getMIcon } from '../Icons'
interface SelectProps {
items: MenuListItemType[]
onClick?: (option: MenuListItemType) => void
label?: string
root?: any
}
export const Select: React.FC<SelectProps> = ({ items, onClick, label = 'Select', root }) => {
const [selected, setSelected] = useState(null)
const handleOnClick = (option: MenuListItemType) => {
setSelected(option)
if (onClick) onClick(option)
else if (option.onSelect) option.onSelect(option)
}
return (
<Menu
noHover
noBackground
root={root}
values={
<Group>
<ItemLabel fontSize="small">{selected?.label ?? items?.at(0)?.label ?? label}</ItemLabel>
<IconDisplay icon={getMIcon('ICON', 'bi:caret-down-fill')} size={10} />
</Group>
}
>
{items.map((op) => {
return (
<MenuItem
fontSize="small"
key={op.id}
icon={op.icon as MIcon}
onClick={(e) => handleOnClick(op)}
label={op.label}
/>
)
})}
</Menu>
)
}