Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add use theme context #3039

Open
wants to merge 8 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/button/src/__stories__/Button.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { ArgsTable, Primary, Stories } from "@storybook/addon-docs";
import { Settings16, Settings24 } from "@weave-design/icons";

import { useThemeContext } from "@weave-design/theme-context";
import Button from "../index";
import Readme from "../../README.md";
import { targets, types, widths } from "../constants";
Expand Down Expand Up @@ -59,6 +60,11 @@ const Template = (args, context) => {
context.globals.density === "Medium density" ? Settings24 : Settings16;
const iconProp =
context.story === "Button with icon" ? { icon: <Icon /> } : {};
// eslint-disable-next-line no-console
console.log(useThemeContext);
const test = useThemeContext();
// eslint-disable-next-line no-console
console.log("useThemeContext", test);
return <Button {...args} {...iconProp} />;
};

Expand Down
1 change: 1 addition & 0 deletions packages/theme-context/src/ThemeContext/BaseContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { createContext } from "react";
import defaultTheme from "@weave-design/theme-data/build/json/lightGrayMediumDensityTheme/theme.json";

const { Provider, Consumer } = createContext(defaultTheme);
// const useThemeContext = () => useContext({Provider, Consumer});

export { Provider, Consumer };
3 changes: 2 additions & 1 deletion packages/theme-context/src/ThemeContext/Consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const Consumer = (props) => (
{(theme) => {
const isDebugging = process.env.NODE_ENV !== "production";
const result = isDebugging ? createThemeProxy(theme) : theme;

// eslint-disable-next-line no-console
console.log("isDebugging", isDebugging);
return props.children(result);
}}
</BaseConsumer>
Expand Down
3 changes: 3 additions & 0 deletions packages/theme-context/src/ThemeContext/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Provider } from "./BaseContext";
import Consumer from "./Consumer";
// import useThemeContext from "./useThemeContext";

// console.log('theme context', useThemeContext);
export { Provider, Consumer };
// export {default as useThemeContext} from "./useThemeContext";
export default { Provider, Consumer };
9 changes: 9 additions & 0 deletions packages/theme-context/src/ThemeContext/useThemeContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useContext } from "react";

import * as BaseContext from "./BaseContext";

// console.log('BaseContext', BaseContext);
const useThemeContext = () => useContext(BaseContext);
// console.log('useThemeContext', useThemeContext);

export default useThemeContext;
1 change: 1 addition & 0 deletions packages/theme-context/src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as ThemeContext } from "./ThemeContext";
export { default } from "./ThemeContext";
export { default as useThemeContext } from "./ThemeContext/useThemeContext";