@mui/x-date-pickers-pro
Version:
The Pro plan edition of the MUI X Date and Time Picker components.
137 lines (135 loc) • 4.35 kB
JavaScript
'use client';
import * as React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import Tab from '@mui/material/Tab';
import Tabs, { tabsClasses } from '@mui/material/Tabs';
import { styled, useThemeProps } from '@mui/material/styles';
import composeClasses from '@mui/utils/composeClasses';
import { TimeIcon } from '@mui/x-date-pickers/icons';
import { usePickerContext, usePickerTranslations } from '@mui/x-date-pickers/hooks';
import { getTimeRangePickerTabsUtilityClass } from "./timeRangePickerTabsClasses.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'],
tab: ['tab']
};
return composeClasses(slots, getTimeRangePickerTabsUtilityClass, classes);
};
const TimeRangePickerTabsRoot = styled(Tabs, {
name: 'MuiTimeRangePickerTabs',
slot: 'Root'
})(({
theme
}) => ({
boxShadow: `0 -1px 0 0 inset ${(theme.vars || theme).palette.divider}`,
'&:last-child': {
boxShadow: `0 1px 0 0 inset ${(theme.vars || theme).palette.divider}`,
[`& .${tabsClasses.indicator}`]: {
bottom: 'auto',
top: 0
}
}
}));
const TimeRangePickerTab = styled(Tab, {
name: 'MuiTimeRangePickerTabs',
slot: 'Tab'
})(({
theme
}) => ({
minHeight: '48px',
gap: theme.spacing(1)
}));
/**
* Demos:
*
* - [TimeRangePicker](https://mui.com/x/react-date-pickers/time-range-picker/)
* - [Custom slots and subcomponents](https://mui.com/x/react-date-pickers/custom-components/)
*
* API:
*
* - [TimeRangePickerTabs API](https://mui.com/x/api/date-pickers/time-range-picker-tabs/)
*/
const TimeRangePickerTabs = function TimeRangePickerTabs(inProps) {
const props = useThemeProps({
props: inProps,
name: 'MuiTimeRangePickerTabs'
});
const {
timeIcon = /*#__PURE__*/_jsx(TimeIcon, {}),
hidden = typeof window === 'undefined' || window.innerHeight < 667,
className,
sx,
classes: classesProp
} = props;
const translations = usePickerTranslations();
const {
view,
setView
} = usePickerContext();
const {
rangePosition,
setRangePosition
} = usePickerRangePositionContext();
const classes = useUtilityClasses(classesProp);
const handleChange = (event, value) => {
if (rangePosition !== value) {
setRangePosition(value);
}
if (view !== 'hours') {
setView('hours');
}
};
if (hidden) {
return null;
}
return /*#__PURE__*/_jsxs(TimeRangePickerTabsRoot, {
variant: "fullWidth",
value: rangePosition,
onChange: handleChange,
className: clsx(className, classes.root),
sx: sx,
children: [/*#__PURE__*/_jsx(TimeRangePickerTab, {
value: "start",
iconPosition: "start",
icon: timeIcon,
label: translations.start,
className: classes.tab
}), /*#__PURE__*/_jsx(TimeRangePickerTab, {
value: "end",
iconPosition: "start",
label: translations.end,
icon: timeIcon,
className: classes.tab
})]
});
};
if (process.env.NODE_ENV !== "production") TimeRangePickerTabs.displayName = "TimeRangePickerTabs";
process.env.NODE_ENV !== "production" ? TimeRangePickerTabs.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,
/**
* Toggles visibility of the tabs allowing view switching.
* @default `window.innerHeight < 667` for `DesktopTimeRangePicker` and `MobileTimeRangePicker`, `displayStaticWrapperAs === 'desktop'` for `StaticTimeRangePicker`
*/
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]),
/**
* Time tab icon.
* @default Time
*/
timeIcon: PropTypes.element
} : void 0;
export { TimeRangePickerTabs };