Skip to content

Commit

Permalink
refactor: remove remaining uses of .defaultProps
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgallo committed Dec 11, 2024
1 parent 2b31cbd commit 40d3f4e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 59 deletions.
26 changes: 7 additions & 19 deletions packages/ibm-products/src/components/AddSelect/AddSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ export interface AddSelectProps {

export const AddSelect = forwardRef(
(
{ items, globalFilters, ...props }: AddSelectProps,
{
items = {
entries: [],
},
globalFilters,
...props
}: AddSelectProps,
ref: ForwardedRef<HTMLDivElement>
) => {
const useNormalizedItems = !!items.entries.find((item) => item.children);
Expand Down Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ const ButtonWrapper = ({
onClick={() => {
setIsTearsheetOpen(!isTearsheetOpen);
if (typeof onClick === 'function') {
onClick();
onClick?.();

Check warning on line 35 in packages/ibm-products/src/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js#L35

Added line #L35 was not covered by tests
}
}}
/>
);
};

ButtonWrapper.defaultProps = {
onClick: () => {},
};

ButtonWrapper.propTypes = {
iconTooltipLabel: PropTypes.string,
isTearsheetOpen: PropTypes.bool.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions packages/ibm-products/src/components/Nav/NavItemLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});

Expand All @@ -20,8 +24,4 @@ NavItemLink.propTypes = {
element: PropTypes.elementType,
};

NavItemLink.defaultProps = {
element: 'a',
};

export default NavItemLink;

0 comments on commit 40d3f4e

Please sign in to comment.