Skip to content

Commit

Permalink
[PropTypes] Exclude deprecated values from checker (#249)
Browse files Browse the repository at this point in the history
* Exclude deprecated values from prop-checking, which triggers deprecation warnings

* Fix comment, DRY up code, why not

* fix story

Co-authored-by: Diego Fortes <[email protected]>
  • Loading branch information
michaeljaltamirano and daigof authored Jun 26, 2020
1 parent ffeab4a commit ffa06cf
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
24 changes: 22 additions & 2 deletions src/constants/colors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* Note: Each config is exported separately to be rendered in storybook:
* https://github.com/PocketDerm/PocketDerm/blob/master/resources/assets/component-library/stories/colors/index.js#L5
*/

import PropTypes from 'prop-types';

import { withDeprecationWarning } from '../../utils';

const DEFAULT = '#706D87';
Expand Down Expand Up @@ -149,17 +152,34 @@ export const guideColors = {
recommendedCleansersGuide: '#cad1b5',
};

const colorsCompilation = {
const sharedColors = {
...brandColors,
...legacyColors,
...colorAliases,
...postcardColors,
...guideColors,
};

const colorsCompilation = {
...sharedColors,
...legacyColors,
};

const deprecatedProperties = {
purple80: 'purple80 is deprecated. Use purple85 instead',
purple60: 'purple60 is deprecated. Use purple70 instead',
};

// Do not include deprecated properties in PropTypes or it will trigger warning
// eslint-disable-next-line
const { purple80, purple60, ...allOtherLegacyColors } = legacyColors;

const NON_DEPRECATED_COLORS = {
...sharedColors,
...allOtherLegacyColors,
};

export const COLORS_PROP_TYPES = PropTypes.oneOf(
Object.values(NON_DEPRECATED_COLORS),
);

export default withDeprecationWarning(colorsCompilation, deprecatedProperties);
2 changes: 1 addition & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { default as ANIMATION } from './animation';
export { default as BOX_SHADOWS } from './boxShadows';
export { default as BREAKPOINTS } from './breakpoints';
export { default as COLORS } from './colors';
export { default as COLORS, COLORS_PROP_TYPES } from './colors';
export { default as FONTS } from './fonts';
export { default as GRID } from './grid';
export { default as LAYOUT } from './layout';
Expand Down
4 changes: 2 additions & 2 deletions src/shared-components/button/components/linkButton/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

import { COLORS } from '../../../../constants';
import { COLORS, COLORS_PROP_TYPES } from '../../../../constants';
import Container from '../../shared-components/container';
import { ButtonContents, ButtonText } from '../../style';
import { linkButtonStyles } from './style';
Expand All @@ -15,7 +15,7 @@ const propTypes = {
'tertiary',
'quaternary',
]),
buttonColor: PropTypes.oneOf(Object.values(COLORS)),
buttonColor: COLORS_PROP_TYPES,
as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]),
onClick: PropTypes.func,
textColor: PropTypes.string,
Expand Down
4 changes: 2 additions & 2 deletions src/shared-components/button/components/roundButton/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

import { COLORS } from '../../../../constants';
import { COLORS, COLORS_PROP_TYPES } from '../../../../constants';
import Loader from '../../shared-components/loader';
import {
RoundButtonWrapper,
Expand Down Expand Up @@ -35,7 +35,7 @@ const propTypes = {
'quaternary',
'action',
]),
buttonColor: PropTypes.oneOf(Object.values(COLORS)),
buttonColor: COLORS_PROP_TYPES,
loading: isLoadingPropFunction,
isLoading: PropTypes.bool,
icon: PropTypes.node.isRequired,
Expand Down
4 changes: 2 additions & 2 deletions src/shared-components/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import withDeprecationWarning from '../../utils/withDeprecationWarning';
import LinkButton from './components/linkButton';
import RoundButton from './components/roundButton';
import TextButton from './components/textButton';
import { COLORS } from '../../constants';
import { COLORS, COLORS_PROP_TYPES } from '../../constants';

const deprecatedProperties = {
loading: "The 'loading' prop is deprecated. Use 'isLoading' instead.",
Expand Down Expand Up @@ -38,7 +38,7 @@ class Button extends React.Component {
'tertiary',
'quaternary',
]),
buttonColor: PropTypes.oneOf(Object.values(COLORS)),
buttonColor: COLORS_PROP_TYPES,
loading: isLoadingPropFunction,
isLoading: PropTypes.bool,
icon: PropTypes.node,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

import { COLORS } from '../../../../constants';
import { COLORS, COLORS_PROP_TYPES } from '../../../../constants';
import ButtonLoader from './style';

const Loader = ({
Expand Down Expand Up @@ -38,7 +38,7 @@ Loader.propTypes = {
'quaternary',
'action',
]),
buttonColor: PropTypes.oneOf(Object.values(COLORS)),
buttonColor: COLORS_PROP_TYPES,
className: PropTypes.string,
disabled: PropTypes.bool,
isFullWidth: PropTypes.bool,
Expand Down
3 changes: 1 addition & 2 deletions stories/constants/colorsStory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import styled from '@emotion/styled';

import { SPACER } from 'src/constants';
import { Typography } from 'src/shared-components';
import * as COLORS from 'src/constants/colors';
Expand All @@ -22,7 +21,7 @@ const ColorsContainer = styled.div`
const colorsStory = () => (
<MainContainer>
{Object.keys(COLORS).map(category => {
if (category === 'default') {
if (category === 'default' || category === 'COLORS_PROP_TYPES') {
return null;
}

Expand Down

0 comments on commit ffa06cf

Please sign in to comment.