201 lines
7.0 KiB
JavaScript
201 lines
7.0 KiB
JavaScript
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
const _excluded = ["ampm", "ampmInClock", "parsedValue", "isLandscape", "isMobileKeyboardViewOpen", "onChange", "openView", "setOpenView", "toggleMobileKeyboardView", "toolbarTitle", "views", "disabled", "readOnly"];
|
|
import * as React from 'react';
|
|
import { useTheme, styled, useThemeProps } from '@mui/material/styles';
|
|
import { unstable_composeClasses as composeClasses } from '@mui/material';
|
|
import { PickersToolbarText } from '../internals/components/PickersToolbarText';
|
|
import { PickersToolbarButton } from '../internals/components/PickersToolbarButton';
|
|
import { PickersToolbar } from '../internals/components/PickersToolbar';
|
|
import { pickersToolbarClasses } from '../internals/components/pickersToolbarClasses';
|
|
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 { 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
|
|
})({
|
|
[`& .${pickersToolbarClasses.penIconButtonLandscape}`]: {
|
|
marginTop: 'auto'
|
|
}
|
|
});
|
|
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'
|
|
}));
|
|
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
|
|
}
|
|
}));
|
|
/**
|
|
* @ignore - internal component.
|
|
*/
|
|
|
|
export function TimePickerToolbar(inProps) {
|
|
const props = useThemeProps({
|
|
props: inProps,
|
|
name: 'MuiTimePickerToolbar'
|
|
});
|
|
|
|
const {
|
|
ampm,
|
|
ampmInClock,
|
|
parsedValue,
|
|
isLandscape,
|
|
isMobileKeyboardViewOpen,
|
|
onChange,
|
|
openView,
|
|
setOpenView,
|
|
toggleMobileKeyboardView,
|
|
toolbarTitle: toolbarTitleProp,
|
|
views,
|
|
disabled,
|
|
readOnly
|
|
} = props,
|
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
|
|
const utils = useUtils();
|
|
const localeText = useLocaleText();
|
|
const toolbarTitle = toolbarTitleProp ?? localeText.timePickerDefaultToolbarTitle;
|
|
const theme = useTheme();
|
|
const showAmPmControl = Boolean(ampm && !ampmInClock);
|
|
const {
|
|
meridiemMode,
|
|
handleMeridiemChange
|
|
} = useMeridiemMode(parsedValue, 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({
|
|
viewType: "clock",
|
|
landscapeDirection: "row",
|
|
toolbarTitle: toolbarTitle,
|
|
isLandscape: isLandscape,
|
|
isMobileKeyboardViewOpen: isMobileKeyboardViewOpen,
|
|
toggleMobileKeyboardView: toggleMobileKeyboardView,
|
|
ownerState: ownerState,
|
|
className: classes.root
|
|
}, other, {
|
|
children: [/*#__PURE__*/_jsxs(TimePickerToolbarHourMinuteLabel, {
|
|
className: classes.hourMinuteLabel,
|
|
ownerState: ownerState,
|
|
children: [arrayIncludes(views, 'hours') && /*#__PURE__*/_jsx(PickersToolbarButton, {
|
|
tabIndex: -1,
|
|
variant: "h3",
|
|
onClick: () => setOpenView('hours'),
|
|
selected: openView === 'hours',
|
|
value: parsedValue ? formatHours(parsedValue) : '--'
|
|
}), arrayIncludes(views, ['hours', 'minutes']) && separator, arrayIncludes(views, 'minutes') && /*#__PURE__*/_jsx(PickersToolbarButton, {
|
|
tabIndex: -1,
|
|
variant: "h3",
|
|
onClick: () => setOpenView('minutes'),
|
|
selected: openView === 'minutes',
|
|
value: parsedValue ? utils.format(parsedValue, 'minutes') : '--'
|
|
}), arrayIncludes(views, ['minutes', 'seconds']) && separator, arrayIncludes(views, 'seconds') && /*#__PURE__*/_jsx(PickersToolbarButton, {
|
|
variant: "h3",
|
|
onClick: () => setOpenView('seconds'),
|
|
selected: openView === 'seconds',
|
|
value: parsedValue ? utils.format(parsedValue, '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: utils.getMeridiemText('am'),
|
|
onClick: readOnly ? undefined : () => handleMeridiemChange('am'),
|
|
disabled: disabled
|
|
}), /*#__PURE__*/_jsx(PickersToolbarButton, {
|
|
disableRipple: true,
|
|
variant: "subtitle2",
|
|
selected: meridiemMode === 'pm',
|
|
typographyClassName: classes.ampmLabel,
|
|
value: utils.getMeridiemText('pm'),
|
|
onClick: readOnly ? undefined : () => handleMeridiemChange('pm'),
|
|
disabled: disabled
|
|
})]
|
|
})]
|
|
}));
|
|
} |