107 lines
4.0 KiB
JavaScript
107 lines
4.0 KiB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||
var _excluded = ["parsedValue", "isLandscape", "isMobileKeyboardViewOpen", "onChange", "toggleMobileKeyboardView", "toolbarFormat", "toolbarPlaceholder", "toolbarTitle", "views"];
|
||
import * as React from 'react';
|
||
import Typography from '@mui/material/Typography';
|
||
import { styled, useThemeProps } from '@mui/material/styles';
|
||
import { unstable_composeClasses as composeClasses } from '@mui/material';
|
||
import { PickersToolbar } from '../internals/components/PickersToolbar';
|
||
import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
|
||
import { isYearAndMonthViews, isYearOnlyView } from './shared';
|
||
import { getDatePickerToolbarUtilityClass } from './datePickerToolbarClasses';
|
||
import { jsx as _jsx } from "react/jsx-runtime";
|
||
|
||
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
||
var classes = ownerState.classes;
|
||
var slots = {
|
||
root: ['root'],
|
||
title: ['title']
|
||
};
|
||
return composeClasses(slots, getDatePickerToolbarUtilityClass, classes);
|
||
};
|
||
|
||
var DatePickerToolbarRoot = styled(PickersToolbar, {
|
||
name: 'MuiDatePickerToolbar',
|
||
slot: 'Root',
|
||
overridesResolver: function overridesResolver(_, styles) {
|
||
return styles.root;
|
||
}
|
||
})({});
|
||
var DatePickerToolbarTitle = styled(Typography, {
|
||
name: 'MuiDatePickerToolbar',
|
||
slot: 'Title',
|
||
overridesResolver: function overridesResolver(_, styles) {
|
||
return styles.title;
|
||
}
|
||
})(function (_ref) {
|
||
var ownerState = _ref.ownerState;
|
||
return _extends({}, ownerState.isLandscape && {
|
||
margin: 'auto 16px auto auto'
|
||
});
|
||
});
|
||
|
||
/**
|
||
* @ignore - internal component.
|
||
*/
|
||
export var DatePickerToolbar = /*#__PURE__*/React.forwardRef(function DatePickerToolbar(inProps, ref) {
|
||
var props = useThemeProps({
|
||
props: inProps,
|
||
name: 'MuiDatePickerToolbar'
|
||
});
|
||
|
||
var parsedValue = props.parsedValue,
|
||
isLandscape = props.isLandscape,
|
||
isMobileKeyboardViewOpen = props.isMobileKeyboardViewOpen,
|
||
onChange = props.onChange,
|
||
toggleMobileKeyboardView = props.toggleMobileKeyboardView,
|
||
toolbarFormat = props.toolbarFormat,
|
||
_props$toolbarPlaceho = props.toolbarPlaceholder,
|
||
toolbarPlaceholder = _props$toolbarPlaceho === void 0 ? '––' : _props$toolbarPlaceho,
|
||
toolbarTitleProp = props.toolbarTitle,
|
||
views = props.views,
|
||
other = _objectWithoutProperties(props, _excluded);
|
||
|
||
var utils = useUtils();
|
||
var localeText = useLocaleText();
|
||
var classes = useUtilityClasses(props);
|
||
var toolbarTitle = toolbarTitleProp != null ? toolbarTitleProp : localeText.datePickerDefaultToolbarTitle;
|
||
var dateText = React.useMemo(function () {
|
||
if (!parsedValue) {
|
||
return toolbarPlaceholder;
|
||
}
|
||
|
||
if (toolbarFormat) {
|
||
return utils.formatByString(parsedValue, toolbarFormat);
|
||
}
|
||
|
||
if (isYearOnlyView(views)) {
|
||
return utils.format(parsedValue, 'year');
|
||
}
|
||
|
||
if (isYearAndMonthViews(views)) {
|
||
return utils.format(parsedValue, 'month');
|
||
} // Little localization hack (Google is doing the same for android native pickers):
|
||
// For english localization it is convenient to include weekday into the date "Mon, Jun 1".
|
||
// For other locales using strings like "June 1", without weekday.
|
||
|
||
|
||
return /en/.test(utils.getCurrentLocaleCode()) ? utils.format(parsedValue, 'normalDateWithWeekday') : utils.format(parsedValue, 'normalDate');
|
||
}, [parsedValue, toolbarFormat, toolbarPlaceholder, utils, views]);
|
||
var ownerState = props;
|
||
return /*#__PURE__*/_jsx(DatePickerToolbarRoot, _extends({
|
||
ref: ref,
|
||
toolbarTitle: toolbarTitle,
|
||
isMobileKeyboardViewOpen: isMobileKeyboardViewOpen,
|
||
toggleMobileKeyboardView: toggleMobileKeyboardView,
|
||
isLandscape: isLandscape,
|
||
className: classes.root
|
||
}, other, {
|
||
children: /*#__PURE__*/_jsx(DatePickerToolbarTitle, {
|
||
variant: "h4",
|
||
align: isLandscape ? 'left' : 'center',
|
||
ownerState: ownerState,
|
||
className: classes.title,
|
||
children: dateText
|
||
})
|
||
}));
|
||
}); |