UNPKG

wix-style-react

Version:
120 lines (108 loc) 4.71 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 from 'react'; import Calendar from '../../src/Calendar'; import ToggleSwitch from 'wix-style-react/ToggleSwitch'; import Label from 'wix-style-react/Label'; var ControlledCalendarExample = function (_React$Component) { _inherits(ControlledCalendarExample, _React$Component); function ControlledCalendarExample(props) { _classCallCheck(this, ControlledCalendarExample); var _this = _possibleConstructorReturn(this, (ControlledCalendarExample.__proto__ || Object.getPrototypeOf(ControlledCalendarExample)).call(this, props)); _this.state = { value: { from: new Date('2018/11/14'), to: new Date('2018/11/18') }, excludePastDates: false, twoMonths: false, selectionMode: 'range' }; return _this; } _createClass(ControlledCalendarExample, [{ key: 'onChange', value: function onChange(value) { this.setState({ value: value }); } }, { key: 'onMonthChange', value: function onMonthChange(value) { this.setState({ month: value }); } }, { key: 'toggleExclude', value: function toggleExclude() { this.setState(function (_ref) { var excludePastDates = _ref.excludePastDates; return { excludePastDates: !excludePastDates }; }); } }, { key: 'toggleSelectionMode', value: function toggleSelectionMode() { this.setState({ selectionMode: this.state.selectionMode === 'day' ? 'range' : 'day' }); } }, { key: 'render', value: function render() { var _this2 = this; return React.createElement( 'div', null, React.createElement(Calendar, { excludePastDates: this.state.excludePastDates, onChange: function onChange(value) { return _this2.onChange(value); }, onMonthChange: function onMonthChange(value) { return _this2.onMonthChange(value); }, value: this.state.value, month: this.state.month, selectionMode: this.state.selectionMode, twoMonths: this.state.twoMonths }), React.createElement( 'div', { style: { display: 'flex' } }, React.createElement(ToggleSwitch, { checked: this.state.excludePastDates, onChange: function onChange() { return _this2.toggleExclude(); } }), React.createElement( Label, null, 'Exclude Past Days' ) ), React.createElement( 'div', { style: { display: 'flex' } }, React.createElement(ToggleSwitch, { checked: this.state.selectionMode === 'day', onChange: function onChange() { return _this2.toggleSelectionMode(); } }), React.createElement( Label, null, 'Selection Mode:', ' ', this.state.selectionMode === 'day' ? 'Single day' : 'Date range' ) ) ); } }]); return ControlledCalendarExample; }(React.Component); export default (function () { return React.createElement(ControlledCalendarExample, null); });