import React from 'react' import * as Ariakit from '@ariakit/react' import { IconSolidCheckCircle, IconSolidMinus } from '../icons' import * as styles from './styles.css' import { Text } from '../Text/Text' import { Box } from '../Box/Box' type Option = { key: string render: React.ReactNode clearsOnClick?: boolean } type Props = { label: string icon?: React.ReactNode defaultValue?: string value: string[] valueRender: () => React.ReactNode options: Option[] onChange: (value: string[]) => void } export const MultiSelectButton: React.FC = ({ label, icon, defaultValue, value, valueRender, options, onChange, }) => { const selectStore = Ariakit.useSelectStore({ defaultValue: defaultValue ? [defaultValue] : [], value: value, setValue: (value: string[]) => onChange(value), }) return ( {label} <> {icon} {valueRender()} {/* There is a bug in v0.2.17 of Ariakit where you need to have this arrow rendered or else positioning of the popover breaks. We render it, but hide it by setting size={0}. This is an issue with anything using a popover coming from the floating-ui library. */} {options.map((option: Option) => (
{option.clearsOnClick && !value.includes(option.key) ? ( ) : ( )}
{option.render}
))}
) }