@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).
33 lines (28 loc) • 1.26 kB
JavaScript
const FormElement = require('./form-element');
const regionConfigByCountry = require('./region-config-by-country');
/**
* Class representing a region selector form element.
* @extends FormElement
*/
class RegionSelector extends FormElement {
/**
* Create a region selector.
*
* @param {Document} document - The document object.
* @param {Object} [options] - Options for the region selector.
* @param {string} [options.country='USA'] - The country code (e.g., 'USA', 'CAN', 'IND'). Defaults to 'USA'.
* @param {string} [options.regionType] - The type of region (e.g., 'state', 'province'). Defaults to the default region type for the country.
* @param {string} [options.fieldId] - The ID of the field element. Defaults to the default field ID for the region type.
*
* @note Ensure that the `country`, `regionType` and `fieldId` used here matches what is used in the props for the `RegionSelector` component.
*/
constructor(document, { country = 'USA', regionType, fieldId } = {}) {
const defaultRegionType =
regionType || regionConfigByCountry[country].defaultRegionType;
const selector = fieldId
? `.ncf #${fieldId}`
: `.ncf #${defaultRegionType}Field`;
super(document, selector);
}
}
module.exports = RegionSelector;