Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storybook): add rtl/ltr toggle storybook addon #32814

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 8 additions & 7 deletions packages/react-components/react-storybook-addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@
"@fluentui/scripts-tasks": "*"
marcosmoura marked this conversation as resolved.
Show resolved Hide resolved
},
"dependencies": {
"@fluentui/react-theme": "^9.1.19",
"@fluentui/react-provider": "^9.17.3",
"@fluentui/react-aria": "^9.13.5",
"@fluentui/react-provider": "^9.17.3",
"@fluentui/react-theme": "^9.1.19",
"@griffel/react": "^1.5.22",
"@swc/helpers": "^0.5.1"
},
"peerDependencies": {
"@types/react": ">=16.14.0 <19.0.0",
"@types/react-dom": ">=16.9.0 <19.0.0",
"react": ">=16.14.0 <19.0.0",
"react-dom": ">=16.14.0 <19.0.0",
"@storybook/components": "^7.6.20",
"@storybook/manager-api": "^7.6.20",
"@storybook/react": "^7.6.20",
"@storybook/theming": "^7.6.20"
"@storybook/theming": "^7.6.20",
"@types/react-dom": ">=16.9.0 <19.0.0",
"@types/react": ">=16.14.0 <19.0.0",
"react-dom": ">=16.14.0 <19.0.0",
"react": ">=16.14.0 <19.0.0"
},
"beachball": {
"disallowedChangeTypes": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { makeStyles } from '@griffel/react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this was the best architectural decision , for storybook UIs we should stick with storybook styling approach


export const useDirSwitchStyles = makeStyles({
monospace: {
fontFamily: 'monospace',
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';
import { IconButton } from '@storybook/components';

import { DIR_ID } from '../constants';
import { useGlobals } from '../hooks';

import { useDirSwitchStyles } from './DirSwitch.styles';

export const DirSwitch = () => {
const [globals, updateGlobals] = useGlobals();
const styles = useDirSwitchStyles();

const direction = globals[DIR_ID] ?? 'ltr';
const isLTR = direction === 'ltr';

const toggleDirection = React.useCallback(
() =>
updateGlobals({
[DIR_ID]: isLTR ? 'rtl' : 'ltr',
}),
[isLTR, updateGlobals],
);

return (
<IconButton key={DIR_ID} title="Change Direction" onClick={toggleDirection}>
<div>
Direction: <span className={styles.monospace}>{isLTR ? 'LTR' : 'RTL'}</span>
marcosmoura marked this conversation as resolved.
Show resolved Hide resolved
</div>
</IconButton>
);
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { addons, types } from '@storybook/manager-api';

import { ADDON_ID, STRICT_MODE_ID, THEME_ID } from '../constants';
import { ADDON_ID, DIR_ID, STRICT_MODE_ID, THEME_ID } from '../constants';
import { ThemePicker } from '../components/ThemePicker';
import { ReactStrictMode } from '../components/ReactStrictMode';
import { DirSwitch } from '../components/DirSwitch';

addons.register(ADDON_ID, () => {
addons.add(THEME_ID, {
Expand All @@ -12,6 +13,13 @@ addons.register(ADDON_ID, () => {
match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)),
render: ThemePicker,
});
addons.add(DIR_ID, {
title: 'Dir Switch',
Hotell marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line deprecation/deprecation
type: types.TOOL,
match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)),
render: DirSwitch,
});
addons.add(STRICT_MODE_ID, {
// eslint-disable-next-line deprecation/deprecation
type: types.TOOL,
Expand Down
Loading