UNPKG

wix-style-react

Version:
91 lines (74 loc) 4.03 kB
var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } /* eslint-disable no-console */ import React from 'react'; import IconWithOptions from 'wix-style-react/IconWithOptions'; import Image from 'wix-style-react/new-icons/Image'; var style = { display: 'inline-block', padding: '0 5px 0', width: '200px', lineHeight: '22px', marginBottom: '160px', marginLeft: '50px', marginTop: '20px' }; var options = [{ id: 1, value: 'Option 1' }, { id: 2, value: 'Option 2' }, { id: 3, value: 'Option 3' }, { id: 4, value: 'Option 4', disabled: true }, { id: 5, value: 'Option 5' }]; var optionsToArray = function optionsToArray(_options) { return _options.map(function (option) { var value = option.value, props = _objectWithoutProperties(option, ['value']); return React.createElement( IconWithOptions.Option, _extends({ key: option.id }, props), value ); }); }; var Example = function (_React$Component) { _inherits(Example, _React$Component); function Example(props) { _classCallCheck(this, Example); var _this = _possibleConstructorReturn(this, (Example.__proto__ || Object.getPrototypeOf(Example)).call(this, props)); _this.state = { selectedId: 1 }; _this.onSelect = _this.onSelect.bind(_this); return _this; } _createClass(Example, [{ key: 'onSelect', value: function onSelect(option) { this.setState({ selectedId: option.id }); console.log('Option ' + JSON.stringify(option) + ' selected'); } }, { key: 'render', value: function render() { return React.createElement( IconWithOptions, { dataHook: 'story-iconWithOptions', onSelect: this.onSelect, selectedId: this.state.selectedId }, React.createElement( IconWithOptions.Icon, null, React.createElement(Image, { size: '30' }) ), optionsToArray(options) ); } }]); return Example; }(React.Component); export default (function () { return React.createElement( 'div', { style: style }, React.createElement(Example, null) ); });