1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.shorthandPropType = shorthandPropType;
|
9 | exports.ThemeablePropTypes = exports.default = void 0;
|
10 |
|
11 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
12 |
|
13 | var _ThemeablePropValues = require("./ThemeablePropValues.js");
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | var SHADOW_TYPES = _ThemeablePropValues.ThemeablePropValues.SHADOW_TYPES,
|
39 | STACKING_TYPES = _ThemeablePropValues.ThemeablePropValues.STACKING_TYPES,
|
40 | BORDER_WIDTHS = _ThemeablePropValues.ThemeablePropValues.BORDER_WIDTHS,
|
41 | BORDER_RADII = _ThemeablePropValues.ThemeablePropValues.BORDER_RADII,
|
42 | BACKGROUNDS = _ThemeablePropValues.ThemeablePropValues.BACKGROUNDS,
|
43 | SIZES = _ThemeablePropValues.ThemeablePropValues.SIZES,
|
44 | SPACING = _ThemeablePropValues.ThemeablePropValues.SPACING;
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | var ThemeablePropTypes = {
|
54 | shadow: _propTypes.default.oneOf(Object.values(SHADOW_TYPES)),
|
55 | stacking: _propTypes.default.oneOf(Object.values(STACKING_TYPES)),
|
56 | borderWidth: shorthandPropType(Object.values(BORDER_WIDTHS)),
|
57 | borderRadius: shorthandPropType(Object.values(BORDER_RADII)),
|
58 | background: _propTypes.default.oneOf(Object.values(BACKGROUNDS)),
|
59 | size: _propTypes.default.oneOf(Object.values(SIZES)),
|
60 | spacing: shorthandPropType(Object.values(SPACING))
|
61 | };
|
62 | exports.ThemeablePropTypes = ThemeablePropTypes;
|
63 |
|
64 | function shorthandPropType(validValues) {
|
65 | return function (props, propName, componentName, location) {
|
66 | var propValue = props[propName];
|
67 |
|
68 | if (typeof propValue === 'undefined') {
|
69 | return;
|
70 | }
|
71 |
|
72 | var propValueType = typeof propValue;
|
73 |
|
74 | if (propValueType !== 'string') {
|
75 | return new Error("Invalid ".concat(location, " `").concat(propName, "` of type `").concat(propValueType, "` supplied to `").concat(componentName, "`, expected ") + "a string.");
|
76 | }
|
77 |
|
78 | var propValues = propValue.split(' ');
|
79 | var valuesLength = propValues.length;
|
80 |
|
81 | if (valuesLength > 0 && valuesLength < 5) {
|
82 | for (var i = 0; i < valuesLength; i++) {
|
83 | var valueIndex = validValues.indexOf(propValues[i]);
|
84 |
|
85 | if (valueIndex === -1) {
|
86 | return new Error("Invalid ".concat(location, " `").concat(propName, "` `").concat(propValues[i], "` supplied to `").concat(componentName, "`, expected ") + "a one of `".concat(validValues.join(', '), "`."));
|
87 | }
|
88 | }
|
89 | } else {
|
90 | return new Error("Invalid ".concat(location, " `").concat(propName, "` `").concat(propValue, "` supplied to `").concat(componentName, "`, expected ") + "between one and four of the following valid values: `".concat(validValues.join(', '), "`."));
|
91 | }
|
92 | };
|
93 | }
|
94 |
|
95 | var _default = ThemeablePropTypes;
|
96 | exports.default = _default; |
\ | No newline at end of file |