wix-style-react
Version:
wix-style-react
185 lines (160 loc) • 6.33 kB
JavaScript
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 _class, _temp;
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; }
import React from 'react';
import PropTypes from 'prop-types';
import WixComponent from '../WixComponent';
import styles from './TextLinkLayout.scss';
import Text from '../../Text';
var ICON_SIZES = {
small: '18px',
medium: '24px'
};
var addIcon = function addIcon(className, icon) {
var size = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'medium';
return icon ? React.createElement(
'div',
{
className: className,
'data-hook': className === styles.prefix ? 'prefix-icon' : 'suffix-icon'
},
React.cloneElement(icon, { size: ICON_SIZES[size] })
) : null;
};
export var ThemeOptions = {
NORMAL: { type: 'normal', color: { hover: '#4eb7f5', normal: '#3899ec' } },
DARK_BACKGROUND: {
type: 'darkBackground',
color: { hover: '#f0f4f7', normal: '#f0f4f7' }
},
GREYSCALE: {
type: 'greyScale',
color: { hover: '#162d3d', normal: '#162d3d' }
},
DISABLED: {
type: 'disabled',
color: { hover: '#cbd3dc', normal: '#cbd3dc' }
}
};
var TextLinkLayout = (_temp = _class = function (_WixComponent) {
_inherits(TextLinkLayout, _WixComponent);
function TextLinkLayout(props) {
_classCallCheck(this, TextLinkLayout);
var _this = _possibleConstructorReturn(this, (TextLinkLayout.__proto__ || Object.getPrototypeOf(TextLinkLayout)).call(this, props));
_this.state = {
isHover: false
};
_this.setHover = _this.setHover.bind(_this);
return _this;
}
_createClass(TextLinkLayout, [{
key: 'setHover',
value: function setHover(hover) {
this.setState({
isHover: hover
});
}
}, {
key: 'getColor',
value: function getColor() {
var _props = this.props,
theme = _props.theme,
darkBackground = _props.darkBackground,
disabled = _props.disabled;
var isHover = this.state.isHover;
if (disabled) {
return ThemeOptions.DISABLED.color.normal;
}
//this should be deprecated
if (darkBackground) {
return ThemeOptions.DARK_BACKGROUND.color.normal;
}
switch (theme) {
case ThemeOptions.DARK_BACKGROUND.type:
return ThemeOptions.DARK_BACKGROUND.color.normal;
case ThemeOptions.GREYSCALE.type:
return ThemeOptions.GREYSCALE.color.normal;
default:
{
var color = ThemeOptions.NORMAL.color;
return isHover ? color.hover : color.normal;
}
}
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
var isHover = this.state.isHover;
var _props2 = this.props,
underlineStyle = _props2.underlineStyle,
size = _props2.size,
children = _props2.children,
display = _props2.display,
disabled = _props2.disabled,
prefixIcon = _props2.prefixIcon,
suffixIcon = _props2.suffixIcon,
ellipsis = _props2.ellipsis;
var color = this.getColor();
var displayStyle = prefixIcon || suffixIcon ? 'flex' : display;
var containerStyles = {
color: color,
display: displayStyle,
background: 'none',
cursor: disabled ? 'default' : 'pointer'
};
var textStyles = {
color: color,
textDecoration: underlineStyle === 'hover' && isHover && !disabled || underlineStyle === 'always' ? 'underline' : 'none'
};
return React.createElement(
'div',
{
role: 'link',
style: containerStyles,
onMouseLeave: function onMouseLeave() {
return _this2.setHover(false);
},
onMouseEnter: function onMouseEnter() {
return _this2.setHover(true);
}
},
addIcon(styles.prefix, prefixIcon, size),
React.createElement(
Text,
{
ellipsis: ellipsis,
style: textStyles,
size: size,
'data-hook': 'text-element'
},
children
),
addIcon(styles.suffix, suffixIcon, size)
);
}
}]);
return TextLinkLayout;
}(WixComponent), _class.propTypes = {
children: PropTypes.node,
underlineStyle: PropTypes.oneOf(['always', 'hover', 'never']),
darkBackground: PropTypes.bool,
theme: PropTypes.oneOf(['normal', 'darkBackground', 'greyScale']),
size: PropTypes.oneOf(['small', 'medium']),
display: PropTypes.oneOf(['block', 'inline-block']),
disabled: PropTypes.bool,
prefixIcon: PropTypes.node,
suffixIcon: PropTypes.node,
ellipsis: PropTypes.bool
}, _class.defaultProps = {
underlineStyle: 'hover',
darkBackground: false, //TODO - this should be deprecated
theme: ThemeOptions.NORMAL.type,
size: 'medium',
display: 'block',
disabled: false,
ellipsis: false
}, _temp);
export { TextLinkLayout as default };