-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5dc0775
commit 26c25da
Showing
7 changed files
with
158 additions
and
7 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
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 @@ | ||
export * from "./navbar"; |
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,4 @@ | ||
.mykn-navbar { | ||
float: right; // Fallback. | ||
float: inline-end | ||
} |
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,74 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { expect, userEvent, within } from "@storybook/test"; | ||
import React from "react"; | ||
|
||
import { Button, ButtonLink } from "../button"; | ||
import { Outline } from "../icon"; | ||
import { Navbar } from "./navbar"; | ||
|
||
const meta = { | ||
title: "Controls/Navbar", | ||
component: Navbar, | ||
} satisfies Meta<typeof Navbar>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const NavbarComponent: Story = { | ||
args: { | ||
children: ( | ||
<> | ||
<Button variant="transparent"> | ||
<Outline.PencilIcon /> | ||
Zaaktypen | ||
</Button> | ||
|
||
<Button variant="transparent"> | ||
<Outline.ClipboardDocumentIcon /> | ||
Documenttypen | ||
</Button> | ||
|
||
<ButtonLink | ||
href="https://www.example.com" | ||
target="_blank" | ||
variant="transparent" | ||
> | ||
<Outline.UserIcon /> | ||
Admin | ||
</ButtonLink> | ||
|
||
<Button variant="primary"> | ||
<Outline.ArrowRightStartOnRectangleIcon /> | ||
Uitloggen | ||
</Button> | ||
</> | ||
), | ||
}, | ||
}; | ||
|
||
export const NavbarOnMobile: Story = { | ||
...NavbarComponent, | ||
parameters: { | ||
viewport: { defaultViewport: "mobile1" }, | ||
}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
const button = canvas.getByRole("button"); | ||
|
||
// Click opens, escape closes. | ||
await userEvent.click(button, { delay: 10 }); | ||
expect(await canvas.findByRole("dialog")).toBeVisible(); | ||
userEvent.keyboard("{Escape}"); | ||
expect(await canvas.findByRole("dialog")).not.toBeVisible(); | ||
await userEvent.click(button, { delay: 10 }); | ||
expect(await canvas.findByRole("dialog")).toBeVisible(); | ||
|
||
// Tab focuses items. | ||
await userEvent.tab({ delay: 10 }); | ||
await userEvent.tab({ delay: 10 }); | ||
await userEvent.tab({ delay: 10 }); | ||
|
||
const buttons = await canvas.findAllByRole("button"); | ||
expect(buttons[buttons.length - 1]).toBe(document.activeElement); | ||
}, | ||
}; |
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,60 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
import { Dropdown } from "../dropdown"; | ||
import { Outline } from "../icon"; | ||
import { Toolbar, ToolbarProps } from "../toolbar"; | ||
import "./navbar.scss"; | ||
|
||
export type NavbarProps = ToolbarProps; | ||
|
||
/** | ||
* Shows a toolbar or dropdown based on mobile/desktop. | ||
* @param children | ||
* @param props | ||
* @constructor | ||
*/ | ||
export const Navbar: React.FC<NavbarProps> = ({ children, ...props }) => { | ||
const [isMobile, setIsMobile] = useState( | ||
window?.matchMedia("(max-width: 767px)").matches, | ||
); | ||
|
||
/** | ||
* Updates `isMobile` on resize. | ||
*/ | ||
useEffect(() => { | ||
const onResize = () => | ||
setIsMobile(window?.matchMedia("(max-width: 767px)").matches); | ||
|
||
window.addEventListener("resize", onResize); | ||
return () => window.removeEventListener("resize", onResize); | ||
}); | ||
|
||
/** | ||
* Renders the toolbar. | ||
*/ | ||
const renderToolbar = () => ( | ||
<Toolbar | ||
align="end" | ||
variant={isMobile ? "normal" : "transparent"} | ||
{...props} | ||
> | ||
{children} | ||
</Toolbar> | ||
); | ||
|
||
return ( | ||
<div className="mykn-navbar"> | ||
{isMobile ? ( | ||
<Dropdown | ||
label={<Outline.Bars2Icon />} | ||
variant="transparent" | ||
aria-label="Menu openen/sluiten" | ||
> | ||
{renderToolbar()} | ||
</Dropdown> | ||
) : ( | ||
renderToolbar() | ||
)} | ||
</div> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
@use '../../settings/style'; | ||
|
||
.mykn-page { | ||
background-color: var(--theme-color-primary-200); | ||
container-name: page; | ||
container-type: size; | ||
box-sizing: border-box; | ||
padding: var(--spacing-h-xl); | ||
width: 100%; | ||
height: 100%; | ||
padding: var(--spacing-v-xl) var(--spacing-h-xl); | ||
|
||
@media screen and (min-width: style.$breakpoint-desktop) { | ||
padding: var(--spacing-v-xl) var(--spacing-h-xl); | ||
} | ||
} |
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