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

chore(storybook): add global dark/light color variables control #1803

Merged
merged 3 commits into from
May 7, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ const DARK_THEME = { ...DEFAULT_THEME, colors: { ...DEFAULT_THEME.colors, base:
const DARK = getColor({ theme: DARK_THEME, variable: 'background.default' });
const LIGHT = getColor({ theme: DEFAULT_THEME, variable: 'background.default' });

export const args = {
'colors.dark': DEFAULT_THEME.colors.variables.dark,
'colors.light': DEFAULT_THEME.colors.variables.light
};

export const argTypes = {
'colors.dark': { table: { category: 'Variables' } },
'colors.light': { table: { category: 'Variables' } }
};

export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
backgrounds: {
Expand Down Expand Up @@ -57,7 +67,15 @@ const withThemeProvider = (story, context) => {
document.querySelector('link[href$="bedrock/dist/index.css"]').setAttribute('disabled', true);
}

const colors = { ...DEFAULT_THEME.colors, primaryHue: context.globals.primaryHue };
const colors = {
...DEFAULT_THEME.colors,
primaryHue: context.globals.primaryHue,
variables: {
...DEFAULT_THEME.colors.variables,
dark: context.args['colors.dark'],
light: context.args['colors.light']
}
};

if (
context.globals.backgrounds && context.globals.backgrounds.value !== 'transparent'
Expand Down
12 changes: 8 additions & 4 deletions packages/theming/demo/utilities.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,25 @@ import README from '../README.md';
<Story
name="getColor()"
args={{
hue: 'primaryHue',
theme: {
colors: Object.fromEntries(
Object.entries(DEFAULT_THEME.colors).filter(([key]) => key !== 'base')
),
opacity: DEFAULT_THEME.opacity,
palette: DEFAULT_THEME.palette
}
},
variable: 'background.primaryEmphasis'
}}
argTypes={{
dark: { control: { type: 'object' } },
hue: { control: { type: 'text' } },
light: { control: { type: 'object' } },
offset: { control: { type: 'number' } },
shade: { control: { type: 'number' } },
transparency: { control: { type: 'range', min: 100, max: 1200, step: 100 } },
variable: { control: { type: 'text' } }
transparency: { control: { type: 'number', min: 100, max: 1200, step: 100 } },
variable: { control: { type: 'text' } },
'colors.dark': { control: false, table: { disable: true } },
'colors.light': { control: false, table: { disable: true } }
}}
>
{args => <GetColorStory {...args} />}
Expand Down
1 change: 1 addition & 0 deletions packages/theming/src/utils/getColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export const getColor = memoize(
shade,
colors: theme.colors,
palette: theme.palette,
opacity: theme.opacity,
Copy link
Member Author

Choose a reason for hiding this comment

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

realized during testing that changes to the theme's opacity were not breaking memoization as expected.

transparency,
variable
})
Expand Down