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

STCOM-1291 avoid defaultProps in functional components #2285

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* `<MultiSelection/>`'s overlay will use the overlay container as its boundary when the `renderToOverlay` prop is applied, as opposed to the scrollParent of the control. Refs STCOM-1282.
* Add `isCursorAtEnd` property to `TextArea` to place the cursor at the end of the value. Refs STCOM-1289.
* Focus the last modified query field when opening `<AdvancedSearch>`. Refs STCOM-1288.
* Avoid deprecated `defaultProps` for functional components. Refs STCOM-1291.

## [12.1.0](https://github.com/folio-org/stripes-components/tree/v12.1.0) (2024-03-12)
[Full Changelog](https://github.com/folio-org/stripes-components/compare/v12.0.0...v12.1.0)
Expand Down
19 changes: 7 additions & 12 deletions lib/Accordion/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,27 @@ const getHighestStackOrder = () => {
return highest;
}


const Accordion = (props) => {
const {
accordionSet,
children,
className = '',
closedByDefault,
contentHeight,
contentId: contentIdProp,
contentRef,
disabled,
header,
headerProps,
header = DefaultAccordionHeader,
headerProps = { headingLevel: 3 },
id,
label,
onClickToggle = noop,
onToggle: onToggleProp,
open,
separator,
separator = true,
toggleKeyHandlers,
toggleKeyMap,
className,
onClickToggle,
label,
} = props;

const toggle = useRef(null);
Expand Down Expand Up @@ -236,11 +237,5 @@ const Accordion = (props) => {
};

Accordion.propTypes = propTypes;
Accordion.defaultProps = {
className: '',
header: DefaultAccordionHeader,
separator: true,
onClickToggle: noop,
};

export default withAccordionSet(Accordion);
10 changes: 2 additions & 8 deletions lib/Accordion/headers/DefaultAccordionHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ const propTypes = {
toggleRef: PropTypes.func,
};

const defaultProps = {
headerProps: {
headingLevel: 3,
}
};

const DefaultAccordionHeader = (props) => {
const DefaultAccordionHeader = ({ headerProps = { headingLevel: 3 }, ...rest }) => {
const props = { headerProps, ...rest };
function handleHeaderClick(e) {
const { id, label } = props;
props.onToggle({ id, label });
Expand Down Expand Up @@ -92,6 +87,5 @@ const DefaultAccordionHeader = (props) => {
};

DefaultAccordionHeader.propTypes = propTypes;
DefaultAccordionHeader.defaultProps = defaultProps;

export default DefaultAccordionHeader;
20 changes: 6 additions & 14 deletions lib/AdvancedSearch/AdvancedSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ const AdvancedSearch = ({
searchOptions,
onSearch,
onCancel,
queryBuilder,
rowFormatter,
hasQueryOption,
hasMatchSelection,
defaultSearchOptionValue,
firstRowInitialSearch,
queryBuilder = defaultQueryBuilder,
rowFormatter = defaultRowFormatter,
hasQueryOption = true,
hasMatchSelection = true,
defaultSearchOptionValue = '',
firstRowInitialSearch = null,
queryToRow,
children,
}) => {
Expand Down Expand Up @@ -103,13 +103,5 @@ const AdvancedSearch = ({
};

AdvancedSearch.propTypes = propTypes;
AdvancedSearch.defaultProps = {
queryBuilder: defaultQueryBuilder,
defaultSearchOptionValue: '',
rowFormatter: defaultRowFormatter,
firstRowInitialSearch: null,
hasQueryOption: true,
hasMatchSelection: true,
};

export default AdvancedSearch;
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const AdvancedSearchRow = ({
rowState,
searchOptions,
onChange,
errorMessage,
errorMessage = '',
hasMatchSelection,
}) => {
const intl = useIntl();
Expand Down Expand Up @@ -134,8 +134,5 @@ const AdvancedSearchRow = ({
};

AdvancedSearchRow.propTypes = propTypes;
AdvancedSearchRow.defaultProps = {
errorMessage: '',
};

export default AdvancedSearchRow;
16 changes: 8 additions & 8 deletions lib/Badge/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import PropTypes from 'prop-types';
import classnames from 'classnames';
import css from './Badge.css';

const Badge = props => (
<span className={classnames(props.className, css.badge, css[props.color], css[props.size])}>
<span className={css.label}>{props.children}</span>
const Badge = ({
children,
className,
color = 'default',
size = 'medium',
}) => (
<span className={classnames(className, css.badge, css[color], css[size])}>
<span className={css.label}>{children}</span>
</span>
);

Expand All @@ -16,9 +21,4 @@ Badge.propTypes = {
size: PropTypes.oneOf(['small', 'medium']),
};

Badge.defaultProps = {
color: 'default',
size: 'medium',
};

export default Badge;
70 changes: 36 additions & 34 deletions lib/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,60 @@ export const propTypes = {
type: PropTypes.string,
};

const defaultProps = {
buttonStyle: 'default',
type: 'button',
};

const Button = React.forwardRef((props, ref) => {
const Button = React.forwardRef((
{
align,
allowAnchorClick,
autoFocus,
bottomMargin0,
zburke marked this conversation as resolved.
Show resolved Hide resolved
buttonClass,
buttonRef,
buttonStyle = 'default',
children,
fullWidth,
href,
marginBottom0,
onClick,
paddingSide0,
role,
to,
type = 'button',
...rest
},
ref) => {
function getStyle() {
const buttonBuiltIn = [];
if (/\s/.test(props.buttonStyle)) {
const csslist = props.buttonStyle.split(/\s+/);
if (/\s/.test(buttonStyle)) {
const csslist = buttonStyle.split(/\s+/);
csslist.forEach((classname) => { buttonBuiltIn.push(css[classname]); });
} else {
buttonBuiltIn.push(css[props.buttonStyle]);
buttonBuiltIn.push(css[buttonStyle]);
}
return className(
css.button,
buttonBuiltIn,
{ [`${css.marginBottom0}`]: props.marginBottom0 },
{ [`${css.marginBottom0}`]: props.bottomMargin0 },
{ [`${css.paddingSide0}`]: props.paddingSide0 },
{ [`${css.fullWidth}`]: props.fullWidth },
{ [`${css[`align-${props.align}`]}`]: props.align },
props.buttonClass,
{ [`${css.marginBottom0}`]: marginBottom0 },
{ [`${css.marginBottom0}`]: bottomMargin0 },
{ [`${css.paddingSide0}`]: paddingSide0 },
{ [`${css.fullWidth}`]: fullWidth },
{ [`${css[`align-${align}`]}`]: align },
buttonClass,
);
}

function handleAnchorClick(e) {
if (e && !props.allowAnchorClick) e.preventDefault();
if (props.onClick) {
props.onClick(e);
if (e && !allowAnchorClick) e.preventDefault();
if (onClick) {
onClick(e);
}
}

const inputCustom = omitProps(props, [
'buttonClass',
'buttonStyle',
'bottomMargin0',
'marginBottom0',
'paddingSide0',
'align',
const inputCustom = omitProps(rest, [
'hollow',
'fullWidth',
'bsRole',
'bsClass',
'onClick',
'allowAnchorClick',
'buttonRef',
'type',
'to',
]);
const { children, onClick, type, to, buttonRef } = props;

const sharedProps = {
...inputCustom,
Expand All @@ -106,11 +109,11 @@ const Button = React.forwardRef((props, ref) => {

// Render a regular anchor tag
// if the "href" prop is provided
if (props.href) {
if (href) {
return (
<a
role="button"
href={props.href}
href={href}
{...sharedProps}
onClick={handleAnchorClick}
ref={buttonRef || ref}
Expand All @@ -136,6 +139,5 @@ const Button = React.forwardRef((props, ref) => {

Button.displayName = 'Button';
Button.propTypes = propTypes;
Button.defaultProps = defaultProps;

export default Button;
22 changes: 7 additions & 15 deletions lib/ButtonGroup/ButtonGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@ const propTypes = {
tagName: PropTypes.string,
};

const defaultProps = {
fullWidth: false,
tagName: 'div'
};

const ButtonGroup = (props) => {
const {
children,
className,
fullWidth,
tagName: Tag,
...rest
} = props;

const ButtonGroup = ({
children,
className,
fullWidth = false,
tagName: Tag = 'div',
...rest
}) => {
return (
<Tag
className={
Expand All @@ -41,6 +34,5 @@ const ButtonGroup = (props) => {
};

ButtonGroup.propTypes = propTypes;
ButtonGroup.defaultProps = defaultProps;

export default ButtonGroup;
55 changes: 28 additions & 27 deletions lib/Callout/CalloutElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,36 @@ const propTypes = {
type: PropTypes.string,
};

const defaultProps = {
timeout: '6000',
transition: 'slide',
type: 'success',
};

const CalloutElement = props => (
<Transition
{...props}
timeout={300}
appear
>
{transitionState => (
<div className={css.calloutRow}>
<div
className={getClassNamefromTransitionState(transitionState, props.type, css.calloutBase, props.transition)}
data-test-callout-element
id={props.id}
>
<Icon icon={getIconForType(props.type)} />
<div className={css.message}>{props.message}</div>
<IconButton icon="times" onClick={() => props.onDismiss(props.id)} data-test-callout-element-close-button />
const CalloutElement = ({
timeout = '6000',
transition = 'slide',
type = 'success',
...rest
}) => {
const props = { timeout, transition, type, ...rest };
return (
<Transition
{...props}
timeout={300}
appear
>
{transitionState => (
<div className={css.calloutRow}>
<div
className={getClassNamefromTransitionState(transitionState, props.type, css.calloutBase, props.transition)}
data-test-callout-element
id={props.id}
>
<Icon icon={getIconForType(props.type)} />
<div className={css.message}>{props.message}</div>
<IconButton icon="times" onClick={() => props.onDismiss(props.id)} data-test-callout-element-close-button />
</div>
</div>
</div>
)}
</Transition>
);
)}
</Transition>
);
}

CalloutElement.propTypes = propTypes;
CalloutElement.defaultProps = defaultProps;

export default CalloutElement;
Loading
Loading