UNPKG

@mui/x-date-pickers

Version:

The community edition of the Date and Time Picker components (MUI X).

155 lines (154 loc) 5.9 kB
"use strict"; 'use client'; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.DatePickerToolbar = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); var React = _interopRequireWildcard(require("react")); var _clsx = _interopRequireDefault(require("clsx")); var _propTypes = _interopRequireDefault(require("prop-types")); var _Typography = _interopRequireDefault(require("@mui/material/Typography")); var _styles = require("@mui/material/styles"); var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses")); var _PickersToolbar = require("../internals/components/PickersToolbar"); var _usePickersTranslations = require("../hooks/usePickersTranslations"); var _useUtils = require("../internals/hooks/useUtils"); var _datePickerToolbarClasses = require("./datePickerToolbarClasses"); var _dateUtils = require("../internals/utils/date-utils"); var _jsxRuntime = require("react/jsx-runtime"); const _excluded = ["value", "isLandscape", "onChange", "toolbarFormat", "toolbarPlaceholder", "views", "className", "onViewChange", "view"]; const useUtilityClasses = ownerState => { const { classes } = ownerState; const slots = { root: ['root'], title: ['title'] }; return (0, _composeClasses.default)(slots, _datePickerToolbarClasses.getDatePickerToolbarUtilityClass, classes); }; const DatePickerToolbarRoot = (0, _styles.styled)(_PickersToolbar.PickersToolbar, { name: 'MuiDatePickerToolbar', slot: 'Root', overridesResolver: (_, styles) => styles.root })({}); const DatePickerToolbarTitle = (0, _styles.styled)(_Typography.default, { name: 'MuiDatePickerToolbar', slot: 'Title', overridesResolver: (_, styles) => styles.title })({ variants: [{ props: { isLandscape: true }, style: { margin: 'auto 16px auto auto' } }] }); /** * Demos: * * - [DatePicker](https://mui.com/x/react-date-pickers/date-picker/) * - [Custom components](https://mui.com/x/react-date-pickers/custom-components/) * * API: * * - [DatePickerToolbar API](https://mui.com/x/api/date-pickers/date-picker-toolbar/) */ const DatePickerToolbar = exports.DatePickerToolbar = /*#__PURE__*/React.forwardRef(function DatePickerToolbar(inProps, ref) { const props = (0, _styles.useThemeProps)({ props: inProps, name: 'MuiDatePickerToolbar' }); const { value, isLandscape, toolbarFormat, toolbarPlaceholder = '––', views, className } = props, other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded); const utils = (0, _useUtils.useUtils)(); const translations = (0, _usePickersTranslations.usePickersTranslations)(); const classes = useUtilityClasses(props); const dateText = React.useMemo(() => { if (!value) { return toolbarPlaceholder; } const formatFromViews = (0, _dateUtils.resolveDateFormat)(utils, { format: toolbarFormat, views }, true); return utils.formatByString(value, formatFromViews); }, [value, toolbarFormat, toolbarPlaceholder, utils, views]); const ownerState = props; return /*#__PURE__*/(0, _jsxRuntime.jsx)(DatePickerToolbarRoot, (0, _extends2.default)({ ref: ref, toolbarTitle: translations.datePickerToolbarTitle, isLandscape: isLandscape, className: (0, _clsx.default)(classes.root, className) }, other, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DatePickerToolbarTitle, { variant: "h4", align: isLandscape ? 'left' : 'center', ownerState: ownerState, className: classes.title, children: dateText }) })); }); process.env.NODE_ENV !== "production" ? DatePickerToolbar.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "pnpm proptypes" | // ---------------------------------------------------------------------- /** * Override or extend the styles applied to the component. */ classes: _propTypes.default.object, className: _propTypes.default.string, disabled: _propTypes.default.bool, /** * If `true`, show the toolbar even in desktop mode. * @default `true` for Desktop, `false` for Mobile. */ hidden: _propTypes.default.bool, isLandscape: _propTypes.default.bool.isRequired, onChange: _propTypes.default.func.isRequired, /** * Callback called when a toolbar is clicked * @template TView * @param {TView} view The view to open */ onViewChange: _propTypes.default.func.isRequired, readOnly: _propTypes.default.bool, /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]), titleId: _propTypes.default.string, /** * Toolbar date format. */ toolbarFormat: _propTypes.default.string, /** * Toolbar value placeholder—it is displayed when the value is empty. * @default "––" */ toolbarPlaceholder: _propTypes.default.node, value: _propTypes.default.object, /** * Currently visible picker view. */ view: _propTypes.default.oneOf(['day', 'month', 'year']).isRequired, /** * Available views. */ views: _propTypes.default.arrayOf(_propTypes.default.oneOf(['day', 'month', 'year']).isRequired).isRequired } : void 0;