Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(util): add and use getIconNameFromStatus function #1909

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions src/components/BannerNotification/BannerNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import clsx from 'clsx';
import React, { type ReactNode } from 'react';

import getIconNameFromStatus from '../../util/getIconNameFromStatus';
import type { Status } from '../../util/variant-types';
import Heading from '../Heading';
import Icon, { type IconName } from '../Icon';
import Icon from '../Icon';
import Text from '../Text';

import styles from './BannerNotification.module.css';
Expand Down Expand Up @@ -41,23 +42,6 @@ export type BannerNotificationProps = {
title?: string;
};

/**
* Map statuses to existing icon names
* TODO-AH: de-dupe this with the function in InlineNotification
*
* @param status component status
* @returns the matching icon name
*/
function getIconNameFromStatus(status: Status): IconName {
const map: Record<Status, IconName> = {
informational: 'info',
critical: 'dangerous',
warning: 'warning',
favorable: 'check-circle',
};
return map[status];
}

/**
* `import {BannerNotification} from "@chanzuckerberg/eds";`
*
Expand Down
18 changes: 2 additions & 16 deletions src/components/InlineNotification/InlineNotification-v2.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import clsx from 'clsx';
import React from 'react';

import getIconNameFromStatus from '../../util/getIconNameFromStatus';
import type { Status } from '../../util/variant-types';

import Icon, { type IconName } from '../Icon';
import Icon from '../Icon';
import Text from '../Text';

import styles from './InlineNotification-v2.module.css';
Expand Down Expand Up @@ -35,21 +36,6 @@ type InlineNotificationProps = {
title: string;
};

/**
* Map statuses to existing icon names
* @param status component status
* @returns the matching icon name
*/
function getIconNameFromStatus(status: Status): IconName {
const map: Record<Status, IconName> = {
informational: 'info',
critical: 'dangerous',
warning: 'warning',
favorable: 'check-circle',
};
return map[status];
}

/**
* `import {InlineNotification} from "@chanzuckerberg/eds";`
*
Expand Down
20 changes: 2 additions & 18 deletions src/components/Toast/Toast-v2.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import clsx from 'clsx';
import React from 'react';

import getIconNameFromStatus from '../../util/getIconNameFromStatus';
import type { Status } from '../../util/variant-types';
import { ButtonV2 as Button } from '../Button';
import Icon, { type IconName } from '../Icon';
import Icon from '../Icon';
import Text from '../Text';

import styles from './Toast-v2.module.css';
Expand All @@ -29,23 +30,6 @@ export type ToastProps = {
title: string;
};

/**
* Map statuses to existing icon names
* TODO-AH: de-dupe this with the function in InlineNotification
*
* @param status component status
* @returns the matching icon name
*/
function getIconNameFromStatus(status: Status): IconName {
const map: Record<Status, IconName> = {
informational: 'info',
critical: 'dangerous',
warning: 'warning',
favorable: 'check-circle',
};
return map[status];
}

/**
* `import {Toast} from "@chanzuckerberg/eds";`
*
Expand Down
18 changes: 18 additions & 0 deletions src/util/getIconNameFromStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Status } from './variant-types';
import type { IconName } from '../icons/spritemap';

/**
* Map statuses to existing icon names
*
* @param status component status
* @returns the matching icon name
*/
export default function getIconNameFromStatus(status: Status): IconName {
const map: Record<Status, IconName> = {
informational: 'info',
critical: 'dangerous',
warning: 'warning',
favorable: 'check-circle',
};
return map[status];
}
Loading