Add dark mode (#371)
This commit is contained in:
parent
bec8d812e8
commit
8cf219308e
8 changed files with 51 additions and 4 deletions
5
.changeset/fresh-guests-report.md
Normal file
5
.changeset/fresh-guests-report.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"saleor-app-crm": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Added dark mode and automatic color synchronization with Dashboard
|
BIN
apps/crm/src/assets/mailchimp-dark.png
Normal file
BIN
apps/crm/src/assets/mailchimp-dark.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4 KiB After Width: | Height: | Size: 4.6 KiB |
24
apps/crm/src/lib/theme-synchronizer.tsx
Normal file
24
apps/crm/src/lib/theme-synchronizer.tsx
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { useAppBridge } from "@saleor/app-sdk/app-bridge";
|
||||||
|
import { useTheme } from "@saleor/macaw-ui/next";
|
||||||
|
import { memo, useEffect } from "react";
|
||||||
|
|
||||||
|
export function ThemeSynchronizer() {
|
||||||
|
const { appBridgeState } = useAppBridge();
|
||||||
|
const { setTheme } = useTheme();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!setTheme || !appBridgeState?.theme) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appBridgeState.theme === "light") {
|
||||||
|
setTheme("defaultLight");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appBridgeState.theme === "dark") {
|
||||||
|
setTheme("defaultDark");
|
||||||
|
}
|
||||||
|
}, [appBridgeState?.theme, setTheme]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
|
@ -29,3 +29,7 @@
|
||||||
width: 30px;
|
width: 30px;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.list[data-macaw-theme="defaultDark"] :global(.darkmode-logo-invert) {
|
||||||
|
filter: invert(100%);
|
||||||
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import { ProviderType } from "../providers-types";
|
import { ProviderType } from "../providers-types";
|
||||||
import MailchimpLogo from "../../../assets/mailchimp.svg";
|
import MailchimpLogo from "../../../assets/mailchimp.svg";
|
||||||
|
import MailchimpLogoDark from "../../../assets/mailchimp-dark.png";
|
||||||
import SegmentLogo from "../../../assets/segment.png";
|
import SegmentLogo from "../../../assets/segment.png";
|
||||||
import RudderstackLogo from "../../../assets/rudderstack.png";
|
import RudderstackLogo from "../../../assets/rudderstack.png";
|
||||||
import { HTMLAttributes } from "react";
|
import { HTMLAttributes } from "react";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import styles from "./providers-list.module.css";
|
import styles from "./providers-list.module.css";
|
||||||
import { Box, MarketplaceIcon, Text } from "@saleor/macaw-ui/next";
|
import { Box, MarketplaceIcon, Text, useTheme } from "@saleor/macaw-ui/next";
|
||||||
import { TextLink } from "../../ui/text-link/text-link";
|
import { TextLink } from "../../ui/text-link/text-link";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -14,8 +15,10 @@ type Props = {
|
||||||
} & HTMLAttributes<HTMLUListElement>;
|
} & HTMLAttributes<HTMLUListElement>;
|
||||||
|
|
||||||
export const ProvidersList = ({ className, onProviderClick, activeProvider, ...props }: Props) => {
|
export const ProvidersList = ({ className, onProviderClick, activeProvider, ...props }: Props) => {
|
||||||
|
const { theme } = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul className={clsx(className, styles.list)}>
|
<ul className={clsx(className, styles.list)} data-macaw-theme={theme}>
|
||||||
<li
|
<li
|
||||||
className={clsx(styles.item, {
|
className={clsx(styles.item, {
|
||||||
[styles.activeItem]: activeProvider === "mailchimp",
|
[styles.activeItem]: activeProvider === "mailchimp",
|
||||||
|
@ -24,7 +27,11 @@ export const ProvidersList = ({ className, onProviderClick, activeProvider, ...p
|
||||||
onProviderClick("mailchimp");
|
onProviderClick("mailchimp");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img alt="Mailchimp logo" className={styles.logo} src={MailchimpLogo.src} />
|
<img
|
||||||
|
alt="Mailchimp logo"
|
||||||
|
className={styles.logo}
|
||||||
|
src={theme === "defaultLight" ? MailchimpLogo.src : MailchimpLogoDark.src}
|
||||||
|
/>
|
||||||
<Text>Mailchimp</Text>
|
<Text>Mailchimp</Text>
|
||||||
</li>
|
</li>
|
||||||
<li className={clsx(styles.item, styles.disabled)}>
|
<li className={clsx(styles.item, styles.disabled)}>
|
||||||
|
@ -37,7 +44,11 @@ export const ProvidersList = ({ className, onProviderClick, activeProvider, ...p
|
||||||
</Box>
|
</Box>
|
||||||
</li>
|
</li>
|
||||||
<li className={clsx(styles.item, styles.disabled)}>
|
<li className={clsx(styles.item, styles.disabled)}>
|
||||||
<img alt="Rudderstack logo" className={styles.logo} src={RudderstackLogo.src} />
|
<img
|
||||||
|
alt="Rudderstack logo"
|
||||||
|
className={clsx(styles.logo, "darkmode-logo-invert")}
|
||||||
|
src={RudderstackLogo.src}
|
||||||
|
/>
|
||||||
<Box>
|
<Box>
|
||||||
<Text as="p" variant="caption" color="textNeutralDisabled">
|
<Text as="p" variant="caption" color="textNeutralDisabled">
|
||||||
Coming soon
|
Coming soon
|
||||||
|
|
|
@ -13,6 +13,7 @@ import { Box, ThemeProvider } from "@saleor/macaw-ui/next";
|
||||||
import { NextPage } from "next";
|
import { NextPage } from "next";
|
||||||
import { GraphQLProvider } from "../lib/graphql-provider";
|
import { GraphQLProvider } from "../lib/graphql-provider";
|
||||||
import { AppBridgeStorageSetter } from "../lib/app-bridge-persistence";
|
import { AppBridgeStorageSetter } from "../lib/app-bridge-persistence";
|
||||||
|
import { ThemeSynchronizer } from "../lib/theme-synchronizer";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure instance is a singleton.
|
* Ensure instance is a singleton.
|
||||||
|
@ -49,6 +50,7 @@ function NextApp({ Component, pageProps: { session, ...pageProps } }: AppPropsWi
|
||||||
<AppBridgeProvider appBridgeInstance={appBridgeInstance}>
|
<AppBridgeProvider appBridgeInstance={appBridgeInstance}>
|
||||||
<GraphQLProvider>
|
<GraphQLProvider>
|
||||||
<ThemeProvider defaultTheme="defaultLight">
|
<ThemeProvider defaultTheme="defaultLight">
|
||||||
|
<ThemeSynchronizer />
|
||||||
<RoutePropagator />
|
<RoutePropagator />
|
||||||
<AppBridgeStorageSetter />
|
<AppBridgeStorageSetter />
|
||||||
<Box padding={8}>
|
<Box padding={8}>
|
||||||
|
|
|
@ -2,6 +2,7 @@ body {
|
||||||
color: var(--mu-colors-foreground-text-neutral-plain);
|
color: var(--mu-colors-foreground-text-neutral-plain);
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
background: var(--mu-colors-background-plain);
|
||||||
}
|
}
|
||||||
|
|
||||||
code {
|
code {
|
||||||
|
|
Loading…
Reference in a new issue