@mui/x-date-pickers-pro
Version:
The Pro plan edition of the MUI X Date and Time Picker components.
130 lines (128 loc) • 4.99 kB
JavaScript
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["toolbarFormat", "className", "classes"];
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, useToolbarOwnerState } from '@mui/x-date-pickers/internals';
import { usePickerAdapter, usePickerContext, usePickerTranslations } from '@mui/x-date-pickers/hooks';
import { getDateRangePickerToolbarUtilityClass } from "./dateRangePickerToolbarClasses.js";
import { usePickerRangePositionContext } from "../hooks/index.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const useUtilityClasses = classes => {
const slots = {
root: ['root'],
container: ['container']
};
return composeClasses(slots, getDateRangePickerToolbarUtilityClass, classes);
};
const DateRangePickerToolbarRoot = styled(PickersToolbar, {
name: 'MuiDateRangePickerToolbar',
slot: 'Root'
})({});
const DateRangePickerToolbarContainer = styled('div', {
name: 'MuiDateRangePickerToolbar',
slot: '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 adapter = usePickerAdapter();
const props = useThemeProps({
props: inProps,
name: 'MuiDateRangePickerToolbar'
});
const {
toolbarFormat: toolbarFormatProp,
className,
classes: classesProp
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const {
value
} = usePickerContext();
const translations = usePickerTranslations();
const ownerState = useToolbarOwnerState();
const {
rangePosition,
setRangePosition
} = usePickerRangePositionContext();
const classes = useUtilityClasses(classesProp);
// This can't be a default value when spreading because it breaks the API generation.
const toolbarFormat = toolbarFormatProp ?? adapter.formats.shortDate;
const formatDate = (date, fallback) => {
if (!adapter.isValid(date)) {
return fallback;
}
return adapter.formatByString(date, toolbarFormat);
};
return /*#__PURE__*/_jsx(DateRangePickerToolbarRoot, _extends({}, other, {
toolbarTitle: translations.dateRangePickerToolbarTitle,
className: clsx(classes.root, className),
ownerState: ownerState,
ref: ref,
children: /*#__PURE__*/_jsxs(DateRangePickerToolbarContainer, {
className: classes.container,
children: [/*#__PURE__*/_jsx(PickersToolbarButton, {
variant: value[0] == null ? 'h6' : 'h5',
value: formatDate(value[0], translations.start),
selected: rangePosition === 'start',
onClick: () => setRangePosition('start')
}), /*#__PURE__*/_jsxs(Typography, {
variant: "h5",
children: ["\xA0", '–', "\xA0"]
}), /*#__PURE__*/_jsx(PickersToolbarButton, {
variant: value[1] == null ? 'h6' : 'h5',
value: formatDate(value[1], translations.end),
selected: rangePosition === 'end',
onClick: () => setRangePosition('end')
})]
})
}));
});
if (process.env.NODE_ENV !== "production") DateRangePickerToolbar.displayName = "DateRangePickerToolbar";
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,
/**
* If `true`, show the toolbar even in desktop mode.
* @default `true` for Desktop, `false` for Mobile.
*/
hidden: 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
} : void 0;
export { DateRangePickerToolbar };