@mui/x-date-pickers-pro
Version:
The Pro plan edition of the MUI X Date and Time Picker components.
604 lines (600 loc) • 21.6 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DateRangePickerDay2 = void 0;
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _clsx = _interopRequireDefault(require("clsx"));
var _styles = require("@mui/material/styles");
var _ButtonBase = _interopRequireDefault(require("@mui/material/ButtonBase"));
var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
var _internals = require("@mui/x-date-pickers/internals");
var _hooks = require("@mui/x-date-pickers/hooks");
var _dateRangePickerDay2Classes = require("./dateRangePickerDay2Classes");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["autoFocus", "className", "classes", "hidden", "isAnimating", "onClick", "onDaySelect", "onFocus", "onBlur", "onKeyDown", "onMouseDown", "onMouseEnter", "children", "isFirstVisibleCell", "isLastVisibleCell", "day", "selected", "disabled", "today", "outsideCurrentMonth", "disableHighlightToday", "showDaysOutsideCurrentMonth", "isEndOfHighlighting", "isEndOfPreviewing", "isHighlighting", "isPreviewing", "isStartOfHighlighting", "isStartOfPreviewing", "isVisuallySelected", "draggable"];
const useUtilityClasses = (ownerState, classes) => {
const {
isDaySelected,
disableHighlightToday,
isDayCurrent,
isDayDisabled,
isDayOutsideMonth,
isDayFillerCell,
isDayPreviewStart,
isDayPreviewEnd,
isDayInsidePreview,
isDayPreviewed,
isDaySelectionStart,
isDaySelectionEnd,
isDayInsideSelection,
isDayStartOfWeek,
isDayEndOfWeek,
isDayStartOfMonth,
isDayEndOfMonth,
isDayDraggable
} = ownerState;
const slots = {
root: ['root', isDayDisabled && 'disabled', !disableHighlightToday && isDayCurrent && !isDaySelected && !isDayFillerCell && 'today', isDayOutsideMonth && 'dayOutsideMonth', isDayFillerCell && 'fillerCell', isDaySelected && 'selected', isDayPreviewStart && 'previewStart', isDayPreviewEnd && 'previewEnd', isDayInsidePreview && 'insidePreviewing', isDaySelectionStart && 'selectionStart', isDaySelectionEnd && 'selectionEnd', isDayInsideSelection && 'insideSelection', isDayEndOfWeek && 'endOfWeek', isDayStartOfWeek && 'startOfWeek', isDayPreviewed && 'previewed', isDayStartOfMonth && 'startOfMonth', isDayEndOfMonth && 'endOfMonth', isDayDraggable && 'draggable']
};
return (0, _composeClasses.default)(slots, _dateRangePickerDay2Classes.getDateRangePickerDay2UtilityClass, classes);
};
const highlightStyles = theme => ({
content: '""' /* Creates an empty element */,
height: '100%',
backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.focusOpacity})` : (0, _styles.alpha)(theme.palette.primary.main, theme.palette.action.focusOpacity),
boxSizing: 'border-box',
left: 'calc(var(--PickerDay-horizontalMargin) * (-1))',
right: 'calc(var(--PickerDay-horizontalMargin) * (-1))'
});
const previewStyles = theme => ({
content: '""' /* Creates an empty element */,
height: '100%',
border: `1.2px dashed ${(theme.vars || theme).palette.divider}`,
borderLeftColor: 'transparent',
borderRightColor: 'transparent',
boxSizing: 'border-box',
borderOffset: '-1px',
left: 'calc(-1 * var(--PickerDay-horizontalMargin))',
right: 'calc(-1 * var(--PickerDay-horizontalMargin))'
});
const selectedDayStyles = theme => ({
color: (theme.vars || theme).palette.primary.contrastText,
backgroundColor: (theme.vars || theme).palette.primary.main,
fontWeight: theme.typography.fontWeightMedium,
'&:focus, &:hover': {
willChange: 'background-color',
backgroundColor: (theme.vars || theme).palette.primary.dark
},
[`&.${_dateRangePickerDay2Classes.dateRangePickerDay2Classes.disabled}`]: {
opacity: 0.6
}
});
const DateRangePickerDay2Root = (0, _styles.styled)(_ButtonBase.default, {
name: 'MuiDateRangePickerDay2',
slot: 'Root',
overridesResolver: (props, styles) => {
const {
ownerState
} = props;
return [styles.root, !ownerState.disableHighlightToday && ownerState.isDayCurrent && styles.today, !ownerState.isDayOutsideMonth && styles.dayOutsideMonth, ownerState.isDayFillerCell && styles.fillerCell, ownerState.isDaySelected && !ownerState.isDayInsideSelection && styles.selected, ownerState.isDayPreviewStart && styles.previewStart, ownerState.isDayPreviewEnd && styles.previewEnd, ownerState.isDayInsidePreview && styles.insidePreviewing, ownerState.isDaySelectionStart && styles.selectionStart, ownerState.isDaySelectionEnd && styles.selectionEnd, ownerState.isDayInsideSelection && styles.insideSelection, ownerState.isDayDraggable && styles.draggable, ownerState.isDayStartOfWeek && styles.startOfWeek, ownerState.isDayEndOfWeek && styles.endOfWeek];
}
})(({
theme
}) => (0, _extends2.default)({
'--PickerDay-horizontalMargin': '2px',
'--PickerDay-size': '36px'
}, theme.typography.caption, {
width: 'var(--PickerDay-size)',
height: 'var(--PickerDay-size)',
borderRadius: '18px',
padding: 0,
position: 'relative',
marginLeft: 'var(--PickerDay-horizontalMargin)',
marginRight: 'var(--PickerDay-horizontalMargin)',
// explicitly setting to `transparent` to avoid potentially getting impacted by change from the overridden component
backgroundColor: 'transparent',
transition: theme.transitions.create('background-color', {
duration: theme.transitions.duration.short
}),
color: (theme.vars || theme).palette.text.primary,
'@media (pointer: fine)': {
'&:hover': {
backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.hoverOpacity})` : (0, _styles.alpha)(theme.palette.primary.main, theme.palette.action.hoverOpacity)
}
},
'&:focus': {
backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.focusOpacity})` : (0, _styles.alpha)(theme.palette.primary.main, theme.palette.action.focusOpacity)
},
zIndex: 1,
isolation: 'isolate',
'&::before, &::after': {
zIndex: -1,
position: 'absolute',
pointerEvents: 'none',
mixBlendMode: 'multiply'
},
variants: [{
props: {
isDayDisabled: true
},
style: {
color: (theme.vars || theme).palette.text.disabled
}
}, {
props: {
isDayFillerCell: true
},
style: {
// visibility: 'hidden' does not work here as it hides the element from screen readers
// and results in unexpected relationships between week day and day columns.
opacity: 0,
pointerEvents: 'none'
}
}, {
props: {
isDayOutsideMonth: true
},
style: {
color: (theme.vars || theme).palette.text.secondary
}
}, {
props: {
isDayCurrent: true,
isDaySelected: false
},
style: {
outline: `1px solid ${(theme.vars || theme).palette.text.secondary}`,
outlineOffset: -1
}
}, {
props: {
isDayDraggable: true
},
style: {
cursor: 'grab',
touchAction: 'none'
}
}, {
props: {
isDayPreviewStart: true
},
style: {
'::after': (0, _extends2.default)({}, previewStyles(theme), {
borderTopLeftRadius: 'inherit',
borderBottomLeftRadius: 'inherit',
borderLeftColor: (theme.vars || theme).palette.divider,
left: 0
})
}
}, {
props: {
isDayPreviewEnd: true
},
style: {
'::after': (0, _extends2.default)({}, previewStyles(theme), {
borderTopRightRadius: 'inherit',
borderBottomRightRadius: 'inherit',
borderRightColor: (theme.vars || theme).palette.divider,
right: 0
})
}
}, {
props: {
isDayInsidePreview: true
},
style: {
'::after': (0, _extends2.default)({}, previewStyles(theme))
}
}, {
props: {
isDaySelectionStart: true
},
style: {
'::before': (0, _extends2.default)({}, highlightStyles(theme), {
borderTopLeftRadius: 'inherit',
borderBottomLeftRadius: 'inherit',
left: 0
})
}
}, {
props: {
isDaySelectionEnd: true
},
style: {
'::before': (0, _extends2.default)({}, highlightStyles(theme), {
borderTopRightRadius: 'inherit',
borderBottomRightRadius: 'inherit',
right: 0
}),
'::after': {
borderLeftColor: 'transparent'
}
}
}, {
props: {
isDayInsideSelection: true
},
color: 'initial',
background: 'initial',
style: {
'::before': (0, _extends2.default)({}, highlightStyles(theme))
}
}, {
props: {
isDaySelected: true,
isDayInsideSelection: false
},
style: (0, _extends2.default)({}, selectedDayStyles(theme))
}, {
props: {
isDaySelectionStart: true,
isDaySelectionEnd: true
},
style: {
'::before': {
left: 0,
right: 0
}
}
}, {
props: {
isDaySelectionStart: true,
isDaySelectionEnd: true,
isDayPreviewEnd: false,
isDayPreviewStart: false
},
style: {
'::after': {
left: 0,
right: 0
}
}
}, {
props: {
isDayPreviewEnd: true,
isDayPreviewStart: true
},
style: {
'::after': {
left: 0,
right: 0
}
}
}, {
props: {
isDayEndOfWeek: true
},
style: {
'::after': {
borderTopRightRadius: 'inherit',
borderBottomRightRadius: 'inherit',
borderRightColor: (theme.vars || theme).palette.divider,
right: 0
},
'::before': {
borderTopRightRadius: 'inherit',
borderBottomRightRadius: 'inherit',
right: 0
}
}
}, {
props: {
isDayStartOfWeek: true
},
style: {
'::after': {
borderTopLeftRadius: 'inherit',
borderBottomLeftRadius: 'inherit',
borderLeftColor: (theme.vars || theme).palette.divider,
left: 0
},
'::before': {
borderTopLeftRadius: 'inherit',
borderBottomLeftRadius: 'inherit',
left: 0
}
}
}]
}));
const noop = () => {};
const DateRangePickerDay2Raw = /*#__PURE__*/React.forwardRef(function DateRangePickerDay2(inProps, forwardedRef) {
const props = (0, _styles.useThemeProps)({
props: inProps,
name: 'MuiDateRangePickerDay2'
});
const adapter = (0, _hooks.usePickerAdapter)();
const {
autoFocus = false,
className,
classes: classesProp,
isAnimating,
onClick,
onDaySelect,
onFocus = noop,
onBlur = noop,
onKeyDown = noop,
onMouseDown = noop,
onMouseEnter = noop,
children,
isFirstVisibleCell,
isLastVisibleCell,
day,
selected,
disabled,
today,
outsideCurrentMonth,
disableHighlightToday,
showDaysOutsideCurrentMonth,
isEndOfHighlighting,
isEndOfPreviewing,
isHighlighting,
isPreviewing,
isStartOfHighlighting,
isStartOfPreviewing,
draggable
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const pickersDayOwnerState = (0, _internals.usePickerDayOwnerState)({
day,
selected,
disabled,
today,
outsideCurrentMonth,
disableMargin: false,
disableHighlightToday,
showDaysOutsideCurrentMonth
});
const ownerState = (0, _extends2.default)({}, pickersDayOwnerState, {
// Properties that the Base UI implementation will have
isDaySelectionStart: isStartOfHighlighting,
isDaySelectionEnd: isEndOfHighlighting,
isDayInsideSelection: isHighlighting && !isStartOfHighlighting && !isEndOfHighlighting,
isDaySelected: isHighlighting || Boolean(selected),
isDayPreviewed: isPreviewing,
isDayPreviewStart: isStartOfPreviewing,
isDayPreviewEnd: isEndOfPreviewing,
isDayInsidePreview: isPreviewing && !isStartOfPreviewing && !isEndOfPreviewing,
// Properties specific to the MUI implementation (some might be removed in the next major)
isDayStartOfMonth: adapter.isSameDay(day, adapter.startOfMonth(day)),
isDayEndOfMonth: adapter.isSameDay(day, adapter.endOfMonth(day)),
isDayFirstVisibleCell: isFirstVisibleCell,
isDayLastVisibleCell: isLastVisibleCell,
isDayFillerCell: outsideCurrentMonth && !showDaysOutsideCurrentMonth,
isDayDraggable: Boolean(draggable)
});
const classes = useUtilityClasses(ownerState, classesProp);
const ref = React.useRef(null);
const handleRef = (0, _useForkRef.default)(ref, forwardedRef);
// Since this is rendered when a Popper is opened we can't use passive effects.
// Focusing in passive effects in Popper causes scroll jump.
(0, _useEnhancedEffect.default)(() => {
if (autoFocus && !disabled && !isAnimating && !outsideCurrentMonth) {
// ref.current being null would be a bug in MUI
ref.current.focus();
}
}, [autoFocus, disabled, isAnimating, outsideCurrentMonth]);
// For a day outside the current month, move the focus from mouseDown to mouseUp
// Goal: have the onClick ends before sliding to the new month
const handleMouseDown = event => {
onMouseDown(event);
if (outsideCurrentMonth) {
event.preventDefault();
}
};
const handleClick = event => {
if (!disabled) {
onDaySelect(day);
}
if (outsideCurrentMonth) {
event.currentTarget.focus();
}
if (onClick) {
onClick(event);
}
};
return /*#__PURE__*/(0, _jsxRuntime.jsx)(DateRangePickerDay2Root, (0, _extends2.default)({
ref: handleRef,
centerRipple: true
// compat with DateRangePickerDay for tests
,
disabled: ownerState.isDayFillerCell ? undefined : disabled,
tabIndex: selected ? 0 : -1,
onKeyDown: event => onKeyDown(event, day),
onFocus: event => onFocus(event, day),
onBlur: event => onBlur(event, day),
onMouseEnter: event => onMouseEnter(event, day),
onClick: handleClick,
onMouseDown: handleMouseDown,
draggable: draggable
}, other, {
ownerState: ownerState,
className: (0, _clsx.default)(classes.root, className),
children: children ?? (ownerState.isDayFillerCell ? null : adapter.format(day, 'dayOfMonth'))
}));
});
if (process.env.NODE_ENV !== "production") DateRangePickerDay2Raw.displayName = "DateRangePickerDay2Raw";
process.env.NODE_ENV !== "production" ? DateRangePickerDay2Raw.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* A ref for imperative actions.
* It currently only supports `focusVisible()` action.
*/
action: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
current: _propTypes.default.shape({
focusVisible: _propTypes.default.func.isRequired
})
})]),
/**
* If `true`, the ripples are centered.
* They won't start at the cursor interaction position.
* @default false
*/
centerRipple: _propTypes.default.bool,
/**
* Override or extend the styles applied to the component.
*/
classes: _propTypes.default.object,
className: _propTypes.default.string,
component: _propTypes.default.elementType,
/**
* The date to show.
*/
day: _propTypes.default.object.isRequired,
/**
* If `true`, renders as disabled.
* @default false
*/
disabled: _propTypes.default.bool,
/**
* If `true`, today's date is rendering without highlighting with circle.
* @default false
*/
disableHighlightToday: _propTypes.default.bool,
/**
* If `true`, days are rendering without margin. Useful for displaying linked range of days.
* @default false
*/
disableMargin: _propTypes.default.bool,
/**
* If `true`, the ripple effect is disabled.
*
* ⚠️ Without a ripple there is no styling for :focus-visible by default. Be sure
* to highlight the element by applying separate styles with the `.Mui-focusVisible` class.
* @default false
*/
disableRipple: _propTypes.default.bool,
/**
* If `true`, the touch ripple effect is disabled.
* @default false
*/
disableTouchRipple: _propTypes.default.bool,
/**
* If `true`, the day can be dragged to change the current date range.
* @default false
*/
draggable: _propTypes.default.bool,
/**
* If `true`, the base button will have a keyboard focus ripple.
* @default false
*/
focusRipple: _propTypes.default.bool,
/**
* This prop can help identify which element has keyboard focus.
* The class name will be applied when the element gains the focus through keyboard interaction.
* It's a polyfill for the [CSS :focus-visible selector](https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo).
* The rationale for using this feature [is explained here](https://github.com/WICG/focus-visible/blob/HEAD/explainer.md).
* A [polyfill can be used](https://github.com/WICG/focus-visible) to apply a `focus-visible` class to other components
* if needed.
*/
focusVisibleClassName: _propTypes.default.string,
isAnimating: _propTypes.default.bool,
/**
* Set to `true` if the `day` is the end of a highlighted date range.
*/
isEndOfHighlighting: _propTypes.default.bool.isRequired,
/**
* Set to `true` if the `day` is the end of a previewing date range.
*/
isEndOfPreviewing: _propTypes.default.bool.isRequired,
/**
* If `true`, day is the first visible cell of the month.
* Either the first day of the month or the first day of the week depending on `showDaysOutsideCurrentMonth`.
*/
isFirstVisibleCell: _propTypes.default.bool.isRequired,
/**
* Set to `true` if the `day` is in a highlighted date range.
*/
isHighlighting: _propTypes.default.bool.isRequired,
/**
* If `true`, day is the last visible cell of the month.
* Either the last day of the month or the last day of the week depending on `showDaysOutsideCurrentMonth`.
*/
isLastVisibleCell: _propTypes.default.bool.isRequired,
/**
* Set to `true` if the `day` is in a preview date range.
*/
isPreviewing: _propTypes.default.bool.isRequired,
/**
* Set to `true` if the `day` is the start of a highlighted date range.
*/
isStartOfHighlighting: _propTypes.default.bool.isRequired,
/**
* Set to `true` if the `day` is the start of a previewing date range.
*/
isStartOfPreviewing: _propTypes.default.bool.isRequired,
/**
* Indicates if the day should be visually selected.
*/
isVisuallySelected: _propTypes.default.bool,
onBlur: _propTypes.default.func,
onDaySelect: _propTypes.default.func.isRequired,
onFocus: _propTypes.default.func,
/**
* Callback fired when the component is focused with a keyboard.
* We trigger a `onFocus` callback too.
*/
onFocusVisible: _propTypes.default.func,
onKeyDown: _propTypes.default.func,
onMouseEnter: _propTypes.default.func,
/**
* If `true`, day is outside of month and will be hidden.
*/
outsideCurrentMonth: _propTypes.default.bool.isRequired,
/**
* If `true`, renders as selected.
* @default false
*/
selected: _propTypes.default.bool,
/**
* If `true`, days outside the current month are rendered:
*
* - if `fixedWeekNumber` is defined, renders days to have the weeks requested.
*
* - if `fixedWeekNumber` is not defined, renders day to fill the first and last week of the current month.
*
* - ignored if `calendars` equals more than `1` on range pickers.
* @default false
*/
showDaysOutsideCurrentMonth: _propTypes.default.bool,
style: _propTypes.default.object,
/**
* 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]),
/**
* @default 0
*/
tabIndex: _propTypes.default.number,
/**
* If `true`, renders as today date.
* @default false
*/
today: _propTypes.default.bool,
/**
* Props applied to the `TouchRipple` element.
*/
TouchRippleProps: _propTypes.default.object,
/**
* A ref that points to the `TouchRipple` element.
*/
touchRippleRef: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
current: _propTypes.default.shape({
pulsate: _propTypes.default.func.isRequired,
start: _propTypes.default.func.isRequired,
stop: _propTypes.default.func.isRequired
})
})])
} : void 0;
const DateRangePickerDay2 = exports.DateRangePickerDay2 = /*#__PURE__*/React.memo(DateRangePickerDay2Raw);
if (process.env.NODE_ENV !== "production") DateRangePickerDay2.displayName = "DateRangePickerDay2";