@material-ui/lab
Version:
Laboratory for new Material-UI modules.
86 lines (79 loc) • 3.47 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import * as React from 'react';
import Typography from '@material-ui/core/Typography';
import { styled } from '@material-ui/core/styles';
import { generateUtilityClasses } from '@material-ui/unstyled';
import PickersToolbar from '../internal/pickers/PickersToolbar';
import { useUtils } from '../internal/pickers/hooks/useUtils';
import { isYearAndMonthViews, isYearOnlyView } from './shared';
import { jsx as _jsx } from "react/jsx-runtime";
var classes = generateUtilityClasses('PrivateDatePickerToolbar', ['penIcon']);
var DatePickerToolbarRoot = styled(PickersToolbar, {
skipSx: true
})(_defineProperty({}, "& .".concat(classes.penIcon), {
position: 'relative',
top: 4
}));
var DatePickerToolbarTitle = styled(Typography, {
skipSx: true
})(function (_ref) {
var styleProps = _ref.styleProps;
return _extends({}, styleProps.isLandscape && {
margin: 'auto 16px auto auto'
});
});
/**
* @ignore - internal component.
*/
var DatePickerToolbar = /*#__PURE__*/React.forwardRef(function DatePickerToolbar(props, ref) {
var date = props.date,
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,
_props$toolbarTitle = props.toolbarTitle,
toolbarTitle = _props$toolbarTitle === void 0 ? 'Select date' : _props$toolbarTitle,
views = props.views,
other = _objectWithoutProperties(props, ["date", "isLandscape", "isMobileKeyboardViewOpen", "onChange", "toggleMobileKeyboardView", "toolbarFormat", "toolbarPlaceholder", "toolbarTitle", "views"]);
var utils = useUtils();
var dateText = React.useMemo(function () {
if (!date) {
return toolbarPlaceholder;
}
if (toolbarFormat) {
return utils.formatByString(date, toolbarFormat);
}
if (isYearOnlyView(views)) {
return utils.format(date, 'year');
}
if (isYearAndMonthViews(views)) {
return utils.format(date, '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(date, 'normalDateWithWeekday') : utils.format(date, 'normalDate');
}, [date, toolbarFormat, toolbarPlaceholder, utils, views]);
var styleProps = props;
return /*#__PURE__*/_jsx(DatePickerToolbarRoot, _extends({
ref: ref,
toolbarTitle: toolbarTitle,
isMobileKeyboardViewOpen: isMobileKeyboardViewOpen,
toggleMobileKeyboardView: toggleMobileKeyboardView,
isLandscape: isLandscape,
penIconClassName: classes.penIcon,
styleProps: styleProps
}, other, {
children: /*#__PURE__*/_jsx(DatePickerToolbarTitle, {
variant: "h4",
align: isLandscape ? 'left' : 'center',
styleProps: styleProps,
children: dateText
})
}));
});
export default DatePickerToolbar;