mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 01:08:28 +02:00
Remove most of Radix UI
This commit is contained in:
35
src-web/components/core/RadioDropdown.tsx
Normal file
35
src-web/components/core/RadioDropdown.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import { memo, useMemo } from 'react';
|
||||
import type { DropdownProps } from './Dropdown';
|
||||
import { Dropdown } from './Dropdown';
|
||||
import { Icon } from './Icon';
|
||||
|
||||
export interface RadioDropdownItem {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface RadioDropdownProps {
|
||||
value: string;
|
||||
onChange: (bodyType: string) => void;
|
||||
items: RadioDropdownItem[];
|
||||
children: DropdownProps['children'];
|
||||
}
|
||||
|
||||
export const RadioDropdown = memo(function RadioDropdown({
|
||||
value,
|
||||
items,
|
||||
onChange,
|
||||
children,
|
||||
}: RadioDropdownProps) {
|
||||
const dropdownItems = useMemo(
|
||||
() =>
|
||||
items.map(({ label, value: v }) => ({
|
||||
label,
|
||||
onSelect: () => onChange(v),
|
||||
leftSlot: <Icon icon={value === v ? 'check' : 'empty'} />,
|
||||
})),
|
||||
[value, items],
|
||||
);
|
||||
|
||||
return <Dropdown items={dropdownItems}>{children}</Dropdown>;
|
||||
});
|
||||
Reference in New Issue
Block a user