Skip to content

Commit

Permalink
feat: introduced compatibility with storybook 6
Browse files Browse the repository at this point in the history
feat: introduced compatibility with storybook 6
  • Loading branch information
semoal authored Aug 25, 2020
2 parents 95a70c2 + 8f1854a commit cd35960
Show file tree
Hide file tree
Showing 31 changed files with 53,686 additions and 230 deletions.
12 changes: 0 additions & 12 deletions .babelrc

This file was deleted.

77 changes: 0 additions & 77 deletions .circleci/config.yml

This file was deleted.

66 changes: 66 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Main CI

on:
workflow_dispatch:
inputs:
distTag:
description: 'Dist tag to publish'
required: true
default: 'latest'
pull_request:
push:
branches:
- 'master'

jobs:
build_and_testing:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
BUNDLESIZE_GITHUB_TOKEN: ${{ secrets.BUNDLESIZE_GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false

- name: Restore cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- uses: actions/setup-node@v2-beta
with:
always-auth: true
node-version: 12
- name: Creates local .npmrc
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

- name: Install
run: npm ci

- name: Build & Testing
run: |
npm run lint
npm run build
npm run test
npm run bundle-size
- name: Release
if: ${{github.event.inputs.distTag == 'latest' || github.event.inputs.distTag == 'next'}}
run: |
git config --global user.email "[email protected]"
git config --global user.name "CI"
npm run release && npm run publish-storybook
- name: Release Docs
if: ${{github.event.inputs.distTag == 'latest' || github.event.inputs.distTag == 'next'}}
uses: JamesIves/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
BRANCH: gh-pages
FOLDER: example/storybook-static
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ node_modules
dist
coverage
.cache
package-lock.json
.DS_Store
pkg
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
![npm](https://img.shields.io/npm/dy/themeprovider-storybook.svg)
![GitHub](https://img.shields.io/github/license/semoal/themeprovider-storybook.svg)
![BundleSize](https://img.shields.io/bundlephobia/min/themeprovider-storybook)
[![Greenkeeper badge](https://badges.greenkeeper.io/semoal/themeprovider-storybook.svg)](https://greenkeeper.io/)
[![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](semanticrelease)

This addon helps you to display a Styled-Components ThemeProvider or a custom one in your [Storybook](https://storybook.js.org).

- Works on Storybook 5.x.x and 6.x.x (latest release)
- Switches background color.
- Works on iframes or visual regression testing.
- Allows passing a custom implementation of your own theme provider.
- Displays a popup with all the current keys of the theme.
- Displays a popup with all the current keys of the theme. [If you want, you can disable it](#disable-popup)
- You can copy individually a value from the theme.

![Screenshot](https://i.imgur.com/y1Je5xR.gif)
Expand All @@ -28,18 +28,21 @@ yarn add themeprovider-storybook --dev
npm install --save-dev themeprovider-storybook
```

Add this line to your `addons.js` file (create this file inside your storybook config directory if needed).
Add this line to your addons array inside `main.js` file (create this file inside your storybook config directory if needed).

```js
import 'themeprovider-storybook/register';
module.exports = {
addons: [
"themeprovider-storybook/register"
]
}
```

### Set options globally

Import and use the `addDecorator` in your `config.js` file.
Import and use the `withThemesProvider` function in your `preview.js` file.

```js
import { addDecorator, configure } from '@storybook/react';
import { withThemesProvider } from "themeprovider-storybook";

// Options:
Expand All @@ -55,9 +58,22 @@ const themes = [
..., // Your theme keys (Check example if you need some help)
}
]
addDecorator(withThemesProvider(themes));

configure(() => require('./stories'), module);
export const decorators = [withThemesProvider(themes)];
```

### Examples

| version | documentation |
|----------|:-------------:|
| For Storybook v5.x.x | [OLD readme](./v5_example/README.md) |
| For Storybook v6.x.x | [Current readme](./README.md) |


### Disable popup

```jsx
export const decorators = [withThemesProvider(themes, { disableThemePreview: false })];
```

### How to use your own implementation of ThemeProvider
Expand Down
2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
storybook-static
1 change: 0 additions & 1 deletion example/.storybook/addons.js

This file was deleted.

24 changes: 9 additions & 15 deletions example/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
module.exports = {
stories: ['../stories/**/*.stories.(tsx|ts)'],
addons: ['@storybook/addon-docs', '@storybook/addon-actions', '@storybook/addon-links'],
webpackFinal: async config => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('ts-loader'),
},
],
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
},
};
stories: [
"../src/**/*.stories.mdx",
"../src/**/*.stories.@(js|jsx|ts|tsx)"
],
addons: [
"@storybook/addon-docs",
"themeprovider-storybook/register"
]
}
46 changes: 46 additions & 0 deletions example/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { withThemesProvider } from "themeprovider-storybook"
const THEMES = [
{
name: 'Light',
backgroundColor: '#fff',
palette: {
TextField: {
backgroundColor: '#f3f3f3',
fontColor: '#212e45',
borderColor: '#e2e6f3',
placeholderColor: '#999999',
opacityDisabled: 0.25,
borderError: '#e25a66',
},
Common: {
backgroundColor: '#1a213f',
fontColor: '#808ab1',
borderError: '#e25a66'
},
}
},
{
name: 'Dark',
backgroundColor: '#121833',
palette: {
TextField: {
backgroundColor: '#1a213f',
fontColor: '#808ab1',
borderColor: '#808ab1',
placeholderColor: '#808ab1',
opacityDisabled: 0.45,
borderError: '#e25a66'
},
Common: {
backgroundColor: '#1a213f',
fontColor: '#808ab1',
borderError: '#e25a66'
},
}
},
]

export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
}
export const decorators = [withThemesProvider(THEMES)];
Loading

0 comments on commit cd35960

Please sign in to comment.