@material-ui/lab
Version:
Laboratory for new Material-UI modules.
246 lines (227 loc) • 9.05 kB
JavaScript
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
const _excluded = ["className", "day", "outsideCurrentMonth", "isEndOfHighlighting", "isEndOfPreviewing", "isHighlighting", "isPreviewing", "isStartOfHighlighting", "isStartOfPreviewing", "selected"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { alpha, styled } from '@material-ui/core/styles';
import { unstable_composeClasses as composeClasses, generateUtilityClass, generateUtilityClasses } from '@material-ui/unstyled';
import { DAY_MARGIN } from '../internal/pickers/constants/dimensions';
import { useUtils } from '../internal/pickers/hooks/useUtils';
import PickersDay, { areDayPropsEqual } from '../PickersDay/PickersDay';
import { jsx as _jsx } from "react/jsx-runtime";
export function getDateRangePickerDayUtilityClass(slot) {
return generateUtilityClass('MuiDateRangePickerDay', slot);
}
export const dateRangePickerDayClasses = generateUtilityClasses('MuiDateRangePickerDay', ['root', 'rangeIntervalDayHighlight', 'rangeIntervalDayHighlightStart', 'rangeIntervalDayHighlightEnd', 'rangeIntervalPreview', 'rangeIntervalDayPreview', 'rangeIntervalDayPreviewStart', 'rangeIntervalDayPreviewEnd', 'day', 'dayOutsideRangeInterval', 'dayInsideRangeInterval', 'notSelectedDate']);
const useUtilityClasses = styleProps => {
const {
isHighlighting,
outsideCurrentMonth,
isStartOfHighlighting,
isStartOfMonth,
isEndOfHighlighting,
isEndOfMonth,
isPreviewing,
isStartOfPreviewing,
isEndOfPreviewing,
selected,
classes
} = styleProps;
const slots = {
root: ['root', isHighlighting && !outsideCurrentMonth && 'rangeIntervalDayHighlight', (isStartOfHighlighting || isStartOfMonth) && 'rangeIntervalDayHighlightStart', (isEndOfHighlighting || isEndOfMonth) && 'rangeIntervalDayHighlightEnd'],
rangeIntervalPreview: ['rangeIntervalPreview', isPreviewing && !outsideCurrentMonth && 'rangeIntervalDayPreview', (isStartOfPreviewing || isStartOfMonth) && 'rangeIntervalDayPreviewStart', (isEndOfPreviewing || isEndOfMonth) && 'rangeIntervalDayPreviewEnd'],
day: ['day', !selected && 'notSelectedDate', !isHighlighting && 'dayOutsideRangeInterval', !selected && isHighlighting && 'dayInsideRangeInterval']
};
return composeClasses(slots, getDateRangePickerDayUtilityClass, classes);
};
const endBorderStyle = {
borderTopRightRadius: '50%',
borderBottomRightRadius: '50%'
};
const startBorderStyle = {
borderTopLeftRadius: '50%',
borderBottomLeftRadius: '50%'
};
const DateRangePickerDayRoot = styled('div', {
name: 'MuiDateRangePickerDay',
slot: 'Root',
overridesResolver: (props, styles) => styles.root
})(({
theme,
styleProps
}) => _extends({
[`&:first-of-type .${dateRangePickerDayClasses.rangeIntervalDayPreview}`]: _extends({}, startBorderStyle, {
borderLeftColor: theme.palette.divider
}),
[`&:last-of-type .${dateRangePickerDayClasses.rangeIntervalDayPreview}`]: _extends({}, endBorderStyle, {
borderRightColor: theme.palette.divider
})
}, styleProps.isHighlighting && !styleProps.outsideCurrentMonth && {
borderRadius: 0,
color: theme.palette.primary.contrastText,
backgroundColor: alpha(theme.palette.primary.light, 0.6),
'&:first-of-type': startBorderStyle,
'&:last-of-type': endBorderStyle
}, (styleProps.isStartOfHighlighting || styleProps.isStartOfMonth) && _extends({}, startBorderStyle, {
paddingLeft: 0,
marginLeft: DAY_MARGIN / 2
}), (styleProps.isEndOfHighlighting || styleProps.isEndOfMonth) && _extends({}, endBorderStyle, {
paddingRight: 0,
marginRight: DAY_MARGIN / 2
})));
const DateRangePickerDayRangeIntervalPreview = styled('div', {
name: 'MuiDateRangePickerDay',
slot: 'RangeIntervalPreview'
})(({
theme,
styleProps
}) => _extends({
// replace default day component margin with transparent border to avoid jumping on preview
border: '2px solid transparent'
}, styleProps.isPreviewing && !styleProps.outsideCurrentMonth && _extends({
borderRadius: 0,
border: `2px dashed ${theme.palette.divider}`,
borderLeftColor: 'transparent',
borderRightColor: 'transparent'
}, (styleProps.isStartOfPreviewing || styleProps.isStartOfMonth) && _extends({
borderLeftColor: theme.palette.divider
}, startBorderStyle), (styleProps.isEndOfPreviewing || styleProps.isEndOfMonth) && _extends({
borderRightColor: theme.palette.divider
}, endBorderStyle))));
const DateRangePickerDayDay = styled(PickersDay, {
name: 'MuiDateRangePickerDay',
slot: 'Day'
})(({
theme,
styleProps
}) => _extends({
// Required to overlap preview border
transform: 'scale(1.1)',
'& > *': {
transform: 'scale(0.9)'
}
}, !styleProps.selected && {
backgroundColor: 'transparent'
}, !styleProps.isHighlighting && {
'&:hover': {
border: `1px solid ${theme.palette.grey[500]}`
}
}, !styleProps.selected && styleProps.isHighlighting && {
color: theme.palette.getContrastText(alpha(theme.palette.primary.light, 0.6))
}));
const DateRangePickerDay = /*#__PURE__*/React.forwardRef(function DateRangePickerDay(props, ref) {
const {
className,
day,
outsideCurrentMonth,
isHighlighting,
isPreviewing,
selected = false
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const utils = useUtils();
const isEndOfMonth = utils.isSameDay(day, utils.endOfMonth(day));
const isStartOfMonth = utils.isSameDay(day, utils.startOfMonth(day));
const shouldRenderHighlight = isHighlighting && !outsideCurrentMonth;
const shouldRenderPreview = isPreviewing && !outsideCurrentMonth;
const styleProps = _extends({}, props, {
selected,
isStartOfMonth,
isEndOfMonth
});
const classes = useUtilityClasses(styleProps);
return /*#__PURE__*/_jsx(DateRangePickerDayRoot, {
className: clsx(classes.root, className),
styleProps: styleProps,
children: /*#__PURE__*/_jsx(DateRangePickerDayRangeIntervalPreview, {
role: "cell",
className: classes.rangeIntervalPreview,
styleProps: styleProps,
children: /*#__PURE__*/_jsx(DateRangePickerDayDay, _extends({}, other, {
ref: ref,
disableMargin: true,
allowSameDateSelection: true,
day: day,
selected: selected,
outsideCurrentMonth: outsideCurrentMonth,
className: classes.day,
styleProps: styleProps
}))
})
});
});
process.env.NODE_ENV !== "production" ? DateRangePickerDay.propTypes
/* remove-proptypes */
= {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The date to show.
*/
day: PropTypes.any.isRequired,
/**
* Set to `true` if the `day` is the end of a highlighted date range.
*/
isEndOfHighlighting: PropTypes.bool.isRequired,
/**
* Set to `true` if the `day` is the start of a highlighted date range.
*/
isEndOfPreviewing: PropTypes.bool.isRequired,
/**
* Set to `true` if the `day` is in a highlighted date range.
*/
isHighlighting: PropTypes.bool.isRequired,
/**
* Set to `true` if the `day` is in a preview date range.
*/
isPreviewing: PropTypes.bool.isRequired,
/**
* Set to `true` if the `day` is the start of a highlighted date range.
*/
isStartOfHighlighting: PropTypes.bool.isRequired,
/**
* Set to `true` if the `day` is the end of a highlighted date range.
*/
isStartOfPreviewing: PropTypes.bool.isRequired,
/**
* If `true`, day is outside of month and will be hidden.
*/
outsideCurrentMonth: PropTypes.bool.isRequired,
/**
* If `true`, renders as selected.
* @default false
*/
selected: PropTypes.bool,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.object
} : void 0;
/**
*
* Demos:
*
* - [Date Range Picker](https://material-ui.com/components/date-range-picker/)
*
* API:
*
* - [DateRangePickerDay API](https://material-ui.com/api/date-range-picker-day/)
*/
export default /*#__PURE__*/React.memo(DateRangePickerDay, (prevProps, nextProps) => {
return prevProps.isHighlighting === nextProps.isHighlighting && prevProps.isEndOfHighlighting === nextProps.isEndOfHighlighting && prevProps.isStartOfHighlighting === nextProps.isStartOfHighlighting && prevProps.isPreviewing === nextProps.isPreviewing && prevProps.isEndOfPreviewing === nextProps.isEndOfPreviewing && prevProps.isStartOfPreviewing === nextProps.isStartOfPreviewing && areDayPropsEqual(prevProps, nextProps);
});