Skip to content
This repository was archived by the owner on Mar 14, 2021. It is now read-only.

Commit edbaaba

Browse files
author
Andrey Okonetchnikov
committed
fix: Fix propTypes and remove React warnings
Fixes #1
1 parent b894dd9 commit edbaaba

File tree

6 files changed

+34
-8
lines changed

6 files changed

+34
-8
lines changed

src/components/ColorSwatch.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from "prop-types";
33
import { readableColor } from "polished";
44
import { Swatch, SwatchToken, SwatchValue } from "../";
55
import { css } from "theme-ui";
6+
import { tokenPropType, valuePropType } from "../propTypes";
67

78
export const ColorSwatch = ({ value, token }) => {
89
const color = readableColor(
@@ -28,8 +29,8 @@ export const ColorSwatch = ({ value, token }) => {
2829
};
2930

3031
ColorSwatch.propTypes = {
31-
token: PropTypes.string.isRequired,
32-
value: PropTypes.string.isRequired
32+
...tokenPropType,
33+
...valuePropType
3334
};
3435

3536
/** @component */

src/components/FontSizeSwatch.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33
import { css } from "theme-ui";
4+
import { valuePropType } from "../propTypes";
45

56
const FontSizeSwatch = ({ value, css: componentCSS, ...rest }) => (
67
<p
@@ -16,7 +17,7 @@ const FontSizeSwatch = ({ value, css: componentCSS, ...rest }) => (
1617
);
1718

1819
FontSizeSwatch.propTypes = {
19-
value: PropTypes.string.isRequired
20+
...valuePropType
2021
};
2122

2223
/** @component */

src/components/PaletteSwatch.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33
import { Swatches, ColorSwatch } from "../index";
4+
import { tokenPropType, valuePropType } from "../propTypes";
45

56
export const PaletteSwatch = ({ token, value }) => (
67
<Swatches items={value}>
@@ -9,8 +10,8 @@ export const PaletteSwatch = ({ token, value }) => (
910
);
1011

1112
PaletteSwatch.propTypes = {
12-
token: PropTypes.string.isRequired,
13-
value: PropTypes.string.isRequired
13+
...tokenPropType,
14+
...valuePropType
1415
};
1516

1617
/** @component */

src/components/SpacingSwatch.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import PropTypes from "prop-types";
33
import { css } from "theme-ui";
44
import { SwatchValue } from "../";
5+
import { valuePropType } from "../propTypes";
56

67
const SpacingSwatch = ({ value, css: componentCSS, ...rest }) => {
78
return (
@@ -21,7 +22,7 @@ const SpacingSwatch = ({ value, css: componentCSS, ...rest }) => {
2122
};
2223

2324
SpacingSwatch.propTypes = {
24-
value: PropTypes.string.isRequired
25+
...valuePropType
2526
};
2627

2728
/** @component */

src/components/Swatch.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33
import copy from "clipboard-copy";
4+
import { tokenPropType, valuePropType } from "../propTypes";
45

56
function Swatch(props) {
67
return (
@@ -16,8 +17,8 @@ function Swatch(props) {
1617
}
1718

1819
Swatch.propTypes = {
19-
token: PropTypes.string.isRequired,
20-
value: PropTypes.string.isRequired
20+
...tokenPropType,
21+
...valuePropType
2122
};
2223

2324
export default Swatch;

src/propTypes.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import PropTypes from "prop-types";
2+
3+
/**
4+
* Design token name
5+
* See https://theme-ui.com/theme-spec
6+
* */
7+
export const tokenPropType = {
8+
token: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired
9+
};
10+
11+
/**
12+
* The value to render inside the swatch
13+
* */
14+
export const valuePropType = {
15+
value: PropTypes.oneOfType([
16+
PropTypes.string,
17+
PropTypes.number,
18+
PropTypes.object,
19+
PropTypes.array
20+
]).isRequired
21+
};

0 commit comments

Comments
 (0)