Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/lib/SectionMessage/SectionMessage.stories.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.container {
display: flex;
flex-direction: column;
gap: 1rem;
padding: 1rem;
}
Comment on lines +1 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not add these styles to the demo, because:

  1. The lack of space between messages shows clients what will happen by default if they stack multiple.
  2. Storybook already adds space to the <body> in the preview window (via .sb-main-padded). If we start doing it for every .container (or .root or whatever the element may be classed), then we give ourselves a chore to remain consistent.

screenshot without these styles


.message {
margin-bottom: 0;
}
Comment on lines +8 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this style is not necessary, because the margin-bottom: 0 is already present for <p> (default element) and inherent for <div> (typical alternative element) (screenshot).

Musing on the current Message components styles…

I've long since thought:

  1. Some margin should always be present between multiple messages; perhaps:

    .container + .container:not(p) /* ignore `<p>` cuz it typically has margin */ {
    	margin-top: /* …something, maybe `1rem` */
    }
  2. The default tag should be <div>.
    So use of <p> by client can rely on whatever <p> margin they set (or allow from browser).

113 changes: 113 additions & 0 deletions src/lib/SectionMessage/SectionMessage.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import type { Meta, StoryObj } from '@storybook/react';
import SectionMessage from './SectionMessage';
import { TYPE_MAP, TYPES } from '../Message/Message';
import styles from './SectionMessage.stories.module.css';

// Filter out the deprecated 'warn' type
const VALID_TYPES = TYPES.filter(type => type !== 'warn');

const meta: Meta<typeof SectionMessage> = {
component: SectionMessage,
argTypes: {
type: {
options: VALID_TYPES,
control: { type: 'select' },
description: 'Message type or severity',
},
canDismiss: {
control: 'boolean',
description: 'Whether message can be dismissed',
},
isVisible: {
control: 'boolean',
description: 'Controls message visibility',
},
ariaLabel: {
control: 'text',
description: 'Accessibility label for the message',
},
dataTestid: {
control: 'text',
description: 'Test identifier',
},
},
parameters: {
docs: {
description: {
component: 'Show a section/page-specific event-based message to the user',
},
},
},
};

export default meta;

type Story = StoryObj<typeof SectionMessage>;

export const Types: Story = {
render: (args) => {
return (
<div className={styles.container}>
{VALID_TYPES.map((type) => (
<SectionMessage
{...args}
key={type}
type={type}
ariaLabel={`${TYPE_MAP[type].iconText} message`}
>
This is a {type} message with icon "{TYPE_MAP[type].iconName}"
</SectionMessage>
))}
</div>
);
},
args: {
className: styles['message'],
canDismiss: true,
isVisible: true,
},
};

export const WithCustomDismiss: Story = {
render: (args) => (
<SectionMessage
{...args}
type="warning"
canDismiss
onDismiss={() => {
console.log('Message dismissed!');
}}
ariaLabel="Warning message with custom dismiss"
>
This message has a custom dismiss handler (check console)
</SectionMessage>
),
};

export const NonDismissible: Story = {
render: (args) => (
<SectionMessage
type="info"
canDismiss={false}
{...args}
ariaLabel="Non-dismissible info message"
>
This message cannot be dismissed as canDismiss is false
</SectionMessage>
),
};

export const WithLongContent: Story = {
render: (args) => (
<SectionMessage
{...args}
type="info"
canDismiss
ariaLabel="Info message with long content"
>
This is a message with longer content to demonstrate how the message component
handles multiple lines of text. The close button should remain properly aligned
and the icon should stay at the top of the content.
</SectionMessage>
),
};