/* * Copyright (C) 2019-2022 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React, { forwardRef } from "react"; import PropTypes from "prop-types"; import { useUID } from "react-uid"; /** Base bootstrap input component. */ const Input = forwardRef( ( { type, label, helpText, error, className, children, labelClassName, groupClassName, ...props }, ref ) => { const uid = useUID(); const inputClassName = `${className || ""} ${ error ? "is-invalid" : "" }`.trim(); return (
{children}
{error &&
{error}
} {helpText && (
{helpText}
)}
); } ); Input.displayName = "Input"; Input.propTypes = { type: PropTypes.string.isRequired, label: PropTypes.string.isRequired, helpText: PropTypes.string, error: PropTypes.string, className: PropTypes.string, children: PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.node), PropTypes.node, ]), labelClassName: PropTypes.string, groupClassName: PropTypes.string, }; export default Input;