@mui/x-date-pickers-pro
Version:
The Pro plan edition of the Date and Time Picker components (MUI X).
141 lines (140 loc) • 5.33 kB
JavaScript
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["value", "rangePosition", "onRangePositionChange", "toolbarFormat", "className", "onViewChange", "view", "views"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import Typography from '@mui/material/Typography';
import { styled, useThemeProps } from '@mui/material/styles';
import composeClasses from '@mui/utils/composeClasses';
import { PickersToolbar, PickersToolbarButton, useUtils } from '@mui/x-date-pickers/internals';
import { usePickersTranslations } from '@mui/x-date-pickers/hooks';
import { getDateRangePickerToolbarUtilityClass } from "./dateRangePickerToolbarClasses.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['root'],
container: ['container']
};
return composeClasses(slots, getDateRangePickerToolbarUtilityClass, classes);
};
const DateRangePickerToolbarRoot = styled(PickersToolbar, {
name: 'MuiDateRangePickerToolbar',
slot: 'Root',
overridesResolver: (_, styles) => styles.root
})({});
const DateRangePickerToolbarContainer = styled('div', {
name: 'MuiDateRangePickerToolbar',
slot: 'Container',
overridesResolver: (_, styles) => styles.container
})({
display: 'flex'
});
/**
* Demos:
*
* - [DateRangePicker](https://mui.com/x/react-date-pickers/date-range-picker/)
* - [Custom components](https://mui.com/x/react-date-pickers/custom-components/)
*
* API:
*
* - [DateRangePickerToolbar API](https://mui.com/x/api/date-pickers/date-range-picker-toolbar/)
*/
const DateRangePickerToolbar = /*#__PURE__*/React.forwardRef(function DateRangePickerToolbar(inProps, ref) {
const utils = useUtils();
const props = useThemeProps({
props: inProps,
name: 'MuiDateRangePickerToolbar'
});
const {
value: [start, end],
rangePosition,
onRangePositionChange,
toolbarFormat,
className
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const translations = usePickersTranslations();
const startDateValue = start ? utils.formatByString(start, toolbarFormat || utils.formats.shortDate) : translations.start;
const endDateValue = end ? utils.formatByString(end, toolbarFormat || utils.formats.shortDate) : translations.end;
const ownerState = props;
const classes = useUtilityClasses(ownerState);
return /*#__PURE__*/_jsx(DateRangePickerToolbarRoot, _extends({}, other, {
toolbarTitle: translations.dateRangePickerToolbarTitle,
isLandscape: false,
className: clsx(classes.root, className),
ownerState: ownerState,
ref: ref,
children: /*#__PURE__*/_jsxs(DateRangePickerToolbarContainer, {
className: classes.container,
children: [/*#__PURE__*/_jsx(PickersToolbarButton, {
variant: start !== null ? 'h5' : 'h6',
value: startDateValue,
selected: rangePosition === 'start',
onClick: () => onRangePositionChange('start')
}), /*#__PURE__*/_jsxs(Typography, {
variant: "h5",
children: ["\xA0", '–', "\xA0"]
}), /*#__PURE__*/_jsx(PickersToolbarButton, {
variant: end !== null ? 'h5' : 'h6',
value: endDateValue,
selected: rangePosition === 'end',
onClick: () => onRangePositionChange('end')
})]
})
}));
});
process.env.NODE_ENV !== "production" ? DateRangePickerToolbar.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.object,
className: PropTypes.string,
disabled: PropTypes.bool,
/**
* If `true`, show the toolbar even in desktop mode.
* @default `true` for Desktop, `false` for Mobile.
*/
hidden: PropTypes.bool,
onRangePositionChange: PropTypes.func.isRequired,
/**
* Callback called when a toolbar is clicked
* @template TView
* @param {TView} view The view to open
*/
onViewChange: PropTypes.func.isRequired,
rangePosition: PropTypes.oneOf(['end', 'start']).isRequired,
readOnly: PropTypes.bool,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
titleId: PropTypes.string,
/**
* Toolbar date format.
*/
toolbarFormat: PropTypes.string,
/**
* Toolbar value placeholder—it is displayed when the value is empty.
* @default "––"
*/
toolbarPlaceholder: PropTypes.node,
value: PropTypes.arrayOf(PropTypes.object).isRequired,
/**
* Currently visible picker view.
*/
view: PropTypes.oneOf(['day']).isRequired,
/**
* Available views.
*/
views: PropTypes.arrayOf(PropTypes.oneOf(['day'])).isRequired
} : void 0;
export { DateRangePickerToolbar };