wix-style-react
Version:
138 lines (119 loc) • 5.48 kB
JavaScript
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";
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 Text from '../Text';
import Button from '../Button';
import CloseButton from '../CloseButton';
import { Appearance } from './constants';
import { classes, st } from './SectionHelper.st.css';
import { FontUpgradeContext } from '../FontUpgrade/context';
/**
* Used in pages where you need to explain or mention things about the content or actions
*/
var SectionHelper = /*#__PURE__*/function (_React$PureComponent) {
_inherits(SectionHelper, _React$PureComponent);
var _super = _createSuper(SectionHelper);
function SectionHelper() {
_classCallCheck(this, SectionHelper);
return _super.apply(this, arguments);
}
_createClass(SectionHelper, [{
key: "render",
value: function render() {
var _this$props = this.props,
dataHook = _this$props.dataHook,
showCloseButton = _this$props.showCloseButton,
onClose = _this$props.onClose,
onAction = _this$props.onAction,
actionText = _this$props.actionText,
appearance = _this$props.appearance,
title = _this$props.title,
size = _this$props.size,
fullWidth = _this$props.fullWidth,
children = _this$props.children;
var isExperimentalDark = appearance === Appearance.ExperimentalDark;
return /*#__PURE__*/React.createElement("div", {
"data-hook": dataHook,
"data-appearance": appearance,
className: st(classes.root, {
appearance: appearance,
withCloseBtn: showCloseButton && !!onClose,
withTitle: !!title,
fullWidth: fullWidth,
size: size
})
}, showCloseButton && onClose && /*#__PURE__*/React.createElement("div", {
className: st(classes.close, {
size: size
})
}, /*#__PURE__*/React.createElement(CloseButton, {
dataHook: "sectionhelper-close-btn",
size: "medium",
skin: isExperimentalDark ? 'light' : 'dark',
onClick: onClose
})), title && /*#__PURE__*/React.createElement("div", {
className: classes.title
}, /*#__PURE__*/React.createElement(FontUpgradeContext.Consumer, null, function (_ref) {
var active = _ref.active;
return /*#__PURE__*/React.createElement(Text, {
light: isExperimentalDark,
dataHook: "sectionhelper-title",
size: "small",
weight: active ? 'bold' : 'normal'
}, title);
})), /*#__PURE__*/React.createElement("div", {
className: classes.content
}, /*#__PURE__*/React.createElement(Text, {
size: "small",
light: isExperimentalDark
}, children)), onAction && actionText && /*#__PURE__*/React.createElement("div", {
className: st(classes.action, {
size: size
})
}, /*#__PURE__*/React.createElement(Button, {
size: size === 'small' ? 'tiny' : 'small',
skin: isExperimentalDark ? 'standard' : 'dark',
priority: isExperimentalDark ? 'primary' : 'secondary',
onClick: onAction,
dataHook: "sectionhelper-action-btn"
}, actionText)));
}
}]);
return SectionHelper;
}(React.PureComponent);
SectionHelper.displayName = 'SectionHelper';
SectionHelper.propTypes = {
/** Applied as data-hook HTML attribute that can be used in the tests */
dataHook: PropTypes.string,
/** Sets the look and feel of the component */
appearance: PropTypes.oneOf(['warning', 'standard', 'danger', 'success', 'premium', 'preview', 'experimentalDark']),
/** Adds text as the title */
title: PropTypes.node,
/** Controls the component padding*/
size: PropTypes.oneOf(['small', 'medium']),
/** decide if to show the close button */
showCloseButton: PropTypes.bool,
/** When provided, will make a close button appear and invoke it upon click */
onClose: PropTypes.func,
/** When provided, will make an action button appear and invoke it upon click */
onAction: PropTypes.func,
/** Text label for the action button */
actionText: PropTypes.string,
/** Children to render */
children: PropTypes.node,
/** Set the content width to 100% */
fullWidth: PropTypes.bool
};
SectionHelper.defaultProps = {
showCloseButton: true,
appearance: 'warning',
fullWidth: false,
size: 'medium'
};
export default SectionHelper;