wix-style-react
Version:
wix-style-react
132 lines (117 loc) • 5.61 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; }; }();
var _class, _temp;
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 PropTypes from 'prop-types';
import Text from '../Text';
import { Item, ItemGroup, Toolbar } from '../TableToolbar';
import Calendar from '../Calendar';
import Button from '../Button';
var CalendarPanelFooter = (_temp = _class = function (_React$PureComponent) {
_inherits(CalendarPanelFooter, _React$PureComponent);
function CalendarPanelFooter() {
_classCallCheck(this, CalendarPanelFooter);
return _possibleConstructorReturn(this, (CalendarPanelFooter.__proto__ || Object.getPrototypeOf(CalendarPanelFooter)).apply(this, arguments));
}
_createClass(CalendarPanelFooter, [{
key: 'render',
value: function render() {
var _props = this.props,
dataHook = _props.dataHook,
dateToString = _props.dateToString,
secondaryActionLabel = _props.secondaryActionLabel,
primaryActionLabel = _props.primaryActionLabel,
selectedDaysProp = _props.selectedDays,
primaryActionDisabled = _props.primaryActionDisabled,
primaryActionOnClick = _props.primaryActionOnClick,
secondaryActionOnClick = _props.secondaryActionOnClick;
function getSelectedDaysString(selectedDaysRaw) {
if (!selectedDaysRaw) {
return '';
}
var selectedDays = Calendar.parseValue(selectedDaysRaw);
if (Calendar.isRangeValue(selectedDays)) {
var toSuffix = selectedDays.to ? ' ' + dateToString(selectedDays.to) : '';
return dateToString(selectedDays.from) + ' -' + toSuffix;
} else {
return dateToString(selectedDays);
}
}
return React.createElement(
'div',
{ 'data-hook': dataHook },
React.createElement(
Toolbar,
null,
React.createElement(
ItemGroup,
{ position: 'start' },
React.createElement(
Item,
null,
React.createElement(
Text,
{
size: 'small',
weight: 'thin',
secondary: true,
dataHook: 'selected-days-text'
},
getSelectedDaysString(selectedDaysProp)
)
)
),
React.createElement(
ItemGroup,
{ position: 'end' },
React.createElement(
Item,
null,
React.createElement(
Button,
{
upgrade: true,
priority: 'secondary',
dataHook: 'secondary-action-button',
onClick: secondaryActionOnClick
},
secondaryActionLabel
)
),
React.createElement(
Item,
null,
React.createElement(
Button,
{
upgrade: true,
disabled: primaryActionDisabled,
dataHook: 'primary-action-button',
onClick: primaryActionOnClick
},
primaryActionLabel
)
)
)
)
);
}
}]);
return CalendarPanelFooter;
}(React.PureComponent), _class.displayName = 'CalendarPanelFooter', _class.propTypes = {
dataHook: PropTypes.string,
primaryActionLabel: PropTypes.string.isRequired,
secondaryActionLabel: PropTypes.string.isRequired,
primaryActionDisabled: PropTypes.bool.isRequired,
primaryActionOnClick: PropTypes.func.isRequired,
secondaryActionOnClick: PropTypes.func.isRequired,
selectedDays: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date), PropTypes.shape({
from: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
to: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)])
})]),
/** Formats a Date into a string for displaying the current slected days. Receives a Date instance (not undefined). */
dateToString: PropTypes.func.isRequired
}, _temp);
export default CalendarPanelFooter;