Skip to content

Commit

Permalink
feat(theme): Add Default Theme
Browse files Browse the repository at this point in the history
  • Loading branch information
victorgcramos authored Apr 11, 2022
1 parent b266c7d commit 4f6b004
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
1 change: 0 additions & 1 deletion .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { addDecorator } from "@storybook/react";
import themeDecorator from "./themeDecorator";
import { withThemes } from "@react-theming/storybook-addon";
import {
DEFAULT_DARK_THEME_NAME,
Expand Down
2 changes: 1 addition & 1 deletion .storybook/providerFn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect } from "react";
import {
useTheme,
ThemeProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exports[`DatePicker component Matches the snapshot 1`] = `
className="rmpCell"
>
<div
className="rmpPopup"
className="rmpPopup light"
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Icon/Icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ const icons = (type, backgroundColor, iconColor) => {
),
cancel: (
<>
<g clip-path="url(#clip0_10_15)">
<g clipPath="url(#clip0_10_15)">
<path d="M141.229 140.771L309.687 309.229Z" fill={iconColor} />
<path d="M141.229 309.229L309.687 140.771Z" fill={iconColor} />
<path
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "./css/base.css";
import "./theme/defaultTheme.js";

export { default as BoxTextInput } from "./components/BoxTextInput/BoxTextInput.jsx";
export { default as Button } from "./components/Button/Button.jsx";
Expand Down
18 changes: 14 additions & 4 deletions src/theme/ThemeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ import React, {
useContext,
} from "react";
import PropTypes from "prop-types";
import defaultLightTheme from "./lightTheme";
import { DEFAULT_LIGHT_THEME_NAME } from "./constants";

const ThemeContext = createContext();
const ThemeContext = createContext({
theme: defaultLightTheme,
themeName: DEFAULT_LIGHT_THEME_NAME,
setThemeName: () => {},
});

export const useTheme = () => useContext(ThemeContext) || {};

Expand All @@ -20,9 +26,7 @@ export const ThemeProvider = ({
const [themeName, setThemeName] = useState(defaultThemeName);
const theme = useMemo(() => themes[themeName], [themes, themeName]);
useLayoutEffect(() => {
Object.keys(theme).forEach((key) => {
document.documentElement.style.setProperty(`--${key}`, theme[key]);
});
applyTheme(theme);
if (fonts) {
applyFontAsset(fonts);
}
Expand Down Expand Up @@ -71,3 +75,9 @@ const applyFontAsset = (fonts) => {
newStyle.type = "text/css";
document.head.appendChild(newStyle);
};

function applyTheme(theme) {
Object.keys(theme).forEach((key) => {
document.documentElement.style.setProperty(`--${key}`, theme[key]);
});
}
9 changes: 9 additions & 0 deletions src/theme/defaultTheme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import lightTheme from "./lightTheme";

function applyDefaultTheme() {
Object.keys(lightTheme).forEach((key) => {
document.documentElement.style.setProperty(`--${key}`, lightTheme[key]);
});
}

applyDefaultTheme();

0 comments on commit 4f6b004

Please sign in to comment.