Skip to content

Commit

Permalink
refactor: use presentational values for colorScheme
Browse files Browse the repository at this point in the history
  • Loading branch information
jordmccord committed Jun 24, 2024
1 parent 1e32bc3 commit 85c8338
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 23 deletions.
3 changes: 2 additions & 1 deletion packages/web-ui/src/Alert/Alert.props.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ComponentPropsWithoutRef } from 'react';
import { COLOR_SCHEME } from '../types';

export interface AlertProps extends ComponentPropsWithoutRef<'div'> {
/**
* Sets the colour scheme.
* @default info
*/
colorScheme?: 'info' | 'success' | 'warning' | 'error';
colorScheme?: COLOR_SCHEME.cyan | COLOR_SCHEME.red | COLOR_SCHEME.green | COLOR_SCHEME.gold;
/**
* Sets the function to be called when the alert is dismissed and shows the dismiss icon.
*/
Expand Down
10 changes: 8 additions & 2 deletions packages/web-ui/src/Alert/Alert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import * as React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { Alert } from './Alert';
import { Flex } from '../Flex';
import { COLOR_SCHEME } from '../types';

const colorSchemes = ['info', 'warning', 'error', 'success'] as const;
const colorSchemes = [
COLOR_SCHEME.cyan,
COLOR_SCHEME.red,
COLOR_SCHEME.green,
COLOR_SCHEME.gold,
] as const;

const meta: Meta<typeof Alert> = {
title: 'Web UI / Components / Alert',
Expand All @@ -18,7 +24,7 @@ const meta: Meta<typeof Alert> = {
text: 'Alert text purus odio, maximus tincidunt aliquet posuere, mollis ut mauris.',
linkText: 'Alert link',
linkHref: '#',
colorScheme: 'info',
colorScheme: COLOR_SCHEME.cyan,
},
};

Expand Down
8 changes: 4 additions & 4 deletions packages/web-ui/src/Alert/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { PropsWithSx } from '../types';
import { COLOR_SCHEME, PropsWithSx } from '../types';
import { AlertProps } from './Alert.props';
import { COLORSCHEME_SELECTORS, DATA_ATTRIBUTES, px, withGlobalPrefix } from '../utils';
import clsx from 'clsx';
Expand Down Expand Up @@ -79,10 +79,10 @@ const StyledElement = styled('div')({
});

const AlertIcon = ({ colorScheme }: { colorScheme: AlertProps['colorScheme'] }) => {
if (colorScheme === 'info') {
if (colorScheme === COLOR_SCHEME.cyan) {
return <InformationMediumContainedIcon />;
}
if (colorScheme === 'success') {
if (colorScheme === COLOR_SCHEME.green) {
return <TickMediumContainedIcon />;
}
return <WarningMediumContainedIcon />;
Expand All @@ -100,7 +100,7 @@ export const Alert = React.forwardRef<
(
{
className,
colorScheme = 'info',
colorScheme = COLOR_SCHEME.cyan,
direction = 'column',
children,
onDismiss,
Expand Down
8 changes: 4 additions & 4 deletions packages/web-ui/src/Alert/AlertLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ const StyledElement = styled(TextLink)({
color: 'var(--alert-link-color)',
textDecorationColor: 'var(--alert-link-color)',
alignSelf: 'flex-start',
[colorSchemeParentSelector(COLOR_SCHEME.info)]: {
[colorSchemeParentSelector(COLOR_SCHEME.cyan)]: {
'--alert-link-color': colors.cyan700,
},
[colorSchemeParentSelector(COLOR_SCHEME.success)]: {
[colorSchemeParentSelector(COLOR_SCHEME.green)]: {
'--alert-link-color': colors.green700,
},
[colorSchemeParentSelector(COLOR_SCHEME.warning)]: {
[colorSchemeParentSelector(COLOR_SCHEME.gold)]: {
'--alert-link-color': colors.gold700,
},
[colorSchemeParentSelector(COLOR_SCHEME.error)]: {
[colorSchemeParentSelector(COLOR_SCHEME.red)]: {
'--alert-link-color': colors.red700,
},
});
Expand Down
8 changes: 4 additions & 4 deletions packages/web-ui/src/Alert/AlertText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ const componentClassName = withGlobalPrefix(componentName);

const StyledElement = styled(Text)({
color: 'var(--alert-text-color)',
[colorSchemeParentSelector(COLOR_SCHEME.info)]: {
[colorSchemeParentSelector(COLOR_SCHEME.cyan)]: {
'--alert-text-color': colors.cyan900,
},
[colorSchemeParentSelector(COLOR_SCHEME.success)]: {
[colorSchemeParentSelector(COLOR_SCHEME.green)]: {
'--alert-text-color': colors.green900,
},
[colorSchemeParentSelector(COLOR_SCHEME.warning)]: {
[colorSchemeParentSelector(COLOR_SCHEME.gold)]: {
'--alert-text-color': colors.gold900,
},
[colorSchemeParentSelector(COLOR_SCHEME.error)]: {
[colorSchemeParentSelector(COLOR_SCHEME.red)]: {
'--alert-text-color': colors.red900,
},
});
Expand Down
8 changes: 4 additions & 4 deletions packages/web-ui/src/Alert/AlertTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ const componentClassName = withGlobalPrefix(componentName);
const StyledElement = styled(Text)({
fontWeight: fontWeights.secondary.semibold,
color: 'var(--alert-text-color)',
[colorSchemeParentSelector(COLOR_SCHEME.info)]: {
[colorSchemeParentSelector(COLOR_SCHEME.cyan)]: {
'--alert-text-color': colors.cyan900,
},
[colorSchemeParentSelector(COLOR_SCHEME.success)]: {
[colorSchemeParentSelector(COLOR_SCHEME.green)]: {
'--alert-text-color': colors.green900,
},
[colorSchemeParentSelector(COLOR_SCHEME.warning)]: {
[colorSchemeParentSelector(COLOR_SCHEME.gold)]: {
'--alert-text-color': colors.gold900,
},
[colorSchemeParentSelector(COLOR_SCHEME.error)]: {
[colorSchemeParentSelector(COLOR_SCHEME.red)]: {
'--alert-text-color': colors.red900,
},
});
Expand Down
4 changes: 0 additions & 4 deletions packages/web-ui/src/types/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ export enum COLOR_SCHEME {
green = 'green',
gold = 'gold',
grey = 'grey',
error = 'error',
info = 'info',
warning = 'warning',
success = 'success',
}

0 comments on commit 85c8338

Please sign in to comment.