Skip to content

Commit

Permalink
chore: remove all default props
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaofan2406 committed Jul 10, 2024
1 parent 2c5c7fb commit 15f5f88
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 110 deletions.
7 changes: 1 addition & 6 deletions src/components/Accordion/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Card from '../Card';
import Panel from '../Panel';
import invariant from '../../invariant';

const Accordion = ({ dts, children, maxExpand, defaultActivePanelIds, onPanelClick }) => {
const Accordion = ({ dts, children, maxExpand = 'max', defaultActivePanelIds = [], onPanelClick }) => {
const [activePanelIds, setActivePanelIds] = React.useState(() => {
return maxExpand === 'max' ? defaultActivePanelIds : _.slice(defaultActivePanelIds, 0, maxExpand);
});
Expand Down Expand Up @@ -78,10 +78,5 @@ Accordion.propTypes = {
maxExpand: PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(['max'])]),
};

Accordion.defaultProps = {
maxExpand: 'max',
defaultActivePanelIds: [],
};

Accordion.Panel = Panel;
export default Accordion;
6 changes: 1 addition & 5 deletions src/components/Alert/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { expandDts } from '../../utils';
import './styles.css';

const Alert = ({ type, children, dts }) => (
const Alert = ({ type = 'info', children, dts }) => (
<div data-testid="alert-wrapper" className={`alert-component alert-component-${type}`} {...expandDts(dts)}>
{children}
</div>
Expand All @@ -18,8 +18,4 @@ Alert.propTypes = {
dts: PropTypes.string,
};

Alert.defaultProps = {
type: 'info',
};

export default Alert;
18 changes: 10 additions & 8 deletions src/components/Breadcrumb/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ import PropTypes from 'prop-types';
import BreadcrumbNode from './Node';
import './styles.css';

const Breadcrumb = ({ rootNode, className, divider, nodes, onClick, disabled }) => {
const defaultRootNode = { id: 'all', label: 'All' };

const Breadcrumb = ({
rootNode = defaultRootNode,
className,
divider = '>',
nodes = [],
onClick,
disabled = false,
}) => {
const baseClass = 'aui--breadcrumb';
const classNames = classnames(baseClass, { [`${baseClass}--disabled`]: disabled }, className);
const onClickFunc = (newActiveId) => !disabled && onClick(newActiveId);
Expand Down Expand Up @@ -46,11 +55,4 @@ Breadcrumb.propTypes = {
className: PropTypes.string,
};

Breadcrumb.defaultProps = {
rootNode: { id: 'all', label: 'All' },
divider: '>',
nodes: [],
disabled: false,
};

export default Breadcrumb;
8 changes: 1 addition & 7 deletions src/components/Card/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
import { expandDts } from '../../utils';
import './styles.css';

const CardContent = ({ children, className, stretch, fill, append, dts }) => {
const CardContent = ({ children, className, stretch = false, fill = false, append = false, dts }) => {
const contentClassNames = classnames('card-component-content', { stretch, fill, append }, className);
return (
<div data-testid="card-content-wrapper" className={contentClassNames} {...expandDts(dts)}>
Expand All @@ -23,12 +23,6 @@ CardContent.propTypes = {
dts: PropTypes.string,
};

CardContent.defaultProps = {
fill: false,
stretch: false,
append: false,
};

const Card = ({ children, className, accent, dts }) => {
const baseClass = 'card-component';
const containerClassNames = classnames(baseClass, { [`accent accent-${accent}`]: accent }, className);
Expand Down
47 changes: 30 additions & 17 deletions src/components/Carousel/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,36 @@ import './styles.css';

const baseClass = 'aui--carousel-component';

const Carousel = React.forwardRef((props, ref) => {
const { className, children } = props;

return (
<Slider {...props} ref={ref} className={classNames(baseClass, className)}>
{children}
</Slider>
);
});
const Carousel = React.forwardRef(
(
{
className,
children,
autoplay = true,
variableWidth = true,
autoplaySpeed = 10000,
slidesToShow = 2,
dots = true,
...rest
},
ref
) => {
return (
<Slider
{...rest}
ref={ref}
autoplay={autoplay}
variableWidth={variableWidth}
autoplaySpeed={autoplaySpeed}
slidesToShow={slidesToShow}
dots={dots}
className={classNames(baseClass, className)}
>
{children}
</Slider>
);
}
);

Carousel.propTypes = {
className: PropTypes.string,
Expand All @@ -28,14 +49,6 @@ Carousel.propTypes = {
dots: PropTypes.bool,
};

Carousel.defaultProps = {
autoplay: true,
variableWidth: true,
autoplaySpeed: 10000,
slidesToShow: 2,
dots: true,
};

const SWIPE_DELTA = 3;

const usePreventCarouselSwipeClicks = () => {
Expand Down
6 changes: 1 addition & 5 deletions src/components/CountBadge/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { expandDts } from '../../utils';
import './styles.css';

const CountBadge = ({ value, status, dts }) => {
const CountBadge = ({ value, status = 'default', dts }) => {
const fontSize = value > 99 ? 'small' : 'normal';
const classNames = `count-badge status-${status} count-badge-font-size-${fontSize}`;
return (
Expand All @@ -28,8 +28,4 @@ CountBadge.propTypes = {
dts: PropTypes.string,
};

CountBadge.defaultProps = {
status: 'default',
};

export default CountBadge;
6 changes: 1 addition & 5 deletions src/components/Empty/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import './styles.css';

const Empty = ({ collection, text, icon }) => {
const Empty = ({ collection, text = 'Nothing to show.', icon }) => {
if (_.isEmpty(collection)) {
return (
<div data-testid="empty-wrapper" className="empty-component">
Expand All @@ -24,8 +24,4 @@ Empty.propTypes = {
icon: PropTypes.node,
};

Empty.defaultProps = {
text: 'Nothing to show.',
};

export default Empty;
7 changes: 1 addition & 6 deletions src/components/FormGroup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash';
import React from 'react';
import PropTypes from 'prop-types';

const FormGroup = ({ addon, disabled, helpText, label, onChange, placeholder, value }) => {
const FormGroup = ({ addon, disabled = false, helpText, label, onChange, placeholder, value = '' }) => {
const addonElement = addon ? <div className="input-group-addon">{addon}</div> : null;
const inputId = _.kebabCase(label);
return (
Expand Down Expand Up @@ -42,9 +42,4 @@ FormGroup.propTypes = {
value: PropTypes.string,
};

FormGroup.defaultProps = {
disabled: false,
value: '',
};

export default FormGroup;
8 changes: 1 addition & 7 deletions src/components/Grid/Cell/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import { expandDts, classSuffixHelper } from '../../../utils';
import './styles.css';

const GridCell = ({ children, classSuffixes, onClick, stretch, dts, addonClassNames }) => {
const GridCell = ({ children, classSuffixes = [], onClick, stretch = false, dts, addonClassNames = [] }) => {
const componentClass = 'grid-component-cell';
const classesList = classSuffixHelper({
classSuffixes,
Expand Down Expand Up @@ -48,10 +48,4 @@ GridCell.propTypes = {
stretch: PropTypes.bool,
};

GridCell.defaultProps = {
addonClassNames: [],
classSuffixes: [],
stretch: false,
};

export default GridCell;
16 changes: 8 additions & 8 deletions src/components/Grid/Row/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import PropTypes from 'prop-types';
import { classSuffixHelper, expandDts } from '../../../utils';
import './styles.css';

const GridRow = ({ horizontalBorder, short, type, verticalCellBorder, children, dts }) => {
const GridRow = ({
horizontalBorder = true,
short = false,
type = 'body',
verticalCellBorder = false,
children,
dts,
}) => {
const componentClass = 'grid-component-row';
const classesList = classSuffixHelper({
classSuffixes: [type],
Expand Down Expand Up @@ -45,11 +52,4 @@ GridRow.propTypes = {
dts: PropTypes.string,
};

GridRow.defaultProps = {
horizontalBorder: true,
short: false,
type: 'body',
verticalCellBorder: false,
};

export default GridRow;
6 changes: 1 addition & 5 deletions src/components/HelpIconPopover/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { expandDts } from '../../utils';
import Popover from '../Popover';
import './styles.css';

const HelpIconPopover = ({ children, id, placement }) => (
const HelpIconPopover = ({ children, id, placement = 'right' }) => (
<div {...expandDts(id)} data-testid="help-icon-popover-wrapper" className="help-icon-popover-component">
<Popover triggers={['hover']} placement={placement} popoverContent={children}>
<div data-testid="help-icon-popover-trigger" className="help-icon-popover-component-trigger" />
Expand All @@ -18,8 +18,4 @@ HelpIconPopover.propTypes = {
placement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
};

HelpIconPopover.defaultProps = {
placement: 'right',
};

export default HelpIconPopover;
6 changes: 1 addition & 5 deletions src/components/Pill/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import './styles.css';

const sizes = ['large', 'medium', 'small'];

const Pill = ({ className, children, onClick, size, dts }) => (
const Pill = ({ className, children, onClick, size = sizes[1], dts }) => (
<div
className={classnames('aui--pill', `aui--pill-${size}`, { 'aui--pill-clickable': onClick }, className)}
onClick={onClick}
Expand All @@ -16,10 +16,6 @@ const Pill = ({ className, children, onClick, size, dts }) => (
</div>
);

Pill.defaultProps = {
size: sizes[1],
};

Pill.propTypes = {
/**
* Content inside pill
Expand Down
6 changes: 1 addition & 5 deletions src/components/PrettyDiff/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import './styles.css';

const PrettyDiff = ({ newText, oldText }) => {
const PrettyDiff = ({ newText = '', oldText = '' }) => {
const dmp = new DiffMatchPatch();
const diffs = dmp.diff_main(oldText, newText);

Expand Down Expand Up @@ -34,9 +34,5 @@ PrettyDiff.propTypes = {
newText: PropTypes.string,
oldText: PropTypes.string,
};
PrettyDiff.defaultProps = {
newText: '',
oldText: '',
};

export default PrettyDiff;
7 changes: 1 addition & 6 deletions src/components/Skeleton/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
import { expandDts } from '../../utils';
import './styles.css';

const Skeleton = ({ animated, className, dts, height, variant, width }) => {
const Skeleton = ({ animated = true, className, dts, height, variant = 'text', width }) => {
const baseClass = 'aui--skeleton';
const variantClass = () => (_.includes(['rect', 'circle', 'text'], variant) ? `${baseClass}-${variant}` : '');

Expand Down Expand Up @@ -40,9 +40,4 @@ Skeleton.propTypes = {
width: PropTypes.string,
};

Skeleton.defaultProps = {
animated: true,
variant: 'text',
};

export default Skeleton;
5 changes: 1 addition & 4 deletions src/components/Slicey/Marker/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { ROUND, QUARTER, getPointX, getPointY } from '../dataProcessor';
import './styles.css';

const Marker = ({ fraction }) => {
const Marker = ({ fraction = 0 }) => {
const getMarkerPoints = (markerValue) => {
const pointOnCircle = ROUND * markerValue - QUARTER;
return `${getPointX(pointOnCircle)},${getPointY(pointOnCircle)} 0,0`;
Expand All @@ -17,8 +17,5 @@ const Marker = ({ fraction }) => {
Marker.propTypes = {
fraction: PropTypes.number,
};
Marker.defaultProps = {
fraction: 0,
};

export default Marker;
6 changes: 1 addition & 5 deletions src/components/TileGrid/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const defaultWidth = 204; // 204px
const defaultMaxWidth = 295; // 295px
const baseClass = 'tile-grid-component';

const TileGrid = ({ title, items, onItemClick, distributed }) => {
const TileGrid = ({ title, items, onItemClick, distributed = false }) => {
const cardList = _.map(items, (item) => {
const itemClassNames = classnames(`${baseClass}-item`, `${baseClass}-item-${item.classSuffix}`, {
[`${baseClass}-item-distributed`]: distributed,
Expand Down Expand Up @@ -67,10 +67,6 @@ const TileGrid = ({ title, items, onItemClick, distributed }) => {
);
};

TileGrid.defaultProps = {
distributed: false,
};

TileGrid.propTypes = {
title: PropTypes.node,
/**
Expand Down
7 changes: 1 addition & 6 deletions src/components/Totals/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Grid from '../Grid';
import GridCell from '../Grid/Cell';
import GridRow from '../Grid/Row';

const Totals = ({ toSum, valueFormatter }) => (
const Totals = ({ toSum = [], valueFormatter = (value) => `${value}` }) => (
<Grid>
{_(toSum)
.reject({ isHidden: true })
Expand Down Expand Up @@ -38,9 +38,4 @@ Totals.propTypes = {
valueFormatter: PropTypes.func,
};

Totals.defaultProps = {
toSum: [],
valueFormatter: (value) => `${value}`,
};

export default Totals;

0 comments on commit 15f5f88

Please sign in to comment.