Skip to content

Commit b206ad4

Browse files
committed
feat(storybook-host): Create storybook lib and add stories for Long Press Hook
1 parent b65ba7a commit b206ad4

20 files changed

+6406
-2135
lines changed

libs/storybook-host/.babelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
[
4+
"@nx/react/babel",
5+
{
6+
"runtime": "automatic",
7+
"useBuiltIns": "usage"
8+
}
9+
]
10+
],
11+
"plugins": []
12+
}

libs/storybook-host/.eslintrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*", "storybook-static"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
}
17+
]
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Stack } from '@mui/material';
2+
import type { ComponentType } from 'react';
3+
4+
export const ContentDecorator = (Story: ComponentType, context: object) => {
5+
return (
6+
<Stack
7+
width="100vw"
8+
height="100vh"
9+
alignItems="center"
10+
justifyContent="center"
11+
sx={{
12+
perspective: 1000,
13+
}}
14+
>
15+
<Story {...context} />
16+
</Stack>
17+
);
18+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { ComponentType, FC } from 'react';
2+
import { SnackbarProvider } from 'notistack';
3+
4+
export const SnackbarDecorator = (Story: ComponentType, context: object) => {
5+
return (
6+
<SnackbarProvider maxSnack={10} autoHideDuration={3000}>
7+
<Story {...context} />
8+
</SnackbarProvider>
9+
);
10+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { CssBaseline, ThemeProvider } from '@mui/material';
2+
import type { ComponentType } from 'react';
3+
import { theme } from '../../src/lib/theme';
4+
5+
export const ThemeDecorator = (Story: ComponentType, context: object) => {
6+
return (
7+
<ThemeProvider theme={theme}>
8+
<CssBaseline />
9+
<Story {...context} />
10+
</ThemeProvider>
11+
);
12+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { StorybookConfig } from '@storybook/react-vite';
2+
3+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
4+
import { mergeConfig } from 'vite';
5+
6+
const config: StorybookConfig = {
7+
stories: ['../src/lib/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
8+
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions'],
9+
framework: {
10+
name: '@storybook/react-vite',
11+
options: {},
12+
},
13+
core: {
14+
disableTelemetry: true,
15+
},
16+
17+
viteFinal: async (config) =>
18+
mergeConfig(config, {
19+
plugins: [nxViteTsPaths()],
20+
}),
21+
};
22+
23+
export default config;
24+
25+
// To customize your Vite configuration you can use the viteFinal field.
26+
// Check https://storybook.js.org/docs/react/builders/vite#configuration
27+
// and https://nx.dev/recipes/storybook/custom-builder-configs
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { Preview } from '@storybook/react';
2+
import { ContentDecorator } from './decorators/Content.decorator';
3+
import { ThemeDecorator } from './decorators/Theme.decorator';
4+
import { SnackbarDecorator } from './decorators/SnackbarDecorator';
5+
6+
const preview: Preview = {
7+
decorators: [ThemeDecorator, ContentDecorator, SnackbarDecorator],
8+
globals: {
9+
backgrounds: '#333',
10+
},
11+
parameters: {
12+
layout: 'fullscreen',
13+
controls: {
14+
expanded: true,
15+
sort: 'requiredFirst',
16+
matchers: {
17+
color: /(background|color)$/i,
18+
date: /Date$/,
19+
},
20+
},
21+
},
22+
};
23+
24+
export default preview;

libs/storybook-host/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# storybook-host
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Running unit tests
6+
7+
Run `nx test storybook-host` to execute the unit tests via [Jest](https://jestjs.io).

libs/storybook-host/project.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "storybook-host",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/storybook-host/src",
5+
"projectType": "library",
6+
"tags": [],
7+
"targets": {
8+
"lint": {
9+
"executor": "@nx/eslint:lint"
10+
},
11+
"storybook": {
12+
"executor": "@nx/storybook:storybook",
13+
"options": {
14+
"port": 4400,
15+
"configDir": "libs/storybook-host/.storybook"
16+
},
17+
"configurations": {
18+
"ci": {
19+
"quiet": true
20+
}
21+
}
22+
},
23+
"build-storybook": {
24+
"executor": "@nx/storybook:build",
25+
"outputs": ["{options.outputDir}"],
26+
"options": {
27+
"outputDir": "dist/storybook/storybook-host",
28+
"configDir": "libs/storybook-host/.storybook"
29+
},
30+
"configurations": {
31+
"ci": {
32+
"quiet": true
33+
}
34+
}
35+
},
36+
"test-storybook": {
37+
"executor": "nx:run-commands",
38+
"options": {
39+
"command": "test-storybook -c libs/storybook-host/.storybook --url=http://localhost:4400"
40+
}
41+
},
42+
"static-storybook": {
43+
"executor": "@nx/web:file-server",
44+
"options": {
45+
"buildTarget": "storybook-host:build-storybook",
46+
"staticFilePath": "dist/storybook/storybook-host",
47+
"spa": true
48+
},
49+
"configurations": {
50+
"ci": {
51+
"buildTarget": "storybook-host:build-storybook:ci"
52+
}
53+
}
54+
}
55+
}
56+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import type { StoryObj, StoryFn, Meta } from '@storybook/react';
2+
import { LongPressButton } from './LongPressButton';
3+
import { LongPressEventType } from 'use-long-press';
4+
5+
const meta: Meta<typeof LongPressButton> = { component: LongPressButton };
6+
export default meta;
7+
8+
type Story = StoryObj<typeof LongPressButton>;
9+
type StoryComponent = StoryFn<typeof LongPressButton>;
10+
11+
export const Default: Story = {
12+
argTypes: {
13+
filterEvents: {
14+
control: false,
15+
table: {
16+
disable: true,
17+
},
18+
},
19+
context: {
20+
control: 'object',
21+
},
22+
cancelOnMovement: {
23+
control: 'boolean',
24+
},
25+
detect: {
26+
options: [LongPressEventType.Mouse, LongPressEventType.Touch, LongPressEventType.Pointer],
27+
control: 'radio',
28+
},
29+
},
30+
args: {
31+
threshold: 1000,
32+
},
33+
};
34+
35+
export const CancelOnMovement: Story = {
36+
...Default,
37+
argTypes: {
38+
...Default.argTypes,
39+
cancelOnMovement: {
40+
control: {
41+
type: 'number',
42+
},
43+
},
44+
},
45+
args: {
46+
...Default.args,
47+
cancelOnMovement: 25,
48+
},
49+
};
50+
51+
export const NoCancelOutsideElement: Story = {
52+
...Default,
53+
args: {
54+
...Default.args,
55+
cancelOutsideElement: false,
56+
},
57+
};
58+
59+
export const FilterRightClick: Story = {
60+
...Default,
61+
argTypes: {
62+
...Default.argTypes,
63+
filterEvents: {
64+
control: false,
65+
},
66+
},
67+
args: {
68+
...Default.args,
69+
filterEvents(event) {
70+
// Filter right clicks
71+
return !(
72+
event.nativeEvent instanceof MouseEvent &&
73+
(event.nativeEvent.which === 3 || event.nativeEvent.button === 2 || event.ctrlKey || event.metaKey)
74+
);
75+
},
76+
},
77+
};
78+
79+
export const WithContext: Story = {
80+
...Default,
81+
args: {
82+
...Default.args,
83+
context: 'Example context',
84+
},
85+
};

0 commit comments

Comments
 (0)