Skip to content

Commit 5025b93

Browse files
committed
chore: adds colors for alert
1 parent 83325f5 commit 5025b93

File tree

5 files changed

+56
-50
lines changed

5 files changed

+56
-50
lines changed

packages/notifications/src/elements/Alert.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,21 @@
77

88
import React from 'react';
99
import PropTypes from 'prop-types';
10-
import { IAlertProps, TYPE, Type } from '../types';
10+
import { IAlertProps, TYPE } from '../types';
1111
import { StyledAlert, StyledIcon } from '../styled';
12-
import { validationIcons, validationHues } from '../utils/icons';
12+
import { validationIcons } from '../utils/icons';
1313
import { NotificationsContext } from '../utils/useNotificationsContext';
1414
import { Title } from './content/Title';
1515
import { Paragraph } from './content/Paragraph';
1616
import { Close } from './content/Close';
1717

1818
export const AlertComponent = React.forwardRef<HTMLDivElement, IAlertProps>(
19-
({ role, ...props }, ref) => {
20-
const type = validationHues[props.type];
21-
const Icon = validationIcons[props.type] as any;
19+
({ role, type, ...props }, ref) => {
20+
const Icon = validationIcons[type] as any;
2221

2322
return (
24-
<NotificationsContext.Provider value={type as Type}>
25-
<StyledAlert ref={ref} hue={type} role={role === undefined ? 'alert' : role} {...props}>
23+
<NotificationsContext.Provider value={type}>
24+
<StyledAlert ref={ref} $type={type} role={role === undefined ? 'alert' : role} {...props}>
2625
<StyledIcon $type={type}>
2726
<Icon />
2827
</StyledIcon>

packages/notifications/src/styled/StyledAlert.spec.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@
77

88
import React from 'react';
99
import { css } from 'styled-components';
10-
import { DEFAULT_THEME, getColorV8 } from '@zendeskgarden/react-theming';
11-
import { render } from 'garden-test-utils';
10+
import { PALETTE } from '@zendeskgarden/react-theming';
11+
import { getRenderFn } from 'garden-test-utils';
1212
import { StyledAlert, StyledTitle } from '../styled';
1313
import { Type } from '../types';
1414

1515
describe('StyledAlert', () => {
16-
it(`should render the styling correctly for a Notification's title`, () => {
17-
const validationHues: Record<Type, string> = {
18-
success: 'successHue',
19-
error: 'dangerHue',
20-
warning: 'warningHue',
21-
info: 'neutralHue'
22-
};
16+
it.each<{ mode: 'light' | 'dark'; type: Type; color: string }>([
17+
{ mode: 'light', type: 'success', color: PALETTE.green[900] },
18+
{ mode: 'dark', type: 'success', color: PALETTE.green[300] },
19+
{ mode: 'light', type: 'error', color: PALETTE.red[900] },
20+
{ mode: 'dark', type: 'error', color: PALETTE.red[300] },
21+
{ mode: 'light', type: 'warning', color: PALETTE.yellow[900] },
22+
{ mode: 'dark', type: 'warning', color: PALETTE.yellow[300] },
23+
{ mode: 'light', type: 'info', color: PALETTE.grey[900] },
24+
{ mode: 'dark', type: 'info', color: PALETTE.grey[300] }
25+
])('renders correct $mode type $type title color', ({ mode, type, color }) => {
26+
const { container } = getRenderFn(mode)(<StyledAlert $type={type} />);
2327

24-
Object.values(validationHues).forEach(hue => {
25-
const { container } = render(<StyledAlert hue={hue} />);
26-
27-
expect(container.firstChild).toHaveStyleRule('color', getColorV8(hue, 800, DEFAULT_THEME), {
28-
modifier: css`
29-
${StyledTitle}
30-
` as any
31-
});
28+
expect(container.firstChild).toHaveStyleRule('color', color, {
29+
modifier: css`
30+
${StyledTitle}
31+
` as any
3232
});
3333
});
3434
});

packages/notifications/src/styled/StyledAlert.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,46 @@
66
*/
77

88
import styled, { css, ThemeProps, DefaultTheme } from 'styled-components';
9-
import { retrieveComponentStyles, getColorV8, DEFAULT_THEME } from '@zendeskgarden/react-theming';
9+
import { retrieveComponentStyles, DEFAULT_THEME, getColor } from '@zendeskgarden/react-theming';
1010
import { StyledTitle } from './content/StyledTitle';
1111
import { IStyledBaseProps, StyledBase } from './StyledBase';
12+
import { validationTypes } from '../utils/icons';
13+
import { Type } from '../types';
1214

1315
const COMPONENT_ID = 'notifications.alert';
1416

1517
export interface IStyledAlertProps extends IStyledBaseProps {
16-
hue?: string;
18+
$type?: Type;
1719
}
1820

19-
const colorStyles = (props: IStyledAlertProps & ThemeProps<DefaultTheme>) => css`
20-
${StyledTitle} {
21-
color: ${props.hue && getColorV8(props.hue, 800, props.theme)};
21+
const colorStyles = (props: IStyledAlertProps & ThemeProps<DefaultTheme>) => {
22+
const { $type, theme } = props;
23+
24+
let variable;
25+
26+
switch ($type) {
27+
case validationTypes.success:
28+
variable = 'foreground.successEmphasis';
29+
break;
30+
case validationTypes.error:
31+
variable = 'foreground.dangerEmphasis';
32+
break;
33+
case validationTypes.warning:
34+
variable = 'foreground.warningEmphasis';
35+
break;
36+
case validationTypes.info:
37+
variable = 'foreground.default';
38+
break;
2239
}
23-
`;
40+
41+
const color = variable ? getColor({ variable, theme }) : undefined;
42+
43+
return css`
44+
${StyledTitle} {
45+
color: ${color};
46+
}
47+
`;
48+
};
2449

2550
/**
2651
* Supports all `<div>` props
@@ -30,6 +55,7 @@ export const StyledAlert = styled(StyledBase).attrs({
3055
'data-garden-version': PACKAGE_VERSION
3156
})<IStyledAlertProps>`
3257
${colorStyles}
58+
3359
${props => retrieveComponentStyles(COMPONENT_ID, props)};
3460
`;
3561

packages/notifications/src/styled/StyledBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const colorStyles = ({ theme, $type, $isFloating }: IStyledBaseProps) => {
6161
fgVariable = 'foreground.warning';
6262
break;
6363
case validationTypes.info:
64-
bgVariable = 'background.raised';
64+
bgVariable = 'background.subtle';
6565
borderVariable = 'border.default';
6666
fgVariable = 'foreground.subtle';
6767
break;

packages/notifications/src/styled/content/StyledClose.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@ interface IStyledCloseProps {
1717
$type?: Type;
1818
}
1919

20-
/**
21-
* 1. IconButton reset
22-
*/
23-
const sizeStyles = ({ theme: { space } }: ThemeProps<DefaultTheme>) => {
24-
return css`
25-
padding: 0;
26-
width: ${space.base * 7}px;
27-
min-width: unset; /* [1] */
28-
height: ${space.base * 7}px;
29-
30-
&& > svg {
31-
width: unset; /* [1] */
32-
height: unset; /* [1] */
33-
}
34-
`;
35-
};
36-
3720
/**
3821
* 1. IconButton reset
3922
*/
@@ -94,8 +77,6 @@ export const StyledClose = styled(IconButton).attrs({
9477
right: ${p => !p.theme.rtl && `${p.theme.space.base}px`};
9578
left: ${p => p.theme.rtl && `${p.theme.space.base}px`};
9679
97-
${sizeStyles}
98-
9980
${colorStyles}
10081
10182
${props => retrieveComponentStyles(COMPONENT_ID, props)};

0 commit comments

Comments
 (0)