UNPKG

@mui/x-date-pickers-pro

Version:

The Pro plan edition of the Date and Time Picker components (MUI X).

355 lines 15 kB
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; import _extends from "@babel/runtime/helpers/esm/extends"; const _excluded = ["slots", "slotProps", "unstableStartFieldRef", "unstableEndFieldRef", "className"]; import * as React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import Stack from '@mui/material/Stack'; import MuiTextField from '@mui/material/TextField'; import Typography from '@mui/material/Typography'; import { styled, useThemeProps } from '@mui/material/styles'; import { useSlotProps } from '@mui/base/utils'; import { unstable_composeClasses as composeClasses, unstable_generateUtilityClass as generateUtilityClass, unstable_generateUtilityClasses as generateUtilityClasses } from '@mui/utils'; import { splitFieldInternalAndForwardedProps, convertFieldResponseIntoMuiTextFieldProps } from '@mui/x-date-pickers/internals'; import { PickersTextField } from '@mui/x-date-pickers/PickersTextField'; import { useMultiInputDateTimeRangeField } from '../internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; export const multiInputDateTimeRangeFieldClasses = generateUtilityClasses('MuiMultiInputDateTimeRangeField', ['root', 'separator']); export const getMultiInputDateTimeRangeFieldUtilityClass = slot => generateUtilityClass('MuiMultiInputDateTimeRangeField', slot); const useUtilityClasses = ownerState => { const { classes } = ownerState; const slots = { root: ['root'], separator: ['separator'] }; return composeClasses(slots, getMultiInputDateTimeRangeFieldUtilityClass, classes); }; const MultiInputDateTimeRangeFieldRoot = styled( /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/_jsx(Stack, _extends({ ref: ref, spacing: 2, direction: "row", alignItems: "center" }, props))), { name: 'MuiMultiInputDateTimeRangeField', slot: 'Root', overridesResolver: (props, styles) => styles.root })({}); const MultiInputDateTimeRangeFieldSeparator = styled(Typography, { name: 'MuiMultiInputDateTimeRangeField', slot: 'Separator', overridesResolver: (props, styles) => styles.separator })({ lineHeight: '1.4375em' // 23px }); /** * Demos: * * - [DateTimeRangeField](http://mui.com/x/react-date-pickers/date-time-range-field/) * - [Fields](https://mui.com/x/react-date-pickers/fields/) * * API: * * - [MultiInputDateTimeRangeField API](https://mui.com/x/api/multi-input-date-time-range-field/) */ const MultiInputDateTimeRangeField = /*#__PURE__*/React.forwardRef(function MultiInputDateTimeRangeField(inProps, ref) { const themeProps = useThemeProps({ props: inProps, name: 'MuiMultiInputDateTimeRangeField' }); const { internalProps, forwardedProps } = splitFieldInternalAndForwardedProps(themeProps, 'date-time'); const { slots, slotProps, unstableStartFieldRef, unstableEndFieldRef, className } = forwardedProps, otherForwardedProps = _objectWithoutPropertiesLoose(forwardedProps, _excluded); const ownerState = themeProps; const classes = useUtilityClasses(ownerState); const Root = slots?.root ?? MultiInputDateTimeRangeFieldRoot; const rootProps = useSlotProps({ elementType: Root, externalSlotProps: slotProps?.root, externalForwardedProps: otherForwardedProps, additionalProps: { ref }, ownerState, className: clsx(className, classes.root) }); const TextField = slots?.textField ?? (inProps.enableAccessibleFieldDOMStructure ? PickersTextField : MuiTextField); const startTextFieldProps = useSlotProps({ elementType: TextField, externalSlotProps: slotProps?.textField, ownerState: _extends({}, ownerState, { position: 'start' }) }); const endTextFieldProps = useSlotProps({ elementType: TextField, externalSlotProps: slotProps?.textField, ownerState: _extends({}, ownerState, { position: 'end' }) }); const Separator = slots?.separator ?? MultiInputDateTimeRangeFieldSeparator; const separatorProps = useSlotProps({ elementType: Separator, externalSlotProps: slotProps?.separator, additionalProps: { children: ` ${internalProps.dateSeparator ?? '–'} ` }, ownerState, className: classes.separator }); const fieldResponse = useMultiInputDateTimeRangeField({ sharedProps: internalProps, startTextFieldProps, endTextFieldProps, unstableStartFieldRef, unstableEndFieldRef }); const startDateProps = convertFieldResponseIntoMuiTextFieldProps(fieldResponse.startDate); const endDateProps = convertFieldResponseIntoMuiTextFieldProps(fieldResponse.endDate); return /*#__PURE__*/_jsxs(Root, _extends({}, rootProps, { children: [/*#__PURE__*/_jsx(TextField, _extends({ fullWidth: true }, startDateProps)), /*#__PURE__*/_jsx(Separator, _extends({}, separatorProps)), /*#__PURE__*/_jsx(TextField, _extends({ fullWidth: true }, endDateProps))] })); }); process.env.NODE_ENV !== "production" ? MultiInputDateTimeRangeField.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "pnpm proptypes" | // ---------------------------------------------------------------------- /** * 12h/24h view for hour selection clock. * @default utils.is12HourCycleInCurrentLocale() */ ampm: PropTypes.bool, /** * If `true`, the `input` element is focused during the first mount. */ autoFocus: PropTypes.bool, /** * Override or extend the styles applied to the component. */ classes: PropTypes.object, className: PropTypes.string, component: PropTypes.elementType, /** * String displayed between the start and the end dates. * @default "–" */ dateSeparator: PropTypes.string, /** * The default value. Use when the component is not controlled. */ defaultValue: PropTypes.arrayOf(PropTypes.object), /** * Defines the `flex-direction` style property. * It is applied for all screen sizes. * @default 'column' */ direction: PropTypes.oneOfType([PropTypes.oneOf(['column-reverse', 'column', 'row-reverse', 'row']), PropTypes.arrayOf(PropTypes.oneOf(['column-reverse', 'column', 'row-reverse', 'row'])), PropTypes.object]), /** * If `true`, the component is disabled. * @default false */ disabled: PropTypes.bool, /** * If `true`, disable values after the current date for date components, time for time components and both for date time components. * @default false */ disableFuture: PropTypes.bool, /** * Do not ignore date part when validating min/max time. * @default false */ disableIgnoringDatePartForTimeValidation: PropTypes.bool, /** * If `true`, disable values before the current date for date components, time for time components and both for date time components. * @default false */ disablePast: PropTypes.bool, /** * Add an element between each child. */ divider: PropTypes.node, /** * @default false */ enableAccessibleFieldDOMStructure: PropTypes.bool, /** * Format of the date when rendered in the input(s). */ format: PropTypes.string, /** * Density of the format when rendered in the input. * Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character. * @default "dense" */ formatDensity: PropTypes.oneOf(['dense', 'spacious']), /** * Maximal selectable date. */ maxDate: PropTypes.object, /** * Maximal selectable moment of time with binding to date, to set max time in each day use `maxTime`. */ maxDateTime: PropTypes.object, /** * Maximal selectable time. * The date part of the object will be ignored unless `props.disableIgnoringDatePartForTimeValidation === true`. */ maxTime: PropTypes.object, /** * Minimal selectable date. */ minDate: PropTypes.object, /** * Minimal selectable moment of time with binding to date, to set min time in each day use `minTime`. */ minDateTime: PropTypes.object, /** * Minimal selectable time. * The date part of the object will be ignored unless `props.disableIgnoringDatePartForTimeValidation === true`. */ minTime: PropTypes.object, /** * Step over minutes. * @default 1 */ minutesStep: PropTypes.number, /** * Callback fired when the value changes. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The new value. * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value. */ onChange: PropTypes.func, /** * Callback fired when the error associated to the current value changes. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TError} error The new error. * @param {TValue} value The value associated to the error. */ onError: PropTypes.func, /** * Callback fired when the selected sections change. * @param {FieldSelectedSections} newValue The new selected sections. */ onSelectedSectionsChange: PropTypes.func, /** * It prevents the user from changing the value of the field * (not from interacting with the field). * @default false */ readOnly: PropTypes.bool, /** * The date used to generate a part of the new value that is not present in the format when both `value` and `defaultValue` are empty. * For example, on time fields it will be used to determine the date to set. * @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used. */ referenceDate: PropTypes.object, /** * The currently selected sections. * This prop accepts four formats: * 1. If a number is provided, the section at this index will be selected. * 2. If a string of type `FieldSectionType` is provided, the first section with that name will be selected. * 3. If `"all"` is provided, all the sections will be selected. * 4. If `null` is provided, no section will be selected. * If not provided, the selected sections will be handled internally. */ selectedSections: PropTypes.oneOfType([PropTypes.oneOf(['all', 'day', 'empty', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'weekDay', 'year']), PropTypes.number]), /** * Disable specific date. * * Warning: This function can be called multiple times (for example when rendering date calendar, checking if focus can be moved to a certain date, etc.). Expensive computations can impact performance. * * @template TDate * @param {TDate} day The date to test. * @param {string} position The date to test, 'start' or 'end'. * @returns {boolean} Returns `true` if the date should be disabled. */ shouldDisableDate: PropTypes.func, /** * Disable specific time. * @template TDate * @param {TDate} value The value to check. * @param {TimeView} view The clock type of the timeValue. * @returns {boolean} If `true` the time will be disabled. */ shouldDisableTime: PropTypes.func, /** * If `true`, the format will respect the leading zeroes (e.g: on dayjs, the format `M/D/YYYY` will render `8/16/2018`) * If `false`, the format will always add leading zeroes (e.g: on dayjs, the format `M/D/YYYY` will render `08/16/2018`) * * Warning n°1: Luxon is not able to respect the leading zeroes when using macro tokens (e.g: "DD"), so `shouldRespectLeadingZeros={true}` might lead to inconsistencies when using `AdapterLuxon`. * * Warning n°2: When `shouldRespectLeadingZeros={true}`, the field will add an invisible character on the sections containing a single digit to make sure `onChange` is fired. * If you need to get the clean value from the input, you can remove this character using `input.value.replace(/\u200e/g, '')`. * * Warning n°3: When used in strict mode, dayjs and moment require to respect the leading zeros. * This mean that when using `shouldRespectLeadingZeros={false}`, if you retrieve the value directly from the input (not listening to `onChange`) and your format contains tokens without leading zeros, the value will not be parsed by your library. * * @default false */ shouldRespectLeadingZeros: PropTypes.bool, /** * The props used for each component slot. * @default {} */ slotProps: PropTypes.object, /** * Overridable component slots. * @default {} */ slots: PropTypes.object, /** * Defines the space between immediate children. * @default 0 */ spacing: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]), style: PropTypes.object, /** * The system prop, which 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]), /** * Choose which timezone to use for the value. * Example: "default", "system", "UTC", "America/New_York". * If you pass values from other timezones to some props, they will be converted to this timezone before being used. * @see See the {@link https://mui.com/x/react-date-pickers/timezone/ timezones documentation} for more details. * @default The timezone of the `value` or `defaultValue` prop is defined, 'default' otherwise. */ timezone: PropTypes.string, unstableEndFieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), unstableStartFieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), /** * If `true`, the CSS flexbox `gap` is used instead of applying `margin` to children. * * While CSS `gap` removes the [known limitations](https://mui.com/joy-ui/react-stack/#limitations), * it is not fully supported in some browsers. We recommend checking https://caniuse.com/?search=flex%20gap before using this flag. * * To enable this flag globally, follow the [theme's default props](https://mui.com/material-ui/customization/theme-components/#default-props) configuration. * @default false */ useFlexGap: PropTypes.bool, /** * The selected value. * Used when the component is controlled. */ value: PropTypes.arrayOf(PropTypes.object) } : void 0; export { MultiInputDateTimeRangeField };