Skip to content

Commit

Permalink
Merge pull request #56 from etchteam/fix/auto-init-global-variables
Browse files Browse the repository at this point in the history
fix: auto init global variables
  • Loading branch information
gavmck authored Dec 14, 2023
2 parents 4f61729 + 397bf94 commit ad8382f
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = {
"stories": ["../stories/**/*.mdx", "../stories/**/*.stories.@(js|jsx|ts|tsx)"],
"addons": ["../register.js", "@storybook/addon-essentials"],
"addons": ["../dist/preset/index.js", "@storybook/addon-essentials"],
"framework": {
name: "@storybook/react-webpack5",
options: {}
},
docs: {
autodocs: true
}
};
};
4 changes: 0 additions & 4 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,3 @@ export const parameters = {
export const decorators = [
cssVariablesTheme,
];

export const globals = {
cssVariables: null,
};
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Add the following code to it:

```js
module.exports = {
addons: ['@etchteam/storybook-addon-css-variables-theme'],
addons: ['@etchteam/storybook-addon-css-variables-theme/preset'],
};
```

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etchteam/storybook-addon-css-variables-theme",
"version": "2.0.0",
"version": "2.0.1",
"description": "Switch CSS files to change themes",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 5 additions & 1 deletion src/preset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ export function managerEntries(entry: any[] = []) {
return [...entry, require.resolve('../register')];
}

module.exports = { managerEntries };
export const previewAnnotations = (entry: any[] = []) => {
return [...entry, require.resolve('../preview')];
};

module.exports = { managerEntries, previewAnnotations };
3 changes: 3 additions & 0 deletions src/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const globals = {
cssVariables: <string | null>null,
};
10 changes: 2 additions & 8 deletions stories/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,24 @@ export default {
} as ComponentMeta<typeof Button>;

// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const Template: ComponentStory<typeof Button> = (args) => {
return <Button {...args} />;
const Template: ComponentStory<typeof Button> = (args, context) => {
return <Button {...args}>{context.globals.cssVariables}</Button>;
};

export const Primary = Template.bind({});
// More on args: https://storybook.js.org/docs/react/writing-stories/args
Primary.args = {
primary: true,
label: 'Button',
};

export const Secondary = Template.bind({});
Secondary.args = {
label: 'Button',
};

export const Large = Template.bind({});
Large.args = {
size: 'large',
label: 'Button',
};

export const Small = Template.bind({});
Small.args = {
size: 'small',
label: 'Button',
};
6 changes: 3 additions & 3 deletions stories/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface ButtonProps {
/**
* Button contents
*/
readonly label: string;
readonly children: React.ReactNode;
/**
* Optional click handler
*/
Expand All @@ -31,7 +31,7 @@ const Button = ({
primary = false,
size = 'medium',
backgroundColor,
label,
children,
...props
}: ButtonProps) => {
const mode = primary
Expand All @@ -46,7 +46,7 @@ const Button = ({
style={{ backgroundColor }}
{...props}
>
{label}
{children}
</button>
);
};
Expand Down

0 comments on commit ad8382f

Please sign in to comment.