UNPKG

wix-style-react

Version:
119 lines (104 loc) 4.64 kB
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; }; 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 PropTypes from 'prop-types'; import reactElementToJSXString from 'react-element-to-jsx-string'; import Close from 'wix-style-react/new-icons/X'; import { ButtonWithOptions } from '../../../src/index'; export var Form = function (_Component) { _inherits(Form, _Component); function Form() { _classCallCheck(this, Form); return _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).apply(this, arguments)); } _createClass(Form, [{ key: 'componentDidUpdate', value: function componentDidUpdate(props) { props.onChange(reactElementToJSXString(this.getComponent())); } }, { key: 'componentDidMount', value: function componentDidMount() { this.props.onChange(reactElementToJSXString(this.getComponent())); } }, { key: 'getComponent', value: function getComponent() { var iconSize = '6px'; if (this.props.height === 'large') { iconSize = '8px'; } if (['close-standard', 'close-dark', 'close-transparent'].indexOf(this.props.theme) < 0) { iconSize = '12px'; } var icons = {}; if (this.props.prefixIcon) { icons.prefixIcon = this.props.prefixIcon; } if (this.props.suffixIcon) { icons.suffixIcon = this.props.suffixIcon; } return React.createElement( ButtonWithOptions, this.props, React.createElement( ButtonWithOptions.Button, _extends({}, this.props, icons), this.props.iconOnly ? React.createElement(Close, { size: iconSize }) : this.props.text ), React.createElement( ButtonWithOptions.Option, { id: '1' }, 'Option 1' ), React.createElement( ButtonWithOptions.Option, { id: '2' }, 'Option 2' ), React.createElement( ButtonWithOptions.Option, { id: '3', disabled: true }, 'Option 3' ), React.createElement( ButtonWithOptions.Option, { id: '4' }, React.createElement( 'span', null, React.createElement(Close, { size: iconSize }), ' Option 4' ) ), React.createElement( ButtonWithOptions.Option, { id: '5' }, 'Option 5' ) ); } }, { key: 'render', value: function render() { return this.getComponent(); } }]); return Form; }(Component); Form.propTypes = { onChange: PropTypes.func.isRequired, theme: PropTypes.string.isRequired, disabled: PropTypes.bool.isRequired, iconOnly: PropTypes.bool, text: PropTypes.string, height: PropTypes.string, prefixIcon: PropTypes.node, suffixIcon: PropTypes.node, dropdownTheme: PropTypes.string, withArrow: PropTypes.bool }; export default Form;