-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storybook): add rtl/ltr toggle storybook addon (#32814)
- Loading branch information
1 parent
5a5fbd3
commit 3b675ae
Showing
4 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/react-components/react-storybook-addon/src/components/DirSwitch.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { makeStyles } from '@griffel/react'; | ||
|
||
export const useDirSwitchStyles = makeStyles({ | ||
monospace: { | ||
fontFamily: 'monospace', | ||
}, | ||
}); |
31 changes: 31 additions & 0 deletions
31
packages/react-components/react-storybook-addon/src/components/DirSwitch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}>{direction.toUpperCase()}</span> | ||
</div> | ||
</IconButton> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters