Skip to content

Commit

Permalink
refactor(dropdown): unstyled trigger, separate button
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Feb 27, 2024
1 parent 5b6bbfc commit 38146b3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function RecipientIdentifierTypeDropdown(props: RecipientIdentifierTypeDr
const { activeRecipientIdentifierType, onSelectRecipientIdentifierType } = props;
return (
<DropdownMenu.Root>
<DropdownMenu.UnstyledTrigger>
<DropdownMenu.Trigger>
<Flag
reverse
img={<ChevronDownIcon variant="small" />}
Expand All @@ -38,7 +38,7 @@ export function RecipientIdentifierTypeDropdown(props: RecipientIdentifierTypeDr
>
{activeRecipientIdentifierType}
</Flag>
</DropdownMenu.UnstyledTrigger>
</DropdownMenu.Trigger>
<DropdownMenu.Portal>
<DropdownMenu.Content>
<DropdownMenu.Group>
Expand Down
4 changes: 2 additions & 2 deletions src/app/ui/components/dowpdown-menu/dropdown-menu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export const DropdownMenu: Story = {
render: () => (
<Component.Root>
<Component.Trigger>
<styled.button>
<Component.Button>
<HStack gap="space.02" width="100%">
<styled.span textStyle="label.02">Options</styled.span>
<ChevronDownIcon variant="small" />
</HStack>
</styled.button>
</Component.Button>
</Component.Trigger>
<Component.Portal>
<Component.Content align="start" sideOffset={8}>
Expand Down
27 changes: 11 additions & 16 deletions src/app/ui/components/dowpdown-menu/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ReactNode, forwardRef } from 'react';

import * as RadixDropdownMenu from '@radix-ui/react-dropdown-menu';
import { css } from 'leather-styles/css';
import { type HTMLStyledProps, styled } from 'leather-styles/jsx';

import { itemBaseStyles, itemInteractiveStyles } from '../item/item-interactive';

Expand All @@ -11,9 +12,7 @@ export interface DropdownMenuItem {
label: string;
}

const Root = RadixDropdownMenu.Root;

const dropdownTriggerStyles = css({
const dropdownButtonStyles = css({
bg: 'ink.background-primary',
borderRadius: 'xs',
fontWeight: 500,
Expand All @@ -22,15 +21,13 @@ const dropdownTriggerStyles = css({
px: 'space.04',
py: 'space.03',
textStyle: 'label.02',
'&[data-state=open]': {
'[data-state=open] &': {
bg: 'ink.component-background-pressed',
},
});
const Trigger: typeof RadixDropdownMenu.Trigger = forwardRef((props, ref) => (
<RadixDropdownMenu.Trigger className={dropdownTriggerStyles} ref={ref} {...props} />
));

const Portal = RadixDropdownMenu.Portal;
function Button(props: HTMLStyledProps<'button'>) {
return <styled.button className={dropdownButtonStyles} {...props} />;
}

const dropdownContentStyles = css({
alignItems: 'center',
Expand All @@ -54,8 +51,6 @@ const Content: typeof RadixDropdownMenu.Content = forwardRef((props, ref) => (
<RadixDropdownMenu.Content className={dropdownContentStyles} ref={ref} {...props} />
));

const Group = RadixDropdownMenu.Group;

const dropdownMenuLabelStyles = css({
color: 'ink.text-subdued',
height: 'auto',
Expand Down Expand Up @@ -87,12 +82,12 @@ const Separator: typeof RadixDropdownMenu.Separator = forwardRef((props, ref) =>
));

export const DropdownMenu = {
Root,
Trigger,
UnstyledTrigger: RadixDropdownMenu.Trigger,
Portal,
Root: RadixDropdownMenu.Root,
Trigger: RadixDropdownMenu.Trigger,
Group: RadixDropdownMenu.Group,
Portal: RadixDropdownMenu.Portal,
Button,
Content,
Group,
Label,
Item,
Separator,
Expand Down
1 change: 0 additions & 1 deletion src/app/ui/components/flag/flag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export function Flag({
return (
<Flex
flexDirection={reverse ? 'row-reverse' : 'row'}
data-reversed={reverse}
width="100%"
data-align={align}
className={flagStyles}
Expand Down

0 comments on commit 38146b3

Please sign in to comment.