UNPKG

@financial-times/n-conversion-forms

Version:

Containing jsx components and styles for forms included on Accounts and Acquisition apps (next-signup, next-profile, next-retention, etc).

81 lines (75 loc) 1.87 kB
import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; export function Industry({ value, isDisabled = false, hasError = false, fieldId = 'industryField', selectId = 'industry', selectName = 'industry', options = [], fieldLabel = 'In which industry do you work?', isRequired = true, }) { const inpiutWrapperClassName = classNames([ 'o-forms-input', 'o-forms-input--select', { 'o-forms-input--invalid': hasError }, ]); const fieldTitleClassName = classNames([ 'o-forms-title', { 'o-forms-field--optional': !isRequired }, ]); options.sort((a, b) => a.description.localeCompare(b.description)); return ( <label id={fieldId} className="o-forms-field ncf__validation-error" htmlFor={selectId} > <span className={fieldTitleClassName}> <span className="o-forms-title__main">{fieldLabel}</span> </span> <span className={inpiutWrapperClassName}> <select id={selectId} name={selectName} data-trackable="industry" aria-required={isRequired} required={isRequired} disabled={isDisabled} defaultValue={value} > <option value="">Please select an industry</option> {options.map(({ code, description }) => { return ( <option key={code} value={code}> {description} </option> ); })} </select> <span className="o-forms-input__error"> Please select your company’s industry </span> </span> </label> ); } Industry.propTypes = { value: PropTypes.string, isDisabled: PropTypes.bool, hasError: PropTypes.bool, fieldId: PropTypes.string, selectId: PropTypes.string, selectName: PropTypes.string, options: PropTypes.arrayOf( PropTypes.shape({ code: PropTypes.string, description: PropTypes.string, }) ), fieldLabel: PropTypes.string, isRequired: PropTypes.bool, };