@gait-financial/react 0.1.0 → 0.1.2
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/dist/index.cjs +239 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +115 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +208 -0
- package/dist/index.js.map +1 -0
- package/dist/register.cjs +64 -0
- package/dist/register.cjs.map +1 -0
- package/dist/register.d.cts +21 -0
- package/dist/register.d.ts +21 -0
- package/dist/register.js +38 -0
- package/dist/register.js.map +1 -0
- package/dist/wc/button.js +958 -0
- package/package.json +14 -19
- package/wc/button.js +958 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var src_exports = {};
|
|
33
|
+
__export(src_exports, {
|
|
34
|
+
GaitButton: () => GaitButton
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
|
|
38
|
+
// src/components/GaitButton.tsx
|
|
39
|
+
var import_react = __toESM(require("react"), 1);
|
|
40
|
+
|
|
41
|
+
// src/register.ts
|
|
42
|
+
var import_meta = {};
|
|
43
|
+
var loadPromise = null;
|
|
44
|
+
async function defineCustomElements(scriptUrl) {
|
|
45
|
+
if (typeof window === "undefined" || typeof customElements === "undefined") {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (customElements.get("gait-button")) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (loadPromise) {
|
|
52
|
+
return loadPromise;
|
|
53
|
+
}
|
|
54
|
+
loadPromise = new Promise((resolve, reject) => {
|
|
55
|
+
const script = document.createElement("script");
|
|
56
|
+
script.async = true;
|
|
57
|
+
if (scriptUrl) {
|
|
58
|
+
script.src = scriptUrl;
|
|
59
|
+
} else {
|
|
60
|
+
try {
|
|
61
|
+
script.src = new URL("./wc/button.js", import_meta.url).href;
|
|
62
|
+
} catch {
|
|
63
|
+
reject(new Error("[@gait-financial/react] Could not resolve bundled script. Load the web component via script tag or pass scriptUrl."));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
script.onload = () => resolve();
|
|
68
|
+
script.onerror = () => reject(new Error("[@gait-financial/react] Failed to load Gait web component script."));
|
|
69
|
+
document.head.appendChild(script);
|
|
70
|
+
});
|
|
71
|
+
return loadPromise;
|
|
72
|
+
}
|
|
73
|
+
if (typeof window !== "undefined" && typeof customElements !== "undefined") {
|
|
74
|
+
void defineCustomElements();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/components/GaitButton.tsx
|
|
78
|
+
var GaitButton = (0, import_react.forwardRef)(function GaitButton2({
|
|
79
|
+
"data-id": dataId,
|
|
80
|
+
disabled,
|
|
81
|
+
size,
|
|
82
|
+
style,
|
|
83
|
+
items,
|
|
84
|
+
priceBreakdown,
|
|
85
|
+
totalCost,
|
|
86
|
+
customer,
|
|
87
|
+
webhook,
|
|
88
|
+
merchantStoreUrl,
|
|
89
|
+
onClick,
|
|
90
|
+
onLoaded,
|
|
91
|
+
onDataProcessed,
|
|
92
|
+
onSplitFeedback,
|
|
93
|
+
onMerchantIdError,
|
|
94
|
+
onConfirm,
|
|
95
|
+
className,
|
|
96
|
+
id,
|
|
97
|
+
...rest
|
|
98
|
+
}, ref) {
|
|
99
|
+
const elementRef = (0, import_react.useRef)(null);
|
|
100
|
+
const [isReady, setIsReady] = (0, import_react.useState)(false);
|
|
101
|
+
(0, import_react.useEffect)(() => {
|
|
102
|
+
if (typeof customElements !== "undefined" && customElements.get("gait-button")) {
|
|
103
|
+
setIsReady(true);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
defineCustomElements().then(() => setIsReady(true)).catch(() => setIsReady(false));
|
|
107
|
+
}, []);
|
|
108
|
+
(0, import_react.useImperativeHandle)(ref, () => elementRef.current, []);
|
|
109
|
+
if (!isReady) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
(0, import_react.useEffect)(() => {
|
|
113
|
+
const el = elementRef.current;
|
|
114
|
+
if (!el) return;
|
|
115
|
+
if (dataId !== void 0) el.setAttribute("data-id", dataId);
|
|
116
|
+
if (size !== void 0) el.setAttribute("size", size);
|
|
117
|
+
if (disabled) {
|
|
118
|
+
el.setAttribute("disabled", "");
|
|
119
|
+
} else {
|
|
120
|
+
el.removeAttribute("disabled");
|
|
121
|
+
}
|
|
122
|
+
if (style !== void 0) {
|
|
123
|
+
const styleStr = typeof style === "string" ? style : Object.entries(style).map(
|
|
124
|
+
([k, v]) => `${k.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${v}`
|
|
125
|
+
).join("; ");
|
|
126
|
+
el.setAttribute("style", styleStr);
|
|
127
|
+
}
|
|
128
|
+
if (items !== void 0) {
|
|
129
|
+
el.setAttribute(
|
|
130
|
+
"items",
|
|
131
|
+
typeof items === "string" ? items : JSON.stringify(items)
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
if (priceBreakdown !== void 0) {
|
|
135
|
+
el.setAttribute(
|
|
136
|
+
"price-breakdown",
|
|
137
|
+
typeof priceBreakdown === "string" ? priceBreakdown : JSON.stringify(priceBreakdown)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
if (totalCost !== void 0) {
|
|
141
|
+
el.setAttribute("total-cost", String(totalCost));
|
|
142
|
+
}
|
|
143
|
+
if (customer !== void 0) {
|
|
144
|
+
el.setAttribute(
|
|
145
|
+
"customer",
|
|
146
|
+
typeof customer === "string" ? customer : JSON.stringify(customer)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
if (webhook !== void 0) {
|
|
150
|
+
el.setAttribute(
|
|
151
|
+
"webhook",
|
|
152
|
+
typeof webhook === "string" ? webhook : JSON.stringify(webhook)
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (merchantStoreUrl !== void 0) {
|
|
156
|
+
el.setAttribute("merchant-store-url", merchantStoreUrl);
|
|
157
|
+
}
|
|
158
|
+
}, [
|
|
159
|
+
dataId,
|
|
160
|
+
disabled,
|
|
161
|
+
size,
|
|
162
|
+
style,
|
|
163
|
+
items,
|
|
164
|
+
priceBreakdown,
|
|
165
|
+
totalCost,
|
|
166
|
+
customer,
|
|
167
|
+
webhook,
|
|
168
|
+
merchantStoreUrl
|
|
169
|
+
]);
|
|
170
|
+
(0, import_react.useEffect)(() => {
|
|
171
|
+
const el = elementRef.current;
|
|
172
|
+
if (!el) return;
|
|
173
|
+
const handleClick = (e) => {
|
|
174
|
+
if (onClick && e instanceof CustomEvent && e.detail) {
|
|
175
|
+
onClick(e.detail);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const handleLoaded = (e) => {
|
|
179
|
+
if (onLoaded && e instanceof CustomEvent && e.detail) {
|
|
180
|
+
onLoaded(e.detail);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const handleDataProcessed = (e) => {
|
|
184
|
+
if (onDataProcessed && e instanceof CustomEvent && e.detail) {
|
|
185
|
+
onDataProcessed(e.detail);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const handleSplitFeedback = (e) => {
|
|
189
|
+
if (onSplitFeedback && e instanceof CustomEvent && e.detail) {
|
|
190
|
+
onSplitFeedback(e.detail);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const handleMerchantIdError = (e) => {
|
|
194
|
+
if (onMerchantIdError && e instanceof CustomEvent && e.detail) {
|
|
195
|
+
onMerchantIdError(e.detail);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const handleConfirm = (e) => {
|
|
199
|
+
if (onConfirm && e instanceof CustomEvent && e.detail) {
|
|
200
|
+
onConfirm(e.detail);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
el.addEventListener("gait-click", handleClick);
|
|
204
|
+
el.addEventListener("gait-loaded", handleLoaded);
|
|
205
|
+
el.addEventListener("gait-data-processed", handleDataProcessed);
|
|
206
|
+
el.addEventListener("gait-split-feedback", handleSplitFeedback);
|
|
207
|
+
el.addEventListener("gait-merchant-id-error", handleMerchantIdError);
|
|
208
|
+
el.addEventListener("gait-confirm", handleConfirm);
|
|
209
|
+
return () => {
|
|
210
|
+
el.removeEventListener("gait-click", handleClick);
|
|
211
|
+
el.removeEventListener("gait-loaded", handleLoaded);
|
|
212
|
+
el.removeEventListener("gait-data-processed", handleDataProcessed);
|
|
213
|
+
el.removeEventListener("gait-split-feedback", handleSplitFeedback);
|
|
214
|
+
el.removeEventListener("gait-merchant-id-error", handleMerchantIdError);
|
|
215
|
+
el.removeEventListener("gait-confirm", handleConfirm);
|
|
216
|
+
};
|
|
217
|
+
}, [
|
|
218
|
+
onClick,
|
|
219
|
+
onLoaded,
|
|
220
|
+
onDataProcessed,
|
|
221
|
+
onSplitFeedback,
|
|
222
|
+
onMerchantIdError,
|
|
223
|
+
onConfirm
|
|
224
|
+
]);
|
|
225
|
+
const passthrough = {};
|
|
226
|
+
if (className) passthrough.className = className;
|
|
227
|
+
if (id) passthrough.id = id;
|
|
228
|
+
Object.assign(passthrough, rest);
|
|
229
|
+
return import_react.default.createElement("gait-button", {
|
|
230
|
+
ref: elementRef,
|
|
231
|
+
...passthrough
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
GaitButton.displayName = "GaitButton";
|
|
235
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
236
|
+
0 && (module.exports = {
|
|
237
|
+
GaitButton
|
|
238
|
+
});
|
|
239
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/components/GaitButton.tsx","../src/register.ts"],"sourcesContent":["'use client';\n\n/**\n * @gait-financial/react - React wrappers for Gait Web Components\n *\n * Usage:\n * 1. Register the Web Component (run once, e.g. in _app.tsx or layout):\n * import '@gait-financial/react/register';\n *\n * 2. Use the React components:\n * import { GaitButton } from '@gait-financial/react';\n */\n\nexport { GaitButton } from './components/GaitButton';\nexport type { GaitButtonProps } from './components/GaitButton';\n\nexport type {\n ButtonSize,\n GaitButtonItem,\n GaitPriceBreakdownItem,\n GaitCustomer,\n GaitWebhook,\n GaitClickDetail,\n GaitLoadedDetail,\n GaitDataProcessedDetail,\n GaitSplitFeedbackDetail,\n GaitMerchantIdErrorDetail,\n GaitConfirmDetail,\n} from './types';\n","'use client';\n\n/**\n * React wrapper for GaitButton Web Component\n * Maps React props to element attributes (WC uses attributes as source of truth).\n * Uses ref + useEffect for binding - no direct JSX attribute spread to avoid React's\n * string coercion of booleans/objects.\n * Waits for WC registration before rendering to avoid invisible element (race condition).\n */\n\nimport React, {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react';\nimport { defineCustomElements } from '../register';\nimport type {\n GaitButtonItem,\n GaitPriceBreakdownItem,\n GaitCustomer,\n GaitWebhook,\n GaitClickDetail,\n GaitLoadedDetail,\n GaitDataProcessedDetail,\n GaitSplitFeedbackDetail,\n GaitMerchantIdErrorDetail,\n GaitConfirmDetail,\n} from '../types';\n\nexport interface GaitButtonProps\n extends Omit<React.HTMLAttributes<HTMLElement>, 'onClick' | 'style'> {\n /** Checkout/data identity (required for payment flow) */\n 'data-id'?: string;\n /** Disable the button */\n disabled?: boolean;\n /** Button size */\n size?: 'small' | 'medium' | 'large';\n /** Inline styles - string (for WC) or React.CSSProperties */\n style?: React.CSSProperties | string;\n /** Cart/order items for split payment modal */\n items?: GaitButtonItem[] | string;\n /** Price breakdown items */\n priceBreakdown?: GaitPriceBreakdownItem[] | string;\n /** Total cost */\n totalCost?: number | string;\n /** Customer info for split payment */\n customer?: GaitCustomer | string;\n /** Webhook config for split payment callbacks */\n webhook?: GaitWebhook | string;\n /** Merchant store URL (defaults to window.location.origin) */\n merchantStoreUrl?: string;\n\n /** Button clicked */\n onClick?: (detail: GaitClickDetail) => void;\n /** Component loaded/rendered */\n onLoaded?: (detail: GaitLoadedDetail) => void;\n /** Data processed (e.g. checkoutId resolved) */\n onDataProcessed?: (detail: GaitDataProcessedDetail) => void;\n /** Split payment API feedback (success/failure) */\n onSplitFeedback?: (detail: GaitSplitFeedbackDetail) => void;\n /** Merchant ID lookup failed */\n onMerchantIdError?: (detail: GaitMerchantIdErrorDetail) => void;\n /** Pay remaining confirmed */\n onConfirm?: (detail: GaitConfirmDetail) => void;\n}\n\nconst GaitButton = forwardRef<HTMLElement, GaitButtonProps>(function GaitButton(\n {\n 'data-id': dataId,\n disabled,\n size,\n style,\n items,\n priceBreakdown,\n totalCost,\n customer,\n webhook,\n merchantStoreUrl,\n onClick,\n onLoaded,\n onDataProcessed,\n onSplitFeedback,\n onMerchantIdError,\n onConfirm,\n className,\n id,\n ...rest\n },\n ref\n) {\n const elementRef = useRef<HTMLElement>(null);\n const [isReady, setIsReady] = useState(false);\n\n // Wait for WC to be registered before rendering (avoids invisible element)\n useEffect(() => {\n if (typeof customElements !== 'undefined' && customElements.get('gait-button')) {\n setIsReady(true);\n return;\n }\n defineCustomElements().then(() => setIsReady(true)).catch(() => setIsReady(false));\n }, []);\n\n useImperativeHandle(ref, () => elementRef.current as HTMLElement, []);\n\n if (!isReady) {\n return null;\n }\n\n // Sync props to element attributes via ref (WC reads attributes)\n useEffect(() => {\n const el = elementRef.current;\n if (!el) return;\n\n if (dataId !== undefined) el.setAttribute('data-id', dataId);\n if (size !== undefined) el.setAttribute('size', size);\n\n if (disabled) {\n el.setAttribute('disabled', '');\n } else {\n el.removeAttribute('disabled');\n }\n\n if (style !== undefined) {\n const styleStr =\n typeof style === 'string'\n ? style\n : Object.entries(style)\n .map(\n ([k, v]) =>\n `${k.replace(/([A-Z])/g, '-$1').toLowerCase()}: ${v}`\n )\n .join('; ');\n el.setAttribute('style', styleStr);\n }\n\n if (items !== undefined) {\n el.setAttribute(\n 'items',\n typeof items === 'string' ? items : JSON.stringify(items)\n );\n }\n\n if (priceBreakdown !== undefined) {\n el.setAttribute(\n 'price-breakdown',\n typeof priceBreakdown === 'string'\n ? priceBreakdown\n : JSON.stringify(priceBreakdown)\n );\n }\n\n if (totalCost !== undefined) {\n el.setAttribute('total-cost', String(totalCost));\n }\n\n if (customer !== undefined) {\n el.setAttribute(\n 'customer',\n typeof customer === 'string' ? customer : JSON.stringify(customer)\n );\n }\n\n if (webhook !== undefined) {\n el.setAttribute(\n 'webhook',\n typeof webhook === 'string' ? webhook : JSON.stringify(webhook)\n );\n }\n\n if (merchantStoreUrl !== undefined) {\n el.setAttribute('merchant-store-url', merchantStoreUrl);\n }\n }, [\n dataId,\n disabled,\n size,\n style,\n items,\n priceBreakdown,\n totalCost,\n customer,\n webhook,\n merchantStoreUrl,\n ]);\n\n // Event listeners\n useEffect(() => {\n const el = elementRef.current;\n if (!el) return;\n\n const handleClick = (e: Event) => {\n if (onClick && e instanceof CustomEvent && e.detail) {\n onClick(e.detail as GaitClickDetail);\n }\n };\n const handleLoaded = (e: Event) => {\n if (onLoaded && e instanceof CustomEvent && e.detail) {\n onLoaded(e.detail as GaitLoadedDetail);\n }\n };\n const handleDataProcessed = (e: Event) => {\n if (onDataProcessed && e instanceof CustomEvent && e.detail) {\n onDataProcessed(e.detail as GaitDataProcessedDetail);\n }\n };\n const handleSplitFeedback = (e: Event) => {\n if (onSplitFeedback && e instanceof CustomEvent && e.detail) {\n onSplitFeedback(e.detail as GaitSplitFeedbackDetail);\n }\n };\n const handleMerchantIdError = (e: Event) => {\n if (onMerchantIdError && e instanceof CustomEvent && e.detail) {\n onMerchantIdError(e.detail as GaitMerchantIdErrorDetail);\n }\n };\n const handleConfirm = (e: Event) => {\n if (onConfirm && e instanceof CustomEvent && e.detail) {\n onConfirm(e.detail as GaitConfirmDetail);\n }\n };\n\n el.addEventListener('gait-click', handleClick as EventListener);\n el.addEventListener('gait-loaded', handleLoaded as EventListener);\n el.addEventListener('gait-data-processed', handleDataProcessed as EventListener);\n el.addEventListener('gait-split-feedback', handleSplitFeedback as EventListener);\n el.addEventListener('gait-merchant-id-error', handleMerchantIdError as EventListener);\n el.addEventListener('gait-confirm', handleConfirm as EventListener);\n\n return () => {\n el.removeEventListener('gait-click', handleClick as EventListener);\n el.removeEventListener('gait-loaded', handleLoaded as EventListener);\n el.removeEventListener('gait-data-processed', handleDataProcessed as EventListener);\n el.removeEventListener('gait-split-feedback', handleSplitFeedback as EventListener);\n el.removeEventListener('gait-merchant-id-error', handleMerchantIdError as EventListener);\n el.removeEventListener('gait-confirm', handleConfirm as EventListener);\n };\n }, [\n onClick,\n onLoaded,\n onDataProcessed,\n onSplitFeedback,\n onMerchantIdError,\n onConfirm,\n ]);\n\n const passthrough: Record<string, unknown> = {};\n if (className) passthrough.className = className;\n if (id) passthrough.id = id;\n Object.assign(passthrough, rest);\n\n return React.createElement('gait-button', {\n ref: elementRef,\n ...passthrough,\n });\n});\n\nGaitButton.displayName = 'GaitButton';\n\nexport { GaitButton };\n","/**\n * Registers Gait Web Components in the browser.\n * Safe to call in SSR environments - no-op when window/customElements unavailable.\n *\n * Usage:\n * import '@gait-financial/react/register'; // Side-effect: registers when in browser\n * // or\n * import { defineCustomElements } from '@gait-financial/react/register';\n * await defineCustomElements(); // Optional: load from custom URL\n */\n\nlet loadPromise: Promise<void> | null = null;\n\n/**\n * Loads and registers Gait Web Components.\n * In browser: loads the WC script if not already registered.\n * In SSR: no-op.\n * Deduplicated: multiple calls return the same promise.\n *\n * @param scriptUrl - Optional URL to the button.js script. If omitted, uses the bundled script.\n */\nexport async function defineCustomElements(\n scriptUrl?: string\n): Promise<void> {\n if (typeof window === 'undefined' || typeof customElements === 'undefined') {\n return;\n }\n if (customElements.get('gait-button')) {\n return;\n }\n if (loadPromise) {\n return loadPromise;\n }\n\n loadPromise = new Promise<void>((resolve, reject) => {\n const script = document.createElement('script');\n script.async = true;\n\n if (scriptUrl) {\n script.src = scriptUrl;\n } else {\n // Use bundled script - path relative to this module\n try {\n script.src = new URL('./wc/button.js', import.meta.url).href;\n } catch {\n reject(new Error('[@gait-financial/react] Could not resolve bundled script. Load the web component via script tag or pass scriptUrl.'));\n return;\n }\n }\n\n script.onload = () => resolve();\n script.onerror = () =>\n reject(new Error('[@gait-financial/react] Failed to load Gait web component script.'));\n document.head.appendChild(script);\n });\n return loadPromise;\n}\n\n// Side-effect: auto-register when imported in browser (SSR-safe)\nif (typeof window !== 'undefined' &&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ACzC;AAAA,IACF;AAEA,OAAG,iBAAiB,cAAc,WAA4B;AAC9D,OAAG,iBAAiB,eAAe,YAA6B;AAChE,OAAG,iBAAiB,uBAAuB,mBAAoC;AAC/E,OAAG,iBAAiB,uBAAuB,mBAAoC;AAC/E,OAAG,iBAAiB,0BAA0B,qBAAsC;AACpF,OAAG,iBAAiB,gBAAgB,aAA8B;AAElE,WAAO,MAAM;AACX,SAAG,oBAAoB,cAAc,WAA4B;AACjE,SAAG,oBAAoB,eAAe,YAA6B;AACnE,SAAG,oBAAoB,uBAAuB,mBAAoC;AAClF,SAAG,oBAAoB,uBAAuB,mBAAoC;AAClF,SAAG,oBAAoB,0BAA0B,qBAAsC;AACvF,SAAG,oBAAoB,gBAAgB,aAA8B;AAAA,IACvE;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,cAAuC,CAAC;AAC9C,MAAI,UAAW,aAAY,YAAY;AACvC,MAAI,GAAI,aAAY,KAAK;AACzB,SAAO,OAAO,aAAa,IAAI;AAE/B,SAAO,aAAAC,QAAM,cAAc,eAAe;AAAA,IACxC,KAAK;AAAA,IACL,GAAG;AAAA,EACL,CAAC;AACH,CAAC;AAED,WAAW,cAAc;","names":["GaitButton","React"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared types for Gait React components
|
|
5
|
+
* Mirrors the Web Component API (source of truth)
|
|
6
|
+
*/
|
|
7
|
+
type ButtonSize = 'small' | 'medium' | 'large';
|
|
8
|
+
interface GaitButtonItem {
|
|
9
|
+
name: string;
|
|
10
|
+
image: string;
|
|
11
|
+
id: string;
|
|
12
|
+
quantity: number;
|
|
13
|
+
category?: string;
|
|
14
|
+
price: number;
|
|
15
|
+
}
|
|
16
|
+
interface GaitPriceBreakdownItem {
|
|
17
|
+
name: string;
|
|
18
|
+
price: number | string;
|
|
19
|
+
}
|
|
20
|
+
interface GaitCustomer {
|
|
21
|
+
email: string;
|
|
22
|
+
name?: string;
|
|
23
|
+
}
|
|
24
|
+
interface GaitWebhook {
|
|
25
|
+
url: string;
|
|
26
|
+
body?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/** gait-click event detail */
|
|
29
|
+
interface GaitClickDetail {
|
|
30
|
+
label: string;
|
|
31
|
+
dataId: string | null;
|
|
32
|
+
dataAttributes: Record<string, string>;
|
|
33
|
+
timestamp: string;
|
|
34
|
+
}
|
|
35
|
+
/** gait-loaded event detail */
|
|
36
|
+
interface GaitLoadedDetail {
|
|
37
|
+
attributes: Record<string, string | null>;
|
|
38
|
+
dataId: string | null;
|
|
39
|
+
dataAttributes: Record<string, string>;
|
|
40
|
+
label: string;
|
|
41
|
+
size: ButtonSize;
|
|
42
|
+
disabled: boolean;
|
|
43
|
+
timestamp: string;
|
|
44
|
+
}
|
|
45
|
+
/** gait-data-processed event detail */
|
|
46
|
+
interface GaitDataProcessedDetail {
|
|
47
|
+
id?: string;
|
|
48
|
+
timestamp: string;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
}
|
|
51
|
+
/** gait-split-feedback event detail */
|
|
52
|
+
interface GaitSplitFeedbackDetail {
|
|
53
|
+
success: boolean;
|
|
54
|
+
message?: string;
|
|
55
|
+
data?: unknown;
|
|
56
|
+
error?: string;
|
|
57
|
+
timestamp: string;
|
|
58
|
+
}
|
|
59
|
+
/** gait-merchant-id-error event detail */
|
|
60
|
+
interface GaitMerchantIdErrorDetail {
|
|
61
|
+
message: string;
|
|
62
|
+
timestamp: string;
|
|
63
|
+
}
|
|
64
|
+
/** gait-confirm event detail */
|
|
65
|
+
interface GaitConfirmDetail {
|
|
66
|
+
merchantId: string;
|
|
67
|
+
splitId: string;
|
|
68
|
+
paymentId: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* React wrapper for GaitButton Web Component
|
|
73
|
+
* Maps React props to element attributes (WC uses attributes as source of truth).
|
|
74
|
+
* Uses ref + useEffect for binding - no direct JSX attribute spread to avoid React's
|
|
75
|
+
* string coercion of booleans/objects.
|
|
76
|
+
* Waits for WC registration before rendering to avoid invisible element (race condition).
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
interface GaitButtonProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onClick' | 'style'> {
|
|
80
|
+
/** Checkout/data identity (required for payment flow) */
|
|
81
|
+
'data-id'?: string;
|
|
82
|
+
/** Disable the button */
|
|
83
|
+
disabled?: boolean;
|
|
84
|
+
/** Button size */
|
|
85
|
+
size?: 'small' | 'medium' | 'large';
|
|
86
|
+
/** Inline styles - string (for WC) or React.CSSProperties */
|
|
87
|
+
style?: React.CSSProperties | string;
|
|
88
|
+
/** Cart/order items for split payment modal */
|
|
89
|
+
items?: GaitButtonItem[] | string;
|
|
90
|
+
/** Price breakdown items */
|
|
91
|
+
priceBreakdown?: GaitPriceBreakdownItem[] | string;
|
|
92
|
+
/** Total cost */
|
|
93
|
+
totalCost?: number | string;
|
|
94
|
+
/** Customer info for split payment */
|
|
95
|
+
customer?: GaitCustomer | string;
|
|
96
|
+
/** Webhook config for split payment callbacks */
|
|
97
|
+
webhook?: GaitWebhook | string;
|
|
98
|
+
/** Merchant store URL (defaults to window.location.origin) */
|
|
99
|
+
merchantStoreUrl?: string;
|
|
100
|
+
/** Button clicked */
|
|
101
|
+
onClick?: (detail: GaitClickDetail) => void;
|
|
102
|
+
/** Component loaded/rendered */
|
|
103
|
+
onLoaded?: (detail: GaitLoadedDetail) => void;
|
|
104
|
+
/** Data processed (e.g. checkoutId resolved) */
|
|
105
|
+
onDataProcessed?: (detail: GaitDataProcessedDetail) => void;
|
|
106
|
+
/** Split payment API feedback (success/failure) */
|
|
107
|
+
onSplitFeedback?: (detail: GaitSplitFeedbackDetail) => void;
|
|
108
|
+
/** Merchant ID lookup failed */
|
|
109
|
+
onMerchantIdError?: (detail: GaitMerchantIdErrorDetail) => void;
|
|
110
|
+
/** Pay remaining confirmed */
|
|
111
|
+
onConfirm?: (detail: GaitConfirmDetail) => void;
|
|
112
|
+
}
|
|
113
|
+
declare const GaitButton: React.ForwardRefExoticComponent<GaitButtonProps & React.RefAttributes<HTMLElement>>;
|
|
114
|
+
|
|
115
|
+
export { type ButtonSize, GaitButton, type GaitButtonItem, type GaitButtonProps, type GaitClickDetail, type GaitConfirmDetail, type GaitCustomer, type GaitDataProcessedDetail, type GaitLoadedDetail, type GaitMerchantIdErrorDetail, type GaitPriceBreakdownItem, type GaitSplitFeedbackDetail, type GaitWebhook };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared types for Gait React components
|
|
5
|
+
* Mirrors the Web Component API (source of truth)
|
|
6
|
+
*/
|
|
7
|
+
type ButtonSize = 'small' | 'medium' | 'large';
|
|
8
|
+
interface GaitButtonItem {
|
|
9
|
+
name: string;
|
|
10
|
+
image: string;
|
|
11
|
+
id: string;
|
|
12
|
+
quantity: number;
|
|
13
|
+
category?: string;
|
|
14
|
+
price: number;
|
|
15
|
+
}
|
|
16
|
+
interface GaitPriceBreakdownItem {
|
|
17
|
+
name: string;
|
|
18
|
+
price: number | string;
|
|
19
|
+
}
|
|
20
|
+
interface GaitCustomer {
|
|
21
|
+
email: string;
|
|
22
|
+
name?: string;
|
|
23
|
+
}
|
|
24
|
+
interface GaitWebhook {
|
|
25
|
+
url: string;
|
|
26
|
+
body?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/** gait-click event detail */
|
|
29
|
+
interface GaitClickDetail {
|
|
30
|
+
label: string;
|
|
31
|
+
dataId: string | null;
|
|
32
|
+
dataAttributes: Record<string, string>;
|
|
33
|
+
timestamp: string;
|
|
34
|
+
}
|
|
35
|
+
/** gait-loaded event detail */
|
|
36
|
+
interface GaitLoadedDetail {
|
|
37
|
+
attributes: Record<string, string | null>;
|
|
38
|
+
dataId: string | null;
|
|
39
|
+
dataAttributes: Record<string, string>;
|
|
40
|
+
label: string;
|
|
41
|
+
size: ButtonSize;
|
|
42
|
+
disabled: boolean;
|
|
43
|
+
timestamp: string;
|
|
44
|
+
}
|
|
45
|
+
/** gait-data-processed event detail */
|
|
46
|
+
interface GaitDataProcessedDetail {
|
|
47
|
+
id?: string;
|
|
48
|
+
timestamp: string;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
}
|
|
51
|
+
/** gait-split-feedback event detail */
|
|
52
|
+
interface GaitSplitFeedbackDetail {
|
|
53
|
+
success: boolean;
|
|
54
|
+
message?: string;
|
|
55
|
+
data?: unknown;
|
|
56
|
+
error?: string;
|
|
57
|
+
timestamp: string;
|
|
58
|
+
}
|
|
59
|
+
/** gait-merchant-id-error event detail */
|
|
60
|
+
interface GaitMerchantIdErrorDetail {
|
|
61
|
+
message: string;
|
|
62
|
+
timestamp: string;
|
|
63
|
+
}
|
|
64
|
+
/** gait-confirm event detail */
|
|
65
|
+
interface GaitConfirmDetail {
|
|
66
|
+
merchantId: string;
|
|
67
|
+
splitId: string;
|
|
68
|
+
paymentId: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* React wrapper for GaitButton Web Component
|
|
73
|
+
* Maps React props to element attributes (WC uses attributes as source of truth).
|
|
74
|
+
* Uses ref + useEffect for binding - no direct JSX attribute spread to avoid React's
|
|
75
|
+
* string coercion of booleans/objects.
|
|
76
|
+
* Waits for WC registration before rendering to avoid invisible element (race condition).
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
interface GaitButtonProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onClick' | 'style'> {
|
|
80
|
+
/** Checkout/data identity (required for payment flow) */
|
|
81
|
+
'data-id'?: string;
|
|
82
|
+
/** Disable the button */
|
|
83
|
+
disabled?: boolean;
|
|
84
|
+
/** Button size */
|
|
85
|
+
size?: 'small' | 'medium' | 'large';
|
|
86
|
+
/** Inline styles - string (for WC) or React.CSSProperties */
|
|
87
|
+
style?: React.CSSProperties | string;
|
|
88
|
+
/** Cart/order items for split payment modal */
|
|
89
|
+
items?: GaitButtonItem[] | string;
|
|
90
|
+
/** Price breakdown items */
|
|
91
|
+
priceBreakdown?: GaitPriceBreakdownItem[] | string;
|
|
92
|
+
/** Total cost */
|
|
93
|
+
totalCost?: number | string;
|
|
94
|
+
/** Customer info for split payment */
|
|
95
|
+
customer?: GaitCustomer | string;
|
|
96
|
+
/** Webhook config for split payment callbacks */
|
|
97
|
+
webhook?: GaitWebhook | string;
|
|
98
|
+
/** Merchant store URL (defaults to window.location.origin) */
|
|
99
|
+
merchantStoreUrl?: string;
|
|
100
|
+
/** Button clicked */
|
|
101
|
+
onClick?: (detail: GaitClickDetail) => void;
|
|
102
|
+
/** Component loaded/rendered */
|
|
103
|
+
onLoaded?: (detail: GaitLoadedDetail) => void;
|
|
104
|
+
/** Data processed (e.g. checkoutId resolved) */
|
|
105
|
+
onDataProcessed?: (detail: GaitDataProcessedDetail) => void;
|
|
106
|
+
/** Split payment API feedback (success/failure) */
|
|
107
|
+
onSplitFeedback?: (detail: GaitSplitFeedbackDetail) => void;
|
|
108
|
+
/** Merchant ID lookup failed */
|
|
109
|
+
onMerchantIdError?: (detail: GaitMerchantIdErrorDetail) => void;
|
|
110
|
+
/** Pay remaining confirmed */
|
|
111
|
+
onConfirm?: (detail: GaitConfirmDetail) => void;
|
|
112
|
+
}
|
|
113
|
+
declare const GaitButton: React.ForwardRefExoticComponent<GaitButtonProps & React.RefAttributes<HTMLElement>>;
|
|
114
|
+
|
|
115
|
+
export { type ButtonSize, GaitButton, type GaitButtonItem, type GaitButtonProps, type GaitClickDetail, type GaitConfirmDetail, type GaitCustomer, type GaitDataProcessedDetail, type GaitLoadedDetail, type GaitMerchantIdErrorDetail, type GaitPriceBreakdownItem, type GaitSplitFeedbackDetail, type GaitWebhook };
|