Skip to content

Commit 0c9210e

Browse files
teodoranemesat-susie
authored andcommitted
feat: Add support for the color of icon in the Alert Style API (#3882)
1 parent 22949b4 commit 0c9210e

File tree

8 files changed

+58
-3
lines changed

8 files changed

+58
-3
lines changed

build-tools/utils/custom-css-properties.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ const customCssPropertiesList = [
9999
'alertFocusRingBorderRadius',
100100
'alertFocusRingBorderWidth',
101101
'alertFocusRingBoxShadow',
102+
'alertIconColor',
102103
];
103104
module.exports = customCssPropertiesList;

pages/alert/style-custom-types.page.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function CustomAlert({ children, type, dismissible, action }: CustomAlertProps)
7373
const borderColor = borderColors[mode][type];
7474
const borderWidth = borderWidths[type];
7575
const color = colors[mode];
76+
const iconColor = iconColors[mode][type];
7677
return (
7778
<CloudscapeAlert
7879
dismissible={dismissible}
@@ -92,6 +93,9 @@ function CustomAlert({ children, type, dismissible, action }: CustomAlertProps)
9293
borderWidth: '2px',
9394
},
9495
},
96+
icon: {
97+
color: iconColor,
98+
},
9599
dismissButton: {
96100
color: {
97101
default: dismissButtonColors[mode][type].default,
@@ -153,6 +157,21 @@ const borderWidths = {
153157
warning: '0px',
154158
};
155159

160+
const iconColors = {
161+
light: {
162+
info: palette.orange80,
163+
success: palette.red60,
164+
error: palette.blue80,
165+
warning: palette.neutral10,
166+
},
167+
dark: {
168+
info: palette.red30,
169+
success: palette.red60,
170+
error: palette.blue40,
171+
warning: palette.neutral90,
172+
},
173+
};
174+
156175
const dismissButtonColors = {
157176
light: {
158177
info: {

src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,22 @@ If the label is assigned via the \`i18nStrings\` property, this label will be ig
247247
"optional": true,
248248
"type": "{ color?: { active?: string | undefined; default?: string | undefined; hover?: string | undefined; } | undefined; focusRing?: { borderColor?: string | undefined; borderRadius?: string | undefined; borderWidth?: string | undefined; } | undefined; }",
249249
},
250+
{
251+
"inlineType": {
252+
"name": "{ color?: string | undefined; }",
253+
"properties": [
254+
{
255+
"name": "color",
256+
"optional": true,
257+
"type": "string",
258+
},
259+
],
260+
"type": "object",
261+
},
262+
"name": "icon",
263+
"optional": true,
264+
"type": "{ color?: string | undefined; }",
265+
},
250266
{
251267
"inlineType": {
252268
"name": "object",

src/alert/__tests__/alert.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ describe('Style API', () => {
287287
borderWidth: '4px',
288288
},
289289
},
290+
icon: {
291+
color: 'rgb(255, 0, 0)',
292+
},
290293
dismissButton: {
291294
color: {
292295
active: 'rgb(12, 136, 22)',
@@ -336,5 +339,8 @@ describe('Style API', () => {
336339
);
337340
expect(getComputedStyle(dismissButton).getPropertyValue(customCssProps.styleFocusRingBorderRadius)).toBe('6px');
338341
expect(getComputedStyle(dismissButton).getPropertyValue(customCssProps.styleFocusRingBorderWidth)).toBe('4px');
342+
343+
const iconElement = wrapper.findByClassName(styles.icon)!.getElement();
344+
expect(getComputedStyle(iconElement).getPropertyValue(customCssProps.alertIconColor)).toBe('rgb(255, 0, 0)');
339345
});
340346
});

src/alert/interfaces.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ export namespace AlertProps {
6161
borderWidth?: string;
6262
};
6363
};
64+
icon?: {
65+
color?: string;
66+
};
6467
dismissButton?: {
6568
color?: {
6669
active?: string;

src/alert/internal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import useContainerWidth from '../internal/utils/use-container-width';
2525
import { ActionsWrapper } from './actions-wrapper';
2626
import { GeneratedAnalyticsMetadataAlertDismiss } from './analytics-metadata/interfaces';
2727
import { AlertProps } from './interfaces';
28-
import { getAlertStyles, getDismissButtonStyles } from './style';
28+
import { getAlertStyles, getDismissButtonStyles, getIconStyles } from './style';
2929

3030
import analyticsSelectors from './analytics-metadata/styles.css.js';
3131
import styles from './styles.css.js';
@@ -139,7 +139,7 @@ const InternalAlert = React.forwardRef(
139139
>
140140
<div className={styles['alert-wrapper']}>
141141
<div className={styles['alert-focus-wrapper']} tabIndex={-1} ref={focusRef} role="group">
142-
<div className={clsx(styles.icon, styles.text)}>
142+
<div className={clsx(styles.icon, styles.text)} style={getIconStyles(style)}>
143143
<InternalIcon name={typeToIcon[type]} size={size} ariaLabel={statusIconAriaLabel} />
144144
</div>
145145
<div className={clsx(styles.message, styles.text)} id={messageSlotId}>

src/alert/style.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ export function getAlertStyles(style: AlertProps['style']) {
2323
};
2424
}
2525

26+
export function getIconStyles(style: AlertProps['style']) {
27+
if (SYSTEM !== 'core' || !style?.icon?.color) {
28+
return undefined;
29+
}
30+
31+
return {
32+
[customCssProps.alertIconColor]: style.icon.color,
33+
};
34+
}
35+
2636
export function getDismissButtonStyles(style: AlertProps['style']) {
2737
if (SYSTEM !== 'core' || !style?.dismissButton) {
2838
return undefined;

src/alert/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ $_text-colors: (
160160
border-color: #{map.get($_border-colors, $type)};
161161
background-color: #{map.get($_background-colors, $type)};
162162
> .alert-wrapper > .alert-focus-wrapper > .icon {
163-
color: #{map.get($_text-colors, $type)};
163+
color: var(#{custom-props.$alertIconColor}, #{map.get($_text-colors, $type)});
164164
}
165165
}
166166
}

0 commit comments

Comments
 (0)