Skip to content

Commit 2dd1055

Browse files
feat(actionable-notifications): add caption prop (#19973)
* feat(actionable-notifications): add caption prop * fix(controls): update
1 parent 9466505 commit 2dd1055

File tree

7 files changed

+62
-2
lines changed

7 files changed

+62
-2
lines changed

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ Map {
225225
"type": "string",
226226
},
227227
"ariaLabel": [Function],
228+
"caption": Object {
229+
"type": "string",
230+
},
228231
"children": Object {
229232
"type": "node",
230233
},

packages/react/src/components/Notification/Notification.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,11 @@ export interface ActionableNotificationProps
826826
*/
827827
'aria-label'?: string;
828828

829+
/**
830+
* Specify the caption
831+
*/
832+
caption?: string;
833+
829834
/**
830835
* Specify the content
831836
*/
@@ -918,6 +923,7 @@ export function ActionableNotification({
918923
['aria-label']: ariaLabel,
919924
// @ts-expect-error: deprecated prop
920925
ariaLabel: deprecatedAriaLabel,
926+
caption,
921927
children,
922928
role = 'alertdialog',
923929
onActionButtonClick,
@@ -1060,6 +1066,13 @@ export function ActionableNotification({
10601066
{subtitle}
10611067
</Text>
10621068
)}
1069+
{caption && (
1070+
<Text
1071+
as="div"
1072+
className={`${prefix}--actionable-notification__caption`}>
1073+
{caption}
1074+
</Text>
1075+
)}
10631076
{children}
10641077
</div>
10651078
</div>
@@ -1116,6 +1129,11 @@ ActionableNotification.propTypes = {
11161129
'This prop syntax has been deprecated. Please use the new `aria-label`.'
11171130
),
11181131

1132+
/**
1133+
* Specify the caption
1134+
*/
1135+
caption: PropTypes.string,
1136+
11191137
/**
11201138
* Specify the content
11211139
*/

packages/react/src/components/Notification/__tests__/Notification-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,20 @@ describe('ActionableNotification', () => {
341341
expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument();
342342
});
343343
});
344+
345+
it('supports `title`, `subtitle`, `caption` props', () => {
346+
render(
347+
<ActionableNotification
348+
title="A title"
349+
subtitle="A subtitle"
350+
caption="00:00:00 AM"
351+
actionButtonLabel="My custom action"></ActionableNotification>
352+
);
353+
// eslint-disable-next-line testing-library/prefer-presence-queries
354+
expect(screen.queryByText(/A title/i)).toBeInTheDocument();
355+
expect(screen.queryByText(/A subtitle/i)).toBeInTheDocument();
356+
expect(screen.queryByText(/00:00:00 AM/i)).toBeInTheDocument();
357+
});
344358
});
345359

346360
// TODO: Remove StaticNotification tests when StaticNotification is removed (v12)

packages/react/src/components/Notification/stories/ActionableNotification.stories.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export default {
3030
},
3131
};
3232

33-
export const Default = (args) => <ActionableNotification {...args} />;
33+
export const Default = (args) => (
34+
<ActionableNotification {...args}></ActionableNotification>
35+
);
3436

3537
Default.argTypes = {
3638
['aria-label']: {

packages/styles/scss/components/notification/_actionable-notification.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,19 @@
280280
.#{$prefix}--actionable-notification__subtitle {
281281
color: $text-primary;
282282
}
283+
284+
.#{$prefix}--actionable-notification__caption {
285+
@include type-style('body-compact-01');
286+
287+
color: $text-inverse;
288+
padding-block-start: $spacing-06;
289+
}
290+
291+
.#{$prefix}--actionable-notification--low-contrast
292+
.#{$prefix}--actionable-notification__caption {
293+
color: $text-primary;
294+
}
295+
283296
/* Ghost action button when inline */
284297
.#{$prefix}--actionable-notification__action-button.#{$prefix}--btn--ghost {
285298
block-size: convert.to-rem(32px);

packages/web-components/src/components/notification/actionable-notification.stories.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const argTypes = {
3737
description:
3838
'Pass in the action button label that will be rendered within the ActionableNotification.',
3939
},
40+
caption: {
41+
control: 'text',
42+
description: 'Specify the caption.',
43+
},
4044
closeOnEscape: {
4145
control: 'boolean',
4246
description:
@@ -111,6 +115,7 @@ export const Playground = {
111115
render: (args) => {
112116
const {
113117
actionButtonLabel,
118+
caption,
114119
closeOnEscape,
115120
hasFocus,
116121
kind,
@@ -135,6 +140,7 @@ export const Playground = {
135140
<cds-actionable-notification
136141
?close-on-escape="${closeOnEscape}"
137142
?has-focus="${hasFocus}"
143+
caption="${ifDefined(caption)}"
138144
kind="${ifDefined(kind)}"
139145
title="${ifDefined(title)}"
140146
subtitle="${ifDefined(subtitle)}"

packages/web-components/src/components/notification/actionable-notification.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class CDSActionableNotification extends HostListenerMixin(
238238
}
239239

240240
protected _renderText() {
241-
const { subtitle, title, _type: type } = this;
241+
const { caption, subtitle, title, _type: type } = this;
242242
return html`
243243
<div class="${prefix}--${type}-notification__text-wrapper">
244244
<div class="${prefix}--${type}-notification__content">
@@ -248,6 +248,10 @@ class CDSActionableNotification extends HostListenerMixin(
248248
<div class="${prefix}--${type}-notification__subtitle">
249249
${subtitle}<slot name="subtitle"></slot>
250250
</div>
251+
${caption &&
252+
html`<div class="${prefix}--${type}-notification__caption">
253+
${caption}<slot name="caption"></slot>
254+
</div>`}
251255
<slot></slot>
252256
</div>
253257
</div>

0 commit comments

Comments
 (0)