From 161d6ba9989387bc380af2db40f0728210b57dc8 Mon Sep 17 00:00:00 2001 From: squiaios <13620819+squiaios@users.noreply.github.com> Date: Thu, 16 May 2024 17:15:08 +0200 Subject: [PATCH] Remove defaultProps (#551) --- src/components/FontAwesomeIcon.js | 88 ++++++++++++++----------------- 1 file changed, 40 insertions(+), 48 deletions(-) diff --git a/src/components/FontAwesomeIcon.js b/src/components/FontAwesomeIcon.js index dc38583d..6bd8ddef 100644 --- a/src/components/FontAwesomeIcon.js +++ b/src/components/FontAwesomeIcon.js @@ -7,30 +7,51 @@ import objectWithKey from '../utils/object-with-key' import PropTypes from 'prop-types' import React from 'react' +const defaultProps = { + border: false, + className: '', + mask: null, + maskId: null, + fixedWidth: false, + inverse: false, + flip: false, + icon: null, + listItem: false, + pull: null, + pulse: false, + rotation: null, + size: null, + spin: false, + spinPulse: false, + spinReverse: false, + beat: false, + fade: false, + beatFade: false, + bounce: false, + shake: false, + symbol: false, + title: '', + titleId: null, + transform: null, + swapOpacity: false +} + const FontAwesomeIcon = React.forwardRef((props, ref) => { - const { - icon: iconArgs, - mask: maskArgs, - symbol, - className, - title, - titleId, - maskId - } = props + const allProps = {...defaultProps, ...props} - const iconLookup = normalizeIconArgs(iconArgs) + const iconLookup = normalizeIconArgs(allProps.icon) const classes = objectWithKey('classes', [ - ...classList(props), - ...className.split(' ') + ...classList(allProps), + ...allProps.className.split(' ') ]) const transform = objectWithKey( 'transform', - typeof props.transform === 'string' - ? parse.transform(props.transform) - : props.transform + typeof allProps.transform === 'string' + ? parse.transform(allProps.transform) + : allProps.transform ) - const mask = objectWithKey('mask', normalizeIconArgs(maskArgs)) + const mask = objectWithKey('mask', normalizeIconArgs(allProps.mask)) const renderedIcon = icon(iconLookup, { ...classes, @@ -50,10 +71,10 @@ const FontAwesomeIcon = React.forwardRef((props, ref) => { const { abstract } = renderedIcon const extraProps = { ref } - Object.keys(props).forEach(key => { + Object.keys(allProps).forEach(key => { // eslint-disable-next-line no-prototype-builtins - if (!FontAwesomeIcon.defaultProps.hasOwnProperty(key)) { - extraProps[key] = props[key] + if (!defaultProps.hasOwnProperty(key)) { + extraProps[key] = allProps[key] } }) @@ -143,35 +164,6 @@ FontAwesomeIcon.propTypes = { swapOpacity: PropTypes.bool } -FontAwesomeIcon.defaultProps = { - border: false, - className: '', - mask: null, - maskId: null, - fixedWidth: false, - inverse: false, - flip: false, - icon: null, - listItem: false, - pull: null, - pulse: false, - rotation: null, - size: null, - spin: false, - spinPulse: false, - spinReverse: false, - beat: false, - fade: false, - beatFade: false, - bounce: false, - shake: false, - symbol: false, - title: '', - titleId: null, - transform: null, - swapOpacity: false -} - export default FontAwesomeIcon const convertCurry = convert.bind(null, React.createElement)