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

feat: remove defaultProps #551

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
88 changes: 40 additions & 48 deletions src/components/FontAwesomeIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]
}
})

Expand Down Expand Up @@ -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)