377 lines
15 KiB
JavaScript
377 lines
15 KiB
JavaScript
"use strict";
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.DateField = void 0;
|
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
var React = _interopRequireWildcard(require("react"));
|
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
var _TextField = _interopRequireDefault(require("@mui/material/TextField"));
|
|
var _styles = require("@mui/material/styles");
|
|
var _utils = require("@mui/base/utils");
|
|
var _utils2 = require("@mui/utils");
|
|
var _useDateField2 = require("./useDateField");
|
|
var _hooks = require("../hooks");
|
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
const _excluded = ["components", "componentsProps", "slots", "slotProps", "InputProps", "inputProps"],
|
|
_excluded2 = ["inputRef"],
|
|
_excluded3 = ["ref", "onPaste", "onKeyDown", "inputMode", "readOnly", "clearable", "onClear"];
|
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
/**
|
|
* Demos:
|
|
*
|
|
* - [DateField](http://mui.com/x/react-date-pickers/date-field/)
|
|
* - [Fields](https://mui.com/x/react-date-pickers/fields/)
|
|
*
|
|
* API:
|
|
*
|
|
* - [DateField API](https://mui.com/x/api/date-pickers/date-field/)
|
|
*/
|
|
const DateField = exports.DateField = /*#__PURE__*/React.forwardRef(function DateField(inProps, ref) {
|
|
const themeProps = (0, _styles.useThemeProps)({
|
|
props: inProps,
|
|
name: 'MuiDateField'
|
|
});
|
|
const {
|
|
components,
|
|
componentsProps,
|
|
slots,
|
|
slotProps,
|
|
InputProps,
|
|
inputProps
|
|
} = themeProps,
|
|
other = (0, _objectWithoutPropertiesLoose2.default)(themeProps, _excluded);
|
|
const ownerState = themeProps;
|
|
const TextField = slots?.textField ?? components?.TextField ?? _TextField.default;
|
|
const _useSlotProps = (0, _utils.useSlotProps)({
|
|
elementType: TextField,
|
|
externalSlotProps: slotProps?.textField ?? componentsProps?.textField,
|
|
externalForwardedProps: other,
|
|
ownerState
|
|
}),
|
|
{
|
|
inputRef: externalInputRef
|
|
} = _useSlotProps,
|
|
textFieldProps = (0, _objectWithoutPropertiesLoose2.default)(_useSlotProps, _excluded2);
|
|
|
|
// TODO: Remove when mui/material-ui#35088 will be merged
|
|
textFieldProps.inputProps = (0, _extends2.default)({}, inputProps, textFieldProps.inputProps);
|
|
textFieldProps.InputProps = (0, _extends2.default)({}, InputProps, textFieldProps.InputProps);
|
|
const _useDateField = (0, _useDateField2.useDateField)({
|
|
props: textFieldProps,
|
|
inputRef: externalInputRef
|
|
}),
|
|
{
|
|
ref: inputRef,
|
|
onPaste,
|
|
onKeyDown,
|
|
inputMode,
|
|
readOnly,
|
|
clearable,
|
|
onClear
|
|
} = _useDateField,
|
|
fieldProps = (0, _objectWithoutPropertiesLoose2.default)(_useDateField, _excluded3);
|
|
const {
|
|
InputProps: ProcessedInputProps,
|
|
fieldProps: processedFieldProps
|
|
} = (0, _hooks.useClearableField)({
|
|
onClear,
|
|
clearable,
|
|
fieldProps,
|
|
InputProps: fieldProps.InputProps,
|
|
slots,
|
|
slotProps,
|
|
components,
|
|
componentsProps
|
|
});
|
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(TextField, (0, _extends2.default)({
|
|
ref: ref
|
|
}, processedFieldProps, {
|
|
InputProps: (0, _extends2.default)({}, ProcessedInputProps, {
|
|
readOnly
|
|
}),
|
|
inputProps: (0, _extends2.default)({}, fieldProps.inputProps, {
|
|
inputMode,
|
|
onPaste,
|
|
onKeyDown,
|
|
ref: inputRef
|
|
})
|
|
}));
|
|
});
|
|
process.env.NODE_ENV !== "production" ? DateField.propTypes = {
|
|
// ----------------------------- Warning --------------------------------
|
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
// ----------------------------------------------------------------------
|
|
/**
|
|
* If `true`, the `input` element is focused during the first mount.
|
|
* @default false
|
|
*/
|
|
autoFocus: _propTypes.default.bool,
|
|
className: _propTypes.default.string,
|
|
/**
|
|
* If `true`, a clear button will be shown in the field allowing value clearing.
|
|
* @default false
|
|
*/
|
|
clearable: _propTypes.default.bool,
|
|
/**
|
|
* The color of the component.
|
|
* It supports both default and custom theme colors, which can be added as shown in the
|
|
* [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
|
|
* @default 'primary'
|
|
*/
|
|
color: _propTypes.default.oneOf(['error', 'info', 'primary', 'secondary', 'success', 'warning']),
|
|
component: _propTypes.default.elementType,
|
|
/**
|
|
* Overridable components.
|
|
* @default {}
|
|
* @deprecated Please use `slots`.
|
|
*/
|
|
components: _propTypes.default.object,
|
|
/**
|
|
* The props used for each component slot.
|
|
* @default {}
|
|
* @deprecated Please use `slotProps`.
|
|
*/
|
|
componentsProps: _propTypes.default.object,
|
|
/**
|
|
* The default value. Use when the component is not controlled.
|
|
*/
|
|
defaultValue: _propTypes.default.any,
|
|
/**
|
|
* If `true`, the component is disabled.
|
|
* @default false
|
|
*/
|
|
disabled: _propTypes.default.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.default.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.default.bool,
|
|
/**
|
|
* If `true`, the component is displayed in focused state.
|
|
*/
|
|
focused: _propTypes.default.bool,
|
|
/**
|
|
* Format of the date when rendered in the input(s).
|
|
*/
|
|
format: _propTypes.default.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.default.oneOf(['dense', 'spacious']),
|
|
/**
|
|
* Props applied to the [`FormHelperText`](/material-ui/api/form-helper-text/) element.
|
|
*/
|
|
FormHelperTextProps: _propTypes.default.object,
|
|
/**
|
|
* If `true`, the input will take up the full width of its container.
|
|
* @default false
|
|
*/
|
|
fullWidth: _propTypes.default.bool,
|
|
/**
|
|
* The helper text content.
|
|
*/
|
|
helperText: _propTypes.default.node,
|
|
/**
|
|
* If `true`, the label is hidden.
|
|
* This is used to increase density for a `FilledInput`.
|
|
* Be sure to add `aria-label` to the `input` element.
|
|
* @default false
|
|
*/
|
|
hiddenLabel: _propTypes.default.bool,
|
|
/**
|
|
* The id of the `input` element.
|
|
* Use this prop to make `label` and `helperText` accessible for screen readers.
|
|
*/
|
|
id: _propTypes.default.string,
|
|
/**
|
|
* Props applied to the [`InputLabel`](/material-ui/api/input-label/) element.
|
|
* Pointer events like `onClick` are enabled if and only if `shrink` is `true`.
|
|
*/
|
|
InputLabelProps: _propTypes.default.object,
|
|
/**
|
|
* [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
|
|
*/
|
|
inputProps: _propTypes.default.object,
|
|
/**
|
|
* Props applied to the Input element.
|
|
* It will be a [`FilledInput`](/material-ui/api/filled-input/),
|
|
* [`OutlinedInput`](/material-ui/api/outlined-input/) or [`Input`](/material-ui/api/input/)
|
|
* component depending on the `variant` prop value.
|
|
*/
|
|
InputProps: _propTypes.default.object,
|
|
/**
|
|
* Pass a ref to the `input` element.
|
|
*/
|
|
inputRef: _utils2.refType,
|
|
/**
|
|
* The label content.
|
|
*/
|
|
label: _propTypes.default.node,
|
|
/**
|
|
* If `dense` or `normal`, will adjust vertical spacing of this and contained components.
|
|
* @default 'none'
|
|
*/
|
|
margin: _propTypes.default.oneOf(['dense', 'none', 'normal']),
|
|
/**
|
|
* Maximal selectable date.
|
|
*/
|
|
maxDate: _propTypes.default.any,
|
|
/**
|
|
* Minimal selectable date.
|
|
*/
|
|
minDate: _propTypes.default.any,
|
|
/**
|
|
* Name attribute of the `input` element.
|
|
*/
|
|
name: _propTypes.default.string,
|
|
onBlur: _propTypes.default.func,
|
|
/**
|
|
* 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.default.func,
|
|
/**
|
|
* Callback fired when the clear button is clicked.
|
|
*/
|
|
onClear: _propTypes.default.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.default.func,
|
|
onFocus: _propTypes.default.func,
|
|
/**
|
|
* Callback fired when the selected sections change.
|
|
* @param {FieldSelectedSections} newValue The new selected sections.
|
|
*/
|
|
onSelectedSectionsChange: _propTypes.default.func,
|
|
/**
|
|
* It prevents the user from changing the value of the field
|
|
* (not from interacting with the field).
|
|
* @default false
|
|
*/
|
|
readOnly: _propTypes.default.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.default.any,
|
|
/**
|
|
* If `true`, the label is displayed as required and the `input` element is required.
|
|
* @default false
|
|
*/
|
|
required: _propTypes.default.bool,
|
|
/**
|
|
* The currently selected sections.
|
|
* This prop accept four formats:
|
|
* 1. If a number is provided, the section at this index will be selected.
|
|
* 2. If an object with a `startIndex` and `endIndex` properties are provided, the sections between those two indexes will be selected.
|
|
* 3. If a string of type `FieldSectionType` is provided, the first section with that name 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.default.oneOfType([_propTypes.default.oneOf(['all', 'day', 'hours', 'meridiem', 'minutes', 'month', 'seconds', 'weekDay', 'year']), _propTypes.default.number, _propTypes.default.shape({
|
|
endIndex: _propTypes.default.number.isRequired,
|
|
startIndex: _propTypes.default.number.isRequired
|
|
})]),
|
|
/**
|
|
* Disable specific date.
|
|
*
|
|
* Warning: This function can be called multiple times (e.g. 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.
|
|
* @returns {boolean} If `true` the date will be disabled.
|
|
*/
|
|
shouldDisableDate: _propTypes.default.func,
|
|
/**
|
|
* Disable specific month.
|
|
* @template TDate
|
|
* @param {TDate} month The month to test.
|
|
* @returns {boolean} If `true`, the month will be disabled.
|
|
*/
|
|
shouldDisableMonth: _propTypes.default.func,
|
|
/**
|
|
* Disable specific year.
|
|
* @template TDate
|
|
* @param {TDate} year The year to test.
|
|
* @returns {boolean} If `true`, the year will be disabled.
|
|
*/
|
|
shouldDisableYear: _propTypes.default.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.default.bool,
|
|
/**
|
|
* The size of the component.
|
|
*/
|
|
size: _propTypes.default.oneOf(['medium', 'small']),
|
|
/**
|
|
* The props used for each component slot.
|
|
* @default {}
|
|
*/
|
|
slotProps: _propTypes.default.object,
|
|
/**
|
|
* Overridable component slots.
|
|
* @default {}
|
|
*/
|
|
slots: _propTypes.default.object,
|
|
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]),
|
|
/**
|
|
* 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 documention} for more details.
|
|
* @default The timezone of the `value` or `defaultValue` prop is defined, 'default' otherwise.
|
|
*/
|
|
timezone: _propTypes.default.string,
|
|
/**
|
|
* The ref object used to imperatively interact with the field.
|
|
*/
|
|
unstableFieldRef: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]),
|
|
/**
|
|
* The selected value.
|
|
* Used when the component is controlled.
|
|
*/
|
|
value: _propTypes.default.any,
|
|
/**
|
|
* The variant to use.
|
|
* @default 'outlined'
|
|
*/
|
|
variant: _propTypes.default.oneOf(['filled', 'outlined', 'standard'])
|
|
} : void 0; |