@robert-stackflow/oneui 0.6.43 → 0.6.44
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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/components/IconButton.d.ts +3 -1
- package/components/IconButton.js +2 -1
- package/components/Lightbox.js +41 -1
- package/components/Lightbox.module.css +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -328,7 +328,7 @@ Menu 支持 iconOnly:`<Menu iconOnly label="更多操作" items={items} />`
|
|
|
328
328
|
|
|
329
329
|
### Lightbox
|
|
330
330
|
|
|
331
|
-
`Lightbox` is a controlled image viewer: pass `open`, `items`, `index`, `onIndexChange` and `onClose`. Each item has a stable `id`, `src`, `alt` and optional `caption`, `thumbnailSrc`, `width` and `height`. The optional `sourceElement(item)` resolves the original image for Hero motion; `onLocate(item)` runs after exit and scroll unlocking. Supply `labels` for localization.
|
|
331
|
+
`Lightbox` is a controlled image viewer: pass `open`, `items`, `index`, `onIndexChange` and `onClose`. Each item has a stable `id`, `src`, `alt` and optional `caption`, `thumbnailSrc`, `width` and `height`. The optional `sourceElement(item)` resolves the original image for Hero motion; `onLocate(item)` runs after exit and scroll unlocking. Supply `labels` for localization. Provide valid `width` and `height` for an aspect-correct loading skeleton fitted to the canvas; images without known dimensions use a compact loading indicator.
|
|
332
332
|
|
|
333
333
|
The viewer uses an opaque black canvas with light controls independently of the document color mode. It supports captions, thumbnail navigation, non-wrapping previous/next, arrow keys, Escape, original-size zoom, bounded dragging, touch pinch/swipe and manual retry of the original URL. A single image hides navigation. Only adjacent full images are preloaded. It uses native modal isolation and shared OneUI focus, scroll lock and motion; reduced motion and missing/offscreen source elements use a quiet fallback. Keep the component mounted through exit and retain the selected index. Resolve resource permissions and document anchors in the host, not inside OneUI.
|
|
334
334
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentPropsWithRef, ReactNode } from "react";
|
|
2
|
-
export declare function IconButton({ label, loading, children, text, variant, size, disclosure, ...props }: ComponentPropsWithRef<"button"> & {
|
|
2
|
+
export declare function IconButton({ label, loading, children, text, variant, size, disclosure, tooltip, ...props }: ComponentPropsWithRef<"button"> & {
|
|
3
3
|
label: string;
|
|
4
4
|
loading?: boolean;
|
|
5
5
|
/** Visible text or count inside the same hover, focus and click target as the icon. */
|
|
@@ -8,4 +8,6 @@ export declare function IconButton({ label, loading, children, text, variant, si
|
|
|
8
8
|
size?: "small" | "normal";
|
|
9
9
|
/** Add a spaced disclosure chevron, driven by aria-expanded. */
|
|
10
10
|
disclosure?: boolean;
|
|
11
|
+
/** Keep the accessible label while omitting redundant hover text in compact surfaces. */
|
|
12
|
+
tooltip?: boolean;
|
|
11
13
|
}): import("react").JSX.Element;
|
package/components/IconButton.js
CHANGED
|
@@ -12,9 +12,10 @@ function IconButton({
|
|
|
12
12
|
variant = "ghost",
|
|
13
13
|
size = "normal",
|
|
14
14
|
disclosure = false,
|
|
15
|
+
tooltip = true,
|
|
15
16
|
...props
|
|
16
17
|
}) {
|
|
17
|
-
return /* @__PURE__ */ jsx(Tooltip, { content: label, children: /* @__PURE__ */ jsxs(
|
|
18
|
+
return /* @__PURE__ */ jsx(Tooltip, { content: label, disabled: !tooltip, children: /* @__PURE__ */ jsxs(
|
|
18
19
|
"button",
|
|
19
20
|
{
|
|
20
21
|
type: "button",
|
package/components/Lightbox.js
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
} from "lucide-react";
|
|
20
20
|
import { IconButton } from "./IconButton.js";
|
|
21
21
|
import { Skeleton } from "./Skeleton.js";
|
|
22
|
+
import { Spinner } from "./Spinner.js";
|
|
22
23
|
import { usePortalRoot } from "./usePortalRoot.js";
|
|
23
24
|
import { useModalScrollLock } from "./useModalScrollLock.js";
|
|
24
25
|
import { useModalFocus } from "./useModalFocus.js";
|
|
@@ -70,6 +71,34 @@ function Lightbox(props) {
|
|
|
70
71
|
const [closing, setClosing] = useState(false), [status, setStatus] = useState("loading");
|
|
71
72
|
const [zoom, setZoom] = useState(1), [pan, setPan] = useState({ x: 0, y: 0 });
|
|
72
73
|
const itemKey = item ? item.id + item.src : "";
|
|
74
|
+
const [loadingSize, setLoadingSize] = useState(null);
|
|
75
|
+
useLayoutEffect(() => {
|
|
76
|
+
const stage = stageRef.current;
|
|
77
|
+
const width = item?.width, height = item?.height;
|
|
78
|
+
if (!open || !stage || !width || !height || !Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) {
|
|
79
|
+
setLoadingSize(null);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const measure = () => {
|
|
83
|
+
const scale = Math.min(
|
|
84
|
+
1,
|
|
85
|
+
stage.clientWidth / width,
|
|
86
|
+
stage.clientHeight / height
|
|
87
|
+
);
|
|
88
|
+
const next = {
|
|
89
|
+
key: itemKey,
|
|
90
|
+
width: width * scale,
|
|
91
|
+
height: height * scale
|
|
92
|
+
};
|
|
93
|
+
setLoadingSize(
|
|
94
|
+
(previous) => previous?.key === next.key && previous.width === next.width && previous.height === next.height ? previous : next
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
measure();
|
|
98
|
+
const observer = new ResizeObserver(measure);
|
|
99
|
+
observer.observe(stage);
|
|
100
|
+
return () => observer.disconnect();
|
|
101
|
+
}, [open, portal, itemKey, item?.width, item?.height]);
|
|
73
102
|
const [slide, setSlide] = useState({ key: itemKey, index, current: item, direction: 0 });
|
|
74
103
|
if (slide.key !== itemKey)
|
|
75
104
|
setSlide({
|
|
@@ -370,6 +399,7 @@ function Lightbox(props) {
|
|
|
370
399
|
);
|
|
371
400
|
};
|
|
372
401
|
const pointerEnd = (event) => {
|
|
402
|
+
if (!pointers.current.has(event.pointerId)) return;
|
|
373
403
|
const start = gesture.current, dx = event.clientX - start.x, dy = event.clientY - start.y;
|
|
374
404
|
pointers.current.delete(event.pointerId);
|
|
375
405
|
if (event.type !== "pointercancel" && !start.multi && zoom === 1 && Math.abs(dx) > 64 && Math.abs(dx) > Math.abs(dy) * 1.2)
|
|
@@ -501,7 +531,17 @@ function Lightbox(props) {
|
|
|
501
531
|
);
|
|
502
532
|
}
|
|
503
533
|
),
|
|
504
|
-
status === "loading" && /* @__PURE__ */ jsx("div", { className: s.feedback, role: "status", "aria-label": t.loading, children: /* @__PURE__ */ jsx(
|
|
534
|
+
status === "loading" && /* @__PURE__ */ jsx("div", { className: s.feedback, role: "status", "aria-label": t.loading, children: loadingSize?.key === itemKey ? /* @__PURE__ */ jsx(
|
|
535
|
+
"div",
|
|
536
|
+
{
|
|
537
|
+
className: s.loadingImage,
|
|
538
|
+
style: {
|
|
539
|
+
width: loadingSize.width,
|
|
540
|
+
height: loadingSize.height
|
|
541
|
+
},
|
|
542
|
+
children: /* @__PURE__ */ jsx(Skeleton, { width: "100%", height: "100%" })
|
|
543
|
+
}
|
|
544
|
+
) : /* @__PURE__ */ jsx(Spinner, { size: 22, decorative: true }) }),
|
|
505
545
|
status === "error" && /* @__PURE__ */ jsxs("div", { className: s.feedback, role: "status", children: [
|
|
506
546
|
/* @__PURE__ */ jsx("span", { children: t.error }),
|
|
507
547
|
/* @__PURE__ */ jsx(
|