UNPKG

@talend/react-forms

Version:

React forms library based on json schema form.

71 lines 2.4 kB
import PropTypes from 'prop-types'; import { Form, StackVertical } from '@talend/design-system'; import { StackHorizontal } from '@talend/design-system'; import Message from '../../Message'; import { getLabelProps } from '../../utils/labels'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; function FieldTemplate(props) { const title = /*#__PURE__*/_jsx(Form.Label, { htmlFor: props.id, ...getLabelProps(props.label, props.labelProps, props.hint, props.required), required: props.required }); const labelAfter = props.hint ? false : props.labelAfter; const Stack = props.inline ? StackHorizontal : StackVertical; const stackProps = props.inline ? { gap: 'S', align: 'center' } : { gap: 'XXS', align: 'stretch', justify: 'start', height: '100%', noShrink: true }; return /*#__PURE__*/_jsx("div", { className: props.className, "aria-busy": props.valueIsUpdating, children: /*#__PURE__*/_jsxs(Stack, { ...stackProps, children: [props.label && !labelAfter && title, props.children, props.label && labelAfter && title, /*#__PURE__*/_jsx(Message, { description: props.description, descriptionId: props.descriptionId, errorId: props.errorId, errorMessage: props.errorMessage, isValid: props.isValid })] }) }); } if (process.env.NODE_ENV !== 'production') { FieldTemplate.propTypes = { children: PropTypes.node, hint: PropTypes.shape({ icon: PropTypes.string, overlayComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.string]).isRequired, overlayPlacement: PropTypes.string, overlayIsFixed: PropTypes.bool, 'data-test': PropTypes.string, 'icon-data-test': PropTypes.string }), className: PropTypes.string, description: PropTypes.string, descriptionId: PropTypes.string.isRequired, errorId: PropTypes.string.isRequired, errorMessage: PropTypes.string, id: PropTypes.string, isValid: PropTypes.bool, label: PropTypes.string, labelProps: PropTypes.object, labelAfter: PropTypes.bool, required: PropTypes.bool, valueIsUpdating: PropTypes.bool, inline: PropTypes.bool }; } FieldTemplate.defaultProps = { isValid: true }; FieldTemplate.displayName = 'FieldTemplate'; export default FieldTemplate; //# sourceMappingURL=FieldTemplate.component.js.map