Skip to content

Commit

Permalink
feat: Restore wrapping of items in Page Menu (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentSmedinga authored Mar 27, 2024
1 parent 848223b commit 4068e52
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 14 deletions.
5 changes: 5 additions & 0 deletions packages/css/src/components/page-menu/page-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
column-gap: var(--ams-page-menu-column-gap);
display: flex;
flex-direction: row;
flex-wrap: wrap;
list-style: none;
row-gap: var(--ams-page-menu-row-gap);

Expand All @@ -30,6 +31,10 @@
justify-content: end;
}

.ams-page-menu--no-wrap {
flex-wrap: nowrap;
}

@mixin page-menu-item {
color: var(--ams-page-menu-item-color);
display: inline-flex;
Expand Down
20 changes: 18 additions & 2 deletions packages/react/src/PageMenu/PageMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,27 @@ export type PageMenuProps = {
* If the menu itself aligns to the end of its container, you should set this to `true`.
*/
alignEnd?: boolean
/**
* Whether menu items should wrap if they don’t fit on a single row.
*/
wrap?: boolean
} & PropsWithChildren<HTMLAttributes<HTMLUListElement>>

const PageMenuRoot = forwardRef(
({ alignEnd, children, className, ...restProps }: PageMenuProps, ref: ForwardedRef<HTMLUListElement>) => (
<ul {...restProps} className={clsx('ams-page-menu', alignEnd && `ams-page-menu--align-end`, className)} ref={ref}>
(
{ alignEnd, children, className, wrap = true, ...restProps }: PageMenuProps,
ref: ForwardedRef<HTMLUListElement>,
) => (
<ul
{...restProps}
className={clsx(
'ams-page-menu',
alignEnd && `ams-page-menu--align-end`,
!wrap && `ams-page-menu--no-wrap`,
className,
)}
ref={ref}
>
{children}
</ul>
),
Expand Down
3 changes: 3 additions & 0 deletions storybook/src/components/Header/Header.docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import README from "../../../../packages/css/src/components/header/README.md?raw

## With links

Use a [Page Menu](?path=/docs/components-navigation-page-menu--docs) to add links.
A Page Menu in the Header should not wrap.

<Canvas of={HeaderStories.WithLinks} />

## With links and menu
Expand Down
6 changes: 3 additions & 3 deletions storybook/src/components/Header/Header.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const WithTitle: Story = {
export const WithLinks: Story = {
args: {
links: (
<PageMenu alignEnd>
<PageMenu alignEnd wrap={false}>
<PageMenu.Link href="#">Contact</PageMenu.Link>
<PageMenu.Link href="#">Mijn Amsterdam</PageMenu.Link>
<PageMenu.Link href="#" icon={SearchIcon}>
Expand All @@ -64,7 +64,7 @@ export const WithLinksAndMenu: Story = {
args: {
menu: <button className="ams-header__menu-button">Menu</button>,
links: (
<PageMenu alignEnd>
<PageMenu alignEnd wrap={false}>
<PageMenu.Link href="#">Contact</PageMenu.Link>
<PageMenu.Link href="#">Mijn Amsterdam</PageMenu.Link>
<PageMenu.Link href="#" icon={SearchIcon}>
Expand All @@ -86,7 +86,7 @@ export const WithTitleLinksAndMenu: Story = {
args: {
title: 'Aan de Amsterdamse grachten',
links: (
<PageMenu alignEnd>
<PageMenu alignEnd wrap={false}>
<PageMenu.Link href="#">Contact</PageMenu.Link>
<PageMenu.Link href="#">Mijn Amsterdam</PageMenu.Link>
<PageMenu.Link href="#" icon={SearchIcon}>
Expand Down
21 changes: 14 additions & 7 deletions storybook/src/components/PageMenu/PageMenu.docs.mdx
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { Canvas, Markdown, Meta, Primary } from "@storybook/blocks";
import { Canvas, Controls, Markdown, Meta, Primary } from "@storybook/blocks";
import * as PageMenuStories from "./PageMenu.stories.tsx";
import README from "../../../../packages/css/src/components/page-menu/README.md?raw";

<Meta of={PageMenuStories} />

<Markdown>{README}</Markdown>

<Primary />

<Controls />

## Examples

### Default
### Alignment

<Primary />
In the [Header](?path=/docs/components-containers-header--docs), the menu aligns to the end of the line.

<Canvas of={PageMenuStories.Alignment} />

## Right Alignment
### Wrapping

It may happen that all menu items do not fit on a single line, for example, in a medium-width window or with zoomed-in text.
If the menu itself is right-aligned, as is often the case in headers, then you should also right-align the items within it.
If all menu items do not fit on a single line, e.g. on a narrow screen or with zoomed-in text, they wrap to new lines.
This is often useful in the [Footer](?path=/docs/components-containers-footer--docs).
The Header has its own responsive behaviour; its Page Menu should be configured not to wrap.

<Canvas of={PageMenuStories.AlignEnd} />
<Canvas of={PageMenuStories.Wrapping} />
33 changes: 31 additions & 2 deletions storybook/src/components/PageMenu/PageMenu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@
*/

import { PageMenu } from '@amsterdam/design-system-react'
import { LoginIcon } from '@amsterdam/design-system-react-icons'
import { LoginIcon, SearchIcon } from '@amsterdam/design-system-react-icons'
import { Meta, StoryObj } from '@storybook/react'

const meta = {
title: 'Components/Navigation/Page Menu',
component: PageMenu,
args: {
alignEnd: false,
wrap: true,
},
argTypes: {
alignEnd: {
control: 'boolean',
},
wrap: {
control: 'boolean',
},
},
} satisfies Meta<typeof PageMenu>

export default meta
Expand All @@ -29,9 +41,26 @@ export const Default: Story = {
},
}

export const AlignEnd: Story = {
export const Alignment: Story = {
args: {
alignEnd: true,
children: [
<PageMenu.Link href="#" key={1}>
Contact
</PageMenu.Link>,
<PageMenu.Link href="#" key={2}>
Mijn Amsterdam
</PageMenu.Link>,
<PageMenu.Link href="#" icon={SearchIcon} key={3}>
Zoeken
</PageMenu.Link>,
],
wrap: false,
},
}

export const Wrapping: Story = {
args: {
children: [
<PageMenu.Link href="#" key={1}>
Onderzoeken
Expand Down

0 comments on commit 4068e52

Please sign in to comment.