Skip to content

Commit 7bff52d

Browse files
authored
feat(InlineNotification)!: introduce 2.0 component (#1903)
- add in 2.0 component with style/token changes - add in updated design API properties
1 parent cf2086b commit 7bff52d

File tree

4 files changed

+209
-0
lines changed

4 files changed

+209
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@import '../../design-tokens/mixins.css';
2+
3+
/*------------------------------------*\
4+
# INLINE NOTIFICATION
5+
\*------------------------------------*/
6+
7+
/**
8+
* A messaging element that is used inline.
9+
*/
10+
.inline-notification {
11+
display: flex;
12+
gap: 0.5rem;
13+
padding: 0.5rem;
14+
border-radius: calc(var(--eds-theme-border-radius-objects-sm) * 1px);
15+
16+
border: 0.125rem solid;
17+
border-left: 0.5rem solid;
18+
19+
/* NOTE: by specifying no default color for borders, they inherit from color below */
20+
&.inline-notification--status-informational {
21+
color: var(--eds-theme-color-text-utility-informational);
22+
background-color: var(--eds-theme-color-background-utility-information-low-emphasis);
23+
}
24+
25+
&.inline-notification--status-critical {
26+
color: var(--eds-theme-color-text-utility-critical);
27+
background-color: var(--eds-theme-color-background-utility-critical-low-emphasis);
28+
}
29+
30+
&.inline-notification--status-favorable {
31+
color: var(--eds-theme-color-text-utility-favorable);
32+
background-color: var(--eds-theme-color-background-utility-favorable-low-emphasis);
33+
}
34+
35+
&.inline-notification--status-warning {
36+
color: var(--eds-theme-color-text-utility-warning);
37+
background-color: var(--eds-theme-color-background-utility-warning-low-emphasis);
38+
}
39+
}
40+
41+
.inline-notification__icon {
42+
flex-shrink: 0;
43+
}
44+
45+
.inline-notification__body {
46+
flex-grow: 2;
47+
}
48+
49+
.inline-notification__sub-title {
50+
color: var(--eds-theme-color-text-utility-default-secondary)
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type { StoryObj, Meta } from '@storybook/react';
2+
import { InlineNotification } from './InlineNotification-v2';
3+
4+
export default {
5+
title: 'Components/V2/InlineNotification',
6+
component: InlineNotification,
7+
parameters: {
8+
badges: ['intro-1.0', 'current-2.0'],
9+
},
10+
args: {
11+
title: 'Inline notifications lorem ipsum text',
12+
},
13+
} as Meta<Args>;
14+
15+
type Args = React.ComponentProps<typeof InlineNotification>;
16+
17+
export const Default: StoryObj<Args> = {};
18+
19+
export const WithSubTitle: StoryObj<Args> = {
20+
args: {
21+
...Default.args,
22+
subTitle: 'Additional text which provides additional detail',
23+
},
24+
};
25+
26+
export const Favorable: StoryObj<Args> = {
27+
args: {
28+
...WithSubTitle.args,
29+
status: 'favorable',
30+
},
31+
};
32+
33+
export const Warning: StoryObj<Args> = {
34+
args: {
35+
...WithSubTitle.args,
36+
status: 'warning',
37+
},
38+
};
39+
40+
export const Critical: StoryObj<Args> = {
41+
args: {
42+
...WithSubTitle.args,
43+
status: 'critical',
44+
},
45+
};
46+
47+
export const LongText: StoryObj<Args> = {
48+
args: {
49+
title:
50+
'Long text inline notification. 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.',
51+
},
52+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import clsx from 'clsx';
2+
import React from 'react';
3+
4+
import type { Status } from '../../util/variant-types';
5+
6+
import Icon, { type IconName } from '../Icon';
7+
import Text from '../Text';
8+
9+
import styles from './InlineNotification-v2.module.css';
10+
11+
/**
12+
* TODO-AH:
13+
* - feedback on api naming in figma
14+
* - handling of aria-live for a11y
15+
*/
16+
17+
type InlineNotificationProps = {
18+
// Component API
19+
/**
20+
* CSS class names that can be appended to the component for styling.
21+
*/
22+
className?: string;
23+
// Design API
24+
/**
25+
* The text contents of the tag, nested inside the component, in addition to the icon.
26+
*/
27+
title: string;
28+
/**
29+
* Text used for the main description of the notification
30+
*/
31+
status?: Status;
32+
/**
33+
* Secondary text used to describe the notification in more detail
34+
*/
35+
subTitle?: string;
36+
};
37+
38+
/**
39+
* Map statuses to existing icon names
40+
* @param status component status
41+
* @returns the matching icon name
42+
*/
43+
function getIconNameFromStatus(status: Status): IconName {
44+
const map: Record<Status, IconName> = {
45+
informational: 'info',
46+
critical: 'dangerous',
47+
warning: 'warning',
48+
favorable: 'check-circle',
49+
};
50+
return map[status];
51+
}
52+
53+
/**
54+
* `import {InlineNotification} from "@chanzuckerberg/eds";`
55+
*
56+
* This component provides an inline banner accompanied with an icon for messaging users.
57+
*/
58+
export const InlineNotification = ({
59+
className,
60+
status = 'informational',
61+
subTitle,
62+
title,
63+
...other
64+
}: InlineNotificationProps) => {
65+
const componentClassName = clsx(
66+
styles['inline-notification'],
67+
status && styles[`inline-notification--status-${status}`],
68+
className,
69+
);
70+
71+
return (
72+
<div className={componentClassName} {...other}>
73+
<Icon
74+
className={styles['inline-notification__icon']}
75+
name={getIconNameFromStatus(status)}
76+
purpose="decorative"
77+
size="1rem"
78+
/>
79+
<div className={styles['inline-notication__body']}>
80+
<Text
81+
as="div"
82+
className={styles[`inline-notification__title`]}
83+
preset="title-xs"
84+
>
85+
{title}
86+
</Text>
87+
{subTitle && (
88+
<Text
89+
as="div"
90+
className={styles[`inline-notification__sub-title`]}
91+
preset="body-xs"
92+
>
93+
{subTitle}
94+
</Text>
95+
)}
96+
</div>
97+
</div>
98+
);
99+
};
100+
101+
InlineNotification.displayName = 'InlineNotification';

src/util/variant-types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export type Align = 'left' | 'center' | 'right';
2424
*/
2525
export type Hint = 'none' | 'required' | 'optional';
2626

27+
/**
28+
* Statuses tied to the state of information being displayed
29+
*/
30+
export type Status = 'informational' | 'warning' | 'favorable' | 'critical';
31+
2732
/**
2833
* List of tier-2 and -3 tokens for use in types:
2934
* - src/design-tokens/tier-2-usage/typography.json

0 commit comments

Comments
 (0)