Skip to content

Commit

Permalink
fix: replace deprecated defaultProps / prop-types
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Roest committed Jun 20, 2024
1 parent 09f7090 commit a9e84f4
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 113 deletions.
11 changes: 1 addition & 10 deletions src/client/rsg-components/Markdown/List/ListRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { cloneElement, Children } from 'react';
import PropTypes from 'prop-types';
import cx from 'clsx';
import Styled, { JssInjectedProps } from 'rsg-components/Styled';
import * as Rsg from '../../../../typings';
Expand Down Expand Up @@ -30,7 +29,7 @@ interface ListProps extends JssInjectedProps {

export const ListRenderer: React.FunctionComponent<ListProps> = ({
classes,
ordered,
ordered = false,
children,
}) => {
const Tag = ordered ? 'ol' : 'ul';
Expand All @@ -45,13 +44,5 @@ export const ListRenderer: React.FunctionComponent<ListProps> = ({
</Tag>
);
};
ListRenderer.propTypes = {
classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired,
ordered: PropTypes.bool,
children: PropTypes.any.isRequired,
};
ListRenderer.defaultProps = {
ordered: false,
};

export default Styled<ListProps>(styles)(ListRenderer);
13 changes: 1 addition & 12 deletions src/client/rsg-components/Markdown/Table/TableCellRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import Styled, { JssInjectedProps } from 'rsg-components/Styled';
import * as Rsg from '../../../../typings';

Expand All @@ -24,23 +23,13 @@ interface TableCellProps extends JssInjectedProps {

export const TableCellRenderer: React.FunctionComponent<TableCellProps> = ({
classes,
header,
header = false,
children,
}) => {
if (header) {
return <th className={classes.th}>{children}</th>;
}

return <td className={classes.td}>{children}</td>;
};

TableCellRenderer.propTypes = {
classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired,
header: PropTypes.bool,
children: PropTypes.any.isRequired,
};
TableCellRenderer.defaultProps = {
header: false,
};

export default Styled<TableCellProps>(styles)(TableCellRenderer);
14 changes: 0 additions & 14 deletions src/client/rsg-components/Playground/Playground.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import debounce from 'lodash/debounce';
import Preview from 'rsg-components/Preview';
import Para from 'rsg-components/Para';
Expand Down Expand Up @@ -31,19 +30,6 @@ interface PlaygroundState {
}

class Playground extends Component<PlaygroundProps, PlaygroundState> {
public static propTypes = {
code: PropTypes.string.isRequired,
evalInContext: PropTypes.func.isRequired,
index: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
exampleMode: PropTypes.string.isRequired,
settings: PropTypes.object,
};

public static defaultProps = {
settings: {},
};

public static contextType = Context;

private handleChange = debounce((code) => {
Expand Down
17 changes: 5 additions & 12 deletions src/client/rsg-components/Ribbon/RibbonRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import Styled, { JssInjectedProps } from 'rsg-components/Styled';
import * as Rsg from '../../../typings';

Expand Down Expand Up @@ -37,7 +36,11 @@ interface RibbonProps extends JssInjectedProps {
text?: string;
}

export const RibbonRenderer: React.FunctionComponent<RibbonProps> = ({ classes, url, text }) => {
export const RibbonRenderer: React.FunctionComponent<RibbonProps> = ({
classes,
url,
text = 'Fork me on GitHub',
}) => {
return (
<footer className={classes.root}>
<a href={url} className={classes.link}>
Expand All @@ -47,14 +50,4 @@ export const RibbonRenderer: React.FunctionComponent<RibbonProps> = ({ classes,
);
};

RibbonRenderer.defaultProps = {
text: 'Fork me on GitHub',
};

RibbonRenderer.propTypes = {
classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired,
url: PropTypes.string.isRequired,
text: PropTypes.string,
};

export default Styled<RibbonProps>(styles)(RibbonRenderer);
19 changes: 1 addition & 18 deletions src/client/rsg-components/StyleGuide/StyleGuide.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import TableOfContents from 'rsg-components/TableOfContents';
import StyleGuideRenderer from 'rsg-components/StyleGuide/StyleGuideRenderer';
import Sections from 'rsg-components/Sections';
Expand Down Expand Up @@ -50,22 +49,6 @@ interface StyleGuideState {
}

export default class StyleGuide extends Component<StyleGuideProps, StyleGuideState> {
public static propTypes = {
codeRevision: PropTypes.number.isRequired,
cssRevision: PropTypes.string.isRequired,
config: PropTypes.object.isRequired,
slots: PropTypes.object.isRequired,
sections: PropTypes.array.isRequired,
welcomeScreen: PropTypes.bool,
patterns: PropTypes.array,
displayMode: PropTypes.string,
allSections: PropTypes.array.isRequired,
pagePerSection: PropTypes.bool,
};
public static defaultProps = {
displayMode: DisplayModes.all,
};

public state = {
error: false,
info: null,
Expand All @@ -85,7 +68,7 @@ export default class StyleGuide extends Component<StyleGuideProps, StyleGuideSta
sections,
welcomeScreen,
patterns,
displayMode,
displayMode = DisplayModes.all,
allSections,
pagePerSection,
codeRevision,
Expand Down
15 changes: 1 addition & 14 deletions src/client/rsg-components/TabButton/TabButtonRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import Styled, { JssInjectedProps } from 'rsg-components/Styled';
import { Styles } from 'jss';
import cx from 'clsx';
Expand Down Expand Up @@ -55,7 +54,7 @@ export const TabButtonRenderer: React.FunctionComponent<TabButtonProps> = ({
name,
className,
onClick,
active,
active = false,
children,
}) => {
const classNames = cx(classes.button, className, {
Expand All @@ -75,16 +74,4 @@ export const TabButtonRenderer: React.FunctionComponent<TabButtonProps> = ({
);
};

TabButtonRenderer.propTypes = {
classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired,
name: PropTypes.string.isRequired,
className: PropTypes.string,
onClick: PropTypes.func.isRequired,
active: PropTypes.bool,
children: PropTypes.any.isRequired,
};
TabButtonRenderer.defaultProps = {
active: false,
};

export default Styled<TabButtonProps>(styles)(TabButtonRenderer);
16 changes: 2 additions & 14 deletions src/client/rsg-components/TableOfContents/TableOfContents.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ComponentsList from 'rsg-components/ComponentsList';
import TableOfContentsRenderer from 'rsg-components/TableOfContents/TableOfContentsRenderer';
import filterSectionsByName from '../../utils/filterSectionsByName';
Expand All @@ -10,21 +9,10 @@ interface TableOfContentsProps {
sections: Rsg.Section[];
useRouterLinks?: boolean;
tocMode?: string;
loc: { hash: string; pathname: string };
loc?: { hash: string; pathname: string };
}

export default class TableOfContents extends Component<TableOfContentsProps> {
public static propTypes = {
sections: PropTypes.array.isRequired,
useRouterLinks: PropTypes.bool,
tocMode: PropTypes.string,
loc: PropTypes.object,
};

public static defaultProps = {
loc: window.location,
};

public state = {
searchTerm: '',
};
Expand All @@ -36,7 +24,7 @@ export default class TableOfContents extends Component<TableOfContentsProps> {
useHashId = false
): { content: React.ReactElement; containsSelected: boolean } {
// Match selected component in both basic routing and pagePerSection routing.
const { hash, pathname } = this.props.loc;
const { hash, pathname } = this.props.loc ?? window.location;
const windowHash = pathname + (useRouterLinks ? hash : getHash(hash));

let childrenContainSelected = false;
Expand Down
22 changes: 3 additions & 19 deletions src/client/rsg-components/Text/TextRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'clsx';
import Styled, { JssInjectedProps } from 'rsg-components/Styled';
import * as Rsg from '../../../typings';
Expand Down Expand Up @@ -49,9 +48,9 @@ export interface TextProps extends JssInjectedProps {
export const TextRenderer: React.FunctionComponent<TextProps> = ({
classes,
semantic,
size,
color,
underlined,
size = 'inherit',
color = 'base',
underlined = false,
children,
...props
}) => {
Expand All @@ -68,19 +67,4 @@ export const TextRenderer: React.FunctionComponent<TextProps> = ({
);
};

TextRenderer.propTypes = {
classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired,
semantic: PropTypes.oneOf(['em', 'strong']),
size: PropTypes.oneOf(['inherit', 'small', 'base', 'text']),
color: PropTypes.oneOf(['base', 'light']),
underlined: PropTypes.bool,
children: PropTypes.any.isRequired,
};

TextRenderer.defaultProps = {
size: 'inherit',
color: 'base',
underlined: false,
};

export default Styled<TextProps>(styles)(TextRenderer);

0 comments on commit a9e84f4

Please sign in to comment.