Skip to content

Commit

Permalink
Merge pull request #541 from Concordium/fix-storybook
Browse files Browse the repository at this point in the history
Update storybook + migrate config
  • Loading branch information
soerenbf authored Oct 17, 2024
2 parents 4d6dced + b58e827 commit 72f43fb
Show file tree
Hide file tree
Showing 26 changed files with 3,008 additions and 7,027 deletions.
44 changes: 29 additions & 15 deletions packages/browser-wallet/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { dirname, join } from 'path';
/* eslint-disable import/no-extraneous-dependencies, @typescript-eslint/no-var-requires, no-param-reassign */
const path = require('path');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

const pathToSvgAssets = path.resolve(__dirname, '../src/assets/svg');

module.exports = {
core: {
builder: {
name: 'webpack5',
// options: {
// lazyCompilation: true,
// fsCache: true,
// },
},
},
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],

addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'@storybook/preset-scss',
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-interactions'),
getAbsolutePath('@storybook/preset-scss'),
getAbsolutePath('@storybook/addon-webpack5-compiler-swc'),
],
framework: '@storybook/react',

framework: {
name: getAbsolutePath('@storybook/react-webpack5'),
options: {},
},

core: {
disableTelemetry: true,
},

webpackFinal: async (config) => {
const { rules } = config.module;

Expand All @@ -38,10 +41,21 @@ module.exports = {

return config;
},

babel: async (options) => {
return {
...options,
plugins: options.plugins.filter((x) => !(typeof x === 'string' && x.includes('plugin-transform-classes'))),
};
},

docs: {},

typescript: {
reactDocgen: 'react-docgen-typescript',
},
};

function getAbsolutePath(value) {
return dirname(require.resolve(join(value, 'package.json')));
}
2 changes: 1 addition & 1 deletion packages/browser-wallet/.storybook/preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const themeDecorator = (Story, { globals, parameters }) => {
};

export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
Expand All @@ -41,3 +40,4 @@ export const parameters = {
};

export const decorators = [themeDecorator];
export const tags = ['autodocs'];
24 changes: 12 additions & 12 deletions packages/browser-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"build": "yarn build:prod",
"test": "jest",
"watch": "cross-env WATCH=1 yarn build:dev",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"browser": {
"stream": "readable-stream"
Expand Down Expand Up @@ -59,16 +59,16 @@
"@babel/core": "^7.18.2",
"@craftamap/esbuild-plugin-html": "^0.4.0",
"@mdx-js/react": "^1.6.22",
"@storybook/addon-actions": "^6.5.7",
"@storybook/addon-docs": "^6.5.7",
"@storybook/addon-essentials": "^6.5.7",
"@storybook/addon-interactions": "^6.5.7",
"@storybook/addon-links": "^6.5.7",
"@storybook/builder-webpack5": "^6.5.7",
"@storybook/manager-webpack5": "^6.5.7",
"@storybook/addon-actions": "^8.3.5",
"@storybook/addon-docs": "^8.3.5",
"@storybook/addon-essentials": "^8.3.5",
"@storybook/addon-interactions": "^8.3.5",
"@storybook/addon-links": "^8.3.5",
"@storybook/addon-webpack5-compiler-swc": "^1.0.5",
"@storybook/preset-scss": "^1.0.3",
"@storybook/react": "^6.5.7",
"@storybook/testing-library": "^0.0.11",
"@storybook/react": "^8.3.5",
"@storybook/react-webpack5": "^8.3.5",
"@storybook/test": "^8.3.5",
"@svgr/webpack": "^6.2.1",
"@types/chrome": "^0.0.247",
"@types/lodash.debounce": "^4.0.7",
Expand All @@ -89,7 +89,7 @@
"jest-chrome": "^0.8.0",
"sass": "^1.52.2",
"sass-loader": "^13.0.0",
"storybook": "^6.5.7",
"storybook": "^8.3.5",
"style-loader": "^3.3.1",
"ts-jest": "^29.0.5",
"tsconfig-paths-webpack-plugin": "^3.5.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
/* eslint-disable react/function-component-definition */
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { Meta, StoryObj } from '@storybook/react';
import clsx from 'clsx';
import EntityList from './EntityList';

export default {
title: 'Page layouts/MainLayout/EntityList',
component: EntityList,
} as ComponentMeta<typeof EntityList>;
} as Meta<typeof EntityList>;

type Entity = { id: number; text: string };

const Template: ComponentStory<typeof EntityList> = (args) => {
return (
<div style={{ width: 300 }}>
<style>
{`
const entities: Entity[] = ['First', 'Second', 'Third'].map((e, i) => ({ id: i, text: e }));
export const Primary: StoryObj<typeof EntityList> = {
args: {
entities,
children: (e: Entity, checked) => (
<div className={clsx('sb-entity-list-item', checked && 'sb-entity-list-item--checked')}>{e.text}</div>
),
getKey: (e: Entity) => e.id,
searchableKeys: ['text'],
newText: 'Add new',
},
render: (args) => {
return (
<div style={{ width: 300 }}>
<style>
{`
.sb-entity-list-item {
padding: 0 0.3rem;
}
Expand All @@ -24,22 +35,10 @@ const Template: ComponentStory<typeof EntityList> = (args) => {
margin-left: 0.5rem;
}
`}
</style>
{/* eslint-disable-next-line no-console */}
<EntityList {...args} onSelect={console.log} />
</div>
);
};

const entities: Entity[] = ['First', 'Second', 'Third'].map((e, i) => ({ id: i, text: e }));

export const Primary = Template.bind({});
Primary.args = {
entities,
children: (e: Entity, checked) => (
<div className={clsx('sb-entity-list-item', checked && 'sb-entity-list-item--checked')}>{e.text}</div>
),
getKey: (e: Entity) => e.id,
searchableKeys: ['text'],
newText: 'Add new',
</style>
{/* eslint-disable-next-line no-console */}
<EntityList {...args} onSelect={console.log} />
</div>
);
},
};
Original file line number Diff line number Diff line change
@@ -1,59 +1,66 @@
/* eslint-disable react/function-component-definition */
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { Meta, StoryObj } from '@storybook/react';
import { DisplayStatementView } from './DisplayStatement';

export default {
title: 'Pages/IdProofRequest/DisplayStatement',
component: DisplayStatementView,
} as ComponentMeta<typeof DisplayStatementView>;
} as Meta<typeof DisplayStatementView>;

const Template: ComponentStory<typeof DisplayStatementView> = (args) => {
type Story = StoryObj<typeof DisplayStatementView>;

const render: Story['render'] = (args) => {
return (
<div style={{ width: 330 }}>
<DisplayStatementView className="w-full" {...args} />
</div>
);
};

export const ValidRevealAttributes = Template.bind({});
ValidRevealAttributes.args = {
dappName: 'Test dApp',
header: 'Information to reveal',
reveal: true,
lines: [
{ attribute: 'First name', value: 'John', isRequirementMet: true },
{ attribute: 'Last name', value: 'Johnson', isRequirementMet: true },
],
export const ValidRevealAttributes: Story = {
args: {
dappName: 'Test dApp',
header: 'Information to reveal',
reveal: true,
lines: [
{ attribute: 'First name', value: 'John', isRequirementMet: true },
{ attribute: 'Last name', value: 'Johnson', isRequirementMet: true },
],
},
render,
};

export const InvalidRevealAttributes = Template.bind({});
InvalidRevealAttributes.args = {
dappName: 'Test dApp',
header: 'Information to reveal',
reveal: true,
lines: [
{ attribute: 'First name', value: 'John', isRequirementMet: true },
{ attribute: 'Last name', value: 'Johnson', isRequirementMet: true },
{ attribute: 'ID document type', value: 'Passport', isRequirementMet: false },
],
export const InvalidRevealAttributes: Story = {
args: {
dappName: 'Test dApp',
header: 'Information to reveal',
reveal: true,
lines: [
{ attribute: 'First name', value: 'John', isRequirementMet: true },
{ attribute: 'Last name', value: 'Johnson', isRequirementMet: true },
{ attribute: 'ID document type', value: 'Passport', isRequirementMet: false },
],
},
render,
};

export const ValidSecretProof = Template.bind({});
ValidSecretProof.args = {
dappName: 'Test dApp',
header: 'Secret proof of age',
reveal: false,
description: 'You date of birth is before YYYY-MM-DD.',
lines: [{ attribute: 'Age', value: 'More than X years old', isRequirementMet: true }],
export const ValidSecretProof: Story = {
args: {
dappName: 'Test dApp',
header: 'Secret proof of age',
reveal: false,
description: 'You date of birth is before YYYY-MM-DD.',
lines: [{ attribute: 'Age', value: 'More than X years old', isRequirementMet: true }],
},
render,
};

export const InvalidSecretProof = Template.bind({});
InvalidSecretProof.args = {
dappName: 'Test dApp',
header: 'Secret proof of identity document issuer',
reveal: false,
description:
'Your identity document issuer is one of the following:\nAndorra, United Arab Emirates, Afghanistan, Antigua and Barbuda, Anguilla, Albania, Benin, Brazil, Bahamas, Bhutan, Belize, Canada, Chile, Spain, Finland, Fiji, Ghana, Hong Kong, Indonesia, Korea, Mali, Malta, Malawi, Mexico, Mozambique, Namibia, Nigeria, Nicaragua, Panama, Peru',
lines: [{ attribute: 'Document issuer', value: '1 of 30 issuers', isRequirementMet: false }],
export const InvalidSecretProof: Story = {
args: {
dappName: 'Test dApp',
header: 'Secret proof of identity document issuer',
reveal: false,
description:
'Your identity document issuer is one of the following:\nAndorra, United Arab Emirates, Afghanistan, Antigua and Barbuda, Anguilla, Albania, Benin, Brazil, Bahamas, Bhutan, Belize, Canada, Chile, Spain, Finland, Fiji, Ghana, Hong Kong, Indonesia, Korea, Mali, Malta, Malawi, Mexico, Mozambique, Namibia, Nigeria, Nicaragua, Panama, Peru',
lines: [{ attribute: 'Document issuer', value: '1 of 30 issuers', isRequirementMet: false }],
},
render,
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable react/function-component-definition, react/destructuring-assignment */
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { Meta, StoryObj } from '@storybook/react';
import { VerifiableCredentialStatus, VerifiableCredentialSchema } from '@shared/storage/types';
import { VerifiableCredentialMetadata } from '@shared/utils/verifiable-credential-helpers';
import { VerifiableCredentialCard } from './VerifiableCredentialCard';

export default {
title: 'VerifiableCredential/VerifiableCredentialCard',
component: VerifiableCredentialCard,
} as ComponentMeta<typeof VerifiableCredentialCard>;
} as Meta<typeof VerifiableCredentialCard>;

const schema: VerifiableCredentialSchema = {
$id: 'https://example-university.com/certificates/JsonSchema2023-education-certificate.json',
Expand Down Expand Up @@ -83,15 +83,17 @@ const credentialSubject = {
},
};

export const Primary: ComponentStory<typeof VerifiableCredentialCard> = () => {
return (
<div style={{ width: 375 }}>
<VerifiableCredentialCard
credentialSubject={credentialSubject}
schema={{ ...schema, usingFallback: false }}
credentialStatus={VerifiableCredentialStatus.Active}
metadata={metadata}
/>
</div>
);
export const Primary: StoryObj<typeof VerifiableCredentialCard> = {
render: () => {
return (
<div style={{ width: 375 }}>
<VerifiableCredentialCard
credentialSubject={credentialSubject}
schema={{ ...schema, usingFallback: false }}
credentialStatus={VerifiableCredentialStatus.Active}
metadata={metadata}
/>
</div>
);
},
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
/* eslint-disable react/function-component-definition */
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { MemoryRouter } from 'react-router-dom';
import { Meta, StoryObj } from '@storybook/react';

import BackButton from './BackButton';

export default {
title: 'Shared/BackButton',
component: BackButton,
} as ComponentMeta<typeof BackButton>;
} as Meta<typeof BackButton>;

export const Primary: ComponentStory<typeof BackButton> = () => {
return <BackButton />;
export const Primary: StoryObj<typeof BackButton> = {
render: () => (
<MemoryRouter>
<BackButton />
</MemoryRouter>
),
};
Loading

0 comments on commit 72f43fb

Please sign in to comment.