Skip to content

Commit

Permalink
feat: add storybook docs with deploy to gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
xobotyi committed Apr 22, 2021
1 parent d0c54f9 commit 84de312
Show file tree
Hide file tree
Showing 15 changed files with 6,512 additions and 236 deletions.
21 changes: 14 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
tsconfigRootDir: __dirname,
},

ignorePatterns: ['dist'],
ignorePatterns: ['dist', 'node_modules', 'coverage', 'storybook-build'],

extends: [
'airbnb',
Expand Down Expand Up @@ -66,12 +66,7 @@ module.exports = {
},
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
},
{
selector: 'parameter',
format: ['camelCase'],
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
},
{
Expand All @@ -81,4 +76,16 @@ module.exports = {
},
],
},
overrides: [
{
files: ['stories/**/*', '.storybook/**/*'],
rules: {
'import/no-extraneous-dependencies': 'off',
'import/no-default-export': 'off',
'react/button-has-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'react/prop-types': 'off',
},
},
],
};
File renamed without changes
26 changes: 26 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,29 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

deploy-gh-pages:
name: "Deploy GH Pages"
runs-on: ubuntu-latest
needs: "semantic-release"
if: needs.semantic-release.outputs.new-release-published == 'true' || github.event_name == 'workflow_dispatch'
steps:
- name: "Checkout"
uses: actions/checkout@v2
with:
ref: "master"

- name: "Setup Node.js"
uses: actions/setup-node@v2
with:
node-version: 15

- name: "Install dependencies"
uses: bahmutov/npm-install@v1
with:
useRollingCache: true

- name: "Deploy storybook"
run: yarn storybook:deploy --ci
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
node_modules
/coverage
/dist
/storybook-build
Binary file added .storybook/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
stories: ['../stories/**/*.story.mdx', '../stories/**/*.story.@(js|jsx|ts|tsx)'],
addons: [
'@storybook/addon-links',
{
name: '@storybook/addon-essentials',
options: {
backgrounds: false,
},
},
],
reactOptions: {
fastRefresh: true,
},
};
11 changes: 11 additions & 0 deletions .storybook/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { addons } from '@storybook/addons';
import { themes } from '@storybook/theming';
import Logo from './logo.png';

addons.setConfig({
theme: {
...themes.light,
brandTitle: '@react-hookz/web',
brandImage: Logo,
},
});
4 changes: 4 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const parameters = {
layout: 'centered',
viewMode: 'docs',
};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<h1><img src="./logo.png" alt="@react-hookz/web"></h1>
<h1><img src=".github/logo.png" alt="@react-hookz/web"></h1>
<p>
<a href="https://www.npmjs.com/package/@react-hookz/web">
<img src="https://flat.badgen.net/npm/v/@react-hookz/web" alt="NPM Version">
Expand Down
17 changes: 14 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
"build:tsc": "tsc -p ./tsconfig.build.json",
"test": "jest",
"test:coverage": "yarn test --coverage",
"lint": "eslint . --ext ts,js,tsx,jsx",
"lint": "eslint ./ ./.storybook --ext ts,js,tsx,jsx",
"lint:fix": "yarn lint --fix",
"prepare": "husky install"
"prepare": "husky install",
"storybook:watch": "start-storybook -p 6006",
"storybook:build": "build-storybook -o ./storybook-build",
"storybook:deploy": "storybook-to-ghpages -s storybook:build"
},
"lint-staged": {
"*.[tj]s?x": "eslint --fix"
"*.{js,jsx,ts,tsx}": "eslint --fix"
},
"commitlint": {
"extends": [
Expand All @@ -54,14 +57,22 @@
"react-dom": "^16.8 || ^17"
},
"devDependencies": {
"@babel/core": "^7.13.16",
"@commitlint/config-conventional": "^12.1.1",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.2.1",
"@storybook/addon-essentials": "^6.2.8",
"@storybook/addon-links": "^6.2.8",
"@storybook/addons": "^6.2.8",
"@storybook/react": "^6.2.8",
"@storybook/storybook-deployer": "^2.8.7",
"@storybook/theming": "^6.2.8",
"@testing-library/react-hooks": "^5.1.1",
"@types/jest": "^26.0.22",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"babel-loader": "^8.2.2",
"commitlint": "^12.1.1",
"eslint": "^7.24.0",
"eslint-config-airbnb": "^18.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src/useUpdateEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DependencyList, EffectCallback, useEffect } from 'react';
import { useFirstMountState } from './useFirstMountState';

/**
* Effect hook that ignores the first invocation (e.g. on mount)
* Effect hook that ignores the first invocation (not invoked on mount)
*
* @param effect Effector to run on updates
* @param deps Dependencies list, as for `useEffect` hook
Expand Down
31 changes: 31 additions & 0 deletions stories/useUpdateEffect.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';
import { useState } from 'react';
import { useRerender, useUpdateEffect } from '../src';

export const Example: React.FC<{ initialCount: number }> = ({ initialCount = 5 }) => {
const [count, setCount] = useState(initialCount);
const [isUpdated, setUpdated] = useState(false);
const rerender = useRerender();

useUpdateEffect(() => {
setUpdated(true);
}, [count]);

return (
<div>
<div>Is counter updated: {isUpdated ? 'yes' : 'no'}</div>
<button
onClick={() => {
setCount((i) => i + 1);
}}>
Increment counter [{count}]
</button>{' '}
<button
onClick={() => {
rerender();
}}>
Just rerender
</button>
</div>
);
};
14 changes: 14 additions & 0 deletions stories/useUpdateEffect.story.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Canvas, Meta, Story } from '@storybook/addon-docs/blocks';
import { Example } from './useUpdateEffect.stories';



<Meta title="Lifecycle/useUpdateEffect" component={Example} />

# useUpdateEffect

Effect hook that ignores the first invocation (not invoked on mount)

<Canvas>
<Story story={Example} />
</Canvas>
11 changes: 8 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@
"DOM"
],
"allowJs": true,
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"jsx": "react"
},
"exclude": [
"node_modules",
"dist"
"dist",
"coverage",
"storybook-build"
],
"include": [
"**.js",
"**.ts",
"src/**/*.js",
"src/**/*.ts",
"tests/**/*.js",
"tests/**/*.ts"
"tests/**/*.ts",
"stories/**/*.tsx",
".storybook/*.js"
]
}
Loading

0 comments on commit 84de312

Please sign in to comment.