Skip to content

Commit

Permalink
chore: replace docs dark mode toggle sun and mood emojis with wpds ic…
Browse files Browse the repository at this point in the history
…ons (#533)
  • Loading branch information
wp-aberg authored Nov 21, 2023
1 parent 895fc1b commit 7d1b8e4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
4 changes: 3 additions & 1 deletion build.washingtonpost.com/components/NavigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ export const NavigationBar = ({ setMobileMenu, mobileMenuState, isClosed }) => {
marginTop: "-$100",
},
"@sm": {
top: "$100",
top: "18px",
right: "$400",
padding: "1px",
backgroundColor: theme.colors.secondary,
},
}}
/>
Expand Down
54 changes: 37 additions & 17 deletions build.washingtonpost.com/components/ThemeToggle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useEffect, useState } from "react";
import { useTheme } from "next-themes";

import { css, styled, VisuallyHidden } from "@washingtonpost/wpds-ui-kit";
import { css, theme, Button, Icon } from "@washingtonpost/wpds-ui-kit";
import { Sun, Moon } from "@washingtonpost/wpds-assets";

const hasWindow = () => {
return typeof window !== "undefined";
Expand All @@ -21,16 +22,6 @@ export const ThemeToggle = (props) => {
setTheme(targetTheme);
};

const Button = styled("button", {
appearance: "none",
background: "none",
cursor: "pointer",
padding: 0,
margin: 0,
border: 0,
fontSize: "$150",
});

const showOnDarkTheme = css({
display: "none",
"@dark": {
Expand All @@ -46,16 +37,45 @@ export const ThemeToggle = (props) => {
});

return (
<Button css={props.css} onClick={toggleTheme} aria-label="Switch theme">
<Button
css={{
border: "none",
paddingBlock: theme.space["025"],
paddingInline: 0,
"&:hover": { backgroundColor: "transparent" },
...props.css,
}}
onClick={toggleTheme}
aria-label="Switch theme"
variant="primary"
icon="center"
density="compact"
isOutline
>
<span className={showOnDarkTheme()}>
{env === "browser" && resolvedTheme === "light" ? "🌞" : "🌕"}
{env === "server" && "🌕"}
{env === "browser" && (
<Icon label="" size="150">
{resolvedTheme === "light" ? <Moon /> : <Sun />}
</Icon>
)}
{env === "server" && (
<Icon label="" size="150">
<Sun />
</Icon>
)}
</span>
<span className={showOnLightTheme()}>
{env === "browser" && resolvedTheme === "light" ? "🌞" : "🌕"}
{env === "server" && "🌞"}
{env === "browser" && (
<Icon label="" size="150">
{resolvedTheme === "light" ? <Moon /> : <Sun />}
</Icon>
)}
{env === "server" && (
<Icon label="" size="150">
<Moon />
</Icon>
)}
</span>
<VisuallyHidden>Switch theme</VisuallyHidden>
</Button>
);
};

4 comments on commit 7d1b8e4

@vercel
Copy link

@vercel vercel bot commented on 7d1b8e4 Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wpds-ui-kit – ./build.washingtonpost.com

build.washingtonpost.com
wpds-ui-kit.preview.now.washingtonpost.com
wpds-ui-kit-git-main.preview.now.washingtonpost.com

@vercel
Copy link

@vercel vercel bot commented on 7d1b8e4 Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 7d1b8e4 Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wpds-ui-kit-vitejs-example – ./apps/vite-project

wpds-ui-kit-vitejs-example.preview.now.washingtonpost.com
wpds-ui-kit-vitejs-example-git-main.preview.now.washingtonpost.com

@vercel
Copy link

@vercel vercel bot commented on 7d1b8e4 Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wpds-ui-kit-storybook – ./

wpds-ui-kit-storybook.preview.now.washingtonpost.com
wpds-ui-kit-storybook-git-main.preview.now.washingtonpost.com

Please sign in to comment.