/* eslint-disable wpcalypso/jsx-classname-namespace */ import { Card, FormInputValidation, FormLabel } from '@automattic/components'; import { ToggleControl } from '@wordpress/components'; import PropTypes from 'prop-types'; import { PureComponent } from 'react'; import { connect } from 'react-redux'; import QuerySmsCountries from 'calypso/components/data/query-countries/sms'; import FormButton from 'calypso/components/forms/form-button'; import FormButtonsBar from 'calypso/components/forms/form-buttons-bar'; import FormCheckbox from 'calypso/components/forms/form-checkbox'; import FormCountrySelect from 'calypso/components/forms/form-country-select'; import FormCurrencyInput from 'calypso/components/forms/form-currency-input'; import FormFieldset from 'calypso/components/forms/form-fieldset'; import FormLegend from 'calypso/components/forms/form-legend'; import FormPasswordInput from 'calypso/components/forms/form-password-input'; import FormPhoneInput from 'calypso/components/forms/form-phone-input'; import FormRadio from 'calypso/components/forms/form-radio'; import FormRadioWithThumbnail from 'calypso/components/forms/form-radio-with-thumbnail'; import FormRadiosBarExample from 'calypso/components/forms/form-radios-bar/docs/example'; import FormSectionHeading from 'calypso/components/forms/form-section-heading'; import FormSelect from 'calypso/components/forms/form-select'; import FormSettingExplanation from 'calypso/components/forms/form-setting-explanation'; import FormTelInput from 'calypso/components/forms/form-tel-input'; import FormTextInput from 'calypso/components/forms/form-text-input'; import FormTextInputWithAction from 'calypso/components/forms/form-text-input-with-action'; import FormTextInputWithAffixes from 'calypso/components/forms/form-text-input-with-affixes'; import FormTextarea from 'calypso/components/forms/form-textarea'; import FormStateSelector from 'calypso/components/forms/us-state-selector'; import PhoneInput from 'calypso/components/phone-input'; import getCountries from 'calypso/state/selectors/get-countries'; export const CURRENCIES = { ALL: { symbol: 'Lek', grouping: '.', decimal: ',', precision: 2, }, BDT: { symbol: '৳', grouping: ',', decimal: '.', precision: 0, }, GIP: { symbol: '£', grouping: ',', decimal: '.', precision: 2, }, KGS: { symbol: 'сом', grouping: ' ', decimal: '-', precision: 2, }, MOP: { symbol: 'MOP$', grouping: ',', decimal: '.', precision: 2, }, UZS: { symbol: 'сўм', grouping: ' ', decimal: ',', precision: 2, }, VEB: { symbol: 'Bs.', grouping: ',', decimal: '.', precision: 2, }, VEF: { symbol: 'Bs. F.', grouping: '.', decimal: ',', precision: 2, }, VND: { symbol: '₫', grouping: '.', decimal: ',', precision: 1, }, VUV: { symbol: 'VT', grouping: ',', decimal: '.', precision: 0, }, WST: { symbol: 'WS$', grouping: ',', decimal: '.', precision: 2, }, XAF: { symbol: 'F', grouping: ',', decimal: '.', precision: 2, }, XCD: { symbol: '$', grouping: ',', decimal: '.', precision: 2, }, XOF: { symbol: 'F', grouping: ' ', decimal: ',', precision: 2, }, }; const currencyList = Object.entries( CURRENCIES ).map( ( [ code ] ) => ( { code } ) ); const visualCurrencyList = Object.entries( CURRENCIES ).map( ( [ code, { symbol } ] ) => ( { code, label: `${ code } ${ symbol }`, } ) ); class FormFields extends PureComponent { static propTypes = { countriesList: PropTypes.array.isRequired, }; state = { checkedRadio: 'first', toggled: false, phoneInput: { countryCode: 'US', value: '' }, currencyInput: { currency: 'USD', value: '' }, }; handleRadioChange = ( event ) => { this.setState( { checkedRadio: event.currentTarget.value } ); }; handleToggle = () => { this.setState( { toggled: ! this.state.toggled } ); }; handleAction = () => { window.alert( 'Thank you.' ); }; handlePhoneInputChange = ( data ) => { this.setState( { phoneInput: data } ); }; handleCurrencyChange = ( event ) => { const { value: currency } = event.currentTarget; this.setState( ( state ) => ( { currencyInput: { ...state.currencyInput, currency }, } ) ); }; handlePriceChange = ( event ) => { const { value } = event.currentTarget; this.setState( ( state ) => ( { currencyInput: { ...state.currencyInput, value }, } ) ); }; render() { return (

The form fields components act as wrapper components to aid in componentizing CSS. Here is an example of all of the form fields components and their expected markup.

The following form fields components are wrapped in Card components to demonstrate the FormSectionHeading component.

Form Section Heading Form Checkbox Email me when someone Likes one of my comments. Disabled Form Text Input Form Text Input This is an explanation of FormTextInput. Form Text Input Form Text Input Form Text Input With Action Action becomes avaliable when filled. Can be triggered by clicking button or pressing enter. Form Text Input With Affixes Form Select
Form Password Input Form Toggle (uses Gutenberg's ToggleControl component)


Form Button
Form Section Heading Form Country Select Form US State Select Form Radios Form Radio With Thumbnail
Form Radios Bar
Form Tel Input Form Tel Input Form Tel Input Form Phone Input Form Media Phone Input Form Currency Input Form Currency Input Form Currency Input Editable Form Currency Input Editable Form Currency Input (customized list) Form Textarea Form Textarea Form Textarea Form Button Secondary Form Button
); } } const ConnectedFormFields = connect( ( state ) => ( { countriesList: getCountries( state, 'sms' ), } ) )( FormFields ); ConnectedFormFields.displayName = 'FormFields'; export default ConnectedFormFields;