wix-style-react
Version:
141 lines (112 loc) • 5.51 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _excluded = ["skin", "priority", "size", "className", "fullWidth", "children", "dataHook", "ellipsis", "showTooltip", "tooltipProps"];
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import React, { PureComponent } from 'react';
import { ButtonNext } from "wix-ui-core/dist/es/src/components/button-next";
import Ellipsis from '../common/Ellipsis';
import { TooltipCommonProps } from '../common/PropTypes/TooltipCommon';
import { generateDataAttr } from '../utils/generateDataAttr';
import { FontUpgradeContext } from '../FontUpgrade/context';
import { st, classes } from './Button.st.css';
import PropTypes from 'prop-types';
var Button = /*#__PURE__*/function (_PureComponent) {
_inherits(Button, _PureComponent);
var _super = _createSuper(Button);
function Button() {
_classCallCheck(this, Button);
return _super.apply(this, arguments);
}
_createClass(Button, [{
key: "render",
value: function render() {
var _this = this;
var _this$props = this.props,
skin = _this$props.skin,
priority = _this$props.priority,
size = _this$props.size,
className = _this$props.className,
fullWidth = _this$props.fullWidth,
children = _this$props.children,
dataHook = _this$props.dataHook,
ellipsis = _this$props.ellipsis,
showTooltip = _this$props.showTooltip,
tooltipProps = _this$props.tooltipProps,
rest = _objectWithoutProperties(_this$props, _excluded);
return /*#__PURE__*/React.createElement(FontUpgradeContext.Consumer, null, function (_ref) {
var active = _ref.active;
return /*#__PURE__*/React.createElement(Ellipsis, _extends({
ellipsis: ellipsis,
showTooltip: showTooltip
}, tooltipProps, {
render: function render(_ref2) {
var ref = _ref2.ref,
ellipsisClasses = _ref2.ellipsisClasses;
return /*#__PURE__*/React.createElement(ButtonNext, _extends({
"data-madefor": active
}, rest, generateDataAttr(_this.props, ['skin', 'size', 'priority']), {
className: st(classes.root, {
fluid: fullWidth,
skin: skin,
priority: priority,
size: size,
ellipsis: ellipsis
}, className),
"data-hook": dataHook,
contentClassName: ellipsisClasses(),
contentRef: ref
}), children);
}
}));
});
}
}]);
return Button;
}(PureComponent);
_defineProperty(Button, "displayName", 'Button');
_defineProperty(Button, "propTypes", {
/** render as some other component or DOM tag */
as: PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.string]),
/** Additional classes */
className: PropTypes.string,
/** Skins of Button content */
skin: PropTypes.oneOf(['standard', 'inverted', 'destructive', 'premium', 'dark', 'light', 'transparent', 'premium-light']),
/** Priority of Button content */
priority: PropTypes.oneOf(['primary', 'secondary']),
/** Size of Button content */
size: PropTypes.oneOf(['tiny', 'small', 'medium', 'large']),
/** Click event handler */
onClick: PropTypes.func,
/** Sets button width to 100% */
fullWidth: PropTypes.bool,
/** Element based icon (svg, image etc.) */
suffixIcon: PropTypes.element,
/** Element based icon (svg, image etc.) */
prefixIcon: PropTypes.element,
/** Applies disabled styles */
disabled: PropTypes.bool,
/** String based node */
children: PropTypes.node,
/** String based data hook */
dataHook: PropTypes.string,
/** should the text get ellipsized with tooltip, or should it get broken into lines when it reaches the end of its container */
ellipsis: PropTypes.bool,
/** True by default, set it to false in order to show ellipsis without a tooltip. */
showTooltip: PropTypes.bool,
/** Props that modify the Tooltip created from text ellipsis */
tooltipProps: PropTypes.shape(TooltipCommonProps)
});
_defineProperty(Button, "defaultProps", {
skin: 'standard',
priority: 'primary',
size: 'medium',
tooltipProps: {}
});
export default Button;