From 1797f50d3fba1fdecb6a80dda474ee04a3d9a49e Mon Sep 17 00:00:00 2001 From: Haider Alshamma Date: Tue, 5 Nov 2024 17:30:28 -0500 Subject: [PATCH] fix: remove theme configuration panel The configuration panel requires duplicating logic of the NDSProvider and can cause unwanted bugs. --- .storybook/nds-theme/index.tsx | 6 +-- .storybook/nds-theme/register.tsx | 77 +------------------------------ 2 files changed, 3 insertions(+), 80 deletions(-) diff --git a/.storybook/nds-theme/index.tsx b/.storybook/nds-theme/index.tsx index 6666b965b..0ef778011 100644 --- a/.storybook/nds-theme/index.tsx +++ b/.storybook/nds-theme/index.tsx @@ -15,14 +15,10 @@ const localeKnobOptions = ALL_NDS_LOCALES.reduce( ); const StorybookNDSProvider = ({ children }) => { - const [theme] = useLocalStorage("nds-sb-theme", desktop, { - serializer: (value) => JSON.stringify(value), - deserializer: (value) => JSON.parse(value), - }); const [themeVariant] = useLocalStorage("nds-sb-theme-variant", "desktop"); return ( - + {children} ); diff --git a/.storybook/nds-theme/register.tsx b/.storybook/nds-theme/register.tsx index 5b21e152d..b2c663c4b 100644 --- a/.storybook/nds-theme/register.tsx +++ b/.storybook/nds-theme/register.tsx @@ -1,34 +1,16 @@ // .storybook/my-addon/register.js -import React, { useEffect } from "react"; +import React from "react"; import { addons, types, RenderOptions } from "@storybook/addons"; import { AddonPanel } from "@storybook/components"; import { Box, Flex, NDSProvider, Heading3, Heading2, QuietButton } from "../../src"; -import { desktop, themes } from "../../src/theme"; import { ComponentVariant } from "../../src/NDSProvider/ComponentVariantContext"; -import useMediaQuery from "../../src/hooks/useMediaQuery"; -import { getThemeByVariant } from "../../src/NDSProvider/useNDSTheme"; -import ThemeKey from "./ThemeKey"; -import { ThemeInput, ThemeOption, ThemeSelect } from "./ThemeInput"; -import ThemeColorInput from "./ThemeColorInput"; +import { ThemeOption, ThemeSelect } from "./ThemeInput"; import { useLocalStorage } from "./useLocalStorage/useLocalStorage"; const ADDON_ID = "ndsThemeAddon"; const PANEL_ID = `${ADDON_ID}/panel`; -const composeTheme = (data, theme) => { - const themeGroup = Object.keys(data)[0]; - const key = Object.keys(data[themeGroup])[0]; - const newValue = data[themeGroup][key]; - return { - ...theme, - [themeGroup]: { - ...theme[themeGroup], - ...(newValue && data[themeGroup]), - }, - }; -}; - const DEFAULT_THEME_VARIANT = "desktop"; const ThemePanel = () => { @@ -36,54 +18,14 @@ const ThemePanel = () => { "nds-sb-theme-variant", DEFAULT_THEME_VARIANT ); - const [theme, setTheme] = useLocalStorage("nds-sb-theme", themes[themeVariant], { - serializer: (value) => JSON.stringify(value), - deserializer: (value) => JSON.parse(value), - }); - const isTabletSize = useMediaQuery(`(min-width: ${desktop.breakpoints.small})`); - - useEffect(() => { - const newTheme = getThemeByVariant(themeVariant, isTabletSize); - setTheme(newTheme); - }, [themeVariant, isTabletSize, setTheme]); - - const onChange = (group, prop) => (e) => { - const value = e.target.value; - const nextTheme = composeTheme( - { - [group]: { - [prop]: value, - }, - }, - theme - ); - setTheme(nextTheme); - }; - - const onChangeColor = (group, prop) => (e) => { - const value = e.hex; - const nextTheme = composeTheme( - { - [group]: { - [prop]: value, - }, - }, - theme - ); - setTheme(nextTheme); - }; const onVariantChange = (e) => { const variant = e.target.value; setThemeVariant(variant); - - const theme = themes[variant]; - setTheme(theme); }; const reset = () => { setThemeVariant(DEFAULT_THEME_VARIANT); - setTheme(themes.desktop); }; return ( @@ -103,21 +45,6 @@ const ThemePanel = () => { Touch - {Object.keys(theme).map((group) => ( - - {group} - {Object.keys(theme[group]).map((prop) => ( - - {prop} - {group === "colors" ? ( - - ) : ( - - )} - - ))} - - ))} ); };