-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
tutorial: update hamburger component to use button element #12171
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
bjohansebas
wants to merge
4
commits into
withastro:main
Choose a base branch
from
bjohansebas:accesibility
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.
+90
−61
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c20ac30
tutorial: update hamburger component to use button element
bjohansebas 81effa8
tutorial: update skillColor variable from navy to crimson in multiple…
bjohansebas 5e56b58
tutorial: rename Hamburger component to Menu and update related refer…
bjohansebas 1bf7051
tutorial: enhance theme toggle accessibility and layout in Header com…
bjohansebas 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,8 @@ Let's build a clickable icon to let your users toggle between light or dark mode | |
```astro title="src/components/ThemeIcon.astro" | ||
--- | ||
--- | ||
<button id="themeToggle"> | ||
<svg width="30px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> | ||
<button id="themeToggle" aria-label="Toggle theme"> | ||
<svg aria-hidden="true" width="30px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> | ||
<path class="sun" fill-rule="evenodd" d="M12 17.5a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zm0 1.5a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm12-7a.8.8 0 0 1-.8.8h-2.4a.8.8 0 0 1 0-1.6h2.4a.8.8 0 0 1 .8.8zM4 12a.8.8 0 0 1-.8.8H.8a.8.8 0 0 1 0-1.6h2.5a.8.8 0 0 1 .8.8zm16.5-8.5a.8.8 0 0 1 0 1l-1.8 1.8a.8.8 0 0 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM6.3 17.7a.8.8 0 0 1 0 1l-1.7 1.8a.8.8 0 1 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM12 0a.8.8 0 0 1 .8.8v2.5a.8.8 0 0 1-1.6 0V.8A.8.8 0 0 1 12 0zm0 20a.8.8 0 0 1 .8.8v2.4a.8.8 0 0 1-1.6 0v-2.4a.8.8 0 0 1 .8-.8zM3.5 3.5a.8.8 0 0 1 1 0l1.8 1.8a.8.8 0 1 1-1 1L3.5 4.6a.8.8 0 0 1 0-1zm14.2 14.2a.8.8 0 0 1 1 0l1.8 1.7a.8.8 0 0 1-1 1l-1.8-1.7a.8.8 0 0 1 0-1z"/> | ||
<path class="moon" fill-rule="evenodd" d="M16.5 6A10.5 10.5 0 0 1 4.7 16.4 8.5 8.5 0 1 0 16.4 4.7l.1 1.3zm-1.7-2a9 9 0 0 1 .2 2 9 9 0 0 1-11 8.8 9.4 9.4 0 0 1-.8-.3c-.4 0-.8.3-.7.7a10 10 0 0 0 .3.8 10 10 0 0 0 9.2 6 10 10 0 0 0 4-19.2 9.7 9.7 0 0 0-.9-.3c-.3-.1-.7.3-.6.7a9 9 0 0 1 .3.8z"/> | ||
</svg> | ||
|
@@ -50,21 +50,30 @@ Let's build a clickable icon to let your users toggle between light or dark mode | |
</style> | ||
``` | ||
|
||
2. Add the icon to `Header.astro` so that it will be displayed on all pages. Don't forget to import the component. | ||
2. Add the icon to `Header.astro` so that it will be displayed on all pages. Wrap the two buttons (ThemeIcon and Menu) inside a `<div>` to group them together, and include some basic styles to improve the layout. Don't forget to import the component. | ||
|
||
```astro title="src/components/Header.astro" ins={4,9} | ||
```astro title="src/components/Header.astro" ins={4,8-9,11,16-21} | ||
--- | ||
import Hamburger from './Hamburger.astro'; | ||
import Menu from './Menu.astro'; | ||
import Navigation from './Navigation.astro'; | ||
import ThemeIcon from './ThemeIcon.astro'; | ||
--- | ||
<header> | ||
<nav> | ||
<Hamburger /> | ||
<ThemeIcon /> | ||
<div> | ||
<ThemeIcon /> | ||
<Menu /> | ||
</div> | ||
<Navigation /> | ||
</nav> | ||
</header> | ||
|
||
<style> | ||
div { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
</style> | ||
``` | ||
|
||
3. Visit your browser preview at `http://localhost:4321` to see the icon now on all your pages. You can try clicking it, but you have not written a script to make it interactive yet. | ||
|
@@ -77,15 +86,35 @@ Choose some alternate colors to use in dark mode. | |
<Steps> | ||
1. In `global.css`, define some dark styles. You can choose your own, or copy and paste: | ||
|
||
:::note | ||
When you update your site to include dark mode, some colors used may need updating. Always check your rendered site when adding new styles and colors, and make adjustments when necessary! This can mean adding more `.dark` CSS style rules to display different styles in dark mode, or you may wish to update some colors so that they work equally well in both themes. | ||
|
||
Consider using accessibility tools such as a contrast checker when creating a set of colors for your site, or running a check on your website, for example with a browser extension, to spot any potential issues. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to recommend a contrast checker? I don't know any to suggest, the one built into the browser is probably sufficient |
||
::: | ||
|
||
```css title="src/styles/global.css" | ||
html.dark { | ||
background-color: #0d0950; | ||
color: #fff; | ||
} | ||
|
||
.dark .menu { | ||
background-color: #fff; | ||
color: #000; | ||
} | ||
|
||
.dark .nav-links a:hover, | ||
.dark .nav-links a:focus { | ||
color: #0d0950; | ||
} | ||
|
||
.dark .nav-links a { | ||
color: #fff; | ||
} | ||
|
||
.dark a { | ||
color: #ff9776; | ||
} | ||
``` | ||
</Steps> | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I split this into more steps, or is it fine as it is? Also, any suggestions about the message are always welcome.