kitten-components
Version:
Front-end components library
124 lines (94 loc) • 5.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Text = 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 _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
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; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Text = exports.Text = function (_Component) {
_inherits(Text, _Component);
function Text() {
_classCallCheck(this, Text);
return _possibleConstructorReturn(this, (Text.__proto__ || Object.getPrototypeOf(Text)).apply(this, arguments));
}
_createClass(Text, [{
key: 'render',
value: function render() {
var _props = this.props,
className = _props.className,
color = _props.color,
decoration = _props.decoration,
lineHeight = _props.lineHeight,
size = _props.size,
fontStyle = _props.fontStyle,
tag = _props.tag,
transform = _props.transform,
weight = _props.weight,
others = _objectWithoutProperties(_props, ['className', 'color', 'decoration', 'lineHeight', 'size', 'fontStyle', 'tag', 'transform', 'weight']);
var Tag = tag;
var textClassName = (0, _classnames2.default)({
// Color.
'k-u-color-font1': color == 'font1',
'k-u-color-font2': color == 'font2',
'k-u-color-primary1': color == 'primary1',
'k-u-color-background1': color == 'background1',
'k-u-color-error': color == 'error',
'k-u-color-valid': color == 'valid',
// Decoration.
'k-u-decoration-underline': decoration == 'underline',
'k-u-decoration-none': decoration == 'none',
// Line height.
'k-u-line-height-normal': lineHeight == 'normal',
// Size.
'k-u-size-huge': size == 'huge',
'k-u-size-big': size == 'big',
'k-u-size-default': size == 'default',
'k-u-size-tiny': size == 'tiny',
'k-u-size-micro': size == 'micro',
'k-u-size-nano': size == 'nano',
// Style.
'k-u-style-normal': fontStyle == 'normal',
'k-u-style-italic': fontStyle == 'italic',
// Transform.
'k-u-transform-uppercase': transform == 'uppercase',
// Weight.
'k-u-weight-light': weight == 'light',
'k-u-weight-regular': weight == 'regular',
'k-u-weight-bold': weight == 'bold'
}, className);
return _react2.default.createElement(Tag, _extends({}, others, { className: textClassName }));
}
}]);
return Text;
}(_react.Component);
Text.propTypes = {
color: _propTypes2.default.oneOf(['font1', 'font2', 'primary1', 'background1', 'error', 'valid']),
decoration: _propTypes2.default.oneOf(['underline', 'none']),
lineHeight: _propTypes2.default.oneOf(['normal']),
size: _propTypes2.default.oneOf(['huge', 'big', 'default', 'tiny', 'micro', 'nano']),
fontStyle: _propTypes2.default.oneOf(['normal', 'italic']),
transform: _propTypes2.default.oneOf(['uppercase']),
weight: _propTypes2.default.oneOf(['light', 'regular', 'bold'])
};
Text.defaultProps = {
className: null,
color: null,
decoration: null,
lineHeight: null,
size: null,
fontStyle: null,
tag: 'span',
transform: null,
weight: null
};