Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #14 from sonnat/master
Browse files Browse the repository at this point in the history
  • Loading branch information
mimshins authored Feb 1, 2022
2 parents 28b95ad + 9d4d708 commit 2ae68e0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
5 changes: 2 additions & 3 deletions lib/styles/createTheme.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from "react";
import type { EmptyIntersectionObject } from "../typings";
import createBreakpoints, {
type Breakpoints,
type BreakpointsInput
} from "./createBreakpoints";
import createColors, { type Colors, type ColorsInput } from "./createColors";
import createMixins, { type Mixins } from "./createMixins";
import createRadius, { type Radius } from "./createRadius";
import createSpacings, {
type Spacings,
type SpacingsInput
Expand All @@ -15,7 +15,6 @@ import createTypography, {
type TypographyInput
} from "./createTypography";
import createZIndexes, { type ZIndexes } from "./createZIndexes";
import createRadius, { type Radius } from "./createRadius";
import swatches, { type Swatches } from "./swatches";

export type Direction = "ltr" | "rtl";
Expand Down Expand Up @@ -48,7 +47,7 @@ export interface ThemeBase {
};
}

const createTheme = <CustomProps = EmptyIntersectionObject>(
const createTheme = <CustomProps = unknown>(
themeInput?: Partial<ThemeInput> & {
custom?: CustomProps | ((theme: ThemeBase) => CustomProps);
}
Expand Down
9 changes: 6 additions & 3 deletions lib/styles/useDarkMode.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import * as React from "react";
import usePreviousValue from "../utils/usePreviousValue";
import { type Theme } from "./createTheme";
import defaultTheme from "./defaultTheme";
import defaultTheme, { type DefaultTheme } from "./defaultTheme";
import type { Theme } from "./createTheme";

const useDarkMode = (isDarkMode = false, theme = defaultTheme): Theme => {
const useDarkMode = <T extends Theme = DefaultTheme>(
isDarkMode = false,
theme: T = defaultTheme as T
): T => {
const cachedTheme = React.useRef(theme);
const prevState = usePreviousValue(isDarkMode);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sonnat/ui",
"version": "2.0.2",
"version": "2.0.3",
"description": "React component library using Sonnat Design System to build faster, elegant, and accessible web applications.",
"license": "MIT",
"homepage": "https://www.sonnat.dev/",
Expand Down
6 changes: 3 additions & 3 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppProps } from "next/app";
import Head from "next/head";
import * as React from "react";
import CssBaseline from "../lib/CssBaseline";
import { useDarkMode, makeStyles, SonnatInitializer } from "../lib/styles";
import { makeStyles, SonnatInitializer, useDarkMode } from "../lib/styles";

interface IAppContext {
setIsDarkMode: React.Dispatch<React.SetStateAction<boolean>>;
Expand Down Expand Up @@ -43,10 +43,10 @@ const App = (props: AppProps) => {

const [isDarkMode, setIsDarkMode] = React.useState(false);

const theme = useDarkMode(isDarkMode);
const newTheme = useDarkMode(isDarkMode);

return (
<SonnatInitializer theme={theme} injectFirst>
<SonnatInitializer theme={newTheme} injectFirst>
<Head>
<meta
name="viewport"
Expand Down

0 comments on commit 2ae68e0

Please sign in to comment.