@slotted/react 0.1.0-beta.42 → 0.1.0-beta.43
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/{app-shell-D54YkU7E.js → app-shell-DsWhsSMU.js} +3 -2
- package/dist/app-shell.js +1 -1
- package/dist/attachment-TZykYNu5.js +300 -0
- package/dist/attachment.js +2 -2
- package/dist/{avatar-group-bJaZE1_C.js → avatar-group-Bzmmj2HI.js} +2 -1
- package/dist/avatar-group.js +1 -1
- package/dist/{carousel-B9nMK7Yf.js → carousel-CRNz-T3g.js} +1 -1
- package/dist/carousel.js +1 -1
- package/dist/{command-palette-C90CzfQi.js → command-palette-Bgf5tfCI.js} +160 -156
- package/dist/command-palette.js +1 -1
- package/dist/{data-grid-D106baPp.js → data-grid-DUft3rJb.js} +1 -1
- package/dist/data-grid.js +1 -1
- package/dist/{data-list-BA0xrySM.js → data-list-Dv3orBtf.js} +15 -15
- package/dist/data-list.js +1 -1
- package/dist/detail-panel-Cke3ZFU3.js +342 -0
- package/dist/detail-panel.js +2 -2
- package/dist/docs/action-bar.examples.md +768 -0
- package/dist/docs/action-bar.json +74 -50
- package/dist/docs/action-bar.md +49 -311
- package/dist/docs/app-shell.examples.md +1221 -64
- package/dist/docs/app-shell.json +92 -60
- package/dist/docs/app-shell.md +92 -57
- package/dist/docs/attachment.examples.md +689 -0
- package/dist/docs/attachment.json +69 -37
- package/dist/docs/attachment.md +44 -203
- package/dist/docs/avatar-group.json +111 -23
- package/dist/docs/avatar-group.md +487 -28
- package/dist/docs/button-group.json +98 -2
- package/dist/docs/button-group.md +411 -8
- package/dist/docs/calendar.examples.md +512 -0
- package/dist/docs/calendar.json +72 -24
- package/dist/docs/calendar.md +18 -147
- package/dist/docs/carousel.examples.md +868 -0
- package/dist/docs/carousel.json +58 -50
- package/dist/docs/carousel.md +66 -300
- package/dist/docs/cascader.examples.md +1269 -0
- package/dist/docs/cascader.json +72 -16
- package/dist/docs/cascader.md +78 -154
- package/dist/docs/chart.examples.md +734 -24
- package/dist/docs/chart.json +93 -13
- package/dist/docs/chart.md +28 -7
- package/dist/docs/clock.json +71 -15
- package/dist/docs/clock.md +326 -21
- package/dist/docs/code-block.json +79 -55
- package/dist/docs/code-block.md +417 -74
- package/dist/docs/color-picker.json +60 -12
- package/dist/docs/color-picker.md +245 -22
- package/dist/docs/column-manager.examples.md +764 -0
- package/dist/docs/column-manager.json +68 -12
- package/dist/docs/column-manager.md +44 -203
- package/dist/docs/command-palette.examples.md +747 -0
- package/dist/docs/command-palette.json +48 -24
- package/dist/docs/command-palette.md +60 -339
- package/dist/docs/currency-field.examples.md +355 -73
- package/dist/docs/currency-field.json +96 -64
- package/dist/docs/currency-field.md +57 -50
- package/dist/docs/dashboard-grid.examples.md +629 -0
- package/dist/docs/dashboard-grid.json +64 -16
- package/dist/docs/dashboard-grid.md +34 -152
- package/dist/docs/data-list.examples.md +1556 -0
- package/dist/docs/data-list.json +58 -18
- package/dist/docs/data-list.md +139 -224
- package/dist/docs/date-field.examples.md +543 -0
- package/dist/docs/date-field.json +64 -24
- package/dist/docs/date-field.md +22 -168
- package/dist/docs/datetime-field.examples.md +699 -0
- package/dist/docs/datetime-field.json +79 -31
- package/dist/docs/datetime-field.md +24 -269
- package/dist/docs/datetime-range-picker.examples.md +682 -0
- package/dist/docs/datetime-range-picker.json +117 -61
- package/dist/docs/datetime-range-picker.md +59 -224
- package/dist/docs/description-list.examples.md +652 -0
- package/dist/docs/description-list.json +49 -25
- package/dist/docs/description-list.md +33 -188
- package/dist/docs/detail-panel.examples.md +1177 -0
- package/dist/docs/detail-panel.json +69 -53
- package/dist/docs/detail-panel.md +114 -324
- package/dist/docs/entity-picker.examples.md +1037 -0
- package/dist/docs/entity-picker.json +66 -18
- package/dist/docs/entity-picker.md +56 -246
- package/dist/docs/event-calendar.examples.md +749 -49
- package/dist/docs/event-calendar.json +46 -22
- package/dist/docs/event-calendar.md +81 -11
- package/dist/docs/field-group.examples.md +554 -0
- package/dist/docs/field-group.json +98 -34
- package/dist/docs/field-group.md +55 -133
- package/dist/docs/filter-bar.examples.md +772 -0
- package/dist/docs/filter-bar.json +41 -25
- package/dist/docs/filter-bar.md +42 -246
- package/dist/docs/form.examples.md +579 -0
- package/dist/docs/form.json +87 -39
- package/dist/docs/form.md +53 -177
- package/dist/docs/fullscreen.examples.md +558 -0
- package/dist/docs/fullscreen.json +58 -18
- package/dist/docs/fullscreen.md +50 -169
- package/dist/docs/highlight.json +57 -25
- package/dist/docs/highlight.md +402 -50
- package/dist/docs/icon.json +85 -5
- package/dist/docs/icon.md +401 -10
- package/dist/docs/image.examples.md +670 -0
- package/dist/docs/image.json +44 -28
- package/dist/docs/image.md +24 -176
- package/dist/docs/import-export-center.examples.md +1280 -0
- package/dist/docs/import-export-center.json +67 -27
- package/dist/docs/import-export-center.md +121 -226
- package/dist/docs/list-item.examples.md +769 -0
- package/dist/docs/list-item.json +110 -38
- package/dist/docs/list-item.md +84 -201
- package/dist/docs/listbox.examples.md +858 -0
- package/dist/docs/listbox.json +76 -28
- package/dist/docs/listbox.md +41 -263
- package/dist/docs/markdown.json +79 -55
- package/dist/docs/markdown.md +581 -85
- package/dist/docs/media-viewer.examples.md +1038 -0
- package/dist/docs/media-viewer.json +70 -15
- package/dist/docs/media-viewer.md +84 -135
- package/dist/docs/message-scroller.examples.md +1193 -0
- package/dist/docs/message-scroller.json +41 -17
- package/dist/docs/message-scroller.md +80 -134
- package/dist/docs/message.examples.md +944 -0
- package/dist/docs/message.json +64 -16
- package/dist/docs/message.md +34 -326
- package/dist/docs/meter.json +58 -26
- package/dist/docs/meter.md +312 -32
- package/dist/docs/navigation-menu.examples.md +1107 -0
- package/dist/docs/navigation-menu.json +57 -41
- package/dist/docs/navigation-menu.md +105 -298
- package/dist/docs/notification-center.examples.md +1045 -0
- package/dist/docs/notification-center.json +71 -15
- package/dist/docs/notification-center.md +76 -266
- package/dist/docs/otp-input.examples.md +490 -0
- package/dist/docs/otp-input.json +65 -25
- package/dist/docs/otp-input.md +20 -191
- package/dist/docs/page-header.examples.md +1041 -0
- package/dist/docs/page-header.json +75 -43
- package/dist/docs/page-header.md +79 -291
- package/dist/docs/page.examples.md +633 -0
- package/dist/docs/page.json +48 -16
- package/dist/docs/page.md +62 -129
- package/dist/docs/prompt-composer.examples.md +630 -0
- package/dist/docs/prompt-composer.json +66 -18
- package/dist/docs/prompt-composer.md +35 -161
- package/dist/docs/prose.json +69 -37
- package/dist/docs/prose.md +393 -75
- package/dist/docs/rating.examples.md +525 -0
- package/dist/docs/rating.json +92 -28
- package/dist/docs/rating.md +27 -241
- package/dist/docs/saved-views.examples.md +1108 -0
- package/dist/docs/saved-views.json +53 -21
- package/dist/docs/saved-views.md +86 -171
- package/dist/docs/scroll-area.examples.md +837 -0
- package/dist/docs/scroll-area.json +64 -24
- package/dist/docs/scroll-area.md +57 -140
- package/dist/docs/section.examples.md +676 -0
- package/dist/docs/section.json +68 -20
- package/dist/docs/section.md +39 -162
- package/dist/docs/segmented-control.examples.md +480 -0
- package/dist/docs/segmented-control.json +76 -28
- package/dist/docs/segmented-control.md +20 -191
- package/dist/docs/side-navigation.examples.md +1468 -0
- package/dist/docs/side-navigation.json +53 -53
- package/dist/docs/side-navigation.md +79 -354
- package/dist/docs/slider.examples.md +505 -0
- package/dist/docs/slider.json +91 -51
- package/dist/docs/slider.md +47 -212
- package/dist/docs/sparkline.json +60 -36
- package/dist/docs/sparkline.md +447 -71
- package/dist/docs/split-button.examples.md +509 -0
- package/dist/docs/split-button.json +73 -41
- package/dist/docs/split-button.md +64 -194
- package/dist/docs/splitter.examples.md +921 -0
- package/dist/docs/splitter.json +94 -46
- package/dist/docs/splitter.md +75 -182
- package/dist/docs/stat-card.examples.md +725 -0
- package/dist/docs/stat-card.json +89 -41
- package/dist/docs/stat-card.md +55 -227
- package/dist/docs/status-indicator.json +80 -32
- package/dist/docs/status-indicator.md +409 -65
- package/dist/docs/stepper.json +53 -21
- package/dist/docs/stepper.md +369 -48
- package/dist/docs/table-of-contents.examples.md +550 -0
- package/dist/docs/table-of-contents.json +60 -28
- package/dist/docs/table-of-contents.md +70 -205
- package/dist/docs/tags-input.examples.md +541 -0
- package/dist/docs/tags-input.json +64 -16
- package/dist/docs/tags-input.md +15 -262
- package/dist/docs/time-field.examples.md +587 -0
- package/dist/docs/time-field.json +69 -29
- package/dist/docs/time-field.md +21 -223
- package/dist/docs/time-picker.json +117 -53
- package/dist/docs/time-picker.md +499 -54
- package/dist/docs/time-range-picker.examples.md +750 -0
- package/dist/docs/time-range-picker.json +139 -75
- package/dist/docs/time-range-picker.md +63 -225
- package/dist/docs/timeline.examples.md +617 -0
- package/dist/docs/timeline.json +44 -28
- package/dist/docs/timeline.md +34 -208
- package/dist/docs/toolbar.json +56 -16
- package/dist/docs/toolbar.md +357 -63
- package/dist/docs/top-navigation.examples.md +1206 -140
- package/dist/docs/top-navigation.json +49 -33
- package/dist/docs/top-navigation.md +87 -36
- package/dist/docs/tour.examples.md +960 -0
- package/dist/docs/tour.json +57 -25
- package/dist/docs/tour.md +60 -244
- package/dist/docs/transfer.examples.md +631 -0
- package/dist/docs/transfer.json +80 -16
- package/dist/docs/transfer.md +41 -170
- package/dist/docs/typography.json +96 -0
- package/dist/docs/typography.md +352 -4
- package/dist/docs/upload.examples.md +555 -53
- package/dist/docs/upload.json +62 -30
- package/dist/docs/upload.md +46 -11
- package/dist/docs/wizard.examples.md +1389 -0
- package/dist/docs/wizard.json +89 -49
- package/dist/docs/wizard.md +122 -263
- package/dist/{entity-picker-CC4VoC3p.js → entity-picker-C78f3Z0o.js} +9 -6
- package/dist/entity-picker.js +1 -1
- package/dist/{event-calendar-CjmF_e0H.js → event-calendar-DJPoCi-O.js} +1 -1
- package/dist/event-calendar.js +1 -1
- package/dist/{filter-bar-B3QJD7SZ.js → filter-bar-D61wiQFP.js} +1 -1
- package/dist/filter-bar.js +1 -1
- package/dist/{import-export-center-CW8YVZev.js → import-export-center-mqvmlzwB.js} +44 -36
- package/dist/import-export-center.js +1 -1
- package/dist/index.js +58 -58
- package/dist/{markdown-BdskE4-L.js → markdown-8CtV4k44.js} +2 -2
- package/dist/markdown.js +1 -1
- package/dist/{media-viewer-zEXcwfEY.js → media-viewer-C_cbuAq-.js} +64 -60
- package/dist/media-viewer.js +2 -2
- package/dist/message-P91bEGyV.js +455 -0
- package/dist/message.js +2 -2
- package/dist/{page-header-DmwBGwlm.js → page-header-jeAIQSZM.js} +103 -108
- package/dist/page-header.js +1 -1
- package/dist/section-CVTQdWBl.js +216 -0
- package/dist/section.js +2 -2
- package/dist/{segmented-control-CbK7SurB.js → segmented-control-BSMVjukr.js} +1 -1
- package/dist/segmented-control.js +1 -1
- package/dist/{side-navigation-CKRETc8E.js → side-navigation-BQzBxz2B.js} +179 -179
- package/dist/side-navigation.js +1 -1
- package/dist/{stat-card-CL3Xe6pV.js → stat-card-BpGZiFbG.js} +12 -14
- package/dist/stat-card.js +1 -1
- package/dist/{stepper-DHdrANZI.js → stepper-Cxb_tHnA.js} +130 -127
- package/dist/stepper.js +2 -2
- package/dist/styles/carousel.css +1 -1
- package/dist/styles/index.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/{timeline-BiL2CXfn.js → timeline-ZngK6zLC.js} +9 -6
- package/dist/timeline.js +1 -1
- package/dist/top-navigation-YSEQzBhD.js +744 -0
- package/dist/top-navigation.js +2 -2
- package/dist/{transfer-sKUvmEKe.js → transfer-Cv5yQuTN.js} +1 -1
- package/dist/transfer.js +1 -1
- package/dist/types/attachment/attachment-parts.d.ts +24 -11
- package/dist/types/attachment/attachment-parts.d.ts.map +1 -1
- package/dist/types/attachment/attachment.d.ts +3 -3
- package/dist/types/attachment/attachment.d.ts.map +1 -1
- package/dist/types/avatar-group/avatar-group.d.ts.map +1 -1
- package/dist/types/carousel/carousel-parts.d.ts +2 -2
- package/dist/types/command-palette/command-palette.d.ts.map +1 -1
- package/dist/types/data-list/data-list.d.ts.map +1 -1
- package/dist/types/detail-panel/detail-panel-parts.d.ts +10 -3
- package/dist/types/detail-panel/detail-panel-parts.d.ts.map +1 -1
- package/dist/types/detail-panel/detail-panel.d.ts.map +1 -1
- package/dist/types/detail-panel/detail-panel.types.d.ts +7 -0
- package/dist/types/detail-panel/detail-panel.types.d.ts.map +1 -1
- package/dist/types/entity-picker/entity-picker.d.ts.map +1 -1
- package/dist/types/import-export-center/import-export-center.d.ts.map +1 -1
- package/dist/types/media-viewer/index.d.ts +2 -2
- package/dist/types/media-viewer/index.d.ts.map +1 -1
- package/dist/types/media-viewer/media-viewer-bar.d.ts +3 -1
- package/dist/types/media-viewer/media-viewer-bar.d.ts.map +1 -1
- package/dist/types/media-viewer/media-viewer.types.d.ts +1 -0
- package/dist/types/media-viewer/media-viewer.types.d.ts.map +1 -1
- package/dist/types/message/message-parts.d.ts +7 -0
- package/dist/types/message/message-parts.d.ts.map +1 -1
- package/dist/types/message/message.d.ts.map +1 -1
- package/dist/types/page-header/page-header-parts.d.ts.map +1 -1
- package/dist/types/section/section-parts.d.ts +16 -8
- package/dist/types/section/section-parts.d.ts.map +1 -1
- package/dist/types/section/section.d.ts.map +1 -1
- package/dist/types/segmented-control/segmented-control-parts.d.ts.map +1 -1
- package/dist/types/side-navigation/side-navigation-parts.d.ts.map +1 -1
- package/dist/types/stat-card/stat-card-delta.d.ts.map +1 -1
- package/dist/types/stat-card/stat-card-parts.d.ts +3 -3
- package/dist/types/stat-card/stat-card-parts.d.ts.map +1 -1
- package/dist/types/stepper/stepper-parts.d.ts +11 -2
- package/dist/types/stepper/stepper-parts.d.ts.map +1 -1
- package/dist/types/stepper/stepper.d.ts.map +1 -1
- package/dist/types/timeline/timeline-parts.d.ts.map +1 -1
- package/dist/types/top-navigation/top-navigation.d.ts.map +1 -1
- package/dist/{wizard-4c0X7Bx_.js → wizard-Dfryz1id.js} +214 -214
- package/dist/wizard.js +1 -1
- package/package.json +6 -6
- package/dist/attachment-MqczA38F.js +0 -292
- package/dist/detail-panel-EImAtksY.js +0 -327
- package/dist/message-D1Dd6Y2k.js +0 -452
- package/dist/section-D_qOfdxR.js +0 -213
- package/dist/top-navigation-D8IHPOmm.js +0 -744
|
@@ -0,0 +1,1038 @@
|
|
|
1
|
+
<!-- index: ./index.md -->
|
|
2
|
+
# media-viewer
|
|
3
|
+
|
|
4
|
+
`data-ui="media-viewer"` · Full-screen viewer of files: fitted, zoomed, stepped.
|
|
5
|
+
|
|
6
|
+
## Examples
|
|
7
|
+
|
|
8
|
+
### The photographs of a claim
|
|
9
|
+
|
|
10
|
+
Open any photograph: it stands whole on the dark ground, never larger than its own pixels. Previous and next walk the set; the bar says which of how many.
|
|
11
|
+
|
|
12
|
+
Excerpt — not a complete module
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
<>
|
|
16
|
+
<AttachmentTrigger
|
|
17
|
+
onClick={() => {
|
|
18
|
+
setValue(file.id);
|
|
19
|
+
setOpen(true);
|
|
20
|
+
}}
|
|
21
|
+
/>
|
|
22
|
+
<MediaViewer
|
|
23
|
+
items={files}
|
|
24
|
+
open={open}
|
|
25
|
+
onOpenChange={setOpen}
|
|
26
|
+
value={value}
|
|
27
|
+
onValueChange={setValue}
|
|
28
|
+
/>
|
|
29
|
+
</>;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Zoom around a point
|
|
33
|
+
|
|
34
|
+
The wheel zooms around the point under the pointer by distance, so a trackpad’s many small events do not jump to the maximum. Drag to pan; double-click returns to the fit.
|
|
35
|
+
|
|
36
|
+
Example
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { Button } from '@slotted/react/button';
|
|
40
|
+
import { Inline } from '@slotted/react/inline';
|
|
41
|
+
import { MediaViewer, type MediaViewerItem } from '@slotted/react/media-viewer';
|
|
42
|
+
import { useState } from 'react';
|
|
43
|
+
|
|
44
|
+
const photo = (width: number, height: number, sky: string, crate: string) =>
|
|
45
|
+
'data:image/svg+xml,' +
|
|
46
|
+
encodeURIComponent(
|
|
47
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}">` +
|
|
48
|
+
`<rect width="100%" height="100%" fill="${sky}"/>` +
|
|
49
|
+
`<rect y="${String(height * 0.7)}" width="100%" height="${String(height * 0.3)}" fill="#4b5563"/>` +
|
|
50
|
+
`<rect x="${String(width * 0.3)}" y="${String(height * 0.4)}" width="${String(width * 0.4)}" height="${String(height * 0.3)}" fill="${crate}"/>` +
|
|
51
|
+
'</svg>',
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const FRONT: MediaViewerItem = {
|
|
55
|
+
id: 'front',
|
|
56
|
+
name: 'pallet-front.jpg',
|
|
57
|
+
type: 'image/jpeg',
|
|
58
|
+
src: photo(2400, 1600, '#bfdbfe', '#c2410c'),
|
|
59
|
+
caption: 'Front face of pallet 7: two crushed corners.',
|
|
60
|
+
downloadHref: '#pallet-front.jpg',
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const REAR: MediaViewerItem = {
|
|
64
|
+
id: 'rear',
|
|
65
|
+
name: 'pallet-rear.jpg',
|
|
66
|
+
type: 'image/jpeg',
|
|
67
|
+
src: photo(1200, 1600, '#e0e7ff', '#9a3412'),
|
|
68
|
+
caption: 'Rear face, taken on the dock.',
|
|
69
|
+
downloadHref: '#pallet-rear.jpg',
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const LABEL: MediaViewerItem = {
|
|
73
|
+
id: 'label',
|
|
74
|
+
name: 'carrier-label.jpg',
|
|
75
|
+
type: 'image/jpeg',
|
|
76
|
+
src: photo(320, 200, '#fde68a', '#78350f'),
|
|
77
|
+
downloadHref: '#carrier-label.jpg',
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const PHOTOS = [FRONT, REAR, LABEL];
|
|
81
|
+
|
|
82
|
+
export default function MediaViewerZoomExample() {
|
|
83
|
+
const [open, setOpen] = useState(false);
|
|
84
|
+
const [value, setValue] = useState('front');
|
|
85
|
+
|
|
86
|
+
function handleOpen(id: string) {
|
|
87
|
+
setValue(id);
|
|
88
|
+
setOpen(true);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<>
|
|
93
|
+
<Inline gap={2}>
|
|
94
|
+
{PHOTOS.map((file) => (
|
|
95
|
+
<Button
|
|
96
|
+
key={file.id}
|
|
97
|
+
onClick={() => handleOpen(file.id)}
|
|
98
|
+
size="sm"
|
|
99
|
+
tone="secondary"
|
|
100
|
+
variant="outline"
|
|
101
|
+
>
|
|
102
|
+
{file.name}
|
|
103
|
+
</Button>
|
|
104
|
+
))}
|
|
105
|
+
</Inline>
|
|
106
|
+
<MediaViewer
|
|
107
|
+
items={PHOTOS}
|
|
108
|
+
open={open}
|
|
109
|
+
onOpenChange={setOpen}
|
|
110
|
+
value={value}
|
|
111
|
+
onValueChange={setValue}
|
|
112
|
+
maxZoom={8}
|
|
113
|
+
zoomStep={0.5}
|
|
114
|
+
/>
|
|
115
|
+
</>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### A photograph, a PDF, a JSON export and a spreadsheet
|
|
121
|
+
|
|
122
|
+
The PDF opens in the browser’s own reader; the JSON export is read as text, indented and never executed, as a log, a CSV or source would be. A spreadsheet the browser cannot draw gets its tile, a sentence and the download.
|
|
123
|
+
|
|
124
|
+
Example
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
import { Button } from '@slotted/react/button';
|
|
128
|
+
import { Inline } from '@slotted/react/inline';
|
|
129
|
+
import { MediaViewer, type MediaViewerItem } from '@slotted/react/media-viewer';
|
|
130
|
+
import { useState } from 'react';
|
|
131
|
+
|
|
132
|
+
const photo = (width: number, height: number, sky: string, crate: string) =>
|
|
133
|
+
'data:image/svg+xml,' +
|
|
134
|
+
encodeURIComponent(
|
|
135
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}">` +
|
|
136
|
+
`<rect width="100%" height="100%" fill="${sky}"/>` +
|
|
137
|
+
`<rect y="${String(height * 0.7)}" width="100%" height="${String(height * 0.3)}" fill="#4b5563"/>` +
|
|
138
|
+
`<rect x="${String(width * 0.3)}" y="${String(height * 0.4)}" width="${String(width * 0.4)}" height="${String(height * 0.3)}" fill="${crate}"/>` +
|
|
139
|
+
'</svg>',
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const FRONT: MediaViewerItem = {
|
|
143
|
+
id: 'front',
|
|
144
|
+
name: 'pallet-front.jpg',
|
|
145
|
+
type: 'image/jpeg',
|
|
146
|
+
src: photo(2400, 1600, '#bfdbfe', '#c2410c'),
|
|
147
|
+
caption: 'Front face of pallet 7: two crushed corners.',
|
|
148
|
+
downloadHref: '#pallet-front.jpg',
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const PDF_SOURCE = `%PDF-1.4
|
|
152
|
+
1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj
|
|
153
|
+
2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj
|
|
154
|
+
3 0 obj<</Type/Page/Parent 2 0 R/MediaBox[0 0 595 842]/Contents 4 0 R/Resources<</Font<</F1 5 0 R>>>>>>endobj
|
|
155
|
+
4 0 obj<</Length 150>>stream
|
|
156
|
+
BT /F1 22 Tf 72 760 Td (Carrier damage report SH-20418) Tj 0 -36 Td /F1 12 Tf (Two pallets crushed at the Rotterdam dock.) Tj ET
|
|
157
|
+
endstream endobj
|
|
158
|
+
5 0 obj<</Type/Font/Subtype/Type1/BaseFont/Helvetica>>endobj
|
|
159
|
+
trailer<</Root 1 0 R>>
|
|
160
|
+
%%EOF`;
|
|
161
|
+
|
|
162
|
+
const REPORT: MediaViewerItem = {
|
|
163
|
+
id: 'report',
|
|
164
|
+
name: 'carrier-report.pdf',
|
|
165
|
+
type: 'application/pdf',
|
|
166
|
+
src: `data:application/pdf;base64,${btoa(PDF_SOURCE)}`,
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const EXPORT = JSON.stringify({
|
|
170
|
+
shipment: 'SH-20418',
|
|
171
|
+
carrier: 'Harbor Freight',
|
|
172
|
+
delivered: '2026-09-13',
|
|
173
|
+
pallets: 12,
|
|
174
|
+
damaged: [7, 9],
|
|
175
|
+
estimate: { parts: 1840.5, labour: 960, currency: 'EUR' },
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const EXPORT_ITEM: MediaViewerItem = {
|
|
179
|
+
id: 'export',
|
|
180
|
+
name: 'shipment-20418.json',
|
|
181
|
+
type: 'application/json',
|
|
182
|
+
src: `data:application/json,${encodeURIComponent(EXPORT)}`,
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const SHEET: MediaViewerItem = {
|
|
186
|
+
id: 'estimate',
|
|
187
|
+
name: 'damage-estimate.xlsx',
|
|
188
|
+
type: '',
|
|
189
|
+
src: '#damage-estimate.xlsx',
|
|
190
|
+
downloadHref: '#damage-estimate.xlsx',
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const FILES = [FRONT, REPORT, EXPORT_ITEM, SHEET];
|
|
194
|
+
|
|
195
|
+
export default function MediaViewerKindsExample() {
|
|
196
|
+
const [open, setOpen] = useState(false);
|
|
197
|
+
const [value, setValue] = useState('front');
|
|
198
|
+
|
|
199
|
+
function handleOpen(id: string) {
|
|
200
|
+
setValue(id);
|
|
201
|
+
setOpen(true);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<>
|
|
206
|
+
<Inline gap={2}>
|
|
207
|
+
{FILES.map((file) => (
|
|
208
|
+
<Button
|
|
209
|
+
key={file.id}
|
|
210
|
+
onClick={() => handleOpen(file.id)}
|
|
211
|
+
size="sm"
|
|
212
|
+
tone="secondary"
|
|
213
|
+
variant="outline"
|
|
214
|
+
>
|
|
215
|
+
{file.name}
|
|
216
|
+
</Button>
|
|
217
|
+
))}
|
|
218
|
+
</Inline>
|
|
219
|
+
<MediaViewer
|
|
220
|
+
items={FILES}
|
|
221
|
+
open={open}
|
|
222
|
+
onOpenChange={setOpen}
|
|
223
|
+
value={value}
|
|
224
|
+
onValueChange={setValue}
|
|
225
|
+
/>
|
|
226
|
+
</>
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### A picture that fails to load
|
|
232
|
+
|
|
233
|
+
The photograph’s address no longer answers: the stage says what happened and offers to try again or to download, and the zoom pill leaves because there is nothing to zoom.
|
|
234
|
+
|
|
235
|
+
Example
|
|
236
|
+
|
|
237
|
+
```tsx
|
|
238
|
+
import { Button } from '@slotted/react/button';
|
|
239
|
+
import { Inline } from '@slotted/react/inline';
|
|
240
|
+
import { MediaViewer, type MediaViewerItem } from '@slotted/react/media-viewer';
|
|
241
|
+
import { useState } from 'react';
|
|
242
|
+
|
|
243
|
+
const photo = (width: number, height: number, sky: string, crate: string) =>
|
|
244
|
+
'data:image/svg+xml,' +
|
|
245
|
+
encodeURIComponent(
|
|
246
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}">` +
|
|
247
|
+
`<rect width="100%" height="100%" fill="${sky}"/>` +
|
|
248
|
+
`<rect y="${String(height * 0.7)}" width="100%" height="${String(height * 0.3)}" fill="#4b5563"/>` +
|
|
249
|
+
`<rect x="${String(width * 0.3)}" y="${String(height * 0.4)}" width="${String(width * 0.4)}" height="${String(height * 0.3)}" fill="${crate}"/>` +
|
|
250
|
+
'</svg>',
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
const FRONT: MediaViewerItem = {
|
|
254
|
+
id: 'front',
|
|
255
|
+
name: 'pallet-front.jpg',
|
|
256
|
+
type: 'image/jpeg',
|
|
257
|
+
src: photo(2400, 1600, '#bfdbfe', '#c2410c'),
|
|
258
|
+
caption: 'Front face of pallet 7: two crushed corners.',
|
|
259
|
+
downloadHref: '#pallet-front.jpg',
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const BROKEN: MediaViewerItem = {
|
|
263
|
+
id: 'broken',
|
|
264
|
+
name: 'pallet-side.jpg',
|
|
265
|
+
type: 'image/jpeg',
|
|
266
|
+
src: 'data:image/jpeg;base64,AAAA',
|
|
267
|
+
downloadHref: '#pallet-side.jpg',
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const REAR: MediaViewerItem = {
|
|
271
|
+
id: 'rear',
|
|
272
|
+
name: 'pallet-rear.jpg',
|
|
273
|
+
type: 'image/jpeg',
|
|
274
|
+
src: photo(1200, 1600, '#e0e7ff', '#9a3412'),
|
|
275
|
+
caption: 'Rear face, taken on the dock.',
|
|
276
|
+
downloadHref: '#pallet-rear.jpg',
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const FILES = [FRONT, BROKEN, REAR];
|
|
280
|
+
|
|
281
|
+
export default function MediaViewerStatesExample() {
|
|
282
|
+
const [open, setOpen] = useState(false);
|
|
283
|
+
const [value, setValue] = useState('front');
|
|
284
|
+
|
|
285
|
+
function handleOpen(id: string) {
|
|
286
|
+
setValue(id);
|
|
287
|
+
setOpen(true);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return (
|
|
291
|
+
<>
|
|
292
|
+
<Inline gap={2}>
|
|
293
|
+
{FILES.map((file) => (
|
|
294
|
+
<Button
|
|
295
|
+
key={file.id}
|
|
296
|
+
onClick={() => handleOpen(file.id)}
|
|
297
|
+
size="sm"
|
|
298
|
+
tone="secondary"
|
|
299
|
+
variant="outline"
|
|
300
|
+
>
|
|
301
|
+
{file.name}
|
|
302
|
+
</Button>
|
|
303
|
+
))}
|
|
304
|
+
</Inline>
|
|
305
|
+
<MediaViewer
|
|
306
|
+
items={FILES}
|
|
307
|
+
open={open}
|
|
308
|
+
onOpenChange={setOpen}
|
|
309
|
+
value={value}
|
|
310
|
+
onValueChange={setValue}
|
|
311
|
+
/>
|
|
312
|
+
</>
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### A long name and a set of one
|
|
318
|
+
|
|
319
|
+
A scanner’s name is cut in the middle so the extension stays; the whole name is in the tooltip and the accessible name. A single file draws no steps and no position.
|
|
320
|
+
|
|
321
|
+
Example
|
|
322
|
+
|
|
323
|
+
```tsx
|
|
324
|
+
import { Button } from '@slotted/react/button';
|
|
325
|
+
import { Inline } from '@slotted/react/inline';
|
|
326
|
+
import { MediaViewer, type MediaViewerItem } from '@slotted/react/media-viewer';
|
|
327
|
+
import { useState } from 'react';
|
|
328
|
+
|
|
329
|
+
const photo = (width: number, height: number, sky: string, crate: string) =>
|
|
330
|
+
'data:image/svg+xml,' +
|
|
331
|
+
encodeURIComponent(
|
|
332
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}">` +
|
|
333
|
+
`<rect width="100%" height="100%" fill="${sky}"/>` +
|
|
334
|
+
`<rect y="${String(height * 0.7)}" width="100%" height="${String(height * 0.3)}" fill="#4b5563"/>` +
|
|
335
|
+
`<rect x="${String(width * 0.3)}" y="${String(height * 0.4)}" width="${String(width * 0.4)}" height="${String(height * 0.3)}" fill="${crate}"/>` +
|
|
336
|
+
'</svg>',
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
const SCAN: MediaViewerItem = {
|
|
340
|
+
id: 'scan',
|
|
341
|
+
name: 'scan_2026-09-14_delivery-note_consignee-signature_page-1-of-3_final.png',
|
|
342
|
+
type: 'image/png',
|
|
343
|
+
src: photo(1240, 1754, '#f5f5f4', '#d6d3d1'),
|
|
344
|
+
width: 1240,
|
|
345
|
+
height: 1754,
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
const FILES = [SCAN];
|
|
349
|
+
|
|
350
|
+
export default function MediaViewerContentExample() {
|
|
351
|
+
const [open, setOpen] = useState(false);
|
|
352
|
+
const [value, setValue] = useState('scan');
|
|
353
|
+
|
|
354
|
+
function handleOpen(id: string) {
|
|
355
|
+
setValue(id);
|
|
356
|
+
setOpen(true);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return (
|
|
360
|
+
<>
|
|
361
|
+
<Inline gap={2}>
|
|
362
|
+
{FILES.map((file) => (
|
|
363
|
+
<Button
|
|
364
|
+
key={file.id}
|
|
365
|
+
onClick={() => handleOpen(file.id)}
|
|
366
|
+
size="sm"
|
|
367
|
+
tone="secondary"
|
|
368
|
+
variant="outline"
|
|
369
|
+
>
|
|
370
|
+
{file.name}
|
|
371
|
+
</Button>
|
|
372
|
+
))}
|
|
373
|
+
</Inline>
|
|
374
|
+
<MediaViewer
|
|
375
|
+
items={FILES}
|
|
376
|
+
open={open}
|
|
377
|
+
onOpenChange={setOpen}
|
|
378
|
+
value={value}
|
|
379
|
+
onValueChange={setValue}
|
|
380
|
+
/>
|
|
381
|
+
</>
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### A strip of the set
|
|
387
|
+
|
|
388
|
+
Composed under the stage: the current photograph is framed and the others dimmed until the pointer reaches them. A press steps straight to that file.
|
|
389
|
+
|
|
390
|
+
Example
|
|
391
|
+
|
|
392
|
+
```tsx
|
|
393
|
+
import { Button } from '@slotted/react/button';
|
|
394
|
+
import { Inline } from '@slotted/react/inline';
|
|
395
|
+
import {
|
|
396
|
+
MediaViewer,
|
|
397
|
+
MediaViewerBar,
|
|
398
|
+
MediaViewerCaption,
|
|
399
|
+
MediaViewerNext,
|
|
400
|
+
MediaViewerPrevious,
|
|
401
|
+
MediaViewerStage,
|
|
402
|
+
MediaViewerThumbnails,
|
|
403
|
+
MediaViewerZoom,
|
|
404
|
+
type MediaViewerItem,
|
|
405
|
+
} from '@slotted/react/media-viewer';
|
|
406
|
+
import { useState } from 'react';
|
|
407
|
+
|
|
408
|
+
const photo = (width: number, height: number, sky: string, crate: string) =>
|
|
409
|
+
'data:image/svg+xml,' +
|
|
410
|
+
encodeURIComponent(
|
|
411
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}">` +
|
|
412
|
+
`<rect width="100%" height="100%" fill="${sky}"/>` +
|
|
413
|
+
`<rect y="${String(height * 0.7)}" width="100%" height="${String(height * 0.3)}" fill="#4b5563"/>` +
|
|
414
|
+
`<rect x="${String(width * 0.3)}" y="${String(height * 0.4)}" width="${String(width * 0.4)}" height="${String(height * 0.3)}" fill="${crate}"/>` +
|
|
415
|
+
'</svg>',
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
const FRONT: MediaViewerItem = {
|
|
419
|
+
id: 'front',
|
|
420
|
+
name: 'pallet-front.jpg',
|
|
421
|
+
type: 'image/jpeg',
|
|
422
|
+
src: photo(2400, 1600, '#bfdbfe', '#c2410c'),
|
|
423
|
+
caption: 'Front face of pallet 7: two crushed corners.',
|
|
424
|
+
downloadHref: '#pallet-front.jpg',
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
const REAR: MediaViewerItem = {
|
|
428
|
+
id: 'rear',
|
|
429
|
+
name: 'pallet-rear.jpg',
|
|
430
|
+
type: 'image/jpeg',
|
|
431
|
+
src: photo(1200, 1600, '#e0e7ff', '#9a3412'),
|
|
432
|
+
caption: 'Rear face, taken on the dock.',
|
|
433
|
+
downloadHref: '#pallet-rear.jpg',
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
const LABEL: MediaViewerItem = {
|
|
437
|
+
id: 'label',
|
|
438
|
+
name: 'carrier-label.jpg',
|
|
439
|
+
type: 'image/jpeg',
|
|
440
|
+
src: photo(320, 200, '#fde68a', '#78350f'),
|
|
441
|
+
downloadHref: '#carrier-label.jpg',
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const PHOTOS = [FRONT, REAR, LABEL];
|
|
445
|
+
|
|
446
|
+
export default function MediaViewerThumbnailsExample() {
|
|
447
|
+
const [open, setOpen] = useState(false);
|
|
448
|
+
const [value, setValue] = useState('front');
|
|
449
|
+
|
|
450
|
+
function handleOpen(id: string) {
|
|
451
|
+
setValue(id);
|
|
452
|
+
setOpen(true);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return (
|
|
456
|
+
<>
|
|
457
|
+
<Inline gap={2}>
|
|
458
|
+
{PHOTOS.map((file) => (
|
|
459
|
+
<Button
|
|
460
|
+
key={file.id}
|
|
461
|
+
onClick={() => handleOpen(file.id)}
|
|
462
|
+
size="sm"
|
|
463
|
+
tone="secondary"
|
|
464
|
+
variant="outline"
|
|
465
|
+
>
|
|
466
|
+
{file.name}
|
|
467
|
+
</Button>
|
|
468
|
+
))}
|
|
469
|
+
</Inline>
|
|
470
|
+
<MediaViewer
|
|
471
|
+
items={PHOTOS}
|
|
472
|
+
open={open}
|
|
473
|
+
onOpenChange={setOpen}
|
|
474
|
+
value={value}
|
|
475
|
+
onValueChange={setValue}
|
|
476
|
+
>
|
|
477
|
+
<MediaViewerBar />
|
|
478
|
+
<MediaViewerStage />
|
|
479
|
+
<MediaViewerPrevious />
|
|
480
|
+
<MediaViewerNext />
|
|
481
|
+
<MediaViewerZoom />
|
|
482
|
+
<MediaViewerCaption />
|
|
483
|
+
<MediaViewerThumbnails aria-label="Shipment photographs" />
|
|
484
|
+
</MediaViewer>
|
|
485
|
+
</>
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### Actions of the product, defaults of the application
|
|
491
|
+
|
|
492
|
+
The bar takes the product’s own controls beside the download. A provider sets the limits, the loop and the words once for every viewer under it.
|
|
493
|
+
|
|
494
|
+
Excerpt — not a complete module
|
|
495
|
+
|
|
496
|
+
```tsx
|
|
497
|
+
<MediaViewerDefaultsProvider maxZoom={6} loop>
|
|
498
|
+
<MediaViewer items={files} defaultOpen>
|
|
499
|
+
<MediaViewerBar>
|
|
500
|
+
<MediaViewerHeading />
|
|
501
|
+
<MediaViewerActions>
|
|
502
|
+
<Button onClick={share}>Share</Button>
|
|
503
|
+
<MediaViewerDownload />
|
|
504
|
+
</MediaViewerActions>
|
|
505
|
+
<MediaViewerClose />
|
|
506
|
+
</MediaViewerBar>
|
|
507
|
+
<MediaViewerStage />
|
|
508
|
+
</MediaViewer>
|
|
509
|
+
</MediaViewerDefaultsProvider>;
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
### The application holds the file and the level
|
|
513
|
+
|
|
514
|
+
Every move is a request with a reason: the step says pointer, keyboard or remove, the level says pointer, keyboard or select. The log below the openers shows each one.
|
|
515
|
+
|
|
516
|
+
Excerpt — not a complete module
|
|
517
|
+
|
|
518
|
+
```tsx
|
|
519
|
+
<MediaViewer
|
|
520
|
+
items={files}
|
|
521
|
+
open={open}
|
|
522
|
+
onOpenChange={setOpen}
|
|
523
|
+
value={value}
|
|
524
|
+
onValueChange={(next, { reason }) => {
|
|
525
|
+
setValue(next);
|
|
526
|
+
log(`step by ${reason}`);
|
|
527
|
+
}}
|
|
528
|
+
zoom={zoom}
|
|
529
|
+
onZoomChange={(next) => setZoom(next)}
|
|
530
|
+
/>;
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
### Every key of the viewer
|
|
534
|
+
|
|
535
|
+
Arrows step while the picture fits and pan once it is zoomed; plus, minus and zero zoom; R turns; Home and End reach the ends; Escape closes and focus returns to the opener.
|
|
536
|
+
|
|
537
|
+
Excerpt — not a complete module
|
|
538
|
+
|
|
539
|
+
```tsx
|
|
540
|
+
<MediaViewer items={files} defaultOpen />;
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
### actions.tsx
|
|
544
|
+
|
|
545
|
+
Example
|
|
546
|
+
|
|
547
|
+
```tsx
|
|
548
|
+
import { Button } from '@slotted/react/button';
|
|
549
|
+
import { Inline } from '@slotted/react/inline';
|
|
550
|
+
import {
|
|
551
|
+
MediaViewer,
|
|
552
|
+
MediaViewerActions,
|
|
553
|
+
MediaViewerBar,
|
|
554
|
+
MediaViewerClose,
|
|
555
|
+
MediaViewerDownload,
|
|
556
|
+
MediaViewerHeading,
|
|
557
|
+
MediaViewerNext,
|
|
558
|
+
MediaViewerPrevious,
|
|
559
|
+
MediaViewerStage,
|
|
560
|
+
MediaViewerZoom,
|
|
561
|
+
type MediaViewerItem,
|
|
562
|
+
} from '@slotted/react/media-viewer';
|
|
563
|
+
import { Stack } from '@slotted/react/stack';
|
|
564
|
+
import { Text } from '@slotted/react/typography';
|
|
565
|
+
import { useState } from 'react';
|
|
566
|
+
|
|
567
|
+
const photo = (width: number, height: number, sky: string, crate: string) =>
|
|
568
|
+
'data:image/svg+xml,' +
|
|
569
|
+
encodeURIComponent(
|
|
570
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}">` +
|
|
571
|
+
`<rect width="100%" height="100%" fill="${sky}"/>` +
|
|
572
|
+
`<rect y="${String(height * 0.7)}" width="100%" height="${String(height * 0.3)}" fill="#4b5563"/>` +
|
|
573
|
+
`<rect x="${String(width * 0.3)}" y="${String(height * 0.4)}" width="${String(width * 0.4)}" height="${String(height * 0.3)}" fill="${crate}"/>` +
|
|
574
|
+
'</svg>',
|
|
575
|
+
);
|
|
576
|
+
|
|
577
|
+
const FRONT: MediaViewerItem = {
|
|
578
|
+
id: 'front',
|
|
579
|
+
name: 'pallet-front.jpg',
|
|
580
|
+
type: 'image/jpeg',
|
|
581
|
+
src: photo(2400, 1600, '#bfdbfe', '#c2410c'),
|
|
582
|
+
caption: 'Front face of pallet 7: two crushed corners.',
|
|
583
|
+
downloadHref: '#pallet-front.jpg',
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
const REAR: MediaViewerItem = {
|
|
587
|
+
id: 'rear',
|
|
588
|
+
name: 'pallet-rear.jpg',
|
|
589
|
+
type: 'image/jpeg',
|
|
590
|
+
src: photo(1200, 1600, '#e0e7ff', '#9a3412'),
|
|
591
|
+
caption: 'Rear face, taken on the dock.',
|
|
592
|
+
downloadHref: '#pallet-rear.jpg',
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
const LABEL: MediaViewerItem = {
|
|
596
|
+
id: 'label',
|
|
597
|
+
name: 'carrier-label.jpg',
|
|
598
|
+
type: 'image/jpeg',
|
|
599
|
+
src: photo(320, 200, '#fde68a', '#78350f'),
|
|
600
|
+
downloadHref: '#carrier-label.jpg',
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
const PHOTOS = [FRONT, REAR, LABEL];
|
|
604
|
+
|
|
605
|
+
export default function MediaViewerActionsExample() {
|
|
606
|
+
const [open, setOpen] = useState(false);
|
|
607
|
+
const [value, setValue] = useState('front');
|
|
608
|
+
const [flagged, setFlagged] = useState('No photograph flagged for the claim.');
|
|
609
|
+
|
|
610
|
+
function handleFlag() {
|
|
611
|
+
const file = PHOTOS.find((photo) => photo.id === value);
|
|
612
|
+
setFlagged(`${file?.name ?? value} flagged for the claim.`);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
return (
|
|
616
|
+
<Stack gap={2}>
|
|
617
|
+
<Inline gap={2}>
|
|
618
|
+
<Button onClick={() => setOpen(true)} size="sm" tone="secondary" variant="outline">
|
|
619
|
+
Review damage photographs
|
|
620
|
+
</Button>
|
|
621
|
+
</Inline>
|
|
622
|
+
<Text size="sm" tone="muted">
|
|
623
|
+
{flagged}
|
|
624
|
+
</Text>
|
|
625
|
+
<MediaViewer
|
|
626
|
+
items={PHOTOS}
|
|
627
|
+
open={open}
|
|
628
|
+
onOpenChange={setOpen}
|
|
629
|
+
value={value}
|
|
630
|
+
onValueChange={setValue}
|
|
631
|
+
>
|
|
632
|
+
<MediaViewerBar>
|
|
633
|
+
<MediaViewerHeading />
|
|
634
|
+
<MediaViewerActions>
|
|
635
|
+
<Button onClick={handleFlag} size="sm" tone="neutral" variant="ghost">
|
|
636
|
+
Flag for claim
|
|
637
|
+
</Button>
|
|
638
|
+
<MediaViewerDownload />
|
|
639
|
+
</MediaViewerActions>
|
|
640
|
+
<MediaViewerClose />
|
|
641
|
+
</MediaViewerBar>
|
|
642
|
+
<MediaViewerStage />
|
|
643
|
+
<MediaViewerPrevious />
|
|
644
|
+
<MediaViewerNext />
|
|
645
|
+
<MediaViewerZoom />
|
|
646
|
+
</MediaViewer>
|
|
647
|
+
</Stack>
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
### defaults.tsx
|
|
653
|
+
|
|
654
|
+
Example
|
|
655
|
+
|
|
656
|
+
```tsx
|
|
657
|
+
import { Button } from '@slotted/react/button';
|
|
658
|
+
import { Inline } from '@slotted/react/inline';
|
|
659
|
+
import {
|
|
660
|
+
MediaViewer,
|
|
661
|
+
MediaViewerDefaultsProvider,
|
|
662
|
+
type MediaViewerItem,
|
|
663
|
+
} from '@slotted/react/media-viewer';
|
|
664
|
+
import { useState } from 'react';
|
|
665
|
+
|
|
666
|
+
const photo = (width: number, height: number, sky: string, crate: string) =>
|
|
667
|
+
'data:image/svg+xml,' +
|
|
668
|
+
encodeURIComponent(
|
|
669
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}">` +
|
|
670
|
+
`<rect width="100%" height="100%" fill="${sky}"/>` +
|
|
671
|
+
`<rect y="${String(height * 0.7)}" width="100%" height="${String(height * 0.3)}" fill="#4b5563"/>` +
|
|
672
|
+
`<rect x="${String(width * 0.3)}" y="${String(height * 0.4)}" width="${String(width * 0.4)}" height="${String(height * 0.3)}" fill="${crate}"/>` +
|
|
673
|
+
'</svg>',
|
|
674
|
+
);
|
|
675
|
+
|
|
676
|
+
const FRONT: MediaViewerItem = {
|
|
677
|
+
id: 'front',
|
|
678
|
+
name: 'pallet-front.jpg',
|
|
679
|
+
type: 'image/jpeg',
|
|
680
|
+
src: photo(2400, 1600, '#bfdbfe', '#c2410c'),
|
|
681
|
+
caption: 'Front face of pallet 7: two crushed corners.',
|
|
682
|
+
downloadHref: '#pallet-front.jpg',
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
const REAR: MediaViewerItem = {
|
|
686
|
+
id: 'rear',
|
|
687
|
+
name: 'pallet-rear.jpg',
|
|
688
|
+
type: 'image/jpeg',
|
|
689
|
+
src: photo(1200, 1600, '#e0e7ff', '#9a3412'),
|
|
690
|
+
caption: 'Rear face, taken on the dock.',
|
|
691
|
+
downloadHref: '#pallet-rear.jpg',
|
|
692
|
+
};
|
|
693
|
+
|
|
694
|
+
const LABEL: MediaViewerItem = {
|
|
695
|
+
id: 'label',
|
|
696
|
+
name: 'carrier-label.jpg',
|
|
697
|
+
type: 'image/jpeg',
|
|
698
|
+
src: photo(320, 200, '#fde68a', '#78350f'),
|
|
699
|
+
downloadHref: '#carrier-label.jpg',
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
const PHOTOS = [FRONT, REAR, LABEL];
|
|
703
|
+
|
|
704
|
+
export default function MediaViewerDefaultsExample() {
|
|
705
|
+
const [open, setOpen] = useState(false);
|
|
706
|
+
const [value, setValue] = useState('front');
|
|
707
|
+
|
|
708
|
+
function handleOpen(id: string) {
|
|
709
|
+
setValue(id);
|
|
710
|
+
setOpen(true);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
return (
|
|
714
|
+
<MediaViewerDefaultsProvider loop maxZoom={6}>
|
|
715
|
+
<Inline gap={2}>
|
|
716
|
+
{PHOTOS.map((file) => (
|
|
717
|
+
<Button
|
|
718
|
+
key={file.id}
|
|
719
|
+
onClick={() => handleOpen(file.id)}
|
|
720
|
+
size="sm"
|
|
721
|
+
tone="secondary"
|
|
722
|
+
variant="outline"
|
|
723
|
+
>
|
|
724
|
+
{file.name}
|
|
725
|
+
</Button>
|
|
726
|
+
))}
|
|
727
|
+
</Inline>
|
|
728
|
+
<MediaViewer
|
|
729
|
+
items={PHOTOS}
|
|
730
|
+
open={open}
|
|
731
|
+
onOpenChange={setOpen}
|
|
732
|
+
value={value}
|
|
733
|
+
onValueChange={setValue}
|
|
734
|
+
/>
|
|
735
|
+
</MediaViewerDefaultsProvider>
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
### fullscreen.tsx
|
|
741
|
+
|
|
742
|
+
Example
|
|
743
|
+
|
|
744
|
+
```tsx
|
|
745
|
+
import { Button } from '@slotted/react/button';
|
|
746
|
+
import { Inline } from '@slotted/react/inline';
|
|
747
|
+
import { MediaViewer, type MediaViewerItem } from '@slotted/react/media-viewer';
|
|
748
|
+
import { useState } from 'react';
|
|
749
|
+
|
|
750
|
+
const photo = (width: number, height: number, sky: string, crate: string) =>
|
|
751
|
+
'data:image/svg+xml,' +
|
|
752
|
+
encodeURIComponent(
|
|
753
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}">` +
|
|
754
|
+
`<rect width="100%" height="100%" fill="${sky}"/>` +
|
|
755
|
+
`<rect y="${String(height * 0.7)}" width="100%" height="${String(height * 0.3)}" fill="#4b5563"/>` +
|
|
756
|
+
`<rect x="${String(width * 0.3)}" y="${String(height * 0.4)}" width="${String(width * 0.4)}" height="${String(height * 0.3)}" fill="${crate}"/>` +
|
|
757
|
+
'</svg>',
|
|
758
|
+
);
|
|
759
|
+
|
|
760
|
+
const FRONT: MediaViewerItem = {
|
|
761
|
+
id: 'front',
|
|
762
|
+
name: 'pallet-front.jpg',
|
|
763
|
+
type: 'image/jpeg',
|
|
764
|
+
src: photo(2400, 1600, '#bfdbfe', '#c2410c'),
|
|
765
|
+
caption: 'Front face of pallet 7: two crushed corners.',
|
|
766
|
+
downloadHref: '#pallet-front.jpg',
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
const REAR: MediaViewerItem = {
|
|
770
|
+
id: 'rear',
|
|
771
|
+
name: 'pallet-rear.jpg',
|
|
772
|
+
type: 'image/jpeg',
|
|
773
|
+
src: photo(1200, 1600, '#e0e7ff', '#9a3412'),
|
|
774
|
+
caption: 'Rear face, taken on the dock.',
|
|
775
|
+
downloadHref: '#pallet-rear.jpg',
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
const LABEL: MediaViewerItem = {
|
|
779
|
+
id: 'label',
|
|
780
|
+
name: 'carrier-label.jpg',
|
|
781
|
+
type: 'image/jpeg',
|
|
782
|
+
src: photo(320, 200, '#fde68a', '#78350f'),
|
|
783
|
+
downloadHref: '#carrier-label.jpg',
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
const PHOTOS = [FRONT, REAR, LABEL];
|
|
787
|
+
|
|
788
|
+
export default function MediaViewerFullscreenExample() {
|
|
789
|
+
const [open, setOpen] = useState(false);
|
|
790
|
+
const [value, setValue] = useState('front');
|
|
791
|
+
|
|
792
|
+
function handleOpen(id: string) {
|
|
793
|
+
setValue(id);
|
|
794
|
+
setOpen(true);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
return (
|
|
798
|
+
<>
|
|
799
|
+
<Inline gap={2}>
|
|
800
|
+
{PHOTOS.map((file) => (
|
|
801
|
+
<Button
|
|
802
|
+
key={file.id}
|
|
803
|
+
onClick={() => handleOpen(file.id)}
|
|
804
|
+
size="sm"
|
|
805
|
+
tone="secondary"
|
|
806
|
+
variant="outline"
|
|
807
|
+
>
|
|
808
|
+
{file.name}
|
|
809
|
+
</Button>
|
|
810
|
+
))}
|
|
811
|
+
</Inline>
|
|
812
|
+
<MediaViewer
|
|
813
|
+
items={PHOTOS}
|
|
814
|
+
open={open}
|
|
815
|
+
onOpenChange={setOpen}
|
|
816
|
+
value={value}
|
|
817
|
+
onValueChange={setValue}
|
|
818
|
+
fullscreenToggle
|
|
819
|
+
/>
|
|
820
|
+
</>
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
```
|
|
824
|
+
|
|
825
|
+
### messages.tsx
|
|
826
|
+
|
|
827
|
+
Example
|
|
828
|
+
|
|
829
|
+
```tsx
|
|
830
|
+
import { Button } from '@slotted/react/button';
|
|
831
|
+
import { Inline } from '@slotted/react/inline';
|
|
832
|
+
import { MediaViewer, type MediaViewerItem } from '@slotted/react/media-viewer';
|
|
833
|
+
import { useState } from 'react';
|
|
834
|
+
|
|
835
|
+
const photo = (width: number, height: number, sky: string, crate: string) =>
|
|
836
|
+
'data:image/svg+xml,' +
|
|
837
|
+
encodeURIComponent(
|
|
838
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}">` +
|
|
839
|
+
`<rect width="100%" height="100%" fill="${sky}"/>` +
|
|
840
|
+
`<rect y="${String(height * 0.7)}" width="100%" height="${String(height * 0.3)}" fill="#4b5563"/>` +
|
|
841
|
+
`<rect x="${String(width * 0.3)}" y="${String(height * 0.4)}" width="${String(width * 0.4)}" height="${String(height * 0.3)}" fill="${crate}"/>` +
|
|
842
|
+
'</svg>',
|
|
843
|
+
);
|
|
844
|
+
|
|
845
|
+
const FRONT: MediaViewerItem = {
|
|
846
|
+
id: 'front',
|
|
847
|
+
name: 'pallet-front.jpg',
|
|
848
|
+
type: 'image/jpeg',
|
|
849
|
+
src: photo(2400, 1600, '#bfdbfe', '#c2410c'),
|
|
850
|
+
caption: 'Front face of pallet 7: two crushed corners.',
|
|
851
|
+
downloadHref: '#pallet-front.jpg',
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
const BROKEN: MediaViewerItem = {
|
|
855
|
+
id: 'broken',
|
|
856
|
+
name: 'pallet-side.jpg',
|
|
857
|
+
type: 'image/jpeg',
|
|
858
|
+
src: 'data:image/jpeg;base64,AAAA',
|
|
859
|
+
downloadHref: '#pallet-side.jpg',
|
|
860
|
+
};
|
|
861
|
+
|
|
862
|
+
const REAR: MediaViewerItem = {
|
|
863
|
+
id: 'rear',
|
|
864
|
+
name: 'pallet-rear.jpg',
|
|
865
|
+
type: 'image/jpeg',
|
|
866
|
+
src: photo(1200, 1600, '#e0e7ff', '#9a3412'),
|
|
867
|
+
caption: 'Rear face, taken on the dock.',
|
|
868
|
+
downloadHref: '#pallet-rear.jpg',
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
const FILES = [FRONT, BROKEN, REAR];
|
|
872
|
+
|
|
873
|
+
const MESSAGES = {
|
|
874
|
+
close: 'Close photographs',
|
|
875
|
+
download: 'Save to the claim file',
|
|
876
|
+
position: 'Photograph {index} of {count}',
|
|
877
|
+
errorTitle: 'Photograph unavailable',
|
|
878
|
+
error: 'The carrier portal did not return this photograph.',
|
|
879
|
+
retry: 'Ask again',
|
|
880
|
+
};
|
|
881
|
+
|
|
882
|
+
export default function MediaViewerMessagesExample() {
|
|
883
|
+
const [open, setOpen] = useState(false);
|
|
884
|
+
const [value, setValue] = useState('front');
|
|
885
|
+
|
|
886
|
+
function handleOpen(id: string) {
|
|
887
|
+
setValue(id);
|
|
888
|
+
setOpen(true);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
return (
|
|
892
|
+
<>
|
|
893
|
+
<Inline gap={2}>
|
|
894
|
+
{FILES.map((file) => (
|
|
895
|
+
<Button
|
|
896
|
+
key={file.id}
|
|
897
|
+
onClick={() => handleOpen(file.id)}
|
|
898
|
+
size="sm"
|
|
899
|
+
tone="secondary"
|
|
900
|
+
variant="outline"
|
|
901
|
+
>
|
|
902
|
+
{file.name}
|
|
903
|
+
</Button>
|
|
904
|
+
))}
|
|
905
|
+
</Inline>
|
|
906
|
+
<MediaViewer
|
|
907
|
+
items={FILES}
|
|
908
|
+
open={open}
|
|
909
|
+
onOpenChange={setOpen}
|
|
910
|
+
value={value}
|
|
911
|
+
onValueChange={setValue}
|
|
912
|
+
messages={MESSAGES}
|
|
913
|
+
/>
|
|
914
|
+
</>
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
```
|
|
918
|
+
|
|
919
|
+
### requests.tsx
|
|
920
|
+
|
|
921
|
+
Example
|
|
922
|
+
|
|
923
|
+
```tsx
|
|
924
|
+
import { Button } from '@slotted/react/button';
|
|
925
|
+
import { Inline } from '@slotted/react/inline';
|
|
926
|
+
import {
|
|
927
|
+
MediaViewer,
|
|
928
|
+
type MediaViewerItem,
|
|
929
|
+
type MediaViewerOpenRequest,
|
|
930
|
+
type MediaViewerRotationRequest,
|
|
931
|
+
type MediaViewerValueRequest,
|
|
932
|
+
type MediaViewerZoomRequest,
|
|
933
|
+
} from '@slotted/react/media-viewer';
|
|
934
|
+
import { Stack } from '@slotted/react/stack';
|
|
935
|
+
import { Text } from '@slotted/react/typography';
|
|
936
|
+
import { useState } from 'react';
|
|
937
|
+
|
|
938
|
+
const photo = (width: number, height: number, sky: string, crate: string) =>
|
|
939
|
+
'data:image/svg+xml,' +
|
|
940
|
+
encodeURIComponent(
|
|
941
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}">` +
|
|
942
|
+
`<rect width="100%" height="100%" fill="${sky}"/>` +
|
|
943
|
+
`<rect y="${String(height * 0.7)}" width="100%" height="${String(height * 0.3)}" fill="#4b5563"/>` +
|
|
944
|
+
`<rect x="${String(width * 0.3)}" y="${String(height * 0.4)}" width="${String(width * 0.4)}" height="${String(height * 0.3)}" fill="${crate}"/>` +
|
|
945
|
+
'</svg>',
|
|
946
|
+
);
|
|
947
|
+
|
|
948
|
+
const FRONT: MediaViewerItem = {
|
|
949
|
+
id: 'front',
|
|
950
|
+
name: 'pallet-front.jpg',
|
|
951
|
+
type: 'image/jpeg',
|
|
952
|
+
src: photo(2400, 1600, '#bfdbfe', '#c2410c'),
|
|
953
|
+
caption: 'Front face of pallet 7: two crushed corners.',
|
|
954
|
+
downloadHref: '#pallet-front.jpg',
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
const REAR: MediaViewerItem = {
|
|
958
|
+
id: 'rear',
|
|
959
|
+
name: 'pallet-rear.jpg',
|
|
960
|
+
type: 'image/jpeg',
|
|
961
|
+
src: photo(1200, 1600, '#e0e7ff', '#9a3412'),
|
|
962
|
+
caption: 'Rear face, taken on the dock.',
|
|
963
|
+
downloadHref: '#pallet-rear.jpg',
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
const LABEL: MediaViewerItem = {
|
|
967
|
+
id: 'label',
|
|
968
|
+
name: 'carrier-label.jpg',
|
|
969
|
+
type: 'image/jpeg',
|
|
970
|
+
src: photo(320, 200, '#fde68a', '#78350f'),
|
|
971
|
+
downloadHref: '#carrier-label.jpg',
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
const PHOTOS = [FRONT, REAR, LABEL];
|
|
975
|
+
|
|
976
|
+
export default function MediaViewerRequestsExample() {
|
|
977
|
+
const [open, setOpen] = useState(false);
|
|
978
|
+
const [value, setValue] = useState('front');
|
|
979
|
+
const [log, setLog] = useState<string[]>([]);
|
|
980
|
+
|
|
981
|
+
const summary = log.length === 0 ? 'Open a photograph, zoom, turn and step.' : log.join(' · ');
|
|
982
|
+
|
|
983
|
+
function record(line: string) {
|
|
984
|
+
setLog((lines) => [line, ...lines].slice(0, 4));
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
function handleOpen(id: string) {
|
|
988
|
+
setValue(id);
|
|
989
|
+
setOpen(true);
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
function handleOpenChange(next: boolean, request: MediaViewerOpenRequest) {
|
|
993
|
+
setOpen(next);
|
|
994
|
+
record(`open ${String(next)} by ${request.reason}`);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
function handleValueChange(next: string, request: MediaViewerValueRequest) {
|
|
998
|
+
setValue(next);
|
|
999
|
+
record(`file ${next} by ${request.reason}`);
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
function handleZoomChange(next: number, request: MediaViewerZoomRequest) {
|
|
1003
|
+
record(`level ${String(Math.round(next * 100))}% by ${request.reason}`);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
function handleRotationChange(next: number, request: MediaViewerRotationRequest) {
|
|
1007
|
+
record(`turn to ${String(next)} degrees by ${request.reason}`);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
return (
|
|
1011
|
+
<Stack gap={4}>
|
|
1012
|
+
<Inline gap={2}>
|
|
1013
|
+
{PHOTOS.map((file) => (
|
|
1014
|
+
<Button
|
|
1015
|
+
key={file.id}
|
|
1016
|
+
onClick={() => handleOpen(file.id)}
|
|
1017
|
+
size="sm"
|
|
1018
|
+
tone="secondary"
|
|
1019
|
+
variant="outline"
|
|
1020
|
+
>
|
|
1021
|
+
{file.name}
|
|
1022
|
+
</Button>
|
|
1023
|
+
))}
|
|
1024
|
+
</Inline>
|
|
1025
|
+
<MediaViewer
|
|
1026
|
+
items={PHOTOS}
|
|
1027
|
+
open={open}
|
|
1028
|
+
onOpenChange={handleOpenChange}
|
|
1029
|
+
value={value}
|
|
1030
|
+
onValueChange={handleValueChange}
|
|
1031
|
+
onZoomChange={handleZoomChange}
|
|
1032
|
+
onRotationChange={handleRotationChange}
|
|
1033
|
+
/>
|
|
1034
|
+
<Text tone="muted">{summary}</Text>
|
|
1035
|
+
</Stack>
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
```
|