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

docs(storybook): add text direction auto/ltr/rtl switcher #14464

Merged
merged 1 commit into from
Aug 23, 2023
Merged
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
37 changes: 33 additions & 4 deletions packages/react/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const devTools = {
description: "Set the layout context's size",
defaultValue: false,
toolbar: {
title: 'unstable__Layout size',
title: 'dev :: unstable__Layout size',
items: [
{
value: false,
Expand All @@ -48,7 +48,7 @@ const devTools = {
description: "Set the layout context's density",
defaultValue: false,
toolbar: {
title: 'unstable__Layout density',
title: 'dev :: unstable__Layout density',
items: [
{
value: false,
Expand All @@ -68,6 +68,7 @@ const globalTypes = {
defaultValue: 'en',
toolbar: {
icon: 'globe',
title: 'Locale',
items: [
{
right: '🇺🇸',
Expand All @@ -82,12 +83,39 @@ const globalTypes = {
],
},
},
dir: {
name: 'Text direction',
description: 'Set the text direction for the story',
defaultValue: 'ltr',
toolbar: {
icon: 'transfer',
title: 'Text direction',
items: [
{
right: '🔄',
title: 'auto',
value: 'auto',
},
{
right: '➡️',
title: 'left-to-right (ltr)',
value: 'ltr',
},
{
right: '⬅️',
title: 'right-to-left (rtl)',
value: 'rtl',
},
],
},
},
theme: {
name: 'Theme',
description: 'Set the global theme for displaying components',
defaultValue: 'white',
toolbar: {
icon: 'paintbrush',
title: 'Theme',
items: ['white', 'g10', 'g90', 'g100'],
},
},
Expand Down Expand Up @@ -277,15 +305,16 @@ const parameters = {

const decorators = [
(Story, context) => {
const { layoutDensity, layoutSize, locale, theme } = context.globals;
const { layoutDensity, layoutSize, locale, dir, theme } = context.globals;

React.useEffect(() => {
document.documentElement.setAttribute('data-carbon-theme', theme);
}, [theme]);

React.useEffect(() => {
document.documentElement.lang = locale;
}, [locale]);
document.documentElement.dir = dir;
}, [locale, dir]);

return (
<GlobalTheme theme={theme}>
Expand Down
Loading