Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: DropdownMenu #1704

Merged
merged 6 commits into from
Aug 19, 2024
Merged

feat: DropdownMenu #1704

merged 6 commits into from
Aug 19, 2024

Conversation

VanishMax
Copy link
Contributor

@VanishMax VanishMax commented Aug 16, 2024

Closes prax-wallet/prax#160

Implement not exactly MenuItem but DropdownMenu because the MenuItem from Figma designs is meant to be used within the dropdown. Radix-ui has great support for these component with a11y enhancement.

The MenuItem from Figma is used for DropdownMenu.Item, DropdownMenu.RadioItem, and DropdownMenu.CheckboxItem components.

Design – https://www.figma.com/design/WKgXSVVK3L0EI0sr9Hwjoa/penumbra-UI-library?node-id=778-49265&m=dev

Storybook – https://penumbra-ui-preview--pr1704-feat-prax-160-menu-mvj0lz31.web.app/?path=/docs/ui-library-dropdownmenu--docs

@VanishMax VanishMax requested review from jessepinho and a team August 16, 2024 16:02
@VanishMax VanishMax self-assigned this Aug 16, 2024
Copy link
Contributor

github-actions bot commented Aug 16, 2024

Visit the preview URL for this PR (updated for commit 656479e):

https://penumbra-ui-preview--pr1704-feat-prax-160-menu-mvj0lz31.web.app

(expires Mon, 26 Aug 2024 08:54:36 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 709d729610ef7a6369b23f1cb2b820a60cc685b1

@@ -200,6 +201,7 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
? theme.borderRadius.sm
: theme.borderRadius.full
}
{...props}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Radix, asChild prop will only work if the nested component passes the rest props.

It doesn't mean we allow users to pass whatever they want - at least TypeScript disagrees with it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Great solution. I was kinda bothered by the fact that I wasn't previously spreading remaining props when Radix wants us to, but I didn't want to change it for TypeScript reasons.

request: could you add a note documenting this? so that future maintainers don't think that there should be add'l props in TypeScript?

*
* @see https://www.radix-ui.com/primitives/docs/guides/composition
*/
asChild?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed asChild prop from the Popover.Trigger and DropdownMenu.Trigger. Since we do not users to change the component styles, it makes to sense to allow asChild={false} – it will always be an unstyled HTML-element

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I could see there being a use case where users want to just have plain text as the trigger. But maybe that's not even a good idea. So, no strong opinion here.

Comment on lines 88 to 90
DropdownMenu.RadioItem = RadioItem;
DropdownMenu.CheckboxItem = CheckboxItem;
DropdownMenu.Item = Item;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These components represent the MenuItem from the design

Comment on lines +50 to +53
&:focus:not(:disabled) {
background-color: ${props => props.theme.color.action.hoverOverlay};
outline: 2px solid ${props => getOutlineColorByActionType(props.theme, props.$actionType)};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the styles do not have :hover and we can't change it – Radix does not distinguish between hover and focus for the menu items. It means that hovering an item also makes it focused to not confuse the states: radix-ui/primitives#956 (comment)

Copy link
Contributor

@jessepinho jessepinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice work 👏🏻 I feel confident that Penumbra UI is in good hands :D

A few comments here and there, but nothing major. Feel free to merge after those are addressed.

packages/ui/src/DropdownMenu/checkbox-item.tsx Outdated Show resolved Hide resolved
packages/ui/src/utils/popover.ts Outdated Show resolved Hide resolved
*
* @see https://www.radix-ui.com/primitives/docs/guides/composition
*/
asChild?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I could see there being a use case where users want to just have plain text as the trigger. But maybe that's not even a good idea. So, no strong opinion here.

onChange?: (value: boolean) => void;
}

export const CheckboxItem = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: keep the dropdown menu open when selecting checkbox items

I couldn't figure out a way to do this in the docs, nor do I see in the code where you're closing the dropdown menu once a user clicks a menu item (maybe Radix does it automatically?). But it'd be nice to keep the dropdown menu open when clicking checkbox items specifically, since the user may wish to click more than one.

Not a blocker for this PR, though !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably investigate the use cases with time. Leaving as-is for now

@TalDerei
Copy link
Contributor

TalDerei commented Aug 16, 2024

Really nice work 👏🏻 I feel confident that Penumbra UI is in good hands :D

one last PR review for the books 📚

@VanishMax VanishMax merged commit 2788cf0 into main Aug 19, 2024
8 checks passed
@VanishMax VanishMax deleted the feat/#prax-160-menu-item branch August 19, 2024 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement MenuItem UI component
3 participants