Skip to content

Commit

Permalink
Revert "fix:themes - switch to theme drop down from toggle (mdn#5628)" (
Browse files Browse the repository at this point in the history
mdn#5647)

This reverts commit 51a39f6.
  • Loading branch information
fiji-flo authored Mar 16, 2022
1 parent 3e3623e commit 7416208
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 14 deletions.
File renamed without changes
File renamed without changes
File renamed without changes
1 change: 1 addition & 0 deletions client/src/ui/atoms/button/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ button,

.button .icon {
background-color: var(--button-color);
margin: 0 -1px; // shrinks icon-only buttons to square.
}

/* Button States */
Expand Down
17 changes: 8 additions & 9 deletions client/src/ui/atoms/icon/index.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
$icons: "add-filled", "add", "altname", "bell-filled", "bell", "bookmark-filled",
"bookmark", "cancel", "checkmark", "chevron", "critical", "theme-dark",
"deprecated", "desktop", "disabled", "edit", "ellipses", "experimental",
"external", "eye-filled", "eye", "firefox", "footnote", "github-mark-small",
"information", "language", "theme-light", "menu-filled", "menu", "mobile",
"next", "no", "nonstandard", "note-info", "note-warning", "note-deprecated",
"theme-os-default", "partial", "prefix", "preview", "previous", "quote",
"search", "server", "sidebar", "small-arrow", "star-filled", "star",
"thumbs-down", "thumbs-up", "trash", "twitter", "unknown", "warning", "yes",
"yes-circle";
"bookmark", "cancel", "checkmark", "chevron", "critical", "deprecated",
"desktop", "disabled", "edit", "ellipses", "experimental", "external",
"eye-filled", "eye", "firefox", "footnote", "github-mark-small", "information",
"language", "menu-filled", "menu", "mobile", "moon-fill", "next", "no",
"nonstandard", "note-info", "note-warning", "note-deprecated", "partial",
"prefix", "preview", "previous", "quote", "search", "server", "sidebar",
"small-arrow", "sun-fill", "star-filled", "star", "theme", "thumbs-down",
"thumbs-up", "trash", "twitter", "unknown", "warning", "yes", "yes-circle";

.icon {
--size: var(--icon-size, 1rem);
Expand Down
2 changes: 1 addition & 1 deletion client/src/ui/molecules/theme-switcher/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const ThemeSwitcher = () => {
ariaControls={menuId}
ariaHasPopup={"menu"}
ariaExpanded={isOpen || undefined}
icon={`theme-${activeTheme}`}
icon="theme"
extraClasses="theme-switcher-menu small"
onClickHandler={() => {
setIsOpen(!isOpen);
Expand Down
5 changes: 5 additions & 0 deletions client/src/ui/molecules/theme-toggle/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.theme-toggle {
display: flex;
align-items: center;
gap: 0.4rem;
}
41 changes: 41 additions & 0 deletions client/src/ui/molecules/theme-toggle/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react";
import { switchTheme } from "../../../utils";
import { Icon } from "../../atoms/icon";
import { Switch } from "../../atoms/switch";

import "./index.scss";

export function ThemeToggle() {
const isServer = typeof window === "undefined";
let prefers = "light";
if (!isServer) {
const mql = window?.matchMedia?.("(prefers-color-scheme: dark)");
if (mql?.matches) {
prefers = "dark";
}
}
const [activeTheme, setActiveTheme] = React.useState(
(!isServer && document?.body?.className) || prefers
);
const [dark, setDark] = React.useState(activeTheme === "dark");

const toggle = (e) => {
let checked = e?.target?.checked || false;
const theme = checked ? "dark" : "light";
switchTheme(theme, setActiveTheme);
setDark(checked);
};

return (
<div className="theme-toggle">
<Icon name="sun-fill" />
<Switch
name="themeToggle"
hiddenLabel={`toggle theme to ${dark ? "light" : "dark"} mode`}
checked={dark}
toggle={toggle}
></Switch>
<Icon name="moon-fill" />
</div>
);
}
8 changes: 5 additions & 3 deletions client/src/ui/organisms/article-actions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ export const ArticleActions = ({
<BookmarkContainer doc={doc} />
</li>
)}
<li className="article-actions-entry">
<ThemeSwitcher />
</li>
{isAuthenticated && (
<li className="article-actions-entry">
<ThemeSwitcher />
</li>
)}
{!MDN_APP && translations && !!translations.length && (
<li className="article-actions-entry">
<LanguageMenu
Expand Down
3 changes: 2 additions & 1 deletion client/src/ui/organisms/top-navigation-main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useUserData } from "../../../user-context";

import "./index.scss";
import { ENABLE_PLUS } from "../../../constants";
import { ThemeToggle } from "../../molecules/theme-toggle";

export const TopNavigationMain = ({ isOpenOnMobile }) => {
const userData = useUserData();
Expand All @@ -37,7 +38,7 @@ export const TopNavigationMain = ({ isOpenOnMobile }) => {
setShowSearch(false);
}}
/>

<ThemeToggle></ThemeToggle>
<Button
type="action"
icon="search"
Expand Down

0 comments on commit 7416208

Please sign in to comment.