1 | "use strict";
|
2 |
|
3 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports["default"] = void 0;
|
9 |
|
10 | var _react = _interopRequireWildcard(require("react"));
|
11 |
|
12 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
13 |
|
14 | var _theming = require("@storybook/theming");
|
15 |
|
16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
17 |
|
18 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
19 |
|
20 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
21 |
|
22 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
23 |
|
24 | 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); } }
|
25 |
|
26 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
27 |
|
28 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
29 |
|
30 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
31 |
|
32 | 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); }; }
|
33 |
|
34 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
35 |
|
36 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
37 |
|
38 | 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; } }
|
39 |
|
40 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
41 |
|
42 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
43 |
|
44 | var CheckboxesWrapper = _theming.styled.div(function (_ref) {
|
45 | var isInline = _ref.isInline;
|
46 | return isInline ? {
|
47 | display: 'flex',
|
48 | flexWrap: 'wrap',
|
49 | alignItems: 'center',
|
50 | '> * + *': {
|
51 | marginLeft: 10
|
52 | }
|
53 | } : {};
|
54 | });
|
55 |
|
56 | var CheckboxFieldset = _theming.styled.fieldset({
|
57 | border: 0,
|
58 | padding: 0,
|
59 | margin: 0
|
60 | });
|
61 |
|
62 | var CheckboxLabel = _theming.styled.label({
|
63 | padding: '3px 0 3px 5px',
|
64 | lineHeight: '18px',
|
65 | display: 'inline-block'
|
66 | });
|
67 |
|
68 | var CheckboxesType = function (_Component) {
|
69 | _inherits(CheckboxesType, _Component);
|
70 |
|
71 | var _super = _createSuper(CheckboxesType);
|
72 |
|
73 | function CheckboxesType(props) {
|
74 | var _this;
|
75 |
|
76 | _classCallCheck(this, CheckboxesType);
|
77 |
|
78 | _this = _super.call(this, props);
|
79 |
|
80 | _defineProperty(_assertThisInitialized(_this), "handleChange", function (e) {
|
81 | var onChange = _this.props.onChange;
|
82 | var currentValue = e.target.value;
|
83 | var values = _this.state.values;
|
84 |
|
85 | if (values.includes(currentValue)) {
|
86 | values.splice(values.indexOf(currentValue), 1);
|
87 | } else {
|
88 | values.push(currentValue);
|
89 | }
|
90 |
|
91 | _this.setState({
|
92 | values: values
|
93 | });
|
94 |
|
95 | onChange(values);
|
96 | });
|
97 |
|
98 | _defineProperty(_assertThisInitialized(_this), "renderCheckboxList", function (_ref2) {
|
99 | var options = _ref2.options;
|
100 | return Object.keys(options).map(function (key) {
|
101 | return _this.renderCheckbox(key, options[key]);
|
102 | });
|
103 | });
|
104 |
|
105 | _defineProperty(_assertThisInitialized(_this), "renderCheckbox", function (label, value) {
|
106 | var knob = _this.props.knob;
|
107 | var name = knob.name;
|
108 | var id = "".concat(name, "-").concat(value);
|
109 | var values = _this.state.values;
|
110 | return _react["default"].createElement("div", {
|
111 | key: id
|
112 | }, _react["default"].createElement("input", {
|
113 | type: "checkbox",
|
114 | id: id,
|
115 | name: name,
|
116 | value: value,
|
117 | onChange: _this.handleChange,
|
118 | checked: values.includes(value)
|
119 | }), _react["default"].createElement(CheckboxLabel, {
|
120 | htmlFor: id
|
121 | }, label));
|
122 | });
|
123 |
|
124 | var _knob = props.knob;
|
125 | _this.state = {
|
126 | values: _knob.defaultValue || []
|
127 | };
|
128 | return _this;
|
129 | }
|
130 |
|
131 | _createClass(CheckboxesType, [{
|
132 | key: "render",
|
133 | value: function render() {
|
134 | var _this$props = this.props,
|
135 | knob = _this$props.knob,
|
136 | isInline = _this$props.isInline;
|
137 | return _react["default"].createElement(CheckboxFieldset, null, _react["default"].createElement(CheckboxesWrapper, {
|
138 | isInline: isInline
|
139 | }, this.renderCheckboxList(knob)));
|
140 | }
|
141 | }]);
|
142 |
|
143 | return CheckboxesType;
|
144 | }(_react.Component);
|
145 |
|
146 | exports["default"] = CheckboxesType;
|
147 |
|
148 | _defineProperty(CheckboxesType, "defaultProps", {
|
149 | knob: {},
|
150 | onChange: function onChange(value) {
|
151 | return value;
|
152 | },
|
153 | isInline: false
|
154 | });
|
155 |
|
156 | _defineProperty(CheckboxesType, "propTypes", {
|
157 | knob: _propTypes["default"].shape({
|
158 | name: _propTypes["default"].string,
|
159 | value: _propTypes["default"].array,
|
160 | options: _propTypes["default"].oneOfType([_propTypes["default"].array, _propTypes["default"].object])
|
161 | }),
|
162 | onChange: _propTypes["default"].func,
|
163 | isInline: _propTypes["default"].bool
|
164 | });
|
165 |
|
166 | _defineProperty(CheckboxesType, "serialize", function (value) {
|
167 | return value;
|
168 | });
|
169 |
|
170 | _defineProperty(CheckboxesType, "deserialize", function (value) {
|
171 | return value;
|
172 | }); |
\ | No newline at end of file |