@flamingo-stack/openframe-frontend-core 0.0.795 → 0.0.796
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/build/export-map.json +1 -1
- package/dist/{chunk-FYHXMHY6.cjs → chunk-6JCTKXHX.cjs} +13 -13
- package/dist/{chunk-HXL7AUPG.cjs → chunk-6WXP5IKR.cjs} +16 -16
- package/dist/{chunk-6VP5UWZG.cjs → chunk-7SEY3FDF.cjs} +2 -2
- package/dist/{chunk-BFCGOHQG.cjs → chunk-7VU4HHUR.cjs} +32 -32
- package/dist/{chunk-43ZVXQJK.cjs → chunk-CC7NRWRF.cjs} +48 -48
- package/dist/{chunk-72NE4G63.cjs → chunk-CFXCCQ6T.cjs} +2 -2
- package/dist/{chunk-RPC4P7GY.cjs → chunk-F64GLU75.cjs} +33 -33
- package/dist/{chunk-PQIWR4Q2.cjs → chunk-G24OX7AC.cjs} +16 -16
- package/dist/{chunk-7VXMO4XJ.cjs → chunk-GP7NV6BK.cjs} +3 -1
- package/dist/{chunk-6TUI5KQS.cjs → chunk-II4A2RUG.cjs} +41 -41
- package/dist/{chunk-ZCMXBX4Z.cjs → chunk-IONS6HDF.cjs} +5 -5
- package/dist/{chunk-4BYNNQBC.cjs → chunk-JC43ULIC.cjs} +71 -71
- package/dist/{chunk-FYPVCCCV.cjs → chunk-JGURZROB.cjs} +27 -27
- package/dist/{chunk-FOWQ4XTB.cjs → chunk-N3J4U7ML.cjs} +2 -2
- package/dist/{chunk-IJ23KNYI.cjs → chunk-NAJ24ODA.cjs} +4 -4
- package/dist/{chunk-F73DM65J.cjs → chunk-NRAH3M66.cjs} +46 -46
- package/dist/{chunk-3XAFK4WH.cjs → chunk-OKAHKZP2.cjs} +8 -8
- package/dist/{chunk-2KLYMAHF.cjs → chunk-PALMLL5T.cjs} +4 -4
- package/dist/{chunk-CLEZ6TWZ.cjs → chunk-QCN46LDL.cjs} +69 -69
- package/dist/{chunk-YPKAMHYA.cjs → chunk-QMDXG3VF.cjs} +574 -457
- package/dist/{chunk-BIYLAAFI.cjs → chunk-TUD7BV6O.cjs} +9 -9
- package/dist/{chunk-OK467OQJ.cjs → chunk-UYOGZJPE.cjs} +4 -4
- package/dist/{chunk-IQTVKPRG.cjs → chunk-VUP7ZGZS.cjs} +20 -20
- package/dist/{chunk-YYKXX5NA.cjs → chunk-VYXNGADV.cjs} +24 -24
- package/dist/{chunk-A6E5ZNQR.cjs → chunk-W4QITOT7.cjs} +5 -5
- package/dist/{chunk-NGGEYE5R.cjs → chunk-XFJ7BZDJ.cjs} +5 -5
- package/dist/{chunk-U4D4ABXK.cjs → chunk-XVVQJXOA.cjs} +39 -39
- package/dist/{chunk-QDW64E6T.cjs → chunk-Y3IMXLLL.cjs} +143 -143
- package/dist/{chunk-NIW4ETGC.cjs → chunk-YFHKBIZT.cjs} +6 -6
- package/dist/{chunk-KQPU5N7T.cjs → chunk-ZMWSN2BD.cjs} +11 -11
- package/dist/{chunk-ZIMPE7D5.cjs → chunk-ZRME3A2D.cjs} +3 -3
- package/dist/{cloud-tenants-Z3AYAXF5.cjs → cloud-tenants-BQUWLMYY.cjs} +12 -12
- package/dist/components/case-studies/index.cjs +26 -26
- package/dist/components/chat/index.cjs +9 -9
- package/dist/components/contact/index.cjs +13 -13
- package/dist/components/docs/index.cjs +16 -16
- package/dist/components/embeds/index.cjs +13 -13
- package/dist/components/faq/index.cjs +14 -14
- package/dist/components/features/index.cjs +12 -12
- package/dist/components/help-center-pages/index.cjs +98 -98
- package/dist/components/index.cjs +82 -68
- package/dist/components/meeting-scheduler/index.cjs +72 -72
- package/dist/components/navigation/index.cjs +15 -15
- package/dist/components/onboarding-guides/index.cjs +15 -15
- package/dist/components/product-demo/index.cjs +23 -23
- package/dist/components/related-content/index.cjs +7 -7
- package/dist/components/tickets/index.cjs +19 -19
- package/dist/components/ui/floating-tooltip.d.ts.map +1 -1
- package/dist/components/ui/floating-tooltip.js +3 -1
- package/dist/components/ui/index.cjs +26 -12
- package/dist/components/ui/index.d.ts +1 -0
- package/dist/components/ui/index.d.ts.map +1 -1
- package/dist/components/ui/index.js +9 -1
- package/dist/components/ui/trendline.d.ts +60 -0
- package/dist/components/ui/trendline.d.ts.map +1 -0
- package/dist/components/ui/trendline.js +121 -0
- package/dist/{devices-P6XQL23S.cjs → devices-BFQOLI3D.cjs} +13 -13
- package/dist/{embeddable-chat-6BNLOSBB.cjs → embeddable-chat-INYF23ST.cjs} +74 -74
- package/dist/index.cjs +31 -17
- package/dist/{knowledge-IU5ORU7U.cjs → knowledge-GGYWTYTP.cjs} +13 -13
- package/dist/{logs-DCFTQVKA.cjs → logs-NO55PTIO.cjs} +20 -20
- package/dist/{policies-ESC6XCVH.cjs → policies-AAFYTVOJ.cjs} +16 -16
- package/dist/{remote-session-4ZNTOLOQ.cjs → remote-session-2CNWLF3P.cjs} +7 -7
- package/dist/{scripts-24PIP2VO.cjs → scripts-H4ECJ65X.cjs} +19 -19
- package/dist/{software-update-47GDTKMI.cjs → software-update-NEEGQBK3.cjs} +16 -16
- package/dist/{tickets-board-X4GHEKPB.cjs → tickets-board-CXYRAMDL.cjs} +8 -8
- package/package.json +1 -1
- package/src/components/ui/floating-tooltip.tsx +4 -1
- package/src/components/ui/index.ts +1 -0
- package/src/components/ui/trendline.tsx +221 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { MouseEvent, ReactNode } from 'react';
|
|
4
|
+
import { formatNumber } from '../../utils/format';
|
|
5
|
+
import { TextLineSkeleton, UnifiedSkeleton } from '../loading/unified-skeleton';
|
|
6
|
+
import { FloatingTooltip } from './floating-tooltip';
|
|
7
|
+
import { LoadingWhen, useLoadingScope } from './loading-scope';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* THE trend beside a number: a small trendline of its recent values and its change since the previous value, with
|
|
11
|
+
* the number's full history in a hover card. Built for tables and stat cards (one per cell): an inline SVG, no chart
|
|
12
|
+
* library.
|
|
13
|
+
*
|
|
14
|
+
* - **Lazy history.** `details` is a function, called only while the hover card is open, so a component that reads
|
|
15
|
+
* the full history (a fetch on mount) loads it on hover and never for the rows nobody points at.
|
|
16
|
+
* - **Loading.** In a loading scope (the page's, or the host's read through `LoadingWhen`) the trendline draws its own
|
|
17
|
+
* skeleton at its loaded size; with no values it draws the same box empty. Nothing moves when the data lands.
|
|
18
|
+
* - **Colour is earned, as a TONE** (`TrendTone`): a change for the better is `positive`, for the worse `negative`, none
|
|
19
|
+
* `neutral`. Each tone is an ODS token (`TREND_TONES`: success, error, secondary text) a host may replace for one
|
|
20
|
+
* trendline (`tones`). Whether a rise is good is the host's to say (`higherIsBetter`): most numbers a monitor shows
|
|
21
|
+
* count problems.
|
|
22
|
+
*
|
|
23
|
+
* `TrendHistory` is the hover card's body: a title and a grid of columns, one height loading and loaded.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const SPARK_W = 56;
|
|
27
|
+
const SPARK_H = 16;
|
|
28
|
+
const SPARK_CLASS = 'h-4 w-14';
|
|
29
|
+
const CHANGE_CLASS = 'w-8 text-right text-h6 tabular-nums';
|
|
30
|
+
const BOX_CLASS = 'inline-flex shrink-0 items-center gap-[var(--spacing-system-xxs)]';
|
|
31
|
+
/** The focus ring of a trendline a keyboard can open (the lib's focus-visible ring). */
|
|
32
|
+
const FOCUS_CLASS = 'rounded-sm outline-none focus-visible:ring-1 focus-visible:ring-ods-accent';
|
|
33
|
+
|
|
34
|
+
/** The change written with its sign: "+3", "−2", "0". */
|
|
35
|
+
export function formatTrendChange(change: number): string {
|
|
36
|
+
return change === 0 ? '0' : `${change > 0 ? '+' : '−'}${formatNumber(Math.abs(change))}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** What a change means: better, worse, or none (or unknown). */
|
|
40
|
+
export type TrendTone = 'positive' | 'negative' | 'neutral';
|
|
41
|
+
|
|
42
|
+
/** THE colour of each tone: the ODS semantic tokens (never a raw palette var). */
|
|
43
|
+
export const TREND_TONES: Readonly<Record<TrendTone, string>> = {
|
|
44
|
+
positive: 'text-ods-success',
|
|
45
|
+
negative: 'text-ods-error',
|
|
46
|
+
neutral: 'text-ods-text-secondary',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** The tone of a change: a rise is positive only when `higherIsBetter`; no change (or an unknown one) is neutral. */
|
|
50
|
+
export function trendTone(change: number | null, higherIsBetter = false): TrendTone {
|
|
51
|
+
if (change === null || change === 0) return 'neutral';
|
|
52
|
+
return change > 0 === higherIsBetter ? 'positive' : 'negative';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The text colour of a change: its tone's class, from `TREND_TONES` or the host's `tones`. */
|
|
56
|
+
export function trendToneClass(change: number | null, higherIsBetter = false, tones: Partial<Record<TrendTone, string>> = {}): string {
|
|
57
|
+
const tone = trendTone(change, higherIsBetter);
|
|
58
|
+
return tones[tone] ?? TREND_TONES[tone];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Where each known value sits in the line's 56 × 16 box (oldest left), skipping unknown values. Scaled between the
|
|
63
|
+
* series' own lowest and highest value, so negative values stay inside the box and a small move near a large value is
|
|
64
|
+
* still visible; a flat series sits mid-height, a single value in the middle.
|
|
65
|
+
*/
|
|
66
|
+
export function trendlinePoints(values: ReadonlyArray<number | null>): Array<{ x: number; y: number }> {
|
|
67
|
+
const known = values
|
|
68
|
+
.map((v, i) => [i, v] as const)
|
|
69
|
+
.filter((p): p is readonly [number, number] => p[1] !== null);
|
|
70
|
+
if (known.length === 0) return [];
|
|
71
|
+
const min = Math.min(...known.map(([, v]) => v));
|
|
72
|
+
const range = Math.max(...known.map(([, v]) => v)) - min;
|
|
73
|
+
const x = (i: number) => (values.length === 1 ? SPARK_W / 2 : (i / (values.length - 1)) * (SPARK_W - 4) + 2);
|
|
74
|
+
const y = (v: number) => (range === 0 ? SPARK_H / 2 : SPARK_H - 2 - ((v - min) / range) * (SPARK_H - 4));
|
|
75
|
+
return known.map(([i, v]) => ({ x: x(i), y: y(v) }));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function Spark({ values, toneClass }: { values: ReadonlyArray<number | null>; toneClass: string }) {
|
|
79
|
+
const points = trendlinePoints(values);
|
|
80
|
+
if (points.length === 0) return <svg className={SPARK_CLASS} aria-hidden="true" />;
|
|
81
|
+
const last = points[points.length - 1];
|
|
82
|
+
return (
|
|
83
|
+
<svg className={`${SPARK_CLASS} ${toneClass}`} viewBox={`0 0 ${SPARK_W} ${SPARK_H}`} aria-hidden="true">
|
|
84
|
+
{points.length > 1 && (
|
|
85
|
+
<polyline
|
|
86
|
+
points={points.map((p) => `${p.x},${p.y}`).join(' ')}
|
|
87
|
+
fill="none"
|
|
88
|
+
stroke="currentColor"
|
|
89
|
+
strokeWidth={1.5}
|
|
90
|
+
strokeLinejoin="round"
|
|
91
|
+
strokeLinecap="round"
|
|
92
|
+
/>
|
|
93
|
+
)}
|
|
94
|
+
<circle cx={last.x} cy={last.y} r={2} fill="currentColor" />
|
|
95
|
+
</svg>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface TrendlineProps {
|
|
100
|
+
/** The values, oldest first; null where a value is unknown. Empty = no history (the box stays, empty). */
|
|
101
|
+
values: ReadonlyArray<number | null>;
|
|
102
|
+
/** What the number is: the accessible name, and what the hover card is about. */
|
|
103
|
+
label: string;
|
|
104
|
+
/** The change shown beside the line. Default: the last value minus the one before (none when either is unknown). */
|
|
105
|
+
change?: number | null;
|
|
106
|
+
/** A rise is good (online devices, revenue). Default: a rise is worse (problems, errors). */
|
|
107
|
+
higherIsBetter?: boolean;
|
|
108
|
+
/** Replace a tone's colour for this trendline (an ODS text class, e.g. `{ positive: 'text-ods-accent' }`). */
|
|
109
|
+
tones?: Partial<Record<TrendTone, string>>;
|
|
110
|
+
/** The hover card's body, called only while it is open (load the full history here). None: no hover card. */
|
|
111
|
+
details?: () => ReactNode;
|
|
112
|
+
side?: 'top' | 'right' | 'bottom' | 'left';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function Trendline({ values, label, change, higherIsBetter = false, tones, details, side = 'top' }: TrendlineProps) {
|
|
116
|
+
// The ONE switch: in a loading scope, the skeleton at the loaded size.
|
|
117
|
+
if (useLoadingScope()) {
|
|
118
|
+
return (
|
|
119
|
+
<span className={BOX_CLASS} aria-hidden="true">
|
|
120
|
+
<UnifiedSkeleton as="span" className={`${SPARK_CLASS} rounded-sm`} />
|
|
121
|
+
<span className={CHANGE_CLASS} />
|
|
122
|
+
</span>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
if (values.length === 0) {
|
|
126
|
+
return (
|
|
127
|
+
<span className={BOX_CLASS} aria-hidden="true">
|
|
128
|
+
<span className={SPARK_CLASS} />
|
|
129
|
+
<span className={CHANGE_CLASS} />
|
|
130
|
+
</span>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
const last = values[values.length - 1] ?? null;
|
|
134
|
+
const before = values.length > 1 ? (values[values.length - 2] ?? null) : null;
|
|
135
|
+
const delta = change !== undefined ? change : last !== null && before !== null ? last - before : null;
|
|
136
|
+
const toneClass = trendToneClass(delta, higherIsBetter, tones);
|
|
137
|
+
const line = (
|
|
138
|
+
<span
|
|
139
|
+
className={details ? `${BOX_CLASS} ${FOCUS_CLASS}` : BOX_CLASS}
|
|
140
|
+
// A trendline sits inside clickable cards and rows: pointing at it must not also click them.
|
|
141
|
+
onClick={(e: MouseEvent) => e.stopPropagation()}
|
|
142
|
+
aria-label={`${label}: last ${values.length} values${delta === null ? '' : `, ${formatTrendChange(delta)}`}`}
|
|
143
|
+
// With a history behind it, a keyboard reaches it too: focusing it opens the card (FloatingTooltip opens on focus).
|
|
144
|
+
role={details ? 'button' : 'img'}
|
|
145
|
+
tabIndex={details ? 0 : undefined}
|
|
146
|
+
aria-haspopup={details ? 'dialog' : undefined}
|
|
147
|
+
>
|
|
148
|
+
<Spark values={values} toneClass={toneClass} />
|
|
149
|
+
<span className={`${CHANGE_CLASS} ${toneClass}`}>{delta === null ? '' : formatTrendChange(delta)}</span>
|
|
150
|
+
</span>
|
|
151
|
+
);
|
|
152
|
+
if (!details) return line;
|
|
153
|
+
return (
|
|
154
|
+
<FloatingTooltip as="span" side={side} triggerClassName={BOX_CLASS} content={<TrendDetails render={details} />}>
|
|
155
|
+
{line}
|
|
156
|
+
</FloatingTooltip>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Mounted only while the hover card is open, so `render` (and any read it starts) runs on hover. */
|
|
161
|
+
function TrendDetails({ render }: { render: () => ReactNode }) {
|
|
162
|
+
return <>{render()}</>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/* ---------------------------------- history --------------------------------- */
|
|
166
|
+
|
|
167
|
+
export interface TrendHistoryColumn {
|
|
168
|
+
label: string;
|
|
169
|
+
/** Numbers align right. */
|
|
170
|
+
align?: 'left' | 'right';
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface TrendHistoryProps {
|
|
174
|
+
title: string;
|
|
175
|
+
columns: TrendHistoryColumn[];
|
|
176
|
+
/** One row per value, each a cell per column; null while the history loads. */
|
|
177
|
+
rows: ReactNode[][] | null;
|
|
178
|
+
/** Rows drawn while loading (the number of values the trendline already shows). */
|
|
179
|
+
loadingRows: number;
|
|
180
|
+
/** Shown in place of the grid when the history could not be read. */
|
|
181
|
+
error?: string | null;
|
|
182
|
+
/** Anything after the grid (who changed, a link). */
|
|
183
|
+
children?: ReactNode;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The hover card's body for a `Trendline`: a title, then the history as a grid (the chart tooltips' anatomy: muted
|
|
188
|
+
* headers, primary values). Every row draws its own skeleton cells while `rows` is null, so the card is one height
|
|
189
|
+
* loading and loaded.
|
|
190
|
+
*/
|
|
191
|
+
export function TrendHistory({ title, columns, rows, loadingRows, error, children }: TrendHistoryProps) {
|
|
192
|
+
const grid = { gridTemplateColumns: `1fr ${'auto '.repeat(Math.max(0, columns.length - 1)).trim()}` };
|
|
193
|
+
const alignClass = (c: TrendHistoryColumn) => (c.align === 'right' ? 'text-right tabular-nums' : 'text-left');
|
|
194
|
+
return (
|
|
195
|
+
<div className="flex w-72 flex-col gap-[var(--spacing-system-sf)] whitespace-normal text-h6">
|
|
196
|
+
<span className="text-ods-text-primary">{title}</span>
|
|
197
|
+
{error ? (
|
|
198
|
+
<span className="text-ods-text-secondary">{error}</span>
|
|
199
|
+
) : (
|
|
200
|
+
<LoadingWhen loading={rows === null}>
|
|
201
|
+
<div className="grid gap-x-[var(--spacing-system-mf)] gap-y-[var(--spacing-system-xxs)]" style={grid}>
|
|
202
|
+
{columns.map((c) => (
|
|
203
|
+
<span key={c.label} className={`${alignClass(c)} text-ods-text-secondary`}>
|
|
204
|
+
{c.label}
|
|
205
|
+
</span>
|
|
206
|
+
))}
|
|
207
|
+
{(rows ?? Array.from({ length: loadingRows }, () => null)).map((row, r) =>
|
|
208
|
+
columns.map((c, i) => <TrendHistoryCell key={`${r}:${c.label}`} column={c} value={row ? row[i] : null} />),
|
|
209
|
+
)}
|
|
210
|
+
</div>
|
|
211
|
+
</LoadingWhen>
|
|
212
|
+
)}
|
|
213
|
+
{children}
|
|
214
|
+
</div>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function TrendHistoryCell({ column, value }: { column: TrendHistoryColumn; value: ReactNode }) {
|
|
219
|
+
if (useLoadingScope()) return <TextLineSkeleton type="h6" className={column.align === 'right' ? 'ml-auto w-8' : 'w-12'} />;
|
|
220
|
+
return <span className={`${column.align === 'right' ? 'text-right tabular-nums' : 'text-left'} text-ods-text-primary`}>{value}</span>;
|
|
221
|
+
}
|