rift-ds 1.24.0 → 1.26.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/README.md +5 -4
- package/chat/ChatThreads.d.ts +3 -1
- package/chat/ChatThreads.js +3 -1
- package/chat/ChatWidget.css +166 -15
- package/chat/ChatWidget.d.ts +6 -2
- package/chat/ChatWidget.js +17 -3
- package/components/ActionCard/ActionCard.d.ts +1 -1
- package/components/Attachment/Attachment.css +8 -0
- package/components/Attachment/AttachmentViewer.js +26 -5
- package/components/Attachment/fileTypes.d.ts +4 -0
- package/components/ContextMenu/ContextMenu.css +11 -0
- package/components/ContextMenu/ContextMenu.d.ts +1 -1
- package/components/ContextMenu/ContextMenu.js +3 -1
- package/components/CurrencyInput/CurrencyInput.css +12 -0
- package/components/CurrencyInput/CurrencyInput.d.ts +51 -0
- package/components/CurrencyInput/CurrencyInput.js +158 -0
- package/components/DataTable/columnTypes.js +4 -16
- package/components/DatePicker/DatePicker.d.ts +2 -0
- package/components/DatePicker/DatePicker.js +44 -131
- package/components/DatePicker/MonthGrid.d.ts +56 -0
- package/components/DatePicker/MonthGrid.js +65 -0
- package/components/DatePicker/calendar.d.ts +42 -0
- package/components/DatePicker/calendar.js +108 -0
- package/components/DateRangePicker/DateRangePicker.css +92 -0
- package/components/DateRangePicker/DateRangePicker.d.ts +86 -0
- package/components/DateRangePicker/DateRangePicker.js +294 -0
- package/components/Deadline/Deadline.css +82 -0
- package/components/Deadline/Deadline.d.ts +44 -0
- package/components/Deadline/Deadline.js +94 -0
- package/components/Deadline/deadlineStatus.d.ts +15 -0
- package/components/Deadline/deadlineStatus.js +13 -0
- package/components/DescriptionList/DescriptionList.css +184 -0
- package/components/DescriptionList/DescriptionList.d.ts +64 -0
- package/components/DescriptionList/DescriptionList.js +100 -0
- package/components/DescriptionList/DescriptionListCopy.d.ts +18 -0
- package/components/DescriptionList/DescriptionListCopy.js +45 -0
- package/components/DocumentViewer/DocumentViewer.css +188 -0
- package/components/DocumentViewer/DocumentViewer.d.ts +59 -0
- package/components/DocumentViewer/DocumentViewer.js +185 -0
- package/components/DropdownMenu/DropdownMenu.css +38 -0
- package/components/DropdownMenu/DropdownMenu.d.ts +4 -0
- package/components/DropdownMenu/DropdownMenu.js +11 -5
- package/components/DropdownMenu/ShortcutHint.d.ts +9 -0
- package/components/DropdownMenu/ShortcutHint.js +6 -0
- package/components/ErrorSummary/ErrorSummary.css +94 -0
- package/components/ErrorSummary/ErrorSummary.d.ts +34 -0
- package/components/ErrorSummary/ErrorSummary.js +70 -0
- package/components/ErrorSummary/fieldErrors.d.ts +36 -0
- package/components/ErrorSummary/fieldErrors.js +19 -0
- package/components/Field/Field.css +12 -0
- package/components/Field/Field.d.ts +10 -2
- package/components/Field/Field.js +12 -5
- package/components/Heading/Heading.css +129 -0
- package/components/Heading/Heading.d.ts +31 -0
- package/components/Heading/Heading.js +39 -0
- package/components/Input/Input.css +120 -0
- package/components/Input/Input.d.ts +20 -1
- package/components/Input/Input.js +70 -5
- package/components/InterruptCard/InterruptCard.d.ts +1 -1
- package/components/Link/Link.css +84 -0
- package/components/Link/Link.d.ts +43 -0
- package/components/Link/Link.js +74 -0
- package/components/List/List.css +173 -0
- package/components/List/List.d.ts +44 -0
- package/components/List/List.js +60 -0
- package/components/MaskedInput/MaskedInput.css +16 -0
- package/components/MaskedInput/MaskedInput.d.ts +57 -0
- package/components/MaskedInput/MaskedInput.js +142 -0
- package/components/MaskedInput/mask.d.ts +58 -0
- package/components/MaskedInput/mask.js +106 -0
- package/components/MessageCard/MessageCard.css +17 -6
- package/components/MessageCard/MessageCard.d.ts +1 -1
- package/components/ShaderScene/ShaderScene.css +19 -0
- package/components/ShaderScene/ShaderScene.d.ts +82 -0
- package/components/ShaderScene/ShaderScene.js +167 -0
- package/components/ShaderScene/assemble.d.ts +5 -0
- package/components/ShaderScene/assemble.js +76 -0
- package/components/ShaderScene/common.glsl.d.ts +6 -0
- package/components/ShaderScene/common.glsl.js +49 -0
- package/components/ShaderScene/passes.d.ts +2 -0
- package/components/ShaderScene/passes.js +93 -0
- package/components/ShaderScene/renderer.d.ts +39 -0
- package/components/ShaderScene/renderer.js +170 -0
- package/components/ShaderScene/scenes.d.ts +76 -0
- package/components/ShaderScene/scenes.js +752 -0
- package/components/ShaderScene/types.d.ts +83 -0
- package/components/ShaderScene/types.js +8 -0
- package/components/SignaturePad/SignaturePad.css +141 -0
- package/components/SignaturePad/SignaturePad.d.ts +68 -0
- package/components/SignaturePad/SignaturePad.js +287 -0
- package/components/SignaturePad/signature.d.ts +32 -0
- package/components/SignaturePad/signature.js +46 -0
- package/components/Text/Text.css +129 -0
- package/components/Text/Text.d.ts +36 -0
- package/components/Text/Text.js +36 -0
- package/components/ThreadPanel/ThreadPanel.css +29 -0
- package/components/ThreadPanel/ThreadPanel.d.ts +2 -0
- package/components/ThreadPanel/ThreadPanel.js +13 -2
- package/components/Widget/Widget.css +111 -0
- package/components/Widget/Widget.d.ts +15 -1
- package/components/Widget/Widget.js +63 -11
- package/components/Widget/WidgetDisclosure.d.ts +30 -0
- package/components/Widget/WidgetDisclosure.js +52 -0
- package/components/registry.json +111 -2
- package/components/registry.json.d.ts +111 -2
- package/components/registry.json.js +2 -2
- package/format/index.d.ts +15 -0
- package/format/index.js +17 -0
- package/format/money.d.ts +89 -0
- package/format/money.js +187 -0
- package/format/relative.d.ts +49 -0
- package/format/relative.js +50 -0
- package/index.d.ts +13 -0
- package/index.js +48 -1
- package/package.json +9 -2
- package/tokens/motion.d.ts +4 -0
- package/tokens/motion.js +4 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/* ============================================
|
|
2
|
+
DOCUMENT VIEWER
|
|
3
|
+
A bordered frame on the secondary container,
|
|
4
|
+
a toolbar row behind a divider, then the file:
|
|
5
|
+
the browser's own PDF viewer, an image that
|
|
6
|
+
zooms inside a scroller, or text set in the
|
|
7
|
+
code face. The frame's height is a step of the
|
|
8
|
+
control-height scale, or its container's.
|
|
9
|
+
============================================ */
|
|
10
|
+
|
|
11
|
+
/* Base */
|
|
12
|
+
.ds-document-viewer {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
min-width: 0;
|
|
17
|
+
border: var(--border-025) solid var(--color-bg-container-border);
|
|
18
|
+
border-radius: var(--radius-300);
|
|
19
|
+
background-color: var(--color-bg-container-secondary);
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
container-type: inline-size;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.ds-document-viewer--height-fill {
|
|
25
|
+
block-size: 100%;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Bare: no frame and no toolbar, the host's own surface and header around it */
|
|
29
|
+
.ds-document-viewer--bare {
|
|
30
|
+
border: none;
|
|
31
|
+
border-radius: 0;
|
|
32
|
+
background-color: transparent;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* Toolbar */
|
|
36
|
+
.ds-document-viewer__toolbar {
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
gap: var(--gap-200);
|
|
40
|
+
min-width: 0;
|
|
41
|
+
padding: var(--padding-150) var(--padding-200) var(--padding-150) var(--padding-400);
|
|
42
|
+
border-block-end: var(--border-025) solid var(--color-divider);
|
|
43
|
+
background-color: var(--color-bg-page-primary);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.ds-document-viewer__title {
|
|
47
|
+
flex: 1 1 auto;
|
|
48
|
+
min-width: 0;
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
white-space: nowrap;
|
|
51
|
+
text-overflow: ellipsis;
|
|
52
|
+
font-family: var(--font-paragraph-sm-emphasis-family);
|
|
53
|
+
font-size: var(--font-paragraph-sm-emphasis-size);
|
|
54
|
+
font-weight: var(--font-paragraph-sm-emphasis-weight);
|
|
55
|
+
line-height: var(--font-paragraph-sm-emphasis-line-height);
|
|
56
|
+
letter-spacing: var(--font-paragraph-sm-emphasis-letter-spacing);
|
|
57
|
+
color: var(--color-text-primary);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.ds-document-viewer__actions {
|
|
61
|
+
display: flex;
|
|
62
|
+
flex-shrink: 0;
|
|
63
|
+
align-items: center;
|
|
64
|
+
gap: var(--gap-050);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* The zoom reading doubles as the fit-to-width button. */
|
|
68
|
+
.ds-document-viewer__zoom {
|
|
69
|
+
box-sizing: border-box;
|
|
70
|
+
min-inline-size: var(--control-height-default);
|
|
71
|
+
height: var(--control-height-compact);
|
|
72
|
+
padding: 0 var(--padding-150);
|
|
73
|
+
border: none;
|
|
74
|
+
border-radius: var(--radius-pill);
|
|
75
|
+
background: none;
|
|
76
|
+
font-family: var(--font-paragraph-sm-family);
|
|
77
|
+
font-size: var(--font-paragraph-sm-size);
|
|
78
|
+
line-height: var(--font-paragraph-sm-line-height);
|
|
79
|
+
font-variant-numeric: tabular-nums;
|
|
80
|
+
color: var(--color-text-secondary);
|
|
81
|
+
cursor: pointer;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.ds-document-viewer__zoom:hover {
|
|
85
|
+
background-color: var(--color-action-passive-bg-hover);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.ds-document-viewer__zoom:focus-visible {
|
|
89
|
+
outline: var(--border-050) solid var(--color-action-primary-bg);
|
|
90
|
+
outline-offset: var(--border-050);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* A narrow frame gives the title a row of its own above the controls,
|
|
94
|
+
so a phone reads the whole name rather than its first word. */
|
|
95
|
+
@container (max-width: 400px) {
|
|
96
|
+
.ds-document-viewer__toolbar {
|
|
97
|
+
flex-wrap: wrap;
|
|
98
|
+
row-gap: var(--gap-050);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.ds-document-viewer__title {
|
|
102
|
+
flex-basis: 100%;
|
|
103
|
+
white-space: normal;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.ds-document-viewer__actions {
|
|
107
|
+
margin-inline-start: auto;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* Body */
|
|
112
|
+
.ds-document-viewer__body {
|
|
113
|
+
display: flex;
|
|
114
|
+
flex-direction: column;
|
|
115
|
+
block-size: calc(var(--control-height-default) * 12);
|
|
116
|
+
min-height: 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.ds-document-viewer--height-tall .ds-document-viewer__body {
|
|
120
|
+
block-size: calc(var(--control-height-default) * 18);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.ds-document-viewer--height-fill .ds-document-viewer__body {
|
|
124
|
+
flex: 1 1 auto;
|
|
125
|
+
block-size: auto;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.ds-document-viewer__frame {
|
|
129
|
+
flex: 1 1 auto;
|
|
130
|
+
inline-size: 100%;
|
|
131
|
+
block-size: 100%;
|
|
132
|
+
border: none;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.ds-document-viewer__scroll {
|
|
136
|
+
flex: 1 1 auto;
|
|
137
|
+
min-height: 0;
|
|
138
|
+
overflow: auto;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.ds-document-viewer__scroll:focus-visible {
|
|
142
|
+
outline: var(--border-050) solid var(--color-action-primary-bg);
|
|
143
|
+
outline-offset: calc(-1 * var(--border-050));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.ds-document-viewer__image {
|
|
147
|
+
display: block;
|
|
148
|
+
max-inline-size: none;
|
|
149
|
+
block-size: auto;
|
|
150
|
+
margin-inline: auto;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.ds-document-viewer__text {
|
|
154
|
+
margin: 0;
|
|
155
|
+
padding: var(--padding-400);
|
|
156
|
+
font-family: var(--font-family-code);
|
|
157
|
+
font-size: var(--font-paragraph-sm-size);
|
|
158
|
+
line-height: var(--font-paragraph-sm-line-height);
|
|
159
|
+
color: var(--color-text-primary);
|
|
160
|
+
white-space: pre-wrap;
|
|
161
|
+
overflow-wrap: anywhere;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/* Loading and fallback */
|
|
165
|
+
.ds-document-viewer__loading,
|
|
166
|
+
.ds-document-viewer__fallback {
|
|
167
|
+
display: flex;
|
|
168
|
+
flex: 1 1 auto;
|
|
169
|
+
flex-direction: column;
|
|
170
|
+
align-items: center;
|
|
171
|
+
justify-content: center;
|
|
172
|
+
gap: var(--gap-300);
|
|
173
|
+
padding: var(--padding-500);
|
|
174
|
+
text-align: center;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.ds-document-viewer__fallback-icon {
|
|
178
|
+
--icon-size: var(--icon-size-800);
|
|
179
|
+
color: var(--color-icon-primary);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.ds-document-viewer__fallback-text {
|
|
183
|
+
margin: 0;
|
|
184
|
+
font-family: var(--font-paragraph-family);
|
|
185
|
+
font-size: var(--font-paragraph-size);
|
|
186
|
+
line-height: var(--font-paragraph-line-height);
|
|
187
|
+
color: var(--color-text-secondary);
|
|
188
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
/** What the viewer shows a file as. */
|
|
3
|
+
export type DocumentViewerKind = 'pdf' | 'image' | 'text';
|
|
4
|
+
/** Props owned by DocumentViewer itself; everything else falls through to the root `<section>`. */
|
|
5
|
+
type DocumentViewerOwnProps = {
|
|
6
|
+
/** The file's address. */
|
|
7
|
+
src: string;
|
|
8
|
+
/** The document's name, shown in the toolbar and naming the frame for a screen reader. Note: this replaces the native `title` tooltip attribute, which DocumentViewer does not expose. */
|
|
9
|
+
title: string;
|
|
10
|
+
/** How to show it, or `auto` to read it from `fileName`, `src` and `mimeType`. A kind the viewer cannot show renders the fallback. Defaults to `auto`. */
|
|
11
|
+
kind?: DocumentViewerKind | 'auto';
|
|
12
|
+
/** The file's name, extension included, for `auto` and for the downloaded file. Defaults to the last part of `src`. */
|
|
13
|
+
fileName?: string;
|
|
14
|
+
/** The file's mime type, when `auto` cannot tell from the name. */
|
|
15
|
+
mimeType?: string;
|
|
16
|
+
/** The viewer's height: `default`, `tall`, or `fill` to take the height of its container. */
|
|
17
|
+
height?: 'default' | 'tall' | 'fill';
|
|
18
|
+
/** Drop the frame and the toolbar and fill the host, for a host that brings its own header with the name and the actions, such as AttachmentViewer. */
|
|
19
|
+
bare?: boolean;
|
|
20
|
+
/** Show the download button. A string names the downloaded file. Defaults to true. */
|
|
21
|
+
download?: boolean | string;
|
|
22
|
+
/** Called when the download button is pressed, in place of the browser's own download: for a file the host must fetch with credentials. */
|
|
23
|
+
onDownload?: () => void;
|
|
24
|
+
/** Show the button that opens the file in a new tab. Defaults to true. */
|
|
25
|
+
openInNewTab?: boolean;
|
|
26
|
+
/** More controls for the toolbar, before the built-in ones: a share button, a page count. */
|
|
27
|
+
toolbar?: React.ReactNode;
|
|
28
|
+
/** What shows when the file cannot be shown here: an unknown kind, a text file that would not load, or a browser that will not embed a PDF. Defaults to a line saying so and a download button. */
|
|
29
|
+
fallback?: React.ReactNode;
|
|
30
|
+
/** Accessible name and text of the download button. Defaults to "Download". */
|
|
31
|
+
downloadLabel?: string;
|
|
32
|
+
/** Accessible name of the open button. Defaults to "Open in new tab". */
|
|
33
|
+
openLabel?: string;
|
|
34
|
+
/** Accessible name of the zoom-in button. Defaults to "Zoom in". */
|
|
35
|
+
zoomInLabel?: string;
|
|
36
|
+
/** Accessible name of the zoom-out button. Defaults to "Zoom out". */
|
|
37
|
+
zoomOutLabel?: string;
|
|
38
|
+
/** Accessible name of the button that fits an image to the width again, given the zoom in percent. Defaults to "Fit to width, now <zoom>%". */
|
|
39
|
+
resetZoomLabel?: (percent: string) => string;
|
|
40
|
+
/** Announced while a text file loads. Defaults to "Loading document". */
|
|
41
|
+
loadingLabel?: string;
|
|
42
|
+
/** The default fallback's line. Defaults to "This file can’t be shown here." */
|
|
43
|
+
fallbackLabel?: string;
|
|
44
|
+
/** The BCP 47 locale the zoom is written in. Defaults to the nearest LocaleProvider's, else `en-US`. */
|
|
45
|
+
locale?: string;
|
|
46
|
+
/** Additional CSS classes */
|
|
47
|
+
className?: string;
|
|
48
|
+
};
|
|
49
|
+
export interface DocumentViewerProps extends DocumentViewerOwnProps, Omit<React.ComponentPropsWithRef<'section'>, keyof DocumentViewerOwnProps | 'children'> {
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A document on the page: a statement, a contract, an invoice, an uploaded
|
|
53
|
+
* receipt. A PDF shows in the browser's own viewer, an image with zoom, a
|
|
54
|
+
* text file in a scrolling frame; the toolbar downloads it or opens it in a
|
|
55
|
+
* new tab. Where the browser will not embed the file, the fallback shows in
|
|
56
|
+
* its place. The library carries no document renderer.
|
|
57
|
+
*/
|
|
58
|
+
export declare function DocumentViewer({ src, title, kind, fileName, mimeType, height, bare, download, onDownload, openInNewTab, toolbar, fallback, downloadLabel, openLabel, zoomInLabel, zoomOutLabel, resetZoomLabel, loadingLabel, fallbackLabel, locale: localeProp, className, ref, ...rest }: DocumentViewerProps): React.JSX.Element;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useEffect } from "react";
|
|
4
|
+
import { CircularButton } from "../CircularButton/CircularButton.js";
|
|
5
|
+
import { Button } from "../Button/Button.js";
|
|
6
|
+
import { Spinner } from "../Spinner/Spinner.js";
|
|
7
|
+
import { useLocale } from "../../behaviors/LocaleProvider.js";
|
|
8
|
+
import { getFileKind } from "../Attachment/fileTypes.js";
|
|
9
|
+
import "../../fonts/material-symbols.css";
|
|
10
|
+
import "../../behaviors/visually-hidden.css";
|
|
11
|
+
import "./DocumentViewer.css";
|
|
12
|
+
const ZOOMS = [0.5, 0.75, 1, 1.5, 2, 3];
|
|
13
|
+
function resolveKind(kind, name, mime) {
|
|
14
|
+
if (kind !== "auto") return kind;
|
|
15
|
+
const file = getFileKind({ name, type: mime });
|
|
16
|
+
if (file === "pdf" || file === "image") return file;
|
|
17
|
+
if (file === "text" || file === "code" || file === "pasted") return "text";
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
function DocumentViewer({
|
|
21
|
+
src,
|
|
22
|
+
title,
|
|
23
|
+
kind = "auto",
|
|
24
|
+
fileName,
|
|
25
|
+
mimeType,
|
|
26
|
+
height = "default",
|
|
27
|
+
bare = false,
|
|
28
|
+
download = true,
|
|
29
|
+
onDownload,
|
|
30
|
+
openInNewTab = true,
|
|
31
|
+
toolbar,
|
|
32
|
+
fallback,
|
|
33
|
+
downloadLabel = "Download",
|
|
34
|
+
openLabel = "Open in new tab",
|
|
35
|
+
zoomInLabel = "Zoom in",
|
|
36
|
+
zoomOutLabel = "Zoom out",
|
|
37
|
+
resetZoomLabel,
|
|
38
|
+
loadingLabel = "Loading document",
|
|
39
|
+
fallbackLabel = "This file can’t be shown here.",
|
|
40
|
+
locale: localeProp,
|
|
41
|
+
className = "",
|
|
42
|
+
ref,
|
|
43
|
+
...rest
|
|
44
|
+
}) {
|
|
45
|
+
const locale = useLocale(localeProp);
|
|
46
|
+
const name = fileName ?? decodeURIComponent(src.split(/[?#]/)[0].split("/").pop() ?? "");
|
|
47
|
+
const resolved = resolveKind(kind, name, mimeType);
|
|
48
|
+
const [zoom, setZoom] = useState(ZOOMS.indexOf(1));
|
|
49
|
+
const [text, setText] = useState(null);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (resolved !== "text") return;
|
|
52
|
+
let cancelled = false;
|
|
53
|
+
fetch(src).then((response) => response.ok ? response.text() : Promise.reject(new Error(String(response.status)))).then((body2) => !cancelled && setText({ src, body: body2, failed: false })).catch(() => !cancelled && setText({ src, body: null, failed: true }));
|
|
54
|
+
return () => {
|
|
55
|
+
cancelled = true;
|
|
56
|
+
};
|
|
57
|
+
}, [resolved, src]);
|
|
58
|
+
const downloadName = typeof download === "string" ? download : name || void 0;
|
|
59
|
+
const downloadButton = download ? onDownload ? /* @__PURE__ */ jsx(CircularButton, { icon: "download", variant: "tertiary", size: "compact", ariaLabel: downloadLabel, onClick: onDownload }) : /* @__PURE__ */ jsx(
|
|
60
|
+
CircularButton,
|
|
61
|
+
{
|
|
62
|
+
icon: "download",
|
|
63
|
+
variant: "tertiary",
|
|
64
|
+
size: "compact",
|
|
65
|
+
ariaLabel: downloadLabel,
|
|
66
|
+
href: src,
|
|
67
|
+
...{ download: downloadName }
|
|
68
|
+
}
|
|
69
|
+
) : null;
|
|
70
|
+
const fallbackNode = fallback ?? /* @__PURE__ */ jsxs("div", { className: "ds-document-viewer__fallback", children: [
|
|
71
|
+
/* @__PURE__ */ jsx("span", { className: "ds-document-viewer__fallback-icon material-symbols-rounded", "aria-hidden": "true", children: "description" }),
|
|
72
|
+
/* @__PURE__ */ jsx("p", { className: "ds-document-viewer__fallback-text", children: fallbackLabel }),
|
|
73
|
+
download && (onDownload ? /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "compact", iconLeft: "download", label: downloadLabel, onClick: onDownload }) : /* @__PURE__ */ jsx(
|
|
74
|
+
Button,
|
|
75
|
+
{
|
|
76
|
+
variant: "secondary",
|
|
77
|
+
size: "compact",
|
|
78
|
+
iconLeft: "download",
|
|
79
|
+
label: downloadLabel,
|
|
80
|
+
href: src,
|
|
81
|
+
...{ download: downloadName }
|
|
82
|
+
}
|
|
83
|
+
))
|
|
84
|
+
] });
|
|
85
|
+
const percent = new Intl.NumberFormat(locale, { style: "percent" }).format(ZOOMS[zoom]);
|
|
86
|
+
const resetLabel = resetZoomLabel ? resetZoomLabel(percent) : `Fit to width, now ${percent}`;
|
|
87
|
+
let body;
|
|
88
|
+
if (resolved === "pdf") {
|
|
89
|
+
body = /* @__PURE__ */ jsx("object", { className: "ds-document-viewer__frame", data: src, type: "application/pdf", "aria-label": title, children: fallbackNode });
|
|
90
|
+
} else if (resolved === "image") {
|
|
91
|
+
body = /* @__PURE__ */ jsx("div", { className: "ds-document-viewer__scroll", role: "region", "aria-label": title, tabIndex: 0, children: /* @__PURE__ */ jsx(
|
|
92
|
+
"img",
|
|
93
|
+
{
|
|
94
|
+
className: "ds-document-viewer__image",
|
|
95
|
+
src,
|
|
96
|
+
alt: title,
|
|
97
|
+
style: { inlineSize: `${ZOOMS[zoom] * 100}%` }
|
|
98
|
+
}
|
|
99
|
+
) });
|
|
100
|
+
} else if (resolved === "text") {
|
|
101
|
+
const current = text?.src === src ? text : null;
|
|
102
|
+
body = current?.failed ? fallbackNode : current?.body != null ? /* @__PURE__ */ jsx("div", { className: "ds-document-viewer__scroll", role: "region", "aria-label": title, tabIndex: 0, children: /* @__PURE__ */ jsx("pre", { className: "ds-document-viewer__text", children: current.body }) }) : /* @__PURE__ */ jsxs("div", { className: "ds-document-viewer__loading", role: "status", children: [
|
|
103
|
+
/* @__PURE__ */ jsx(Spinner, { size: "md" }),
|
|
104
|
+
/* @__PURE__ */ jsx("span", { className: "ds-visually-hidden", children: loadingLabel })
|
|
105
|
+
] });
|
|
106
|
+
} else {
|
|
107
|
+
body = fallbackNode;
|
|
108
|
+
}
|
|
109
|
+
return (
|
|
110
|
+
// The frame itself stays unnamed, so it is a plain container rather than
|
|
111
|
+
// a second landmark beside the scrolling region the title names.
|
|
112
|
+
/* @__PURE__ */ jsxs(
|
|
113
|
+
"section",
|
|
114
|
+
{
|
|
115
|
+
...rest,
|
|
116
|
+
ref,
|
|
117
|
+
className: [
|
|
118
|
+
"ds-document-viewer",
|
|
119
|
+
`ds-document-viewer--height-${bare ? "fill" : height}`,
|
|
120
|
+
bare && "ds-document-viewer--bare",
|
|
121
|
+
className
|
|
122
|
+
].filter(Boolean).join(" "),
|
|
123
|
+
children: [
|
|
124
|
+
!bare && /* @__PURE__ */ jsxs("header", { className: "ds-document-viewer__toolbar", children: [
|
|
125
|
+
/* @__PURE__ */ jsx("span", { className: "ds-document-viewer__title", children: title }),
|
|
126
|
+
/* @__PURE__ */ jsxs("div", { className: "ds-document-viewer__actions", children: [
|
|
127
|
+
resolved === "image" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
128
|
+
/* @__PURE__ */ jsx(
|
|
129
|
+
CircularButton,
|
|
130
|
+
{
|
|
131
|
+
icon: "zoom_out",
|
|
132
|
+
variant: "tertiary",
|
|
133
|
+
size: "compact",
|
|
134
|
+
ariaLabel: zoomOutLabel,
|
|
135
|
+
disabled: zoom === 0,
|
|
136
|
+
onClick: () => setZoom((z) => Math.max(0, z - 1))
|
|
137
|
+
}
|
|
138
|
+
),
|
|
139
|
+
/* @__PURE__ */ jsx(
|
|
140
|
+
"button",
|
|
141
|
+
{
|
|
142
|
+
type: "button",
|
|
143
|
+
className: "ds-document-viewer__zoom",
|
|
144
|
+
"aria-label": resetLabel,
|
|
145
|
+
onClick: () => setZoom(ZOOMS.indexOf(1)),
|
|
146
|
+
children: percent
|
|
147
|
+
}
|
|
148
|
+
),
|
|
149
|
+
/* @__PURE__ */ jsx(
|
|
150
|
+
CircularButton,
|
|
151
|
+
{
|
|
152
|
+
icon: "zoom_in",
|
|
153
|
+
variant: "tertiary",
|
|
154
|
+
size: "compact",
|
|
155
|
+
ariaLabel: zoomInLabel,
|
|
156
|
+
disabled: zoom === ZOOMS.length - 1,
|
|
157
|
+
onClick: () => setZoom((z) => Math.min(ZOOMS.length - 1, z + 1))
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
] }),
|
|
161
|
+
toolbar,
|
|
162
|
+
openInNewTab && /* @__PURE__ */ jsx(
|
|
163
|
+
CircularButton,
|
|
164
|
+
{
|
|
165
|
+
icon: "open_in_new",
|
|
166
|
+
variant: "tertiary",
|
|
167
|
+
size: "compact",
|
|
168
|
+
ariaLabel: openLabel,
|
|
169
|
+
href: src,
|
|
170
|
+
target: "_blank",
|
|
171
|
+
rel: "noopener noreferrer"
|
|
172
|
+
}
|
|
173
|
+
),
|
|
174
|
+
downloadButton
|
|
175
|
+
] })
|
|
176
|
+
] }),
|
|
177
|
+
/* @__PURE__ */ jsx("div", { className: "ds-document-viewer__body", children: body })
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
)
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
export {
|
|
184
|
+
DocumentViewer
|
|
185
|
+
};
|
|
@@ -211,6 +211,32 @@
|
|
|
211
211
|
line-height: 1;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
+
/* A row with a description: the label over a caption line, the pair
|
|
215
|
+
stacked and the icon centred on them, the two-line row ThemePicker's
|
|
216
|
+
rows set the pattern for. */
|
|
217
|
+
.ds-dropdown-menu__item-text {
|
|
218
|
+
display: flex;
|
|
219
|
+
flex-direction: column;
|
|
220
|
+
min-width: 0;
|
|
221
|
+
text-align: start;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.ds-dropdown-menu__item-title {
|
|
225
|
+
line-height: var(--font-paragraph-sm-line-height);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.ds-dropdown-menu__item-description {
|
|
229
|
+
font-size: var(--font-caption-size);
|
|
230
|
+
font-weight: var(--font-caption-weight);
|
|
231
|
+
line-height: var(--font-caption-line-height);
|
|
232
|
+
color: var(--color-text-tertiary);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.ds-dropdown-menu__item--destructive .ds-dropdown-menu__item-description {
|
|
236
|
+
color: var(--color-action-destructive-text-secondary);
|
|
237
|
+
opacity: 0.7;
|
|
238
|
+
}
|
|
239
|
+
|
|
214
240
|
/* Figma: icons are 24px within menu items */
|
|
215
241
|
.ds-dropdown-menu__item-icon {
|
|
216
242
|
--icon-size: var(--icon-size-600);
|
|
@@ -222,6 +248,18 @@
|
|
|
222
248
|
line-height: 1;
|
|
223
249
|
}
|
|
224
250
|
|
|
251
|
+
/* A trailing icon (an external link's open_in_new): the row's quietest
|
|
252
|
+
mark, one step under the leading icon, pushed to the trailing edge. */
|
|
253
|
+
.ds-dropdown-menu__item-icon-right {
|
|
254
|
+
--icon-size: var(--icon-size-500);
|
|
255
|
+
color: var(--color-icon-secondary);
|
|
256
|
+
flex-shrink: 0;
|
|
257
|
+
display: flex;
|
|
258
|
+
align-items: center;
|
|
259
|
+
margin-inline-start: auto;
|
|
260
|
+
line-height: 1;
|
|
261
|
+
}
|
|
262
|
+
|
|
225
263
|
/* ============================================
|
|
226
264
|
KEYBOARD SHORTCUT
|
|
227
265
|
============================================ */
|
|
@@ -4,12 +4,16 @@ export interface DropdownMenuItem {
|
|
|
4
4
|
type?: 'item';
|
|
5
5
|
/** Display label */
|
|
6
6
|
label: string;
|
|
7
|
+
/** A line under the label, such as what the choice does or means. It wraps the row to two lines in the caption style; the icon stays centred on the pair. */
|
|
8
|
+
description?: string;
|
|
7
9
|
/** Keyboard shortcut hint as literal text (e.g. "⇧ ⌘ P"). `keys` writes it for the reader's platform instead. */
|
|
8
10
|
shortcut?: string;
|
|
9
11
|
/** Keyboard shortcut hint in the shortcut grammar (`mod+shift+p`), written for the reader's platform (⇧⌘P on a Mac, Ctrl+Shift+P elsewhere) and announced through `aria-keyshortcuts`. Display only: bind the action itself with `useShortcut`. Wins over `shortcut`. */
|
|
10
12
|
keys?: Shortcut;
|
|
11
13
|
/** Item icon — Material Symbol name (string) or custom element (ReactNode) */
|
|
12
14
|
icon?: string | React.ReactNode;
|
|
15
|
+
/** A trailing icon after the label, such as `open_in_new` on an item that opens another site. Decorative: say what the item does in its label. A Material Symbol name (string) or a custom element (ReactNode). Ignored on an item that opens a sub-menu. */
|
|
16
|
+
iconRight?: string | React.ReactNode;
|
|
13
17
|
/** Disabled state */
|
|
14
18
|
disabled?: boolean;
|
|
15
19
|
/** Marks a dangerous or irreversible item (delete, remove…): it takes the destructive colour, with the error tint on hover and focus */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
3
|
import React, { useState, useCallback, useRef, useId, useEffect } from "react";
|
|
4
4
|
import { ChosenMark } from "../Dropdown/Dropdown.js";
|
|
5
5
|
import { CheckboxIndicator } from "../Checkbox/Checkbox.js";
|
|
@@ -8,7 +8,7 @@ import { useAnchoredPosition } from "../../behaviors/useAnchoredPosition.js";
|
|
|
8
8
|
import { MOTION_HOVER_HIDE_DELAY_MS } from "../../tokens/motion.js";
|
|
9
9
|
import "./DropdownMenu.css";
|
|
10
10
|
import "../../fonts/material-symbols.css";
|
|
11
|
-
import { MenuKeyLabelsContext, MenuShortcutHint } from "./ShortcutHint.js";
|
|
11
|
+
import { MenuKeyLabelsContext, MenuShortcutHint, MenuIconRight } from "./ShortcutHint.js";
|
|
12
12
|
import { shortcutAriaAnyPlatform } from "../../behaviors/shortcut-keys.js";
|
|
13
13
|
import { mirrorClass } from "../../behaviors/direction.js";
|
|
14
14
|
function collectItems(entries) {
|
|
@@ -33,6 +33,10 @@ function itemSemantics(item) {
|
|
|
33
33
|
return { role: "menuitem" };
|
|
34
34
|
}
|
|
35
35
|
const closesOnSelect = (item) => item.closeOnSelect ?? item.checked === void 0;
|
|
36
|
+
const MenuItemText = ({ baseClass, label, description }) => description ? /* @__PURE__ */ jsxs("span", { className: `${baseClass}__item-text`, children: [
|
|
37
|
+
/* @__PURE__ */ jsx("span", { className: `${baseClass}__item-title`, children: label }),
|
|
38
|
+
/* @__PURE__ */ jsx("span", { className: `${baseClass}__item-description`, children: description })
|
|
39
|
+
] }) : /* @__PURE__ */ jsx(Fragment, { children: label });
|
|
36
40
|
const ITEM_SELECTOR = '[role="menuitem"], [role="menuitemradio"], [role="menuitemcheckbox"]';
|
|
37
41
|
const SubMenuItem = ({ item, baseClass, itemId, focused, size, onActivate }) => {
|
|
38
42
|
const [subOpen, setSubOpen] = useState(false);
|
|
@@ -91,7 +95,7 @@ const SubMenuItem = ({ item, baseClass, itemId, focused, size, onActivate }) =>
|
|
|
91
95
|
children: [
|
|
92
96
|
/* @__PURE__ */ jsxs("span", { className: `${baseClass}__item-label`, children: [
|
|
93
97
|
item.icon && (typeof item.icon === "string" ? /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon material-symbols-rounded ${mirrorClass(item.icon)}`, "aria-hidden": "true", children: item.icon }) : /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon`, "aria-hidden": "true", children: item.icon })),
|
|
94
|
-
item.label
|
|
98
|
+
/* @__PURE__ */ jsx(MenuItemText, { baseClass, label: item.label, description: item.description })
|
|
95
99
|
] }),
|
|
96
100
|
/* @__PURE__ */ jsx("span", { className: `${baseClass}__submenu-icon material-symbols-rounded ds-mirror-rtl`, "aria-hidden": "true", children: "chevron_right" }),
|
|
97
101
|
subOpen && item.children && /* @__PURE__ */ jsx(
|
|
@@ -182,9 +186,10 @@ const MenuPanel = ({
|
|
|
182
186
|
}
|
|
183
187
|
),
|
|
184
188
|
entry.icon && (typeof entry.icon === "string" ? /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon material-symbols-rounded ${mirrorClass(entry.icon)}`, "aria-hidden": "true", children: entry.icon }) : /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon`, "aria-hidden": "true", children: entry.icon })),
|
|
185
|
-
entry.label
|
|
189
|
+
/* @__PURE__ */ jsx(MenuItemText, { baseClass, label: entry.label, description: entry.description })
|
|
186
190
|
] }),
|
|
187
191
|
/* @__PURE__ */ jsx(MenuShortcutHint, { item: entry, className: `${baseClass}__shortcut` }),
|
|
192
|
+
/* @__PURE__ */ jsx(MenuIconRight, { item: entry, baseClass }),
|
|
188
193
|
entry.selected && /* @__PURE__ */ jsx(ChosenMark, {})
|
|
189
194
|
]
|
|
190
195
|
},
|
|
@@ -393,9 +398,10 @@ const DropdownMenu = React.forwardRef(({
|
|
|
393
398
|
}
|
|
394
399
|
),
|
|
395
400
|
entry.icon && (typeof entry.icon === "string" ? /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon material-symbols-rounded ${mirrorClass(entry.icon)}`, "aria-hidden": "true", children: entry.icon }) : /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon`, "aria-hidden": "true", children: entry.icon })),
|
|
396
|
-
entry.label
|
|
401
|
+
/* @__PURE__ */ jsx(MenuItemText, { baseClass, label: entry.label, description: entry.description })
|
|
397
402
|
] }),
|
|
398
403
|
/* @__PURE__ */ jsx(MenuShortcutHint, { item: entry, className: `${baseClass}__shortcut` }),
|
|
404
|
+
/* @__PURE__ */ jsx(MenuIconRight, { item: entry, baseClass }),
|
|
399
405
|
entry.selected && /* @__PURE__ */ jsx(ChosenMark, {})
|
|
400
406
|
]
|
|
401
407
|
},
|
|
@@ -10,3 +10,12 @@ export declare function MenuShortcutHint({ item, className }: {
|
|
|
10
10
|
item: DropdownMenuItem;
|
|
11
11
|
className: string;
|
|
12
12
|
}): import("react").JSX.Element | null;
|
|
13
|
+
/**
|
|
14
|
+
* A menu row's trailing icon (`iconRight`), after the label and any
|
|
15
|
+
* shortcut hint, shared by DropdownMenu and ContextMenu. Decorative: the
|
|
16
|
+
* label says what the item does.
|
|
17
|
+
*/
|
|
18
|
+
export declare function MenuIconRight({ item, baseClass }: {
|
|
19
|
+
item: DropdownMenuItem;
|
|
20
|
+
baseClass: string;
|
|
21
|
+
}): import("react").JSX.Element | null;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useContext } from "react";
|
|
4
4
|
import { usePlatform } from "../../behaviors/shortcuts.js";
|
|
5
|
+
import { mirrorClass } from "../../behaviors/direction.js";
|
|
5
6
|
import { formatShortcut } from "../../behaviors/shortcut-keys.js";
|
|
6
7
|
const MenuKeyLabelsContext = createContext(void 0);
|
|
7
8
|
function MenuShortcutHint({ item, className }) {
|
|
@@ -11,7 +12,12 @@ function MenuShortcutHint({ item, className }) {
|
|
|
11
12
|
if (item.shortcut) return /* @__PURE__ */ jsx("span", { className, children: item.shortcut });
|
|
12
13
|
return null;
|
|
13
14
|
}
|
|
15
|
+
function MenuIconRight({ item, baseClass }) {
|
|
16
|
+
if (!item.iconRight) return null;
|
|
17
|
+
return typeof item.iconRight === "string" ? /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon-right material-symbols-rounded ${mirrorClass(item.iconRight)}`, "aria-hidden": "true", children: item.iconRight }) : /* @__PURE__ */ jsx("span", { className: `${baseClass}__item-icon-right`, "aria-hidden": "true", children: item.iconRight });
|
|
18
|
+
}
|
|
14
19
|
export {
|
|
20
|
+
MenuIconRight,
|
|
15
21
|
MenuKeyLabelsContext,
|
|
16
22
|
MenuShortcutHint
|
|
17
23
|
};
|