wix-style-react
Version:
105 lines (82 loc) • 4.92 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 = ["size", "skin", "styles", "dataHook", "className"];
var _checkedIconMap, _uncheckedIconMap;
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 { ToggleSwitch as CoreToggleSwitch } from "wix-ui-core/dist/es/src/components/toggle-switch";
import ToggleOff from 'wix-ui-icons-common/system/ToggleOff';
import ToggleOn from 'wix-ui-icons-common/system/ToggleOn';
import ToggleOffSmall from 'wix-ui-icons-common/system/ToggleOffSmall';
import ToggleOnSmall from 'wix-ui-icons-common/system/ToggleOnSmall';
import { generateDataAttr } from '../utils/generateDataAttr';
import { SIZES } from './constants';
import { st, classes } from './ToggleSwitch.st.css';
var checkedIconMap = (_checkedIconMap = {}, _defineProperty(_checkedIconMap, SIZES.small, undefined), _defineProperty(_checkedIconMap, SIZES.medium, /*#__PURE__*/React.createElement(ToggleOnSmall, null)), _defineProperty(_checkedIconMap, SIZES.large, /*#__PURE__*/React.createElement(ToggleOn, null)), _checkedIconMap);
var uncheckedIconMap = (_uncheckedIconMap = {}, _defineProperty(_uncheckedIconMap, SIZES.small, undefined), _defineProperty(_uncheckedIconMap, SIZES.medium, /*#__PURE__*/React.createElement(ToggleOffSmall, null)), _defineProperty(_uncheckedIconMap, SIZES.large, /*#__PURE__*/React.createElement(ToggleOff, null)), _uncheckedIconMap);
/** toggle switch */
var ToggleSwitch = /*#__PURE__*/function (_React$PureComponent) {
_inherits(ToggleSwitch, _React$PureComponent);
var _super = _createSuper(ToggleSwitch);
function ToggleSwitch() {
_classCallCheck(this, ToggleSwitch);
return _super.apply(this, arguments);
}
_createClass(ToggleSwitch, [{
key: "render",
value: function render() {
var _this$props = this.props,
size = _this$props.size,
skin = _this$props.skin,
stylesProp = _this$props.styles,
dataHook = _this$props.dataHook,
className = _this$props.className,
rest = _objectWithoutProperties(_this$props, _excluded);
return /*#__PURE__*/React.createElement(CoreToggleSwitch, _extends({
className: st(classes.root, {
skin: skin,
size: size
}, className)
}, generateDataAttr(this.props, ['skin', 'size']), {
"data-hook": dataHook,
checkedIcon: checkedIconMap[size],
uncheckedIcon: uncheckedIconMap[size]
}, rest));
}
}]);
return ToggleSwitch;
}(React.PureComponent);
_defineProperty(ToggleSwitch, "displayName", 'ToggleSwitch');
_defineProperty(ToggleSwitch, "propTypes", {
/** Applies a data-hook HTML attribute that can be used in the tests. */
dataHook: PropTypes.string,
/** Specifies a CSS class name to be appended to the component’s root element. */
className: PropTypes.string,
/** Assigns an unique identifier for the root element. */
id: PropTypes.string,
/** Controls the skin of a toggle. */
skin: PropTypes.oneOf(['standard', 'success', 'error']),
/** Controls the size of a toggle. */
size: PropTypes.oneOf(['small', 'medium', 'large']),
/** Specifies whether toggle is checked. */
checked: PropTypes.bool,
/** Specifies whether toggle is disabled. */
disabled: PropTypes.bool,
/** Defines a callback function which is called every time toggle state changes. */
onChange: PropTypes.func,
/** Indicates that element can be focused and where it participates in sequential keyboard navigation. */
tabIndex: PropTypes.number
});
_defineProperty(ToggleSwitch, "defaultProps", {
skin: 'standard',
size: 'large'
});
export default ToggleSwitch;