Skip to content

Commit

Permalink
refactor: remove default prop usage
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgallo committed Dec 12, 2024
1 parent ca0f50b commit 90ec4ee
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import {
Email,
} from '@carbon/react/icons';

const defaults = {
color: 'light',
disabled: false,
actionIcon: '',
};

export default class ArticleCard extends React.Component {
render() {
const {
Expand All @@ -20,9 +26,9 @@ export default class ArticleCard extends React.Component {
author,
date,
readTime,
color,
disabled,
actionIcon,
color = defaults.color,
disabled = defaults.disabled,
actionIcon = defaults.actionIcon,
className,
...rest
} = this.props;
Expand Down Expand Up @@ -168,9 +174,3 @@ ArticleCard.propTypes = {
*/
className: PropTypes.string,
};

ArticleCard.defaultProps = {
color: 'light',
disabled: false,
actionIcon: '',
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ const Anchor = ({ id, string, position }) => {
);
};

const AutolinkHeader = ({ is: Component, className, ...props }) => {
const defaults = {
is: 'h2',
};

const AutolinkHeader = ({
is: Component = defaults.is,
className,
...props
}) => {
const isMobile = useMedia({ maxWidth: breakpoints.md.width });

const string = React.Children.map(
Expand All @@ -48,6 +56,4 @@ const AutolinkHeader = ({ is: Component, className, ...props }) => {
);
};

AutolinkHeader.defaultProps = { is: 'h2' };

export default AutolinkHeader;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { CheckmarkFilled, Misuse } from '@carbon/react/icons';
import { Column } from '../Grid';
import * as styles from './DoDontRow.module.scss';

const defaults = {
type: 'do',
};
export default class DoDont extends React.Component {
static renderCaption = (caption, captionTitle) => {
if (caption || captionTitle) {
Expand All @@ -25,7 +28,7 @@ export default class DoDont extends React.Component {
text,
aspectRatio,
color,
type,
type = defaults.type,
className,
...columnProps
} = this.props;
Expand Down Expand Up @@ -79,10 +82,6 @@ export default class DoDont extends React.Component {
}
}

DoDont.defaultProps = {
type: 'do',
};

DoDont.propTypes = {
children: PropTypes.node,
/** title for the caption (optional) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { AspectRatio } from '@carbon/react';
import { Row, Column } from '../Grid';
import ResourceCard from '../ResourceCard';

const defaults = {
disabled: false,
actionIcon: 'launch',
};
export default class FeatureCard extends React.Component {
render() {
const {
Expand All @@ -14,8 +18,8 @@ export default class FeatureCard extends React.Component {
subTitle,
title,
color,
disabled,
actionIcon,
disabled = defaults.disabled,
actionIcon = defaults.actionIcon,
className,
...resourceCardProps
} = this.props;
Expand Down Expand Up @@ -123,8 +127,3 @@ FeatureCard.propTypes = {
*/
resourceCardProps: PropTypes.object,
};

FeatureCard.defaultProps = {
disabled: false,
actionIcon: 'launch',
};
66 changes: 35 additions & 31 deletions packages/gatsby-theme-carbon/src/components/Footer/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,41 @@ import {
content,
} from './Footer.module.scss';

const Footer = ({ Content, links, Logo }) => {
const defaults = {
links: {
firstCol: [
{ href: 'https://www.ibm.com/design', linkText: 'Sample' },
{ href: 'https://www.ibm.com/design', linkText: 'Links' },
{
href: 'https://www.ibm.com/design',
linkText: 'Column',
},
{ href: 'https://www.ibm.com/design', linkText: 'One' },
],
secondCol: [
{
href: 'https://www.ibm.com/design',
linkText: 'Dribbble',
},
{
href: 'https://www.ibm.com/design',
linkText: 'Medium',
},
{
href: 'https://www.ibm.com/design',
linkText: 'Twitter',
},
],
},
Content: DefaultContent,
Logo: IBMLogo,
};

const Footer = ({
Content = defaults.Content,
links = defaults.links,
Logo = defaults.Logo,
}) => {
const { firstCol, secondCol } = links;
const { site } = useStaticQuery(graphql`
query BUILD_TIME_QUERY {
Expand Down Expand Up @@ -86,36 +120,6 @@ const DefaultContent = () => (
</p>
);

Footer.defaultProps = {
links: {
firstCol: [
{ href: 'https://www.ibm.com/design', linkText: 'Sample' },
{ href: 'https://www.ibm.com/design', linkText: 'Links' },
{
href: 'https://www.ibm.com/design',
linkText: 'Column',
},
{ href: 'https://www.ibm.com/design', linkText: 'One' },
],
secondCol: [
{
href: 'https://www.ibm.com/design',
linkText: 'Dribbble',
},
{
href: 'https://www.ibm.com/design',
linkText: 'Medium',
},
{
href: 'https://www.ibm.com/design',
linkText: 'Twitter',
},
],
},
Content: DefaultContent,
Logo: IBMLogo,
};

Footer.propTypes = {
/**
* Specify the first and second columns of your links
Expand Down
17 changes: 11 additions & 6 deletions packages/gatsby-theme-carbon/src/components/GifPlayer/GifPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ const Play = ({ hovering }) =>
const ToggleIcon = ({ paused, hovering }) =>
paused ? <Play hovering={hovering} /> : <Pause hovering={hovering} />;

const GifPlayer = ({ children, color, className, isInDialog }) => {
const defaults = {
color: 'light',
isInDialog: false,
};

const GifPlayer = ({
children,
color = defaults.color,
className,
isInDialog = defaults.isInDialog,
}) => {
const [paused, setPaused] = useState(false);

const [hovering, setHovering] = useState(false);
Expand Down Expand Up @@ -96,9 +106,4 @@ GifPlayer.propTypes = {
isInDialog: PropTypes.bool,
};

GifPlayer.defaultProps = {
color: 'light',
isInDialog: false,
};

export default GifPlayer;
10 changes: 5 additions & 5 deletions packages/gatsby-theme-carbon/src/components/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ Row.propTypes = {
className: PropTypes.string,
};

const colDefaults = {
colLg: 12,
};

export const Column = ({
children,
colSm,
colMd,
colLg,
colLg = colDefaults.colLg,
colXl,
colMax,
offsetSm,
Expand Down Expand Up @@ -94,10 +98,6 @@ export const Column = ({
);
};

Column.defaultProps = {
colLg: 12,
};

Column.propTypes = {
children: PropTypes.node,
/**
Expand Down
10 changes: 5 additions & 5 deletions packages/gatsby-theme-carbon/src/components/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import useMetadata from '../../util/hooks/useMetadata';

import * as styles from './Header.module.scss';

const Header = ({ children }) => {
const defaults = {
children: <DefaultHeaderText />,
};

const Header = ({ children = defaults.children }) => {
const {
leftNavIsOpen,
toggleNavState,
Expand Down Expand Up @@ -81,8 +85,4 @@ const DefaultHeaderText = () => (
</>
);

Header.defaultProps = {
children: <DefaultHeaderText />,
};

export default Header;
46 changes: 23 additions & 23 deletions packages/gatsby-theme-carbon/src/components/Homepage/Callout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,30 @@ const getBackgroundColor = (backgroundColor) =>
const getColor = (color) =>
theme.colors[color] || color || theme.colors.inverse01;

const defaults = {
leftText: function renderLeftText() {
return (
<>
Think → <strong>Guide</strong>
</>
);
},
rightText: function renderRightText() {
return (
<p>
<strong>Build Bonds.</strong>
<br />
This is the guiding ethos behind IBM’s design philosophy and principles.
This helps us distinguish every element and every experience Designed by
IBM.
</p>
);
},
};

const HomepageCallout = ({
leftText,
rightText,
leftText = defaults.leftText,
rightText = defaults.rightText,
backgroundColor: backgroundColorProp,
color: colorProp,
...rest
Expand All @@ -38,25 +59,4 @@ const HomepageCallout = ({
);
};

HomepageCallout.defaultProps = {
leftText: function renderLeftText() {
return (
<>
Think → <strong>Guide</strong>
</>
);
},
rightText: function renderRightText() {
return (
<p>
<strong>Build Bonds.</strong>
<br />
This is the guiding ethos behind IBM’s design philosophy and principles.
This helps us distinguish every element and every experience Designed by
IBM.
</p>
);
},
};

export default HomepageCallout;
30 changes: 15 additions & 15 deletions packages/gatsby-theme-carbon/src/components/ImageCard/ImageCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,28 @@ import {
Email,
} from '@carbon/react/icons';

const defaults = {
disabled: false,
aspectRatio: '1:1',
titleColor: 'light',
subTitleColor: 'light',
iconColor: 'light',
hoverColor: 'light',
};

export default class ImageCard extends React.Component {
render() {
const {
children,
href,
subTitle,
title,
titleColor,
subTitleColor,
iconColor,
hoverColor,
disabled,
aspectRatio,
titleColor = defaults.titleColor,
subTitleColor = defaults.subTitleColor,
iconColor = defaults.iconColor,
hoverColor = defaults.hoverColor,
disabled = defaults.disabled,
aspectRatio = defaults.aspectRatio,
actionIcon,
className,
...rest
Expand Down Expand Up @@ -181,12 +190,3 @@ ImageCard.propTypes = {
*/
linkProps: PropTypes.object,
};

ImageCard.defaultProps = {
disabled: false,
aspectRatio: '1:1',
titleColor: 'light',
subTitleColor: 'light',
iconColor: 'light',
hoverColor: 'light',
};
Loading

0 comments on commit 90ec4ee

Please sign in to comment.