From 757201fdc5c04a3f15504f74bf8ab85bb6018c2b Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 27 Oct 2023 11:09:38 +0200 Subject: refactor(hooks,provider): move reduce motion setter Since the local storage key is not meant to change between the components, it should be set directly inside the app file. So both the local storage and the data attribute should be handle in a provider. I also added a custom document because we need a script to retrieve the stored value in local storage earlier to avoid flashing on hydration. --- src/components/molecules/forms/switch/switch.tsx | 4 +- .../forms/motion-toggle/motion-toggle.fixture.ts | 1 - .../forms/motion-toggle/motion-toggle.stories.tsx | 30 +------- .../forms/motion-toggle/motion-toggle.test.tsx | 3 +- .../forms/motion-toggle/motion-toggle.tsx | 44 ++---------- .../organisms/modals/settings-modal.stories.tsx | 15 +--- .../organisms/modals/settings-modal.test.tsx | 5 +- src/components/organisms/modals/settings-modal.tsx | 19 +---- .../organisms/toolbar/settings.stories.tsx | 13 ---- src/components/organisms/toolbar/settings.test.tsx | 16 +---- src/components/organisms/toolbar/settings.tsx | 10 +-- .../organisms/toolbar/toolbar.stories.tsx | 11 --- src/components/organisms/toolbar/toolbar.test.tsx | 4 +- src/components/organisms/toolbar/toolbar.tsx | 25 +++---- src/components/templates/layout/layout.tsx | 2 - src/pages/_app.tsx | 37 ++++++---- src/pages/_document.tsx | 26 +++++++ src/utils/constants.ts | 1 + src/utils/helpers/strings.ts | 32 +++++---- src/utils/hooks/index.ts | 1 + src/utils/hooks/use-reduced-motion/index.ts | 1 + .../use-reduced-motion/use-reduced-motion.test.tsx | 66 +++++++++++++++++ .../hooks/use-reduced-motion/use-reduced-motion.ts | 9 +++ src/utils/providers/index.ts | 1 + src/utils/providers/motion-provider/index.ts | 1 + .../motion-provider/motion-provider.test.tsx | 50 +++++++++++++ .../providers/motion-provider/motion-provider.tsx | 83 ++++++++++++++++++++++ 27 files changed, 314 insertions(+), 196 deletions(-) delete mode 100644 src/components/organisms/forms/motion-toggle/motion-toggle.fixture.ts create mode 100644 src/pages/_document.tsx create mode 100644 src/utils/hooks/use-reduced-motion/index.ts create mode 100644 src/utils/hooks/use-reduced-motion/use-reduced-motion.test.tsx create mode 100644 src/utils/hooks/use-reduced-motion/use-reduced-motion.ts create mode 100644 src/utils/providers/motion-provider/index.ts create mode 100644 src/utils/providers/motion-provider/motion-provider.test.tsx create mode 100644 src/utils/providers/motion-provider/motion-provider.tsx (limited to 'src') diff --git a/src/components/molecules/forms/switch/switch.tsx b/src/components/molecules/forms/switch/switch.tsx index df2ba0c..ad3e514 100644 --- a/src/components/molecules/forms/switch/switch.tsx +++ b/src/components/molecules/forms/switch/switch.tsx @@ -55,9 +55,7 @@ const SwitchItem: FC = ({ value, ...props }) => { - const selectedItemClass = isSelected ? styles['item--selected'] : ''; - const disabledItemClass = isDisabled ? styles['item--disabled'] : ''; - const itemClass = `${styles.item} ${selectedItemClass} ${disabledItemClass} ${className}`; + const itemClass = `${styles.item} ${className}`; return (