-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components)!: add
Menu
, MenuItem
, MenuTrigger
, Header
, `…
…Keyboard`, `Section`, `Separator`, and `Text` (#1154) * feat(components): add menu * feat: add supporting components * feat: support slots with selection * feat!: support grid line names * refactor: update class selectors * chore: add changeset * docs: update migration guidelines * feat: update story * feat: add tests * fix: align headers * fix: add missing styles * fix: excludeDecorators
- Loading branch information
Showing
29 changed files
with
590 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
"@launchpad-ui/split-button": minor | ||
"@launchpad-ui/inline-edit": minor | ||
"@launchpad-ui/snackbar": minor | ||
"@launchpad-ui/tooltip": minor | ||
"@launchpad-ui/button": minor | ||
"@launchpad-ui/filter": minor | ||
"@launchpad-ui/alert": minor | ||
"@launchpad-ui/form": minor | ||
"@launchpad-ui/menu": minor | ||
"@launchpad-ui/core": minor | ||
"@launchpad-ui/icons": minor | ||
--- | ||
|
||
Change class pattern to `[hash]_[local]` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@launchpad-ui/components": patch | ||
--- | ||
|
||
Add `Menu`, `MenuItem`, `MenuTrigger`, `Header`, `Keyboard`, `Section`, `Separator`, and `Text` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Popover, Menu, MenuItem, MenuTrigger, Button } from '@launchpad-ui/components'; | ||
|
||
export default function Index() { | ||
return ( | ||
<MenuTrigger> | ||
<Button>Trigger</Button> | ||
<Popover isOpen> | ||
<Menu> | ||
<MenuItem>Item one</MenuItem> | ||
<MenuItem>Item two</MenuItem> | ||
<MenuItem>Item three</MenuItem> | ||
</Menu> | ||
</Popover> | ||
</MenuTrigger> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { it, expect, describe } from 'vitest'; | ||
|
||
import { render, screen, userEvent } from '../../../test/utils'; | ||
import { Menu, MenuItem, MenuTrigger, Button, Popover } from '../src'; | ||
|
||
describe('Menu', () => { | ||
it('renders', async () => { | ||
const user = userEvent.setup(); | ||
render( | ||
<MenuTrigger> | ||
<Button>Trigger</Button> | ||
<Popover> | ||
<Menu> | ||
<MenuItem>Item one</MenuItem> | ||
<MenuItem>Item two</MenuItem> | ||
<MenuItem>Item three</MenuItem> | ||
</Menu> | ||
</Popover> | ||
</MenuTrigger> | ||
); | ||
|
||
await user.click(screen.getByRole('button')); | ||
expect(await screen.findByRole('menu')).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Header } from 'react-aria-components'; | ||
|
||
export { Header }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Keyboard } from 'react-aria-components'; | ||
|
||
export { Keyboard }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import type { ForwardedRef } from 'react'; | ||
import type { | ||
MenuProps as AriaMenuProps, | ||
MenuItemProps, | ||
MenuTriggerProps, | ||
} from 'react-aria-components'; | ||
|
||
import { Icon } from '@launchpad-ui/icons'; | ||
import { cva } from 'class-variance-authority'; | ||
import { forwardRef } from 'react'; | ||
import { | ||
Menu as AriaMenu, | ||
MenuItem as AriaMenuItem, | ||
MenuTrigger, | ||
composeRenderProps, | ||
} from 'react-aria-components'; | ||
|
||
import styles from './styles/Menu.module.css'; | ||
|
||
type MenuProps<T> = AriaMenuProps<T>; | ||
|
||
const menu = cva(styles.menu); | ||
const item = cva(styles.item); | ||
|
||
const _Menu = <T extends object>( | ||
{ className, ...props }: MenuProps<T>, | ||
ref: ForwardedRef<HTMLDivElement> | ||
) => { | ||
return <AriaMenu {...props} ref={ref} className={menu({ className })} />; | ||
}; | ||
|
||
/** | ||
* A menu displays a list of actions or options that a user can choose. | ||
* | ||
* https://react-spectrum.adobe.com/react-aria/Menu.html | ||
*/ | ||
const Menu = forwardRef(_Menu); | ||
|
||
const _MenuItem = <T extends object>( | ||
props: MenuItemProps<T>, | ||
ref: ForwardedRef<HTMLDivElement> | ||
) => { | ||
return ( | ||
<AriaMenuItem | ||
{...props} | ||
ref={ref} | ||
className={composeRenderProps(props.className, (className, renderProps) => | ||
item({ ...renderProps, className }) | ||
)} | ||
> | ||
{composeRenderProps(props.children, (children, { selectionMode, isSelected }) => ( | ||
<> | ||
{selectionMode !== 'none' && ( | ||
<span className={styles.check}>{isSelected && <Icon name="check" size="small" />}</span> | ||
)} | ||
{children} | ||
</> | ||
))} | ||
</AriaMenuItem> | ||
); | ||
}; | ||
|
||
/** | ||
* A MenuItem represents an individual action in a Menu. | ||
*/ | ||
const MenuItem = forwardRef(_MenuItem); | ||
|
||
export { Menu, MenuItem, MenuTrigger }; | ||
export type { MenuProps, MenuItemProps, MenuTriggerProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { SectionProps } from 'react-aria-components'; | ||
|
||
import { Section } from 'react-aria-components'; | ||
|
||
export { Section }; | ||
export type { SectionProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { SeparatorProps } from 'react-aria-components'; | ||
|
||
import { Separator } from 'react-aria-components'; | ||
|
||
export { Separator }; | ||
export type { SeparatorProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { TextProps } from 'react-aria-components'; | ||
|
||
import { Text } from 'react-aria-components'; | ||
|
||
export { Text }; | ||
export type { TextProps }; |
Oops, something went wrong.