333 lines
No EOL
13 KiB
JavaScript
333 lines
No EOL
13 KiB
JavaScript
"use strict";
|
|
'use client';
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.TimePicker = 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 _refType = _interopRequireDefault(require("@mui/utils/refType"));
|
|
var _DesktopTimePicker = require("../DesktopTimePicker");
|
|
var _MobileTimePicker = require("../MobileTimePicker");
|
|
var _utils = require("../internals/utils/utils");
|
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
const _excluded = ["desktopModeMediaQuery"];
|
|
/**
|
|
* Demos:
|
|
*
|
|
* - [TimePicker](https://mui.com/x/react-date-pickers/time-picker/)
|
|
* - [Validation](https://mui.com/x/react-date-pickers/validation/)
|
|
*
|
|
* API:
|
|
*
|
|
* - [TimePicker API](https://mui.com/x/api/date-pickers/time-picker/)
|
|
*/
|
|
const TimePicker = exports.TimePicker = /*#__PURE__*/React.forwardRef(function TimePicker(inProps, ref) {
|
|
const props = (0, _styles.useThemeProps)({
|
|
props: inProps,
|
|
name: 'MuiTimePicker'
|
|
});
|
|
const {
|
|
desktopModeMediaQuery = _utils.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)(_DesktopTimePicker.DesktopTimePicker, (0, _extends2.default)({
|
|
ref: ref
|
|
}, other));
|
|
}
|
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_MobileTimePicker.MobileTimePicker, (0, _extends2.default)({
|
|
ref: ref
|
|
}, other));
|
|
});
|
|
if (process.env.NODE_ENV !== "production") TimePicker.displayName = "TimePicker";
|
|
process.env.NODE_ENV !== "production" ? TimePicker.propTypes = {
|
|
// ----------------------------- Warning --------------------------------
|
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
// ----------------------------------------------------------------------
|
|
/**
|
|
* 12h/24h view for hour selection clock.
|
|
* @default adapter.is12HourCycleInCurrentLocale()
|
|
*/
|
|
ampm: _propTypes.default.bool,
|
|
/**
|
|
* Display ampm controls under the clock (instead of in the toolbar).
|
|
* @default true on desktop, false on mobile
|
|
*/
|
|
ampmInClock: _propTypes.default.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.default.bool,
|
|
className: _propTypes.default.string,
|
|
/**
|
|
* If `true`, the Picker will close after submitting the full date.
|
|
* @default false
|
|
*/
|
|
closeOnSelect: _propTypes.default.bool,
|
|
/**
|
|
* The default value.
|
|
* Used when the component is not controlled.
|
|
*/
|
|
defaultValue: _propTypes.default.object,
|
|
/**
|
|
* 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 component is disabled.
|
|
* When disabled, the value cannot be changed and no interaction is possible.
|
|
* @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,
|
|
/**
|
|
* Do not ignore date part when validating min/max time.
|
|
* @default false
|
|
*/
|
|
disableIgnoringDatePartForTimeValidation: _propTypes.default.bool,
|
|
/**
|
|
* If `true`, the button to open the Picker will not be rendered (it will only render the field).
|
|
* @deprecated Use the [field component](https://mui.com/x/react-date-pickers/fields/) instead.
|
|
* @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,
|
|
/**
|
|
* @default true
|
|
*/
|
|
enableAccessibleFieldDOMStructure: _propTypes.default.any,
|
|
/**
|
|
* 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: _refType.default,
|
|
/**
|
|
* The label content.
|
|
*/
|
|
label: _propTypes.default.node,
|
|
/**
|
|
* Locale for components texts.
|
|
* Allows overriding texts coming from `LocalizationProvider` and `theme`.
|
|
*/
|
|
localeText: _propTypes.default.object,
|
|
/**
|
|
* Maximal selectable time.
|
|
* The date part of the object will be ignored unless `props.disableIgnoringDatePartForTimeValidation === true`.
|
|
*/
|
|
maxTime: _propTypes.default.object,
|
|
/**
|
|
* Minimal selectable time.
|
|
* The date part of the object will be ignored unless `props.disableIgnoringDatePartForTimeValidation === true`.
|
|
*/
|
|
minTime: _propTypes.default.object,
|
|
/**
|
|
* Step over minutes.
|
|
* @default 1
|
|
*/
|
|
minutesStep: _propTypes.default.number,
|
|
/**
|
|
* 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. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
* @template TError The validation error type. It will be either `string` or a `null`. It can be in `[start, end]` format in case of range value.
|
|
* @param {TValue} value The value that was just accepted.
|
|
* @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
|
|
*/
|
|
onAccept: _propTypes.default.func,
|
|
/**
|
|
* Callback fired when the value changes.
|
|
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
* @template TError The validation error type. It will be either `string` or a `null`. It 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 with the current value changes.
|
|
* When a validation error is detected, the `error` parameter contains a non-null value.
|
|
* This can be used to render an appropriate form error.
|
|
* @template TError The validation error type. It will be either `string` or a `null`. It can be in `[start, end]` format in case of range value.
|
|
* @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
|
|
* @param {TError} error The reason why the current value is not valid.
|
|
* @param {TValue} value The value associated with the error.
|
|
*/
|
|
onError: _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 Type of the view. It will vary based on the Picker type and the `views` it uses.
|
|
* @param {TView} view The new view.
|
|
*/
|
|
onViewChange: _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(['hours', 'meridiem', 'minutes', 'seconds']),
|
|
/**
|
|
* Force rendering in particular orientation.
|
|
*/
|
|
orientation: _propTypes.default.oneOf(['landscape', 'portrait']),
|
|
/**
|
|
* If `true`, the component is read-only.
|
|
* When read-only, the value cannot be changed but the user can interact with the interface.
|
|
* @default false
|
|
*/
|
|
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.object,
|
|
/**
|
|
* The currently selected sections.
|
|
* This prop accepts four formats:
|
|
* 1. If a number is provided, the section at this index will be selected.
|
|
* 2. If a string of type `FieldSectionType` is provided, the first section with that name will be selected.
|
|
* 3. If `"all"` is provided, all the sections 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', 'empty', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'weekDay', 'year']), _propTypes.default.number]),
|
|
/**
|
|
* Disable specific time.
|
|
* @param {PickerValidDate} 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.default.func,
|
|
/**
|
|
* If `true`, disabled digital clock items will not be rendered.
|
|
* @default false
|
|
*/
|
|
skipDisabled: _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]),
|
|
/**
|
|
* Amount of time options below or at which the single column time renderer is used.
|
|
* @default 24
|
|
*/
|
|
thresholdToRenderTimeInASingleColumn: _propTypes.default.number,
|
|
/**
|
|
* The time steps between two time unit options.
|
|
* For example, if `timeSteps.minutes = 8`, then the available minute options will be `[0, 8, 16, 24, 32, 40, 48, 56]`.
|
|
* When single column time renderer is used, only `timeSteps.minutes` will be used.
|
|
* @default{ hours: 1, minutes: 5, seconds: 5 }
|
|
*/
|
|
timeSteps: _propTypes.default.shape({
|
|
hours: _propTypes.default.number,
|
|
minutes: _propTypes.default.number,
|
|
seconds: _propTypes.default.number
|
|
}),
|
|
/**
|
|
* 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 documentation} 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.object,
|
|
/**
|
|
* The visible view.
|
|
* Used when the component view is controlled.
|
|
* Must be a valid option from `views` list.
|
|
*/
|
|
view: _propTypes.default.oneOf(['hours', 'meridiem', 'minutes', 'seconds']),
|
|
/**
|
|
* Define custom view renderers for each section.
|
|
* If `null`, the section will only have field editing.
|
|
* If `undefined`, internally defined view will be used.
|
|
*/
|
|
viewRenderers: _propTypes.default.shape({
|
|
hours: _propTypes.default.func,
|
|
meridiem: _propTypes.default.func,
|
|
minutes: _propTypes.default.func,
|
|
seconds: _propTypes.default.func
|
|
}),
|
|
/**
|
|
* Available views.
|
|
*/
|
|
views: _propTypes.default.arrayOf(_propTypes.default.oneOf(['hours', 'minutes', 'seconds']).isRequired)
|
|
} : void 0; |