@mui/x-date-pickers
Version:
The community edition of the Date and Time Picker components (MUI X).
264 lines (262 loc) • 10.3 kB
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.TimePickerToolbar = TimePickerToolbar;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _clsx = _interopRequireDefault(require("clsx"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _RtlProvider = require("@mui/system/RtlProvider");
var _styles = require("@mui/material/styles");
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _PickersToolbarText = require("../internals/components/PickersToolbarText");
var _PickersToolbarButton = require("../internals/components/PickersToolbarButton");
var _PickersToolbar = require("../internals/components/PickersToolbar");
var _utils = require("../internals/utils/utils");
var _usePickersTranslations = require("../hooks/usePickersTranslations");
var _useUtils = require("../internals/hooks/useUtils");
var _dateHelpersHooks = require("../internals/hooks/date-helpers-hooks");
var _timePickerToolbarClasses = require("./timePickerToolbarClasses");
var _dateUtils = require("../internals/utils/date-utils");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["ampm", "ampmInClock", "value", "isLandscape", "onChange", "view", "onViewChange", "views", "disabled", "readOnly", "className"];
const useUtilityClasses = ownerState => {
const {
isLandscape,
classes,
isRtl
} = ownerState;
const slots = {
root: ['root'],
separator: ['separator'],
hourMinuteLabel: ['hourMinuteLabel', isLandscape && 'hourMinuteLabelLandscape', isRtl && 'hourMinuteLabelReverse'],
ampmSelection: ['ampmSelection', isLandscape && 'ampmLandscape'],
ampmLabel: ['ampmLabel']
};
return (0, _composeClasses.default)(slots, _timePickerToolbarClasses.getTimePickerToolbarUtilityClass, classes);
};
const TimePickerToolbarRoot = (0, _styles.styled)(_PickersToolbar.PickersToolbar, {
name: 'MuiTimePickerToolbar',
slot: 'Root',
overridesResolver: (props, styles) => styles.root
})({});
const TimePickerToolbarSeparator = (0, _styles.styled)(_PickersToolbarText.PickersToolbarText, {
name: 'MuiTimePickerToolbar',
slot: 'Separator',
overridesResolver: (props, styles) => styles.separator
})({
outline: 0,
margin: '0 4px 0 2px',
cursor: 'default'
});
const TimePickerToolbarHourMinuteLabel = (0, _styles.styled)('div', {
name: 'MuiTimePickerToolbar',
slot: 'HourMinuteLabel',
overridesResolver: (props, styles) => [{
[`&.${_timePickerToolbarClasses.timePickerToolbarClasses.hourMinuteLabelLandscape}`]: styles.hourMinuteLabelLandscape,
[`&.${_timePickerToolbarClasses.timePickerToolbarClasses.hourMinuteLabelReverse}`]: styles.hourMinuteLabelReverse
}, styles.hourMinuteLabel]
})({
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'flex-end',
variants: [{
props: {
isRtl: true
},
style: {
flexDirection: 'row-reverse'
}
}, {
props: {
isLandscape: true
},
style: {
marginTop: 'auto'
}
}]
});
const TimePickerToolbarAmPmSelection = (0, _styles.styled)('div', {
name: 'MuiTimePickerToolbar',
slot: 'AmPmSelection',
overridesResolver: (props, styles) => [{
[`.${_timePickerToolbarClasses.timePickerToolbarClasses.ampmLabel}`]: styles.ampmLabel
}, {
[`&.${_timePickerToolbarClasses.timePickerToolbarClasses.ampmLandscape}`]: styles.ampmLandscape
}, styles.ampmSelection]
})({
display: 'flex',
flexDirection: 'column',
marginRight: 'auto',
marginLeft: 12,
[`& .${_timePickerToolbarClasses.timePickerToolbarClasses.ampmLabel}`]: {
fontSize: 17
},
variants: [{
props: {
isLandscape: true
},
style: {
margin: '4px 0 auto',
flexDirection: 'row',
justifyContent: 'space-around',
flexBasis: '100%'
}
}]
});
/**
* Demos:
*
* - [TimePicker](https://mui.com/x/react-date-pickers/time-picker/)
* - [Custom components](https://mui.com/x/react-date-pickers/custom-components/)
*
* API:
*
* - [TimePickerToolbar API](https://mui.com/x/api/date-pickers/time-picker-toolbar/)
*/
function TimePickerToolbar(inProps) {
const props = (0, _styles.useThemeProps)({
props: inProps,
name: 'MuiTimePickerToolbar'
});
const {
ampm,
ampmInClock,
value,
isLandscape,
onChange,
view,
onViewChange,
views,
disabled,
readOnly,
className
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const utils = (0, _useUtils.useUtils)();
const translations = (0, _usePickersTranslations.usePickersTranslations)();
const isRtl = (0, _RtlProvider.useRtl)();
const showAmPmControl = Boolean(ampm && !ampmInClock && views.includes('hours'));
const {
meridiemMode,
handleMeridiemChange
} = (0, _dateHelpersHooks.useMeridiemMode)(value, ampm, onChange);
const formatHours = time => ampm ? utils.format(time, 'hours12h') : utils.format(time, 'hours24h');
const ownerState = (0, _extends2.default)({}, props, {
isRtl
});
const classes = useUtilityClasses(ownerState);
const separator = /*#__PURE__*/(0, _jsxRuntime.jsx)(TimePickerToolbarSeparator, {
tabIndex: -1,
value: ":",
variant: "h3",
selected: false,
className: classes.separator
});
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(TimePickerToolbarRoot, (0, _extends2.default)({
landscapeDirection: "row",
toolbarTitle: translations.timePickerToolbarTitle,
isLandscape: isLandscape,
ownerState: ownerState,
className: (0, _clsx.default)(classes.root, className)
}, other, {
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(TimePickerToolbarHourMinuteLabel, {
className: classes.hourMinuteLabel,
ownerState: ownerState,
children: [(0, _utils.arrayIncludes)(views, 'hours') && /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickersToolbarButton.PickersToolbarButton, {
tabIndex: -1,
variant: "h3",
onClick: () => onViewChange('hours'),
selected: view === 'hours',
value: value ? formatHours(value) : '--'
}), (0, _utils.arrayIncludes)(views, ['hours', 'minutes']) && separator, (0, _utils.arrayIncludes)(views, 'minutes') && /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickersToolbarButton.PickersToolbarButton, {
tabIndex: -1,
variant: "h3",
onClick: () => onViewChange('minutes'),
selected: view === 'minutes',
value: value ? utils.format(value, 'minutes') : '--'
}), (0, _utils.arrayIncludes)(views, ['minutes', 'seconds']) && separator, (0, _utils.arrayIncludes)(views, 'seconds') && /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickersToolbarButton.PickersToolbarButton, {
variant: "h3",
onClick: () => onViewChange('seconds'),
selected: view === 'seconds',
value: value ? utils.format(value, 'seconds') : '--'
})]
}), showAmPmControl && /*#__PURE__*/(0, _jsxRuntime.jsxs)(TimePickerToolbarAmPmSelection, {
className: classes.ampmSelection,
ownerState: ownerState,
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_PickersToolbarButton.PickersToolbarButton, {
disableRipple: true,
variant: "subtitle2",
selected: meridiemMode === 'am',
typographyClassName: classes.ampmLabel,
value: (0, _dateUtils.formatMeridiem)(utils, 'am'),
onClick: readOnly ? undefined : () => handleMeridiemChange('am'),
disabled: disabled
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickersToolbarButton.PickersToolbarButton, {
disableRipple: true,
variant: "subtitle2",
selected: meridiemMode === 'pm',
typographyClassName: classes.ampmLabel,
value: (0, _dateUtils.formatMeridiem)(utils, 'pm'),
onClick: readOnly ? undefined : () => handleMeridiemChange('pm'),
disabled: disabled
})]
})]
}));
}
process.env.NODE_ENV !== "production" ? TimePickerToolbar.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
ampm: _propTypes.default.bool,
ampmInClock: _propTypes.default.bool,
/**
* Override or extend the styles applied to the component.
*/
classes: _propTypes.default.object,
className: _propTypes.default.string,
disabled: _propTypes.default.bool,
/**
* If `true`, show the toolbar even in desktop mode.
* @default `true` for Desktop, `false` for Mobile.
*/
hidden: _propTypes.default.bool,
isLandscape: _propTypes.default.bool.isRequired,
onChange: _propTypes.default.func.isRequired,
/**
* Callback called when a toolbar is clicked
* @template TView
* @param {TView} view The view to open
*/
onViewChange: _propTypes.default.func.isRequired,
readOnly: _propTypes.default.bool,
/**
* 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]),
titleId: _propTypes.default.string,
/**
* Toolbar date format.
*/
toolbarFormat: _propTypes.default.string,
/**
* Toolbar value placeholder—it is displayed when the value is empty.
* @default "––"
*/
toolbarPlaceholder: _propTypes.default.node,
value: _propTypes.default.object,
/**
* Currently visible picker view.
*/
view: _propTypes.default.oneOf(['hours', 'meridiem', 'minutes', 'seconds']).isRequired,
/**
* Available views.
*/
views: _propTypes.default.arrayOf(_propTypes.default.oneOf(['hours', 'meridiem', 'minutes', 'seconds']).isRequired).isRequired
} : void 0;