-
Notifications
You must be signed in to change notification settings - Fork 0
Responsive navigation container #51
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
Open
grahamc
wants to merge
5
commits into
main
Choose a base branch
from
grahamc/navigation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b776f2
Add a mixin for borders
grahamc cdd6568
Add a Navigation component that auto-hides and stuff
grahamc ee52f7c
Make a more fully fleshed out PageLayout
grahamc c777466
Reuse keys
grahamc 5bbc07d
drop header inside Header, and set it in PageLayout
grahamc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,116 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
|
|
||
| import Navigation from "."; | ||
| import { Placeholder } from "../Placeholder"; | ||
| import Header from "../Header"; | ||
| import ColorSchemeToggle from "../ColorSchemeToggle"; | ||
| import DetSysIcon from "../DetSysIcon"; | ||
|
|
||
| const meta = { | ||
| title: "Molecules/Navigation", | ||
| component: Navigation, | ||
| argTypes: { | ||
| initialState: { | ||
| options: ["open", "closed"], | ||
| }, | ||
| elements: { type: "function" }, | ||
| }, | ||
| } satisfies Meta<typeof Navigation>; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| initialState: undefined, | ||
| elements: [ | ||
| <Placeholder key="primary" height="100%" label="Primary Element" />, | ||
| <Placeholder key="nav" height="100%" label="Navigation Link" />, | ||
| ], | ||
| }, | ||
| render: (props) => ( | ||
| <div | ||
| style={{ | ||
| height: "300px", | ||
| width: "500px", | ||
| border: "1px solid black", | ||
| display: "flex", | ||
| justifyContent: "end", | ||
| }} | ||
| > | ||
| <Navigation {...props} /> | ||
| </div> | ||
| ), | ||
| }; | ||
|
|
||
| export const InHeader: Story = { | ||
| args: { | ||
| initialState: undefined, | ||
| elements: [ | ||
| <Placeholder key="lorem" height="100%" label="Lorem" />, | ||
| <Placeholder key="ipsum" height="100%" label="Ipsum" />, | ||
| ], | ||
| }, | ||
| render: (props) => ( | ||
| <Header | ||
| logo={<DetSysIcon size="base" />} | ||
| elements={[ | ||
| <ColorSchemeToggle key="color-scheme-toggle" />, | ||
| <Navigation key="nav" {...props} />, | ||
| ]} | ||
| /> | ||
| ), | ||
| }; | ||
|
|
||
| export const DefaultOpen: Story = { | ||
| args: { | ||
| initialState: "open", | ||
| elements: [ | ||
| <Placeholder key="lorem" height="100%" label="Lorem" />, | ||
| <Placeholder key="ipsum" height="100%" label="Ipsum" />, | ||
| ], | ||
| }, | ||
| render: (props) => ( | ||
| <> | ||
| <div | ||
| style={{ | ||
| height: "300px", | ||
| width: "500px", | ||
| border: "1px solid black", | ||
| display: "flex", | ||
| justifyContent: "end", | ||
| }} | ||
| > | ||
| <Navigation {...props} /> | ||
| </div> | ||
| </> | ||
| ), | ||
| }; | ||
|
|
||
| export const InHeaderOpen: Story = { | ||
| args: { | ||
| initialState: "open", | ||
| elements: [ | ||
| <a key="docs" href="#"> | ||
| Docs | ||
| </a>, | ||
| <a key="flakes" href="#"> | ||
| Flakes | ||
| </a>, | ||
| <a key="orgs" href="#"> | ||
| Orgs | ||
| </a>, | ||
| <Placeholder key="lorem" height="100%" label="Lorem" />, | ||
| <Placeholder key="ipsum" height="100%" label="Ipsum" />, | ||
| ], | ||
| }, | ||
| render: (props) => ( | ||
| <Header | ||
| logo={<DetSysIcon size="base" />} | ||
| elements={[ | ||
| <ColorSchemeToggle key="color-scheme-toggle" />, | ||
| <Navigation key="nav" {...props} />, | ||
| ]} | ||
| /> | ||
| ), | ||
| }; |
This file contains hidden or 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,75 @@ | ||
| @use "sass:map"; | ||
|
|
||
| @use "../sass/mixins"; | ||
| @use "../sass/tokens"; | ||
| @use "../sass/functions"; | ||
|
|
||
| @media screen and (width >= 1024px) { | ||
| .navigation { | ||
| height: 24px; // Matches the svg-icon height used by the expander in closed mode | ||
| padding: 4px; // Matches the svg-icon height used by the expander in closed mode | ||
| .navigation__expand { | ||
| display: none; | ||
| } | ||
|
|
||
| .navigation__elements { | ||
| height: 24px; | ||
| display: flex; | ||
| flex-direction: row; | ||
| align-items: center; | ||
| gap: 1em; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @media screen and (width < 1024px) { | ||
| .navigation { | ||
| position: relative; | ||
|
|
||
| .navigation__expand { | ||
| @include mixins.svg-button; | ||
| } | ||
|
|
||
| .navigation__elements { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: map.get(tokens.$spacing, sm); | ||
|
|
||
| max-width: 100vw; | ||
|
|
||
| position: absolute; | ||
| transform-origin: 100% 0; | ||
| z-index: 10; | ||
| right: 0; | ||
| top: calc(100% + #{map.get(tokens.$spacing, xs)}); | ||
|
|
||
| @include mixins.pad(base); | ||
| border-radius: map.get(tokens.$border-radius, base); | ||
|
|
||
| background-color: map.get(tokens.$brand, very-black); | ||
| $offset: map.get(tokens.$spacing, xs); | ||
| border-style: solid; | ||
| border-width: 1px; | ||
| border-color: map.get(tokens.$brand, black); | ||
| @include mixins.light-mode { | ||
| border: none; | ||
| background-color: map.get(tokens.$brand, white); | ||
| box-shadow: | ||
| $offset $offset $offset 0px map.get(tokens.$brand, light), | ||
| -$offset $offset $offset 0px map.get(tokens.$brand, light); | ||
| } | ||
| } | ||
|
|
||
| .navigation__element { | ||
| width: min(320px, 100vw); | ||
|
|
||
| @media screen and (width < 650px) { | ||
| width: 268px; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .navigation--closed .navigation__elements { | ||
| display: none; | ||
| } | ||
| } |
This file contains hidden or 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,57 @@ | ||
| import { useId, useState, type FC } from "react"; | ||
|
|
||
| import "./index.scss"; | ||
| import React from "react"; | ||
| import clsx from "clsx"; | ||
| import { Bars3Icon } from "@heroicons/react/24/outline"; | ||
|
|
||
| export interface NavigationProps { | ||
| initialState?: "open" | "closed"; | ||
| elements: React.ReactElement[]; | ||
| } | ||
|
|
||
| const Navigation: FC<NavigationProps> = ({ | ||
| elements, | ||
| initialState = "closed", | ||
| }) => { | ||
| const navigationId = useId(); | ||
|
|
||
| const [menuState, setMenuState] = useState<boolean>(initialState === "open"); | ||
|
|
||
| const toggleNavigation = () => { | ||
| setMenuState((prev) => !prev); | ||
| }; | ||
|
|
||
| return ( | ||
| <nav | ||
| className={clsx( | ||
| "navigation", | ||
| menuState ? "navigation--open" : "navigation--closed", | ||
| )} | ||
| > | ||
| <button | ||
| type="button" | ||
| className="navigation__expand" | ||
| aria-label={menuState ? "Close navigation" : "Open navigation"} | ||
| aria-expanded={menuState} | ||
| aria-controls={navigationId} | ||
| onClick={toggleNavigation} | ||
| > | ||
| <Bars3Icon aria-hidden="true" focusable="false" /> | ||
| </button> | ||
| <div | ||
| id={navigationId} | ||
| aria-hidden={!menuState} | ||
| className="navigation__elements" | ||
| > | ||
| {elements.map((child, idx) => ( | ||
| <div key={child.key ?? idx} className="navigation__element"> | ||
| {child} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </nav> | ||
| ); | ||
| }; | ||
|
|
||
| export default Navigation; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.