UNPKG

@roo-ui/components

Version:

103 lines (79 loc) 5.53 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.CalendarEmptyDay = exports.CalendarDay = undefined; 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 _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _styledSystem = require('styled-system'); var _styledComponents = require('styled-components'); var _styledComponents2 = _interopRequireDefault(_styledComponents); var _polished = require('polished'); var _ = require('../../../'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } var DayWrapper = (0, _styledComponents2.default)(_.Box).withConfig({ displayName: 'CalendarDay__DayWrapper' })(['flex:1 1 auto;width:calc(100% / 7);margin:0 -1px -1px 0;position:relative;border:', ' transparent;&:after{content:"";display:block;padding-bottom:100%;}', ';', ';'], (0, _styledSystem.themeGet)('borders.1'), function (props) { return props.selectable && (0, _styledComponents.css)(['&:hover{border-color:', ';z-index:1;}'], (0, _styledSystem.themeGet)('colors.brand.secondary')); }, function (props) { return props.selected && (0, _styledComponents.css)(['z-index:1;border-color:', ';'], (0, _styledSystem.themeGet)('colors.brand.secondary')); }); DayWrapper.defaultProps = _extends({}, _.Box.defaultProps, { blacklist: [].concat(_toConsumableArray(Object.keys(_.Box.propTypes)), ['selected', 'selectable']) }); var Button = (0, _styledComponents2.default)(_.NakedButton).withConfig({ displayName: 'CalendarDay__Button' })(['position:absolute;left:0;top:0;width:100%;height:100%;color:', ';padding:0;border:', ' transparent;&:focus{outline:none;}&:disabled{cursor:not-allowed;background-color:', ';}', ';', ';', ';', ';', ';', ';'], (0, _styledSystem.themeGet)('colors.greys.charcoal'), (0, _styledSystem.themeGet)('borders.1'), (0, _styledSystem.themeGet)('colors.greys.alto'), function (props) { return props.selectable && (0, _styledComponents.css)(['background-color:', ';'], (0, _styledSystem.themeGet)('colors.white')); }, function (props) { return props.selected && !props.highlighted && (0, _styledComponents.css)(['background-color:', ';&:hover,&:focus{border-color:', ';background-color:', ';;}'], (0, _styledSystem.themeGet)('colors.lightBlue'), (0, _styledSystem.themeGet)('colors.brand.secondary'), (0, _styledSystem.themeGet)('colors.white')); }, function (props) { return props.highlighted && !props.selected && (0, _styledComponents.css)(['background-color:', ';&:hover,&:focus{background-color:transparent;border-color:', ';}'], (0, _styledSystem.themeGet)('colors.lightBlue'), (0, _styledSystem.themeGet)('colors.brand.secondary')); }, function (props) { return props.highlighted && props.selected && (0, _styledComponents.css)(['background-color:', ';&:hover{background-color:transparent;border-color:', ';}'], (0, _styledSystem.themeGet)('colors.brand.secondary'), (0, _styledSystem.themeGet)('colors.brand.secondary')); }, function (props) { return props.selectable && !props.selected && (0, _styledComponents.css)(['&:hover,&:focus{background-color:', ';border-color:', ';}'], (0, _styledSystem.themeGet)('colors.white'), (0, _styledSystem.themeGet)('colors.brand.secondary')); }, function (props) { return !props.selectable && !props.disabled && (0, _styledComponents.css)(['background-color:', ';&:hover,&:focus{background-color:', ';}'], (0, _styledSystem.themeGet)('colors.greys.alto'), (0, _polished.darken)(0.1, (0, _styledSystem.themeGet)('colors.greys.alto')(props))); }); Button.defaultProps = _extends({}, _.NakedButton.defaultProps, { disabled: _propTypes2.default.bool, blacklist: [].concat(_toConsumableArray(Object.keys(_.NakedButton.propTypes)), ['selectable', 'highlighted']) }); var CalendarDay = function CalendarDay(_ref) { var children = _ref.children, selected = _ref.selected, rest = _objectWithoutProperties(_ref, ['children', 'selected']); return _react2.default.createElement( DayWrapper, { selected: selected }, _react2.default.createElement( Button, _extends({ selected: selected }, rest), children ) ); }; exports.CalendarDay = CalendarDay; CalendarDay.defaultProps = { selectable: true, disabled: false, selected: false, highlighted: false }; CalendarDay.propTypes = { children: _propTypes2.default.node.isRequired, selected: _propTypes2.default.bool, selectable: _propTypes2.default.bool, disabled: _propTypes2.default.bool, highlighted: _propTypes2.default.bool }; var CalendarEmptyDay = exports.CalendarEmptyDay = (0, _styledComponents2.default)(DayWrapper.withComponent('div')).withConfig({ displayName: 'CalendarDay__CalendarEmptyDay' })(['border-color:transparent;']); CalendarEmptyDay.displayName = 'CalendarEmptyDay';