Skip to content

Commit

Permalink
Merge pull request #803 from open-formulieren/chore/445-upgrade-utrec…
Browse files Browse the repository at this point in the history
…ht-components

Upgrade to @utrecht/components v7
  • Loading branch information
sergei-maertens authored Mar 6, 2025
2 parents 3426375 + 496e97f commit 19fc530
Show file tree
Hide file tree
Showing 55 changed files with 136 additions and 190 deletions.
24 changes: 15 additions & 9 deletions .storybook/decorators.jsx → .storybook/decorators.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type {Decorator} from '@storybook/react';
import {Document} from '@utrecht/component-library-react';

/**
* Storybook does not have a before/after cleanup cycle, and localStorage would in
* these situations break story/test isolation.
*
* This decorator is applied to every story to reset the storage state.
*/
export const withClearSessionStorage = Story => {
export const withClearSessionStorage: Decorator = Story => {
window.sessionStorage.clear();
return <Story />;
};
Expand All @@ -17,7 +20,7 @@ export const withClearSessionStorage = Story => {
* 'e450890a-4166-410e-8d64-0a54ad30ba01'. You can specify another key via parameters
* or args.
*/
export const withClearSubmissionLocalStorage = (Story, {args, parameters}) => {
export const withClearSubmissionLocalStorage: Decorator = (Story, {args, parameters}) => {
const formId =
args?.formId ?? parameters?.localStorage?.formId ?? 'e450890a-4166-410e-8d64-0a54ad30ba01';
window.localStorage.removeItem(formId);
Expand All @@ -28,10 +31,13 @@ export const withClearSubmissionLocalStorage = (Story, {args, parameters}) => {
* This decorator wraps stories so that they are inside a container with the class name "utrecht-document". This is
* needed so that components inherit the right font.
*/
export const utrechtDocumentDecorator = Story => {
return (
<div className="utrecht-document utrecht-document--surface">
<Story />
</div>
);
};
export const withUtrechtDocument: Decorator = (Story, {parameters}) => (
<Document
className="utrecht-document--surface"
style={{
'--utrecht-space-around': parameters?.utrechtDocument?.spaceAround ?? 0,
}}
>
<Story />
</Document>
);
1 change: 1 addition & 0 deletions .storybook/main.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {StorybookConfig} from '@storybook/react-vite';
const config: StorybookConfig = {
core: {
disableTelemetry: true,
disableWhatsNewNotifications: true,
},
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
Expand Down
4 changes: 2 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import OFLibrary from 'formio/templates';
import {withModalDecorator} from 'story-utils/decorators';

import {
utrechtDocumentDecorator,
withClearSessionStorage,
withClearSubmissionLocalStorage,
withUtrechtDocument,
} from './decorators';
import {allModes} from './modes.mjs';
import {reactIntl} from './reactIntl.mjs';
Expand Down Expand Up @@ -53,7 +53,7 @@ export default {
withClearSessionStorage,
withClearSubmissionLocalStorage,
withModalDecorator,
utrechtDocumentDecorator,
withUtrechtDocument,
],
parameters: {
viewport: {
Expand Down
32 changes: 20 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"@floating-ui/react": "^0.27.5",
"@formio/protected-eval": "^1.2.1",
"@fortawesome/fontawesome-free": "^6.4.0",
"@open-formulieren/design-tokens": "^0.55.0",
"@open-formulieren/formio-renderer": "^0.2.0",
"@open-formulieren/design-tokens": "^0.57.0",
"@open-formulieren/formio-renderer": "^0.3.0",
"@open-formulieren/formiojs": "^4.13.14",
"@open-formulieren/leaflet-tools": "^1.0.0",
"@sentry/react": "^8.50.0",
Expand Down Expand Up @@ -127,7 +127,7 @@
"@types/react-dom": "^18.3.5",
"@typescript-eslint/parser": "^8.26.0",
"@utrecht/component-library-react": "1.0.0-alpha.353",
"@utrecht/components": "1.0.0-alpha.565",
"@utrecht/components": "^7.4.0",
"@utrecht/design-tokens": "^2.5.0",
"@vitejs/plugin-react": "^4.3.4",
"@vitest/coverage-istanbul": "^3.0.7",
Expand Down
12 changes: 6 additions & 6 deletions src/components/appointments/fields/LocationSelect.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export const MultipleCandidates = {
const canvas = within(canvasElement);
await expect(canvas.queryByText('Open Gem')).not.toBeInTheDocument();
const dropdown = canvas.getByLabelText('Locatie');
await userEvent.click(dropdown);
dropdown.focus();
await userEvent.keyboard('[ArrowDown]');
await expect(await canvas.findByText('Open Gem')).toBeVisible();
await expect(await canvas.findByText('Bahamas')).toBeVisible();
expect(await canvas.findByRole('option', {name: 'Open Gem'})).toBeVisible();
expect(await canvas.findByRole('option', {name: 'Bahamas'})).toBeVisible();
},
};

Expand All @@ -52,7 +52,7 @@ export const SingleCandidate = {
await expect(canvas.queryByText('Bahamas')).not.toBeInTheDocument();

const dropdown = canvas.getByLabelText('Locatie');
await userEvent.click(dropdown);
dropdown.focus();
await userEvent.keyboard('[ArrowDown]');

// wait for locations to be loaded
Expand All @@ -61,8 +61,8 @@ export const SingleCandidate = {
expect(textNodes.length).toBeGreaterThan(0);
});

await expect(canvas.queryByText('Bahamas')).not.toBeInTheDocument();
expect(canvas.queryByText('Bahamas')).not.toBeInTheDocument();
await userEvent.keyboard('[Escape]');
await expect(await canvas.findByText('Open Gem')).toBeVisible();
expect(await canvas.findByText('Open Gem')).toBeVisible();
},
};
4 changes: 2 additions & 2 deletions src/formio/components/AddressNL.stories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect, userEvent, waitFor, within} from '@storybook/test';

import {ConfigDecorator, withUtrechtDocument} from 'story-utils/decorators';
import {ConfigDecorator} from 'story-utils/decorators';

import {
mockBAGDataGet,
Expand All @@ -12,7 +12,7 @@ import {SingleFormioComponent} from './story-util';

export default {
title: 'Form.io components / Custom / Address NL',
decorators: [withUtrechtDocument, ConfigDecorator],
decorators: [ConfigDecorator],
args: {
type: 'addressNL',
key: 'addressNL',
Expand Down
3 changes: 0 additions & 3 deletions src/formio/components/BsnField.stories.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {withUtrechtDocument} from 'story-utils/decorators';

import {SingleFormioComponent} from './story-util';

export default {
title: 'Form.io components / Custom / BSNField',
decorators: [withUtrechtDocument],
args: {
type: 'bsn',
extraComponentProperties: {},
Expand Down
2 changes: 1 addition & 1 deletion src/formio/components/Checkbox.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@use 'microscope-sass/lib/bem';

@import '@utrecht/components/dist/custom-checkbox/css/index.css';
@import '@utrecht/components/custom-checkbox/';

// Design tokens: see src/components/checkbox-field.tokens.json

Expand Down
3 changes: 0 additions & 3 deletions src/formio/components/Checkbox.stories.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {withUtrechtDocument} from 'story-utils/decorators';

import {SingleFormioComponent} from './story-util';

export default {
title: 'Form.io components / Vanilla / Checkbox',
decorators: [withUtrechtDocument],
args: {
type: 'checkbox',
extraComponentProperties: {},
Expand Down
3 changes: 0 additions & 3 deletions src/formio/components/Columns.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {withUtrechtDocument} from 'story-utils/decorators';

import {MultipleFormioComponents, SingleFormioComponent} from './story-util';

export default {
title: 'Form.io components / Vanilla / Columns',
decorators: [withUtrechtDocument],
args: {
evalContext: {},
},
Expand Down
3 changes: 0 additions & 3 deletions src/formio/components/Content.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {withUtrechtDocument} from 'story-utils/decorators';

import {SingleFormioComponent} from './story-util';

export default {
title: 'Form.io components / Vanilla / Content',
decorators: [withUtrechtDocument],
args: {
type: 'content',
extraComponentProperties: {},
Expand Down
3 changes: 0 additions & 3 deletions src/formio/components/Cosign.stories.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {withUtrechtDocument} from 'story-utils/decorators';

import {SingleFormioComponent} from './story-util';

export default {
title: 'Form.io components / Custom / Cosign',
decorators: [withUtrechtDocument],
args: {
key: 'cosign',
type: 'cosign',
Expand Down
3 changes: 0 additions & 3 deletions src/formio/components/Currency.stories.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {withUtrechtDocument} from 'story-utils/decorators';

import {SingleFormioComponent} from './story-util';

export default {
title: 'Form.io components / Vanilla / Currency',
decorators: [withUtrechtDocument],
args: {
type: 'currency',
extraComponentProperties: {
Expand Down
2 changes: 0 additions & 2 deletions src/formio/components/DateField.stories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {expect, userEvent, within} from '@storybook/test';

import {withUtrechtDocument} from 'story-utils/decorators';
import {sleep} from 'utils';

import {SingleFormioComponent} from './story-util';
Expand All @@ -24,7 +23,6 @@ const waitForFlatpickr = async node => {

export default {
title: 'Form.io components / Custom / DateField',
decorators: [withUtrechtDocument],
args: {
type: 'date',
extraComponentProperties: {
Expand Down
3 changes: 0 additions & 3 deletions src/formio/components/DateTimeField.stories.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {withUtrechtDocument} from 'story-utils/decorators';

import {SingleFormioComponent} from './story-util';

export default {
title: 'Form.io components / Vanilla / DateTimeField',
decorators: [withUtrechtDocument],
args: {
type: 'datetime',
extraComponentProperties: {
Expand Down
3 changes: 1 addition & 2 deletions src/formio/components/EditGrid.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect, userEvent, waitFor, within} from '@storybook/test';

import {ConfigDecorator, withUtrechtDocument} from 'story-utils/decorators';
import {ConfigDecorator} from 'story-utils/decorators';
import {sleep} from 'utils';

import {mockBAGDataGet, mockBAGNoDataGet} from './AddressNL.mocks';
Expand Down Expand Up @@ -40,7 +40,6 @@ const defaultNested = [

export default {
title: 'Form.io components / Vanilla / EditGrid (Repeating group)',
decorators: [withUtrechtDocument],
args: {
type: 'editgrid',
groupLabel: '',
Expand Down
3 changes: 0 additions & 3 deletions src/formio/components/Email.stories.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {fn} from '@storybook/test';

import {withUtrechtDocument} from 'story-utils/decorators';

import {SingleFormioComponent} from './story-util';

export default {
title: 'Form.io components / Vanilla / Email',
decorators: [withUtrechtDocument],
args: {
type: 'email',
extraComponentProperties: {},
Expand Down
3 changes: 0 additions & 3 deletions src/formio/components/Fieldset.stories.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {withUtrechtDocument} from 'story-utils/decorators';

import {SingleFormioComponent} from './story-util';

export default {
title: 'Form.io components / Vanilla / Fieldset',
decorators: [withUtrechtDocument],
args: {
type: 'fieldset',
extraComponentProperties: {
Expand Down
2 changes: 0 additions & 2 deletions src/formio/components/FileField.stories.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {expect, userEvent, within} from '@storybook/test';
import {getWorker} from 'msw-storybook-addon';

import {withUtrechtDocument} from 'story-utils/decorators';
import {sleep} from 'utils';

import {
Expand Down Expand Up @@ -38,7 +37,6 @@ const MIME_TO_LABEL = {

export default {
title: 'Form.io components / Vanilla / FileUpload',
decorators: [withUtrechtDocument],
args: {
type: 'file',
extraComponentProperties: {},
Expand Down
3 changes: 0 additions & 3 deletions src/formio/components/IBANField.stories.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {withUtrechtDocument} from 'story-utils/decorators';

import {SingleFormioComponent} from './story-util';

export default {
title: 'Form.io components / Custom / IBANField',
decorators: [withUtrechtDocument],
args: {
type: 'iban',
extraComponentProperties: {},
Expand Down
3 changes: 0 additions & 3 deletions src/formio/components/LicensePlateField.stories.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {withUtrechtDocument} from 'story-utils/decorators';

import {SingleFormioComponent} from './story-util';

export default {
title: 'Form.io components / Custom / LicensePlateField',
decorators: [withUtrechtDocument],
args: {
type: 'licenseplate',
extraComponentProperties: {},
Expand Down
Loading

0 comments on commit 19fc530

Please sign in to comment.