UNPKG

@atlaskit/datetime-picker

Version:

A date time picker allows the user to select an associated date and time.

80 lines (77 loc) 3.01 kB
/* menu.tsx generated by @compiled/babel-plugin v3.0.2 */ import _extends from "@babel/runtime/helpers/extends"; import "./menu.compiled.css"; import * as React from 'react'; import { ax, ix } from "@compiled/react/runtime"; import { Fragment } from 'react'; // oxlint-disable-next-line @atlassian/no-restricted-imports import { isValid, parseISO } from 'date-fns'; import Calendar from '@atlaskit/calendar/calendar'; import { Layering } from '@atlaskit/layering/layering'; import FixedLayer from '../internal/fixed-layer'; /** * @param isos A series of ISO dates. * @returns The last valid date within the array of ISO strings. */ function getValidDate(isos) { return isos.reduce(function (acc, iso) { var date = parseISO(iso); return isValid(date) ? { day: date.getDate(), month: date.getMonth() + 1, year: date.getFullYear() } : acc; }, {}); } var menuStyles = null; /** * This is the menu used in the select of the date picker. */ export var Menu = function Menu(_ref) { var selectProps = _ref.selectProps, innerProps = _ref.innerProps; var calendarValue = selectProps.calendarValue, calendarView = selectProps.calendarView, MenuInnerWrapper = selectProps.menuInnerWrapper; var _getValidDate = getValidDate([calendarValue, calendarView]), day = _getValidDate.day, month = _getValidDate.month, year = _getValidDate.year; var onMenuMouseDown = function onMenuMouseDown(event) { if (event.button !== 0) { return; } event.stopPropagation(); event.preventDefault(); }; var Wrapper = typeof MenuInnerWrapper === 'function' ? MenuInnerWrapper : Fragment; return /*#__PURE__*/React.createElement(Layering, { isDisabled: false }, /*#__PURE__*/React.createElement(FixedLayer, { inputValue: selectProps.inputValue, containerRef: selectProps.calendarContainerRef, content: /*#__PURE__*/React.createElement("div", _extends({}, innerProps, { onMouseDown: onMenuMouseDown, className: ax(["_2rko1mok _1reo15vq _18m915vq _1pbyowjs _bfhk1bhr _16qs130s"]) }), /*#__PURE__*/React.createElement(Wrapper, null, /*#__PURE__*/React.createElement(Calendar, { day: day, month: month, year: year, disabled: selectProps.calendarDisabled, disabledDateFilter: selectProps.calendarDisabledDateFilter, minDate: selectProps.calendarMinDate, maxDate: selectProps.calendarMaxDate, nextMonthLabel: selectProps.nextMonthLabel, onChange: selectProps.onCalendarChange, onSelect: selectProps.onCalendarSelect, previousMonthLabel: selectProps.previousMonthLabel, ref: selectProps.calendarRef, selected: [selectProps.calendarValue], shouldSetFocusOnCurrentDay: selectProps.shouldSetFocusOnCurrentDay, locale: selectProps.calendarLocale, testId: selectProps.testId && "".concat(selectProps.testId, "--calendar"), weekStartDay: selectProps.calendarWeekStartDay }))), testId: selectProps.testId })); };