Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/forms / build / dist / src / new-forms / plugins / AddressPlugins / ProvincePlugin.js
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = require("react");
const exotic_1 = require("exotic");
const mobx_react_1 = require("xmobx/mobx-react");
const validators_1 = require("../../../validators");
const ObserverInput_1 = require("../../inputs/ObserverInput");
function fromCountryToLabel(country) {
    switch (country) {
        case 'IN':
        case 'INDIA':
        case 'CA':
        case 'CANADA':
            return 'Province';
        case 'US':
        case 'USA':
            return 'State';
        default:
            return 'State / Province';
    }
}
/**
 * @see https://en.wikipedia.org/wiki/List_of_long_place_names
 */
let ProvincePlugin = class ProvincePlugin extends React.Component {
    static isSatisfiedByProps(props) {
        return ['province', 'state', 'region'].includes(props.type);
    }
    /** @description this dynamically changes province based on country */
    get label() {
        const formState = this.props.state.formState;
        // minor perf here on dynamic forms is fine
        const countryState = exotic_1.isObj(formState) &&
            formState.get(inputState => inputState.type === 'country');
        const country = exotic_1.isObj(countryState) && countryState.value;
        const label = fromCountryToLabel(country);
        return label;
    }
    render() {
        return (React.createElement(ObserverInput_1.ObserverInput, Object.assign({ label: this.label, "data-qa": "qa-region", type: "text", minLength: 2, maxLength: 24, required: true, placeholder: "California", 
            // pattern="[A-Za-z0-9\.\-]+"
            autoComplete: "shipping region" }, this.props)));
    }
};
ProvincePlugin.defaultState = (inputState) => {
    return {
        tooltip: '☑',
        validator: (value) => validators_1.isValidProvince(value) || validators_1.errorMessageFor('postalCode'),
    };
};
ProvincePlugin = tslib_1.__decorate([
    mobx_react_1.observer
], ProvincePlugin);
exports.ProvincePlugin = ProvincePlugin;
exports.default = ProvincePlugin;
//# sourceMappingURL=ProvincePlugin.js.map