|
| 1 | +import PropTypes from 'prop-types' |
| 2 | +import {getGfFieldId, getGfHiddenClassName} from '@/functions/gravityForms' |
| 3 | +import {Field} from 'formik' |
| 4 | +import InputError from '@/components/atoms/Inputs/InputError' |
| 5 | +import styles from '@/components/atoms/Inputs/Text/Text.module.css' |
| 6 | +import cn from 'classnames' |
| 7 | + |
| 8 | +/** |
| 9 | + * Render GravityForms Textarea field component. |
| 10 | + * |
| 11 | + * @param {object} props GravityForm Select field as props. |
| 12 | + * @param {string} props.className GravityForm field wrapper class. |
| 13 | + * @param {string} props.description GravityForm field description. |
| 14 | + * @param {string|number} props.id GravityForm field id. |
| 15 | + * @param {boolean} props.isRequired GravityForm field is required. |
| 16 | + * @param {string} props.label GravityForm field label. |
| 17 | + * @param {boolean} props.visibility GravityForm visibility option. |
| 18 | + * @return {Element} The File component. |
| 19 | + */ |
| 20 | +export default function TextArea({ |
| 21 | + className, |
| 22 | + description, |
| 23 | + id, |
| 24 | + isRequired, |
| 25 | + label, |
| 26 | + visibility |
| 27 | +}) { |
| 28 | + const fieldId = getGfFieldId(id) |
| 29 | + const isHiddenClass = getGfHiddenClassName(visibility) |
| 30 | + const thisClassName = cn(className, isHiddenClass) |
| 31 | + |
| 32 | + return ( |
| 33 | + <div className={cn(styles.text, thisClassName)}> |
| 34 | + {label && ( |
| 35 | + <label htmlFor={id} required={isRequired}> |
| 36 | + {label} |
| 37 | + </label> |
| 38 | + )} |
| 39 | + <Field |
| 40 | + aria-required={isRequired} |
| 41 | + id={fieldId} |
| 42 | + name={fieldId} |
| 43 | + required={isRequired} |
| 44 | + as="textarea" |
| 45 | + style={{borderWidth: '1px'}} |
| 46 | + /> |
| 47 | + {description && <p>{description}</p>} |
| 48 | + <InputError name={id} /> |
| 49 | + </div> |
| 50 | + ) |
| 51 | +} |
| 52 | + |
| 53 | +TextArea.propTypes = { |
| 54 | + className: PropTypes.string, |
| 55 | + description: PropTypes.string, |
| 56 | + id: PropTypes.number.isRequired, |
| 57 | + isRequired: PropTypes.bool, |
| 58 | + label: PropTypes.string, |
| 59 | + selectChoices: PropTypes.arrayOf(PropTypes.object), |
| 60 | + visibility: PropTypes.string |
| 61 | +} |
0 commit comments