From 40d3f4edb0a97eacff6542010cdfc7882b979fd3 Mon Sep 17 00:00:00 2001 From: Matt Gallo Date: Wed, 11 Dec 2024 13:51:36 -0500 Subject: [PATCH] refactor: remove remaining uses of .defaultProps --- .../src/components/AddSelect/AddSelect.tsx | 26 +++----- .../addons/CustomizeColumns/ButtonWrapper.js | 6 +- .../addons/RowSize/RowSizeRadioGroup.js | 61 ++++++++++--------- .../src/components/Nav/NavItemLink.js | 10 +-- 4 files changed, 44 insertions(+), 59 deletions(-) diff --git a/packages/ibm-products/src/components/AddSelect/AddSelect.tsx b/packages/ibm-products/src/components/AddSelect/AddSelect.tsx index 474ac88a1f..f49e46eda0 100644 --- a/packages/ibm-products/src/components/AddSelect/AddSelect.tsx +++ b/packages/ibm-products/src/components/AddSelect/AddSelect.tsx @@ -56,7 +56,13 @@ export interface AddSelectProps { export const AddSelect = forwardRef( ( - { items, globalFilters, ...props }: AddSelectProps, + { + items = { + entries: [], + }, + globalFilters, + ...props + }: AddSelectProps, ref: ForwardedRef ) => { const useNormalizedItems = !!items.entries.find((item) => item.children); @@ -179,22 +185,4 @@ AddSelect.propTypes = { title: PropTypes.string.isRequired, }; -AddSelect.defaultProps = { - closeIconDescription: '', - description: '', - itemsLabel: '', - items: { - entries: [], - }, - multi: false, - noResultsDescription: '', - noResultsTitle: '', - onClose: () => {}, - onCloseButtonText: '', - onSubmit: () => {}, - onSubmitButtonText: '', - open: false, - title: '', -}; - AddSelect.displayName = componentName; diff --git a/packages/ibm-products/src/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js b/packages/ibm-products/src/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js index c970b76fdf..5828d499ed 100644 --- a/packages/ibm-products/src/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +++ b/packages/ibm-products/src/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js @@ -32,17 +32,13 @@ const ButtonWrapper = ({ onClick={() => { setIsTearsheetOpen(!isTearsheetOpen); if (typeof onClick === 'function') { - onClick(); + onClick?.(); } }} /> ); }; -ButtonWrapper.defaultProps = { - onClick: () => {}, -}; - ButtonWrapper.propTypes = { iconTooltipLabel: PropTypes.string, isTearsheetOpen: PropTypes.bool.isRequired, diff --git a/packages/ibm-products/src/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js b/packages/ibm-products/src/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js index aa0393ff84..06bf011620 100644 --- a/packages/ibm-products/src/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +++ b/packages/ibm-products/src/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js @@ -13,20 +13,42 @@ import { pkg } from '../../../../../settings'; const blockClass = `${pkg.prefix}--datagrid__row-size`; +const defaults = { + rowSizes: [ + { + value: 'xl', // 64 + }, + { + value: 'lg', // 48 + }, + { + value: 'md', // 40 + }, + { + value: 'sm', // 32 + }, + { + value: 'xs', // 24 + }, + ], + rowSizeLabels: { + xl: 'Extra large', + lg: 'Large (default)', + md: 'Medium', + sm: 'Small', + xs: 'Extra small', + }, + selectedOption: 'lg', +}; + const RowSizeRadioGroup = forwardRef( ( { - rowSizes, - selectedOption, + rowSizes = defaults.rowSizes, + selectedOption = defaults.selectedOption, onChange, legendText, - rowSizeLabels = { - xl: 'Extra large', - lg: 'Large (default)', - md: 'Medium', - sm: 'Small', - xs: 'Extra small', - }, + rowSizeLabels = defaults.rowSizeLabels, tableId, }, ref @@ -76,27 +98,6 @@ const getBackwardCompatibleRowSize = (rowSize) => { return rowSizeMap[rowSize] || rowSize; }; -RowSizeRadioGroup.defaultProps = { - rowSizes: [ - { - value: 'xl', // 64 - }, - { - value: 'lg', // 48 - }, - { - value: 'md', // 40 - }, - { - value: 'sm', // 32 - }, - { - value: 'xs', // 24 - }, - ], - selectedOption: 'lg', -}; - RowSizeRadioGroup.propTypes = { legendText: PropTypes.string, onChange: PropTypes.func.isRequired, diff --git a/packages/ibm-products/src/components/Nav/NavItemLink.js b/packages/ibm-products/src/components/Nav/NavItemLink.js index 384147db46..756b3673a6 100644 --- a/packages/ibm-products/src/components/Nav/NavItemLink.js +++ b/packages/ibm-products/src/components/Nav/NavItemLink.js @@ -8,8 +8,12 @@ import PropTypes from 'prop-types'; import React from 'react'; +const defaults = { + element: 'a', +}; + const NavItemLink = React.forwardRef(function NavItemLink(props, ref) { - const { element, ...rest } = props; + const { element = defaults.element, ...rest } = props; return React.createElement(element, { ...rest, ref }); }); @@ -20,8 +24,4 @@ NavItemLink.propTypes = { element: PropTypes.elementType, }; -NavItemLink.defaultProps = { - element: 'a', -}; - export default NavItemLink;