mirror of https://github.com/buster-so/buster.git
close on select update
This commit is contained in:
parent
f235d1a4a8
commit
49337658ea
|
@ -12,6 +12,11 @@ const meta: Meta<typeof Dropdown> = {
|
||||||
closeOnSelect: {
|
closeOnSelect: {
|
||||||
control: 'boolean',
|
control: 'boolean',
|
||||||
defaultValue: true
|
defaultValue: true
|
||||||
|
},
|
||||||
|
align: {
|
||||||
|
control: 'select',
|
||||||
|
options: ['start', 'center', 'end'],
|
||||||
|
defaultValue: 'start'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tags: ['autodocs']
|
tags: ['autodocs']
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
} from './DropdownBase';
|
} from './DropdownBase';
|
||||||
import { CircleSpinnerLoader } from '../loaders/CircleSpinnerLoader';
|
import { CircleSpinnerLoader } from '../loaders/CircleSpinnerLoader';
|
||||||
import { useMemoizedFn } from 'ahooks';
|
import { useMemoizedFn } from 'ahooks';
|
||||||
|
import { cn } from '@/lib/classMerge';
|
||||||
|
|
||||||
export interface DropdownItem {
|
export interface DropdownItem {
|
||||||
label: React.ReactNode;
|
label: React.ReactNode;
|
||||||
|
@ -27,7 +28,6 @@ export interface DropdownItem {
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
icon?: React.ReactNode;
|
icon?: React.ReactNode;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
link?: string;
|
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
items?: (DropdownItem | DropdownDivider)[];
|
items?: (DropdownItem | DropdownDivider)[];
|
||||||
|
@ -47,6 +47,9 @@ export interface DropdownProps extends DropdownMenuProps {
|
||||||
maxWidth?: number;
|
maxWidth?: number;
|
||||||
closeOnSelect?: boolean;
|
closeOnSelect?: boolean;
|
||||||
onSelect?: (itemId: string) => void;
|
onSelect?: (itemId: string) => void;
|
||||||
|
align?: 'start' | 'center' | 'end';
|
||||||
|
side?: 'top' | 'right' | 'bottom' | 'left';
|
||||||
|
contentClassName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dropdownItemKey = (item: DropdownItem | DropdownDivider, index: number) => {
|
const dropdownItemKey = (item: DropdownItem | DropdownDivider, index: number) => {
|
||||||
|
@ -59,17 +62,20 @@ export const Dropdown: React.FC<DropdownProps> = React.memo(
|
||||||
items = [],
|
items = [],
|
||||||
selectType = 'default',
|
selectType = 'default',
|
||||||
menuLabel,
|
menuLabel,
|
||||||
minWidth = 200,
|
minWidth = 240,
|
||||||
maxWidth,
|
maxWidth,
|
||||||
closeOnSelect = true,
|
closeOnSelect = true,
|
||||||
onSelect,
|
onSelect,
|
||||||
children,
|
children,
|
||||||
|
align = 'center',
|
||||||
|
side = 'bottom',
|
||||||
|
contentClassName,
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>{children}</DropdownMenuTrigger>
|
<DropdownMenuTrigger asChild>{children}</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent className="w-56">
|
<DropdownMenuContent className={cn('w-56', contentClassName)} align={align} side={side}>
|
||||||
{menuLabel && (
|
{menuLabel && (
|
||||||
<>
|
<>
|
||||||
<DropdownMenuLabel>{menuLabel}</DropdownMenuLabel>
|
<DropdownMenuLabel>{menuLabel}</DropdownMenuLabel>
|
||||||
|
@ -129,7 +135,6 @@ const DropdownItem = ({
|
||||||
onClick,
|
onClick,
|
||||||
icon,
|
icon,
|
||||||
disabled,
|
disabled,
|
||||||
link,
|
|
||||||
loading,
|
loading,
|
||||||
selected,
|
selected,
|
||||||
index,
|
index,
|
||||||
|
|
|
@ -83,7 +83,7 @@ const DropdownMenuItem = React.forwardRef<
|
||||||
closeOnSelect?: boolean;
|
closeOnSelect?: boolean;
|
||||||
selectType?: string;
|
selectType?: string;
|
||||||
}
|
}
|
||||||
>(({ className, onClick, closeOnSelect, inset, selectType, ...props }, ref) => (
|
>(({ className, closeOnSelect = true, onClick, inset, selectType, ...props }, ref) => (
|
||||||
<DropdownMenuPrimitive.Item
|
<DropdownMenuPrimitive.Item
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
|
@ -92,7 +92,7 @@ const DropdownMenuItem = React.forwardRef<
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (closeOnSelect) {
|
if (!closeOnSelect) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ const DropdownMenuCheckboxItem = React.forwardRef<
|
||||||
closeOnSelect?: boolean;
|
closeOnSelect?: boolean;
|
||||||
selectType?: string;
|
selectType?: string;
|
||||||
}
|
}
|
||||||
>(({ className, children, onClick, checked, closeOnSelect, selectType, ...props }, ref) => (
|
>(({ className, children, onClick, checked, closeOnSelect = true, selectType, ...props }, ref) => (
|
||||||
<DropdownMenuPrimitive.CheckboxItem
|
<DropdownMenuPrimitive.CheckboxItem
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
|
|
Loading…
Reference in New Issue