From 018c2fc26c46a5a3be5aeaf828f2ac8cca475f0c Mon Sep 17 00:00:00 2001 From: Mozafar Haider Date: Sat, 14 Sep 2024 15:15:10 +0100 Subject: [PATCH 1/7] refactor(react-18): replace defaultProps with JS default params --- components/alert/src/alert-bar/alert-bar.js | 12 ++----- components/alert/src/alert-bar/icon.js | 6 +--- .../alert/src/alert-stack/alert-stack.js | 10 +++--- components/box/src/box.js | 6 +--- .../button/src/button-strip/button-strip.js | 12 ++++--- components/button/src/button/button.js | 9 ++--- .../src/dropdown-button/dropdown-button.js | 4 --- .../button/src/split-button/split-button.js | 4 --- .../src/calendar-input/calendar-input.js | 3 -- components/calendar/src/calendar/calendar.js | 12 ++----- .../src/stories/calendar-story-wrapper.js | 6 ---- components/card/src/card.js | 6 +--- components/center/src/center.js | 5 --- .../src/checkbox-field/checkbox-field.js | 12 +++---- components/checkbox/src/checkbox/checkbox.js | 6 ---- components/chip/src/chip.js | 12 ++----- components/cover/src/cover.js | 12 ++++--- .../css/src/css-variables/css-variables.js | 16 ++++----- components/divider/src/divider.js | 12 +++---- .../field/src/field-group/field-group.js | 6 +--- components/field/src/field-set/field-set.js | 10 +++--- components/field/src/field/field.js | 6 +--- .../file-input-field-with-list.js | 9 ----- .../src/file-input-field/file-input-field.js | 16 +++------ .../file-input/src/file-input/file-input.js | 5 --- .../src/file-list/file-list-item.js | 6 +--- .../src/file-list/file-list-placeholder.js | 9 +++-- .../file-input/src/file-list/file-list.js | 10 +++--- .../header-bar/src/notification-icon.js | 6 +--- components/help/src/help.js | 13 ++++--- .../input/src/input-field/input-field.js | 4 --- components/input/src/input/input.js | 5 --- .../src/intersection-detector.js | 9 ++--- components/label/src/label.js | 6 +--- components/layer/src/layer.js | 12 ++----- components/legend/src/legend.js | 11 +++--- .../src/circular-loader/circular-loader.js | 6 +--- .../loader/src/linear-loader/linear-loader.js | 12 ++----- components/logo/src/logo.js | 35 +++++++----------- .../menu/src/flyout-menu/flyout-menu.js | 12 ++----- .../menu/src/menu-divider/menu-divider.js | 10 +++--- components/menu/src/menu-item/menu-item.js | 6 +--- .../menu-section-header.js | 6 +--- components/menu/src/menu/menu.js | 11 +++--- .../modal/src/modal-actions/modal-actions.js | 9 +++-- .../modal/src/modal-content/modal-content.js | 10 +++--- .../modal/src/modal-title/modal-title.js | 9 +++-- components/modal/src/modal/modal.js | 9 ++--- components/node/src/node.js | 6 +--- .../notice-box/src/notice-box-content.js | 10 +++--- components/notice-box/src/notice-box.js | 6 +--- .../organisation-unit-tree-root-error.js | 9 +++-- .../organisation-unit-tree-root-loading.js | 8 ++--- .../organisation-unit-tree.js | 21 ++++------- components/pagination/src/pagination.js | 24 ++++--------- components/popover/src/popover.e2e.stories.js | 5 --- components/popover/src/popover.js | 17 +++------ components/popper/src/popper.js | 12 ++----- components/radio/src/radio.js | 4 --- .../multi-select-field/multi-select-field.js | 11 ------ .../multi-select-option.js | 6 +--- components/select/src/multi-select/input.js | 6 +--- components/select/src/multi-select/menu.js | 6 +--- .../select/src/multi-select/multi-select.js | 9 ++--- components/select/src/select/input-wrapper.js | 6 +--- components/select/src/select/menu-wrapper.js | 6 +--- components/select/src/select/select.js | 4 --- .../single-select-field.js | 11 ------ .../single-select-option.js | 6 +--- components/select/src/single-select/input.js | 6 +--- components/select/src/single-select/menu.js | 6 +--- .../select/src/single-select/single-select.js | 9 ++--- .../selector-bar-item/selector-bar-item.js | 6 +--- .../src/selector-bar/selector-bar.js | 6 +--- .../src/autocomplete/autocomplete.js | 6 +--- .../src/autocomplete/menu-popup.js | 6 +--- components/sharing-dialog/src/modal/modal.js | 11 +++--- .../sharing-dialog/src/sharing-dialog.js | 30 ++++++---------- .../switch/src/switch-field/switch-field.js | 12 +++---- components/switch/src/switch/switch.js | 6 ---- components/tab/src/tab-bar/tab-bar.js | 12 ++++--- components/tab/src/tab/tab.js | 4 --- .../table/src/data-table/data-table-cell.js | 7 ---- .../data-table-column-header.js | 4 --- .../data-table-row/data-table-row.js | 4 --- components/table/src/data-table/data-table.js | 6 ---- .../data-table/table-elements/table-body.js | 4 --- .../table-data-cell/table-data-cell.js | 7 ---- .../data-table/table-elements/table-foot.js | 4 --- .../data-table/table-elements/table-head.js | 4 --- .../table-header-cell-action.js | 4 --- .../table-header-cell/table-header-cell.js | 8 ----- .../data-table/table-elements/table-row.js | 4 --- .../table-elements/table-scroll-box.js | 6 ---- .../table-elements/table-toolbar.js | 5 --- .../src/data-table/table-elements/table.js | 6 ---- .../src/stacked-table/stacked-table-body.js | 10 +++--- .../stacked-table/stacked-table-cell-head.js | 9 ++--- .../src/stacked-table/stacked-table-cell.js | 9 ++--- .../src/stacked-table/stacked-table-foot.js | 10 +++--- .../src/stacked-table/stacked-table-head.js | 10 +++--- .../stacked-table/stacked-table-row-head.js | 10 +++--- .../src/stacked-table/stacked-table-row.js | 10 +++--- .../table/src/stacked-table/stacked-table.js | 6 +--- components/table/src/table/table-body.js | 11 +++--- components/table/src/table/table-cell-head.js | 6 +--- components/table/src/table/table-cell.js | 6 +--- components/table/src/table/table-foot.js | 11 +++--- components/table/src/table/table-head.js | 11 +++--- components/table/src/table/table-row-head.js | 6 +--- components/table/src/table/table-row.js | 6 +--- components/table/src/table/table.js | 6 +--- components/tag/src/tag.js | 9 ++--- .../src/text-area-field/text-area-field.js | 12 ++----- .../text-area/src/text-area/text-area.js | 7 ---- components/tooltip/src/tooltip.js | 18 +++------- components/transfer/src/options-container.js | 6 +--- components/transfer/src/transfer-option.js | 6 +--- components/transfer/src/transfer.js | 36 ++++++------------- .../transfer/src/transfer.prod.stories.js | 11 +++--- components/user-avatar/src/text-avatar.js | 6 +--- components/user-avatar/src/user-avatar.js | 6 +--- 122 files changed, 306 insertions(+), 777 deletions(-) diff --git a/components/alert/src/alert-bar/alert-bar.js b/components/alert/src/alert-bar/alert-bar.js index 8e84bd2c23..4440e1996f 100644 --- a/components/alert/src/alert-bar/alert-bar.js +++ b/components/alert/src/alert-bar/alert-bar.js @@ -13,10 +13,10 @@ const AlertBar = ({ children, className, critical, - dataTest, - duration, + dataTest = 'dhis2-uicore-alertbar', + duration = 8000, hidden, - icon, + icon = true, permanent, success, warning, @@ -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}]`*/ diff --git a/components/alert/src/alert-bar/icon.js b/components/alert/src/alert-bar/icon.js index cb78de8a30..dec45757b7 100644 --- a/components/alert/src/alert-bar/icon.js +++ b/components/alert/src/alert-bar/icon.js @@ -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 } @@ -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, diff --git a/components/alert/src/alert-stack/alert-stack.js b/components/alert/src/alert-stack/alert-stack.js index c4b35ed022..31ce8f4838 100644 --- a/components/alert/src/alert-stack/alert-stack.js +++ b/components/alert/src/alert-stack/alert-stack.js @@ -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', +}) => (
{children} @@ -33,10 +37,6 @@ export const AlertStack = ({ className, children, dataTest }) => ( ) -AlertStack.defaultProps = { - dataTest: 'dhis2-uicore-alertstack', -} - AlertStack.propTypes = { children: PropTypes.node, className: PropTypes.string, diff --git a/components/box/src/box.js b/components/box/src/box.js index da9daa35b1..0221e1462e 100644 --- a/components/box/src/box.js +++ b/components/box/src/box.js @@ -11,7 +11,7 @@ export const Box = ({ maxWidth, marginTop, children, - dataTest, + dataTest = 'dhis2-uicore-box', className, }) => (
@@ -31,10 +31,6 @@ export const Box = ({
) -Box.defaultProps = { - dataTest: 'dhis2-uicore-box', -} - Box.propTypes = { children: PropTypes.node, className: PropTypes.string, diff --git a/components/button/src/button-strip/button-strip.js b/components/button/src/button-strip/button-strip.js index 38ccc7a8d5..3857a0b194 100644 --- a/components/button/src/button-strip/button-strip.js +++ b/components/button/src/button-strip/button-strip.js @@ -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', +}) => (
( const alignmentPropType = mutuallyExclusive(['middle', 'end'], PropTypes.bool) -ButtonStrip.defaultProps = { - dataTest: 'dhis2-uicore-buttonstrip', -} - ButtonStrip.propTypes = { children: PropTypes.node, className: PropTypes.string, diff --git a/components/button/src/button/button.js b/components/button/src/button/button.js index a920e49b77..b25843f6e7 100644 --- a/components/button/src/button/button.js +++ b/components/button/src/button/button.js @@ -8,7 +8,7 @@ import styles from './button.styles.js' export const Button = ({ children, className, - dataTest, + dataTest = 'dhis2-uicore-button', destructive, disabled, icon, @@ -20,7 +20,7 @@ export const Button = ({ small, tabIndex, toggled, - type, + type = 'button', value, onBlur, onClick, @@ -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, diff --git a/components/button/src/dropdown-button/dropdown-button.js b/components/button/src/dropdown-button/dropdown-button.js index 82abc73249..7120a625d5 100644 --- a/components/button/src/dropdown-button/dropdown-button.js +++ b/components/button/src/dropdown-button/dropdown-button.js @@ -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, diff --git a/components/button/src/split-button/split-button.js b/components/button/src/split-button/split-button.js index 4aab19d6f5..192f59ea62 100644 --- a/components/button/src/split-button/split-button.js +++ b/components/button/src/split-button/split-button.js @@ -159,10 +159,6 @@ class SplitButton extends Component { } } -SplitButton.defaultProps = { - dataTest: 'dhis2-uicore-splitbutton', -} - SplitButton.propTypes = { children: PropTypes.string, className: PropTypes.string, diff --git a/components/calendar/src/calendar-input/calendar-input.js b/components/calendar/src/calendar-input/calendar-input.js index 2a8ae395fe..cbc26d885d 100644 --- a/components/calendar/src/calendar-input/calendar-input.js +++ b/components/calendar/src/calendar-input/calendar-input.js @@ -143,9 +143,6 @@ export const CalendarInput = ({ ) } -CalendarInput.defaultProps = { - dataTest: 'dhis2-uiwidgets-calendar-inputfield', -} CalendarInput.propTypes = { ...CalendarProps, ...InputFieldProps, diff --git a/components/calendar/src/calendar/calendar.js b/components/calendar/src/calendar/calendar.js index 51176ea25d..59962a09ec 100644 --- a/components/calendar/src/calendar/calendar.js +++ b/components/calendar/src/calendar/calendar.js @@ -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' @@ -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, diff --git a/components/calendar/src/stories/calendar-story-wrapper.js b/components/calendar/src/stories/calendar-story-wrapper.js index e43ed91688..89724da63a 100644 --- a/components/calendar/src/stories/calendar-story-wrapper.js +++ b/components/calendar/src/stories/calendar-story-wrapper.js @@ -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, diff --git a/components/card/src/card.js b/components/card/src/card.js index 9319d2b974..8de324e841 100644 --- a/components/card/src/card.js +++ b/components/card/src/card.js @@ -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' }) => (
{children} @@ -23,10 +23,6 @@ const Card = ({ className, children, dataTest }) => (
) -Card.defaultProps = { - dataTest: 'dhis2-uicore-card', -} - Card.propTypes = { children: PropTypes.node, className: PropTypes.string, diff --git a/components/center/src/center.js b/components/center/src/center.js index 7222bbb4aa..09f27ab6a2 100644 --- a/components/center/src/center.js +++ b/components/center/src/center.js @@ -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, diff --git a/components/checkbox/src/checkbox-field/checkbox-field.js b/components/checkbox/src/checkbox-field/checkbox-field.js index 78e5883eed..3659bd6a5f 100644 --- a/components/checkbox/src/checkbox-field/checkbox-field.js +++ b/components/checkbox/src/checkbox-field/checkbox-field.js @@ -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', +}) => ( {label} {required && } @@ -37,7 +41,7 @@ const CheckboxField = ({ required, helpText, validationText, - dataTest, + dataTest = 'dhis2-uiwidgets-checkboxfield', }) => ( ) -CheckboxField.defaultProps = { - dataTest: 'dhis2-uiwidgets-checkboxfield', -} - CheckboxField.propTypes = { checked: PropTypes.bool, className: PropTypes.string, diff --git a/components/checkbox/src/checkbox/checkbox.js b/components/checkbox/src/checkbox/checkbox.js index c4e95492df..0a722e57c3 100644 --- a/components/checkbox/src/checkbox/checkbox.js +++ b/components/checkbox/src/checkbox/checkbox.js @@ -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 diff --git a/components/chip/src/chip.js b/components/chip/src/chip.js index 221bf677cd..c06364b3b3 100644 --- a/components/chip/src/chip.js +++ b/components/chip/src/chip.js @@ -19,11 +19,11 @@ const Chip = ({ onRemove, onClick, icon, - dataTest, - marginBottom, + dataTest = 'dhis2-uicore-chip', + marginBottom = 4, marginLeft, marginRight, - marginTop, + marginTop = 4, marginInlineStart, marginInlineEnd, }) => ( @@ -114,12 +114,6 @@ const Chip = ({ ) -Chip.defaultProps = { - dataTest: 'dhis2-uicore-chip', - marginBottom: 4, - marginTop: 4, -} - Chip.propTypes = { children: PropTypes.any, className: PropTypes.string, diff --git a/components/cover/src/cover.js b/components/cover/src/cover.js index 01b2422fdc..2ddb89ff52 100644 --- a/components/cover/src/cover.js +++ b/components/cover/src/cover.js @@ -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, +}) => (
(
) -Cover.defaultProps = { - dataTest: 'dhis2-uicore-componentcover', -} - Cover.propTypes = { children: PropTypes.node, className: PropTypes.string, diff --git a/components/css/src/css-variables/css-variables.js b/components/css/src/css-variables/css-variables.js index d1136932fa..959956efc7 100644 --- a/components/css/src/css-variables/css-variables.js +++ b/components/css/src/css-variables/css-variables.js @@ -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 @@ -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, diff --git a/components/divider/src/divider.js b/components/divider/src/divider.js index 1db09c1b3e..10f75165db 100644 --- a/components/divider/src/divider.js +++ b/components/divider/src/divider.js @@ -15,7 +15,12 @@ const flipMargin = (margin) => { return margin } -const Divider = ({ className, dataTest, dense, margin }) => { +const Divider = ({ + className, + dataTest = 'dhis2-uicore-divider', + dense, + margin = `${spacers.dp8} 0`, +}) => { return (