Skip to content

Commit ba08792

Browse files
authored
Merge pull request #18 from Coreoz/dev/storybook
ADD Storybook on Front template
2 parents d38f977 + 1836273 commit ba08792

File tree

9 files changed

+7893
-788
lines changed

9 files changed

+7893
-788
lines changed

templates/front/.eslintrc.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
'airbnb-typescript',
1111
'plugin:compat/recommended',
1212
'plugin:jsx-a11y/recommended',
13+
'plugin:storybook/recommended'
1314
// à décommenter pour voir l'usage des fonctions un peu exotiques
1415
// => par contre on ne peut pas laisser ce plugin tout le temps
1516
// => car il ne tient ni compte des polyfill, ni des navigateurs configurés dans browserslist
@@ -79,14 +80,14 @@ module.exports = {
7980
'functions': false,
8081
}],
8182
// Uniformize TS type members delimiter (comma instead of semicolon)
82-
"@typescript-eslint/member-delimiter-style": ["error", {
83-
"multiline": {
84-
"delimiter": "comma",
85-
"requireLast": true
83+
'@typescript-eslint/member-delimiter-style': ['error', {
84+
'multiline': {
85+
'delimiter': 'comma',
86+
'requireLast': true
8687
},
87-
"singleline": {
88-
"delimiter": "comma",
89-
"requireLast": false
88+
'singleline': {
89+
'delimiter': 'comma',
90+
'requireLast': false
9091
}
9192
}],
9293
// Force explicit type definition

templates/front/.storybook/main.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { StorybookConfig } from '@storybook/react-vite';
2+
3+
import { join, dirname } from 'path';
4+
5+
/**
6+
* This function is used to resolve the absolute path of a package.
7+
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
8+
*/
9+
// getAbsolutePath use internal types of storybook : "FrameworkName"
10+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11+
function getAbsolutePath(value: string): any {
12+
return dirname(require.resolve(join(value, 'package.json')));
13+
}
14+
15+
const config: StorybookConfig = {
16+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
17+
addons: [
18+
getAbsolutePath('@storybook/addon-interactions'),
19+
getAbsolutePath('@storybook/addon-links'),
20+
getAbsolutePath('@storybook/addon-essentials'),
21+
getAbsolutePath('@storybook/addon-onboarding'),
22+
],
23+
framework: {
24+
name: getAbsolutePath('@storybook/react-vite'),
25+
options: {},
26+
},
27+
docs: {
28+
autodocs: 'tag',
29+
},
30+
};
31+
export default config;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { Preview } from '@storybook/react';
2+
3+
// Import du CSS de l'application
4+
import '../assets/scss/app.scss';
5+
6+
const preview: Preview = {
7+
parameters: {
8+
actions: { argTypesRegex: '^on[A-Z].*' },
9+
controls: {
10+
matchers: {
11+
color: /(background|color)$/i,
12+
date: /Date$/,
13+
},
14+
},
15+
},
16+
// decorators: [
17+
// (Story) => {
18+
// // Ajouter ici un décorateur générique si besoin
19+
// return (
20+
// <Story />
21+
// )
22+
// }
23+
// ],
24+
};
25+
26+
export default preview;

templates/front/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Plume admin React TS
1+
Plume React TS
22
====================
33

44
Installation
@@ -89,3 +89,4 @@ Some key points about the technologies used in the project :
8989
- [MUI](https://mui.com/)
9090
- [validator.js](https://github.com/validatorjs/validator.js)
9191
- [browser-user-session](https://github.com/Coreoz/browser-user-session)
92+
- Frontend workshop for UI components and pages in isolation is perform with [Storybook](https://storybook.js.org/docs/react/get-started/install/)

templates/front/package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,24 @@
1818
},
1919
"devDependencies": {
2020
"@sayari/eslint-plugin": "^0.0.1-rc.4",
21+
"@storybook/addon-docs": "^7.4.6",
22+
"@storybook/addon-essentials": "7.4.6",
23+
"@storybook/addon-interactions": "7.4.6",
24+
"@storybook/addon-links": "7.4.6",
25+
"@storybook/addon-onboarding": "1.0.8",
26+
"@storybook/blocks": "7.4.6",
27+
"@storybook/builder-vite": "^7.4.6",
28+
"@storybook/react": "7.4.6",
29+
"@storybook/react-vite": "7.4.6",
30+
"@storybook/testing-library": "0.2.2",
2131
"@types/enzyme": "^3.10.12",
2232
"@types/jest": "^29.1.2",
2333
"@types/node": "^20.3.0",
2434
"@types/react": "^18.0.21",
2535
"@types/react-dom": "^18.0.6",
2636
"@types/react-router": "^5.1.19",
2737
"@types/react-router-dom": "^5.3.3",
38+
"@types/storybook__react": "^5.2.1",
2839
"@types/validator": "^13.7.7",
2940
"@typescript-eslint/eslint-plugin": "^5.47.0",
3041
"@typescript-eslint/parser": "^5.47.0",
@@ -41,6 +52,7 @@
4152
"eslint-plugin-jsx-a11y": "^6.6.1",
4253
"eslint-plugin-react": "^7.31.11",
4354
"eslint-plugin-react-hooks": "^4.6.0",
55+
"eslint-plugin-storybook": "^0.6.15",
4456
"eslint-plugin-typescript-compat": "^0.3.1",
4557
"fetch-mock": "^9.11.0",
4658
"fetch-mock-jest": "^1.5.1",
@@ -52,6 +64,8 @@
5264
"postcss": "^8.4.18",
5365
"react-router": "^6.4.2",
5466
"sass": "^1.55.0",
67+
"storybook": "7.4.6",
68+
"storybook-addon-react-router-v6": "^2.0.7",
5569
"stylelint": "^14.13.0",
5670
"stylelint-config-recommended-scss": "^7.0.0",
5771
"stylelint-scss": "^4.3.0",
@@ -85,7 +99,9 @@
8599
"typescript": "tsc --noEmit",
86100
"test": "jest --config jest.config.js",
87101
"coverage": "jest --config jest.config.js --coverage --watchAll=false",
88-
"check-scss-types": "typed-scss-modules 'src/**/*.scss' -l"
102+
"check-scss-types": "typed-scss-modules 'src/**/*.scss' -l",
103+
"storybook": "storybook dev -p 6006",
104+
"build-storybook": "storybook build"
89105
},
90106
"packageManager": "yarn@3.6.4",
91107
"engines": {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Storybook
2+
====================
3+
4+
Official Documentation
5+
----------------------
6+
[Documentation](https://storybook.js.org/docs/react/writing-stories/introduction)
7+
8+
9+
To launch Storybook, use the following command: `yarn storybook`
10+
11+
This command starts a local server and opens Storybook in your default web browser.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
import LocaleSelector from '@components/theme/LocaleSelector';
3+
import { Locale } from '@lib/locale-resolver/LocaleResolver';
4+
5+
// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
6+
const meta: Meta<typeof LocaleSelector> = {
7+
title: 'Components/LocaleSelector',
8+
component: LocaleSelector,
9+
parameters: {
10+
// Optional parameter to center the component in the Canvas.
11+
// More info: https://storybook.js.org/docs/react/configure/story-layout
12+
layout: 'centered',
13+
},
14+
// This component will have an automatically generated Autodocs entry:
15+
// https://storybook.js.org/docs/react/writing-docs/autodocs
16+
tags: ['autodocs'],
17+
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
18+
argTypes: {
19+
availableLocales: { control: 'array' },
20+
onLocaleSelected: { action: 'onLocaleSelected' },
21+
currentLocale: { control: 'text' },
22+
},
23+
} satisfies Meta<typeof LocaleSelector>;
24+
25+
export default meta;
26+
type Story = StoryObj<typeof meta>;
27+
28+
const LOCAL_FR: Locale = { code: 'fr', name: 'Français' } as Locale;
29+
const LOCAL_EN: Locale = { code: 'en', name: 'English' } as Locale;
30+
31+
// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
32+
export const Test: Story = {
33+
args: {
34+
availableLocales: [LOCAL_FR, LOCAL_EN],
35+
onLocaleSelected: () => {
36+
// We can't use action here because it's a sample component
37+
// eslint-disable-next-line no-console
38+
console.log('btn click');
39+
},
40+
currentLocale: LOCAL_FR,
41+
},
42+
};

templates/front/tsconfig.eslint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"tests",
77
"vite.config.ts",
88
"di-transformer-adapter.ts",
9-
"typed-scss-modules.config.ts"
9+
"typed-scss-modules.config.ts",
10+
".storybook/*.ts"
1011
]
1112
}

0 commit comments

Comments
 (0)