UNPKG

wix-style-react

Version:
255 lines (220 loc) • 9.55 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _extends from "@babel/runtime/helpers/extends"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; 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 = ["dataHook", "disabled", "skin", "prefixIcon", "onClick", "focusableOnFocus", "focusableOnBlur", "as", "tabIndex", "onKeyDown", "autoFocus", "highlighted", "className", "subtitle"], _excluded2 = ["selected", "hovered", "ellipsis", "title"], _excluded3 = ["title", "prefixIcon", "onClick", "id", "disabled", "skin", "size", "dataHook", "as", "tabIndex", "autoFocus", "className", "ellipsis", "subtitle"]; 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 from 'react'; import PropTypes from 'prop-types'; import { withFocusable } from "wix-ui-core/dist/es/src/hocs/Focusable/FocusableHOC"; import { FontUpgradeContext } from '../FontUpgrade/context'; import { st, classes } from './ListItemAction.st.css'; import Text from '../Text'; import Box from '../Box'; /** ListItemAction */ var ListItemActionComponent = /*#__PURE__*/function (_React$PureComponent) { _inherits(ListItemActionComponent, _React$PureComponent); var _super = _createSuper(ListItemActionComponent); function ListItemActionComponent() { var _this; _classCallCheck(this, ListItemActionComponent); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "_renderText", function (_ref) { var isMadefor = _ref.isMadefor; var _this$props = _this.props, title = _this$props.title, size = _this$props.size, ellipsis = _this$props.ellipsis, tooltipModifiers = _this$props.tooltipModifiers, subtitle = _this$props.subtitle, disabled = _this$props.disabled; return /*#__PURE__*/React.createElement(Box, { direction: "vertical", className: classes.textBox, width: "100%" }, /*#__PURE__*/React.createElement(Text, _extends({ className: st(classes.text, { subtitle: Boolean(subtitle) }), dataHook: "list-item-action-title", size: size, ellipsis: ellipsis, weight: isMadefor ? 'thin' : 'normal', placement: "right", skin: disabled ? 'disabled' : 'standard' }, tooltipModifiers), title), subtitle && /*#__PURE__*/React.createElement(Text, { dataHook: "list-item-action-subtitle", secondary: true, size: "small", ellipsis: ellipsis, weight: isMadefor ? 'thin' : 'normal', placement: "right", skin: disabled ? 'disabled' : 'standard', light: !disabled }, subtitle)); }); _defineProperty(_assertThisInitialized(_this), "_renderPrefix", function () { var _this$props2 = _this.props, prefixIcon = _this$props2.prefixIcon, size = _this$props2.size, subtitle = _this$props2.subtitle; return /*#__PURE__*/React.cloneElement(prefixIcon, { size: size === 'medium' ? 24 : 18, className: st(classes.prefixIcon, { subtitle: Boolean(subtitle) }), 'data-hook': 'list-item-action-prefix-icon' }); }); return _this; } _createClass(ListItemActionComponent, [{ key: "focus", value: function focus() { if (this.innerComponentRef) { this.innerComponentRef.focus(); } } }, { key: "render", value: function render() { var _this2 = this; var _this$props3 = this.props, dataHook = _this$props3.dataHook, disabled = _this$props3.disabled, skin = _this$props3.skin, prefixIcon = _this$props3.prefixIcon, onClick = _this$props3.onClick, focusableOnFocus = _this$props3.focusableOnFocus, focusableOnBlur = _this$props3.focusableOnBlur, Component = _this$props3.as, tabIndex = _this$props3.tabIndex, onKeyDown = _this$props3.onKeyDown, autoFocus = _this$props3.autoFocus, highlighted = _this$props3.highlighted, className = _this$props3.className, subtitle = _this$props3.subtitle, others = _objectWithoutProperties(_this$props3, _excluded); // since we're spreading the "rest" props, we don't want to pass var selected = others.selected, hovered = others.hovered, ellipsis = others.ellipsis, title = others.title, rest = _objectWithoutProperties(others, _excluded2); return /*#__PURE__*/React.createElement(FontUpgradeContext.Consumer, null, function (_ref2) { var isMadefor = _ref2.active; return /*#__PURE__*/React.createElement(Component, _extends({}, rest, { className: st(classes.root, { skin: skin, disabled: disabled, highlighted: highlighted, ellipsis: ellipsis }, className), "data-skin": skin, "data-disabled": disabled, tabIndex: tabIndex, ref: function ref(_ref3) { return _this2.innerComponentRef = _ref3; }, autoFocus: autoFocus, onFocus: focusableOnFocus, onBlur: focusableOnBlur, type: Component === 'button' ? 'button' : undefined, "data-hook": dataHook, onKeyDown: !disabled ? onKeyDown : undefined, onClick: !disabled ? onClick : undefined }), prefixIcon && _this2._renderPrefix(), _this2._renderText({ isMadefor: isMadefor })); }); } }]); return ListItemActionComponent; }(React.PureComponent); _defineProperty(ListItemActionComponent, "displayName", 'ListItemAction'); _defineProperty(ListItemActionComponent, "propTypes", { /** render as some other element */ as: PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.string]), /** Data attribute for testing purposes */ dataHook: PropTypes.string, /** Item theme (standard, dark, destructive) */ skin: PropTypes.oneOf(['standard', 'dark', 'destructive']), /** Text Size (small, medium) */ size: PropTypes.oneOf(['small', 'medium']), /** Prefix Icon */ prefixIcon: PropTypes.node, /** When present, it specifies that a button should automatically get focus when the page loads. */ autoFocus: PropTypes.bool, /** should the text get ellipsed with tooltip, or should it get broken into lines when it reaches the end of its container */ ellipsis: PropTypes.bool, /** Title */ title: PropTypes.string.isRequired, /** If true, the item is highlighted */ highlighted: PropTypes.bool, /** Disabled */ disabled: PropTypes.bool, /** Tooltip floating modifiers */ tooltipModifiers: PropTypes.object, /** On Click */ onClick: PropTypes.func, /** Text of the list item subtitle */ subtitle: PropTypes.string }); _defineProperty(ListItemActionComponent, "defaultProps", { as: 'button', skin: 'standard', size: 'medium', highlighted: false }); export var ListItemAction = withFocusable(ListItemActionComponent); export var listItemActionBuilder = function listItemActionBuilder(_ref4) { var title = _ref4.title, prefixIcon = _ref4.prefixIcon, onClick = _ref4.onClick, id = _ref4.id, disabled = _ref4.disabled, skin = _ref4.skin, size = _ref4.size, dataHook = _ref4.dataHook, as = _ref4.as, tabIndex = _ref4.tabIndex, autoFocus = _ref4.autoFocus, className = _ref4.className, ellipsis = _ref4.ellipsis, subtitle = _ref4.subtitle, rest = _objectWithoutProperties(_ref4, _excluded3); return { id: id, disabled: disabled, overrideOptionStyle: true, value: function value(_ref5) { var hovered = _ref5.hovered; return /*#__PURE__*/React.createElement(ListItemAction, _extends({}, rest, { ellipsis: ellipsis, className: className, autoFocus: autoFocus, tabIndex: tabIndex, as: as, onClick: onClick, dataHook: dataHook, title: title, prefixIcon: prefixIcon, skin: skin, size: size, highlighted: hovered, disabled: disabled, subtitle: subtitle })); } }; };