383 lines
15 KiB
JavaScript
383 lines
15 KiB
JavaScript
"use strict";
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.DatePicker = void 0;
|
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
var React = _interopRequireWildcard(require("react"));
|
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
var _useMediaQuery = _interopRequireDefault(require("@mui/material/useMediaQuery"));
|
|
var _styles = require("@mui/material/styles");
|
|
var _utils = require("@mui/utils");
|
|
var _DesktopDatePicker = require("../DesktopDatePicker");
|
|
var _MobileDatePicker = require("../MobileDatePicker");
|
|
var _utils2 = require("../internals/utils/utils");
|
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
const _excluded = ["desktopModeMediaQuery"];
|
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
/**
|
|
* Demos:
|
|
*
|
|
* - [DatePicker](https://mui.com/x/react-date-pickers/date-picker/)
|
|
* - [Validation](https://mui.com/x/react-date-pickers/validation/)
|
|
*
|
|
* API:
|
|
*
|
|
* - [DatePicker API](https://mui.com/x/api/date-pickers/date-picker/)
|
|
*/
|
|
const DatePicker = exports.DatePicker = /*#__PURE__*/React.forwardRef(function DatePicker(inProps, ref) {
|
|
const props = (0, _styles.useThemeProps)({
|
|
props: inProps,
|
|
name: 'MuiDatePicker'
|
|
});
|
|
const {
|
|
desktopModeMediaQuery = _utils2.DEFAULT_DESKTOP_MODE_MEDIA_QUERY
|
|
} = props,
|
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
|
|
// defaults to `true` in environments where `window.matchMedia` would not be available (i.e. test/jsdom)
|
|
const isDesktop = (0, _useMediaQuery.default)(desktopModeMediaQuery, {
|
|
defaultMatches: true
|
|
});
|
|
if (isDesktop) {
|
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DesktopDatePicker.DesktopDatePicker, (0, _extends2.default)({
|
|
ref: ref
|
|
}, other));
|
|
}
|
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_MobileDatePicker.MobileDatePicker, (0, _extends2.default)({
|
|
ref: ref
|
|
}, other));
|
|
});
|
|
process.env.NODE_ENV !== "production" ? DatePicker.propTypes = {
|
|
// ----------------------------- Warning --------------------------------
|
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
// ----------------------------------------------------------------------
|
|
/**
|
|
* If `true`, the main element is focused during the first mount.
|
|
* This main element is:
|
|
* - the element chosen by the visible view if any (i.e: the selected day on the `day` view).
|
|
* - the `input` element if there is a field rendered.
|
|
*/
|
|
autoFocus: _propTypes.default.bool,
|
|
/**
|
|
* Class name applied to the root element.
|
|
*/
|
|
className: _propTypes.default.string,
|
|
/**
|
|
* If `true`, the popover or modal will close after submitting the full date.
|
|
* @default `true` for desktop, `false` for mobile (based on the chosen wrapper and `desktopModeMediaQuery` prop).
|
|
*/
|
|
closeOnSelect: _propTypes.default.bool,
|
|
/**
|
|
* Overridable components.
|
|
* @default {}
|
|
* @deprecated Please use `slots`.
|
|
*/
|
|
components: _propTypes.default.object,
|
|
/**
|
|
* The props used for each component slot.
|
|
* @default {}
|
|
* @deprecated Please use `slotProps`.
|
|
*/
|
|
componentsProps: _propTypes.default.object,
|
|
/**
|
|
* Formats the day of week displayed in the calendar header.
|
|
* @param {string} day The day of week provided by the adapter. Deprecated, will be removed in v7: Use `date` instead.
|
|
* @param {TDate} date The date of the day of week provided by the adapter.
|
|
* @returns {string} The name to display.
|
|
* @default (_day: string, date: TDate) => adapter.format(date, 'weekdayShort').charAt(0).toUpperCase()
|
|
*/
|
|
dayOfWeekFormatter: _propTypes.default.func,
|
|
/**
|
|
* Default calendar month displayed when `value` and `defaultValue` are empty.
|
|
* @deprecated Consider using `referenceDate` instead.
|
|
*/
|
|
defaultCalendarMonth: _propTypes.default.any,
|
|
/**
|
|
* The default value.
|
|
* Used when the component is not controlled.
|
|
*/
|
|
defaultValue: _propTypes.default.any,
|
|
/**
|
|
* CSS media query when `Mobile` mode will be changed to `Desktop`.
|
|
* @default '@media (pointer: fine)'
|
|
* @example '@media (min-width: 720px)' or theme.breakpoints.up("sm")
|
|
*/
|
|
desktopModeMediaQuery: _propTypes.default.string,
|
|
/**
|
|
* If `true`, the picker and text field are disabled.
|
|
* @default false
|
|
*/
|
|
disabled: _propTypes.default.bool,
|
|
/**
|
|
* If `true`, disable values after the current date for date components, time for time components and both for date time components.
|
|
* @default false
|
|
*/
|
|
disableFuture: _propTypes.default.bool,
|
|
/**
|
|
* If `true`, today's date is rendering without highlighting with circle.
|
|
* @default false
|
|
*/
|
|
disableHighlightToday: _propTypes.default.bool,
|
|
/**
|
|
* If `true`, the open picker button will not be rendered (renders only the field).
|
|
* @default false
|
|
*/
|
|
disableOpenPicker: _propTypes.default.bool,
|
|
/**
|
|
* If `true`, disable values before the current date for date components, time for time components and both for date time components.
|
|
* @default false
|
|
*/
|
|
disablePast: _propTypes.default.bool,
|
|
/**
|
|
* If `true`, the week number will be display in the calendar.
|
|
*/
|
|
displayWeekNumber: _propTypes.default.bool,
|
|
/**
|
|
* Calendar will show more weeks in order to match this value.
|
|
* Put it to 6 for having fix number of week in Gregorian calendars
|
|
* @default undefined
|
|
*/
|
|
fixedWeekNumber: _propTypes.default.number,
|
|
/**
|
|
* Format of the date when rendered in the input(s).
|
|
* Defaults to localized format based on the used `views`.
|
|
*/
|
|
format: _propTypes.default.string,
|
|
/**
|
|
* Density of the format when rendered in the input.
|
|
* Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
|
|
* @default "dense"
|
|
*/
|
|
formatDensity: _propTypes.default.oneOf(['dense', 'spacious']),
|
|
/**
|
|
* Pass a ref to the `input` element.
|
|
*/
|
|
inputRef: _utils.refType,
|
|
/**
|
|
* The label content.
|
|
*/
|
|
label: _propTypes.default.node,
|
|
/**
|
|
* If `true`, calls `renderLoading` instead of rendering the day calendar.
|
|
* Can be used to preload information and show it in calendar.
|
|
* @default false
|
|
*/
|
|
loading: _propTypes.default.bool,
|
|
/**
|
|
* Locale for components texts.
|
|
* Allows overriding texts coming from `LocalizationProvider` and `theme`.
|
|
*/
|
|
localeText: _propTypes.default.object,
|
|
/**
|
|
* Maximal selectable date.
|
|
*/
|
|
maxDate: _propTypes.default.any,
|
|
/**
|
|
* Minimal selectable date.
|
|
*/
|
|
minDate: _propTypes.default.any,
|
|
/**
|
|
* Months rendered per row.
|
|
* @default 3
|
|
*/
|
|
monthsPerRow: _propTypes.default.oneOf([3, 4]),
|
|
/**
|
|
* Name attribute used by the `input` element in the Field.
|
|
*/
|
|
name: _propTypes.default.string,
|
|
/**
|
|
* Callback fired when the value is accepted.
|
|
* @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
|
|
* @param {TValue} value The value that was just accepted.
|
|
*/
|
|
onAccept: _propTypes.default.func,
|
|
/**
|
|
* Callback fired when the value changes.
|
|
* @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
|
|
* @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
|
|
* @param {TValue} value The new value.
|
|
* @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
|
|
*/
|
|
onChange: _propTypes.default.func,
|
|
/**
|
|
* Callback fired when the popup requests to be closed.
|
|
* Use in controlled mode (see `open`).
|
|
*/
|
|
onClose: _propTypes.default.func,
|
|
/**
|
|
* Callback fired when the error associated to the current value changes.
|
|
* If the error has a non-null value, then the `TextField` will be rendered in `error` state.
|
|
*
|
|
* @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
|
|
* @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value.
|
|
* @param {TError} error The new error describing why the current value is not valid.
|
|
* @param {TValue} value The value associated to the error.
|
|
*/
|
|
onError: _propTypes.default.func,
|
|
/**
|
|
* Callback fired on month change.
|
|
* @template TDate
|
|
* @param {TDate} month The new month.
|
|
*/
|
|
onMonthChange: _propTypes.default.func,
|
|
/**
|
|
* Callback fired when the popup requests to be opened.
|
|
* Use in controlled mode (see `open`).
|
|
*/
|
|
onOpen: _propTypes.default.func,
|
|
/**
|
|
* Callback fired when the selected sections change.
|
|
* @param {FieldSelectedSections} newValue The new selected sections.
|
|
*/
|
|
onSelectedSectionsChange: _propTypes.default.func,
|
|
/**
|
|
* Callback fired on view change.
|
|
* @template TView
|
|
* @param {TView} view The new view.
|
|
*/
|
|
onViewChange: _propTypes.default.func,
|
|
/**
|
|
* Callback fired on year change.
|
|
* @template TDate
|
|
* @param {TDate} year The new year.
|
|
*/
|
|
onYearChange: _propTypes.default.func,
|
|
/**
|
|
* Control the popup or dialog open state.
|
|
* @default false
|
|
*/
|
|
open: _propTypes.default.bool,
|
|
/**
|
|
* The default visible view.
|
|
* Used when the component view is not controlled.
|
|
* Must be a valid option from `views` list.
|
|
*/
|
|
openTo: _propTypes.default.oneOf(['day', 'month', 'year']),
|
|
/**
|
|
* Force rendering in particular orientation.
|
|
*/
|
|
orientation: _propTypes.default.oneOf(['landscape', 'portrait']),
|
|
readOnly: _propTypes.default.bool,
|
|
/**
|
|
* If `true`, disable heavy animations.
|
|
* @default `@media(prefers-reduced-motion: reduce)` || `navigator.userAgent` matches Android <10 or iOS <13
|
|
*/
|
|
reduceAnimations: _propTypes.default.bool,
|
|
/**
|
|
* The date used to generate the new value when both `value` and `defaultValue` are empty.
|
|
* @default The closest valid date-time using the validation props, except callbacks like `shouldDisable<...>`.
|
|
*/
|
|
referenceDate: _propTypes.default.any,
|
|
/**
|
|
* Component displaying when passed `loading` true.
|
|
* @returns {React.ReactNode} The node to render when loading.
|
|
* @default () => <span data-mui-test="loading-progress">...</span>
|
|
*/
|
|
renderLoading: _propTypes.default.func,
|
|
/**
|
|
* The currently selected sections.
|
|
* This prop accept four formats:
|
|
* 1. If a number is provided, the section at this index will be selected.
|
|
* 2. If an object with a `startIndex` and `endIndex` properties are provided, the sections between those two indexes will be selected.
|
|
* 3. If a string of type `FieldSectionType` is provided, the first section with that name will be selected.
|
|
* 4. If `null` is provided, no section will be selected
|
|
* If not provided, the selected sections will be handled internally.
|
|
*/
|
|
selectedSections: _propTypes.default.oneOfType([_propTypes.default.oneOf(['all', 'day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'weekDay', 'year']), _propTypes.default.number, _propTypes.default.shape({
|
|
endIndex: _propTypes.default.number.isRequired,
|
|
startIndex: _propTypes.default.number.isRequired
|
|
})]),
|
|
/**
|
|
* Disable specific date.
|
|
*
|
|
* Warning: This function can be called multiple times (e.g. when rendering date calendar, checking if focus can be moved to a certain date, etc.). Expensive computations can impact performance.
|
|
*
|
|
* @template TDate
|
|
* @param {TDate} day The date to test.
|
|
* @returns {boolean} If `true` the date will be disabled.
|
|
*/
|
|
shouldDisableDate: _propTypes.default.func,
|
|
/**
|
|
* Disable specific month.
|
|
* @template TDate
|
|
* @param {TDate} month The month to test.
|
|
* @returns {boolean} If `true`, the month will be disabled.
|
|
*/
|
|
shouldDisableMonth: _propTypes.default.func,
|
|
/**
|
|
* Disable specific year.
|
|
* @template TDate
|
|
* @param {TDate} year The year to test.
|
|
* @returns {boolean} If `true`, the year will be disabled.
|
|
*/
|
|
shouldDisableYear: _propTypes.default.func,
|
|
/**
|
|
* If `true`, days outside the current month are rendered:
|
|
*
|
|
* - if `fixedWeekNumber` is defined, renders days to have the weeks requested.
|
|
*
|
|
* - if `fixedWeekNumber` is not defined, renders day to fill the first and last week of the current month.
|
|
*
|
|
* - ignored if `calendars` equals more than `1` on range pickers.
|
|
* @default false
|
|
*/
|
|
showDaysOutsideCurrentMonth: _propTypes.default.bool,
|
|
/**
|
|
* The props used for each component slot.
|
|
* @default {}
|
|
*/
|
|
slotProps: _propTypes.default.object,
|
|
/**
|
|
* Overridable component slots.
|
|
* @default {}
|
|
*/
|
|
slots: _propTypes.default.object,
|
|
/**
|
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
*/
|
|
sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
|
|
/**
|
|
* Choose which timezone to use for the value.
|
|
* Example: "default", "system", "UTC", "America/New_York".
|
|
* If you pass values from other timezones to some props, they will be converted to this timezone before being used.
|
|
* @see See the {@link https://mui.com/x/react-date-pickers/timezone/ timezones documention} for more details.
|
|
* @default The timezone of the `value` or `defaultValue` prop is defined, 'default' otherwise.
|
|
*/
|
|
timezone: _propTypes.default.string,
|
|
/**
|
|
* The selected value.
|
|
* Used when the component is controlled.
|
|
*/
|
|
value: _propTypes.default.any,
|
|
/**
|
|
* The visible view.
|
|
* Used when the component view is controlled.
|
|
* Must be a valid option from `views` list.
|
|
*/
|
|
view: _propTypes.default.oneOf(['day', 'month', 'year']),
|
|
/**
|
|
* Define custom view renderers for each section.
|
|
* If `null`, the section will only have field editing.
|
|
* If `undefined`, internally defined view will be the used.
|
|
*/
|
|
viewRenderers: _propTypes.default.shape({
|
|
day: _propTypes.default.func,
|
|
month: _propTypes.default.func,
|
|
year: _propTypes.default.func
|
|
}),
|
|
/**
|
|
* Available views.
|
|
*/
|
|
views: _propTypes.default.arrayOf(_propTypes.default.oneOf(['day', 'month', 'year']).isRequired),
|
|
/**
|
|
* Years rendered per row.
|
|
* @default 4 on desktop, 3 on mobile
|
|
*/
|
|
yearsPerRow: _propTypes.default.oneOf([3, 4])
|
|
} : void 0; |