@orbitcommerce/constellation-docs 0.0.0-stage → 1.2.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.
- package/LICENSE.md +6 -0
- package/README.md +6 -2
- package/dist/docs.css +20787 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +308 -0
- package/dist/pages/Playground-Mk1yIWXb.js +129 -0
- package/dist/pages/_address-data-L9BR499w.js +161 -0
- package/dist/pages/_builder-demo-C0eJUmPU.js +282 -0
- package/dist/pages/_card-art-0be5ncyV.js +18 -0
- package/dist/pages/_conversation-samples-Bq7cn-4d.js +70 -0
- package/dist/pages/_figures-data-DaDvB7Nm.js +606 -0
- package/dist/pages/_foundations-blXWyYh8.js +30 -0
- package/dist/pages/_kpi-examples-DeGCBB9T.js +208 -0
- package/dist/pages/_overlays-specimens-bawR331Z.js +320 -0
- package/dist/pages/_preview-specimens-DKQC9HAo.js +153 -0
- package/dist/pages/accordion-Sg0TUqxB.js +1036 -0
- package/dist/pages/address-autocomplete-DP0PUOlK.js +360 -0
- package/dist/pages/address-block-BZOOOPA9.js +368 -0
- package/dist/pages/address-fields-CwSqro3W.js +277 -0
- package/dist/pages/ai-highlight-D3x2vD83.js +642 -0
- package/dist/pages/alert-D3i7xZTU.js +914 -0
- package/dist/pages/anchored-overlay-BV0OCu2Q.js +788 -0
- package/dist/pages/app-shell-D4hdlHps.js +1558 -0
- package/dist/pages/area-chart-BEWFwiB2.js +718 -0
- package/dist/pages/avatar-BFEqQViw.js +895 -0
- package/dist/pages/avatar-upload-BDCzJfyN.js +484 -0
- package/dist/pages/badge-0-PyMrih.js +1035 -0
- package/dist/pages/bar-chart-DkLogYlt.js +1060 -0
- package/dist/pages/bar-fold-B-3XeIDZ.js +360 -0
- package/dist/pages/board-card-D2tZY_mU.js +415 -0
- package/dist/pages/brand-mark-BqiLvFSR.js +417 -0
- package/dist/pages/button-DAyfssDY.js +715 -0
- package/dist/pages/calendar-Ds7KsgSI.js +682 -0
- package/dist/pages/canvas-stage-1KiPspkX.js +472 -0
- package/dist/pages/card-CQEM1_wc.js +1567 -0
- package/dist/pages/caret-suggestions-oHI6QvqW.js +526 -0
- package/dist/pages/chart-legend-B20AbakD.js +724 -0
- package/dist/pages/chat-composer-CwzUJYIa.js +437 -0
- package/dist/pages/checkbox-BG9Zkb6j.js +1581 -0
- package/dist/pages/checklist-card-DEyykVFS.js +783 -0
- package/dist/pages/chip-Ck-o3Ui6.js +839 -0
- package/dist/pages/chip-list-k1LxXuCi.js +414 -0
- package/dist/pages/clamp-text-n-iE8RDR.js +203 -0
- package/dist/pages/coachmark-Be2ghobT.js +366 -0
- package/dist/pages/code-block-Dv_Y5GYq.js +622 -0
- package/dist/pages/collab-field-CfqqK7d2.js +696 -0
- package/dist/pages/color-field-CZpfcA-A.js +1127 -0
- package/dist/pages/colour-q2ntvI0w.js +1974 -0
- package/dist/pages/column-mapper-TsTG39cl.js +502 -0
- package/dist/pages/combobox-DvK2j5tI.js +1334 -0
- package/dist/pages/command-palette-CJ7uBA04.js +1386 -0
- package/dist/pages/comment-box-CDSGYhr5.js +346 -0
- package/dist/pages/composer-D4B0NgpA.js +689 -0
- package/dist/pages/condition-builder-BZy2ZGXe.js +715 -0
- package/dist/pages/conflict-chooser-C--_9UIS.js +210 -0
- package/dist/pages/context-menu-F9DV30ia.js +487 -0
- package/dist/pages/copy-button-Cn7WiKRF.js +568 -0
- package/dist/pages/copy-field-D3Xt3Jq6.js +511 -0
- package/dist/pages/danger-zone-Db_UUeiP.js +564 -0
- package/dist/pages/date-input-GOW067EB.js +956 -0
- package/dist/pages/date-picker-GdBciR99.js +1569 -0
- package/dist/pages/date-time-BLKCXtVZ.js +678 -0
- package/dist/pages/delta-CNAGv8JY.js +779 -0
- package/dist/pages/description-list-BPeXn1eW.js +1268 -0
- package/dist/pages/device-switcher-BCaN99c1.js +554 -0
- package/dist/pages/dialog-CRpkRC98.js +3164 -0
- package/dist/pages/docs-lM2UBSir.js +520 -0
- package/dist/pages/doodle-nzkqi2UI.js +201 -0
- package/dist/pages/drag-ghost-B6kpzC3O.js +426 -0
- package/dist/pages/drill-menu-cskH5mol.js +490 -0
- package/dist/pages/dropzone-DOY_Rhw0.js +1069 -0
- package/dist/pages/element-toolbar-DZIhXlCJ.js +498 -0
- package/dist/pages/emoji-picker-CqaWaffD.js +235 -0
- package/dist/pages/empty-state-4U2txFpI.js +1113 -0
- package/dist/pages/facet-filters-McbBeY9e.js +353 -0
- package/dist/pages/figure-D-HF5vCj.js +563 -0
- package/dist/pages/figure-strip-BB3mNl7D.js +1364 -0
- package/dist/pages/figure-tabs-QOeQMY6N.js +578 -0
- package/dist/pages/file-chip-DMDjtlqQ.js +738 -0
- package/dist/pages/filter-pill-DzqNOsD4.js +1295 -0
- package/dist/pages/font-picker-Bqhu0QMh.js +416 -0
- package/dist/pages/form-grid-BfWCVlie.js +692 -0
- package/dist/pages/gallery-BBk2EOri.js +453 -0
- package/dist/pages/gif-picker-CnoDTCaL.js +270 -0
- package/dist/pages/gradient-editor-Bqxp7Fxj.js +378 -0
- package/dist/pages/grouped-checklist-gNZ0tBKU.js +477 -0
- package/dist/pages/heatmap-BohgIcNk.js +507 -0
- package/dist/pages/highlight-text-BfxzfmvS.js +287 -0
- package/dist/pages/home-dashboard-CxPmvduE.js +962 -0
- package/dist/pages/host-B6znjEgQ.js +109 -0
- package/dist/pages/hosted-embed-Jef3aIMP.js +163 -0
- package/dist/pages/hosted-field-BLh-53AE.js +208 -0
- package/dist/pages/hosted-field-DEpI4lVS.js +514 -0
- package/dist/pages/icon-button-Bu4Gj5sy.js +1200 -0
- package/dist/pages/icon-picker-DEyoMUTh.js +291 -0
- package/dist/pages/icon-tile-DcgxyXPF.js +592 -0
- package/dist/pages/icons-CJ9Aar3d.js +736 -0
- package/dist/pages/image-cropper-NyougqLH.js +466 -0
- package/dist/pages/image-field-7knBv4mJ.js +567 -0
- package/dist/pages/import-result-CmTtGXW_.js +486 -0
- package/dist/pages/inline-confirm-CEcI5Lxo.js +327 -0
- package/dist/pages/inline-edit-Ba39SzhM.js +1125 -0
- package/dist/pages/input-CzLCzfyx.js +2372 -0
- package/dist/pages/installation-C3UcpQJT.js +528 -0
- package/dist/pages/job-indicator-DOXWbFdl.js +755 -0
- package/dist/pages/kanban-Dy9sPAI0.js +740 -0
- package/dist/pages/kbd-UNj4zqxn.js +545 -0
- package/dist/pages/layout-primitives-CPRaZeyt.js +483 -0
- package/dist/pages/line-chart-CntWxeMF.js +1117 -0
- package/dist/pages/link-CXqvAg9z.js +689 -0
- package/dist/pages/link-picker-BMFGCC67.js +478 -0
- package/dist/pages/link-row-x8yaUuWc.js +595 -0
- package/dist/pages/live-globe-95ROMhGQ.js +715 -0
- package/dist/pages/loading-overlay-BeGuXM9G.js +456 -0
- package/dist/pages/loading-state-BNbCo51C.js +556 -0
- package/dist/pages/log-viewer-BQz8I_a2.js +503 -0
- package/dist/pages/logo-B38rnzoq.js +571 -0
- package/dist/pages/lottie_light-CxEH8eiR.js +9116 -0
- package/dist/pages/markdown-Ied72vMT.js +237 -0
- package/dist/pages/markdown-field-BfnIEKZH.js +193 -0
- package/dist/pages/media-banner-DkStCia0.js +233 -0
- package/dist/pages/menu-NrLYKqKp.js +2132 -0
- package/dist/pages/message-thread-Bo4zbxqu.js +731 -0
- package/dist/pages/meta-line-D5p2TycR.js +371 -0
- package/dist/pages/model-viewer-BfokvHoc.js +60288 -0
- package/dist/pages/model-viewer-C8PFO8wk.js +577 -0
- package/dist/pages/month-calendar-T1vw9Rup.js +457 -0
- package/dist/pages/motion-CrXtiBvA.js +865 -0
- package/dist/pages/number-input-CuyMZg18.js +968 -0
- package/dist/pages/orbit-loader-DeVBtkFE.js +219 -0
- package/dist/pages/orbit-spinner-Dxv5qAhr.js +348 -0
- package/dist/pages/otp-input-CVRoX1mw.js +591 -0
- package/dist/pages/overview-LA9XRhZc.js +130 -0
- package/dist/pages/package-dimensions-DFCyZj_T.js +192 -0
- package/dist/pages/pagination-C1EgVtW4.js +294 -0
- package/dist/pages/palette-tile-X9ZXu2Z0.js +414 -0
- package/dist/pages/password-field-DHEQKyUC.js +912 -0
- package/dist/pages/person-cell-BmjbADBz.js +564 -0
- package/dist/pages/phone-input-B3G7Qpb2.js +747 -0
- package/dist/pages/plan-card-DRaA6RuB.js +621 -0
- package/dist/pages/plan-card-DtloWvMh.js +258 -0
- package/dist/pages/plan-comparison-BVIGTtbd.js +559 -0
- package/dist/pages/plan-grid-cfPVTB5V.js +251 -0
- package/dist/pages/point-list-BbPmZjsm.js +222 -0
- package/dist/pages/popover-C3Oar9D5.js +1198 -0
- package/dist/pages/presence-avatars-CRZIk8n9.js +328 -0
- package/dist/pages/preview-frame-Bcwk0y_Q.js +1631 -0
- package/dist/pages/price-CRBLoa9h.js +604 -0
- package/dist/pages/principles-pnDyfHpK.js +483 -0
- package/dist/pages/print-page-BkLv6bW8.js +513 -0
- package/dist/pages/profile-hero-CC9dUzuN.js +498 -0
- package/dist/pages/progress-CP_awmo4.js +904 -0
- package/dist/pages/progress-ring-JuOAwk2T.js +576 -0
- package/dist/pages/radio-group-C-4tg6FS.js +1639 -0
- package/dist/pages/radius-control-B2kRA2Ch.js +441 -0
- package/dist/pages/rating-CweKN2SX.js +471 -0
- package/dist/pages/record-layout-DUP_X0RL.js +719 -0
- package/dist/pages/record-pager-y9D7JFgb.js +278 -0
- package/dist/pages/registry-BZg-xAbi.js +594 -0
- package/dist/pages/release-Cs6tl16C.js +16 -0
- package/dist/pages/repeater-BRZYKRQa.js +1351 -0
- package/dist/pages/reply-feedback-BDnHprla.js +192 -0
- package/dist/pages/reveal-BygENBbL.js +460 -0
- package/dist/pages/rich-text-DOFQZEpT.js +156 -0
- package/dist/pages/rich-text-editor-BhIM20JI.js +1265 -0
- package/dist/pages/rolldown-runtime-CbKu08Hx.js +25 -0
- package/dist/pages/rolling-number-GR3Cyfpz.js +529 -0
- package/dist/pages/row-list-Dl6CYhC-.js +1565 -0
- package/dist/pages/rule-list-DTCmIMpT.js +648 -0
- package/dist/pages/save-status-B5KkyMZP.js +378 -0
- package/dist/pages/schedule-YycI95O1.js +243 -0
- package/dist/pages/scroll-area-B2sGm23Q.js +423 -0
- package/dist/pages/search-field-D1uG7R6A.js +693 -0
- package/dist/pages/search-menu-DMuXyUUW.js +580 -0
- package/dist/pages/secret-field-Dj9x3LL8.js +337 -0
- package/dist/pages/section-rail-BtTCETS5.js +637 -0
- package/dist/pages/section-v2Pubup9.js +639 -0
- package/dist/pages/segmented-control-D-FB1K1T.js +1190 -0
- package/dist/pages/select-DZ43NpOm.js +1434 -0
- package/dist/pages/selection-chrome-Czcs6RN6.js +437 -0
- package/dist/pages/separator-CFwqRvfO.js +428 -0
- package/dist/pages/serp-preview-BGwORjmo.js +346 -0
- package/dist/pages/setting-row-Bt-dZV8H.js +913 -0
- package/dist/pages/shape-DzniHAVT.js +627 -0
- package/dist/pages/share-list-D4wgBxKN.js +926 -0
- package/dist/pages/side-panel-CCtkrZjs.js +811 -0
- package/dist/pages/site-preview-Dj1hM2Yo.js +353 -0
- package/dist/pages/skeleton-C1F5HkAu.js +1325 -0
- package/dist/pages/skip-link-BxznhSkz.js +252 -0
- package/dist/pages/slider-CAoPURKD.js +774 -0
- package/dist/pages/sortable-card-Sr44uCpI.js +424 -0
- package/dist/pages/sortable-list-DUAleYE1.js +1298 -0
- package/dist/pages/sortable-tree-BLzK-hTE.js +737 -0
- package/dist/pages/spacing-box-CtuvzxQu.js +550 -0
- package/dist/pages/sparkline-D3aavCly.js +947 -0
- package/dist/pages/split-bar-DYgZnFID.js +414 -0
- package/dist/pages/split-button-Be08-VI-.js +335 -0
- package/dist/pages/split-pane-lSNZgTKt.js +523 -0
- package/dist/pages/status-badge-DOdNhmzn.js +1074 -0
- package/dist/pages/status-checklist-CWkjCZIC.js +1152 -0
- package/dist/pages/status-dot-D99gAGsV.js +567 -0
- package/dist/pages/stepper-CxKTbEA-.js +1093 -0
- package/dist/pages/success-mark-CqFTOBEu.js +142 -0
- package/dist/pages/swatch-H_kNvHuC.js +565 -0
- package/dist/pages/switch-C93K6j9h.js +617 -0
- package/dist/pages/table-CL0vomno.js +3225 -0
- package/dist/pages/tabs-Dh0mUsLw.js +1690 -0
- package/dist/pages/tag-input-BjZWKKRJ.js +1307 -0
- package/dist/pages/task-card-Dv0sR1-w.js +295 -0
- package/dist/pages/textarea-CCM-SnGN.js +949 -0
- package/dist/pages/thumbnail-DwFJL_k1.js +1147 -0
- package/dist/pages/time-input-CA9-uZAa.js +442 -0
- package/dist/pages/time-zone-select-CEtMXVYO.js +296 -0
- package/dist/pages/timeline-BsMUTlpR.js +1798 -0
- package/dist/pages/toast-zXLRiMRT.js +1391 -0
- package/dist/pages/tool-rail-B1AbTMCP.js +355 -0
- package/dist/pages/toolbar-B9l_fHKy.js +754 -0
- package/dist/pages/tooltip-LHtCUkF-.js +826 -0
- package/dist/pages/translation-field-CTRXiF2N.js +251 -0
- package/dist/pages/tree-checklist-CJj3OcLg.js +451 -0
- package/dist/pages/tree-select-DU1qXHy_.js +492 -0
- package/dist/pages/tree-view-g_RjLtAb.js +739 -0
- package/dist/pages/typography-BSijtiRl.js +876 -0
- package/dist/pages/unit-input-Dml4fjmK.js +659 -0
- package/dist/pages/upload-rules-yozEzSah.js +419 -0
- package/dist/pages/url-upload-input-SSnMgfpA.js +307 -0
- package/dist/pages/value-change-CnubDKyO.js +489 -0
- package/dist/pages/weekly-hours-i2EpsmTx.js +287 -0
- package/dist/pages/widget-preview-CUJMyZ_k.js +625 -0
- package/dist/pages/working-status-CENemSsw.js +389 -0
- package/manifest.json +13001 -0
- package/package.json +35 -4
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, forwardRef, useContext, useMemo, useSyncExternalStore } from "react";
|
|
3
|
+
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/site/host.tsx
|
|
5
|
+
var PlainLink = forwardRef(function PlainLink(props, ref) {
|
|
6
|
+
return /* @__PURE__ */ jsx("a", {
|
|
7
|
+
ref,
|
|
8
|
+
...props
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
/** Without a host theme, mark <html> the way Constellation reads it. */
|
|
12
|
+
function setDocumentTheme(theme) {
|
|
13
|
+
document.documentElement.dataset.oTheme = theme;
|
|
14
|
+
document.documentElement.style.colorScheme = theme;
|
|
15
|
+
}
|
|
16
|
+
var DEFAULT_HOST = {
|
|
17
|
+
link: PlainLink,
|
|
18
|
+
basePath: "",
|
|
19
|
+
audience: "internal",
|
|
20
|
+
navigate: (href) => window.location.assign(href),
|
|
21
|
+
setTheme: setDocumentTheme,
|
|
22
|
+
backLink: null,
|
|
23
|
+
documentTitle: true
|
|
24
|
+
};
|
|
25
|
+
var DocsHostContext = createContext(DEFAULT_HOST);
|
|
26
|
+
function DocsHostProvider({ link, basePath, audience, navigate, setTheme, backLink, documentTitle, children }) {
|
|
27
|
+
const value = useMemo(() => ({
|
|
28
|
+
link: link ?? DEFAULT_HOST.link,
|
|
29
|
+
basePath: (basePath ?? "").replace(/\/+$/, ""),
|
|
30
|
+
audience: audience ?? DEFAULT_HOST.audience,
|
|
31
|
+
navigate: navigate ?? DEFAULT_HOST.navigate,
|
|
32
|
+
setTheme: setTheme ?? DEFAULT_HOST.setTheme,
|
|
33
|
+
backLink: backLink ?? DEFAULT_HOST.backLink,
|
|
34
|
+
documentTitle: documentTitle ?? DEFAULT_HOST.documentTitle
|
|
35
|
+
}), [
|
|
36
|
+
link,
|
|
37
|
+
basePath,
|
|
38
|
+
audience,
|
|
39
|
+
navigate,
|
|
40
|
+
setTheme,
|
|
41
|
+
backLink,
|
|
42
|
+
documentTitle
|
|
43
|
+
]);
|
|
44
|
+
return /* @__PURE__ */ jsx(DocsHostContext.Provider, {
|
|
45
|
+
value,
|
|
46
|
+
children
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function useDocsHost() {
|
|
50
|
+
return useContext(DocsHostContext);
|
|
51
|
+
}
|
|
52
|
+
/** A docs path ('/components/button#sizes') as the host's href. Anything not starting with '/' passes through. */
|
|
53
|
+
function docsHref(basePath, to) {
|
|
54
|
+
if (!to.startsWith("/")) return to;
|
|
55
|
+
const hashAt = to.indexOf("#");
|
|
56
|
+
const path = hashAt === -1 ? to : to.slice(0, hashAt);
|
|
57
|
+
const hash = hashAt === -1 ? "" : to.slice(hashAt);
|
|
58
|
+
return `${path === "/" ? basePath || "/" : `${basePath}${path}`}${hash}`;
|
|
59
|
+
}
|
|
60
|
+
/** A link to another docs page. Works with `asChild` (Button, IconButton). */
|
|
61
|
+
var DocLink = forwardRef(function DocLink({ to, ...rest }, ref) {
|
|
62
|
+
const host = useDocsHost();
|
|
63
|
+
const Link = host.link;
|
|
64
|
+
return /* @__PURE__ */ jsx(Link, {
|
|
65
|
+
ref,
|
|
66
|
+
href: docsHref(host.basePath, to),
|
|
67
|
+
...rest
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
/** Renders its children for one audience only, e.g. repo set-up notes the public docs leave out. */
|
|
71
|
+
function ForAudience({ audience, children }) {
|
|
72
|
+
return useDocsHost().audience === audience ? /* @__PURE__ */ jsx(Fragment$1, { children }) : null;
|
|
73
|
+
}
|
|
74
|
+
function readDocumentTheme() {
|
|
75
|
+
const root = document.documentElement;
|
|
76
|
+
const named = root.dataset.oTheme ?? root.dataset.theme;
|
|
77
|
+
if (named === "light" || named === "dark") return named;
|
|
78
|
+
return root.classList.contains("dark") ? "dark" : "light";
|
|
79
|
+
}
|
|
80
|
+
function subscribeToDocumentTheme(onChange) {
|
|
81
|
+
const observer = new MutationObserver(onChange);
|
|
82
|
+
observer.observe(document.documentElement, {
|
|
83
|
+
attributes: true,
|
|
84
|
+
attributeFilter: [
|
|
85
|
+
"class",
|
|
86
|
+
"data-theme",
|
|
87
|
+
"data-o-theme"
|
|
88
|
+
]
|
|
89
|
+
});
|
|
90
|
+
return () => observer.disconnect();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The theme the page is showing, read from `<html>` the way Constellation's own CSS reads it
|
|
94
|
+
* (`data-o-theme`, then `data-theme`, then a `dark` class). The server cannot know it, so a server
|
|
95
|
+
* render and the hydration after it say 'light', and the real theme follows straight away.
|
|
96
|
+
*/
|
|
97
|
+
function useDocumentTheme() {
|
|
98
|
+
return useSyncExternalStore(subscribeToDocumentTheme, readDocumentTheme, () => "light");
|
|
99
|
+
}
|
|
100
|
+
var noSubscription = () => () => {};
|
|
101
|
+
/**
|
|
102
|
+
* False on the server and while hydrating, true afterwards (and straight away in a browser-only
|
|
103
|
+
* render). For output the server cannot reproduce, such as anything drawn from today's date.
|
|
104
|
+
*/
|
|
105
|
+
function useHydrated() {
|
|
106
|
+
return useSyncExternalStore(noSubscription, () => true, () => false);
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
export { useDocsHost as a, docsHref as i, DocsHostProvider as n, useDocumentTheme as o, ForAudience as r, useHydrated as s, DocLink as t };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { t as DocLink } from "./host-B6znjEgQ.js";
|
|
3
|
+
import { d as Section, i as DocPage, l as Note, n as CodeBlock, o as Example, s as Guidelines, u as PropsTable } from "./docs-lM2UBSir.js";
|
|
4
|
+
import { n as DemoEmbed } from "./hosted-field-BLh-53AE.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
//#region src/pages/components/hosted-embed.tsx
|
|
7
|
+
function Preview() {
|
|
8
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
9
|
+
className: "hosted-demo__embed",
|
|
10
|
+
style: { width: 236 },
|
|
11
|
+
children: [/* @__PURE__ */ jsx("strong", { children: "Payouts" }), /* @__PURE__ */ jsx("span", { children: "Your next payout of £1,204.50 arrives on Friday." })]
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function Page() {
|
|
15
|
+
return /* @__PURE__ */ jsxs(DocPage, {
|
|
16
|
+
title: "Hosted embed",
|
|
17
|
+
status: "new",
|
|
18
|
+
importNames: ["HostedEmbed", "HOSTED_EMBED_LABELS"],
|
|
19
|
+
lead: "The stage for an embed another service draws, such as Stripe Connect's onboarding or payouts: one instance per client secret, the kit's spinner while it is made, an error with a retry, and a stage height so the page does not jump.",
|
|
20
|
+
children: [
|
|
21
|
+
/* @__PURE__ */ jsx(Section, {
|
|
22
|
+
id: "basics",
|
|
23
|
+
title: "Basics",
|
|
24
|
+
description: /* @__PURE__ */ jsxs("p", { children: [
|
|
25
|
+
"Give it the client ",
|
|
26
|
+
/* @__PURE__ */ jsx("code", { children: "secret" }),
|
|
27
|
+
", a ",
|
|
28
|
+
/* @__PURE__ */ jsx("code", { children: "load" }),
|
|
29
|
+
" that makes the service's instance for it, and the embed to draw with that instance. A secret can be claimed only once, so the instance is made once per secret, however often the embed mounts, and shared by every embed on the same secret. It brings no payment library:",
|
|
30
|
+
" ",
|
|
31
|
+
/* @__PURE__ */ jsx("code", { children: "load" }),
|
|
32
|
+
" is yours. Press the buttons to load a new session, or one that fails."
|
|
33
|
+
] }),
|
|
34
|
+
children: /* @__PURE__ */ jsx(Example, {
|
|
35
|
+
align: "fill",
|
|
36
|
+
clientOnly: true,
|
|
37
|
+
code: `
|
|
38
|
+
<HostedEmbed
|
|
39
|
+
secret={clientSecret}
|
|
40
|
+
load={(secret) =>
|
|
41
|
+
loadConnectAndInitialize({ publishableKey, fetchClientSecret: async () => secret, appearance, fonts: stripeFonts() })
|
|
42
|
+
}
|
|
43
|
+
onRetry={fetchNewSecret}
|
|
44
|
+
minHeight={480}
|
|
45
|
+
>
|
|
46
|
+
{(instance) => (
|
|
47
|
+
<ConnectComponentsProvider connectInstance={instance}>
|
|
48
|
+
<ConnectPayouts />
|
|
49
|
+
</ConnectComponentsProvider>
|
|
50
|
+
)}
|
|
51
|
+
</HostedEmbed>`,
|
|
52
|
+
children: /* @__PURE__ */ jsx(DemoEmbed, {})
|
|
53
|
+
})
|
|
54
|
+
}),
|
|
55
|
+
/* @__PURE__ */ jsx(Section, {
|
|
56
|
+
id: "stages",
|
|
57
|
+
title: "Loading, failing and trying again",
|
|
58
|
+
description: /* @__PURE__ */ jsxs("p", { children: [
|
|
59
|
+
"While the instance is made, the kit's ",
|
|
60
|
+
/* @__PURE__ */ jsx(DocLink, {
|
|
61
|
+
to: "/components/loading-state",
|
|
62
|
+
children: "Loading state"
|
|
63
|
+
}),
|
|
64
|
+
" sits in the middle of the stage, which keeps ",
|
|
65
|
+
/* @__PURE__ */ jsx("code", { children: "minHeight" }),
|
|
66
|
+
" (320px by default) throughout, so nothing below it moves when the embed arrives or draws itself in. A failure is the",
|
|
67
|
+
" ",
|
|
68
|
+
/* @__PURE__ */ jsx(DocLink, {
|
|
69
|
+
to: "/components/empty-state",
|
|
70
|
+
children: "Empty state"
|
|
71
|
+
}),
|
|
72
|
+
"'s error, with its words, and Try again makes the instance again. A used secret cannot be claimed twice, so give ",
|
|
73
|
+
/* @__PURE__ */ jsx("code", { children: "onRetry" }),
|
|
74
|
+
" to fetch a new one and pass it as ",
|
|
75
|
+
/* @__PURE__ */ jsx("code", { children: "secret" }),
|
|
76
|
+
". When a retry works, focus moves to the stage rather than being dropped with the button."
|
|
77
|
+
] }),
|
|
78
|
+
children: /* @__PURE__ */ jsx(CodeBlock, { code: `<HostedEmbed secret={secret} load={load} onRetry={() => refetchSecret()} onError={(error) => report(error)}>…</HostedEmbed>` })
|
|
79
|
+
}),
|
|
80
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
81
|
+
id: "accessibility",
|
|
82
|
+
title: "Accessibility",
|
|
83
|
+
children: [/* @__PURE__ */ jsx(Guidelines, { items: [
|
|
84
|
+
"While it loads, a polite status says \"Loading\" (labels.loading).",
|
|
85
|
+
"A failure is an alert, with the title, what went wrong and Try again, which stays focused and says \"Retrying\" while it runs.",
|
|
86
|
+
"When a retry works, focus moves to the stage, so a keyboard is not left on the page.",
|
|
87
|
+
"The embed itself is the service's: its focus, its dialogs and its words are drawn in its own frame."
|
|
88
|
+
] }), /* @__PURE__ */ jsxs(Note, {
|
|
89
|
+
title: "The appearance",
|
|
90
|
+
children: [
|
|
91
|
+
"Give ",
|
|
92
|
+
/* @__PURE__ */ jsx("code", { children: "load" }),
|
|
93
|
+
" the kit's look for the service: ",
|
|
94
|
+
/* @__PURE__ */ jsx("code", { children: "connectAppearance()" }),
|
|
95
|
+
" and",
|
|
96
|
+
" ",
|
|
97
|
+
/* @__PURE__ */ jsx("code", { children: "stripeFonts()" }),
|
|
98
|
+
", and ",
|
|
99
|
+
/* @__PURE__ */ jsx("code", { children: "useConnectAppearance(instance)" }),
|
|
100
|
+
" to follow a theme switch. See",
|
|
101
|
+
" ",
|
|
102
|
+
/* @__PURE__ */ jsx(DocLink, {
|
|
103
|
+
to: "/components/hosted-field#with-stripe",
|
|
104
|
+
children: "Hosted field"
|
|
105
|
+
}),
|
|
106
|
+
"."
|
|
107
|
+
]
|
|
108
|
+
})]
|
|
109
|
+
}),
|
|
110
|
+
/* @__PURE__ */ jsx(Section, {
|
|
111
|
+
id: "props",
|
|
112
|
+
title: "Props",
|
|
113
|
+
description: /* @__PURE__ */ jsx("p", { children: "Also accepts every native div attribute except children and onError." }),
|
|
114
|
+
children: /* @__PURE__ */ jsx(PropsTable, {
|
|
115
|
+
title: "HostedEmbed",
|
|
116
|
+
rows: [
|
|
117
|
+
{
|
|
118
|
+
name: "secret",
|
|
119
|
+
type: "string",
|
|
120
|
+
required: true,
|
|
121
|
+
description: "The client secret. A new one makes a new instance."
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "load",
|
|
125
|
+
type: "(secret: string) => Promise<T>",
|
|
126
|
+
required: true,
|
|
127
|
+
description: "Makes the instance for a secret. Called once per secret."
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: "children",
|
|
131
|
+
type: "(instance: T) => ReactNode",
|
|
132
|
+
required: true,
|
|
133
|
+
description: "Draws the embed with its instance."
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: "minHeight",
|
|
137
|
+
type: "number | string",
|
|
138
|
+
default: "320",
|
|
139
|
+
description: "The stage's least height, loading or loaded."
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "onRetry",
|
|
143
|
+
type: "() => void",
|
|
144
|
+
description: "Called for Try again in place of making the instance again: fetch a new secret."
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "onError",
|
|
148
|
+
type: "(error: unknown) => void",
|
|
149
|
+
description: "Called with what went wrong."
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: "labels",
|
|
153
|
+
type: "Partial<HostedEmbedLabels>",
|
|
154
|
+
description: "loading, error, errorDescription, retry and retrying. HOSTED_EMBED_LABELS is the English set."
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
]
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
export { Page, Preview };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { Button, Field, HostedEmbed, HostedField, useStripeElementStyle } from "@orbitcommerce/constellation";
|
|
5
|
+
import { CreditCardIcon } from "@orbitcommerce/constellation/icons";
|
|
6
|
+
//#region src/pages/components/_hosted-examples.tsx
|
|
7
|
+
var PLACEHOLDER = {
|
|
8
|
+
number: "1234 1234 1234 1234",
|
|
9
|
+
expiry: "MM / YY",
|
|
10
|
+
cvc: "CVC"
|
|
11
|
+
};
|
|
12
|
+
var COMPLETE_AT = {
|
|
13
|
+
number: 16,
|
|
14
|
+
expiry: 4,
|
|
15
|
+
cvc: 3
|
|
16
|
+
};
|
|
17
|
+
var NAME = {
|
|
18
|
+
number: "Card number",
|
|
19
|
+
expiry: "Expiry date",
|
|
20
|
+
cvc: "Security code"
|
|
21
|
+
};
|
|
22
|
+
/** The iframe's page: one input, styled by message, which posts its state to the frame around it. */
|
|
23
|
+
function documentFor(kind, id, value, invalid) {
|
|
24
|
+
const format = kind === "number" ? "digits.replace(/(\\d{4})(?=\\d)/g, '$1 ')" : kind === "expiry" ? "digits.length > 2 ? digits.slice(0, 2) + ' / ' + digits.slice(2) : digits" : "digits";
|
|
25
|
+
return `<!doctype html><html><head><meta charset="utf-8"><style>
|
|
26
|
+
html,body{margin:0;background:transparent;overflow:hidden}
|
|
27
|
+
input{all:unset;box-sizing:border-box;width:100%;height:20px;font:400 14px/20px var(--font, system-ui, sans-serif);color:var(--ink, CanvasText);caret-color:var(--ink, CanvasText);font-variant-numeric:tabular-nums}
|
|
28
|
+
input::placeholder{color:var(--placeholder, GrayText)}
|
|
29
|
+
input.invalid{color:var(--invalid, red)}
|
|
30
|
+
</style></head><body><input aria-label="${NAME[kind]}" inputmode="numeric" autocomplete="off" placeholder="${PLACEHOLDER[kind]}" value="${value}"${invalid ? " class=\"invalid\"" : ""}>
|
|
31
|
+
<script>
|
|
32
|
+
const input = document.querySelector('input');
|
|
33
|
+
const say = (type, extra) => parent.postMessage(Object.assign({ hosted: '${id}', type }, extra || {}), '*');
|
|
34
|
+
input.addEventListener('focus', () => say('focus'));
|
|
35
|
+
input.addEventListener('blur', () => { const digits = input.value.replace(/\\D/g, ''); const bad = digits.length > 0 && digits.length < ${COMPLETE_AT[kind]}; input.classList.toggle('invalid', bad); say('blur', { invalid: bad }) });
|
|
36
|
+
input.addEventListener('input', () => { const digits = input.value.replace(/\\D/g, '').slice(0, ${COMPLETE_AT[kind]}); input.value = ${format}; input.classList.remove('invalid'); say('change', { complete: digits.length === ${COMPLETE_AT[kind]}, empty: digits.length === 0 }) });
|
|
37
|
+
addEventListener('message', (event) => {
|
|
38
|
+
const data = event.data || {};
|
|
39
|
+
if (data.focus === '${id}') input.focus();
|
|
40
|
+
if (data.style && data.to === '${id}') for (const [name, value] of Object.entries(data.style)) document.documentElement.style.setProperty(name, value);
|
|
41
|
+
});
|
|
42
|
+
say('ready');
|
|
43
|
+
<\/script></body></html>`;
|
|
44
|
+
}
|
|
45
|
+
/** The field's style as the stand-in's CSS variables: what Stripe's own field reads from `options.style`. */
|
|
46
|
+
function variablesOf(style) {
|
|
47
|
+
const base = style.base;
|
|
48
|
+
return {
|
|
49
|
+
"--ink": String(base.color),
|
|
50
|
+
"--font": String(base.fontFamily),
|
|
51
|
+
"--placeholder": base["::placeholder"].color ?? "",
|
|
52
|
+
"--invalid": style.invalid.color ?? ""
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** A value for a pinned specimen: a full card number, or one cut short. */
|
|
56
|
+
var SPECIMEN = {
|
|
57
|
+
complete: {
|
|
58
|
+
number: "4242 4242 4242 4242",
|
|
59
|
+
expiry: "12 / 29",
|
|
60
|
+
cvc: "123"
|
|
61
|
+
},
|
|
62
|
+
invalid: {
|
|
63
|
+
number: "4242 4242 42",
|
|
64
|
+
expiry: "12",
|
|
65
|
+
cvc: "1"
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* A hosted card field: an iframe in a HostedField, wired as `useHostedField` wires a Stripe field, with the words a
|
|
70
|
+
* Field shows for it. `pinned` holds a state for the specimens, with a value typed in for complete and invalid.
|
|
71
|
+
*/
|
|
72
|
+
function DemoCardField({ kind, label, pinned, disabled }) {
|
|
73
|
+
const id = useId().replace(/[^\w-]/g, "");
|
|
74
|
+
const [spot, setSpot] = useState(null);
|
|
75
|
+
const frame = useRef(null);
|
|
76
|
+
const [state, setState] = useState({
|
|
77
|
+
focused: false,
|
|
78
|
+
complete: false,
|
|
79
|
+
invalid: false,
|
|
80
|
+
ready: false
|
|
81
|
+
});
|
|
82
|
+
const style = useStripeElementStyle({ element: spot });
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
const listen = (event) => {
|
|
85
|
+
const data = event.data;
|
|
86
|
+
if (!data || data.hosted !== id) return;
|
|
87
|
+
setState((now) => {
|
|
88
|
+
if (data.type === "ready") return {
|
|
89
|
+
...now,
|
|
90
|
+
ready: true
|
|
91
|
+
};
|
|
92
|
+
if (data.type === "focus") return {
|
|
93
|
+
...now,
|
|
94
|
+
focused: true
|
|
95
|
+
};
|
|
96
|
+
if (data.type === "blur") return {
|
|
97
|
+
...now,
|
|
98
|
+
focused: false,
|
|
99
|
+
invalid: data.invalid === true
|
|
100
|
+
};
|
|
101
|
+
if (data.type === "change") return {
|
|
102
|
+
...now,
|
|
103
|
+
complete: data.complete === true,
|
|
104
|
+
invalid: false
|
|
105
|
+
};
|
|
106
|
+
return now;
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
window.addEventListener("message", listen);
|
|
110
|
+
return () => window.removeEventListener("message", listen);
|
|
111
|
+
}, [id]);
|
|
112
|
+
const [styled, setStyled] = useState(false);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!style || !state.ready) return;
|
|
115
|
+
frame.current?.contentWindow?.postMessage({
|
|
116
|
+
to: id,
|
|
117
|
+
style: variablesOf(style)
|
|
118
|
+
}, "*");
|
|
119
|
+
setStyled(true);
|
|
120
|
+
}, [
|
|
121
|
+
style,
|
|
122
|
+
state.ready,
|
|
123
|
+
id
|
|
124
|
+
]);
|
|
125
|
+
const specimen = pinned?.complete ? SPECIMEN.complete[kind] : pinned?.invalid ? SPECIMEN.invalid[kind] : "";
|
|
126
|
+
const srcDoc = useMemo(() => documentFor(kind, id, specimen, Boolean(pinned?.invalid)), [
|
|
127
|
+
kind,
|
|
128
|
+
id,
|
|
129
|
+
specimen,
|
|
130
|
+
pinned?.invalid
|
|
131
|
+
]);
|
|
132
|
+
const error = pinned?.error ?? (state.invalid ? `Your ${NAME[kind].toLowerCase()} is incomplete.` : void 0);
|
|
133
|
+
return /* @__PURE__ */ jsx("div", {
|
|
134
|
+
ref: setSpot,
|
|
135
|
+
children: /* @__PURE__ */ jsx(Field, {
|
|
136
|
+
label,
|
|
137
|
+
messages: error ? [{
|
|
138
|
+
tone: "error",
|
|
139
|
+
text: error
|
|
140
|
+
}] : [],
|
|
141
|
+
children: /* @__PURE__ */ jsx(HostedField, {
|
|
142
|
+
icon: kind === "number" ? /* @__PURE__ */ jsx(CreditCardIcon, {}) : void 0,
|
|
143
|
+
focused: pinned?.focused ?? state.focused,
|
|
144
|
+
invalid: pinned?.invalid ?? state.invalid,
|
|
145
|
+
complete: pinned?.complete ?? state.complete,
|
|
146
|
+
ready: pinned?.ready ?? (state.ready && styled),
|
|
147
|
+
disabled,
|
|
148
|
+
onFocusRequest: () => frame.current?.contentWindow?.postMessage({ focus: id }, "*"),
|
|
149
|
+
children: pinned?.ready === false ? null : /* @__PURE__ */ jsx("iframe", {
|
|
150
|
+
ref: frame,
|
|
151
|
+
title: label,
|
|
152
|
+
srcDoc,
|
|
153
|
+
className: "hosted-demo__iframe",
|
|
154
|
+
tabIndex: disabled ? -1 : void 0
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/** A payment service's embed stand-in: loads in a moment, or fails, so every stage of the embed shows. */
|
|
161
|
+
function DemoEmbed() {
|
|
162
|
+
const [round, setRound] = useState(0);
|
|
163
|
+
const [failNext, setFailNext] = useState(false);
|
|
164
|
+
const secret = `cs_demo_${round}_${failNext ? "fail" : "ok"}`;
|
|
165
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
166
|
+
className: "hosted-demo",
|
|
167
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
168
|
+
className: "hosted-demo__controls",
|
|
169
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
170
|
+
size: "sm",
|
|
171
|
+
variant: "soft",
|
|
172
|
+
onClick: () => {
|
|
173
|
+
setFailNext(false);
|
|
174
|
+
setRound((n) => n + 1);
|
|
175
|
+
},
|
|
176
|
+
children: "Load a new session"
|
|
177
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
178
|
+
size: "sm",
|
|
179
|
+
variant: "soft",
|
|
180
|
+
onClick: () => {
|
|
181
|
+
setFailNext(true);
|
|
182
|
+
setRound((n) => n + 1);
|
|
183
|
+
},
|
|
184
|
+
children: "Load one that fails"
|
|
185
|
+
})]
|
|
186
|
+
}), /* @__PURE__ */ jsx(HostedEmbed, {
|
|
187
|
+
secret,
|
|
188
|
+
minHeight: 260,
|
|
189
|
+
load: (value) => new Promise((resolve, reject) => {
|
|
190
|
+
window.setTimeout(() => value.endsWith("fail") ? reject(/* @__PURE__ */ new Error("The account session has expired.")) : resolve({ account: "acct_harbourdesk" }), 1200);
|
|
191
|
+
}),
|
|
192
|
+
onRetry: () => {
|
|
193
|
+
setFailNext(false);
|
|
194
|
+
setRound((n) => n + 1);
|
|
195
|
+
},
|
|
196
|
+
children: (instance) => /* @__PURE__ */ jsxs("div", {
|
|
197
|
+
className: "hosted-demo__embed",
|
|
198
|
+
children: [/* @__PURE__ */ jsx("strong", { children: "Payouts" }), /* @__PURE__ */ jsxs("span", { children: [
|
|
199
|
+
"Drawn by the payment service for ",
|
|
200
|
+
instance.account,
|
|
201
|
+
". Your next payout of £1,204.50 arrives on Friday."
|
|
202
|
+
] })]
|
|
203
|
+
})
|
|
204
|
+
})]
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
export { DemoEmbed as n, DemoCardField as t };
|