UNPKG

@material-ui/lab

Version:
86 lines (79 loc) 3.01 kB
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; import _extends from "@babel/runtime/helpers/esm/extends"; const _excluded = ["date", "isLandscape", "isMobileKeyboardViewOpen", "onChange", "toggleMobileKeyboardView", "toolbarFormat", "toolbarPlaceholder", "toolbarTitle", "views"]; 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"; const classes = generateUtilityClasses('PrivateDatePickerToolbar', ['penIcon']); const DatePickerToolbarRoot = styled(PickersToolbar, { skipSx: true })({ [`& .${classes.penIcon}`]: { position: 'relative', top: 4 } }); const DatePickerToolbarTitle = styled(Typography, { skipSx: true })(({ styleProps }) => _extends({}, styleProps.isLandscape && { margin: 'auto 16px auto auto' })); /** * @ignore - internal component. */ const DatePickerToolbar = /*#__PURE__*/React.forwardRef(function DatePickerToolbar(props, ref) { const { date, isLandscape, isMobileKeyboardViewOpen, toggleMobileKeyboardView, toolbarFormat, toolbarPlaceholder = '––', toolbarTitle = 'Select date', views } = props, other = _objectWithoutPropertiesLoose(props, _excluded); const utils = useUtils(); const dateText = React.useMemo(() => { 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]); const 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;