mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-04 01:18:20 +02:00
This PR extracts the dialog form that we created for the new project form into a shared component in the `common` folder. Most of the code has been lifted and shifted, but there's been some minor adjustments along the way. The main file is `frontend/src/component/common/DialogFormTemplate/DialogFormTemplate.tsx`. Everything else is just cleanup.
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { type FC, useState } from 'react';
|
|
import { ConfigButton, type ConfigButtonProps } from './ConfigButton';
|
|
import { DropdownList, type DropdownListProps } from './DropdownList';
|
|
|
|
type MultiSelectConfigButtonProps = Pick<
|
|
ConfigButtonProps,
|
|
'button' | 'onOpen' | 'onClose' | 'description' | 'tooltip'
|
|
> &
|
|
Pick<DropdownListProps, 'search' | 'options'> & {
|
|
selectedOptions: Set<string>;
|
|
onChange: (values: Set<string>) => void;
|
|
};
|
|
|
|
export const MultiSelectConfigButton: FC<MultiSelectConfigButtonProps> = ({
|
|
selectedOptions,
|
|
onChange,
|
|
...rest
|
|
}) => {
|
|
const [anchorEl, setAnchorEl] = useState<HTMLDivElement | null>();
|
|
|
|
const handleToggle = (value: string) => {
|
|
if (selectedOptions.has(value)) {
|
|
selectedOptions.delete(value);
|
|
} else {
|
|
selectedOptions.add(value);
|
|
}
|
|
|
|
onChange(new Set(selectedOptions));
|
|
};
|
|
|
|
return (
|
|
<ConfigButton {...rest} anchorEl={anchorEl} setAnchorEl={setAnchorEl}>
|
|
<DropdownList
|
|
multiselect={{
|
|
selectedOptions,
|
|
}}
|
|
onChange={handleToggle}
|
|
{...rest}
|
|
/>
|
|
</ConfigButton>
|
|
);
|
|
};
|