diff --git a/.codeclimate.json b/.codeclimate.json index aa9df5c..2adc48f 100644 --- a/.codeclimate.json +++ b/.codeclimate.json @@ -15,6 +15,7 @@ "**/stories/", "**/tests/", "**/dist/", + "**/css/", "**/LICENSE", "**/*.d.ts", "**/*.lock", @@ -27,6 +28,11 @@ ".gitignore", ".npmignore", ".codeclimate.json", + "**/darkBase.ts", + "**/lightBase.ts", + "**/palettes.ts", + "**/world.svg.ts", + "**/_fileType.ts", "**/_countries.ts", "**/hijri-date.js" ] diff --git a/.github/workflows/master.yml b/.github/workflows/build.yml similarity index 77% rename from .github/workflows/master.yml rename to .github/workflows/build.yml index ac33a45..7089f67 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ name: Build and Deploy on: # Triggers the workflow on push events for the master branch push: - branches: [WIP-v4] + branches: [main] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -33,6 +33,14 @@ jobs: run: | yarn dist + # Collect test coverage + - name: Run coverage + uses: paambaati/codeclimate-action@v5.0.0 + env: + CC_TEST_REPORTER_ID: ${{ secrets.COVERAGE_TOKEN }} + with: + coverageCommand: yarn test --coverage --json --outputFile=./.storybook/jest-test-results.json + # Runs a set of commands using the runners shell - name: Build storybook run: | @@ -42,8 +50,7 @@ jobs: - name: Deploy to GitHub Pages # You may pin to the exact commit or the version. # uses: JamesIves/github-pages-deploy-action@5dc1d5a192aeb5ab5b7d5a77b7d36aea4a7f5c92 - uses: JamesIves/github-pages-deploy-action@4.1.5 + uses: JamesIves/github-pages-deploy-action@v4 with: branch: gh-pages - target-folder: v4 folder: build diff --git a/.storybook/addon-theme/register.tsx b/.storybook/addon-theme/register.tsx index d004815..3c67536 100644 --- a/.storybook/addon-theme/register.tsx +++ b/.storybook/addon-theme/register.tsx @@ -7,61 +7,374 @@ import { useGlobals, useParameter, useStorybookApi } from "@storybook/api"; import { IconButton } from "@storybook/components"; -import { SunIcon, MoonIcon } from "@storybook/icons"; -import { ThemeVars, themes } from "@storybook/theming"; +import { MoonIcon, SunIcon } from "@storybook/icons"; +import { themes, ThemeVars } from "@storybook/theming"; import React, { useCallback, useEffect, useState } from "react"; -const STORAGE_KEY = "storybook-theme"; +const STORAGE_KEY = "storybook-scheme"; +const THEME_KEY = "storybook-theme"; +const TINT_KEY = "storybook-tint"; +const ROUNDING_KEY = "storybook-rounding"; + const GLOBAL_KEY = "theme"; -enum THEME { + +enum COLOR_SCHEME { LIGHT = "light", DARK = "dark", } -interface ThemeToggleParams { +interface ColorSchemeToggleParams { lightTheme: ThemeVars; darkTheme: ThemeVars; } +enum THEME { + DENIM = "denim:jade", + IRIS = "iris:coral", + AVACADO = "avacado:wood", + PUMPKIN = "pumpkin:lilac", + SCARLET = "scarlet:marigold", +} +enum TINT { + SILVER = "silver", + STEEL = "steel", + OLIVE = "olive", + SAND = "sand", +} +enum ROUNDING { + SMALL = "sm", + NORMAL = "normal", + MEDIUM = "md", + FULL = "full", +} + export const ThemeToggle = () => { const api = useStorybookApi(); const [globals, updateGlobals] = useGlobals(); - const { darkTheme = themes.dark, lightTheme = themes.light } = useParameter< - Partial - >("themeToggle", {}); const [theme, setTheme] = useState( - (localStorage.getItem(STORAGE_KEY) as THEME) ?? THEME.LIGHT, + (localStorage.getItem(THEME_KEY) as THEME) ?? THEME.DENIM, + ); + const [tint, setTint] = useState( + (localStorage.getItem(TINT_KEY) as TINT) ?? TINT.SILVER, + ); + const [rounding, setRounding] = useState( + (localStorage.getItem(ROUNDING_KEY) as ROUNDING) ?? ROUNDING.NORMAL, + ); + const { darkTheme = themes.dark, lightTheme = themes.light } = useParameter< + Partial + >("schemeToggle", {}); + const [colorScheme, setColorScheme] = useState( + (localStorage.getItem(STORAGE_KEY) as COLOR_SCHEME) ?? COLOR_SCHEME.LIGHT, ); // Function that will update the global value and trigger a UI refresh. - const refreshAndUpdateGlobal = useCallback((key: THEME, theme: ThemeVars) => { - api.setOptions({ theme }); - // Updates Storybook global value - updateGlobals({ - [GLOBAL_KEY]: key, - }); - api.getChannel()?.emit("THEME_CHANGED", key); - }, []); + // Function that will update the global value and trigger a UI refresh. + const refreshAndUpdateGlobal = useCallback( + (key: COLOR_SCHEME, theme: ThemeVars) => { + api.setOptions({ theme }); + // Updates Storybook global value + updateGlobals({ + [GLOBAL_KEY]: key, + }); + api.getChannel()?.emit("SCHEME_CHANGED", key); + }, + [], + ); + + const changeTheme = useCallback( + (key: THEME = THEME.DENIM) => { + localStorage.setItem(THEME_KEY, key); + setTheme(key); + }, + [theme], + ); + + const changeTint = useCallback( + (key: TINT) => { + localStorage.setItem(TINT_KEY, key); + setTint(key); + }, + [theme], + ); - const toggleTheme = useCallback(() => { - const newTheme = theme === THEME.DARK ? THEME.LIGHT : THEME.DARK; + const changeRounding = useCallback( + (key: ROUNDING) => { + localStorage.setItem(ROUNDING_KEY, key); + setRounding(key); + }, + [theme], + ); + + const toggleColorScheme = useCallback(() => { + const newTheme = + colorScheme === COLOR_SCHEME.DARK + ? COLOR_SCHEME.LIGHT + : COLOR_SCHEME.DARK; localStorage.setItem(STORAGE_KEY, newTheme); - setTheme(newTheme); - }, [theme]); + setColorScheme(newTheme); + }, [colorScheme]); useEffect(() => { api.getChannel()?.emit("LOCALE_CHANGED", globals.locale); }, [globals.locale]); useEffect(() => { - refreshAndUpdateGlobal(theme, { - ...(theme === THEME.DARK ? darkTheme : lightTheme), + refreshAndUpdateGlobal(colorScheme, { + ...(colorScheme === COLOR_SCHEME.DARK ? darkTheme : lightTheme), }); - }, [theme, darkTheme, lightTheme, globals.primary, globals.accent]); + }, [colorScheme, darkTheme, lightTheme, globals.primary, globals.accent]); + + useEffect(() => { + const [primary, accent] = theme.split(":"); + api.getChannel()?.emit("THEME_CHANGED", primary, accent); + api.getChannel()?.emit("TINT_CHANGED", tint ?? TINT.SILVER); + api.getChannel()?.emit("ROUNDING_CHANGED", rounding ?? ROUNDING.NORMAL); + }, [theme, tint, rounding, colorScheme]); return ( - - {theme === THEME.DARK ? : } - + <> +
+ + {colorScheme === COLOR_SCHEME.DARK ? : } + +
+ + changeTheme(THEME.DENIM)} + > +
+ + + changeTheme(THEME.AVACADO)} + > +
+ + + changeTheme(THEME.SCARLET)} + > +
+ + + changeTheme(THEME.PUMPKIN)} + > +
+ + + changeTheme(THEME.IRIS)} + > +
+ + +
+ + changeTint(TINT.SILVER)} + > +
+ + + changeTint(TINT.STEEL)} + > +
+ + + changeTint(TINT.OLIVE)} + > +
+ + + changeTint(TINT.SAND)} + > +
+ + +
+ + changeRounding(ROUNDING.SMALL)} + > +
+ + + changeRounding(ROUNDING.NORMAL)} + > +
+ + + changeRounding(ROUNDING.MEDIUM)} + > +
+ + + changeRounding(ROUNDING.FULL)} + > +
+ + ); }; diff --git a/.storybook/manager-head.html b/.storybook/manager-head.html index 77f17d1..58da660 100644 --- a/.storybook/manager-head.html +++ b/.storybook/manager-head.html @@ -5,6 +5,23 @@