From e5257ff646f070a4914ac55a35184487fd976579 Mon Sep 17 00:00:00 2001 From: Oleksandr Fediashov Date: Tue, 23 Jul 2024 15:11:01 +0200 Subject: [PATCH] PR comments --- .../react-storybook-addon/src/decorators/withAriaLive.tsx | 5 ++--- .../src/decorators/withFluentProvider.tsx | 5 ++--- .../src/decorators/withReactStrictMode.tsx | 5 ++--- .../react-storybook-addon/src/utils/isDecoratorDisabled.ts | 7 +++++++ 4 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 packages/react-components/react-storybook-addon/src/utils/isDecoratorDisabled.ts diff --git a/packages/react-components/react-storybook-addon/src/decorators/withAriaLive.tsx b/packages/react-components/react-storybook-addon/src/decorators/withAriaLive.tsx index 30f7579afe967b..a607fb28a5c79d 100644 --- a/packages/react-components/react-storybook-addon/src/decorators/withAriaLive.tsx +++ b/packages/react-components/react-storybook-addon/src/decorators/withAriaLive.tsx @@ -2,11 +2,10 @@ import { AriaLiveAnnouncer } from '@fluentui/react-aria'; import * as React from 'react'; import { FluentStoryContext } from '../hooks'; +import { isDecoratorDisabled } from '../utils/isDecoratorDisabled'; export const withAriaLive = (Story: () => JSX.Element, context: FluentStoryContext) => { - const shouldDisable = context.parameters.reactStorybookAddon?.disabledDecorators?.includes('AriaLive'); - - if (shouldDisable) { + if (isDecoratorDisabled(context, 'AriaLive')) { return Story(); } diff --git a/packages/react-components/react-storybook-addon/src/decorators/withFluentProvider.tsx b/packages/react-components/react-storybook-addon/src/decorators/withFluentProvider.tsx index ad1eaa888a5918..467bed589a9d64 100644 --- a/packages/react-components/react-storybook-addon/src/decorators/withFluentProvider.tsx +++ b/packages/react-components/react-storybook-addon/src/decorators/withFluentProvider.tsx @@ -5,6 +5,7 @@ import { Theme } from '@fluentui/react-theme'; import { themes, defaultTheme, ThemeIds } from '../theme'; import { DIR_ID, THEME_ID } from '../constants'; import { FluentGlobals, FluentStoryContext } from '../hooks'; +import { isDecoratorDisabled } from '../utils/isDecoratorDisabled'; const findTheme = (themeId?: ThemeIds) => { if (!themeId) { @@ -24,9 +25,7 @@ export const withFluentProvider = (StoryFn: () => JSX.Element, context: FluentSt const { globals, parameters } = context; const { mode } = parameters; - const shouldDisable = parameters.reactStorybookAddon?.disabledDecorators?.includes('FluentProvider'); - - if (shouldDisable) { + if (isDecoratorDisabled(context, 'FluentProvider')) { return StoryFn(); } diff --git a/packages/react-components/react-storybook-addon/src/decorators/withReactStrictMode.tsx b/packages/react-components/react-storybook-addon/src/decorators/withReactStrictMode.tsx index efe774f821c779..3592371cd96527 100644 --- a/packages/react-components/react-storybook-addon/src/decorators/withReactStrictMode.tsx +++ b/packages/react-components/react-storybook-addon/src/decorators/withReactStrictMode.tsx @@ -2,11 +2,10 @@ import * as React from 'react'; import { STRICT_MODE_ID } from '../constants'; import { FluentStoryContext } from '../hooks'; +import { isDecoratorDisabled } from '../utils/isDecoratorDisabled'; export const withReactStrictMode = (StoryFn: () => JSX.Element, context: FluentStoryContext) => { - const shouldDisable = context.parameters.reactStorybookAddon?.disabledDecorators?.includes('ReactStrictMode'); - - if (shouldDisable) { + if (isDecoratorDisabled(context, 'ReactStrictMode')) { return StoryFn(); } diff --git a/packages/react-components/react-storybook-addon/src/utils/isDecoratorDisabled.ts b/packages/react-components/react-storybook-addon/src/utils/isDecoratorDisabled.ts new file mode 100644 index 00000000000000..9295f69a4a992c --- /dev/null +++ b/packages/react-components/react-storybook-addon/src/utils/isDecoratorDisabled.ts @@ -0,0 +1,7 @@ +import type { FluentParameters, FluentStoryContext } from '../hooks'; + +type DecoratorName = NonNullable['disabledDecorators'][number]; + +export function isDecoratorDisabled(context: FluentStoryContext, decoratorName: DecoratorName): boolean { + return context.parameters.reactStorybookAddon?.disabledDecorators?.includes(decoratorName) ?? false; +}