@internetarchive/donation-form 1.0.2 → 1.0.3-alpha-webdev7960.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -661
- package/README.md +115 -115
- package/dist/demo/braintree-endpoint-manager.js.map +1 -1
- package/dist/demo/demo-analytics-handler.js.map +1 -1
- package/dist/demo/submit-form-with.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/src/braintree-manager/braintree-interfaces.js.map +1 -1
- package/dist/src/braintree-manager/braintree-manager.js.map +1 -1
- package/dist/src/braintree-manager/payment-clients.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay-interface.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-datasource-delegate.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-datasource-interface.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-datasource.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-manager.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/credit-card/credit-card-interface.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/credit-card/credit-card.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/credit-card/hosted-field-configuration.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/credit-card/hosted-field-container.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/google-pay-interface.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/google-pay.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/paypal/paypal-button-datasource.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/paypal/paypal-interface.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/paypal/paypal.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/venmo-interface.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers/venmo.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers-interface.js.map +1 -1
- package/dist/src/braintree-manager/payment-providers.js.map +1 -1
- package/dist/src/donation-form-controller.js +123 -123
- package/dist/src/donation-form-controller.js.map +1 -1
- package/dist/src/donation-form-error.js.map +1 -1
- package/dist/src/donation-form.js +107 -107
- package/dist/src/donation-form.js.map +1 -1
- package/dist/src/form-elements/badged-input.js +47 -47
- package/dist/src/form-elements/badged-input.js.map +1 -1
- package/dist/src/form-elements/contact-form/autocomplete-field-options.js.map +1 -1
- package/dist/src/form-elements/contact-form/contact-form.js +157 -157
- package/dist/src/form-elements/contact-form/contact-form.js.map +1 -1
- package/dist/src/form-elements/contact-form/countries.js.map +1 -1
- package/dist/src/form-elements/header/donation-form-header.js +14 -14
- package/dist/src/form-elements/header/donation-form-header.js.map +1 -1
- package/dist/src/form-elements/header/donation-summary.js +15 -15
- package/dist/src/form-elements/header/donation-summary.js.map +1 -1
- package/dist/src/form-elements/payment-selector.js +164 -164
- package/dist/src/form-elements/payment-selector.js.map +1 -1
- package/dist/src/form-elements/total-amount.js +16 -16
- package/dist/src/form-elements/total-amount.js.map +1 -1
- package/dist/src/modals/confirm-donation-modal-content.js +51 -51
- package/dist/src/modals/confirm-donation-modal-content.js.map +1 -1
- package/dist/src/modals/error-modal-content.js +22 -22
- package/dist/src/modals/error-modal-content.js.map +1 -1
- package/dist/src/modals/upsell-modal-content.js +182 -182
- package/dist/src/modals/upsell-modal-content.js.map +1 -1
- package/dist/src/payment-flow-handlers/donation-flow-modal-manager.js +20 -20
- package/dist/src/payment-flow-handlers/donation-flow-modal-manager.js.map +1 -1
- package/dist/src/payment-flow-handlers/handlers/applepay-flow-handler.js.map +1 -1
- package/dist/src/payment-flow-handlers/handlers/creditcard-flow-handler.js.map +1 -1
- package/dist/src/payment-flow-handlers/handlers/googlepay-flow-handler.js.map +1 -1
- package/dist/src/payment-flow-handlers/handlers/paypal-flow-handler.js.map +1 -1
- package/dist/src/payment-flow-handlers/handlers/venmo-flow-handler.js.map +1 -1
- package/dist/src/payment-flow-handlers/handlers/venmo-restoration-state-handler.js.map +1 -1
- package/dist/src/payment-flow-handlers/payment-flow-handlers.js.map +1 -1
- package/dist/src/recaptcha-manager/recaptcha-manager.js.map +1 -1
- package/dist/src/util/promisedSleep.js.map +1 -1
- package/dist/test/helpers/fillInContactForm.js.map +1 -1
- package/dist/test/mocks/flow-handlers/individual-handlers/mock-applepay-flow-handler.js.map +1 -1
- package/dist/test/mocks/flow-handlers/individual-handlers/mock-creditcard-flow-handler.js.map +1 -1
- package/dist/test/mocks/flow-handlers/individual-handlers/mock-googlepay-flow-handler.js.map +1 -1
- package/dist/test/mocks/flow-handlers/individual-handlers/mock-paypal-flow-handler.js.map +1 -1
- package/dist/test/mocks/flow-handlers/individual-handlers/mock-venmo-flow-handler.js.map +1 -1
- package/dist/test/mocks/flow-handlers/mock-payment-flow-handlers.js.map +1 -1
- package/dist/test/mocks/mock-braintree-manager.js.map +1 -1
- package/dist/test/mocks/mock-donation-info.js.map +1 -1
- package/dist/test/mocks/mock-endpoint-manager.js.map +1 -1
- package/dist/test/mocks/mock-hosted-fields-config.js.map +1 -1
- package/dist/test/mocks/mock-hosted-fields-container.js.map +1 -1
- package/dist/test/mocks/mock-lazy-loader.js.map +1 -1
- package/dist/test/mocks/mock-modal-manager.js.map +1 -1
- package/dist/test/mocks/mock-payment-clients.js.map +1 -1
- package/dist/test/mocks/mock-paypal-button-renderer.js.map +1 -1
- package/dist/test/mocks/mock-recaptcha-manager.js.map +1 -1
- package/dist/test/mocks/models/mock-billing-info.js.map +1 -1
- package/dist/test/mocks/models/mock-custom-fields.js.map +1 -1
- package/dist/test/mocks/models/mock-customer-info.js.map +1 -1
- package/dist/test/mocks/models/mock-donation-request.js.map +1 -1
- package/dist/test/mocks/models/mock-success-response.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-applepay-client.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-applepay-payment.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-applepay-paymentauthorizedevent.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-applepay-session.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-applepay-sessionmanager.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-applepay-validatemerchantevent.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-braintree-client.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-data-collector.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-googlepay-client.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-googlepay-library.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-grecaptcha.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-hostedfields-client.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-hostedfieldstateobject-generator.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-hostedfieldtokenizepayload.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-paypal-client.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-paypal-library.js.map +1 -1
- package/dist/test/mocks/payment-clients/mock-venmo-client.js.map +1 -1
- package/dist/test/mocks/payment-providers/individual-providers/mock-applepay-datasource-delegate.js.map +1 -1
- package/dist/test/mocks/payment-providers/individual-providers/mock-applepay-handler.js.map +1 -1
- package/dist/test/mocks/payment-providers/individual-providers/mock-creditcard-handler.js.map +1 -1
- package/dist/test/mocks/payment-providers/individual-providers/mock-googlepay-handler.js.map +1 -1
- package/dist/test/mocks/payment-providers/individual-providers/mock-paypal-button-datasource-delegate.js.map +1 -1
- package/dist/test/mocks/payment-providers/individual-providers/mock-paypal-button-datasource.js.map +1 -1
- package/dist/test/mocks/payment-providers/individual-providers/mock-paypal-handler.js.map +1 -1
- package/dist/test/mocks/payment-providers/individual-providers/mock-venmo-handler.js.map +1 -1
- package/dist/test/mocks/payment-providers/mock-payment-providers.js.map +1 -1
- package/dist/test/tests/braintree-manager.test.js.map +1 -1
- package/dist/test/tests/donation-form-controller.test.js +39 -39
- package/dist/test/tests/donation-form-controller.test.js.map +1 -1
- package/dist/test/tests/donation-form.test.js +4 -4
- package/dist/test/tests/donation-form.test.js.map +1 -1
- package/dist/test/tests/flow-handlers/donation-flow-modal-manager.test.js +14 -14
- package/dist/test/tests/flow-handlers/donation-flow-modal-manager.test.js.map +1 -1
- package/dist/test/tests/form-elements/donation-summary.test.js.map +1 -1
- package/dist/test/tests/form-elements/payment-selector.test.js.map +1 -1
- package/dist/test/tests/modals/error-modal-content.test.js +2 -2
- package/dist/test/tests/modals/error-modal-content.test.js.map +1 -1
- package/dist/test/tests/modals/upsell-modal-content.test.js +31 -31
- package/dist/test/tests/modals/upsell-modal-content.test.js.map +1 -1
- package/dist/test/tests/models/donation-payment-info.test.js.map +1 -1
- package/dist/test/tests/payment-clients.test.js.map +1 -1
- package/dist/test/tests/payment-providers/applepay-sessiondatasource.test.js.map +1 -1
- package/dist/test/tests/payment-providers/applepay-sessionmanager.test.js.map +1 -1
- package/dist/test/tests/payment-providers/applepay.test.js.map +1 -1
- package/dist/test/tests/payment-providers/creditcard.test.js.map +1 -1
- package/dist/test/tests/payment-providers/googlepay.test.js.map +1 -1
- package/dist/test/tests/payment-providers/payment-providers.test.js.map +1 -1
- package/dist/test/tests/payment-providers/paypal-button-datasource.test.js.map +1 -1
- package/dist/test/tests/payment-providers/paypal.test.js.map +1 -1
- package/dist/test/tests/payment-providers/venmo.test.js.map +1 -1
- package/dist/test/tests/recaptcha-manager.test.js.map +1 -1
- package/package.json +107 -107
- package/src/@types/analytics-handler/index.d.ts +8 -8
- package/src/@types/braintree-web/LICENSE +21 -21
- package/src/@types/braintree-web/index.d.ts +93 -93
- package/src/@types/braintree-web/modules/american-express.d.ts +50 -50
- package/src/@types/braintree-web/modules/apple-pay.d.ts +213 -213
- package/src/@types/braintree-web/modules/client.d.ts +103 -103
- package/src/@types/braintree-web/modules/core.d.ts +34 -34
- package/src/@types/braintree-web/modules/data-collector.d.ts +13 -13
- package/src/@types/braintree-web/modules/google-payment.d.ts +269 -269
- package/src/@types/braintree-web/modules/hosted-fields.d.ts +366 -366
- package/src/@types/braintree-web/modules/paypal-checkout.d.ts +262 -262
- package/src/@types/braintree-web/modules/paypal.d.ts +177 -177
- package/src/@types/braintree-web/modules/three-d-secure.d.ts +141 -141
- package/src/@types/braintree-web/modules/unionpay.d.ts +224 -224
- package/src/@types/braintree-web/modules/us-bank-account.d.ts +81 -81
- package/src/@types/braintree-web/modules/venmo.d.ts +110 -110
- package/src/@types/braintree-web/package.json +64 -64
- package/src/@types/paypal-checkout-components/LICENSE +21 -21
- package/src/@types/paypal-checkout-components/index.d.ts +67 -67
- package/src/@types/paypal-checkout-components/modules/button.d.ts +50 -50
- package/src/@types/paypal-checkout-components/modules/callback-data.d.ts +244 -244
- package/src/@types/paypal-checkout-components/modules/configuration.d.ts +114 -114
- package/src/@types/paypal-checkout-components/package.json +58 -58
- package/src/braintree-manager/braintree-interfaces.ts +172 -172
- package/src/braintree-manager/braintree-manager.ts +281 -281
- package/src/braintree-manager/payment-clients.ts +146 -146
- package/src/braintree-manager/payment-providers/apple-pay/apple-pay-interface.ts +13 -13
- package/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-datasource-delegate.ts +8 -8
- package/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-datasource-interface.ts +10 -10
- package/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-datasource.ts +119 -119
- package/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-manager.ts +21 -21
- package/src/braintree-manager/payment-providers/apple-pay/apple-pay.ts +97 -97
- package/src/braintree-manager/payment-providers/credit-card/credit-card-interface.ts +21 -21
- package/src/braintree-manager/payment-providers/credit-card/credit-card.ts +130 -130
- package/src/braintree-manager/payment-providers/credit-card/hosted-field-configuration.ts +19 -19
- package/src/braintree-manager/payment-providers/credit-card/hosted-field-container.ts +85 -85
- package/src/braintree-manager/payment-providers/google-pay-interface.ts +8 -8
- package/src/braintree-manager/payment-providers/google-pay.ts +59 -59
- package/src/braintree-manager/payment-providers/paypal/paypal-button-datasource.ts +218 -218
- package/src/braintree-manager/payment-providers/paypal/paypal-interface.ts +13 -13
- package/src/braintree-manager/payment-providers/paypal/paypal.ts +78 -78
- package/src/braintree-manager/payment-providers/venmo-interface.ts +8 -8
- package/src/braintree-manager/payment-providers/venmo.ts +67 -67
- package/src/braintree-manager/payment-providers-interface.ts +25 -25
- package/src/braintree-manager/payment-providers.ts +147 -147
- package/src/donation-form-controller.ts +623 -623
- package/src/donation-form-error.ts +6 -6
- package/src/donation-form.ts +576 -576
- package/src/form-elements/badged-input.ts +109 -109
- package/src/form-elements/contact-form/autocomplete-field-options.ts +63 -63
- package/src/form-elements/contact-form/contact-form.ts +434 -434
- package/src/form-elements/contact-form/countries.ts +252 -252
- package/src/form-elements/header/donation-form-header.ts +98 -98
- package/src/form-elements/header/donation-summary.ts +61 -61
- package/src/form-elements/payment-selector.ts +365 -365
- package/src/form-elements/total-amount.ts +46 -46
- package/src/modals/confirm-donation-modal-content.ts +168 -168
- package/src/modals/error-modal-content.ts +48 -48
- package/src/modals/upsell-modal-content.ts +284 -284
- package/src/payment-flow-handlers/donation-flow-modal-manager.ts +439 -439
- package/src/payment-flow-handlers/handlers/applepay-flow-handler.ts +109 -109
- package/src/payment-flow-handlers/handlers/creditcard-flow-handler.ts +232 -232
- package/src/payment-flow-handlers/handlers/googlepay-flow-handler.ts +111 -111
- package/src/payment-flow-handlers/handlers/paypal-flow-handler.ts +331 -331
- package/src/payment-flow-handlers/handlers/venmo-flow-handler.ts +119 -119
- package/src/payment-flow-handlers/handlers/venmo-restoration-state-handler.ts +127 -127
- package/src/payment-flow-handlers/payment-flow-handlers.ts +218 -218
- package/src/recaptcha-manager/recaptcha-manager.ts +123 -123
- package/src/util/promisedSleep.ts +3 -3
- package/dist/demo/app-root.d.ts +0 -0
- package/dist/demo/app-root.js +0 -2
- package/dist/demo/app-root.js.map +0 -1
|
@@ -1,434 +1,434 @@
|
|
|
1
|
-
import { LitElement, html, css, TemplateResult, PropertyValues } from 'lit';
|
|
2
|
-
import { customElement, property, query } from 'lit/decorators.js';
|
|
3
|
-
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
BillingInfo,
|
|
7
|
-
CustomerInfo,
|
|
8
|
-
DonorContactInfo,
|
|
9
|
-
} from '@internetarchive/donation-form-data-models';
|
|
10
|
-
import { AutoCompleteFieldOptions } from './autocomplete-field-options';
|
|
11
|
-
import { SpacerOption } from '../badged-input';
|
|
12
|
-
import { BadgedInput } from '../badged-input';
|
|
13
|
-
import '../badged-input';
|
|
14
|
-
|
|
15
|
-
import emailImg from '@internetarchive/icon-email/index.js';
|
|
16
|
-
import localePinImg from '@internetarchive/icon-locale-pin/index.js';
|
|
17
|
-
import userIcon from '@internetarchive/icon-user/index.js';
|
|
18
|
-
|
|
19
|
-
import { countries } from './countries';
|
|
20
|
-
|
|
21
|
-
@customElement('contact-form')
|
|
22
|
-
export class ContactForm extends LitElement {
|
|
23
|
-
@query('badged-input.donation-contact-form-email') emailBadgedInput!: BadgedInput;
|
|
24
|
-
@query('#donation-contact-form-email') emailField!: HTMLInputElement;
|
|
25
|
-
|
|
26
|
-
@query('badged-input.donation-contact-form-first-name') firstNameBadgedInput!: BadgedInput;
|
|
27
|
-
@query('#donation-contact-form-first-name') firstNameField!: HTMLInputElement;
|
|
28
|
-
|
|
29
|
-
@query('badged-input.donation-contact-form-last-name') lastNameBadgedInput!: BadgedInput;
|
|
30
|
-
@query('#donation-contact-form-last-name') lastNameField!: HTMLInputElement;
|
|
31
|
-
|
|
32
|
-
@query('badged-input.donation-contact-form-postal-code') postalBadgedInput!: BadgedInput;
|
|
33
|
-
@query('#donation-contact-form-postal-code') postalCodeField!: HTMLInputElement;
|
|
34
|
-
|
|
35
|
-
@query('badged-input.donation-contact-form-street-address')
|
|
36
|
-
streetAddressBadgedInput!: BadgedInput;
|
|
37
|
-
@query('#donation-contact-form-street-address') streetAddressField!: HTMLInputElement;
|
|
38
|
-
|
|
39
|
-
@query('badged-input.donation-contact-form-extended-address')
|
|
40
|
-
extendedAddressBadgedInput!: BadgedInput;
|
|
41
|
-
@query('#donation-contact-form-extended-address') extendedAddressField!: HTMLInputElement;
|
|
42
|
-
|
|
43
|
-
@query('badged-input.donation-contact-form-locality') localityBadgedInput!: BadgedInput;
|
|
44
|
-
@query('#donation-contact-form-locality') localityField!: HTMLInputElement;
|
|
45
|
-
|
|
46
|
-
@query('badged-input.donation-contact-form-region') regionBadgedInput!: BadgedInput;
|
|
47
|
-
@query('#donation-contact-form-region') regionField!: HTMLInputElement;
|
|
48
|
-
|
|
49
|
-
@query('#donation-contact-form-countryCodeAlpha2') countryCodeAlpha2Field!: HTMLSelectElement;
|
|
50
|
-
|
|
51
|
-
@query('#donation-contact-form-error-message') errorMessage!: HTMLDivElement;
|
|
52
|
-
@query('form') form!: HTMLFormElement;
|
|
53
|
-
|
|
54
|
-
/** @keyof countries */
|
|
55
|
-
@property({ type: String }) selectedCountry = 'US';
|
|
56
|
-
|
|
57
|
-
@property({ type: String }) donorEmail = '';
|
|
58
|
-
|
|
59
|
-
updated(changed: PropertyValues): void {
|
|
60
|
-
if (changed.has('donorEmail')) {
|
|
61
|
-
this.emailField.value = this.donorEmail ?? '';
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
reportValidity(): boolean {
|
|
66
|
-
const fieldBadgedInputs: Array<[HTMLInputElement, BadgedInput]> = [
|
|
67
|
-
[this.emailField, this.emailBadgedInput],
|
|
68
|
-
[this.firstNameField, this.firstNameBadgedInput],
|
|
69
|
-
[this.lastNameField, this.lastNameBadgedInput],
|
|
70
|
-
[this.regionField, this.regionBadgedInput],
|
|
71
|
-
[this.localityField, this.localityBadgedInput],
|
|
72
|
-
[this.streetAddressField, this.streetAddressBadgedInput],
|
|
73
|
-
[this.postalCodeField, this.postalBadgedInput],
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
let isValid = true;
|
|
77
|
-
fieldBadgedInputs.forEach(([inputElement, badgedInput]) => {
|
|
78
|
-
const fieldValid = inputElement.checkValidity();
|
|
79
|
-
isValid = isValid && fieldValid;
|
|
80
|
-
if (!fieldValid) {
|
|
81
|
-
badgedInput.error = true;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
if (!isValid) {
|
|
86
|
-
this.errorMessage.innerText = 'Please enter any missing contact information below';
|
|
87
|
-
} else {
|
|
88
|
-
this.errorMessage.innerText = '';
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return isValid;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
focus(): void {
|
|
95
|
-
this.emailField.focus();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** @inheritdoc */
|
|
99
|
-
render(): TemplateResult {
|
|
100
|
-
return html`
|
|
101
|
-
<div id="donation-contact-form-error-message"></div>
|
|
102
|
-
<form>
|
|
103
|
-
<fieldset>
|
|
104
|
-
<div class="row">
|
|
105
|
-
${this.generateInput({
|
|
106
|
-
id: 'donation-contact-form-email',
|
|
107
|
-
placeholder: 'Email',
|
|
108
|
-
required: true,
|
|
109
|
-
fieldType: 'email',
|
|
110
|
-
name: 'email',
|
|
111
|
-
autocomplete: 'email',
|
|
112
|
-
maxlength: 255,
|
|
113
|
-
icon: emailImg,
|
|
114
|
-
})}
|
|
115
|
-
</div>
|
|
116
|
-
</fieldset>
|
|
117
|
-
|
|
118
|
-
<fieldset>
|
|
119
|
-
<div class="row">
|
|
120
|
-
${this.generateInput({
|
|
121
|
-
id: 'donation-contact-form-first-name',
|
|
122
|
-
placeholder: 'First name',
|
|
123
|
-
name: 'fname',
|
|
124
|
-
required: true,
|
|
125
|
-
maxlength: 255,
|
|
126
|
-
autocomplete: 'given-name',
|
|
127
|
-
icon: userIcon,
|
|
128
|
-
})}
|
|
129
|
-
</div>
|
|
130
|
-
<div class="row">
|
|
131
|
-
${this.generateInput({
|
|
132
|
-
id: 'donation-contact-form-last-name',
|
|
133
|
-
placeholder: 'Last name',
|
|
134
|
-
name: 'lname',
|
|
135
|
-
autocomplete: 'family-name',
|
|
136
|
-
required: true,
|
|
137
|
-
maxlength: 255,
|
|
138
|
-
})}
|
|
139
|
-
</div>
|
|
140
|
-
</fieldset>
|
|
141
|
-
<fieldset>
|
|
142
|
-
<div class="row">
|
|
143
|
-
${this.generateInput({
|
|
144
|
-
id: 'donation-contact-form-street-address',
|
|
145
|
-
placeholder: 'Address Line 1',
|
|
146
|
-
required: true,
|
|
147
|
-
autocomplete: 'address-line1',
|
|
148
|
-
icon: localePinImg,
|
|
149
|
-
name: 'street-address',
|
|
150
|
-
})}
|
|
151
|
-
</div>
|
|
152
|
-
<div class="row">
|
|
153
|
-
${this.generateInput({
|
|
154
|
-
id: 'donation-contact-form-extended-address',
|
|
155
|
-
placeholder: 'Address Line 2 (optional)',
|
|
156
|
-
autocomplete: 'address-line2',
|
|
157
|
-
required: false,
|
|
158
|
-
name: 'extended-address',
|
|
159
|
-
})}
|
|
160
|
-
</div>
|
|
161
|
-
<div class="row">
|
|
162
|
-
${this.generateInput({
|
|
163
|
-
id: 'donation-contact-form-locality',
|
|
164
|
-
placeholder: 'City',
|
|
165
|
-
autocomplete: 'address-level2',
|
|
166
|
-
required: true,
|
|
167
|
-
name: 'locality',
|
|
168
|
-
})}
|
|
169
|
-
</div>
|
|
170
|
-
<div class="row">
|
|
171
|
-
${this.generateInput({
|
|
172
|
-
id: 'donation-contact-form-region',
|
|
173
|
-
placeholder: 'State / Province',
|
|
174
|
-
autocomplete: 'address-level1',
|
|
175
|
-
required: true,
|
|
176
|
-
name: 'region',
|
|
177
|
-
})}
|
|
178
|
-
${this.generateInput({
|
|
179
|
-
id: 'donation-contact-form-postal-code',
|
|
180
|
-
placeholder: 'Zip / Postal',
|
|
181
|
-
autocomplete: 'postal-code',
|
|
182
|
-
required: true,
|
|
183
|
-
name: 'postal',
|
|
184
|
-
maxlength: 9,
|
|
185
|
-
// must start with a character, then may contain spaces
|
|
186
|
-
validationPattern: '[a-zA-Z\\-\\d]+[a-zA-Z\\-\\d\\s]*',
|
|
187
|
-
iconSpaceOption: SpacerOption.CompressSpace,
|
|
188
|
-
})}
|
|
189
|
-
</div>
|
|
190
|
-
<div class="row">${this.countrySelectorTemplate}</div>
|
|
191
|
-
</fieldset>
|
|
192
|
-
</form>
|
|
193
|
-
${this.getStyles}
|
|
194
|
-
`;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
private get countrySelectorTemplate(): TemplateResult {
|
|
198
|
-
return html`
|
|
199
|
-
<badged-input>
|
|
200
|
-
<select
|
|
201
|
-
id="donation-contact-form-countryCodeAlpha2"
|
|
202
|
-
@change=${(e: Event) => {
|
|
203
|
-
const currCountry = this.selectedCountry;
|
|
204
|
-
this.selectedCountry = (e.target as HTMLInputElement)?.value
|
|
205
|
-
? ((e.target as HTMLInputElement)?.value as string)
|
|
206
|
-
: currCountry;
|
|
207
|
-
// update required visual cue on region/state/province & postal code fields
|
|
208
|
-
if (this.selectedCountry === 'US') {
|
|
209
|
-
this.postalBadgedInput?.setAttribute('required', '');
|
|
210
|
-
this.postalCodeField?.setAttribute('required', '');
|
|
211
|
-
this.regionBadgedInput?.setAttribute('required', '');
|
|
212
|
-
this.regionField?.setAttribute('required', '');
|
|
213
|
-
} else {
|
|
214
|
-
this.postalBadgedInput?.removeAttribute('required');
|
|
215
|
-
this.postalCodeField?.removeAttribute('required');
|
|
216
|
-
this.regionBadgedInput?.removeAttribute('required');
|
|
217
|
-
this.regionField?.removeAttribute('required');
|
|
218
|
-
}
|
|
219
|
-
}}
|
|
220
|
-
>
|
|
221
|
-
${Object.keys(countries).map(key => {
|
|
222
|
-
const name = countries[key];
|
|
223
|
-
return html`
|
|
224
|
-
<option value=${key} ?selected=${key === this.selectedCountry}>${name}</option>
|
|
225
|
-
`;
|
|
226
|
-
})}
|
|
227
|
-
</select>
|
|
228
|
-
</badged-input>
|
|
229
|
-
`;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/** @inheritdoc */
|
|
233
|
-
createRenderRoot(): this {
|
|
234
|
-
// Render template without shadow DOM. Note that shadow DOM features like
|
|
235
|
-
// encapsulated CSS and slots are unavailable.
|
|
236
|
-
// Form autofill does not work properly in the shadow DOM
|
|
237
|
-
// so we need our form fields in the light DOM
|
|
238
|
-
return this;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// reset the error state when the user focuses the input
|
|
242
|
-
private inputFocused(e: KeyboardEvent): void {
|
|
243
|
-
this.errorMessage.innerText = '';
|
|
244
|
-
const input = e.target as HTMLInputElement;
|
|
245
|
-
const inputIdentifier = input.id;
|
|
246
|
-
const badgedInput = this.querySelector(`badged-input.${inputIdentifier}`) as BadgedInput;
|
|
247
|
-
badgedInput.error = false;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
private generateInput(options: {
|
|
251
|
-
id: string;
|
|
252
|
-
placeholder: string;
|
|
253
|
-
required?: boolean;
|
|
254
|
-
fieldType?: 'text' | 'email';
|
|
255
|
-
autocomplete?: AutoCompleteFieldOptions;
|
|
256
|
-
maxlength?: number;
|
|
257
|
-
name: string;
|
|
258
|
-
icon?: TemplateResult;
|
|
259
|
-
iconSpaceOption?: SpacerOption;
|
|
260
|
-
validationPattern?: string;
|
|
261
|
-
}): TemplateResult {
|
|
262
|
-
const required = options.required ?? true;
|
|
263
|
-
const fieldType = options.fieldType ?? 'text';
|
|
264
|
-
const iconOption = options.iconSpaceOption ?? SpacerOption.LeaveSpace;
|
|
265
|
-
|
|
266
|
-
return html`
|
|
267
|
-
<badged-input
|
|
268
|
-
class=${options.id}
|
|
269
|
-
.icon=${options.icon}
|
|
270
|
-
.iconSpaceOption=${iconOption}
|
|
271
|
-
?required=${options.required}
|
|
272
|
-
>
|
|
273
|
-
<label for=${options.id}>${options.placeholder}</label>
|
|
274
|
-
<input
|
|
275
|
-
type=${fieldType}
|
|
276
|
-
id=${options.id}
|
|
277
|
-
class="donation-contact-form-input"
|
|
278
|
-
name=${options.name}
|
|
279
|
-
aria-label=${options.placeholder}
|
|
280
|
-
placeholder=${options.placeholder}
|
|
281
|
-
maxlength=${ifDefined(options.maxlength)}
|
|
282
|
-
autocomplete=${options.autocomplete ?? 'on'}
|
|
283
|
-
pattern=${ifDefined(options.validationPattern)}
|
|
284
|
-
@focus=${this.inputFocused}
|
|
285
|
-
?required=${required}
|
|
286
|
-
/>
|
|
287
|
-
</badged-input>
|
|
288
|
-
`;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
get donorContactInfo(): DonorContactInfo {
|
|
292
|
-
return new DonorContactInfo({
|
|
293
|
-
billing: this.billingInfo,
|
|
294
|
-
customer: this.contactInfo,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
get billingInfo(): BillingInfo {
|
|
299
|
-
const billingInfo = new BillingInfo({
|
|
300
|
-
streetAddress: this.streetAddressField.value,
|
|
301
|
-
extendedAddress: this.extendedAddressField.value,
|
|
302
|
-
locality: this.localityField.value,
|
|
303
|
-
region: this.regionField.value,
|
|
304
|
-
postalCode: this.postalCodeField.value,
|
|
305
|
-
countryCodeAlpha2: this.countryCodeAlpha2Field.value,
|
|
306
|
-
});
|
|
307
|
-
return billingInfo;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
get contactInfo(): CustomerInfo {
|
|
311
|
-
return new CustomerInfo({
|
|
312
|
-
email: this.emailField.value,
|
|
313
|
-
firstName: this.firstNameField.value,
|
|
314
|
-
lastName: this.lastNameField.value,
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* This is not the normal LitElement styles block.
|
|
320
|
-
*
|
|
321
|
-
* This element uses the clear DOM instead of the shadow DOM so it can't use
|
|
322
|
-
* the shadowRoot's isolated styling. This is a bit of a workaround to keep all of
|
|
323
|
-
* the styling local by writing out our own <style> tag and just be careful about
|
|
324
|
-
* the selectors since they will leak outside of this component.
|
|
325
|
-
*
|
|
326
|
-
* @readonly
|
|
327
|
-
* @private
|
|
328
|
-
* @type {TemplateResult}
|
|
329
|
-
* @memberof ContactForm
|
|
330
|
-
*/
|
|
331
|
-
private get getStyles(): TemplateResult {
|
|
332
|
-
const noIconSpacerWidth = css`var(--badgedInputNoIconSpacerWidth, 3rem)`;
|
|
333
|
-
const iconSpacerWidth = css`var(--badgedInputIconSpacerWidth, 5rem)`;
|
|
334
|
-
|
|
335
|
-
const fieldSetSpacing = css`var(--fieldSetSpacing, 1rem)`;
|
|
336
|
-
const fieldFontFamily = css`var(--fontFamily, "Helvetica Neue", Helvetica, Arial, sans-serif)`;
|
|
337
|
-
const fieldFontSize = css`var(--contactFieldFontSize, 1.6rem)`;
|
|
338
|
-
const fieldFontColor = css`var(--inputFieldFontColor, #333)`;
|
|
339
|
-
|
|
340
|
-
const iconFieldWidth = css`calc(100% - ${iconSpacerWidth})`;
|
|
341
|
-
const noIconFieldWidth = css`calc(100% - ${noIconSpacerWidth})`;
|
|
342
|
-
|
|
343
|
-
return html`
|
|
344
|
-
<style>
|
|
345
|
-
/*
|
|
346
|
-
**NOTE**
|
|
347
|
-
This element is in the lightDOM so be sure to prefix all styles
|
|
348
|
-
with "contact-form" so styles don't leak.
|
|
349
|
-
*/
|
|
350
|
-
contact-form fieldset {
|
|
351
|
-
border: 0;
|
|
352
|
-
padding: 0;
|
|
353
|
-
margin: 0;
|
|
354
|
-
margin-bottom: ${fieldSetSpacing};
|
|
355
|
-
background-color: white;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/* These 1px and 0 margins in the next few selectors are to account for the
|
|
359
|
-
double outlines caused by the fields being right next to each other */
|
|
360
|
-
contact-form .row {
|
|
361
|
-
display: flex;
|
|
362
|
-
margin: -1px 0 0 0;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
contact-form fieldset .row:first-child {
|
|
366
|
-
margin-top: 0;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
contact-form badged-input.donation-contact-form-region {
|
|
370
|
-
width: 60%;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
contact-form badged-input.donation-contact-form-postal-code {
|
|
374
|
-
width: 40%;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
contact-form #donation-contact-form-region {
|
|
378
|
-
width: ${iconFieldWidth};
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
contact-form #donation-contact-form-postal-code {
|
|
382
|
-
width: ${noIconFieldWidth};
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
contact-form #donation-contact-form-error-message {
|
|
386
|
-
color: red;
|
|
387
|
-
font-size: 1.4rem;
|
|
388
|
-
margin-bottom: 0.6rem;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
contact-form #donation-contact-form-last-name {
|
|
392
|
-
width: ${noIconFieldWidth};
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/* only show for screen readers */
|
|
396
|
-
contact-form label {
|
|
397
|
-
position: absolute;
|
|
398
|
-
left: -10000px;
|
|
399
|
-
top: auto;
|
|
400
|
-
width: 1px;
|
|
401
|
-
height: 1px;
|
|
402
|
-
overflow: hidden;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
contact-form .donation-contact-form-input {
|
|
406
|
-
width: ${iconFieldWidth};
|
|
407
|
-
border: 0;
|
|
408
|
-
outline: 0;
|
|
409
|
-
background: transparent;
|
|
410
|
-
font-weight: bold;
|
|
411
|
-
color: ${fieldFontColor};
|
|
412
|
-
font-size: ${fieldFontSize};
|
|
413
|
-
padding: 0;
|
|
414
|
-
font-family: ${fieldFontFamily};
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
contact-form .donation-contact-form-input::placeholder {
|
|
418
|
-
color: revert;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
contact-form #donation-contact-form-countryCodeAlpha2 {
|
|
422
|
-
width: calc(100%);
|
|
423
|
-
height: 100%;
|
|
424
|
-
box-sizing: border-box;
|
|
425
|
-
font-weight: bold;
|
|
426
|
-
font-size: ${fieldFontSize};
|
|
427
|
-
font-family: ${fieldFontFamily};
|
|
428
|
-
border: 0;
|
|
429
|
-
background: #fff;
|
|
430
|
-
}
|
|
431
|
-
</style>
|
|
432
|
-
`;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
1
|
+
import { LitElement, html, css, TemplateResult, PropertyValues } from 'lit';
|
|
2
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
|
3
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
BillingInfo,
|
|
7
|
+
CustomerInfo,
|
|
8
|
+
DonorContactInfo,
|
|
9
|
+
} from '@internetarchive/donation-form-data-models';
|
|
10
|
+
import { AutoCompleteFieldOptions } from './autocomplete-field-options';
|
|
11
|
+
import { SpacerOption } from '../badged-input';
|
|
12
|
+
import { BadgedInput } from '../badged-input';
|
|
13
|
+
import '../badged-input';
|
|
14
|
+
|
|
15
|
+
import emailImg from '@internetarchive/icon-email/index.js';
|
|
16
|
+
import localePinImg from '@internetarchive/icon-locale-pin/index.js';
|
|
17
|
+
import userIcon from '@internetarchive/icon-user/index.js';
|
|
18
|
+
|
|
19
|
+
import { countries } from './countries';
|
|
20
|
+
|
|
21
|
+
@customElement('contact-form')
|
|
22
|
+
export class ContactForm extends LitElement {
|
|
23
|
+
@query('badged-input.donation-contact-form-email') emailBadgedInput!: BadgedInput;
|
|
24
|
+
@query('#donation-contact-form-email') emailField!: HTMLInputElement;
|
|
25
|
+
|
|
26
|
+
@query('badged-input.donation-contact-form-first-name') firstNameBadgedInput!: BadgedInput;
|
|
27
|
+
@query('#donation-contact-form-first-name') firstNameField!: HTMLInputElement;
|
|
28
|
+
|
|
29
|
+
@query('badged-input.donation-contact-form-last-name') lastNameBadgedInput!: BadgedInput;
|
|
30
|
+
@query('#donation-contact-form-last-name') lastNameField!: HTMLInputElement;
|
|
31
|
+
|
|
32
|
+
@query('badged-input.donation-contact-form-postal-code') postalBadgedInput!: BadgedInput;
|
|
33
|
+
@query('#donation-contact-form-postal-code') postalCodeField!: HTMLInputElement;
|
|
34
|
+
|
|
35
|
+
@query('badged-input.donation-contact-form-street-address')
|
|
36
|
+
streetAddressBadgedInput!: BadgedInput;
|
|
37
|
+
@query('#donation-contact-form-street-address') streetAddressField!: HTMLInputElement;
|
|
38
|
+
|
|
39
|
+
@query('badged-input.donation-contact-form-extended-address')
|
|
40
|
+
extendedAddressBadgedInput!: BadgedInput;
|
|
41
|
+
@query('#donation-contact-form-extended-address') extendedAddressField!: HTMLInputElement;
|
|
42
|
+
|
|
43
|
+
@query('badged-input.donation-contact-form-locality') localityBadgedInput!: BadgedInput;
|
|
44
|
+
@query('#donation-contact-form-locality') localityField!: HTMLInputElement;
|
|
45
|
+
|
|
46
|
+
@query('badged-input.donation-contact-form-region') regionBadgedInput!: BadgedInput;
|
|
47
|
+
@query('#donation-contact-form-region') regionField!: HTMLInputElement;
|
|
48
|
+
|
|
49
|
+
@query('#donation-contact-form-countryCodeAlpha2') countryCodeAlpha2Field!: HTMLSelectElement;
|
|
50
|
+
|
|
51
|
+
@query('#donation-contact-form-error-message') errorMessage!: HTMLDivElement;
|
|
52
|
+
@query('form') form!: HTMLFormElement;
|
|
53
|
+
|
|
54
|
+
/** @keyof countries */
|
|
55
|
+
@property({ type: String }) selectedCountry = 'US';
|
|
56
|
+
|
|
57
|
+
@property({ type: String }) donorEmail = '';
|
|
58
|
+
|
|
59
|
+
updated(changed: PropertyValues): void {
|
|
60
|
+
if (changed.has('donorEmail')) {
|
|
61
|
+
this.emailField.value = this.donorEmail ?? '';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
reportValidity(): boolean {
|
|
66
|
+
const fieldBadgedInputs: Array<[HTMLInputElement, BadgedInput]> = [
|
|
67
|
+
[this.emailField, this.emailBadgedInput],
|
|
68
|
+
[this.firstNameField, this.firstNameBadgedInput],
|
|
69
|
+
[this.lastNameField, this.lastNameBadgedInput],
|
|
70
|
+
[this.regionField, this.regionBadgedInput],
|
|
71
|
+
[this.localityField, this.localityBadgedInput],
|
|
72
|
+
[this.streetAddressField, this.streetAddressBadgedInput],
|
|
73
|
+
[this.postalCodeField, this.postalBadgedInput],
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
let isValid = true;
|
|
77
|
+
fieldBadgedInputs.forEach(([inputElement, badgedInput]) => {
|
|
78
|
+
const fieldValid = inputElement.checkValidity();
|
|
79
|
+
isValid = isValid && fieldValid;
|
|
80
|
+
if (!fieldValid) {
|
|
81
|
+
badgedInput.error = true;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (!isValid) {
|
|
86
|
+
this.errorMessage.innerText = 'Please enter any missing contact information below';
|
|
87
|
+
} else {
|
|
88
|
+
this.errorMessage.innerText = '';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return isValid;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
focus(): void {
|
|
95
|
+
this.emailField.focus();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** @inheritdoc */
|
|
99
|
+
render(): TemplateResult {
|
|
100
|
+
return html`
|
|
101
|
+
<div id="donation-contact-form-error-message"></div>
|
|
102
|
+
<form>
|
|
103
|
+
<fieldset>
|
|
104
|
+
<div class="row">
|
|
105
|
+
${this.generateInput({
|
|
106
|
+
id: 'donation-contact-form-email',
|
|
107
|
+
placeholder: 'Email',
|
|
108
|
+
required: true,
|
|
109
|
+
fieldType: 'email',
|
|
110
|
+
name: 'email',
|
|
111
|
+
autocomplete: 'email',
|
|
112
|
+
maxlength: 255,
|
|
113
|
+
icon: emailImg,
|
|
114
|
+
})}
|
|
115
|
+
</div>
|
|
116
|
+
</fieldset>
|
|
117
|
+
|
|
118
|
+
<fieldset>
|
|
119
|
+
<div class="row">
|
|
120
|
+
${this.generateInput({
|
|
121
|
+
id: 'donation-contact-form-first-name',
|
|
122
|
+
placeholder: 'First name',
|
|
123
|
+
name: 'fname',
|
|
124
|
+
required: true,
|
|
125
|
+
maxlength: 255,
|
|
126
|
+
autocomplete: 'given-name',
|
|
127
|
+
icon: userIcon,
|
|
128
|
+
})}
|
|
129
|
+
</div>
|
|
130
|
+
<div class="row">
|
|
131
|
+
${this.generateInput({
|
|
132
|
+
id: 'donation-contact-form-last-name',
|
|
133
|
+
placeholder: 'Last name',
|
|
134
|
+
name: 'lname',
|
|
135
|
+
autocomplete: 'family-name',
|
|
136
|
+
required: true,
|
|
137
|
+
maxlength: 255,
|
|
138
|
+
})}
|
|
139
|
+
</div>
|
|
140
|
+
</fieldset>
|
|
141
|
+
<fieldset>
|
|
142
|
+
<div class="row">
|
|
143
|
+
${this.generateInput({
|
|
144
|
+
id: 'donation-contact-form-street-address',
|
|
145
|
+
placeholder: 'Address Line 1',
|
|
146
|
+
required: true,
|
|
147
|
+
autocomplete: 'address-line1',
|
|
148
|
+
icon: localePinImg,
|
|
149
|
+
name: 'street-address',
|
|
150
|
+
})}
|
|
151
|
+
</div>
|
|
152
|
+
<div class="row">
|
|
153
|
+
${this.generateInput({
|
|
154
|
+
id: 'donation-contact-form-extended-address',
|
|
155
|
+
placeholder: 'Address Line 2 (optional)',
|
|
156
|
+
autocomplete: 'address-line2',
|
|
157
|
+
required: false,
|
|
158
|
+
name: 'extended-address',
|
|
159
|
+
})}
|
|
160
|
+
</div>
|
|
161
|
+
<div class="row">
|
|
162
|
+
${this.generateInput({
|
|
163
|
+
id: 'donation-contact-form-locality',
|
|
164
|
+
placeholder: 'City',
|
|
165
|
+
autocomplete: 'address-level2',
|
|
166
|
+
required: true,
|
|
167
|
+
name: 'locality',
|
|
168
|
+
})}
|
|
169
|
+
</div>
|
|
170
|
+
<div class="row">
|
|
171
|
+
${this.generateInput({
|
|
172
|
+
id: 'donation-contact-form-region',
|
|
173
|
+
placeholder: 'State / Province',
|
|
174
|
+
autocomplete: 'address-level1',
|
|
175
|
+
required: true,
|
|
176
|
+
name: 'region',
|
|
177
|
+
})}
|
|
178
|
+
${this.generateInput({
|
|
179
|
+
id: 'donation-contact-form-postal-code',
|
|
180
|
+
placeholder: 'Zip / Postal',
|
|
181
|
+
autocomplete: 'postal-code',
|
|
182
|
+
required: true,
|
|
183
|
+
name: 'postal',
|
|
184
|
+
maxlength: 9,
|
|
185
|
+
// must start with a character, then may contain spaces
|
|
186
|
+
validationPattern: '[a-zA-Z\\-\\d]+[a-zA-Z\\-\\d\\s]*',
|
|
187
|
+
iconSpaceOption: SpacerOption.CompressSpace,
|
|
188
|
+
})}
|
|
189
|
+
</div>
|
|
190
|
+
<div class="row">${this.countrySelectorTemplate}</div>
|
|
191
|
+
</fieldset>
|
|
192
|
+
</form>
|
|
193
|
+
${this.getStyles}
|
|
194
|
+
`;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private get countrySelectorTemplate(): TemplateResult {
|
|
198
|
+
return html`
|
|
199
|
+
<badged-input>
|
|
200
|
+
<select
|
|
201
|
+
id="donation-contact-form-countryCodeAlpha2"
|
|
202
|
+
@change=${(e: Event) => {
|
|
203
|
+
const currCountry = this.selectedCountry;
|
|
204
|
+
this.selectedCountry = (e.target as HTMLInputElement)?.value
|
|
205
|
+
? ((e.target as HTMLInputElement)?.value as string)
|
|
206
|
+
: currCountry;
|
|
207
|
+
// update required visual cue on region/state/province & postal code fields
|
|
208
|
+
if (this.selectedCountry === 'US') {
|
|
209
|
+
this.postalBadgedInput?.setAttribute('required', '');
|
|
210
|
+
this.postalCodeField?.setAttribute('required', '');
|
|
211
|
+
this.regionBadgedInput?.setAttribute('required', '');
|
|
212
|
+
this.regionField?.setAttribute('required', '');
|
|
213
|
+
} else {
|
|
214
|
+
this.postalBadgedInput?.removeAttribute('required');
|
|
215
|
+
this.postalCodeField?.removeAttribute('required');
|
|
216
|
+
this.regionBadgedInput?.removeAttribute('required');
|
|
217
|
+
this.regionField?.removeAttribute('required');
|
|
218
|
+
}
|
|
219
|
+
}}
|
|
220
|
+
>
|
|
221
|
+
${Object.keys(countries).map(key => {
|
|
222
|
+
const name = countries[key];
|
|
223
|
+
return html`
|
|
224
|
+
<option value=${key} ?selected=${key === this.selectedCountry}>${name}</option>
|
|
225
|
+
`;
|
|
226
|
+
})}
|
|
227
|
+
</select>
|
|
228
|
+
</badged-input>
|
|
229
|
+
`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** @inheritdoc */
|
|
233
|
+
createRenderRoot(): this {
|
|
234
|
+
// Render template without shadow DOM. Note that shadow DOM features like
|
|
235
|
+
// encapsulated CSS and slots are unavailable.
|
|
236
|
+
// Form autofill does not work properly in the shadow DOM
|
|
237
|
+
// so we need our form fields in the light DOM
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// reset the error state when the user focuses the input
|
|
242
|
+
private inputFocused(e: KeyboardEvent): void {
|
|
243
|
+
this.errorMessage.innerText = '';
|
|
244
|
+
const input = e.target as HTMLInputElement;
|
|
245
|
+
const inputIdentifier = input.id;
|
|
246
|
+
const badgedInput = this.querySelector(`badged-input.${inputIdentifier}`) as BadgedInput;
|
|
247
|
+
badgedInput.error = false;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
private generateInput(options: {
|
|
251
|
+
id: string;
|
|
252
|
+
placeholder: string;
|
|
253
|
+
required?: boolean;
|
|
254
|
+
fieldType?: 'text' | 'email';
|
|
255
|
+
autocomplete?: AutoCompleteFieldOptions;
|
|
256
|
+
maxlength?: number;
|
|
257
|
+
name: string;
|
|
258
|
+
icon?: TemplateResult;
|
|
259
|
+
iconSpaceOption?: SpacerOption;
|
|
260
|
+
validationPattern?: string;
|
|
261
|
+
}): TemplateResult {
|
|
262
|
+
const required = options.required ?? true;
|
|
263
|
+
const fieldType = options.fieldType ?? 'text';
|
|
264
|
+
const iconOption = options.iconSpaceOption ?? SpacerOption.LeaveSpace;
|
|
265
|
+
|
|
266
|
+
return html`
|
|
267
|
+
<badged-input
|
|
268
|
+
class=${options.id}
|
|
269
|
+
.icon=${options.icon}
|
|
270
|
+
.iconSpaceOption=${iconOption}
|
|
271
|
+
?required=${options.required}
|
|
272
|
+
>
|
|
273
|
+
<label for=${options.id}>${options.placeholder}</label>
|
|
274
|
+
<input
|
|
275
|
+
type=${fieldType}
|
|
276
|
+
id=${options.id}
|
|
277
|
+
class="donation-contact-form-input"
|
|
278
|
+
name=${options.name}
|
|
279
|
+
aria-label=${options.placeholder}
|
|
280
|
+
placeholder=${options.placeholder}
|
|
281
|
+
maxlength=${ifDefined(options.maxlength)}
|
|
282
|
+
autocomplete=${options.autocomplete ?? 'on'}
|
|
283
|
+
pattern=${ifDefined(options.validationPattern)}
|
|
284
|
+
@focus=${this.inputFocused}
|
|
285
|
+
?required=${required}
|
|
286
|
+
/>
|
|
287
|
+
</badged-input>
|
|
288
|
+
`;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
get donorContactInfo(): DonorContactInfo {
|
|
292
|
+
return new DonorContactInfo({
|
|
293
|
+
billing: this.billingInfo,
|
|
294
|
+
customer: this.contactInfo,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
get billingInfo(): BillingInfo {
|
|
299
|
+
const billingInfo = new BillingInfo({
|
|
300
|
+
streetAddress: this.streetAddressField.value,
|
|
301
|
+
extendedAddress: this.extendedAddressField.value,
|
|
302
|
+
locality: this.localityField.value,
|
|
303
|
+
region: this.regionField.value,
|
|
304
|
+
postalCode: this.postalCodeField.value,
|
|
305
|
+
countryCodeAlpha2: this.countryCodeAlpha2Field.value,
|
|
306
|
+
});
|
|
307
|
+
return billingInfo;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
get contactInfo(): CustomerInfo {
|
|
311
|
+
return new CustomerInfo({
|
|
312
|
+
email: this.emailField.value,
|
|
313
|
+
firstName: this.firstNameField.value,
|
|
314
|
+
lastName: this.lastNameField.value,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* This is not the normal LitElement styles block.
|
|
320
|
+
*
|
|
321
|
+
* This element uses the clear DOM instead of the shadow DOM so it can't use
|
|
322
|
+
* the shadowRoot's isolated styling. This is a bit of a workaround to keep all of
|
|
323
|
+
* the styling local by writing out our own <style> tag and just be careful about
|
|
324
|
+
* the selectors since they will leak outside of this component.
|
|
325
|
+
*
|
|
326
|
+
* @readonly
|
|
327
|
+
* @private
|
|
328
|
+
* @type {TemplateResult}
|
|
329
|
+
* @memberof ContactForm
|
|
330
|
+
*/
|
|
331
|
+
private get getStyles(): TemplateResult {
|
|
332
|
+
const noIconSpacerWidth = css`var(--badgedInputNoIconSpacerWidth, 3rem)`;
|
|
333
|
+
const iconSpacerWidth = css`var(--badgedInputIconSpacerWidth, 5rem)`;
|
|
334
|
+
|
|
335
|
+
const fieldSetSpacing = css`var(--fieldSetSpacing, 1rem)`;
|
|
336
|
+
const fieldFontFamily = css`var(--fontFamily, "Helvetica Neue", Helvetica, Arial, sans-serif)`;
|
|
337
|
+
const fieldFontSize = css`var(--contactFieldFontSize, 1.6rem)`;
|
|
338
|
+
const fieldFontColor = css`var(--inputFieldFontColor, #333)`;
|
|
339
|
+
|
|
340
|
+
const iconFieldWidth = css`calc(100% - ${iconSpacerWidth})`;
|
|
341
|
+
const noIconFieldWidth = css`calc(100% - ${noIconSpacerWidth})`;
|
|
342
|
+
|
|
343
|
+
return html`
|
|
344
|
+
<style>
|
|
345
|
+
/*
|
|
346
|
+
**NOTE**
|
|
347
|
+
This element is in the lightDOM so be sure to prefix all styles
|
|
348
|
+
with "contact-form" so styles don't leak.
|
|
349
|
+
*/
|
|
350
|
+
contact-form fieldset {
|
|
351
|
+
border: 0;
|
|
352
|
+
padding: 0;
|
|
353
|
+
margin: 0;
|
|
354
|
+
margin-bottom: ${fieldSetSpacing};
|
|
355
|
+
background-color: white;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/* These 1px and 0 margins in the next few selectors are to account for the
|
|
359
|
+
double outlines caused by the fields being right next to each other */
|
|
360
|
+
contact-form .row {
|
|
361
|
+
display: flex;
|
|
362
|
+
margin: -1px 0 0 0;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
contact-form fieldset .row:first-child {
|
|
366
|
+
margin-top: 0;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
contact-form badged-input.donation-contact-form-region {
|
|
370
|
+
width: 60%;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
contact-form badged-input.donation-contact-form-postal-code {
|
|
374
|
+
width: 40%;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
contact-form #donation-contact-form-region {
|
|
378
|
+
width: ${iconFieldWidth};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
contact-form #donation-contact-form-postal-code {
|
|
382
|
+
width: ${noIconFieldWidth};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
contact-form #donation-contact-form-error-message {
|
|
386
|
+
color: red;
|
|
387
|
+
font-size: 1.4rem;
|
|
388
|
+
margin-bottom: 0.6rem;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
contact-form #donation-contact-form-last-name {
|
|
392
|
+
width: ${noIconFieldWidth};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/* only show for screen readers */
|
|
396
|
+
contact-form label {
|
|
397
|
+
position: absolute;
|
|
398
|
+
left: -10000px;
|
|
399
|
+
top: auto;
|
|
400
|
+
width: 1px;
|
|
401
|
+
height: 1px;
|
|
402
|
+
overflow: hidden;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
contact-form .donation-contact-form-input {
|
|
406
|
+
width: ${iconFieldWidth};
|
|
407
|
+
border: 0;
|
|
408
|
+
outline: 0;
|
|
409
|
+
background: transparent;
|
|
410
|
+
font-weight: bold;
|
|
411
|
+
color: ${fieldFontColor};
|
|
412
|
+
font-size: ${fieldFontSize};
|
|
413
|
+
padding: 0;
|
|
414
|
+
font-family: ${fieldFontFamily};
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
contact-form .donation-contact-form-input::placeholder {
|
|
418
|
+
color: revert;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
contact-form #donation-contact-form-countryCodeAlpha2 {
|
|
422
|
+
width: calc(100%);
|
|
423
|
+
height: 100%;
|
|
424
|
+
box-sizing: border-box;
|
|
425
|
+
font-weight: bold;
|
|
426
|
+
font-size: ${fieldFontSize};
|
|
427
|
+
font-family: ${fieldFontFamily};
|
|
428
|
+
border: 0;
|
|
429
|
+
background: #fff;
|
|
430
|
+
}
|
|
431
|
+
</style>
|
|
432
|
+
`;
|
|
433
|
+
}
|
|
434
|
+
}
|