From 313a30b0b594de0e9d3c2459ddd3edff04eeb3d8 Mon Sep 17 00:00:00 2001 From: Wilbert Mui Date: Thu, 7 Sep 2023 10:01:00 -0700 Subject: [PATCH 1/8] feat: export useThemeContext hook --- packages/theme-context/src/ThemeContext/BaseContext.js | 3 ++- packages/theme-context/src/ThemeContext/index.js | 3 +++ packages/theme-context/src/ThemeContext/index.test.js | 4 ++++ packages/theme-context/src/index.js | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/theme-context/src/ThemeContext/BaseContext.js b/packages/theme-context/src/ThemeContext/BaseContext.js index d72b3230f0..b81a6af8b7 100644 --- a/packages/theme-context/src/ThemeContext/BaseContext.js +++ b/packages/theme-context/src/ThemeContext/BaseContext.js @@ -1,6 +1,7 @@ -import { createContext } from "react"; +import { createContext, useContext } 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 }; diff --git a/packages/theme-context/src/ThemeContext/index.js b/packages/theme-context/src/ThemeContext/index.js index 1310d9c670..afef137cb6 100644 --- a/packages/theme-context/src/ThemeContext/index.js +++ b/packages/theme-context/src/ThemeContext/index.js @@ -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 }; diff --git a/packages/theme-context/src/ThemeContext/index.test.js b/packages/theme-context/src/ThemeContext/index.test.js index 91def12097..c03e70b808 100644 --- a/packages/theme-context/src/ThemeContext/index.test.js +++ b/packages/theme-context/src/ThemeContext/index.test.js @@ -19,5 +19,9 @@ describe("themes/ThemeContext/index", () => { name: "Provider", value: expect.any(Object), }, + { + name: "useThemeContext", + value: expect.any(Function), + }, ]); }); diff --git a/packages/theme-context/src/index.js b/packages/theme-context/src/index.js index 264c5d212d..bd03c6c092 100644 --- a/packages/theme-context/src/index.js +++ b/packages/theme-context/src/index.js @@ -1,2 +1,3 @@ export { default as ThemeContext } from "./ThemeContext"; export { default } from "./ThemeContext"; +export { default as useThemeContext } from "./ThemeContext/useThemeContext"; From 9347f63506f47c25c4a8e0bd57a9b470299dc1f8 Mon Sep 17 00:00:00 2001 From: Wilbert Mui Date: Thu, 7 Sep 2023 10:01:37 -0700 Subject: [PATCH 2/8] docs: test theme-context hook --- packages/button/src/__stories__/Button.story.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/button/src/__stories__/Button.story.js b/packages/button/src/__stories__/Button.story.js index 99bca1515f..6676c22ecf 100644 --- a/packages/button/src/__stories__/Button.story.js +++ b/packages/button/src/__stories__/Button.story.js @@ -6,6 +6,8 @@ import Button from "../index"; import Readme from "../../README.md"; import { targets, types, widths } from "../constants"; +import { ThemeContext, useThemeContext } from "@weave-design/theme-context"; + export default { title: "Components/Button", component: Button, @@ -59,6 +61,9 @@ const Template = (args, context) => { context.globals.density === "Medium density" ? Settings24 : Settings16; const iconProp = context.story === "Button with icon" ? { icon: } : {}; + console.log(useThemeContext); + const test = useThemeContext(); + console.log('useThemeContext', test); return