@panneau/ui 5.0.0-alpha.20 → 5.0.0-alpha.22
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/line-chart/LineChart.d.ts.map +1 -1
- package/dist/line-chart/LineChart.js +3 -3
- package/dist/line-chart/LineChart.js.map +1 -1
- package/dist/toast/Toast.d.ts +10 -2
- package/dist/toast/Toast.d.ts.map +1 -1
- package/dist/toast/Toast.js +32 -5
- package/dist/toast/Toast.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../src/line-chart/LineChart.tsx"],"names":[],"mappings":"AAQA,gCAAgC;AAChC,MAAM,WAAW,cAAc;IAC3B,mFAAmF;IACnF,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC3B,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAC;IACd,sFAAsF;IACtF,MAAM,CAAC,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;IACtC,kGAAkG;IAClG,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACxC,yFAAyF;IACzF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAKD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,EACtB,KAAK,EACL,MAAM,EACN,WAAW,EACX,MAAM,EACN,KAAS,EACT,SAAS,GACZ,EAAE,cAAc,+
|
|
1
|
+
{"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../src/line-chart/LineChart.tsx"],"names":[],"mappings":"AAQA,gCAAgC;AAChC,MAAM,WAAW,cAAc;IAC3B,mFAAmF;IACnF,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC3B,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAC;IACd,sFAAsF;IACtF,MAAM,CAAC,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;IACtC,kGAAkG;IAClG,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACxC,yFAAyF;IACzF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAKD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,EACtB,KAAK,EACL,MAAM,EACN,WAAW,EACX,MAAM,EACN,KAAS,EACT,SAAS,GACZ,EAAE,cAAc,+BA2FhB"}
|
|
@@ -212,7 +212,7 @@ function LineChart(t0) {
|
|
|
212
212
|
$[63] = t17;
|
|
213
213
|
$[64] = t7;
|
|
214
214
|
} else t7 = $[64];
|
|
215
|
-
t8 = points.length > 0 ? /* @__PURE__ */ jsx("span", {
|
|
215
|
+
t8 = points.length > 0 && Math.max(...values) > low ? /* @__PURE__ */ jsx("span", {
|
|
216
216
|
className: LineChart_module_default.max,
|
|
217
217
|
"aria-hidden": "true",
|
|
218
218
|
children: format(Math.max(...values))
|
|
@@ -290,9 +290,9 @@ function LineChart(t0) {
|
|
|
290
290
|
} else t15 = $[81];
|
|
291
291
|
let t16;
|
|
292
292
|
if ($[82] !== t13 || $[83] !== t15) {
|
|
293
|
-
t16 = /* @__PURE__ */
|
|
293
|
+
t16 = /* @__PURE__ */ jsx("div", {
|
|
294
294
|
className: LineChart_module_default.visuallyHidden,
|
|
295
|
-
children: [t13, t15]
|
|
295
|
+
children: /* @__PURE__ */ jsxs("table", { children: [t13, t15] })
|
|
296
296
|
});
|
|
297
297
|
$[82] = t13;
|
|
298
298
|
$[83] = t15;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineChart.js","names":["CSSProperties","usePanneauIntl","Skeleton","chartColors","cx","styles","LineChartPoint","label","value","LineChartProps","points","formatValue","height","color","className","MAX_DOTS","LineChart","t0","$","_c","t1","undefined","intl","t2","formatNumber","format","t3","categorical","t4","t5","style","t6","chart","t7","t8","Symbol","for","plot","t9","first","last","t10","values","map","_temp","low","Math","min","high","max","top","t11","length","index","x","t12","value_0","y","t13","t14","point_0","index_0","point","join","line","zero","at","t15","baseline","t16","area","t17","t18","point_1","index_1","dot","svg","labels","point_2","visuallyHidden","_c","styles","_Fragment"],"sources":["../../src/line-chart/LineChart.tsx"],"sourcesContent":["import type { CSSProperties } from 'react';\n\nimport { usePanneauIntl } from '../intl/usePanneauIntl';\nimport { Skeleton } from '../skeleton/Skeleton';\nimport { chartColors } from '../theme/chartColors';\nimport { cx } from '../utils/cx';\nimport styles from './LineChart.module.css';\n\n/** A point of a `LineChart`. */\nexport interface LineChartPoint {\n /** What the point is, under the chart and in its table: a day, a week, a month. */\n label: string;\n value: number;\n}\n\nexport interface LineChartProps {\n /** What the chart shows: the caption of its table, for assistive technologies. */\n label: string;\n /** The points, in order. Left `undefined` while they load: a skeleton of the plot. */\n points?: LineChartPoint[] | undefined;\n /** Formats a value, in the table and the top of the scale. Defaults to a number of the locale. */\n formatValue?: (value: number) => string;\n /** Height of the plot, without the labels: `'10rem'`. Defaults to the `height` token. */\n height?: string;\n /** The categorical color of the line, from 0. Defaults to the first. */\n color?: number;\n className?: string;\n}\n\n/** Points get dots up to this count: past it, only the last one has one. */\nconst MAX_DOTS = 31;\n\n/**\n * A line of values over time, on the categorical chart colors of the theme: the line, the area\n * under it, the top of its scale, and the labels of its first and last points. The plot is hidden\n * from assistive technologies, which read the values in a table instead.\n */\nexport function LineChart({\n label,\n points,\n formatValue,\n height,\n color = 0,\n className,\n}: LineChartProps) {\n const intl = usePanneauIntl();\n const format = formatValue ?? ((value: number) => intl.formatNumber(value));\n const style = {\n '--_panneau-line-chart-color': chartColors.categorical(color),\n ...(height !== undefined ? { '--_panneau-line-chart-height': height } : {}),\n } as CSSProperties;\n if (points === undefined) {\n return (\n <div className={cx('panneau-line-chart', styles.chart, className)} style={style}>\n <div className={styles.plot}>\n <Skeleton shape=\"rect\" height=\"100%\" />\n </div>\n <Skeleton width=\"100%\" />\n </div>\n );\n }\n const values = points.map((point) => point.value);\n const low = Math.min(0, ...values);\n const high = Math.max(low + 1, ...values);\n // Room above the highest point, for the width of the line and its dot\n const top = high + (high - low) * 0.08;\n const x = (index: number) => (points.length === 1 ? 50 : (index / (points.length - 1)) * 100);\n const y = (value: number) => 100 - ((value - low) / (top - low)) * 100;\n const line = points\n .map((point, index) => `${index === 0 ? 'M' : 'L'}${x(index)},${y(point.value)}`)\n .join(' ');\n const zero = y(Math.max(low, 0));\n const first = points[0];\n const last = points.at(-1);\n return (\n <figure className={cx('panneau-line-chart', styles.chart, className)} style={style}>\n <div className={styles.plot}>\n <svg\n className={styles.svg}\n viewBox=\"0 0 100 100\"\n preserveAspectRatio=\"none\"\n aria-hidden=\"true\"\n focusable=\"false\"\n >\n <line className={styles.baseline} x1=\"0\" x2=\"100\" y1={zero} y2={zero} />\n {points.length > 1 ? (\n <>\n <path\n className={styles.area}\n d={`${line} L${x(points.length - 1)},${zero} L${x(0)},${zero} Z`}\n />\n <path className={styles.line} d={line} />\n </>\n ) : null}\n {points.map((point, index) =>\n points.length <= MAX_DOTS || index === points.length - 1 ? (\n <path\n key={point.label}\n className={styles.dot}\n d={`M${x(index)},${y(point.value)} h0`}\n >\n <title>{`${point.label}: ${format(point.value)}`}</title>\n </path>\n ) : null,\n )}\n </svg>\n {points.length > 0 ? (\n <span className={styles.max} aria-hidden=\"true\">\n {format(Math.max(...values))}\n </span>\n ) : null}\n </div>\n {first !== undefined && last !== undefined ? (\n <div className={styles.labels} aria-hidden=\"true\">\n <span>{first.label}</span>\n {points.length > 1 ? <span>{last.label}</span> : null}\n </div>\n ) : null}\n <table className={styles.visuallyHidden}>\n <caption>{label}</caption>\n <tbody>\n {points.map((point) => (\n <tr key={point.label}>\n <th scope=\"row\">{point.label}</th>\n <td>{format(point.value)}</td>\n </tr>\n ))}\n </tbody>\n </table>\n </figure>\n );\n}\n"],"mappings":";;;;;;;;;AA8BA,IAAMe,WAAW;;;;;;AAOjB,SAAOC,UAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAmB,MAAA,EAAAZ,OAAAG,QAAAC,aAAAC,QAAAC,OAAAO,IAAAN,cAAAG;CAKtB,MAAAJ,QAAAO,OAAAC,KAAAA,IAAA,IAAAD;CAGA,MAAAE,OAAarB,eAAe;CAAE,IAAAsB;CAAA,IAAAL,EAAA,OAAAP,eAAAO,EAAA,OAAAI,MAAA;EACfC,KAAAZ,iBAAAH,UAAmCc,KAAIE,aAAchB,KAAK;EAAEU,EAAA,KAAAP;EAAAO,EAAA,KAAAI;EAAAJ,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAA3E,MAAAO,SAAeF;CAA6D,IAAAG;CAAA,IAAAR,EAAA,OAAAL,OAAA;EAEzCa,KAAAvB,YAAWwB,YAAad,KAAK;EAACK,EAAA,KAAAL;EAAAK,EAAA,KAAAQ;CAAA,OAAAA,KAAAR,EAAA;CAAA,IAAAU;CAAA,IAAAV,EAAA,OAAAN,QAAA;EACzDgB,KAAAhB,WAAWS,KAAAA,IAAX,EAAA,gCAAyDT,OAAY,IAArE,CAAqE;EAACM,EAAA,KAAAN;EAAAM,EAAA,KAAAU;CAAA,OAAAA,KAAAV,EAAA;CAAA,IAAAW;CAAA,IAAAX,EAAA,OAAAQ,MAAAR,EAAA,OAAAU,IAAA;EAFhEC,KAAA;GAAA,+BACqBH;GAA8B,GACzDE;EACR;EAACV,EAAA,KAAAQ;EAAAR,EAAA,KAAAU;EAAAV,EAAA,KAAAW;CAAA,OAAAA,KAAAX,EAAA;CAHD,MAAAY,QAAcD;CAId,IAAInB,WAAWW,KAAAA,GAAS;EAAA,IAAAU;EAAA,IAAAb,E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AAAjC;GAA0DR,OAAAA;GAA7E,UAAA;IACIqB;IAoCCI;IAMDc;GAWK;;EAAAnD,EAAA,MAAAuB;EAAAvB,EAAA,MAAAiC;EAAAjC,EAAA,MAAAqC;EAAArC,EAAA,MAAAmD;EAAAnD,EAAA,MAAAoB;EAAApB,EAAA,MAAAqD;CAAA,OAAAA,MAAArD,EAAA;CAAA,OAtDTqD;AAsDS;AA5FV,SAAA3B,MAAAkB,OAAA;CAAA,OAwBkCA,MAAKtD;AAAM"}
|
|
1
|
+
{"version":3,"file":"LineChart.js","names":["CSSProperties","usePanneauIntl","Skeleton","chartColors","cx","styles","LineChartPoint","label","value","LineChartProps","points","formatValue","height","color","className","MAX_DOTS","LineChart","t0","$","_c","t1","undefined","intl","t2","formatNumber","format","t3","categorical","t4","t5","style","t6","chart","t7","t8","Symbol","for","plot","t9","first","last","t10","values","map","_temp","low","Math","min","high","max","top","t11","length","index","x","t12","value_0","y","t13","t14","point_0","index_0","point","join","line","zero","at","t15","baseline","t16","area","t17","t18","point_1","index_1","dot","svg","labels","point_2","visuallyHidden","_c","styles","_Fragment"],"sources":["../../src/line-chart/LineChart.tsx"],"sourcesContent":["import type { CSSProperties } from 'react';\n\nimport { usePanneauIntl } from '../intl/usePanneauIntl';\nimport { Skeleton } from '../skeleton/Skeleton';\nimport { chartColors } from '../theme/chartColors';\nimport { cx } from '../utils/cx';\nimport styles from './LineChart.module.css';\n\n/** A point of a `LineChart`. */\nexport interface LineChartPoint {\n /** What the point is, under the chart and in its table: a day, a week, a month. */\n label: string;\n value: number;\n}\n\nexport interface LineChartProps {\n /** What the chart shows: the caption of its table, for assistive technologies. */\n label: string;\n /** The points, in order. Left `undefined` while they load: a skeleton of the plot. */\n points?: LineChartPoint[] | undefined;\n /** Formats a value, in the table and the top of the scale. Defaults to a number of the locale. */\n formatValue?: (value: number) => string;\n /** Height of the plot, without the labels: `'10rem'`. Defaults to the `height` token. */\n height?: string;\n /** The categorical color of the line, from 0. Defaults to the first. */\n color?: number;\n className?: string;\n}\n\n/** Points get dots up to this count: past it, only the last one has one. */\nconst MAX_DOTS = 31;\n\n/**\n * A line of values over time, on the categorical chart colors of the theme: the line, the area\n * under it, the top of its scale, and the labels of its first and last points. The plot is hidden\n * from assistive technologies, which read the values in a table instead.\n */\nexport function LineChart({\n label,\n points,\n formatValue,\n height,\n color = 0,\n className,\n}: LineChartProps) {\n const intl = usePanneauIntl();\n const format = formatValue ?? ((value: number) => intl.formatNumber(value));\n const style = {\n '--_panneau-line-chart-color': chartColors.categorical(color),\n ...(height !== undefined ? { '--_panneau-line-chart-height': height } : {}),\n } as CSSProperties;\n if (points === undefined) {\n return (\n <div className={cx('panneau-line-chart', styles.chart, className)} style={style}>\n <div className={styles.plot}>\n <Skeleton shape=\"rect\" height=\"100%\" />\n </div>\n <Skeleton width=\"100%\" />\n </div>\n );\n }\n const values = points.map((point) => point.value);\n const low = Math.min(0, ...values);\n const high = Math.max(low + 1, ...values);\n // Room above the highest point, for the width of the line and its dot\n const top = high + (high - low) * 0.08;\n const x = (index: number) => (points.length === 1 ? 50 : (index / (points.length - 1)) * 100);\n const y = (value: number) => 100 - ((value - low) / (top - low)) * 100;\n const line = points\n .map((point, index) => `${index === 0 ? 'M' : 'L'}${x(index)},${y(point.value)}`)\n .join(' ');\n const zero = y(Math.max(low, 0));\n const first = points[0];\n const last = points.at(-1);\n return (\n <figure className={cx('panneau-line-chart', styles.chart, className)} style={style}>\n <div className={styles.plot}>\n <svg\n className={styles.svg}\n viewBox=\"0 0 100 100\"\n preserveAspectRatio=\"none\"\n aria-hidden=\"true\"\n focusable=\"false\"\n >\n <line className={styles.baseline} x1=\"0\" x2=\"100\" y1={zero} y2={zero} />\n {points.length > 1 ? (\n <>\n <path\n className={styles.area}\n d={`${line} L${x(points.length - 1)},${zero} L${x(0)},${zero} Z`}\n />\n <path className={styles.line} d={line} />\n </>\n ) : null}\n {points.map((point, index) =>\n points.length <= MAX_DOTS || index === points.length - 1 ? (\n <path\n key={point.label}\n className={styles.dot}\n d={`M${x(index)},${y(point.value)} h0`}\n >\n <title>{`${point.label}: ${format(point.value)}`}</title>\n </path>\n ) : null,\n )}\n </svg>\n {/* The top of the scale, unless every value is at the bottom of it (all 0) */}\n {points.length > 0 && Math.max(...values) > low ? (\n <span className={styles.max} aria-hidden=\"true\">\n {format(Math.max(...values))}\n </span>\n ) : null}\n </div>\n {first !== undefined && last !== undefined ? (\n <div className={styles.labels} aria-hidden=\"true\">\n <span>{first.label}</span>\n {points.length > 1 ? <span>{last.label}</span> : null}\n </div>\n ) : null}\n {/* Hidden in a wrapper: on the table itself, Chrome leaves its caption visible */}\n <div className={styles.visuallyHidden}>\n <table>\n <caption>{label}</caption>\n <tbody>\n {points.map((point) => (\n <tr key={point.label}>\n <th scope=\"row\">{point.label}</th>\n <td>{format(point.value)}</td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n </figure>\n );\n}\n"],"mappings":";;;;;;;;;AA8BA,IAAMe,WAAW;;;;;;AAOjB,SAAOC,UAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAmB,MAAA,EAAAZ,OAAAG,QAAAC,aAAAC,QAAAC,OAAAO,IAAAN,cAAAG;CAKtB,MAAAJ,QAAAO,OAAAC,KAAAA,IAAA,IAAAD;CAGA,MAAAE,OAAarB,eAAe;CAAE,IAAAsB;CAAA,IAAAL,EAAA,OAAAP,eAAAO,EAAA,OAAAI,MAAA;EACfC,KAAAZ,iBAAAH,UAAmCc,KAAIE,aAAchB,KAAK;EAAEU,EAAA,KAAAP;EAAAO,EAAA,KAAAI;EAAAJ,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAA3E,MAAAO,SAAeF;CAA6D,IAAAG;CAAA,IAAAR,EAAA,OAAAL,OAAA;EAEzCa,KAAAvB,YAAWwB,YAAad,KAAK;EAACK,EAAA,KAAAL;EAAAK,EAAA,KAAAQ;CAAA,OAAAA,KAAAR,EAAA;CAAA,IAAAU;CAAA,IAAAV,EAAA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;EAAAzC,EAAA,MAAAiD;CAAA,OAAAA,MAAAjD,EAAA;CAAA,IAAAmD;CAAA,IAAAnD,EAAA,QAAAwC,OAAAxC,EAAA,QAAAiD,KAAA;EAVhBE,MAAA,oBAAA,OAAA;GAAgB,WAAAhE,yBAAM0E;GAClB,UAAA,qBAAA,SAAA,EAAA,UAAA,CACIrB,KACAS,GAQI,EAAA,CAAA;EACN,CAAA;EAAAjD,EAAA,MAAAwC;EAAAxC,EAAA,MAAAiD;EAAAjD,EAAA,MAAAmD;CAAA,OAAAA,MAAAnD,EAAA;CAAA,IAAAqD;CAAA,IAAArD,EAAA,QAAAuB,OAAAvB,EAAA,QAAAiC,OAAAjC,EAAA,QAAAqC,OAAArC,EAAA,QAAAmD,OAAAnD,EAAA,QAAAoB,IAAA;EAzDViC,MAAA,qBAAA,UAAA;GAAmB,WAAAjC;GAA0DR,OAAAA;GAA7E,UAAA;IACIqB;IAqCCI;IAODc;GAaK;;EAAAnD,EAAA,MAAAuB;EAAAvB,EAAA,MAAAiC;EAAAjC,EAAA,MAAAqC;EAAArC,EAAA,MAAAmD;EAAAnD,EAAA,MAAAoB;EAAApB,EAAA,MAAAqD;CAAA,OAAAA,MAAArD,EAAA;CAAA,OA1DTqD;AA0DS;AAhGV,SAAA3B,MAAAkB,OAAA;CAAA,OAwBkCA,MAAKtD;AAAM"}
|
package/dist/toast/Toast.d.ts
CHANGED
|
@@ -55,10 +55,18 @@ export declare const MAX_VISIBLE_TOASTS = 3;
|
|
|
55
55
|
export declare function getToastTimeout(content: ToastContent): number | null;
|
|
56
56
|
/** Shows toasts in the closest `PanneauRoot`. */
|
|
57
57
|
export declare function useToast(): Toasts;
|
|
58
|
+
/**
|
|
59
|
+
* How far the toasts rise above an element: from its top to the bottom of the viewport, when it
|
|
60
|
+
* covers the bottom of the viewport, as a sticky footer does once the page scrolls. `0` when it
|
|
61
|
+
* shows higher, as the footer of a short form does, after its last field: toasts then stay at the
|
|
62
|
+
* bottom, rather than floating where nothing is.
|
|
63
|
+
*/
|
|
64
|
+
export declare function getToastOffset(rect: Pick<DOMRect, 'top' | 'bottom' | 'height'>, viewport: number): number;
|
|
58
65
|
/**
|
|
59
66
|
* Raises the toasts above an element that sticks to the bottom of the page, such as the footer of
|
|
60
|
-
* a form, while it is mounted and `active
|
|
61
|
-
*
|
|
67
|
+
* a form, while it is mounted and `active` and it covers the bottom of the viewport: the space it
|
|
68
|
+
* takes there becomes the `--panneau-bottom-offset` of the region. Measured again when the page
|
|
69
|
+
* scrolls or resizes. Toasts at the top ignore it.
|
|
62
70
|
*/
|
|
63
71
|
export declare function useToastOffset(ref: RefObject<HTMLElement | null>, active?: boolean): void;
|
|
64
72
|
export interface ToastProviderProps {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../../src/toast/Toast.tsx"],"names":[],"mappings":"AACA,OAAO,EAGH,KAAK,SAAS,EACd,KAAK,SAAS,EAMjB,MAAM,OAAO,CAAC;AAef,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAI3C,8BAA8B;AAC9B,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC;AAE7B;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ;;;OAGG;IACH,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;CACpD;AAED,MAAM,WAAW,YAAY;IACzB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,MAAM;IACnB,kFAAkF;IACl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O,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IAC5D,6BAA6B;IAC7B,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,sFAAsF;AACtF,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC;AAEjE,0EAA0E;AAC1E,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAWpC;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CAWpE;AAoBD,iDAAiD;AACjD,wBAAgB,QAAQ,IAAI,MAAM,CAMjC;AAKD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC,EAAE,QAAQ,EAAE,MAAM,UAGhG;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,MAAM,UAAO,GAAG,IAAI,CAuCtF;AA4DD,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,mDAAmD;IACnD,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,iFAAiF;IACjF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC,QAAQ,MAAM,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAC9D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAC1B,QAAQ,EACR,SAAoB,EACpB,eAAe,EACf,WAAW,GACd,EAAE,kBAAkB,+BAwEpB"}
|
package/dist/toast/Toast.js
CHANGED
|
@@ -48,10 +48,22 @@ function useToast() {
|
|
|
48
48
|
if (toasts === null) throw new Error("useToast() must be used inside <PanneauRoot>.");
|
|
49
49
|
return toasts;
|
|
50
50
|
}
|
|
51
|
+
/** How far from the bottom of the viewport an element can end and still stick to it (the frame's gutter). */
|
|
52
|
+
var STUCK_SLACK = 32;
|
|
53
|
+
/**
|
|
54
|
+
* How far the toasts rise above an element: from its top to the bottom of the viewport, when it
|
|
55
|
+
* covers the bottom of the viewport, as a sticky footer does once the page scrolls. `0` when it
|
|
56
|
+
* shows higher, as the footer of a short form does, after its last field: toasts then stay at the
|
|
57
|
+
* bottom, rather than floating where nothing is.
|
|
58
|
+
*/
|
|
59
|
+
function getToastOffset(rect, viewport) {
|
|
60
|
+
return rect.height > 0 && rect.top < viewport && rect.bottom >= viewport - STUCK_SLACK ? Math.ceil(viewport - rect.top) : 0;
|
|
61
|
+
}
|
|
51
62
|
/**
|
|
52
63
|
* Raises the toasts above an element that sticks to the bottom of the page, such as the footer of
|
|
53
|
-
* a form, while it is mounted and `active
|
|
54
|
-
*
|
|
64
|
+
* a form, while it is mounted and `active` and it covers the bottom of the viewport: the space it
|
|
65
|
+
* takes there becomes the `--panneau-bottom-offset` of the region. Measured again when the page
|
|
66
|
+
* scrolls or resizes. Toasts at the top ignore it.
|
|
55
67
|
*/
|
|
56
68
|
function useToastOffset(ref, t0) {
|
|
57
69
|
const $ = c(5);
|
|
@@ -64,12 +76,27 @@ function useToastOffset(ref, t0) {
|
|
|
64
76
|
const element = ref.current;
|
|
65
77
|
if (toasts === null || element === null || !active) return;
|
|
66
78
|
const id = {};
|
|
67
|
-
|
|
79
|
+
let frame = null;
|
|
80
|
+
const measure = () => {
|
|
81
|
+
frame = null;
|
|
82
|
+
toasts.setOffset(id, getToastOffset(element.getBoundingClientRect(), window.innerHeight));
|
|
83
|
+
};
|
|
84
|
+
const schedule = () => {
|
|
85
|
+
if (frame === null) frame = requestAnimationFrame(measure);
|
|
86
|
+
};
|
|
68
87
|
measure();
|
|
69
|
-
const observer = typeof ResizeObserver !== "undefined" ? new ResizeObserver(
|
|
88
|
+
const observer = typeof ResizeObserver !== "undefined" ? new ResizeObserver(schedule) : null;
|
|
70
89
|
observer?.observe(element);
|
|
90
|
+
window.addEventListener("scroll", schedule, {
|
|
91
|
+
capture: true,
|
|
92
|
+
passive: true
|
|
93
|
+
});
|
|
94
|
+
window.addEventListener("resize", schedule, { passive: true });
|
|
71
95
|
return () => {
|
|
72
96
|
observer?.disconnect();
|
|
97
|
+
window.removeEventListener("scroll", schedule, { capture: true });
|
|
98
|
+
window.removeEventListener("resize", schedule);
|
|
99
|
+
if (frame !== null) cancelAnimationFrame(frame);
|
|
73
100
|
toasts.setOffset(id, null);
|
|
74
101
|
};
|
|
75
102
|
};
|
|
@@ -273,6 +300,6 @@ function _temp() {
|
|
|
273
300
|
return new UNSTABLE_ToastQueue({ maxVisibleToasts: 3 });
|
|
274
301
|
}
|
|
275
302
|
//#endregion
|
|
276
|
-
export { MAX_VISIBLE_TOASTS, ToastProvider, getToastTimeout, useToast, useToastOffset };
|
|
303
|
+
export { MAX_VISIBLE_TOASTS, ToastProvider, getToastOffset, getToastTimeout, useToast, useToastOffset };
|
|
277
304
|
|
|
278
305
|
//# sourceMappingURL=Toast.js.map
|
package/dist/toast/Toast.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.js","names":["CircleAlert","CircleCheck","Info","TriangleAlert","X","CSSProperties","Dispatch","ReactNode","RefObject","SetStateAction","createContext","use","useEffect","useState","UNSTABLE_Toast","AriaToast","UNSTABLE_ToastContent","AriaToastContent","UNSTABLE_ToastQueue","AriaToastQueue","UNSTABLE_ToastRegion","AriaToastRegion","Text","Button","IconButton","Icon","IconComponent","messages","usePanneauIntl","toneClass","Tone","cx","styles","ToastTone","ToastContent","title","description","tone","action","label","onAction","ToastOptions","key","timeout","onClose","Toasts","show","content","options","close","ToastPlacement","MAX_VISIBLE_TOASTS","MIN_TIMEOUT","ACTION_TIMEOUT","MAX_TIMEOUT","PER_WORD","NOTICE","getToastTimeout","words","split","filter","word","length","reading","undefined","Math","min","max","TONE_ICONS","Partial","Record","neutral","success","danger","warning","info","EDGE_TONES","Set","ToastContextValue","setOffset","id","height","ToastContext","useToast","toasts","Error","useToastOffset","ref","t0","$","_c","active","t1","t2","element","current","measure","getBoundingClientRect","observer","ResizeObserver","observe","disconnect","createToasts","queue","setOffsets","ReadonlyMap","shown","Map","keys","forget","added","own","get","delete","delay","previous","add","set","next","ToastProviderProps","children","placement","regionClassName","regionProps","ToastProvider","intl","_temp","offsets","_temp2","t3","values","offset","t4","formatMessage","notifications","t5","region","t6","t7","t8","t9","t10","toast","icon","has","edge","actions","t11","maxVisibleToasts","_c","styles","AriaToast","AriaToastContent","Button","AriaToastRegion","AriaToastQueue"],"sources":["../../src/toast/Toast.tsx"],"sourcesContent":["import { CircleAlert, CircleCheck, Info, TriangleAlert, X } from 'lucide-react';\nimport {\n type CSSProperties,\n type Dispatch,\n type ReactNode,\n type RefObject,\n type SetStateAction,\n createContext,\n use,\n useEffect,\n useState,\n} from 'react';\nimport {\n UNSTABLE_Toast as AriaToast,\n UNSTABLE_ToastContent as AriaToastContent,\n UNSTABLE_ToastQueue as AriaToastQueue,\n UNSTABLE_ToastRegion as AriaToastRegion,\n Text,\n} from 'react-aria-components';\n\nimport { Button } from '../button/Button';\nimport { IconButton } from '../icon-button/IconButton';\nimport { Icon, type IconComponent } from '../icon/Icon';\nimport { messages } from '../intl/messages';\nimport { usePanneauIntl } from '../intl/usePanneauIntl';\nimport { toneClass } from '../theme/toneClass';\nimport type { Tone } from '../theme/tones';\nimport { cx } from '../utils/cx';\nimport styles from './Toast.module.css';\n\n/** @deprecated Use `Tone`. */\nexport type ToastTone = Tone;\n\n/**\n * What a toast says: what was done to what (\"“Spring contest” saved\", \"3 entries archived\"), and\n * the next step when there is one.\n */\nexport interface ToastContent {\n title: string;\n description?: string;\n /**\n * Defaults to `neutral`. A success keeps the neutral look with its icon; only `warning` and\n * `danger` color the edge.\n */\n tone?: Tone;\n /**\n * A button in the toast that leads to the result (\"Open\", \"Show\", \"Download\") or undoes what was\n * done (\"Undo\"). The toast closes when it is pressed.\n */\n action?: { label: string; onAction: () => void };\n}\n\nexport interface ToastOptions {\n /**\n * A toast with the key of one already shown replaces it instead of adding another: \"Saved\"\n * once, however many saves. `show()` returns it.\n */\n key?: string;\n /**\n * Milliseconds before the toast closes by itself, or `null` to keep it until it is closed.\n * Defaults to what the toast holds (`getToastTimeout()`): about 5 seconds, longer for a longer\n * text, about 10 seconds with an action, and none for an error.\n */\n timeout?: number | null;\n onClose?: () => void;\n}\n\nexport interface Toasts {\n /** Shows a toast. Returns its key: the one given in its options, or a new one. */\n show(content: ToastContent, options?: ToastOptions): string;\n /** Closes a toast by key. */\n close(key: string): void;\n}\n\n/** Where toasts show: `bottom` (centered, the default), `bottom-end` or `top-end`. */\nexport type ToastPlacement = 'bottom' | 'bottom-end' | 'top-end';\n\n/** At most this many toasts show at once: older ones wait for a place. */\nexport const MAX_VISIBLE_TOASTS = 3;\n\n/** Reading time of a toast without an action: at least 5 seconds, at most 10. */\nconst MIN_TIMEOUT = 5000;\n/** A toast with an action stays about 10 seconds, longer for a longer text. */\nconst ACTION_TIMEOUT = 10000;\nconst MAX_TIMEOUT = 15000;\n/** About 200 words a minute, plus the time to notice the toast. */\nconst PER_WORD = 300;\nconst NOTICE = 2000;\n\n/**\n * How long a toast stays, from what it holds: about 5 seconds, longer for a longer text; about 10\n * seconds with an action, which must be reached in that time (an action to reach later belongs in\n * the page, not in a toast that stays); and `null`, no timeout, for an error the user must read.\n */\nexport function getToastTimeout(content: ToastContent): number | null {\n if (content.tone === 'danger') {\n return null;\n }\n const words = `${content.title} ${content.description ?? ''} ${content.action?.label ?? ''}`\n .split(/\\s+/)\n .filter((word) => word !== '').length;\n const reading = NOTICE + words * PER_WORD;\n return content.action !== undefined\n ? Math.min(Math.max(ACTION_TIMEOUT, reading), MAX_TIMEOUT)\n : Math.min(Math.max(MIN_TIMEOUT, reading), ACTION_TIMEOUT);\n}\n\nconst TONE_ICONS: Partial<Record<Tone, IconComponent | null>> = {\n neutral: null,\n success: CircleCheck,\n danger: CircleAlert,\n warning: TriangleAlert,\n info: Info,\n};\n\n/** Tones that color the edge of a toast: what needs a look. */\nconst EDGE_TONES = new Set<Tone>(['warning', 'danger']);\n\ninterface ToastContextValue extends Toasts {\n /** Sets how far toasts rise above what sticks to the bottom of the page, by who sets it. */\n setOffset(id: object, height: number | null): void;\n}\n\nconst ToastContext = createContext<ToastContextValue | null>(null);\n\n/** Shows toasts in the closest `PanneauRoot`. */\nexport function useToast(): Toasts {\n const toasts = use(ToastContext);\n if (toasts === null) {\n throw new Error('useToast() must be used inside <PanneauRoot>.');\n }\n return toasts;\n}\n\n/**\n * Raises the toasts above an element that sticks to the bottom of the page, such as the footer of\n * a form, while it is mounted and `active`: its height becomes the `--panneau-bottom-offset` of the\n * region. Toasts at the top ignore it.\n */\nexport function useToastOffset(ref: RefObject<HTMLElement | null>, active = true): void {\n const toasts = use(ToastContext);\n useEffect(() => {\n const element = ref.current;\n if (toasts === null || element === null || !active) {\n return undefined;\n }\n const id = {};\n const measure = () => toasts.setOffset(id, element.getBoundingClientRect().height);\n measure();\n const observer = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(measure) : null;\n observer?.observe(element);\n return () => {\n observer?.disconnect();\n toasts.setOffset(id, null);\n };\n }, [ref, toasts, active]);\n}\n\n/**\n * The toasts of a region: `show()` with keys over React Aria's queue, and the offsets of what\n * sticks to the bottom of the page.\n */\nfunction createToasts(\n queue: AriaToastQueue<ToastContent>,\n setOffsets: Dispatch<SetStateAction<ReadonlyMap<object, number>>>,\n): ToastContextValue {\n // The toast shown for each key given to show(), and back.\n const shown = new Map<string, string>();\n const keys = new Map<string, string>();\n const forget = (added: string) => {\n const own = keys.get(added);\n if (own !== undefined && shown.get(own) === added) {\n shown.delete(own);\n }\n keys.delete(added);\n };\n return {\n show(content, { key, timeout, onClose } = {}) {\n const delay = timeout === undefined ? getToastTimeout(content) : timeout;\n const previous = key !== undefined ? shown.get(key) : undefined;\n if (previous !== undefined) {\n keys.delete(previous);\n queue.close(previous);\n }\n let added = '';\n added = queue.add(content, {\n ...(delay !== null ? { timeout: delay } : {}),\n onClose: () => {\n forget(added);\n onClose?.();\n },\n });\n if (key === undefined) {\n return added;\n }\n shown.set(key, added);\n keys.set(added, key);\n return key;\n },\n close(key) {\n queue.close(shown.get(key) ?? key);\n },\n setOffset(id, height) {\n setOffsets((current) => {\n const next = new Map(current);\n if (height === null) {\n next.delete(id);\n } else {\n next.set(id, height);\n }\n return next;\n });\n },\n };\n}\n\nexport interface ToastProviderProps {\n children?: ReactNode;\n /** Where the toasts show. Defaults to `bottom`. */\n placement?: ToastPlacement;\n /** Class names that give the region its tokens, since it renders in the body. */\n regionClassName?: string;\n regionProps?: Record<`data-${string}`, string | undefined>;\n}\n\n/**\n * Holds the toasts of a `PanneauRoot` and renders them in an accessible region (decision 0062): at\n * the bottom by default, one per key, at most three, the older ones folded behind the newest until\n * the region is hovered or focused, where their timers pause.\n */\nexport function ToastProvider({\n children,\n placement = 'bottom',\n regionClassName,\n regionProps,\n}: ToastProviderProps) {\n const intl = usePanneauIntl();\n const [queue] = useState(\n () => new AriaToastQueue<ToastContent>({ maxVisibleToasts: MAX_VISIBLE_TOASTS }),\n );\n const [offsets, setOffsets] = useState<ReadonlyMap<object, number>>(() => new Map());\n const [toasts] = useState(() => createToasts(queue, setOffsets));\n const offset = Math.max(0, ...offsets.values());\n return (\n <ToastContext value={toasts}>\n {children}\n <AriaToastRegion\n queue={queue}\n aria-label={intl.formatMessage(messages.notifications)}\n className={cx('panneau-toast-region', regionClassName, styles.region)}\n data-placement={placement}\n style={{ '--panneau-bottom-offset': `${offset}px` } as CSSProperties}\n {...regionProps}\n >\n {({ toast }) => {\n const tone = toast.content.tone ?? 'neutral';\n const icon = TONE_ICONS[tone] ?? null;\n const { action } = toast.content;\n return (\n <AriaToast\n toast={toast}\n className={cx(\n 'panneau-toast',\n styles.toast,\n toneClass(tone),\n EDGE_TONES.has(tone) && styles.edge,\n )}\n >\n {icon !== null ? (\n <Icon icon={icon} size=\"lg\" className={styles.icon} />\n ) : null}\n <AriaToastContent className={styles.content}>\n <Text slot=\"title\" className={styles.title}>\n {toast.content.title}\n </Text>\n {toast.content.description !== undefined ? (\n <Text slot=\"description\" className={styles.description}>\n {toast.content.description}\n </Text>\n ) : null}\n </AriaToastContent>\n <div className={styles.actions}>\n {action !== undefined ? (\n <Button\n size=\"sm\"\n onPress={() => {\n action.onAction();\n queue.close(toast.key);\n }}\n >\n {action.label}\n </Button>\n ) : null}\n <IconButton\n slot=\"close\"\n icon={X}\n size=\"sm\"\n label={intl.formatMessage(messages.close)}\n showTooltip={false}\n />\n </div>\n </AriaToast>\n );\n }}\n </AriaToastRegion>\n </ToastContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8EA,IAAamD,qBAAqB;;AAGlC,IAAMC,cAAc;;AAEpB,IAAMC,iBAAiB;AACvB,IAAMC,cAAc;;AAEpB,IAAMC,WAAW;AACjB,IAAMC,SAAS;;;;;;AAOf,SAAgBC,gBAAgBV,SAAsC;CAClE,IAAIA,QAAQV,SAAS,UACjB,OAAO;CAKX,MAAM0B,UAAUP,SAHF,GAAGT,QAAQZ,MAAK,GAAIY,QAAQX,eAAe,GAAE,GAAIW,QAAQT,QAAQC,SAAS,KACnFoB,MAAM,KAAK,CAAC,CACZC,QAAQC,SAASA,SAAS,EAAE,CAAC,CAACC,SACFP;CACjC,OAAOR,QAAQT,WAAW0B,KAAAA,IACpBC,KAAKC,IAAID,KAAKE,IAAId,gBAAgBU,OAAO,GAAGT,WAAW,IACvDW,KAAKC,IAAID,KAAKE,IAAIf,aAAaW,OAAO,GAAGV,cAAc;AACjE;AAEA,IAAMe,aAA0D;CAC5DG,SAAS;CACTC,SAASvE;CACTwE,QAAQzE;CACR0E,SAASvE;CACTwE,MAAMzE;AACV;;AAGA,IAAM0E,6BAAa,IAAIC,IAAU,CAAC,WAAW,QAAQ,CAAC;AAOtD,IAAMK,eAAexE,cAAwC,IAAI;;AAGjE,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A3C,EAAA,QAAA8C,MAAA9C,EAAA,QAAAkD,MAAAlD,EAAA,QAAAmD,IAAA;EAzDLC,MAAA,oBAACa,sBAAD;GACWnD;GACK,cAAA6B;GACD,WAAAG;GACKd,kBAAAA;GACT,OAAAkB;GAA6D,GAChEhB;GAEHiB,UAAAA;EARW,CAAA;EA0DEnD,EAAA,MAAAgC;EAAAhC,EAAA,MAAAc;EAAAd,EAAA,MAAAkC;EAAAlC,EAAA,MAAA2C;EAAA3C,EAAA,MAAA8C;EAAA9C,EAAA,MAAAkD;EAAAlD,EAAA,MAAAmD;EAAAnD,EAAA,MAAAoD;CAAA,OAAAA,MAAApD,EAAA;CAAA,IAAA0D;CAAA,IAAA1D,EAAA,QAAA+B,YAAA/B,EAAA,QAAAoD,OAAApD,EAAA,QAAAL,QAAA;EA5DtB+D,MAAA,qBAAC,cAAD;GAAqB/D,OAAAA;GAArB,UAAA,CACKoC,UACDqB,GAFS;;EA6DEpD,EAAA,MAAA+B;EAAA/B,EAAA,MAAAoD;EAAApD,EAAA,MAAAL;EAAAK,EAAA,MAAA0D;CAAA,OAAAA,MAAA1D,EAAA;CAAA,OA7Df0D;AA6De;AA3EhB,SAAAnB,SAAA;CAAA,uBAUuE,IAAIrB,IAAI;AAAC;AAVhF,SAAAmB,QAAA;CAAA,OAQO,IAAI3G,oBAA6B,EAAAiI,kBAAAA,EAAuC,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"file":"Toast.js","names":["CircleAlert","CircleCheck","Info","TriangleAlert","X","CSSProperties","Dispatch","ReactNode","RefObject","SetStateAction","createContext","use","useEffect","useState","UNSTABLE_Toast","AriaToast","UNSTABLE_ToastContent","AriaToastContent","UNSTABLE_ToastQueue","AriaToastQueue","UNSTABLE_ToastRegion","AriaToastRegion","Text","Button","IconButton","Icon","IconComponent","messages","usePanneauIntl","toneClass","Tone","cx","styles","ToastTone","ToastContent","title","description","tone","action","label","onAction","ToastOptions","key","timeout","onClose","Toasts","show","content","options","close","ToastPlacement","MAX_VISIBLE_TOASTS","MIN_TIMEOUT","ACTION_TIMEOUT","MAX_TIMEOUT","PER_WORD","NOTICE","getToastTimeout","words","split","filter","word","length","reading","undefined","Math","min","max","TONE_ICONS","Partial","Record","neutral","success","danger","warning","info","EDGE_TONES","Set","ToastContextValue","setOffset","id","height","ToastContext","useToast","toasts","Error","STUCK_SLACK","getToastOffset","rect","Pick","DOMRect","viewport","stuck","top","bottom","ceil","useToastOffset","ref","t0","$","_c","active","t1","t2","element","current","frame","measure","getBoundingClientRect","window","innerHeight","schedule","requestAnimationFrame","observer","ResizeObserver","observe","addEventListener","capture","passive","disconnect","removeEventListener","cancelAnimationFrame","createToasts","queue","setOffsets","ReadonlyMap","shown","Map","keys","forget","added","own","get","delete","delay","previous","add","set","next","ToastProviderProps","children","placement","regionClassName","regionProps","ToastProvider","intl","_temp","offsets","_temp2","t3","values","offset","t4","formatMessage","notifications","t5","region","t6","t7","t8","t9","t10","toast","icon","has","edge","actions","t11","maxVisibleToasts","_c","styles","AriaToast","AriaToastContent","Button","AriaToastRegion","AriaToastQueue"],"sources":["../../src/toast/Toast.tsx"],"sourcesContent":["import { CircleAlert, CircleCheck, Info, TriangleAlert, X } from 'lucide-react';\nimport {\n type CSSProperties,\n type Dispatch,\n type ReactNode,\n type RefObject,\n type SetStateAction,\n createContext,\n use,\n useEffect,\n useState,\n} from 'react';\nimport {\n UNSTABLE_Toast as AriaToast,\n UNSTABLE_ToastContent as AriaToastContent,\n UNSTABLE_ToastQueue as AriaToastQueue,\n UNSTABLE_ToastRegion as AriaToastRegion,\n Text,\n} from 'react-aria-components';\n\nimport { Button } from '../button/Button';\nimport { IconButton } from '../icon-button/IconButton';\nimport { Icon, type IconComponent } from '../icon/Icon';\nimport { messages } from '../intl/messages';\nimport { usePanneauIntl } from '../intl/usePanneauIntl';\nimport { toneClass } from '../theme/toneClass';\nimport type { Tone } from '../theme/tones';\nimport { cx } from '../utils/cx';\nimport styles from './Toast.module.css';\n\n/** @deprecated Use `Tone`. */\nexport type ToastTone = Tone;\n\n/**\n * What a toast says: what was done to what (\"“Spring contest” saved\", \"3 entries archived\"), and\n * the next step when there is one.\n */\nexport interface ToastContent {\n title: string;\n description?: string;\n /**\n * Defaults to `neutral`. A success keeps the neutral look with its icon; only `warning` and\n * `danger` color the edge.\n */\n tone?: Tone;\n /**\n * A button in the toast that leads to the result (\"Open\", \"Show\", \"Download\") or undoes what was\n * done (\"Undo\"). The toast closes when it is pressed.\n */\n action?: { label: string; onAction: () => void };\n}\n\nexport interface ToastOptions {\n /**\n * A toast with the key of one already shown replaces it instead of adding another: \"Saved\"\n * once, however many saves. `show()` returns it.\n */\n key?: string;\n /**\n * Milliseconds before the toast closes by itself, or `null` to keep it until it is closed.\n * Defaults to what the toast holds (`getToastTimeout()`): about 5 seconds, longer for a longer\n * text, about 10 seconds with an action, and none for an error.\n */\n timeout?: number | null;\n onClose?: () => void;\n}\n\nexport interface Toasts {\n /** Shows a toast. Returns its key: the one given in its options, or a new one. */\n show(content: ToastContent, options?: ToastOptions): string;\n /** Closes a toast by key. */\n close(key: string): void;\n}\n\n/** Where toasts show: `bottom` (centered, the default), `bottom-end` or `top-end`. */\nexport type ToastPlacement = 'bottom' | 'bottom-end' | 'top-end';\n\n/** At most this many toasts show at once: older ones wait for a place. */\nexport const MAX_VISIBLE_TOASTS = 3;\n\n/** Reading time of a toast without an action: at least 5 seconds, at most 10. */\nconst MIN_TIMEOUT = 5000;\n/** A toast with an action stays about 10 seconds, longer for a longer text. */\nconst ACTION_TIMEOUT = 10000;\nconst MAX_TIMEOUT = 15000;\n/** About 200 words a minute, plus the time to notice the toast. */\nconst PER_WORD = 300;\nconst NOTICE = 2000;\n\n/**\n * How long a toast stays, from what it holds: about 5 seconds, longer for a longer text; about 10\n * seconds with an action, which must be reached in that time (an action to reach later belongs in\n * the page, not in a toast that stays); and `null`, no timeout, for an error the user must read.\n */\nexport function getToastTimeout(content: ToastContent): number | null {\n if (content.tone === 'danger') {\n return null;\n }\n const words = `${content.title} ${content.description ?? ''} ${content.action?.label ?? ''}`\n .split(/\\s+/)\n .filter((word) => word !== '').length;\n const reading = NOTICE + words * PER_WORD;\n return content.action !== undefined\n ? Math.min(Math.max(ACTION_TIMEOUT, reading), MAX_TIMEOUT)\n : Math.min(Math.max(MIN_TIMEOUT, reading), ACTION_TIMEOUT);\n}\n\nconst TONE_ICONS: Partial<Record<Tone, IconComponent | null>> = {\n neutral: null,\n success: CircleCheck,\n danger: CircleAlert,\n warning: TriangleAlert,\n info: Info,\n};\n\n/** Tones that color the edge of a toast: what needs a look. */\nconst EDGE_TONES = new Set<Tone>(['warning', 'danger']);\n\ninterface ToastContextValue extends Toasts {\n /** Sets how far toasts rise above what sticks to the bottom of the page, by who sets it. */\n setOffset(id: object, height: number | null): void;\n}\n\nconst ToastContext = createContext<ToastContextValue | null>(null);\n\n/** Shows toasts in the closest `PanneauRoot`. */\nexport function useToast(): Toasts {\n const toasts = use(ToastContext);\n if (toasts === null) {\n throw new Error('useToast() must be used inside <PanneauRoot>.');\n }\n return toasts;\n}\n\n/** How far from the bottom of the viewport an element can end and still stick to it (the frame's gutter). */\nconst STUCK_SLACK = 32;\n\n/**\n * How far the toasts rise above an element: from its top to the bottom of the viewport, when it\n * covers the bottom of the viewport, as a sticky footer does once the page scrolls. `0` when it\n * shows higher, as the footer of a short form does, after its last field: toasts then stay at the\n * bottom, rather than floating where nothing is.\n */\nexport function getToastOffset(rect: Pick<DOMRect, 'top' | 'bottom' | 'height'>, viewport: number) {\n const stuck = rect.height > 0 && rect.top < viewport && rect.bottom >= viewport - STUCK_SLACK;\n return stuck ? Math.ceil(viewport - rect.top) : 0;\n}\n\n/**\n * Raises the toasts above an element that sticks to the bottom of the page, such as the footer of\n * a form, while it is mounted and `active` and it covers the bottom of the viewport: the space it\n * takes there becomes the `--panneau-bottom-offset` of the region. Measured again when the page\n * scrolls or resizes. Toasts at the top ignore it.\n */\nexport function useToastOffset(ref: RefObject<HTMLElement | null>, active = true): void {\n const toasts = use(ToastContext);\n useEffect(() => {\n const element = ref.current;\n if (toasts === null || element === null || !active) {\n return undefined;\n }\n const id = {};\n let frame: number | null = null;\n const measure = () => {\n frame = null;\n toasts.setOffset(\n id,\n getToastOffset(element.getBoundingClientRect(), window.innerHeight),\n );\n };\n // Once per frame, however many scroll events\n const schedule = () => {\n if (frame === null) {\n frame = requestAnimationFrame(measure);\n }\n };\n measure();\n const observer =\n typeof ResizeObserver !== 'undefined' ? new ResizeObserver(schedule) : null;\n observer?.observe(element);\n // Any scroll: the page may scroll in an element of the frame rather than the window\n window.addEventListener('scroll', schedule, { capture: true, passive: true });\n window.addEventListener('resize', schedule, { passive: true });\n return () => {\n observer?.disconnect();\n window.removeEventListener('scroll', schedule, { capture: true });\n window.removeEventListener('resize', schedule);\n if (frame !== null) {\n cancelAnimationFrame(frame);\n }\n toasts.setOffset(id, null);\n };\n }, [ref, toasts, active]);\n}\n\n/**\n * The toasts of a region: `show()` with keys over React Aria's queue, and the offsets of what\n * sticks to the bottom of the page.\n */\nfunction createToasts(\n queue: AriaToastQueue<ToastContent>,\n setOffsets: Dispatch<SetStateAction<ReadonlyMap<object, number>>>,\n): ToastContextValue {\n // The toast shown for each key given to show(), and back.\n const shown = new Map<string, string>();\n const keys = new Map<string, string>();\n const forget = (added: string) => {\n const own = keys.get(added);\n if (own !== undefined && shown.get(own) === added) {\n shown.delete(own);\n }\n keys.delete(added);\n };\n return {\n show(content, { key, timeout, onClose } = {}) {\n const delay = timeout === undefined ? getToastTimeout(content) : timeout;\n const previous = key !== undefined ? shown.get(key) : undefined;\n if (previous !== undefined) {\n keys.delete(previous);\n queue.close(previous);\n }\n let added = '';\n added = queue.add(content, {\n ...(delay !== null ? { timeout: delay } : {}),\n onClose: () => {\n forget(added);\n onClose?.();\n },\n });\n if (key === undefined) {\n return added;\n }\n shown.set(key, added);\n keys.set(added, key);\n return key;\n },\n close(key) {\n queue.close(shown.get(key) ?? key);\n },\n setOffset(id, height) {\n setOffsets((current) => {\n const next = new Map(current);\n if (height === null) {\n next.delete(id);\n } else {\n next.set(id, height);\n }\n return next;\n });\n },\n };\n}\n\nexport interface ToastProviderProps {\n children?: ReactNode;\n /** Where the toasts show. Defaults to `bottom`. */\n placement?: ToastPlacement;\n /** Class names that give the region its tokens, since it renders in the body. */\n regionClassName?: string;\n regionProps?: Record<`data-${string}`, string | undefined>;\n}\n\n/**\n * Holds the toasts of a `PanneauRoot` and renders them in an accessible region (decision 0062): at\n * the bottom by default, one per key, at most three, the older ones folded behind the newest until\n * the region is hovered or focused, where their timers pause.\n */\nexport function ToastProvider({\n children,\n placement = 'bottom',\n regionClassName,\n regionProps,\n}: ToastProviderProps) {\n const intl = usePanneauIntl();\n const [queue] = useState(\n () => new AriaToastQueue<ToastContent>({ maxVisibleToasts: MAX_VISIBLE_TOASTS }),\n );\n const [offsets, setOffsets] = useState<ReadonlyMap<object, number>>(() => new Map());\n const [toasts] = useState(() => createToasts(queue, setOffsets));\n const offset = Math.max(0, ...offsets.values());\n return (\n <ToastContext value={toasts}>\n {children}\n <AriaToastRegion\n queue={queue}\n aria-label={intl.formatMessage(messages.notifications)}\n className={cx('panneau-toast-region', regionClassName, styles.region)}\n data-placement={placement}\n style={{ '--panneau-bottom-offset': `${offset}px` } as CSSProperties}\n {...regionProps}\n >\n {({ toast }) => {\n const tone = toast.content.tone ?? 'neutral';\n const icon = TONE_ICONS[tone] ?? null;\n const { action } = toast.content;\n return (\n <AriaToast\n toast={toast}\n className={cx(\n 'panneau-toast',\n styles.toast,\n toneClass(tone),\n EDGE_TONES.has(tone) && styles.edge,\n )}\n >\n {icon !== null ? (\n <Icon icon={icon} size=\"lg\" className={styles.icon} />\n ) : null}\n <AriaToastContent className={styles.content}>\n <Text slot=\"title\" className={styles.title}>\n {toast.content.title}\n </Text>\n {toast.content.description !== undefined ? (\n <Text slot=\"description\" className={styles.description}>\n {toast.content.description}\n </Text>\n ) : null}\n </AriaToastContent>\n <div className={styles.actions}>\n {action !== undefined ? (\n <Button\n size=\"sm\"\n onPress={() => {\n action.onAction();\n queue.close(toast.key);\n }}\n >\n {action.label}\n </Button>\n ) : null}\n <IconButton\n slot=\"close\"\n icon={X}\n size=\"sm\"\n label={intl.formatMessage(messages.close)}\n showTooltip={false}\n />\n </div>\n </AriaToast>\n );\n }}\n </AriaToastRegion>\n </ToastContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8EA,IAAamD,qBAAqB;;AAGlC,IAAMC,cAAc;;AAEpB,IAAMC,iBAAiB;AACvB,IAAMC,cAAc;;AAEpB,IAAMC,WAAW;AACjB,IAAMC,SAAS;;;;;;AAOf,SAAgBC,gBAAgBV,SAAsC;CAClE,IAAIA,QAAQV,SAAS,UACjB,OAAO;CAKX,MAAM0B,UAAUP,SAHF,GAAGT,QAAQZ,MAAK,GAAIY,QAAQX,eAAe,GAAE,GAAIW,QAAQT,QAAQC,SAAS,KACnFoB,MAAM,KAAK,CAAC,CACZC,QAAQC,SAASA,SAAS,EAAE,CAAC,CAACC,SACFP;CACjC,OAAOR,QAAQT,WAAW0B,KAAAA,IACpBC,KAAKC,IAAID,KAAKE,IAAId,gBAAgBU,OAAO,GAAGT,WAAW,IACvDW,KAAKC,IAAID,KAAKE,IAAIf,aAAaW,OAAO,GAAGV,cAAc;AACjE;AAEA,IAAMe,aAA0D;CAC5DG,SAAS;CACTC,SAASvE;CACTwE,QAAQzE;CACR0E,SAASvE;CACTwE,MAAMzE;AACV;;AAGA,IAAM0E,6BAAa,IAAIC,IAAU,CAAC,WAAW,QAAQ,CAAC;AAOtD,IAAMK,eAAexE,cAAwC,IAAI;;AAGjE,SAAgByE,WAAmB;CAC/B,MAAMC,SAASzE,IAAIuE,YAAY;CAC/B,IAAIE,WAAW,MACX,MAAM,IAAIC,MAAM,+CAA+C;CAEnE,OAAOD;AACX;;AAGA,IAAME,cAAc;;;;;;;AAQpB,SAAgBC,eAAeC,MAAkDG,UAAkB;CAE/F,OADcH,KAAKP,SAAS,KAAKO,KAAKK,MAA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BAA6B,EAAAqJ,kBAAAA,EAAuC,CAAC;AAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/ui",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.22",
|
|
4
4
|
"description": "Design tokens, themes and accessible primitives of Panneau, built on React Aria Components.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
"react-intl": "^12.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@panneau/intl": "5.0.0-alpha.
|
|
60
|
+
"@panneau/intl": "5.0.0-alpha.22",
|
|
61
61
|
"lucide-react": "^1.57.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@panneau/protocol": "5.0.0-alpha.
|
|
64
|
+
"@panneau/protocol": "5.0.0-alpha.22"
|
|
65
65
|
}
|
|
66
66
|
}
|