UNPKG

@awsui/components-react

Version:

AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A

31 lines (30 loc) 1.46 kB
import { __assign, __rest } from "tslib"; import React from 'react'; import { getBaseProps } from '../../base-component'; import { useFormFieldContext } from '../../context/form-field-context'; import useForwardFocus from '../../hooks/forward-focus'; import MaskedInput from '../masked-input'; import { daysInMonth, parseDate, displayToIso } from './utils/date'; function daysMax(value) { var baseDate = displayToIso(value).substring(0, 7); return daysInMonth(parseDate(baseDate)); } var maskArgs = { separator: '/', inputSeparators: ['-', '.', ' '], segments: [ { min: 0, max: 9999, "default": 2000, length: 4 }, { min: 1, max: 12, length: 2 }, { min: 1, max: daysMax, length: 2 } ] }; var DateInput = React.forwardRef(function (_a, ref) { var disableAutocompleteOnBlur = _a.disableAutocompleteOnBlur, props = __rest(_a, ["disableAutocompleteOnBlur"]); var baseProps = getBaseProps(props); var formFieldContext = useFormFieldContext(props); var inputRef = React.useRef(null); useForwardFocus(ref, inputRef); var inputProps = __assign(__assign(__assign({}, baseProps), formFieldContext), props); return (React.createElement(MaskedInput, __assign({}, inputProps, { ref: inputRef, className: baseProps.className, rightIcon: "calendar", disableAutocompleteOnBlur: disableAutocompleteOnBlur, disableBrowserAutocorrect: true, mask: maskArgs, autofix: true }))); }); export default DateInput;