@colabcommerce/elements 0.0.4 → 0.9.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.
Files changed (99) hide show
  1. package/.pnp.cjs +16484 -0
  2. package/.pnp.loader.mjs +2126 -0
  3. package/.yarn/install-state.gz +0 -0
  4. package/.yarn/releases/yarn-4.12.0.cjs +942 -0
  5. package/.yarnrc.yml +1 -0
  6. package/README.md +60 -41
  7. package/cypress/fixtures/example.json +5 -0
  8. package/cypress/support/commands.js +25 -0
  9. package/cypress/support/component-index.html +15 -0
  10. package/cypress/support/component.js +26 -0
  11. package/cypress.config.js +10 -0
  12. package/eslint.config.js +32 -0
  13. package/index.html +13 -0
  14. package/package.json +91 -67
  15. package/playground/index.html +14 -0
  16. package/playground/main.jsx +36 -0
  17. package/public/vite.svg +1 -0
  18. package/src/App.css +0 -0
  19. package/src/App.jsx +65 -0
  20. package/src/components/CollapsibleStoreHours/index.jsx +269 -0
  21. package/src/components/HoursList/index.jsx +225 -0
  22. package/src/components/LeadForm/index.jsx +241 -0
  23. package/src/components/MessageDialog/index.jsx +169 -0
  24. package/src/components/QuoteForm/index.jsx +82 -0
  25. package/src/components/QuoteFormSearch/index.jsx +276 -0
  26. package/src/components/QuoteFormStoreList/index.jsx +65 -0
  27. package/src/components/QuoteFormStoreListItem/index.jsx +134 -0
  28. package/src/components/QuoteLeadForm/index.jsx +16 -0
  29. package/src/components/QuoteMap/index.jsx +96 -0
  30. package/src/components/QuoteMapMarker/index.jsx +56 -0
  31. package/src/components/StaticMap/index.jsx +24 -0
  32. package/src/components/Store/index.jsx +44 -0
  33. package/src/components/StoreContact/index.jsx +96 -0
  34. package/src/components/StoreInfo/index.jsx +50 -0
  35. package/src/components/StoreList/index.jsx +59 -0
  36. package/src/components/StoreListItem/index.jsx +99 -0
  37. package/src/components/StoreListItem/indexStoreListItem.cy.jsx +30 -0
  38. package/src/components/StoreListNoneFound/index.jsx +16 -0
  39. package/src/components/StoreLocator/index.jsx +43 -0
  40. package/src/components/StoreLocatorMap/index.jsx +93 -0
  41. package/src/components/StoreLocatorMapMarker/index.jsx +55 -0
  42. package/src/components/StoreLocatorMessageDialog/index.jsx +20 -0
  43. package/src/components/StoreLocatorSearch/index.jsx +316 -0
  44. package/src/components/StoreMap/index.jsx +30 -0
  45. package/src/components/StoreMeta/index.jsx +7 -0
  46. package/src/components/StoreProducts/index.jsx +112 -0
  47. package/src/components/ui/Badge/index.jsx +46 -0
  48. package/src/components/ui/Button/index.jsx +56 -0
  49. package/src/components/ui/Button/indexButton.cy.jsx +9 -0
  50. package/src/components/ui/Card/index.jsx +90 -0
  51. package/src/components/ui/Input/index.jsx +19 -0
  52. package/src/components/ui/Input/indexInput.cy.jsx +9 -0
  53. package/src/components/ui/LoadingPuff/index.jsx +10 -0
  54. package/src/components/ui/Panel/index.jsx +23 -0
  55. package/src/components/ui/PhoneNumberInput/index.jsx +17 -0
  56. package/src/contexts/quote-form.jsx +94 -0
  57. package/src/contexts/store-locator.jsx +83 -0
  58. package/src/contexts/store.jsx +59 -0
  59. package/src/contexts/translations.jsx +11 -0
  60. package/src/dist.css +229 -0
  61. package/src/entries/QuoteForm.js +2 -0
  62. package/src/entries/Store.js +2 -0
  63. package/src/entries/StoreLocator.js +2 -0
  64. package/src/entries/StoreLocatorProvider.js +2 -0
  65. package/src/entries/styles.js +2 -0
  66. package/src/entries/useStoreLocator.js +2 -0
  67. package/src/i18n/defaultResources.js +19 -0
  68. package/src/i18n/index.js +44 -0
  69. package/src/i18n/mergeResources.js +22 -0
  70. package/src/index.css +214 -0
  71. package/src/lib/addressComponentsToAddress.js +43 -0
  72. package/src/lib/productSchema.js +6 -0
  73. package/src/lib/useGeolocation.js +266 -0
  74. package/src/lib/useHours.js +205 -0
  75. package/src/lib/usePlacesAutocomplete.js +288 -0
  76. package/src/lib/useProductAvailability.js +38 -0
  77. package/src/lib/useRudderAnalytics.js +50 -0
  78. package/src/lib/useSearchResults.js +102 -0
  79. package/src/lib/useStoreLocatorConfig.js +50 -0
  80. package/src/lib/utils/cn.js +6 -0
  81. package/src/lib/utils/measure.js +31 -0
  82. package/src/locales/en/default.json +58 -0
  83. package/src/locales/es/default.json +58 -0
  84. package/src/locales/fr/default.json +58 -0
  85. package/src/locales/it/default.json +58 -0
  86. package/src/main.jsx +10 -0
  87. package/vite.config.js +60 -53
  88. package/dist/CartForm.js +0 -617
  89. package/dist/Container-CU_WrBOi.js +0 -22
  90. package/dist/Modal-DTBKy_6d.js +0 -863
  91. package/dist/ProductForm.js +0 -343
  92. package/dist/Retailer.js +0 -3637
  93. package/dist/StoreLocator.js +0 -797
  94. package/dist/addressComponentsToAddress-DCL-K8mn.js +0 -1932
  95. package/dist/browser-ponyfill-DcK7_cJB.js +0 -339
  96. package/dist/globals-B8-hYoIU.js +0 -8518
  97. package/dist/index-CqSfhXDd.js +0 -137
  98. package/dist/index-FM02Uq_P.js +0 -100
  99. package/dist/style.css +0 -1
@@ -1,343 +0,0 @@
1
- import { jsx as e, jsxs as s } from "react/jsx-runtime";
2
- import { useEffect as j, useState as E, Suspense as z } from "react";
3
- import { u as F, L as H, g as R, d as D, S as Q, b as U, k as J, f as V, A as K, c as G, w as X, h as Y, e as Z } from "./addressComponentsToAddress-DCL-K8mn.js";
4
- import { L as ee, F as te, Q as oe } from "./index-CqSfhXDd.js";
5
- import { a as W, c as k, e as ae, h as b, i as ne, F as d, R as se, C as _, O as y, B as re, l as M, I as ie, m as le } from "./globals-B8-hYoIU.js";
6
- import { S as ce } from "./index-FM02Uq_P.js";
7
- const de = () => {
8
- const { locationName: m, setLocationName: l, setSearchCenter: c, setMapCenter: t, setLoadingGeo: f, getPosition: n } = F();
9
- return /* @__PURE__ */ e(
10
- H,
11
- {
12
- locationName: m,
13
- setLocationName: l,
14
- setSearchCenter: c,
15
- setMapCenter: t,
16
- handleLocate: () => {
17
- f(!0), n();
18
- }
19
- }
20
- );
21
- }, me = "_5BvSp", ue = "NnCF-", he = "OxA-3", pe = "fIWeh", C = {
22
- loading: me,
23
- itemWrapper: ue,
24
- selected: he,
25
- wrapper: pe
26
- }, fe = () => {
27
- const { t: m } = W(), { locations: l, isLoading: c, focusedLocationId: t } = F();
28
- function f(n, h) {
29
- if (!n || !h) return;
30
- const p = n.getBoundingClientRect(), i = h.getBoundingClientRect().top - p.top + n.scrollTop;
31
- n.scrollTo({
32
- top: i,
33
- behavior: "smooth"
34
- });
35
- }
36
- return j(() => {
37
- const n = document.getElementById(`location-${t}`);
38
- if (n) {
39
- const h = document.getElementById("llw");
40
- f(h, n);
41
- }
42
- }, [t]), c ? /* @__PURE__ */ e("div", { className: k(C.loading), children: /* @__PURE__ */ e("img", { src: "https://images.sofasandsectionals.com/cc/pal-loader.svg", width: "50", height: "50", alt: m("store_locator.loading") }) }) : /* @__PURE__ */ e("div", { className: k(C.wrapper), id: "llw", children: l.map((n) => /* @__PURE__ */ e("div", { className: t === n.id ? k(C.itemWrapper, C.selected) : k(C.itemWrapper), id: `location-${n.id}`, children: /* @__PURE__ */ e(ee, { id: n.id, location: n }) }, n.id)) });
43
- }, _e = "NQ6-h", ge = "_4wmyC", ve = "_9dVCP", P = {
44
- wrapper: _e,
45
- name: ge,
46
- address: ve
47
- }, Ne = () => {
48
- var S, I, q, x, w, B, o;
49
- const { cc_company_retailer_location_id: m } = R(), { distanceUnit: l, searchCenter: c, selectedLocation: t, setSelectedLocationId: f, selectedLocationId: n, setMessageModalOpen: h, setShowMap: p, setShowDetails: N } = F(), i = D({ lat: (S = t == null ? void 0 : t.address) == null ? void 0 : S.latitude, lng: (I = t == null ? void 0 : t.address) == null ? void 0 : I.longitude }, c), L = l === "km" ? i : J(i), a = Math.round(L * 10) / 10, g = (q = t == null ? void 0 : t.store_type) != null && q.includes("Studio") ? "studio" : "retailer";
50
- return !t || t.location_id === m ? null : /* @__PURE__ */ e("div", { children: /* @__PURE__ */ s("div", { className: P.wrapper, children: [
51
- /* @__PURE__ */ s("div", { className: "d-flex align-items-center justify-content-between", children: [
52
- /* @__PURE__ */ e("h3", { className: P.name, children: t == null ? void 0 : t.retailer_name }),
53
- /* @__PURE__ */ e("div", { className: "text-end", children: /* @__PURE__ */ e(Q, { type: g }) })
54
- ] }),
55
- /* @__PURE__ */ s("div", { className: "text-muted fs-6 fw-normal mt-1", children: [
56
- a,
57
- " ",
58
- l
59
- ] }),
60
- /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e(U, { hours: t == null ? void 0 : t.retailer_location_hours }) }),
61
- /* @__PURE__ */ s("address", { className: P.address, children: [
62
- /* @__PURE__ */ e("div", { children: (x = t == null ? void 0 : t.address) == null ? void 0 : x.street_line_one }),
63
- /* @__PURE__ */ s("div", { children: [
64
- (w = t == null ? void 0 : t.address) == null ? void 0 : w.city,
65
- ", ",
66
- (B = t == null ? void 0 : t.address) == null ? void 0 : B.province,
67
- " ",
68
- (o = t == null ? void 0 : t.address) == null ? void 0 : o.postal_code
69
- ] })
70
- ] })
71
- ] }) });
72
- }, be = "KsfpB", ye = "t-v-7", Ce = "UFm9T", v = {
73
- changeLocationBtn: be,
74
- submitButton: ye,
75
- successContainer: Ce
76
- }, Se = ({ id: m, product: l = null, onSuccess: c, onCancel: t, onClose: f, optInText: n }) => {
77
- l || console.warn("Colab Commerce: No product(s) provided to the ProductForm component.");
78
- const { cc_company_retailer_location_id: h } = R(), { selectedLocationId: p, setSelectedLocationId: N, searchCenter: i, setFocusedLocationId: L } = F(), { t: a } = W("default"), [g, S] = E(!1), [I, q] = E(!1), x = {
79
- firstName: "",
80
- lastName: "",
81
- email: "",
82
- phone: "",
83
- notes: ""
84
- }, w = ae().shape({
85
- firstName: b().required(a("quote_form.first_name_required")),
86
- lastName: b().required(a("quote_form.last_name_required")),
87
- email: b().email(a("quote_form.invalid_email")).required(a("quote_form.email_required")),
88
- phone: b().required(a("quote_form.phone_required")),
89
- notes: b()
90
- }), o = ne({
91
- initialValues: x,
92
- validationSchema: w,
93
- onSubmit: async (u) => {
94
- X("AIzaSyAnJmWEU1r63DiRWHkjczxzHyIEq3dhj4M");
95
- const T = await K(i == null ? void 0 : i.lat, i == null ? void 0 : i.lng), r = G(T.results[0].address_components), A = await fetch("https://api.colabcommerce.com/widget_api/leads", {
96
- method: "POST",
97
- headers: {
98
- "Content-Type": "application/json"
99
- },
100
- body: JSON.stringify({
101
- id: m,
102
- lead: {
103
- name: `${u.firstName} ${u.lastName}`,
104
- emails_attributes: [{ email: u.email }],
105
- phone_numbers_attributes: [{ phone_number: u.phone, country_code: "US" }],
106
- message: u.message,
107
- opt_in: u.optIn,
108
- location_attributes: {
109
- street_line_one: r == null ? void 0 : r.addressLine1,
110
- street_line_two: r == null ? void 0 : r.addressLine2,
111
- city: r == null ? void 0 : r.city,
112
- province: r == null ? void 0 : r.province,
113
- postal_code: r == null ? void 0 : r.postalCode,
114
- country: r == null ? void 0 : r.country,
115
- latitude: (i == null ? void 0 : i.lat) || null,
116
- longitude: (i == null ? void 0 : i.lng) || null
117
- },
118
- assignee_id: p || null,
119
- assignee_type: "CompanyRetailerLocation",
120
- lead_activities_attributes: [{
121
- type: "LeadActivity::QuoteRequest",
122
- products: [l],
123
- notes: u.notes,
124
- source_type: "Company",
125
- source_id: m
126
- }]
127
- }
128
- })
129
- });
130
- if (!A.ok) {
131
- q(!0);
132
- return;
133
- }
134
- const O = await A.json();
135
- S(!0), c && c(O);
136
- }
137
- });
138
- j(() => {
139
- const u = document.getElementById("cc-accordion-anchor");
140
- u && u.scrollIntoView({ behavior: "instant" });
141
- }, [p]);
142
- const $ = (u) => {
143
- L(u.id);
144
- };
145
- return /* @__PURE__ */ s("div", { className: "cc", children: [
146
- g && /* @__PURE__ */ e("div", { className: v.successContainer, children: /* @__PURE__ */ e("div", { className: "text-center", children: /* @__PURE__ */ e("h2", { className: "fw-bold fs-2", style: { marginBottom: "3.2rem" }, children: a("cart_form.success_title") }) }) }),
147
- !g && /* @__PURE__ */ s("div", { id: "cc-accordion-anchor", children: [
148
- !p && /* @__PURE__ */ s("div", { children: [
149
- /* @__PURE__ */ e("div", { className: "mb-3", children: /* @__PURE__ */ e(de, {}) }),
150
- /* @__PURE__ */ s("div", { className: "position-relative", children: [
151
- /* @__PURE__ */ e(V, {}),
152
- /* @__PURE__ */ e(ce, { onMarkerClick: $ })
153
- ] }),
154
- /* @__PURE__ */ e(te, {}),
155
- /* @__PURE__ */ e(fe, {})
156
- ] }),
157
- p && /* @__PURE__ */ s("div", { children: [
158
- /* @__PURE__ */ s("div", { children: [
159
- /* @__PURE__ */ s("div", { className: "d-flex align-items-center justify-content-between px-3 mb-2 fs-6", children: [
160
- /* @__PURE__ */ e("span", { className: "fw-bold", children: h === p ? "" : a("quote.selected_location.title") }),
161
- /* @__PURE__ */ e("button", { onClick: () => N(null), className: v.changeLocationBtn, children: a("quote.change_location") })
162
- ] }),
163
- /* @__PURE__ */ e("div", { className: v.selectedLocation, children: /* @__PURE__ */ e(Ne, {}) })
164
- ] }),
165
- /* @__PURE__ */ e("div", { className: "p-3", children: /* @__PURE__ */ e(d, { onSubmit: o.handleSubmit, className: v.form, children: /* @__PURE__ */ s(se, { children: [
166
- /* @__PURE__ */ e(_, { xs: 12, md: 12, children: /* @__PURE__ */ s(
167
- y,
168
- {
169
- controlId: "floatingInput",
170
- label: a("quote_form.first_name"),
171
- className: "mb-3",
172
- children: [
173
- /* @__PURE__ */ e(
174
- d.Control,
175
- {
176
- type: "text",
177
- name: "firstName",
178
- placeholder: a("quote_form.first_name_placeholder"),
179
- onChange: o.handleChange,
180
- value: o.values.firstName,
181
- className: "rounded-0",
182
- isInvalid: !!o.errors.firstName
183
- }
184
- ),
185
- /* @__PURE__ */ e(d.Control.Feedback, { type: "invalid", children: o.errors.firstName })
186
- ]
187
- }
188
- ) }),
189
- /* @__PURE__ */ e(_, { xs: 12, md: 12, children: /* @__PURE__ */ s(
190
- y,
191
- {
192
- controlId: "floatingInput",
193
- label: a("quote_form.last_name"),
194
- className: "mb-3",
195
- children: [
196
- /* @__PURE__ */ e(
197
- d.Control,
198
- {
199
- type: "text",
200
- name: "lastName",
201
- className: "rounded-0",
202
- placeholder: a("quote_form.last_name_placeholder"),
203
- onChange: o.handleChange,
204
- value: o.values.lastName,
205
- isInvalid: !!o.errors.lastName
206
- }
207
- ),
208
- /* @__PURE__ */ e(d.Control.Feedback, { type: "invalid", children: o.errors.lastName })
209
- ]
210
- }
211
- ) }),
212
- /* @__PURE__ */ e(_, { xs: 12, md: 12, children: /* @__PURE__ */ s(
213
- y,
214
- {
215
- controlId: "floatingInput",
216
- label: a("quote_form.email"),
217
- className: "mb-3",
218
- children: [
219
- /* @__PURE__ */ e(
220
- d.Control,
221
- {
222
- type: "email",
223
- name: "email",
224
- className: "rounded-0",
225
- placeholder: a("quote_form.email_placeholder"),
226
- onChange: o.handleChange,
227
- value: o.values.email,
228
- isInvalid: !!o.errors.email
229
- }
230
- ),
231
- /* @__PURE__ */ e(d.Control.Feedback, { type: "invalid", children: o.errors.email })
232
- ]
233
- }
234
- ) }),
235
- /* @__PURE__ */ e(_, { xs: 12, md: 12, children: /* @__PURE__ */ s(
236
- y,
237
- {
238
- controlId: "floatingInput",
239
- label: a("quote_form.phone"),
240
- className: "mb-3",
241
- children: [
242
- /* @__PURE__ */ e(
243
- d.Control,
244
- {
245
- type: "text",
246
- name: "phone",
247
- className: "rounded-0",
248
- placeholder: a("quote_form.phone_placeholder"),
249
- onChange: o.handleChange,
250
- value: o.values.phone,
251
- isInvalid: !!o.errors.phone
252
- }
253
- ),
254
- /* @__PURE__ */ e(d.Control.Feedback, { type: "invalid", children: o.errors.phone })
255
- ]
256
- }
257
- ) }),
258
- /* @__PURE__ */ e(_, { xs: 12, children: /* @__PURE__ */ s(
259
- y,
260
- {
261
- controlId: "floatingTextarea",
262
- label: a("quote_form.notes"),
263
- className: ["mb-3", v.textarea].join(" "),
264
- children: [
265
- /* @__PURE__ */ e(
266
- d.Control,
267
- {
268
- as: "textarea",
269
- name: "notes",
270
- className: "rounded-0",
271
- placeholder: a("quote_form.notes_placeholder"),
272
- onChange: o.handleChange,
273
- value: o.values.notes,
274
- isInvalid: !!o.errors.notes,
275
- style: { height: "100px" }
276
- }
277
- ),
278
- /* @__PURE__ */ e(d.Control.Feedback, { type: "invalid", children: o.errors.notes })
279
- ]
280
- }
281
- ) }),
282
- n && /* @__PURE__ */ s(_, { xs: 12, children: [
283
- /* @__PURE__ */ e(
284
- d.Check,
285
- {
286
- name: "optIn",
287
- type: "checkbox",
288
- label: n,
289
- className: "mb-3 fs-6",
290
- onChange: o.handleChange,
291
- isInvalid: !!o.errors.optIn
292
- }
293
- ),
294
- /* @__PURE__ */ e(d.Control.Feedback, { type: "invalid", children: o.errors.optIn })
295
- ] }),
296
- /* @__PURE__ */ s(_, { xs: 12, className: "text-start d-flex align-items-center", children: [
297
- /* @__PURE__ */ e(re, { type: "submit", variant: "dark", className: v.submitButton, disabled: g, children: o.isSubmitting ? a("quote.submitting") : a("quote_form.submit") }),
298
- I && /* @__PURE__ */ e("div", { className: "text-danger ms-2", children: a("quote_form.error") }),
299
- g && /* @__PURE__ */ e("div", { className: "text-success ms-2", children: a("quote_form.success") })
300
- ] })
301
- ] }) }) })
302
- ] })
303
- ] })
304
- ] });
305
- }, Le = ({
306
- id: m,
307
- // The entity ID for the Store Locator.
308
- locale: l,
309
- product: c,
310
- filterRetailerByStockedProduct: t = !1,
311
- filterRetailerByAvailableProduct: f = !1,
312
- optInText: n = null,
313
- onCancel: h,
314
- onClose: p,
315
- onSuccess: N
316
- }) => (j(() => {
317
- M.changeLanguage(l);
318
- }, [l]), c || (console.warn("Colab Commerce: No product(s) provided to the ProductForm component."), c = []), /* @__PURE__ */ e(z, { children: /* @__PURE__ */ e(ie, { i18n: M, children: /* @__PURE__ */ e(le, { apiKey: "AIzaSyAnJmWEU1r63DiRWHkjczxzHyIEq3dhj4M", libraries: ["places"], children: /* @__PURE__ */ e(Y, { id: m, children: /* @__PURE__ */ e(
319
- Z,
320
- {
321
- id: m,
322
- locale: l,
323
- filterRetailerByStockedProduct: t,
324
- filterRetailerByAvailableProduct: f,
325
- optInText: n,
326
- autoLocate: !0,
327
- products: [c],
328
- children: /* @__PURE__ */ e(oe, { children: /* @__PURE__ */ e(
329
- Se,
330
- {
331
- id: m,
332
- product: c,
333
- onSuccess: N,
334
- optInText: n,
335
- onCancel: h,
336
- onClose: p
337
- }
338
- ) })
339
- }
340
- ) }) }) }) }));
341
- export {
342
- Le as default
343
- };