UNPKG

@enact/sandstone

Version:

Large-screen/TV support library for Enact, containing a variety of UI components.

348 lines (346 loc) 13.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = exports.DatePickerBase = void 0; var _kind = _interopRequireDefault(require("@enact/core/kind")); var _propTypes = _interopRequireDefault(require("prop-types")); var _$L = _interopRequireDefault(require("../internal/$L")); var _DateComponentPicker = require("../internal/DateComponentPicker"); var _DateTime = _interopRequireDefault(require("../internal/DateTime")); var _DatePickerModule = _interopRequireDefault(require("./DatePicker.module.css")); var _jsxRuntime = require("react/jsx-runtime"); var _excluded = ["data-webos-voice-disabled", "disabled", "day", "dayAriaLabel", "maxDays", "maxMonths", "maxYear", "minYear", "month", "monthAriaLabel", "noLabel", "onChangeDate", "onChangeMonth", "onChangeYear", "onSpotlightDisappear", "onSpotlightLeft", "onSpotlightRight", "order", "rtl", "spotlightDisabled", "year", "yearAriaLabel"]; /** * A date selection component. * * This component is most often not used directly but may be composed within another component as it * is within {@link sandstone/DatePicker.DatePicker|DatePicker}. * * @class DatePickerBase * @memberof sandstone/DatePicker * @ui * @public */ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } var DatePickerBase = exports.DatePickerBase = (0, _kind["default"])({ name: 'DatePickerBase', propTypes: /** @lends sandstone/DatePicker.DatePickerBase.prototype */{ /** * The `day` component of the Date. * * The value should be a number between 1 and `maxDays`. * * @type {Number} * @required * @public */ day: _propTypes["default"].number.isRequired, /** * The number of days in the month. * * @type {Number} * @required * @public */ maxDays: _propTypes["default"].number.isRequired, /** * The number of months in the year. * * @type {Number} * @required * @public */ maxMonths: _propTypes["default"].number.isRequired, /** * The `month` component of the Date. * * The value should be a number between 1 and `maxMonths`. * * @type {Number} * @required * @public */ month: _propTypes["default"].number.isRequired, /** * The order in which the component pickers are displayed. * * The value should be an array of 3 strings containing one of `'m'`, `'d'`, and `'y'`. * * @type {String[]} * @required * @public */ order: _propTypes["default"].arrayOf(_propTypes["default"].oneOf(['m', 'd', 'y'])).isRequired, /** * The `year` component of the Date. * * @type {Number} * @required * @public */ year: _propTypes["default"].number.isRequired, /** * Disables voice control. * * @type {Boolean} * @memberof sandstone/DatePicker.DatePickerBase.prototype * @public */ 'data-webos-voice-disabled': _propTypes["default"].bool, /** * The "aria-label" for the day picker. * * If not specified, the "aria-label" for the day picker will be * a combination of the current value and 'day change a value with up down button'. * * @type {String} * @public */ dayAriaLabel: _propTypes["default"].string, /** * Disables the `DatePicker`. * * @type {Boolean} * @public */ disabled: _propTypes["default"].bool, /** * The primary text of the `DatePicker`. * * @type {String} * @public */ label: _propTypes["default"].string, /** * The maximum selectable `year` value. * * @type {Number} * @default 2099 * @public */ maxYear: _propTypes["default"].number, /** * The minimum selectable `year` value. * * @type {Number} * @default 1900 * @public */ minYear: _propTypes["default"].number, /** * The "aria-label" for the month picker. * * If not specified, the "aria-label" for the month picker will be * a combination of the current value and 'month change a value with up down button'. * * @type {String} * @public */ monthAriaLabel: _propTypes["default"].string, /** * Hides the label that displays the date. * * @type {Boolean} * @public */ noLabel: _propTypes["default"].bool, /** * Called when the `date` component of the Date changes. * * @type {Function} * @public */ onChangeDate: _propTypes["default"].func, /** * Called when the `month` component of the Date changes. * * @type {Function} * @public */ onChangeMonth: _propTypes["default"].func, /** * Called when the `year` component of the Date changes. * * @type {Function} * @public */ onChangeYear: _propTypes["default"].func, /** * Called when the component is removed when it had focus. * * @type {Function} * @param {Object} event * @public */ onSpotlightDisappear: _propTypes["default"].func, /** * Called prior to focus leaving the picker when the 5-way left key is pressed. * * @type {Function} * @param {Object} event * @public */ onSpotlightLeft: _propTypes["default"].func, /** * Called prior to focus leaving the picker when the 5-way right key is pressed. * * @type {Function} * @param {Object} event * @public */ onSpotlightRight: _propTypes["default"].func, /** * Indicates the content's text direction is right-to-left. * * @type {Boolean} * @private */ rtl: _propTypes["default"].bool, /** * Disables 5-way spotlight from navigating into the component. * * @type {Boolean} * @default false * @public */ spotlightDisabled: _propTypes["default"].bool, /** * The "aria-label" for the year picker. * * If not specified, the "aria-label" for the year picker will be * a combination of the current value and 'year change a value with up down button'. * * @type {String} * @public */ yearAriaLabel: _propTypes["default"].string }, defaultProps: { maxYear: 2099, minYear: 1900, disabled: false, spotlightDisabled: false }, styles: { css: _DatePickerModule["default"], className: 'datePicker' }, render: function render(_ref) { var voiceDisabled = _ref['data-webos-voice-disabled'], disabled = _ref.disabled, day = _ref.day, dayAriaLabel = _ref.dayAriaLabel, maxDays = _ref.maxDays, maxMonths = _ref.maxMonths, maxYear = _ref.maxYear, minYear = _ref.minYear, month = _ref.month, monthAriaLabel = _ref.monthAriaLabel, noLabel = _ref.noLabel, onChangeDate = _ref.onChangeDate, onChangeMonth = _ref.onChangeMonth, onChangeYear = _ref.onChangeYear, onSpotlightDisappear = _ref.onSpotlightDisappear, onSpotlightLeft = _ref.onSpotlightLeft, onSpotlightRight = _ref.onSpotlightRight, order = _ref.order, rtl = _ref.rtl, spotlightDisabled = _ref.spotlightDisabled, year = _ref.year, yearAriaLabel = _ref.yearAriaLabel, rest = _objectWithoutProperties(_ref, _excluded); var dayAccessibilityHint = (0, _$L["default"])('day'), monthAccessibilityHint = (0, _$L["default"])('month'), yearAccessibilityHint = (0, _$L["default"])('year'); if (noLabel) { delete rest.label; } return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateTime["default"], _objectSpread(_objectSpread({}, rest), {}, { children: order.map(function (picker, index) { var isFirst = index === 0; var isLast = index === order.length - 1; var isLeft = isFirst && !rtl || isLast && rtl; var isRight = isFirst && rtl || isLast && !rtl; switch (picker) { case 'd': return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateComponentPicker.DateComponentRangePicker, { accessibilityHint: dayAccessibilityHint, "aria-label": dayAriaLabel, className: _DatePickerModule["default"].day, "data-last-element": isLast, "data-webos-voice-disabled": voiceDisabled, "data-webos-voice-group-label": dayAccessibilityHint, disabled: disabled, max: maxDays, min: 1, onChange: onChangeDate, onSpotlightDisappear: onSpotlightDisappear, onSpotlightLeft: isLeft ? onSpotlightLeft : null, onSpotlightRight: isRight ? onSpotlightRight : null, spotlightDisabled: spotlightDisabled, value: day, width: 4, wrap: true }, "day-picker"); case 'm': return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateComponentPicker.DateComponentRangePicker, { accessibilityHint: monthAccessibilityHint, "aria-label": monthAriaLabel, className: _DatePickerModule["default"].month, "data-last-element": isLast, "data-webos-voice-disabled": voiceDisabled, "data-webos-voice-group-label": monthAccessibilityHint, disabled: disabled, max: maxMonths, min: 1, onChange: onChangeMonth, onSpotlightDisappear: onSpotlightDisappear, onSpotlightLeft: isLeft ? onSpotlightLeft : null, onSpotlightRight: isRight ? onSpotlightRight : null, spotlightDisabled: spotlightDisabled, value: month, width: 4, wrap: true }, "month-picker"); case 'y': return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateComponentPicker.DateComponentRangePicker, { accessibilityHint: yearAccessibilityHint, "aria-label": yearAriaLabel, className: _DatePickerModule["default"].year, "data-last-element": isLast, "data-webos-voice-disabled": voiceDisabled, "data-webos-voice-group-label": yearAccessibilityHint, disabled: disabled, max: maxYear, min: minYear, onChange: onChangeYear, onSpotlightDisappear: onSpotlightDisappear, onSpotlightLeft: isLeft ? onSpotlightLeft : null, onSpotlightRight: isRight ? onSpotlightRight : null, spotlightDisabled: spotlightDisabled, value: year, width: 4 }, "year-picker"); } return null; }) })); } }); /** * Called when `Enter` key down on the last picker * * @name onComplete * @memberof sandstone/DatePicker.DatePickerBase.prototype * @type {Function} * @public */ var _default = exports["default"] = DatePickerBase;