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

33 lines (32 loc) 1.71 kB
import { __assign, __rest } from "tslib"; import clsx from 'clsx'; import React, { useRef } from 'react'; import { getBaseProps } from '../internal/base-component'; import { useFormFieldContext } from '../internal/context/form-field-context'; import useForwardFocus from '../internal/hooks/forward-focus'; import MaskedInput from '../internal/components/masked-input'; import { useTelemetry } from '../internal/hooks/use-telemetry'; import styles from './styles.css.js'; var getMaskArgs = function (format, use24Hour) { var segments = [ use24Hour ? { min: 0, max: 23, length: 2 } : { min: 1, max: 12, length: 2 }, { min: 0, max: 59, length: 2 }, { min: 0, max: 59, length: 2 } ]; return { separator: ':', segments: segments.slice(0, format.split(':').length) }; }; var TimeInput = React.forwardRef(function (_a, ref) { var _b = _a.format, format = _b === void 0 ? 'hh:mm:ss' : _b, _c = _a.use24Hour, use24Hour = _c === void 0 ? true : _c, _d = _a.autoComplete, autoComplete = _d === void 0 ? true : _d, rest = __rest(_a, ["format", "use24Hour", "autoComplete"]); useTelemetry('TimeInput'); var baseProps = getBaseProps(rest); var formFieldContext = useFormFieldContext(rest); var inputRef = useRef(null); useForwardFocus(ref, inputRef); var inputProps = __assign(__assign(__assign({}, baseProps), formFieldContext), rest); var maskArgs = getMaskArgs(format, use24Hour); return (React.createElement(MaskedInput, __assign({}, inputProps, { ref: inputRef, className: clsx(styles.root, baseProps.className), autoComplete: autoComplete, disableBrowserAutocorrect: true, mask: maskArgs }))); }); export default TimeInput;