Skip to content

Commit

Permalink
refactor(react-18): replace defaultProps with JS default params
Browse files Browse the repository at this point in the history
  • Loading branch information
kabaros committed Sep 14, 2024
1 parent fc45bbb commit 018c2fc
Show file tree
Hide file tree
Showing 122 changed files with 306 additions and 777 deletions.
12 changes: 3 additions & 9 deletions components/alert/src/alert-bar/alert-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const AlertBar = ({
children,
className,
critical,
dataTest,
duration,
dataTest = 'dhis2-uicore-alertbar',
duration = 8000,
hidden,
icon,
icon = true,
permanent,
success,
warning,
Expand Down Expand Up @@ -142,12 +142,6 @@ const alertTypePropType = mutuallyExclusive(
PropTypes.bool
)

AlertBar.defaultProps = {
duration: 8000,
dataTest: 'dhis2-uicore-alertbar',
icon: true,
}

AlertBar.propTypes = {
/** An array of 0-2 action objects
`[{label: "Save", onClick: clickHandler}]`*/
Expand Down
6 changes: 1 addition & 5 deletions components/alert/src/alert-bar/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import PropTypes from 'prop-types'
import React from 'react'

const StatusIcon = ({ error, warning, valid, info, defaultTo }) => {
const StatusIcon = ({ error, warning, valid, info, defaultTo = null }) => {
if (error) {
return <IconErrorFilled24 color={colors.white} />
}
Expand All @@ -26,10 +26,6 @@ const StatusIcon = ({ error, warning, valid, info, defaultTo }) => {
return defaultTo
}

StatusIcon.defaultProps = {
defaultTo: null,
}

StatusIcon.propTypes = {
defaultTo: PropTypes.element,
error: PropTypes.bool,
Expand Down
10 changes: 5 additions & 5 deletions components/alert/src/alert-stack/alert-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import cx from 'classnames'
import PropTypes from 'prop-types'
import React from 'react'

export const AlertStack = ({ className, children, dataTest }) => (
export const AlertStack = ({
className,
children,
dataTest = 'dhis2-uicore-alertstack',
}) => (
<Portal>
<div className={cx(className)} data-test={dataTest}>
{children}
Expand Down Expand Up @@ -33,10 +37,6 @@ export const AlertStack = ({ className, children, dataTest }) => (
</Portal>
)

AlertStack.defaultProps = {
dataTest: 'dhis2-uicore-alertstack',
}

AlertStack.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
Expand Down
6 changes: 1 addition & 5 deletions components/box/src/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const Box = ({
maxWidth,
marginTop,
children,
dataTest,
dataTest = 'dhis2-uicore-box',
className,
}) => (
<div data-test={dataTest} className={className}>
Expand All @@ -31,10 +31,6 @@ export const Box = ({
</div>
)

Box.defaultProps = {
dataTest: 'dhis2-uicore-box',
}

Box.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
Expand Down
12 changes: 7 additions & 5 deletions components/button/src/button-strip/button-strip.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import cx from 'classnames'
import PropTypes from 'prop-types'
import React, { Children } from 'react'

const ButtonStrip = ({ className, children, middle, end, dataTest }) => (
const ButtonStrip = ({
className,
children,
middle,
end,
dataTest = 'dhis2-uicore-buttonstrip',
}) => (
<div
className={cx(className, { start: !middle && !end, middle, end })}
data-test={dataTest}
Expand Down Expand Up @@ -39,10 +45,6 @@ const ButtonStrip = ({ className, children, middle, end, dataTest }) => (

const alignmentPropType = mutuallyExclusive(['middle', 'end'], PropTypes.bool)

ButtonStrip.defaultProps = {
dataTest: 'dhis2-uicore-buttonstrip',
}

ButtonStrip.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
Expand Down
9 changes: 2 additions & 7 deletions components/button/src/button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import styles from './button.styles.js'
export const Button = ({
children,
className,
dataTest,
dataTest = 'dhis2-uicore-button',
destructive,
disabled,
icon,
Expand All @@ -20,7 +20,7 @@ export const Button = ({
small,
tabIndex,
toggled,
type,
type = 'button',
value,
onBlur,
onClick,
Expand Down Expand Up @@ -94,11 +94,6 @@ export const Button = ({
)
}

Button.defaultProps = {
type: 'button',
dataTest: 'dhis2-uicore-button',
}

Button.propTypes = {
/** Component to render inside the button */
children: PropTypes.node,
Expand Down
4 changes: 0 additions & 4 deletions components/button/src/dropdown-button/dropdown-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ class DropdownButton extends Component {
}
}

DropdownButton.defaultProps = {
dataTest: 'dhis2-uicore-dropdownbutton',
}

DropdownButton.propTypes = {
/** Children to render inside the buton */
children: PropTypes.node,
Expand Down
4 changes: 0 additions & 4 deletions components/button/src/split-button/split-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ class SplitButton extends Component {
}
}

SplitButton.defaultProps = {
dataTest: 'dhis2-uicore-splitbutton',
}

SplitButton.propTypes = {
children: PropTypes.string,
className: PropTypes.string,
Expand Down
3 changes: 0 additions & 3 deletions components/calendar/src/calendar-input/calendar-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ export const CalendarInput = ({
)
}

CalendarInput.defaultProps = {
dataTest: 'dhis2-uiwidgets-calendar-inputfield',
}
CalendarInput.propTypes = {
...CalendarProps,
...InputFieldProps,
Expand Down
12 changes: 3 additions & 9 deletions components/calendar/src/calendar/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export const Calendar = ({
dir,
locale,
numberingSystem,
weekDayFormat,
weekDayFormat = 'narrow',
timeZone,
width,
cellSize,
width = '240px',
cellSize = '32px',
}) => {
const wrapperBorderColor = colors.grey300
const backgroundColor = 'none'
Expand Down Expand Up @@ -85,12 +85,6 @@ export const Calendar = ({
)
}

Calendar.defaultProps = {
cellSize: '32px',
width: '240px',
weekDayFormat: 'narrow',
}

export const CalendarProps = {
/** the calendar to use such gregory, ethiopic, nepali - full supported list here: https://github.com/dhis2/multi-calendar-dates/blob/main/src/constants/calendars.ts */
calendar: PropTypes.any.isRequired,
Expand Down
6 changes: 0 additions & 6 deletions components/calendar/src/stories/calendar-story-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,6 @@ export const CalendarStoryWrapper = (props) => {
)
}

CalendarStoryWrapper.defaultProps = {
calendar: 'gregorian',
component: Calendar,
weekDayFormat: 'narrow',
}

CalendarStoryWrapper.propTypes = {
calendar: PropTypes.string.isRequired,
component: PropTypes.elementType.isRequired,
Expand Down
6 changes: 1 addition & 5 deletions components/card/src/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cx from 'classnames'
import PropTypes from 'prop-types'
import React from 'react'

const Card = ({ className, children, dataTest }) => (
const Card = ({ className, children, dataTest = 'dhis2-uicore-card' }) => (
<div className={cx(className)} data-test={dataTest}>
{children}

Expand All @@ -23,10 +23,6 @@ const Card = ({ className, children, dataTest }) => (
</div>
)

Card.defaultProps = {
dataTest: 'dhis2-uicore-card',
}

Card.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
Expand Down
5 changes: 0 additions & 5 deletions components/center/src/center.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ export const Center = forwardRef(

Center.displayName = 'Center'

Center.defaultProps = {
dataTest: 'dhis2-uicore-centeredcontent',
position: 'middle',
}

Center.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
Expand Down
12 changes: 6 additions & 6 deletions components/checkbox/src/checkbox-field/checkbox-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import PropTypes from 'prop-types'
import React from 'react'
import { Checkbox } from '../checkbox/index.js'

const AddRequired = ({ label, required, dataTest }) => (
const AddRequired = ({
label,
required,
dataTest = 'dhis2-uiwidgets-checkboxfield',
}) => (
<React.Fragment>
{label}
{required && <Required dataTest={`${dataTest}-required`} />}
Expand Down Expand Up @@ -37,7 +41,7 @@ const CheckboxField = ({
required,
helpText,
validationText,
dataTest,
dataTest = 'dhis2-uiwidgets-checkboxfield',
}) => (
<Field
className={className}
Expand Down Expand Up @@ -75,10 +79,6 @@ const CheckboxField = ({
</Field>
)

CheckboxField.defaultProps = {
dataTest: 'dhis2-uiwidgets-checkboxfield',
}

CheckboxField.propTypes = {
checked: PropTypes.bool,
className: PropTypes.string,
Expand Down
6 changes: 0 additions & 6 deletions components/checkbox/src/checkbox/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,6 @@ class Checkbox extends Component {
}
}

Checkbox.defaultProps = {
checked: false,
indeterminate: false,
dataTest: 'dhis2-uicore-checkbox',
}

const uniqueOnStatePropType = mutuallyExclusive(
['checked', 'indeterminate'],
PropTypes.bool
Expand Down
12 changes: 3 additions & 9 deletions components/chip/src/chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const Chip = ({
onRemove,
onClick,
icon,
dataTest,
marginBottom,
dataTest = 'dhis2-uicore-chip',
marginBottom = 4,
marginLeft,
marginRight,
marginTop,
marginTop = 4,
marginInlineStart,
marginInlineEnd,
}) => (
Expand Down Expand Up @@ -114,12 +114,6 @@ const Chip = ({
</span>
)

Chip.defaultProps = {
dataTest: 'dhis2-uicore-chip',
marginBottom: 4,
marginTop: 4,
}

Chip.propTypes = {
children: PropTypes.any,
className: PropTypes.string,
Expand Down
12 changes: 7 additions & 5 deletions components/cover/src/cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ const createClickHandler = (onClick) => (event) => {
}
}

const Cover = ({ children, className, dataTest, onClick, translucent }) => (
const Cover = ({
children,
className,
dataTest = 'dhis2-uicore-componentcover',
onClick,
translucent,
}) => (
<div
className={cx(className, { translucent })}
onClick={createClickHandler(onClick)}
Expand All @@ -33,10 +39,6 @@ const Cover = ({ children, className, dataTest, onClick, translucent }) => (
</div>
)

Cover.defaultProps = {
dataTest: 'dhis2-uicore-componentcover',
}

Cover.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
Expand Down
16 changes: 7 additions & 9 deletions components/css/src/css-variables/css-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ const toCustomPropertyString = (themeSection) =>
.map(([key, value]) => `--${key}: ${value};`)
.join('\n')

const CssVariables = ({ colors, theme, layers, spacers, elevations }) => {
const CssVariables = ({
colors = false,
theme = false,
layers = false,
spacers = false,
elevations = false,
}) => {
const allowedProps = { colors, theme, layers, spacers, elevations }
const variables = Object.keys(allowedProps)
// Filter all props that are false
Expand All @@ -36,14 +42,6 @@ const CssVariables = ({ colors, theme, layers, spacers, elevations }) => {
)
}

CssVariables.defaultProps = {
colors: false,
theme: false,
layers: false,
spacers: false,
elevations: false,
}

CssVariables.propTypes = {
colors: PropTypes.bool,
elevations: PropTypes.bool,
Expand Down
Loading

0 comments on commit 018c2fc

Please sign in to comment.