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

fix: update default props to JS default params #1598

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
children,
className,
critical,
dataTest,
duration,
dataTest = 'dhis2-uicore-alertbar',
duration = 8000,
hidden,
icon,
icon = true,
permanent,
success,
warning,
Expand Down Expand Up @@ -98,7 +98,7 @@
}

return clearAllTimeouts
}, [hidden])

Check warning on line 101 in components/alert/src/alert-bar/alert-bar.js

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has missing dependencies: 'inDOM', 'runHideAnimation', and 'runShowAnimation'. Either include them or remove the dependency array

return !inDOM ? null : (
<div
Expand Down Expand Up @@ -142,12 +142,6 @@
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 @@
export const Button = ({
children,
className,
dataTest,
dataTest = 'dhis2-uicore-button',
destructive,
disabled,
icon,
Expand All @@ -20,7 +20,7 @@
small,
tabIndex,
toggled,
type,
type = 'button',
value,
onBlur,
onClick,
Expand All @@ -35,7 +35,7 @@
if (initialFocus && ref.current) {
ref.current.focus()
}
}, [initialFocus, ref.current])

Check warning on line 38 in components/button/src/button/button.js

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has an unnecessary dependency: 'ref.current'. Either exclude it or remove the dependency array. Mutable values like 'ref.current' aren't valid dependencies because mutating them doesn't re-render the component

const { 'aria-label': ariaLabel, title } = otherProps

Expand Down Expand Up @@ -94,11 +94,6 @@
)
}

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

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

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

anchorRef = React.createRef()

componentDidMount() {
Expand Down Expand Up @@ -124,7 +128,7 @@ class DropdownButton extends Component {
tabIndex,
type,
initialFocus,
dataTest,
dataTest = 'dhis2-uicore-dropdownbutton',
} = this.props
const open =
typeof this.props.open === 'boolean'
Expand Down Expand Up @@ -181,10 +185,6 @@ class DropdownButton extends Component {
}
}

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

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

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

anchorRef = React.createRef()

componentDidMount() {
Expand Down Expand Up @@ -72,12 +76,13 @@ class SplitButton extends Component {
disabled,
type,
tabIndex,
dataTest,
dataTest = 'dhis2-uicore-splitbutton',
initialFocus,
} = this.props

const arrow = open ? <IconChevronUp16 /> : <IconChevronDown16 />

console.log(dataTest)
return (
<div ref={this.anchorRef} data-test={dataTest}>
<Button
Expand Down Expand Up @@ -159,10 +164,6 @@ class SplitButton extends Component {
}
}

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

SplitButton.propTypes = {
children: PropTypes.string,
className: PropTypes.string,
Expand Down
5 changes: 2 additions & 3 deletions components/calendar/src/calendar-input/calendar-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const CalendarInput = ({
width,
cellSize,
clearable,
dataTest = 'dhis2-uiwidgets-calendar-inputfield',
...rest
} = {}) => {
const ref = useRef()
Expand Down Expand Up @@ -72,6 +73,7 @@ export const CalendarInput = ({
<InputField
label={i18n.t('Pick a date')}
{...rest}
dataTest={dataTest}
type="text"
onFocus={onFocus}
value={date}
Expand Down Expand Up @@ -143,9 +145,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
12 changes: 3 additions & 9 deletions components/calendar/src/stories/calendar-story-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { Calendar } from '../calendar/calendar.js'
const { calendars, numberingSystems } = constants
export const CalendarStoryWrapper = (props) => {
const {
calendar,
calendar = 'gregory',
locale,
timeZone,
dir,
component: Component,
component: Component = Calendar,
date,
weekDayFormat,
weekDayFormat = 'narrow',
} = props
const [selectedCalendar, setSelectedCalendar] = useState(calendar)
const [selectedNumberingSystem, setSelectedNumberingSystem] = useState()
Expand Down 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
15 changes: 9 additions & 6 deletions components/center/src/center.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import PropTypes from 'prop-types'
import React, { forwardRef } from 'react'

export const Center = forwardRef(
({ className, dataTest, children, position }, ref) => (
(
{
className,
dataTest = 'dhis2-uicore-centeredcontent',
children,
position = 'middle',
},
ref
) => (
<div
className={cx('center', className, position)}
data-test={dataTest}
Expand Down Expand Up @@ -37,11 +45,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
6 changes: 1 addition & 5 deletions components/checkbox/src/checkbox-field/checkbox-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const CheckboxField = ({
required,
helpText,
validationText,
dataTest,
dataTest = 'dhis2-uiwidgets-checkboxfield',
}) => (
<Field
className={className}
Expand Down Expand Up @@ -75,10 +75,6 @@ const CheckboxField = ({
</Field>
)

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

CheckboxField.propTypes = {
checked: PropTypes.bool,
className: PropTypes.string,
Expand Down
Loading
Loading