Skip to content

Commit

Permalink
feat(Badge)!: deprecate name prop on component (#1865)
Browse files Browse the repository at this point in the history
Removing this prop `name` for consistency with other components. The
practice is that any component using another component in a prop should
use a camelCase version of the component's name. Because both were
supported, users of the now-removed `name` component can change the prop
to `icon` without any issue.
  • Loading branch information
booc0mtaco authored Feb 28, 2024
1 parent 9d3ffec commit cff5d5e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/components/Badge/Badge.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const IconBadge: StoryObj<Args> = {
>
Ava
</div>
<Badge.Icon name="alarm" />
<Badge.Icon icon="alarm" />
</>
),
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Badge/Badge.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('<Badge />', () => {
<Badge.Icon />
</Badge>,
);
}).toThrow(/Name or Icon must be passed to the Badge sub-component/);
}).toThrow(/Icon must be passed to the Badge sub-component/);
consoleErrorMock.mockRestore();
});
});
29 changes: 8 additions & 21 deletions src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import clsx from 'clsx';
import React from 'react';
import type { EitherExclusive } from '../../util/utility-types';
import Icon from '../Icon';
import type { IconName, IconProps } from '../Icon';
import styles from './Badge.module.css';
Expand All @@ -17,22 +16,12 @@ type BadgeProps = {
className?: string;
};

type BadgeIconProps = Omit<IconProps, 'purpose' | 'name'> &
EitherExclusive<
{
/**
* Name of icon to render. Please use `icon` instead, which has the same behavior.
* @deprecated
*/
name: IconName;
},
{
/**
* Name of icon to render.
*/
icon: IconName;
}
>;
type BadgeIconProps = Omit<IconProps, 'purpose' | 'name'> & {
/**
* Icon name from the defined set of EDS icons
*/
icon: IconName;
};

type BadgeTextProps = {
/**
Expand All @@ -45,17 +34,15 @@ type BadgeTextProps = {
className?: string;
};

const BadgeIcon = ({ className, name, icon, ...other }: BadgeIconProps) => {
const BadgeIcon = ({ className, icon, ...other }: BadgeIconProps) => {
const componentClassName = clsx(styles['badge'], className);
let iconName: IconName;

if (icon) {
iconName = icon;
} else if (name) {
iconName = name;
} else {
// both name and icon are undefined. throw an error
throw new Error('Name or Icon must be passed to the Badge sub-component');
throw new ReferenceError('Icon must be passed to the Badge sub-component');
}

return (
Expand Down

0 comments on commit cff5d5e

Please sign in to comment.