@mui/x-date-pickers
Version:
The community edition of the Date and Time Picker components (MUI X).
246 lines (244 loc) • 10.6 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.StaticTimePicker = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _shared = require("../TimePicker/shared");
var _timeViewRenderers = require("../timeViewRenderers");
var _valueManagers = require("../internals/utils/valueManagers");
var _useStaticPicker = require("../internals/hooks/useStaticPicker");
var _validateTime = require("../internals/utils/validation/validateTime");
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 && {}.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:
*
* - [TimePicker](https://mui.com/x/react-date-pickers/time-picker/)
* - [Validation](https://mui.com/x/react-date-pickers/validation/)
*
* API:
*
* - [StaticTimePicker API](https://mui.com/x/api/date-pickers/static-time-picker/)
*/
const StaticTimePicker = exports.StaticTimePicker = /*#__PURE__*/React.forwardRef(function StaticTimePicker(inProps, ref) {
const defaultizedProps = (0, _shared.useTimePickerDefaultizedProps)(inProps, 'MuiStaticTimePicker');
const displayStaticWrapperAs = defaultizedProps.displayStaticWrapperAs ?? 'mobile';
const ampmInClock = defaultizedProps.ampmInClock ?? displayStaticWrapperAs === 'desktop';
const viewRenderers = (0, _extends2.default)({
hours: _timeViewRenderers.renderTimeViewClock,
minutes: _timeViewRenderers.renderTimeViewClock,
seconds: _timeViewRenderers.renderTimeViewClock
}, defaultizedProps.viewRenderers);
// Props with the default values specific to the static variant
const props = (0, _extends2.default)({}, defaultizedProps, {
viewRenderers,
displayStaticWrapperAs,
ampmInClock,
slotProps: (0, _extends2.default)({}, defaultizedProps.slotProps, {
toolbar: (0, _extends2.default)({
hidden: displayStaticWrapperAs === 'desktop',
ampmInClock
}, defaultizedProps.slotProps?.toolbar)
})
});
const {
renderPicker
} = (0, _useStaticPicker.useStaticPicker)({
props,
valueManager: _valueManagers.singleItemValueManager,
valueType: 'time',
validator: _validateTime.validateTime,
ref
});
return renderPicker();
});
StaticTimePicker.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.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,
/**
* The default value.
* Used when the component is not controlled.
*/
defaultValue: _propTypes.default.object,
/**
* 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,
/**
* Do not ignore date part when validating min/max time.
* @default false
*/
disableIgnoringDatePartForTimeValidation: _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,
/**
* Force static wrapper inner components to be rendered in mobile or desktop mode.
* @default "mobile"
*/
displayStaticWrapperAs: _propTypes.default.oneOf(['desktop', 'mobile']),
/**
* 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,
/**
* 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 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.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 view change.
* @template TView
* @param {TView} view The new view.
*/
onViewChange: _propTypes.default.func,
/**
* 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', 'minutes', 'seconds']),
/**
* 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.object,
/**
* 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.default.func,
/**
* 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 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', '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,
minutes: _propTypes.default.func,
seconds: _propTypes.default.func
}),
/**
* Available views.
*/
views: _propTypes.default.arrayOf(_propTypes.default.oneOf(['hours', 'minutes', 'seconds']).isRequired)
};