@spectare-personalisation/react 0.2.2 → 0.5.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/dist/index.cjs +429 -156
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +189 -5
- package/dist/index.d.ts +189 -5
- package/dist/index.js +357 -127
- package/dist/index.js.map +1 -1
- package/dist/tokens.css +78 -0
- package/dist/tokens.css.map +1 -0
- package/dist/tokens.d.cts +2 -0
- package/dist/tokens.d.ts +2 -0
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
|
-
type ComponentName = 'HeroStatement' | 'AtomCard' | 'StatGrid' | 'CodeBlock' | 'ComparisonTable' | 'FeatureList' | 'TestimonialCard' | 'ImageCtaHero' | 'CtaStrip';
|
|
4
|
-
type AssemblyZone = 'hero' | 'body' | 'proof' | 'cta';
|
|
3
|
+
type ComponentName = 'AnnouncementBar' | 'HeroStatement' | 'AtomCard' | 'StatGrid' | 'CodeBlock' | 'ComparisonTable' | 'FeatureList' | 'TestimonialCard' | 'ImageCtaHero' | 'CtaStrip';
|
|
4
|
+
type AssemblyZone = 'announce' | 'hero' | 'body' | 'proof' | 'cta';
|
|
5
5
|
type ComponentAssembly = Array<{
|
|
6
6
|
component: ComponentName;
|
|
7
7
|
slots?: Record<string, unknown>;
|
|
@@ -25,13 +25,130 @@ interface PersonalisedSectionProps {
|
|
|
25
25
|
audience: string;
|
|
26
26
|
stage: string;
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Seed conversion attribution with a server-rendered arrangement: pass the variantId that
|
|
30
|
+
* /api/assemble/ssr returned alongside initialAssembly. Without it, a visit where the client
|
|
31
|
+
* classification matches the server's (so no client render happens) has no variant for a
|
|
32
|
+
* later conversion to credit.
|
|
33
|
+
*/
|
|
34
|
+
initialVariantId?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Explicit visitor-typed context (e.g. a demo input box). Bypasses the session token cache
|
|
37
|
+
* and re-qualifies immediately with the direct flag, which the server cost-caps (cheaper
|
|
38
|
+
* model on a cache miss) and never writes to the shared cache.
|
|
39
|
+
*/
|
|
40
|
+
directSummary?: string;
|
|
28
41
|
/** Render only components assigned to this zone. */
|
|
29
42
|
zone?: AssemblyZone;
|
|
30
43
|
/** Alignment for statement-style components, to match the host page. */
|
|
31
44
|
align?: 'left' | 'center' | 'right';
|
|
45
|
+
/**
|
|
46
|
+
* Brand accent. Passed through to ComponentRenderer, which emits it into the scoped
|
|
47
|
+
* token set. Defaults to #60a5fa.
|
|
48
|
+
*/
|
|
49
|
+
accent?: string;
|
|
32
50
|
}
|
|
33
|
-
declare function PersonalisedSection({ orgSlug, baseUrl, brand, pageHint, className, style, initialAssembly, initialIntent, zone, align, }: PersonalisedSectionProps): react_jsx_runtime.JSX.Element | null;
|
|
51
|
+
declare function PersonalisedSection({ orgSlug, baseUrl, brand, pageHint, className, style, initialAssembly, initialIntent, initialVariantId, directSummary, zone, align, accent, }: PersonalisedSectionProps): react_jsx_runtime.JSX.Element | null;
|
|
34
52
|
|
|
53
|
+
type Unit = 'px' | 'rem';
|
|
54
|
+
type Align = 'left' | 'center' | 'right';
|
|
55
|
+
/**
|
|
56
|
+
* A single line above everything else. Deliberately the plainest component in the set: no
|
|
57
|
+
* heading, no image, no padding to speak of. A bar that draws attention to itself competes with
|
|
58
|
+
* the page it is announcing something about.
|
|
59
|
+
*
|
|
60
|
+
* Uses the accent rather than a red or amber alert colour. This is a fact worth knowing, not a
|
|
61
|
+
* warning, and a venue putting "members book from Thursday" in an alarm colour reads as a problem
|
|
62
|
+
* rather than an offer.
|
|
63
|
+
*/
|
|
64
|
+
declare function AnnouncementBar({ text, link, unit }: {
|
|
65
|
+
text?: string;
|
|
66
|
+
link?: {
|
|
67
|
+
label: string;
|
|
68
|
+
href: string;
|
|
69
|
+
};
|
|
70
|
+
unit?: Unit;
|
|
71
|
+
}): react_jsx_runtime.JSX.Element | null;
|
|
72
|
+
declare function HeroStatement({ headline, subheading, align, unit }: {
|
|
73
|
+
headline: string;
|
|
74
|
+
subheading?: string;
|
|
75
|
+
align?: Align;
|
|
76
|
+
unit?: Unit;
|
|
77
|
+
}): react_jsx_runtime.JSX.Element;
|
|
78
|
+
declare function AtomCard({ title, content, layout, stats, ctaText, ctaUrl, full, unit }: {
|
|
79
|
+
title?: string;
|
|
80
|
+
content?: string;
|
|
81
|
+
layout?: string[];
|
|
82
|
+
stats?: {
|
|
83
|
+
value: string;
|
|
84
|
+
label: string;
|
|
85
|
+
}[];
|
|
86
|
+
ctaText?: string;
|
|
87
|
+
ctaUrl?: string;
|
|
88
|
+
full?: boolean;
|
|
89
|
+
unit?: Unit;
|
|
90
|
+
}): react_jsx_runtime.JSX.Element;
|
|
91
|
+
declare function StatGrid({ stats, caption, unit }: {
|
|
92
|
+
stats?: {
|
|
93
|
+
value: string;
|
|
94
|
+
label: string;
|
|
95
|
+
}[];
|
|
96
|
+
caption?: string;
|
|
97
|
+
unit?: Unit;
|
|
98
|
+
}): react_jsx_runtime.JSX.Element;
|
|
99
|
+
declare function CodeBlock({ code, lang, caption, unit }: {
|
|
100
|
+
code: string;
|
|
101
|
+
lang?: string;
|
|
102
|
+
caption?: string;
|
|
103
|
+
unit?: Unit;
|
|
104
|
+
}): react_jsx_runtime.JSX.Element;
|
|
105
|
+
declare function ComparisonTable({ brand, competitor, rows, unit }: {
|
|
106
|
+
brand?: string;
|
|
107
|
+
competitor: string;
|
|
108
|
+
rows?: {
|
|
109
|
+
label: string;
|
|
110
|
+
spectare: string;
|
|
111
|
+
them: string;
|
|
112
|
+
}[];
|
|
113
|
+
unit?: Unit;
|
|
114
|
+
}): react_jsx_runtime.JSX.Element;
|
|
115
|
+
declare function FeatureList({ items, unit }: {
|
|
116
|
+
items?: {
|
|
117
|
+
text: string;
|
|
118
|
+
sub?: string;
|
|
119
|
+
}[];
|
|
120
|
+
unit?: Unit;
|
|
121
|
+
}): react_jsx_runtime.JSX.Element;
|
|
122
|
+
declare function TestimonialCard({ quote, name, role, company, unit }: {
|
|
123
|
+
quote: string;
|
|
124
|
+
name: string;
|
|
125
|
+
role: string;
|
|
126
|
+
company?: string;
|
|
127
|
+
unit?: Unit;
|
|
128
|
+
}): react_jsx_runtime.JSX.Element;
|
|
129
|
+
declare function ImageCtaHero({ src, alt, headline, subheading, ctaLabel, ctaHref, align, unit }: {
|
|
130
|
+
src?: string;
|
|
131
|
+
alt?: string;
|
|
132
|
+
headline?: string;
|
|
133
|
+
subheading?: string;
|
|
134
|
+
ctaLabel?: string;
|
|
135
|
+
ctaHref?: string;
|
|
136
|
+
align?: Align;
|
|
137
|
+
unit?: Unit;
|
|
138
|
+
}): react_jsx_runtime.JSX.Element | null;
|
|
139
|
+
declare function CtaStrip({ headline, primary, secondary, align, unit }: {
|
|
140
|
+
headline: string;
|
|
141
|
+
primary: {
|
|
142
|
+
label: string;
|
|
143
|
+
href: string;
|
|
144
|
+
};
|
|
145
|
+
secondary?: {
|
|
146
|
+
label: string;
|
|
147
|
+
href: string;
|
|
148
|
+
};
|
|
149
|
+
align?: Align;
|
|
150
|
+
unit?: Unit;
|
|
151
|
+
}): react_jsx_runtime.JSX.Element;
|
|
35
152
|
interface ComponentRendererProps {
|
|
36
153
|
assembly: ComponentAssembly;
|
|
37
154
|
/** Your brand name, used as the left column header in ComparisonTable. Defaults to "Us". */
|
|
@@ -46,7 +163,74 @@ interface ComponentRendererProps {
|
|
|
46
163
|
* default (HeroStatement left, CtaStrip centered).
|
|
47
164
|
*/
|
|
48
165
|
align?: 'left' | 'center' | 'right';
|
|
166
|
+
/**
|
|
167
|
+
* Brand accent, as an explicit input rather than a custom property you override and hope
|
|
168
|
+
* wins on tag order. Any CSS colour. `--sp-accent-bg` and `--sp-accent-border` are derived
|
|
169
|
+
* from it, so one value covers all three. Defaults to #60a5fa.
|
|
170
|
+
*/
|
|
171
|
+
accent?: string;
|
|
172
|
+
/**
|
|
173
|
+
* px (default) sizes components absolutely, predictable inside arbitrary host pages.
|
|
174
|
+
* rem tracks the reader's font-size preference; the root then also inherits the host's
|
|
175
|
+
* font size instead of pinning 16px.
|
|
176
|
+
*/
|
|
177
|
+
unit?: Unit;
|
|
178
|
+
/**
|
|
179
|
+
* Substitute rendering for an item: return a node to replace the built-in renderer
|
|
180
|
+
* (including null to render nothing), or undefined to keep the default. How the Spectare
|
|
181
|
+
* app swaps the card-variant AtomCard for its server-rendered card face.
|
|
182
|
+
*/
|
|
183
|
+
renderOverride?: (item: ComponentAssembly[0]) => React.ReactNode | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* Wrap each rendered item, e.g. with source attribution or a debug badge. Receives the
|
|
186
|
+
* assembly item and its rendered node; whatever it returns is placed in the layout.
|
|
187
|
+
*/
|
|
188
|
+
renderItem?: (item: ComponentAssembly[0], rendered: React.ReactNode) => React.ReactNode;
|
|
189
|
+
/** Extra attributes for the root element (e.g. a data marker a host overlay targets). */
|
|
190
|
+
rootProps?: Record<string, unknown>;
|
|
49
191
|
}
|
|
50
|
-
declare function ComponentRenderer({ assembly, brand, xray, zone, align }: ComponentRendererProps): react_jsx_runtime.JSX.Element;
|
|
192
|
+
declare function ComponentRenderer({ assembly, brand, xray, zone, align, accent, unit, renderOverride, renderItem, rootProps }: ComponentRendererProps): react_jsx_runtime.JSX.Element;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* The one place this package's design tokens are defined.
|
|
196
|
+
*
|
|
197
|
+
* Two things that are easy to get wrong here:
|
|
198
|
+
*
|
|
199
|
+
* 1. Tokens are declared on `.sp-root`, not `:root`. Declaring them at `:root` writes into
|
|
200
|
+
* the host's document, allows only one theme per page, and means a customer overriding
|
|
201
|
+
* `--sp-accent` competes with us at equal specificity so tag order decides the winner.
|
|
202
|
+
* Scoping also lets two differently themed sections sit on one page.
|
|
203
|
+
*
|
|
204
|
+
* 2. `tokens.css` must stay byte-identical to `buildTokenCss({ scope: STYLESHEET_SCOPE })`,
|
|
205
|
+
* which differs from the injected CSS in its selector and in nothing else.
|
|
206
|
+
* tests/unit/react-tokens.test.ts enforces both halves, because a customer who imports the
|
|
207
|
+
* stylesheet and a customer who renders the component must get the same page.
|
|
208
|
+
*
|
|
209
|
+
* components/ServerAssemblyRenderer.tsx in the Spectare app is a deliberate mirror of the
|
|
210
|
+
* values below. It is not the same file: that renderer uses rem, this one uses px.
|
|
211
|
+
*/
|
|
212
|
+
/** The package default. `spectare.js` and the WordPress plugin default to #2563eb, which is
|
|
213
|
+
* a live inconsistency and a brand decision rather than a technical one, so it is left alone
|
|
214
|
+
* here. Pass `accent` to override on either path. */
|
|
215
|
+
declare const DEFAULT_ACCENT = "#60a5fa";
|
|
216
|
+
/** Class the tokens are scoped to. Applied by ComponentRenderer to its own wrapper. */
|
|
217
|
+
declare const SP_ROOT = "sp-root";
|
|
218
|
+
/**
|
|
219
|
+
* Returns the stylesheet a renderer injects.
|
|
220
|
+
*
|
|
221
|
+
* @param accent brand colour. Accepts anything CSS does; `--sp-accent-bg` and
|
|
222
|
+
* `--sp-accent-border` are derived from it so a customer sets one value
|
|
223
|
+
* rather than three. Defaults to DEFAULT_ACCENT.
|
|
224
|
+
* @param unit length unit for layout rules. 'px' for this package, 'rem' for the app's
|
|
225
|
+
* server renderer, which sizes in rem throughout.
|
|
226
|
+
* @param scope selector the custom properties are declared on. Defaults to `.sp-root`, which is
|
|
227
|
+
* what a renderer injecting this at runtime wants. `tokens.css` is generated with
|
|
228
|
+
* STYLESHEET_SCOPE instead, so importing it works without a wrapper.
|
|
229
|
+
*/
|
|
230
|
+
declare function buildTokenCss({ accent, unit, scope }?: {
|
|
231
|
+
accent?: string;
|
|
232
|
+
unit?: 'px' | 'rem';
|
|
233
|
+
scope?: string;
|
|
234
|
+
}): string;
|
|
51
235
|
|
|
52
|
-
export { type AssemblyZone, type ComponentAssembly, type ComponentName, ComponentRenderer, type ComponentRendererProps, PersonalisedSection, type PersonalisedSectionProps, filterAssemblyByZone };
|
|
236
|
+
export { AnnouncementBar, type AssemblyZone, AtomCard, CodeBlock, ComparisonTable, type ComponentAssembly, type ComponentName, ComponentRenderer, type ComponentRendererProps, CtaStrip, DEFAULT_ACCENT, FeatureList, HeroStatement, ImageCtaHero, PersonalisedSection, type PersonalisedSectionProps, SP_ROOT, StatGrid, TestimonialCard, buildTokenCss, filterAssemblyByZone };
|