UNPKG

wix-style-react

Version:
76 lines (60 loc) 3.47 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; }; }(); 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; } import React, { Component } from 'react'; import DropdownLayout from 'wix-style-react/DropdownLayout'; var style = { display: 'inline-block', padding: '0 5px', width: '160px', lineHeight: '22px' }; var options = [{ id: 'first title', value: 'title', title: true }, { id: 1, value: 'Option 1' }, { id: 'title', value: 'this is a title', title: true }, { id: 2, value: 'Option 2' }, { id: 0, value: '-' }, { id: 'disabled', value: 'Disabled', disabled: true }, { id: 4, value: 'Option 4' }]; var ControlledExample = function (_Component) { _inherits(ControlledExample, _Component); function ControlledExample() { _classCallCheck(this, ControlledExample); var _this = _possibleConstructorReturn(this, (ControlledExample.__proto__ || Object.getPrototypeOf(ControlledExample)).call(this)); _this.state = { selectedId: 1, show: true }; return _this; } _createClass(ControlledExample, [{ key: 'render', value: function render() { var _this2 = this; var onSelect = function onSelect(option) { return _this2.setState({ selectedId: option.id }); }; var onClose = function onClose() { return _this2.setState({ selectedId: -1 }); }; var selectedOption = options.find(function (item) { return item.id === _this2.state.selectedId; }); return React.createElement( 'div', { style: style }, ' ', 'Left to right', React.createElement(DropdownLayout, { visible: true, options: options, onSelect: onSelect, selectedId: this.state.selectedId, onClose: onClose }), React.createElement( 'div', { style: { padding: '185px 0 16px' } }, selectedOption ? selectedOption.value : 'Nothing', ' is selected' ) ); } }]); return ControlledExample; }(Component); export default (function () { return React.createElement(ControlledExample, null); });