wix-style-react
Version:
wix-style-react
90 lines (72 loc) • 3.92 kB
JavaScript
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; }
/* eslint-disable no-console */
import React from 'react';
import Dropdown from 'wix-style-react/Dropdown';
import Checkbox from 'wix-style-react/Checkbox';
var style = {
display: 'inline-block',
padding: '0 5px 0',
width: '200px',
lineHeight: '22px',
marginBottom: '350px'
};
var CustomValuesInDropdown = function (_React$Component) {
_inherits(CustomValuesInDropdown, _React$Component);
function CustomValuesInDropdown(props) {
_classCallCheck(this, CustomValuesInDropdown);
var _this = _possibleConstructorReturn(this, (CustomValuesInDropdown.__proto__ || Object.getPrototypeOf(CustomValuesInDropdown)).call(this, props));
_this.state = { checkboxChecked: false };
return _this;
}
_createClass(CustomValuesInDropdown, [{
key: 'render',
value: function render() {
var _this2 = this;
var valueParser = function valueParser(option) {
return typeof option.value === 'string' ? option.value : option.value.props.children[0].props.children;
};
var onSelect = function onSelect(option) {
return console.log('Selected ', valueParser(option));
};
var onChange = function onChange() {
return _this2.setState({ checkboxChecked: !_this2.state.checkboxChecked });
};
var customValue = React.createElement(
'div',
null,
React.createElement(
'span',
null,
'Custom Value'
),
React.createElement(
'span',
{ style: { marginLeft: '5px' }, onClick: function onClick(e) {
return e.stopPropagation();
} },
React.createElement(Checkbox, { onChange: onChange, checked: this.state.checkboxChecked })
)
);
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' }, { id: 6, value: customValue }, { id: 7, value: customValue }];
return React.createElement(Dropdown, {
options: options,
initiallySelectedId: 6,
placeholder: 'Choose an option',
valueParser: valueParser,
onSelect: onSelect,
upgrade: true
});
}
}]);
return CustomValuesInDropdown;
}(React.Component);
export default (function () {
return React.createElement(
'div',
{ style: style },
React.createElement(CustomValuesInDropdown, null)
);
});