Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Commit

Permalink
feat(Icon): deprecate name prop (#2104)
Browse files Browse the repository at this point in the history
Refs #2100.

Aligns the actual behavior to that doc update.
  • Loading branch information
asudoh authored and joshblack committed Mar 28, 2019
1 parent b2fa89f commit 4a677b4
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/components/Icon/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import invariant from 'invariant';
import PropTypes from 'prop-types';
import React from 'react';
import warning from 'warning';
import icons from 'carbon-icons';
import isRequiredOneOf from '../../prop-types/isRequiredOneOf';
import { breakingChangesX } from '../../internal/FeatureFlags';

/**
* The icons list object from `carbon-icons`.
Expand Down Expand Up @@ -112,6 +114,11 @@ export function isPrefixed(name) {
return name && name.split('--')[0] === 'icon';
}

let didWarnAboutDeprecation;

const findIconWithPrefix = name =>
isPrefixed(name) ? findIcon(name) : findIcon(`icon--${name}`);

const Icon = ({
className,
iconTitle,
Expand All @@ -120,13 +127,22 @@ const Icon = ({
fillRule,
height,
name,
icon = isPrefixed(name) ? findIcon(name) : findIcon(`icon--${name}`),
icon = !breakingChangesX && findIconWithPrefix(name),
role,
style,
width,
iconRef,
...other
}) => {
if (__DEV__ && breakingChangesX && name) {
warning(
didWarnAboutDeprecation,
'The `name` property in the `Icon` component is being removed in the next release of ' +
'`carbon-components-react`. Please use `icon` instead.'
);
didWarnAboutDeprecation = true;
}

const props = {
className,
fill,
Expand Down

0 comments on commit 4a677b4

Please sign in to comment.