From 2ef6b5468aebfbd4af76657b5222513a6199309e Mon Sep 17 00:00:00 2001 From: Robbert Broersma Date: Sun, 8 Oct 2023 09:48:39 +0200 Subject: [PATCH] fix: ensure `hidden` attribute still works for every HTML component --- components/button/html/_mixin.scss | 4 ++ components/code-block/html/_mixin.scss | 4 ++ components/form-fieldset/css/_reset.scss | 1 + components/form-fieldset/html/_mixin.scss | 8 ++++ .../storybook-html/src/Article.stories.tsx | 47 ++++++++++++++----- .../storybook-html/src/Blockquote.stories.tsx | 22 ++++++++- .../storybook-html/src/Button.stories.tsx | 22 ++++++++- .../storybook-html/src/Checkbox.stories.tsx | 36 +++++++++++++- packages/storybook-html/src/Code.stories.tsx | 22 ++++++++- .../storybook-html/src/CodeBlock.stories.tsx | 24 ++++++++-- .../storybook-html/src/Document.stories.tsx | 31 ++++++++++-- .../storybook-html/src/Emphasis.stories.tsx | 22 ++++++++- .../src/FormFieldset.stories.tsx | 27 +++++++++-- .../storybook-html/src/FormLabel.stories.tsx | 30 ++++++++++-- .../storybook-html/src/Heading1.stories.tsx | 22 ++++++++- .../storybook-html/src/Heading2.stories.tsx | 22 ++++++++- .../storybook-html/src/Heading3.stories.tsx | 22 ++++++++- .../storybook-html/src/Heading4.stories.tsx | 22 ++++++++- .../storybook-html/src/Heading5.stories.tsx | 22 ++++++++- .../storybook-html/src/Heading6.stories.tsx | 22 ++++++++- packages/storybook-html/src/Link.stories.tsx | 30 +++++++++++- packages/storybook-html/src/Mark.stories.tsx | 22 ++++++++- .../src/OrderedList.stories.tsx | 30 ++++++++++-- .../storybook-html/src/Paragraph.stories.tsx | 31 ++++++++++-- .../src/RadioButton.stories.tsx | 34 +++++++++++--- .../storybook-html/src/Select.stories.tsx | 44 +++++++++++++++-- .../storybook-html/src/Separator.stories.tsx | 28 +++++++++-- .../storybook-html/src/Strong.stories.tsx | 22 ++++++++- packages/storybook-html/src/Table.stories.tsx | 22 ++++++++- .../storybook-html/src/Textarea.stories.tsx | 45 +++++++++++++++--- .../storybook-html/src/Textbox.stories.tsx | 45 +++++++++++++----- .../src/UnorderedList.stories.tsx | 38 +++++++++++++-- packages/storybook-html/src/_hidden.md | 4 ++ .../storybook-html/src/util/htmlArgTypes.ts | 17 +++++++ 34 files changed, 743 insertions(+), 101 deletions(-) create mode 100644 packages/storybook-html/src/_hidden.md create mode 100644 packages/storybook-html/src/util/htmlArgTypes.ts diff --git a/components/button/html/_mixin.scss b/components/button/html/_mixin.scss index 0fd84a917d1..09ee4196960 100644 --- a/components/button/html/_mixin.scss +++ b/components/button/html/_mixin.scss @@ -14,6 +14,10 @@ @include utrecht-button--distanced; } + button[hidden] { + display: none; + } + button[type="submit" i], input[type="submit" i] { @include utrecht-button--submit; diff --git a/components/code-block/html/_mixin.scss b/components/code-block/html/_mixin.scss index e81ff7524e3..a80fc38575c 100644 --- a/components/code-block/html/_mixin.scss +++ b/components/code-block/html/_mixin.scss @@ -11,6 +11,10 @@ @include utrecht-code-block; } + pre[hidden]:has(> code:only-child) { + display: none; + } + pre:has(> code:only-child) > code { display: contents; } diff --git a/components/form-fieldset/css/_reset.scss b/components/form-fieldset/css/_reset.scss index 189902d6ad8..fef7ccf07ed 100644 --- a/components/form-fieldset/css/_reset.scss +++ b/components/form-fieldset/css/_reset.scss @@ -4,6 +4,7 @@ */ @mixin reset-fieldset { + /* `all: revert` unfortunately has as side-effect that the `hidde` attribute has no effect */ all: revert; border: 0; margin-inline-end: 0; diff --git a/components/form-fieldset/html/_mixin.scss b/components/form-fieldset/html/_mixin.scss index 74928da2b0b..24e7cbd3df5 100644 --- a/components/form-fieldset/html/_mixin.scss +++ b/components/form-fieldset/html/_mixin.scss @@ -11,6 +11,10 @@ @include utrecht-form-fieldset--html-fieldset; @include utrecht-form-fieldset--distanced; } + + fieldset[hidden] { + display: none; + } } @mixin utrecht-html-legend { @@ -20,6 +24,10 @@ @include utrecht-form-fieldset__legend--distanced; } + legend[hidden] { + display: none; + } + fieldset:disabled > legend { @include utrecht-form-fieldset__legend--disabled; } diff --git a/packages/storybook-html/src/Article.stories.tsx b/packages/storybook-html/src/Article.stories.tsx index b815f8080e2..97b3c14d705 100644 --- a/packages/storybook-html/src/Article.stories.tsx +++ b/packages/storybook-html/src/Article.stories.tsx @@ -4,11 +4,15 @@ import type { Meta, StoryObj } from '@storybook/react'; import readme from '@utrecht/components/article/README.md?raw'; import tokensDefinition from '@utrecht/components/article/tokens.json'; import tokens from '@utrecht/design-tokens/dist/index.json'; -import React from 'react'; +import React, { HTMLAttributes, PropsWithChildren } from 'react'; +import hiddenDocs from './_hidden.md?raw'; import { htmlContentDecorator } from './decorator'; import { designTokenStory } from './design-token-story'; +import { hidden } from './util/htmlArgTypes'; -const Article = ({ children }) =>
{children}
; +const Article = ({ children, ...restProps }: PropsWithChildren>) => ( +
{children}
+); const meta = { title: 'HTML Component/Article', @@ -19,18 +23,11 @@ const meta = { children: { description: 'Content of the article', }, + hidden, }, args: { - children: [ -

Lorem ipsum

, -

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore - magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo - consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla - pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est - laborum. -

, - ], + children: '', + hidden: false, }, tags: ['autodocs'], parameters: { @@ -53,6 +50,18 @@ export default meta; type Story = StoryObj; export const Default: Story = { + args: { + children: [ +

Lorem ipsum

, +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore + magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo + consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla + pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est + laborum. +

, + ], + }, parameters: { docs: { description: { @@ -62,4 +71,18 @@ export const Default: Story = { }, }; +export const Hidden: Story = { + args: { + ...Default.args, + hidden: true, + }, + parameters: { + docs: { + description: { + story: hiddenDocs, + }, + }, + }, +}; + export const DesignTokens = designTokenStory(meta); diff --git a/packages/storybook-html/src/Blockquote.stories.tsx b/packages/storybook-html/src/Blockquote.stories.tsx index b85cac33cb6..93cf48c01a6 100644 --- a/packages/storybook-html/src/Blockquote.stories.tsx +++ b/packages/storybook-html/src/Blockquote.stories.tsx @@ -4,11 +4,13 @@ import type { Meta, StoryObj } from '@storybook/react'; import readme from '@utrecht/components/blockquote/README.md?raw'; import tokensDefinition from '@utrecht/components/blockquote/tokens.json'; import tokens from '@utrecht/design-tokens/dist/index.json'; -import React from 'react'; +import React, { HTMLAttributes, PropsWithChildren } from 'react'; +import hiddenDocs from './_hidden.md?raw'; import { htmlContentDecorator } from './decorator'; import { designTokenStory } from './design-token-story'; +import { hidden } from './util/htmlArgTypes'; -const Blockquote = ({ children }) =>
{children}
; +const Blockquote = ({ ...restProps }: PropsWithChildren>) =>
; const meta = { title: 'HTML Component/Blockquote', @@ -19,9 +21,11 @@ const meta = { children: { description: 'Content of the quote', }, + hidden, }, args: { children: [], + hidden: false, }, tags: ['autodocs'], parameters: { @@ -64,4 +68,18 @@ export const Default: Story = { }, }; +export const Hidden: Story = { + args: { + ...Default.args, + hidden: true, + }, + parameters: { + docs: { + description: { + story: hiddenDocs, + }, + }, + }, +}; + export const DesignTokens = designTokenStory(meta); diff --git a/packages/storybook-html/src/Button.stories.tsx b/packages/storybook-html/src/Button.stories.tsx index ecfc4e73ff6..ff220ea1d9d 100644 --- a/packages/storybook-html/src/Button.stories.tsx +++ b/packages/storybook-html/src/Button.stories.tsx @@ -4,12 +4,14 @@ import type { Meta, StoryObj } from '@storybook/react'; import readme from '@utrecht/components/button/README.md?raw'; import tokensDefinition from '@utrecht/components/button/tokens.json'; import tokens from '@utrecht/design-tokens/dist/index.json'; -import React from 'react'; +import React, { HTMLAttributes, PropsWithChildren } from 'react'; import buttonDisabledTabindexMarkdown from './_button-disabled-tabindex.md?raw'; +import hiddenDocs from './_hidden.md?raw'; import { htmlContentDecorator } from './decorator'; import { designTokenStory } from './design-token-story'; +import { hidden } from './util/htmlArgTypes'; -const Button = ({ children, ...attributes }) => ; +const Button = ({ ...attributes }: PropsWithChildren>) =>