UNPKG

@talend/react-forms

Version:

React forms library based on json schema form.

100 lines 2.68 kB
import { useState } from 'react'; import PropTypes from 'prop-types'; import FieldTemplate from '../FieldTemplate'; import { generateDescriptionId, generateErrorId } from '../../Message/generateId'; import { InputTimePicker } from "@talend/react-components"; import { jsx as _jsx } from "react/jsx-runtime"; function TimeWidget({ errorMessage, id, isValid, options = {}, onChange, onFinish, schema, value, valueIsUpdating }) { const descriptionId = generateDescriptionId(id); const errorId = generateErrorId(id); const [state, setState] = useState({ errorMessage: '' }); function onBlur(event) { onFinish(event, { schema }); } function onTimeChange(event, { errorMessage: nextErrorMessage, textInput }) { setState({ errorMessage: nextErrorMessage }); const payload = { schema, value: textInput }; onChange(event, payload); if (!nextErrorMessage) { onFinish(event, payload); } } return /*#__PURE__*/_jsx(FieldTemplate, { description: schema.description, descriptionId: descriptionId, errorId: errorId, errorMessage: state.errorMessage || errorMessage, id: id, isValid: isValid && !state.errorMessage, label: schema.title, labelProps: schema.labelProps, required: schema.required, valueIsUpdating: valueIsUpdating, children: /*#__PURE__*/_jsx(InputTimePicker, { id: id // eslint-disable-next-line jsx-a11y/no-autofocus , autoFocus: schema.autoFocus, disabled: schema.disabled || valueIsUpdating, readOnly: schema.readOnly, value: value, useSeconds: options.useSeconds, onBlur: onBlur, onChange: onTimeChange }) }); } TimeWidget.displayName = 'TimeWidget'; if (process.env.NODE_ENV !== 'production') { TimeWidget.propTypes = { id: PropTypes.string, isValid: PropTypes.bool, errorMessage: PropTypes.string, onChange: PropTypes.func.isRequired, onFinish: PropTypes.func.isRequired, options: PropTypes.shape({ dateFormat: PropTypes.string, useUTC: PropTypes.bool }), schema: PropTypes.shape({ autoFocus: PropTypes.bool, description: PropTypes.string, disabled: PropTypes.bool, format: PropTypes.string, placeholder: PropTypes.string, readOnly: PropTypes.bool, required: PropTypes.bool, title: PropTypes.string, labelProps: PropTypes.object, schema: PropTypes.shape({ type: PropTypes.string }) }), value: PropTypes.string, valueIsUpdating: PropTypes.bool }; } export default TimeWidget; //# sourceMappingURL=Time.component.js.map