-
Notifications
You must be signed in to change notification settings - Fork 0
Add SectionMessage story #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| .container { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 1rem; | ||
| padding: 1rem; | ||
| } | ||
|
|
||
| .message { | ||
| margin-bottom: 0; | ||
| } | ||
|
Comment on lines
+8
to
+10
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this style is not necessary, because the Musing on the current Message components styles…I've long since thought:
|
||
| 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> | ||
| ), | ||
| }; |
There was a problem hiding this comment.
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:
<body>in the preview window (via.sb-main-padded). If we start doing it for every.container(or.rootor whatever the element may be classed), then we give ourselves a chore to remain consistent.screenshot without these styles