Add automatic theme

This commit is contained in:
Zoe Roux
2023-01-07 01:53:07 +09:00
parent 1e7acacbe5
commit a7e17b35e0
7 changed files with 118 additions and 7 deletions
+9 -3
View File
@@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for details.
//
import { Theme, ThemeProvider } from "yoshiki";
import { Theme, ThemeProvider, useAutomaticTheme } from "yoshiki";
import { useYoshiki, useMobileHover } from "yoshiki/web";
import { AppProps } from "next/app";
@@ -11,25 +11,31 @@ declare module "yoshiki" {
export interface Theme {
spacing: string;
name: string;
background: string;
light: { background: string; nested: { black: string } };
dark: { background: string; nested: { black: string } };
}
}
export const theme: Theme = {
spacing: "24px",
name: "yoshiki",
background: "white",
light: { background: "white", nested: { black: "black" } },
dark: { background: "black", nested: { black: "red" } },
};
const AppName = () => {
const { css, theme } = useYoshiki();
return <p {...css({ padding: (theme) => theme.spacing })}>{theme.name}</p>;
};
const App = ({ Component, pageProps }: AppProps) => {
useMobileHover();
const auto = useAutomaticTheme(theme);
return (
<ThemeProvider theme={theme}>
<ThemeProvider theme={{ ...theme, ...auto }}>
<Component {...pageProps} />
<AppName />
</ThemeProvider>
+3 -2
View File
@@ -5,7 +5,7 @@
import Head from "next/head";
import Image from "next/image";
import { useYoshiki, Stylable, px, md } from "yoshiki/web";
import { useYoshiki, Stylable, md } from "yoshiki/web";
import { ReactNode } from "react";
const Box = ({ children, ...props }: { children?: ReactNode } & Stylable) => {
@@ -27,6 +27,7 @@ export default function Home(props: object) {
display: "flex",
paddingLeft: "2rem",
paddingRight: "2rem",
bg: (theme) => theme.background,
},
md({
flexGrow: 1,
@@ -48,7 +49,7 @@ export default function Home(props: object) {
</h1>
<Box />
<Box {...css({ bg: "blue", p: px(12) })} />
<Box {...css({ bg: "blue", padding: "12px" })} />
<p>
Get started by editing <code>pages/index.tsx</code>