stupa-pdf-api/frontend/node_modules/@mui/x-date-pickers/modern/TimePicker/TimePickerToolbar.js

262 lines
9.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
const _excluded = ["ampm", "ampmInClock", "value", "isLandscape", "onChange", "view", "onViewChange", "views", "disabled", "readOnly", "className"];
import * as React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import { useTheme, styled, useThemeProps } from '@mui/material/styles';
import { unstable_composeClasses as composeClasses } from '@mui/utils';
import { PickersToolbarText } from '../internals/components/PickersToolbarText';
import { PickersToolbarButton } from '../internals/components/PickersToolbarButton';
import { PickersToolbar } from '../internals/components/PickersToolbar';
import { arrayIncludes } from '../internals/utils/utils';
import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
import { useMeridiemMode } from '../internals/hooks/date-helpers-hooks';
import { getTimePickerToolbarUtilityClass, timePickerToolbarClasses } from './timePickerToolbarClasses';
import { formatMeridiem } from '../internals/utils/date-utils';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
theme,
isLandscape,
classes
} = ownerState;
const slots = {
root: ['root'],
separator: ['separator'],
hourMinuteLabel: ['hourMinuteLabel', isLandscape && 'hourMinuteLabelLandscape', theme.direction === 'rtl' && 'hourMinuteLabelReverse'],
ampmSelection: ['ampmSelection', isLandscape && 'ampmLandscape'],
ampmLabel: ['ampmLabel']
};
return composeClasses(slots, getTimePickerToolbarUtilityClass, classes);
};
const TimePickerToolbarRoot = styled(PickersToolbar, {
name: 'MuiTimePickerToolbar',
slot: 'Root',
overridesResolver: (props, styles) => styles.root
})({});
const TimePickerToolbarSeparator = styled(PickersToolbarText, {
name: 'MuiTimePickerToolbar',
slot: 'Separator',
overridesResolver: (props, styles) => styles.separator
})({
outline: 0,
margin: '0 4px 0 2px',
cursor: 'default'
});
const TimePickerToolbarHourMinuteLabel = styled('div', {
name: 'MuiTimePickerToolbar',
slot: 'HourMinuteLabel',
overridesResolver: (props, styles) => [{
[`&.${timePickerToolbarClasses.hourMinuteLabelLandscape}`]: styles.hourMinuteLabelLandscape,
[`&.${timePickerToolbarClasses.hourMinuteLabelReverse}`]: styles.hourMinuteLabelReverse
}, styles.hourMinuteLabel]
})(({
theme,
ownerState
}) => _extends({
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'flex-end'
}, ownerState.isLandscape && {
marginTop: 'auto'
}, theme.direction === 'rtl' && {
flexDirection: 'row-reverse'
}));
TimePickerToolbarHourMinuteLabel.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
as: PropTypes.elementType,
ownerState: PropTypes.object.isRequired,
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
};
const TimePickerToolbarAmPmSelection = styled('div', {
name: 'MuiTimePickerToolbar',
slot: 'AmPmSelection',
overridesResolver: (props, styles) => [{
[`.${timePickerToolbarClasses.ampmLabel}`]: styles.ampmLabel
}, {
[`&.${timePickerToolbarClasses.ampmLandscape}`]: styles.ampmLandscape
}, styles.ampmSelection]
})(({
ownerState
}) => _extends({
display: 'flex',
flexDirection: 'column',
marginRight: 'auto',
marginLeft: 12
}, ownerState.isLandscape && {
margin: '4px 0 auto',
flexDirection: 'row',
justifyContent: 'space-around',
flexBasis: '100%'
}, {
[`& .${timePickerToolbarClasses.ampmLabel}`]: {
fontSize: 17
}
}));
TimePickerToolbarAmPmSelection.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
as: PropTypes.elementType,
ownerState: PropTypes.object.isRequired,
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
};
/**
* 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 = useThemeProps({
props: inProps,
name: 'MuiTimePickerToolbar'
});
const {
ampm,
ampmInClock,
value,
isLandscape,
onChange,
view,
onViewChange,
views,
disabled,
readOnly,
className
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const utils = useUtils();
const localeText = useLocaleText();
const theme = useTheme();
const showAmPmControl = Boolean(ampm && !ampmInClock && views.includes('hours'));
const {
meridiemMode,
handleMeridiemChange
} = useMeridiemMode(value, ampm, onChange);
const formatHours = time => ampm ? utils.format(time, 'hours12h') : utils.format(time, 'hours24h');
const ownerState = props;
const classes = useUtilityClasses(_extends({}, ownerState, {
theme
}));
const separator = /*#__PURE__*/_jsx(TimePickerToolbarSeparator, {
tabIndex: -1,
value: ":",
variant: "h3",
selected: false,
className: classes.separator
});
return /*#__PURE__*/_jsxs(TimePickerToolbarRoot, _extends({
landscapeDirection: "row",
toolbarTitle: localeText.timePickerToolbarTitle,
isLandscape: isLandscape,
ownerState: ownerState,
className: clsx(classes.root, className)
}, other, {
children: [/*#__PURE__*/_jsxs(TimePickerToolbarHourMinuteLabel, {
className: classes.hourMinuteLabel,
ownerState: ownerState,
children: [arrayIncludes(views, 'hours') && /*#__PURE__*/_jsx(PickersToolbarButton, {
tabIndex: -1,
variant: "h3",
onClick: () => onViewChange('hours'),
selected: view === 'hours',
value: value ? formatHours(value) : '--'
}), arrayIncludes(views, ['hours', 'minutes']) && separator, arrayIncludes(views, 'minutes') && /*#__PURE__*/_jsx(PickersToolbarButton, {
tabIndex: -1,
variant: "h3",
onClick: () => onViewChange('minutes'),
selected: view === 'minutes',
value: value ? utils.format(value, 'minutes') : '--'
}), arrayIncludes(views, ['minutes', 'seconds']) && separator, arrayIncludes(views, 'seconds') && /*#__PURE__*/_jsx(PickersToolbarButton, {
variant: "h3",
onClick: () => onViewChange('seconds'),
selected: view === 'seconds',
value: value ? utils.format(value, 'seconds') : '--'
})]
}), showAmPmControl && /*#__PURE__*/_jsxs(TimePickerToolbarAmPmSelection, {
className: classes.ampmSelection,
ownerState: ownerState,
children: [/*#__PURE__*/_jsx(PickersToolbarButton, {
disableRipple: true,
variant: "subtitle2",
selected: meridiemMode === 'am',
typographyClassName: classes.ampmLabel,
value: formatMeridiem(utils, 'am'),
onClick: readOnly ? undefined : () => handleMeridiemChange('am'),
disabled: disabled
}), /*#__PURE__*/_jsx(PickersToolbarButton, {
disableRipple: true,
variant: "subtitle2",
selected: meridiemMode === 'pm',
typographyClassName: classes.ampmLabel,
value: 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 "yarn proptypes" |
// ----------------------------------------------------------------------
ampm: PropTypes.bool,
ampmInClock: PropTypes.bool,
/**
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
/**
* className applied to the root component.
*/
className: PropTypes.string,
disabled: PropTypes.bool,
/**
* If `true`, show the toolbar even in desktop mode.
* @default `true` for Desktop, `false` for Mobile.
*/
hidden: PropTypes.bool,
isLandscape: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired,
/**
* Callback called when a toolbar is clicked
* @template TView
* @param {TView} view The view to open
*/
onViewChange: PropTypes.func.isRequired,
readOnly: PropTypes.bool,
/**
* 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]),
titleId: PropTypes.string,
/**
* Toolbar date format.
*/
toolbarFormat: PropTypes.string,
/**
* Toolbar value placeholder—it is displayed when the value is empty.
* @default ""
*/
toolbarPlaceholder: PropTypes.node,
value: PropTypes.any,
/**
* Currently visible picker view.
*/
view: PropTypes.oneOf(['hours', 'meridiem', 'minutes', 'seconds']).isRequired,
views: PropTypes.arrayOf(PropTypes.oneOf(['hours', 'meridiem', 'minutes', 'seconds']).isRequired).isRequired
} : void 0;
export { TimePickerToolbar };