[ui][dropdown] make button look like button

pull/547/head
Yangshun Tay 2 years ago
parent 2618784dd0
commit 7b4b120c2f

@ -199,7 +199,7 @@ export default function OffersTable({
)[0].label )[0].label
: OfferTableYoeOptions[0].label : OfferTableYoeOptions[0].label
} }
size="inherit"> size="md">
{OfferTableYoeOptions.map(({ label: itemLabel, value }) => ( {OfferTableYoeOptions.map(({ label: itemLabel, value }) => (
<DropdownMenu.Item <DropdownMenu.Item
key={value} key={value}

@ -184,7 +184,7 @@ export default function OffersTable({
)[0].label )[0].label
: OfferTableYoeOptions[0].label : OfferTableYoeOptions[0].label
} }
size="inherit"> size="md">
{OfferTableYoeOptions.map(({ label: itemLabel, value }) => ( {OfferTableYoeOptions.map(({ label: itemLabel, value }) => (
<DropdownMenu.Item <DropdownMenu.Item
key={value} key={value}

@ -7,10 +7,7 @@ const DropdownMenuAlignments: ReadonlyArray<DropdownMenuAlignment> = [
'start', 'start',
'end', 'end',
]; ];
const DropdownMenuSizes: ReadonlyArray<DropdownMenuSize> = [ const DropdownMenuSizes: ReadonlyArray<DropdownMenuSize> = ['sm', 'md', 'lg'];
'default',
'inherit',
];
export default { export default {
argTypes: { argTypes: {
@ -80,7 +77,7 @@ export function Basic({
Basic.args = { Basic.args = {
align: 'start', align: 'start',
label: 'More actions', label: 'More actions',
size: 'default', size: 'md',
}; };
export function Align() { export function Align() {
@ -103,7 +100,7 @@ export function Align() {
return ( return (
<div className="flex justify-between"> <div className="flex justify-between">
<DropdownMenu align="start" label="Select an action" size="default"> <DropdownMenu align="start" label="Select an action" size="md">
{menuItems.map(({ label, value }) => ( {menuItems.map(({ label, value }) => (
<DropdownMenu.Item <DropdownMenu.Item
key={value} key={value}
@ -115,7 +112,7 @@ export function Align() {
/> />
))} ))}
</DropdownMenu> </DropdownMenu>
<DropdownMenu align="end" label="Select an action" size="default"> <DropdownMenu align="end" label="Select an action" size="md">
{menuItems.map(({ label, value }) => ( {menuItems.map(({ label, value }) => (
<DropdownMenu.Item <DropdownMenu.Item
key={value} key={value}

@ -6,7 +6,7 @@ import { ChevronDownIcon } from '@heroicons/react/24/solid';
import DropdownMenuItem from './DropdownMenuItem'; import DropdownMenuItem from './DropdownMenuItem';
export type DropdownMenuAlignment = 'end' | 'start'; export type DropdownMenuAlignment = 'end' | 'start';
export type DropdownMenuSize = 'default' | 'inherit'; export type DropdownMenuSize = 'lg' | 'md' | 'sm';
type Props = Readonly<{ type Props = Readonly<{
align?: DropdownMenuAlignment; align?: DropdownMenuAlignment;
@ -22,24 +22,53 @@ const alignmentClasses: Record<DropdownMenuAlignment, string> = {
start: 'origin-top-left left-0', start: 'origin-top-left left-0',
}; };
const sizeClasses: Record<DropdownMenuSize, string> = {
lg: 'px-5 py-2.5',
md: 'px-4 py-2',
sm: 'px-2.5 py-1.5',
};
const baseClasses: Record<DropdownMenuSize, string> = {
lg: 'text-base rounded-xl',
md: 'text-sm rounded-lg',
sm: 'text-xs rounded-md',
};
const sizeIconSpacingEndClasses: Record<DropdownMenuSize, string> = {
lg: 'ml-3 -mr-1',
md: 'ml-2 -mr-1',
sm: 'ml-2 -mr-0.5',
};
const sizeIconClasses: Record<DropdownMenuSize, string> = {
lg: '!h-5 !w-5',
md: '!h-5 !w-5',
sm: '!h-4 !w-4',
};
export default function DropdownMenu({ export default function DropdownMenu({
align = 'start', align = 'start',
children, children,
label, label,
size = 'default', size = 'md',
}: Props) { }: Props) {
return ( return (
<Menu as="div" className="relative inline-block"> <Menu as="div" className="relative inline-block">
<div className="flex"> <div className="flex">
<Menu.Button <Menu.Button
className={clsx( className={clsx(
'group inline-flex items-center justify-center font-medium text-slate-700 hover:text-slate-900', 'group inline-flex items-center justify-center whitespace-nowrap border border-slate-300 bg-white font-medium text-slate-700 hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-slate-600 focus:ring-offset-2',
size === 'default' && 'text-sm', baseClasses[size],
sizeClasses[size],
)}> )}>
<div>{label}</div> <div>{label}</div>
<ChevronDownIcon <ChevronDownIcon
aria-hidden="true" aria-hidden="true"
className="-mr-1 ml-1 h-5 w-5 flex-shrink-0 text-slate-400 group-hover:text-slate-500" className={clsx(
'flex-shrink-0 text-slate-400 group-hover:text-slate-500',
sizeIconSpacingEndClasses[size],
sizeIconClasses[size],
)}
/> />
</Menu.Button> </Menu.Button>
</div> </div>

Loading…
Cancel
Save