Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/vr-tests-react-components/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,10 @@ setAddon({
});

/** @type {import("@fluentui/react-storybook-addon").FluentParameters} */
export const parameters = { layout: 'none', mode: 'vr-test' };
export const parameters = {
Comment thread
layershifter marked this conversation as resolved.
layout: 'none',
mode: 'vr-test',
reactStorybookAddon: {
disabledDecorators: ['AriaLive'],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface FluentParameters extends Parameters_2 {
fluentTheme?: ThemeIds;
// (undocumented)
mode?: 'default' | 'vr-test';
// (undocumented)
reactStorybookAddon?: {
disabledDecorators: ['AriaLive' | 'FluentProvider' | 'ReactStrictMode'];
};
}

// @public (undocumented)
Expand All @@ -46,6 +50,9 @@ export function parameters(options?: FluentParameters): {
dir: string;
fluentTheme: string;
mode: string;
reactStorybookAddon?: {
disabledDecorators: ["AriaLive" | "FluentProvider" | "ReactStrictMode"];
} | undefined;
fileName?: string | undefined;
options?: OptionsParameter | undefined;
layout?: "centered" | "fullscreen" | "padded" | "none" | undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { AriaLiveAnnouncer } from '@fluentui/react-aria';
import * as React from 'react';

Comment thread
layershifter marked this conversation as resolved.
import { AriaLiveAnnouncer } from '@fluentui/react-aria';
import { FluentStoryContext } from '../hooks';
import { isDecoratorDisabled } from '../utils/isDecoratorDisabled';

export const withAriaLive = (Story: () => JSX.Element, context: FluentStoryContext) => {
if (isDecoratorDisabled(context, 'AriaLive')) {
return Story();
}

export const withAriaLive = (StoryFn: () => JSX.Element) => {
return <AriaLiveWrapper>{StoryFn()}</AriaLiveWrapper>;
return (
<AriaLiveWrapper>
<Story />
</AriaLiveWrapper>
);
};

const AriaLiveWrapper: React.FC<{ children: React.ReactNode }> = props => {
const [mounted, setMounted] = React.useState(false);

React.useEffect(() => {
// The AriaLiveAnnouncer appends an element to DOM in an effect
// Trigger an extra renderer to make sure that doc examples that need to announce on mount can do so
setMounted(true);
}, []);

return <AriaLiveAnnouncer>{mounted && props.children}</AriaLiveAnnouncer>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -23,8 +24,12 @@ const getActiveFluentTheme = (globals: FluentGlobals) => {
export const withFluentProvider = (StoryFn: () => JSX.Element, context: FluentStoryContext) => {
const { globals, parameters } = context;
const { mode } = parameters;
const isVrTest = mode === 'vr-test';

if (isDecoratorDisabled(context, 'FluentProvider')) {
return StoryFn();
}

const isVrTest = mode === 'vr-test';
const dir = parameters.dir ?? globals[DIR_ID] ?? 'ltr';
const globalTheme = getActiveFluentTheme(globals);
const paramTheme = findTheme(parameters.fluentTheme);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ 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) => {
if (isDecoratorDisabled(context, 'ReactStrictMode')) {
return StoryFn();
}

const isActive = context.globals[STRICT_MODE_ID] ?? false;

return <StrictModeWrapper strictMode={isActive}>{StoryFn()}</StrictModeWrapper>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface FluentParameters extends Parameters {
dir?: 'ltr' | 'rtl';
fluentTheme?: ThemeIds;
mode?: 'default' | 'vr-test';
reactStorybookAddon?: { disabledDecorators: ['AriaLive' | 'FluentProvider' | 'ReactStrictMode'] };
}

export function useGlobals(): [FluentGlobals, (newGlobals: FluentGlobals) => void] {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { FluentParameters, FluentStoryContext } from '../hooks';

type DecoratorName = NonNullable<FluentParameters['reactStorybookAddon']>['disabledDecorators'][number];

export function isDecoratorDisabled(context: FluentStoryContext, decoratorName: DecoratorName): boolean {
return context.parameters.reactStorybookAddon?.disabledDecorators?.includes(decoratorName) ?? false;
}