UNPKG

@instructure/ui-themeable

Version:

A UI component library made by Instructure Inc.

96 lines (82 loc) 4.05 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.shorthandPropType = shorthandPropType; exports.ThemeablePropTypes = exports.default = void 0; var _propTypes = _interopRequireDefault(require("prop-types")); var _ThemeablePropValues = require("./ThemeablePropValues.js"); /* * The MIT License (MIT) * * Copyright (c) 2015 - present Instructure, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ var SHADOW_TYPES = _ThemeablePropValues.ThemeablePropValues.SHADOW_TYPES, STACKING_TYPES = _ThemeablePropValues.ThemeablePropValues.STACKING_TYPES, BORDER_WIDTHS = _ThemeablePropValues.ThemeablePropValues.BORDER_WIDTHS, BORDER_RADII = _ThemeablePropValues.ThemeablePropValues.BORDER_RADII, BACKGROUNDS = _ThemeablePropValues.ThemeablePropValues.BACKGROUNDS, SIZES = _ThemeablePropValues.ThemeablePropValues.SIZES, SPACING = _ThemeablePropValues.ThemeablePropValues.SPACING; /** * --- * category: utilities/themes * --- * Custom prop types for themeable React components. * @module ThemeablePropTypes */ var ThemeablePropTypes = { shadow: _propTypes.default.oneOf(Object.values(SHADOW_TYPES)), stacking: _propTypes.default.oneOf(Object.values(STACKING_TYPES)), borderWidth: shorthandPropType(Object.values(BORDER_WIDTHS)), borderRadius: shorthandPropType(Object.values(BORDER_RADII)), background: _propTypes.default.oneOf(Object.values(BACKGROUNDS)), size: _propTypes.default.oneOf(Object.values(SIZES)), spacing: shorthandPropType(Object.values(SPACING)) }; exports.ThemeablePropTypes = ThemeablePropTypes; function shorthandPropType(validValues) { return function (props, propName, componentName, location) { var propValue = props[propName]; if (typeof propValue === 'undefined') { return; } var propValueType = typeof propValue; if (propValueType !== 'string') { return new Error("Invalid ".concat(location, " `").concat(propName, "` of type `").concat(propValueType, "` supplied to `").concat(componentName, "`, expected ") + "a string."); } var propValues = propValue.split(' '); var valuesLength = propValues.length; if (valuesLength > 0 && valuesLength < 5) { for (var i = 0; i < valuesLength; i++) { var valueIndex = validValues.indexOf(propValues[i]); if (valueIndex === -1) { return new Error("Invalid ".concat(location, " `").concat(propName, "` `").concat(propValues[i], "` supplied to `").concat(componentName, "`, expected ") + "a one of `".concat(validValues.join(', '), "`.")); } } } else { 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(', '), "`.")); } }; } var _default = ThemeablePropTypes; exports.default = _default;