386 lines
14 KiB
JavaScript
386 lines
14 KiB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
import * as React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { useDateTimePickerDefaultizedProps } from '../DateTimePicker/shared';
|
|
import { renderTimeViewClock } from '../timeViewRenderers';
|
|
import { renderDateViewCalendar } from '../dateViewRenderers';
|
|
import { singleItemValueManager } from '../internals/utils/valueManagers';
|
|
import { useStaticPicker } from '../internals/hooks/useStaticPicker';
|
|
import { validateDateTime } from '../internals/utils/validation/validateDateTime';
|
|
/**
|
|
* Demos:
|
|
*
|
|
* - [DateTimePicker](https://mui.com/x/react-date-pickers/date-time-picker/)
|
|
* - [Validation](https://mui.com/x/react-date-pickers/validation/)
|
|
*
|
|
* API:
|
|
*
|
|
* - [StaticDateTimePicker API](https://mui.com/x/api/date-pickers/static-date-time-picker/)
|
|
*/
|
|
const StaticDateTimePicker = /*#__PURE__*/React.forwardRef(function StaticDateTimePicker(inProps, ref) {
|
|
var _defaultizedProps$dis, _defaultizedProps$amp, _defaultizedProps$yea, _defaultizedProps$slo, _defaultizedProps$slo2;
|
|
const defaultizedProps = useDateTimePickerDefaultizedProps(inProps, 'MuiStaticDateTimePicker');
|
|
const displayStaticWrapperAs = (_defaultizedProps$dis = defaultizedProps.displayStaticWrapperAs) != null ? _defaultizedProps$dis : 'mobile';
|
|
const ampmInClock = (_defaultizedProps$amp = defaultizedProps.ampmInClock) != null ? _defaultizedProps$amp : displayStaticWrapperAs === 'desktop';
|
|
const viewRenderers = _extends({
|
|
day: renderDateViewCalendar,
|
|
month: renderDateViewCalendar,
|
|
year: renderDateViewCalendar,
|
|
hours: renderTimeViewClock,
|
|
minutes: renderTimeViewClock,
|
|
seconds: renderTimeViewClock
|
|
}, defaultizedProps.viewRenderers);
|
|
|
|
// Props with the default values specific to the static variant
|
|
const props = _extends({}, defaultizedProps, {
|
|
viewRenderers,
|
|
displayStaticWrapperAs,
|
|
ampmInClock,
|
|
yearsPerRow: (_defaultizedProps$yea = defaultizedProps.yearsPerRow) != null ? _defaultizedProps$yea : displayStaticWrapperAs === 'mobile' ? 3 : 4,
|
|
slotProps: _extends({}, defaultizedProps.slotProps, {
|
|
tabs: _extends({
|
|
hidden: displayStaticWrapperAs === 'desktop'
|
|
}, (_defaultizedProps$slo = defaultizedProps.slotProps) == null ? void 0 : _defaultizedProps$slo.tabs),
|
|
toolbar: _extends({
|
|
hidden: displayStaticWrapperAs === 'desktop',
|
|
ampmInClock
|
|
}, (_defaultizedProps$slo2 = defaultizedProps.slotProps) == null ? void 0 : _defaultizedProps$slo2.toolbar)
|
|
})
|
|
});
|
|
const {
|
|
renderPicker
|
|
} = useStaticPicker({
|
|
props,
|
|
valueManager: singleItemValueManager,
|
|
valueType: 'date-time',
|
|
validator: validateDateTime,
|
|
ref
|
|
});
|
|
return renderPicker();
|
|
});
|
|
StaticDateTimePicker.propTypes = {
|
|
// ----------------------------- Warning --------------------------------
|
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
// ----------------------------------------------------------------------
|
|
/**
|
|
* 12h/24h view for hour selection clock.
|
|
* @default `utils.is12HourCycleInCurrentLocale()`
|
|
*/
|
|
ampm: PropTypes.bool,
|
|
/**
|
|
* Display ampm controls under the clock (instead of in the toolbar).
|
|
* @default true on desktop, false on mobile
|
|
*/
|
|
ampmInClock: PropTypes.bool,
|
|
/**
|
|
* 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.bool,
|
|
/**
|
|
* Class name applied to the root element.
|
|
*/
|
|
className: PropTypes.string,
|
|
/**
|
|
* Overridable components.
|
|
* @default {}
|
|
* @deprecated Please use `slots`.
|
|
*/
|
|
components: PropTypes.object,
|
|
/**
|
|
* The props used for each component slot.
|
|
* @default {}
|
|
* @deprecated Please use `slotProps`.
|
|
*/
|
|
componentsProps: PropTypes.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.func,
|
|
/**
|
|
* Default calendar month displayed when `value` and `defaultValue` are empty.
|
|
* @deprecated Consider using `referenceDate` instead.
|
|
*/
|
|
defaultCalendarMonth: PropTypes.any,
|
|
/**
|
|
* The default value.
|
|
* Used when the component is not controlled.
|
|
*/
|
|
defaultValue: PropTypes.any,
|
|
/**
|
|
* If `true`, the picker and text field are disabled.
|
|
* @default false
|
|
*/
|
|
disabled: PropTypes.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.bool,
|
|
/**
|
|
* If `true`, today's date is rendering without highlighting with circle.
|
|
* @default false
|
|
*/
|
|
disableHighlightToday: PropTypes.bool,
|
|
/**
|
|
* Do not ignore date part when validating min/max time.
|
|
* @default false
|
|
*/
|
|
disableIgnoringDatePartForTimeValidation: PropTypes.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.bool,
|
|
/**
|
|
* Force static wrapper inner components to be rendered in mobile or desktop mode.
|
|
* @default "mobile"
|
|
*/
|
|
displayStaticWrapperAs: PropTypes.oneOf(['desktop', 'mobile']),
|
|
/**
|
|
* If `true`, the week number will be display in the calendar.
|
|
*/
|
|
displayWeekNumber: PropTypes.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.number,
|
|
/**
|
|
* 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.bool,
|
|
/**
|
|
* Locale for components texts.
|
|
* Allows overriding texts coming from `LocalizationProvider` and `theme`.
|
|
*/
|
|
localeText: PropTypes.object,
|
|
/**
|
|
* Maximal selectable date.
|
|
*/
|
|
maxDate: PropTypes.any,
|
|
/**
|
|
* Maximal selectable moment of time with binding to date, to set max time in each day use `maxTime`.
|
|
*/
|
|
maxDateTime: PropTypes.any,
|
|
/**
|
|
* Maximal selectable time.
|
|
* The date part of the object will be ignored unless `props.disableIgnoringDatePartForTimeValidation === true`.
|
|
*/
|
|
maxTime: PropTypes.any,
|
|
/**
|
|
* Minimal selectable date.
|
|
*/
|
|
minDate: PropTypes.any,
|
|
/**
|
|
* Minimal selectable moment of time with binding to date, to set min time in each day use `minTime`.
|
|
*/
|
|
minDateTime: PropTypes.any,
|
|
/**
|
|
* Minimal selectable time.
|
|
* The date part of the object will be ignored unless `props.disableIgnoringDatePartForTimeValidation === true`.
|
|
*/
|
|
minTime: PropTypes.any,
|
|
/**
|
|
* Step over minutes.
|
|
* @default 1
|
|
*/
|
|
minutesStep: PropTypes.number,
|
|
/**
|
|
* Months rendered per row.
|
|
* @default 3
|
|
*/
|
|
monthsPerRow: PropTypes.oneOf([3, 4]),
|
|
/**
|
|
* 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.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.func,
|
|
/**
|
|
* Callback fired when component requests to be closed.
|
|
* Can be fired when selecting (by default on `desktop` mode) or clearing a value.
|
|
* @deprecated Please avoid using as it will be removed in next major version.
|
|
*/
|
|
onClose: PropTypes.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.func,
|
|
/**
|
|
* Callback fired on month change.
|
|
* @template TDate
|
|
* @param {TDate} month The new month.
|
|
*/
|
|
onMonthChange: PropTypes.func,
|
|
/**
|
|
* Callback fired on view change.
|
|
* @template TView
|
|
* @param {TView} view The new view.
|
|
*/
|
|
onViewChange: PropTypes.func,
|
|
/**
|
|
* Callback fired on year change.
|
|
* @template TDate
|
|
* @param {TDate} year The new year.
|
|
*/
|
|
onYearChange: PropTypes.func,
|
|
/**
|
|
* The default visible view.
|
|
* Used when the component view is not controlled.
|
|
* Must be a valid option from `views` list.
|
|
*/
|
|
openTo: PropTypes.oneOf(['day', 'hours', 'minutes', 'month', 'seconds', 'year']),
|
|
/**
|
|
* Force rendering in particular orientation.
|
|
*/
|
|
orientation: PropTypes.oneOf(['landscape', 'portrait']),
|
|
readOnly: PropTypes.bool,
|
|
/**
|
|
* If `true`, disable heavy animations.
|
|
* @default `@media(prefers-reduced-motion: reduce)` || `navigator.userAgent` matches Android <10 or iOS <13
|
|
*/
|
|
reduceAnimations: PropTypes.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.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.func,
|
|
/**
|
|
* Disable specific clock time.
|
|
* @param {number} clockValue The value to check.
|
|
* @param {TimeView} view The clock type of the timeValue.
|
|
* @returns {boolean} If `true` the time will be disabled.
|
|
* @deprecated Consider using `shouldDisableTime`.
|
|
*/
|
|
shouldDisableClock: PropTypes.func,
|
|
/**
|
|
* 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.func,
|
|
/**
|
|
* Disable specific month.
|
|
* @template TDate
|
|
* @param {TDate} month The month to test.
|
|
* @returns {boolean} If `true`, the month will be disabled.
|
|
*/
|
|
shouldDisableMonth: PropTypes.func,
|
|
/**
|
|
* Disable specific time.
|
|
* @template TDate
|
|
* @param {TDate} value The value to check.
|
|
* @param {TimeView} view The clock type of the timeValue.
|
|
* @returns {boolean} If `true` the time will be disabled.
|
|
*/
|
|
shouldDisableTime: PropTypes.func,
|
|
/**
|
|
* Disable specific year.
|
|
* @template TDate
|
|
* @param {TDate} year The year to test.
|
|
* @returns {boolean} If `true`, the year will be disabled.
|
|
*/
|
|
shouldDisableYear: PropTypes.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.bool,
|
|
/**
|
|
* The props used for each component slot.
|
|
* @default {}
|
|
*/
|
|
slotProps: PropTypes.object,
|
|
/**
|
|
* Overridable component slots.
|
|
* @default {}
|
|
*/
|
|
slots: PropTypes.object,
|
|
/**
|
|
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
*/
|
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.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.string,
|
|
/**
|
|
* The selected value.
|
|
* Used when the component is controlled.
|
|
*/
|
|
value: PropTypes.any,
|
|
/**
|
|
* The visible view.
|
|
* Used when the component view is controlled.
|
|
* Must be a valid option from `views` list.
|
|
*/
|
|
view: PropTypes.oneOf(['day', 'hours', 'minutes', 'month', 'seconds', '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.shape({
|
|
day: PropTypes.func,
|
|
hours: PropTypes.func,
|
|
minutes: PropTypes.func,
|
|
month: PropTypes.func,
|
|
seconds: PropTypes.func,
|
|
year: PropTypes.func
|
|
}),
|
|
/**
|
|
* Available views.
|
|
*/
|
|
views: PropTypes.arrayOf(PropTypes.oneOf(['day', 'hours', 'minutes', 'month', 'seconds', 'year']).isRequired),
|
|
/**
|
|
* Years rendered per row.
|
|
* @default 3
|
|
*/
|
|
yearsPerRow: PropTypes.oneOf([3, 4])
|
|
};
|
|
export { StaticDateTimePicker }; |