Skip to content

Commit 5854171

Browse files
I9527 storybook migration part4 (#305)
* pkp/pkp-lib#9527 Form fields migrated to storybook * pkp/pkp-lib#9527 Migrate ListPanel components to storybok * pkp/pkp-lib#9527 Page components migrated to storybook * pkp/pkp-lib#9527 Make initPageConfig as props for better documentation * pkp/pkp-lib#9527 Create defineComponentStore to hide implementation details for stores that needs to follow component lifecycle * pkp/pkp-lib#9527 Adjust size for modal to be screenshoted * pkp/pkp-lib#9527 Add margin to stories to properly see borders/shadows * pkp/pkp-lib#9527 Move global dialog to decorators * pkp/pkp-lib#9527 Tweak padding for better snapshoting * pkp/pkp-lib#9527 Adjust default view port to get full desktop layouts * pkp/pkp-lib#9527 Add rtl snapshoting * pkp/pkp-lib#9527 Activate rtl snapshots * pkp/pkp-lib#9527 using addons-themes for ltr/rtl, instead of dedicated addons to handle compatibility with modes * pkp/pkp-lib#9527 Apply rtl to storybook root to prevent breaking layout in some cases * pkp/pkp-lib#9527 reenable other decorators * pkp/pkp-lib#9527 Address RTL issues for 'screenreader only' styling, which was creating additional space * pkp/pkp-lib#9527 To cover modals/dialogs, move dir attribute to body * pkp/pkp-lib#9527 Same source of the truth for dir rtl/ltr * pkp/pkp-lib#9527 Adjust viewport to xl * pkp/pkp-lib#9527 fix composer rtl issue * pkp/pkp-lib#9527 Attempt to stabilize StatsPage data * pkp/pkp-lib#9527 stabilize table data * pkp/pkp-lib#9527 Trigger build to verify it has stable snapshots. * pkp/pkp-lib#9527 move components to the same category for now * pkp/pkp-lib#9527 Stabilize stats page for snapshots * pkp/pkp-lib#9527 migrate to msw2, add some useFetch tests * pkp/pkp-lib#9527 stabilize SelectReviewerListPanel stories
1 parent 779060f commit 5854171

File tree

242 files changed

+14527
-1309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+14527
-1309
lines changed

Diff for: .storybook/main.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
const config = {
33
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
44
addons: [
5-
'@storybook/addon-links',
6-
'@storybook/addon-essentials',
7-
'@storybook/addon-interactions',
8-
'storybook-addon-rtl',
9-
"@storybook/addon-mdx-gfm"
10-
],
5+
'@storybook/addon-links',
6+
'@storybook/addon-essentials',
7+
'@storybook/addon-interactions',
8+
'@storybook/addon-themes',
9+
'@storybook/addon-mdx-gfm',
10+
],
1111
framework: {
1212
name: '@storybook/vue3-vite',
1313
options: {},

Diff for: .storybook/modes.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const allModes = {
2+
desktop: {
3+
viewport: 'large',
4+
theme: 'ltr',
5+
},
6+
'desktop rtl': {
7+
viewport: 'large',
8+
theme: 'rtl',
9+
},
10+
// for snapshotting scrollable areas with all content, like modals
11+
desktopLargeHeight: {
12+
viewport: 'largeHeight',
13+
},
14+
};

Diff for: .storybook/preview.js

+65-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @type { import('@storybook/vue3').Preview } */
22

3+
import {withThemeByDataAttribute} from '@storybook/addon-themes';
34
import {setup} from '@storybook/vue3';
4-
55
import GlobalMixins from '@/mixins/global.js';
66
import emitter from 'tiny-emitter/instance';
77

@@ -20,19 +20,24 @@ import Tab from '@/components/Tabs/Tab.vue';
2020
import Tabs from '@/components/Tabs/Tabs.vue';
2121
import FloatingVue from 'floating-vue';
2222

23+
import PkpDialog from '@/components/Modal/Dialog.vue';
24+
import {useDialogStore} from '@/stores/dialogStore';
25+
26+
import VueScrollTo from 'vue-scrollto';
27+
2328
import '../src/styles/_import.less';
2429
import '../src/styles/_global.less';
25-
import {initializeRTL} from 'storybook-addon-rtl';
30+
import {allModes} from './modes';
2631
import {initialize, mswLoader} from 'msw-storybook-addon';
2732

2833
import {createPinia} from 'pinia';
2934

3035
const pinia = createPinia();
3136

32-
initializeRTL();
3337
// Initialize MSW
3438
initialize({
35-
onUnhandledRequest: ({method, url}) => {
39+
/** To be migrated to msw2 if neede */
40+
/*onUnhandledRequest: ({method, url}) => {
3641
if (url.pathname.includes('://mock/')) {
3742
console.error(`Unhandled ${method} request to ${url}.
3843
@@ -41,7 +46,7 @@ initialize({
4146
If you wish to mock an error response, please refer to this guide: https://mswjs.io/docs/recipes/mocking-error-responses
4247
`);
4348
}
44-
},
49+
},*/
4550
});
4651

4752
setup((app) => {
@@ -61,6 +66,8 @@ setup((app) => {
6166
},
6267
});
6368

69+
app.use(VueScrollTo);
70+
6471
app.component('Badge', Badge);
6572
app.component('Dropdown', Dropdown);
6673
app.component('Icon', Icon);
@@ -86,6 +93,43 @@ setup((app) => {
8693

8794
const preview = {
8895
loaders: [mswLoader],
96+
decorators: [
97+
withThemeByDataAttribute({
98+
themes: {
99+
ltr: 'ltr',
100+
rtl: 'rtl',
101+
},
102+
defaultTheme: 'ltr',
103+
}),
104+
(story, {globals}) => {
105+
/** withThemebyDataAttribute decorator applies attribute after render, which
106+
* is too late fort tinyMCE which needs to detect it on first render correctly
107+
*
108+
*/
109+
document.body.setAttribute('dir', globals.theme);
110+
return story();
111+
},
112+
(story) => ({
113+
components: {story},
114+
template: '<div style="padding: 10px;"><story /></div>',
115+
}),
116+
/** Globally Available Dialog */
117+
(story) => ({
118+
setup() {
119+
const dialogStore = useDialogStore();
120+
return {dialogStore};
121+
},
122+
components: {story, PkpDialog},
123+
template: `<div>
124+
<PkpDialog
125+
:open="dialogStore.dialogOpened"
126+
v-bind="dialogStore.dialogProps"
127+
@close="dialogStore.closeDialog"
128+
></PkpDialog>
129+
<story />
130+
</div>`,
131+
}),
132+
],
89133
parameters: {
90134
actions: {argTypesRegex: '^on[A-Z].*'},
91135
controls: {
@@ -104,12 +148,27 @@ const preview = {
104148
if (b.id.includes('introduction--docs')) {
105149
return 1;
106150
}
107-
108151
return a.id === b.id
109152
? 0
110153
: a.id.localeCompare(b.id, undefined, {numeric: true});
111154
},*/
112155
},
156+
viewport: {
157+
viewports: {
158+
large: {name: 'Large', styles: {width: '1280px', height: '1000px'}},
159+
/** For scrollable scenarios */
160+
largeHeight: {
161+
name: 'Large',
162+
styles: {width: '1024px', height: '1500px'},
163+
},
164+
},
165+
},
166+
chromatic: {
167+
modes: {
168+
desktop: allModes['desktop'],
169+
'desktop rtl': allModes['desktop rtl'],
170+
},
171+
},
113172
},
114173
};
115174

0 commit comments

Comments
 (0)