UNPKG

@astarte-platform/react-bootstrap

Version:

React Bootstrap theme, fields and widgets for react-jsonschema-form, powered by react-bootstrap, this is a package from a fork of official project

19 lines 1.79 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import Form from 'react-bootstrap/Form'; import { ariaDescribedByIds, examplesId, getInputProps, } from '@rjsf/utils'; export default function BaseInputTemplate({ id, placeholder, required, readonly, disabled, type, value, onChange, onChangeOverride, onBlur, onFocus, autofocus, options, schema, rawErrors = [], children, extraProps, }) { const inputProps = { ...extraProps, ...getInputProps(schema, type, options), }; const _onChange = ({ target: { value } }) => onChange(value === '' ? options.emptyValue : value); const _onBlur = ({ target: { value } }) => onBlur(id, value); const _onFocus = ({ target: { value } }) => onFocus(id, value); // const classNames = [rawErrors.length > 0 ? "is-invalid" : "", type === 'file' ? 'custom-file-label': ""] return (_jsxs(_Fragment, { children: [_jsx(Form.Control, { id: id, name: id, placeholder: placeholder, autoFocus: autofocus, required: required, disabled: disabled, readOnly: readonly, className: rawErrors.length > 0 ? 'is-invalid' : '', list: schema.examples ? examplesId(id) : undefined, ...inputProps, value: value || value === 0 ? value : '', onChange: onChangeOverride || _onChange, onBlur: _onBlur, onFocus: _onFocus, "aria-describedby": ariaDescribedByIds(id, !!schema.examples) }), children, Array.isArray(schema.examples) ? (_jsx("datalist", { id: examplesId(id), children: schema.examples .concat(schema.default && !schema.examples.includes(schema.default) ? [schema.default] : []) .map((example) => { return _jsx("option", { value: example }, example); }) })) : null] })); } //# sourceMappingURL=BaseInputTemplate.js.map