Skip to content

Commit

Permalink
chore(angular): add theme-decorator example
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaudAV committed Jan 28, 2021
1 parent 9113153 commit 53248ca
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/angular-cli/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ module.exports = {
'@storybook/addon-jest',
'@storybook/addon-backgrounds',
'@storybook/addon-a11y',
'@storybook/addon-toolbars',
],
};
15 changes: 15 additions & 0 deletions examples/angular-cli/.storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,18 @@ addParameters({
prepareForInline,
},
});

export const globalTypes = {
theme: {
name: 'Theme',
description: 'Global theme for components',
defaultValue: 'light',
toolbar: {
icon: 'paintbrush',
items: [
{ value: 'light', title: 'Light theme' },
{ value: 'dark', title: 'Dark theme' },
],
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ exports[`Storyshots Core/Parameters passed to story 1`] = `
"docs": {
"inlineStories": true
},
"globalTypes": {
"theme": {
"name": "Theme",
"description": "Global theme for components",
"defaultValue": "light",
"toolbar": {
"icon": "paintbrush",
"items": [
{
"value": "light",
"title": "Light theme"
},
{
"value": "dark",
"title": "Dark theme"
}
]
}
}
},
"globalParameter": "globalParameter",
"framework": "angular",
"chapterParameter": "chapterParameter",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Storyshots Core / Theme Decorators Base 1`] = `
<storybook-wrapper>
<div
class="light-theme"
>
Change theme with the brush in toolbar
</div>
</storybook-wrapper>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { componentWrapperDecorator, Meta } from '@storybook/angular';

export default {
title: 'Core / Theme Decorators',
decorators: [
componentWrapperDecorator(
(story) => `<div [class]="myTheme">${story}</div>`,
({ globals }) => ({ myTheme: `${globals.theme}-theme` })
),
],
} as Meta;

export const Base = (args) => ({
template: 'Change theme with the brush in toolbar',
props: {
...args,
},
});
9 changes: 9 additions & 0 deletions examples/angular-cli/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@
.green-color {
color: $color;
}

.light-theme {
background-color: white;
}

.dark-theme {
background-color: rgb(75, 75, 75);
color: white;
}

0 comments on commit 53248ca

Please sign in to comment.