@kiva/kv-components 10.8.0 → 10.9.0

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.
@@ -0,0 +1,168 @@
1
+ import { toRefs as C, ref as p, computed as t } from "vue";
2
+ import E from "./KvButton.js";
3
+ import L from "./KvCheckbox.js";
4
+ import U from "./KvLightbox.js";
5
+ import A from "./KvTextInput.js";
6
+ const R = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, x = "I have read and agree to the Terms of Use and Privacy Policy", f = "Receive email updates from Kiva (including borrower updates and promos). You can unsubscribe anytime.", q = {
7
+ name: "KvCheckoutLightbox",
8
+ components: {
9
+ KvButton: E,
10
+ KvCheckbox: L,
11
+ KvLightbox: U,
12
+ KvTextInput: A
13
+ },
14
+ props: {
15
+ /**
16
+ * Whether the lightbox is shown.
17
+ */
18
+ visible: {
19
+ type: Boolean,
20
+ default: !1
21
+ },
22
+ /**
23
+ * The host is still preparing what is being paid for: the `loading` slot shows instead of
24
+ * the form and the lightbox cannot be dismissed.
25
+ */
26
+ loading: {
27
+ type: Boolean,
28
+ default: !1
29
+ },
30
+ /**
31
+ * Keep the lightbox from being dismissed. It is already locked while loading or paying.
32
+ */
33
+ preventClose: {
34
+ type: Boolean,
35
+ default: !1
36
+ },
37
+ title: {
38
+ type: String,
39
+ default: "Finalize your impact"
40
+ },
41
+ /**
42
+ * A signed-in lender skips the guest fields.
43
+ */
44
+ isLoggedIn: {
45
+ type: Boolean,
46
+ default: !1
47
+ },
48
+ /**
49
+ * The amounts are known. Until then the submit stays disabled and the "covered" note is hidden.
50
+ */
51
+ totalsLoaded: {
52
+ type: Boolean,
53
+ default: !1
54
+ },
55
+ /**
56
+ * Something is still owed: the `payment` slot and the disclaimer show, and the submit waits
57
+ * for `paymentReady`.
58
+ */
59
+ depositRequired: {
60
+ type: Boolean,
61
+ default: !1
62
+ },
63
+ /**
64
+ * The payment method in the `payment` slot is ready to be charged.
65
+ */
66
+ paymentReady: {
67
+ type: Boolean,
68
+ default: !1
69
+ },
70
+ /**
71
+ * The host is carrying out the submit: the button shows its loading state and the lightbox
72
+ * cannot be dismissed.
73
+ */
74
+ paying: {
75
+ type: Boolean,
76
+ default: !1
77
+ },
78
+ submitLabel: {
79
+ type: String,
80
+ default: "Submit my contribution"
81
+ },
82
+ /**
83
+ * Origin of the legal pages linked from the terms checkbox.
84
+ */
85
+ appUri: {
86
+ type: String,
87
+ default: "https://www.kiva.org"
88
+ },
89
+ /**
90
+ * Analytics callback: (category, action, label, property, value).
91
+ */
92
+ kvTrackFunction: {
93
+ type: Function,
94
+ default: () => {
95
+ }
96
+ },
97
+ category: {
98
+ type: String,
99
+ default: "basket"
100
+ },
101
+ /**
102
+ * Prefix for the guest email input id, so two lightboxes on a page do not share one.
103
+ */
104
+ idPrefix: {
105
+ type: String,
106
+ default: "kv-checkout"
107
+ },
108
+ /**
109
+ * Guest fields, each a v-model: `v-model:email`, `v-model:terms-agreement`,
110
+ * `v-model:email-updates`.
111
+ */
112
+ email: {
113
+ type: String,
114
+ default: ""
115
+ },
116
+ termsAgreement: {
117
+ type: Boolean,
118
+ default: !1
119
+ },
120
+ emailUpdates: {
121
+ type: Boolean,
122
+ default: !1
123
+ }
124
+ },
125
+ emits: [
126
+ "lightbox-closed",
127
+ /**
128
+ * The form is valid and the lender pressed submit; the host carries out the checkout.
129
+ */
130
+ "submit",
131
+ "update:email",
132
+ "update:termsAgreement",
133
+ "update:emailUpdates"
134
+ ],
135
+ setup(a, { emit: o }) {
136
+ const {
137
+ isLoggedIn: l,
138
+ totalsLoaded: c,
139
+ depositRequired: g,
140
+ paymentReady: v,
141
+ paying: s,
142
+ email: y,
143
+ termsAgreement: u
144
+ } = C(a), n = (e, T, S, B) => {
145
+ a.kvTrackFunction(a.category, e, T, S, B);
146
+ }, i = p(!1), r = p(!1), d = t(() => R.test(y.value.trim())), m = t(() => l.value || d.value && u.value), b = t(() => !l.value && i.value && !d.value), h = t(() => !l.value && r.value && !u.value), k = t(() => !c.value || g.value && !v.value || !m.value ? "disabled" : s.value ? "loading" : "");
147
+ return {
148
+ emailTouched: i,
149
+ emailUpdatesCopy: f,
150
+ onEmailUpdatesChange: (e) => {
151
+ o("update:emailUpdates", e), n("click", "marketing-updates", f, e ? 1 : 0);
152
+ },
153
+ onSubmit: () => {
154
+ s.value || (i.value = !0, r.value = !0, m.value && o("submit"));
155
+ },
156
+ onTermsChange: (e) => {
157
+ o("update:termsAgreement", e), n("click", "terms-of-use", x, e ? 1 : 0);
158
+ },
159
+ showEmailError: b,
160
+ showTermsError: h,
161
+ submitState: k,
162
+ track: n
163
+ };
164
+ }
165
+ };
166
+ export {
167
+ q as default
168
+ };