UNPKG

wix-style-react

Version:
124 lines (93 loc) 3.43 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.WEIGHTS = exports.SKINS = exports.SIZES = undefined; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _TextSt = require('./Text.st.css'); var _TextSt2 = _interopRequireDefault(_TextSt); var _deprecationLog = require('../utils/deprecationLog'); var _deprecationLog2 = _interopRequireDefault(_deprecationLog); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } /* * Temporary fix: SIZES, SKINS, WEIGHTS constants are copied here from constants.js * in order to have AutoDocs able to parse them. * See this issue: https://github.com/wix/wix-ui/issues/784 */ var SIZES = exports.SIZES = { tiny: 'tiny', small: 'small', medium: 'medium' }; var SKINS = exports.SKINS = { standard: 'standard', error: 'error', success: 'success', premium: 'premium' }; var WEIGHTS = exports.WEIGHTS = { thin: 'thin', normal: 'normal', bold: 'bold' }; var Text = function Text(_ref) { var size = _ref.size, secondary = _ref.secondary, skin = _ref.skin, light = _ref.light, bold = _ref.bold, weight = _ref.weight, tagName = _ref.tagName, children = _ref.children, rest = _objectWithoutProperties(_ref, ['size', 'secondary', 'skin', 'light', 'bold', 'weight', 'tagName', 'children']); if (bold !== undefined) { (0, _deprecationLog2.default)('Text prop "bold" is deprecated, use "weight" prop instead'); } else { bold = false; } /* eslint-disable no-unused-vars */ var dataHook = rest.dataHook, textProps = _objectWithoutProperties(rest, ['dataHook']); return _react2.default.createElement(tagName, _extends({}, textProps, (0, _TextSt2.default)('root', { size: size, secondary: secondary, skin: skin, light: light && skin === SKINS.standard, weight: weight, bold: bold }, rest)), children); }; Text.displayName = 'Text'; Text.propTypes = { /** tag name that will be rendered */ tagName: _propTypes.string, /** class to be applied to the root element */ className: _propTypes.string, /** font size of the text */ size: (0, _propTypes.oneOf)(Object.keys(SIZES)), /** any nodes to be rendered (usually text nodes) */ children: _propTypes.any, /** is the text type is secondary. Affects the font color */ secondary: _propTypes.bool, /** skin color of the text */ skin: (0, _propTypes.oneOf)(Object.keys(SKINS)), /** is the text has dark or light skin */ light: _propTypes.bool, /** font weight of the text */ weight: (0, _propTypes.oneOf)(Object.keys(WEIGHTS)), /** is the text bold */ bold: _propTypes.bool }; Text.defaultProps = { size: SIZES.medium, secondary: false, skin: SKINS.standard, light: false, weight: WEIGHTS.thin, tagName: 'span' }; exports.default = Text;