Skip to content
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

docs: Create dark mode feature #974

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/DocsLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function DocsLayout({
}, [router.asPath]);

return (
<Container>
<Container id="panel">
<Head title={prefixedTitle} description={description}>
<meta name="robots" content="noodp" />
{feedLink && <link rel="alternate" type="application/atom+xml" title={prefixedTitle} href={feedLink} />}
Expand Down
2 changes: 2 additions & 0 deletions components/Nav/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import MobileNavbar from './MobileNavbar';
import NavLinks from './NavLinks';
import SearchWithAlgolia from './SearchWithAlgolia';
import Social from './Social';
import { ToggleButton } from './Toggle';

export interface NavbarProps {
onSideToggle?: () => void;
Expand Down Expand Up @@ -57,6 +58,7 @@ export default function Navbar({
`)}
`}
>
<ToggleButton />
<SearchWithAlgolia />
<StyledSocial style={{ marginLeft: 16 }} />
</EndWrapper>
Expand Down
136 changes: 136 additions & 0 deletions components/Nav/Toggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import styled, { keyframes } from 'styled-components';

const Span = styled.span`
width: 5px;
height: 3px;
border-radius: 3px;
position: relative;
background-color: #fff;
left: 37px;
top: 12px;
transition: all 150ms ease-in;

&::before,
&::after {
content: '';
position: absolute;
width: 15px;
height: 3px;
border-radius: 3px;
background-color: #fff;
transition: all 150ms ease-in;
}

&::before {
top: -5px;
left: -5px;
}

&::after {
top: 5px;
left: -2px;
}
`;

const Switch = keyframes`
0% {
left: 2px;
}
60% {
left: 2px;
width: 30px;
}
100% {
left: 36px;
width: 18px;
}
`;

const Input = styled.input`
display: none;

&:checked + label {
background-color: #6b7abb;
border-color: #5d6baa;

& > span {
left: 15px;
width: 3px;

&::before {
width: 3px;
height: 3px;
top: -5px;
}

&::after {
width: 3px;
height: 3px;
left: -8px;
top: 7px;
}
}

&::before {
background-color: #fff;
border-color: #e8e8e8;
animation: ${Switch} 350ms forwards;
}

&::after {
transition-delay: 350ms;
opacity: 1;
}
}
`;

const Reverset = keyframes`
0% {
left: 32px;
width: 18px;
}
60% {
left: 2px;
width: 30px;
}
100% {
left: 2px;
}
`;

const Label = styled.label`
width: 60px;
height: 30px;
background-color: #96dcee;
border-radius: 100px;
border: 2px solid #72cce3;
display: flex;
position: relative;
transition: all 350ms ease-in;
cursor: pointer;

&::before {
animation: ${Reverset} 350ms forwards;
transition: all 350ms ease-in;
content: '';
width: 18px;
height: 18px;
border: 2px solid #f5eb71;
top: 4px;
left: 0px;
position: absolute;
border-radius: 82px;
background-color: #fffaa8;
}
`;

export const ToggleButton = () => {
return (
<span>
<Input type="checkbox" id="toggle" />
<Label htmlFor="toggle">
<Span />
</Label>
</span>
);
};
2 changes: 1 addition & 1 deletion components/Nav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Nav = (props: NavProps) => {
/>

{showSideNav !== false && (
<Sidebar $isFolded={isSideFolded}>
<Sidebar id="navbar" $isFolded={isSideFolded}>
{useDocsSidebarMenu !== false ? <DocsSidebarMenu /> : <SimpleSidebarMenu pages={pages} />}
</Sidebar>
)}
Expand Down
16 changes: 16 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ const ResetStyles = createGlobalStyle`
-webkit-font-smoothing: subpixel-antialiased;
}

body:has(input#toggle:checked) {
color: rgb(245, 245, 245);
}

body:has(input#toggle:checked) h1 {
color: rgb(245, 245, 245);
}

body:has(input#toggle:checked) #panel {
background-color: #222;
}

body:has(input#toggle:checked) #navbar {
background-color: #444;
}

body.sticky {
overflow: hidden;
}
Expand Down
137 changes: 124 additions & 13 deletions test/components/NavBar/__snapshots__/Navbar.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -124,43 +124,139 @@ exports[`Navbar renders correctly 1`] = `
height: 2rem;
}

.c17 {
.c20 {
display: flex;
align-items: center;
flex: 1 1 auto;
}

.c18 {
.c21 {
display: flex;
margin-right: 1.1111111111111112rem;
line-height: 3.3333333333333335rem;
transition: opacity 0.2s,transform 0.2s;
cursor: pointer;
}

.c18:last-child {
.c21:last-child {
margin-right: 0;
}

.c18:hover,
.c18:focus {
.c21:hover,
.c21:focus {
opacity: 0.8;
}

.c18:active {
.c21:active {
transform: scale(0.95);
opacity: 0.6;
}

.c18 svg path {
.c21 svg path {
fill: currentColor;
}

.c19.c19 {
.c22.c22 {
width: NaNrem;
height: 1rem;
}

.c19 {
width: 5px;
height: 3px;
border-radius: 3px;
position: relative;
background-color: #fff;
left: 37px;
top: 12px;
transition: all 150ms ease-in;
}

.c19::before,
.c19::after {
content: '';
position: absolute;
width: 15px;
height: 3px;
border-radius: 3px;
background-color: #fff;
transition: all 150ms ease-in;
}

.c19::before {
top: -5px;
left: -5px;
}

.c19::after {
top: 5px;
left: -2px;
}

.c17 {
display: none;
}

.c17:checked+label {
background-color: #6b7abb;
border-color: #5d6baa;
}

.c17:checked+label>span {
left: 15px;
width: 3px;
}

.c17:checked+label>span::before {
width: 3px;
height: 3px;
top: -5px;
}

.c17:checked+label>span::after {
width: 3px;
height: 3px;
left: -8px;
top: 7px;
}

.c17:checked+label::before {
background-color: #fff;
border-color: #e8e8e8;
animation: eVutBq 350ms forwards;
}

.c17:checked+label::after {
transition-delay: 350ms;
opacity: 1;
}

.c18 {
width: 60px;
height: 30px;
background-color: #96dcee;
border-radius: 100px;
border: 2px solid #72cce3;
display: flex;
position: relative;
transition: all 350ms ease-in;
cursor: pointer;
}

.c18::before {
animation: jnkQbK 350ms forwards;
transition: all 350ms ease-in;
content: '';
width: 18px;
height: 18px;
border: 2px solid #f5eb71;
top: 4px;
left: 0px;
position: absolute;
border-radius: 82px;
background-color: #fffaa8;
}

.c0 {
align-items: center;
background-color: rgba(12, 13, 15, 0.7);
Expand Down Expand Up @@ -396,33 +492,48 @@ exports[`Navbar renders correctly 1`] = `
]
}
>
<span>
<input
className="c17"
id="toggle"
type="checkbox"
/>
<label
className="c18"
htmlFor="toggle"
>
<span
className="c19"
/>
</label>
</span>
<div
id="docs-search-input"
/>
<nav
className="c17 "
className="c20 "
style={
{
"marginLeft": 16,
}
}
>
<a
className="c18"
className="c21"
target="_blank"
title="GitHub: Source code"
>
<svg
className="c19"
className="c22"
/>
</a>
<a
className="c18"
className="c21"
target="_blank"
title="Medium: Announcements, blog posts, and more"
>
<svg
className="c19"
className="c22"
/>
</a>
</nav>
Expand Down
Loading