Skip to content

Commit 96427b8

Browse files
feat(notification): implement top-left alignment for all elements
- Update NotificationItem to always use flex-start alignment - Add alignSelf: 'flex-start' to icon styles for consistent top-left positioning - Add TopLeftAlignment and MultipleLineParagraph stories to showcase the alignment behavior - Ensure all notification elements (icon, title, content, close button) align to top-left
1 parent defaff5 commit 96427b8

3 files changed

Lines changed: 83 additions & 1 deletion

File tree

packages/components/notification/src/NotificationItem/NotificationItem.styles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const getIconStyle = ({ variant }) =>
3636
fill: variantColors[variant],
3737
marginRight: tokens.spacingM,
3838
alignItems: 'flex-start',
39+
alignSelf: 'flex-start',
3940
});
4041

4142
export const getStyles = ({ variant }: { variant: NotificationVariant }) => ({

packages/components/notification/src/NotificationItem/NotificationItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const _NotificationItem = (props: ExpandProps<NotificationItemProps>, ref) => {
9595
data-intent={intents[variant]}
9696
aria-live={variant === 'positive' ? 'polite' : 'assertive'}
9797
className={cx(styles.wrapper, className)}
98-
alignItems={title ? 'flex-start' : 'center'}
98+
alignItems="flex-start"
9999
{...otherProps}
100100
ref={ref}
101101
>

packages/components/notification/stories/Notification.stories.tsx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,84 @@ overview.args = {
184184
onClose: action('onClose'),
185185
children: 'Body for the notification',
186186
};
187+
188+
export const TopLeftAlignment = () => {
189+
return (
190+
<Flex fullWidth flexDirection="column">
191+
<SectionHeading marginBottom="spacingS" as="h3">
192+
Top-Left Alignment Preview
193+
</SectionHeading>
194+
<Flex marginBottom="spacingL">
195+
<NotificationItem
196+
variant="positive"
197+
title="Long notification title that spans multiple lines to demonstrate top-left alignment"
198+
cta={{
199+
label: 'Call to Action',
200+
}}
201+
onClose={action('onClose')}
202+
>
203+
This is a longer notification body that contains multiple lines of
204+
text to demonstrate how all elements align to the top-left when the
205+
notification has both a title and content.
206+
</NotificationItem>
207+
</Flex>
208+
209+
<Flex marginBottom="spacingL">
210+
<NotificationItem
211+
variant="negative"
212+
title="Error Title"
213+
cta={{
214+
label: 'Resolve Error',
215+
}}
216+
onClose={action('onClose')}
217+
>
218+
Short error message.
219+
</NotificationItem>
220+
</Flex>
221+
222+
<Flex marginBottom="spacingL">
223+
<NotificationItem variant="warning" onClose={action('onClose')}>
224+
Notification without title - icon should still align to top-left with
225+
the text content.
226+
</NotificationItem>
227+
</Flex>
228+
229+
<Flex marginBottom="spacingL">
230+
<NotificationItem
231+
variant="primary"
232+
title="Info Notification"
233+
onClose={action('onClose')}
234+
>
235+
This demonstrates the alignment of icon, title, content, and close
236+
button when all elements are present.
237+
</NotificationItem>
238+
</Flex>
239+
</Flex>
240+
);
241+
};
242+
243+
TopLeftAlignment.args = {};
244+
245+
// Example story with multiple line blind text for the paragraph
246+
export const MultipleLineParagraph = (args) => {
247+
return (
248+
<NotificationItem
249+
{...args}
250+
title="Notification with multiple line paragraph"
251+
variant="primary"
252+
onClose={action('onClose')}
253+
>
254+
{`Lorem ipsum dolor sit amet, consectetur adipiscing elit.
255+
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
256+
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
257+
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.`}
258+
</NotificationItem>
259+
);
260+
};
261+
262+
MultipleLineParagraph.args = {
263+
cta: {
264+
label: 'Learn more',
265+
},
266+
closeButtonAriaLabel: 'Close',
267+
};

0 commit comments

Comments
 (0)