@hogoshi/ui 0.1.5 → 0.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hogoshi/ui",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@base-ui/react": "^1.8.0",
41
- "@hogoshi/tokens": "^0.1.1",
41
+ "@hogoshi/tokens": "^0.1.2",
42
42
  "@hugeicons-pro/core-duotone-rounded": "^4.2.2",
43
43
  "@hugeicons-pro/core-solid-rounded": "^4.2.2",
44
44
  "@hugeicons-pro/core-stroke-rounded": "^4.2.2",
@@ -0,0 +1,16 @@
1
+ import type { IconSvgElement } from "@hugeicons/react";
2
+
3
+ const stroke = {
4
+ fill: "none",
5
+ stroke: "currentColor",
6
+ strokeWidth: 2.4,
7
+ strokeLinecap: "round",
8
+ strokeLinejoin: "round",
9
+ } as const;
10
+
11
+ export const CollapseScreenIcon: IconSvgElement = [
12
+ ["path", { d: "M9 5 V9 H5", ...stroke, key: "0" }],
13
+ ["path", { d: "M15 5 V9 H19", ...stroke, key: "1" }],
14
+ ["path", { d: "M9 19 V15 H5", ...stroke, key: "2" }],
15
+ ["path", { d: "M15 19 V15 H19", ...stroke, key: "3" }],
16
+ ];
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import { Dialog as BaseDialog } from "@base-ui/react/dialog";
4
+ import { FullScreenIcon } from "@hugeicons-pro/core-solid-rounded";
4
5
  import {
5
6
  ArrowLeft01Icon,
6
7
  ArrowRight01Icon,
@@ -23,7 +24,9 @@ import {
23
24
  import { cn } from "../lib/cn";
24
25
  import { ContextMenuContent, ContextMenuItem, ContextMenuRoot, ContextMenuTrigger } from "./context-menu";
25
26
  import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "./dropdown-menu";
27
+ import { CollapseScreenIcon } from "./collapse-screen-icon";
26
28
  import { Icon } from "./icon";
29
+ import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip";
27
30
  import { backdropMotion, popupMotion } from "./popup";
28
31
 
29
32
  export interface ViewerImage {
@@ -317,11 +320,28 @@ export function ImageGallery({
317
320
  className?: string;
318
321
  imageClassName?: string;
319
322
  }) {
323
+ const root = useRef<HTMLDivElement>(null);
320
324
  const [open, setOpen] = useState(false);
321
325
  const [index, setIndex] = useState(0);
326
+ const [full, setFull] = useState(false);
327
+ useEffect(() => {
328
+ const sync = () => setFull(document.fullscreenElement === root.current);
329
+ document.addEventListener("fullscreenchange", sync);
330
+ return () => document.removeEventListener("fullscreenchange", sync);
331
+ }, []);
332
+ const toggleFull = () => {
333
+ const node = root.current as (HTMLDivElement & { webkitRequestFullscreen?: () => void }) | null;
334
+ if (document.fullscreenElement) void document.exitFullscreen();
335
+ else if (node?.requestFullscreen) void node.requestFullscreen();
336
+ else node?.webkitRequestFullscreen?.();
337
+ };
322
338
  return (
323
339
  <>
324
- <div className={cn("grid grid-cols-[repeat(auto-fill,minmax(8rem,1fr))] gap-2", className)}>
340
+ <div
341
+ ref={root}
342
+ className={cn("relative min-w-0 pb-10", full && "bg-bg flex h-full w-full items-center justify-center p-6 pb-16")}
343
+ >
344
+ <div className={cn("grid min-w-0 grid-cols-[repeat(auto-fill,minmax(min(100%,8rem),1fr))] gap-2", full && "w-full max-w-5xl", className)}>
325
345
  {images.map((image, at) => (
326
346
  <button
327
347
  key={`${image.src}-${at}`}
@@ -346,6 +366,23 @@ export function ImageGallery({
346
366
  </button>
347
367
  ))}
348
368
  </div>
369
+ <Tooltip>
370
+ <TooltipTrigger
371
+ delay={0}
372
+ render={
373
+ <button
374
+ type="button"
375
+ aria-label={full ? "Exit fullscreen" : "Fullscreen"}
376
+ className="text-fg-muted hover:bg-bg-muted hover:text-fg absolute right-2 bottom-2 inline-flex size-7 items-center justify-center rounded-[var(--radius-sm)]"
377
+ onClick={toggleFull}
378
+ />
379
+ }
380
+ >
381
+ <Icon icon={full ? CollapseScreenIcon : FullScreenIcon} size={16} />
382
+ </TooltipTrigger>
383
+ <TooltipContent>{full ? "Exit fullscreen" : "Fullscreen"}</TooltipContent>
384
+ </Tooltip>
385
+ </div>
349
386
  <ImageViewer images={images} index={index} open={open} onOpenChange={setOpen} onIndexChange={setIndex} />
350
387
  </>
351
388
  );
@@ -21,7 +21,7 @@ export function TopBar({ contained = false, children, className }: { contained?:
21
21
  const root = document.querySelector("[data-scroll-root]");
22
22
  const read = () => {
23
23
  const top = root instanceof HTMLElement ? root.scrollTop : window.scrollY;
24
- setCompact(top > 24);
24
+ setCompact((current) => (current ? top > 8 : top > 24));
25
25
  };
26
26
  read();
27
27
  const target: EventTarget = root instanceof HTMLElement ? root : window;
@@ -30,13 +30,13 @@ export function TopBar({ contained = false, children, className }: { contained?:
30
30
  }, []);
31
31
 
32
32
  return (
33
- <header className={cn("pointer-events-none inset-x-0 top-0 z-[var(--z-sticky)] flex justify-center", contained ? "absolute" : "fixed", className)}>
33
+ <header className={cn("pointer-events-none inset-x-0 top-0 z-[var(--z-sticky)]", contained ? "absolute" : "fixed", className)}>
34
34
  <div
35
35
  className={cn(
36
- "pointer-events-auto flex items-center transition-[width,height,margin,border-radius,background-color,border-color,box-shadow] duration-500 ease-[var(--motion-ease)] motion-reduce:transition-none",
36
+ "pointer-events-auto relative mx-auto flex h-12 items-center border transition-[width,translate,border-radius,background-color,border-color,box-shadow] duration-[calc(var(--motion-duration)*4)] ease-[var(--motion-ease)]",
37
37
  compact
38
- ? "border-border bg-bg-elevated mt-[calc(var(--safe-top)+0.75rem)] h-12 w-[min(40rem,calc(100%-1.5rem))] rounded-full border px-2 shadow-[var(--shadow-md)]"
39
- : "mt-[calc(var(--safe-top)+0.5rem)] h-14 w-full border border-transparent bg-transparent px-3",
38
+ ? "border-border bg-bg-elevated w-[min(40rem,calc(100%-max(0.75rem,var(--safe-left))-max(0.75rem,var(--safe-right))))] translate-y-[calc(var(--safe-top)+0.75rem)] rounded-full px-2 shadow-[var(--shadow-md)]"
39
+ : "before:pointer-events-auto w-full translate-y-[var(--safe-top)] border-transparent bg-transparent pl-[max(0.75rem,var(--safe-left))] pr-[max(0.75rem,var(--safe-right))] before:absolute before:inset-x-0 before:bottom-full before:h-[var(--safe-top)] before:content-['']",
40
40
  )}
41
41
  >
42
42
  <Navbar className="relative h-full w-full bg-transparent px-1 shadow-none backdrop-blur-none">{children}</Navbar>
@@ -154,7 +154,7 @@ export function BottomBar({ className, children, ...props }: ComponentProps<"nav
154
154
  return (
155
155
  <nav
156
156
  className={cn(
157
- "bg-bg-elevated/70 border-border fixed right-[max(0.75rem,var(--safe-right))] bottom-2 left-[max(0.75rem,var(--safe-left))] z-[var(--z-sticky)] rounded-[var(--radius-lg)] border p-1 shadow-[var(--shadow-md)] backdrop-blur-xl md:hidden",
157
+ "bg-bg-elevated/70 border-border fixed right-[max(0.75rem,var(--safe-right))] bottom-[max(0.5rem,var(--safe-bottom))] left-[max(0.75rem,var(--safe-left))] z-[var(--z-sticky)] rounded-[var(--radius-lg)] border p-1 shadow-[var(--shadow-md)] backdrop-blur-xl md:hidden",
158
158
  className,
159
159
  )}
160
160
  {...props}
@@ -33,8 +33,7 @@ function markScrolling(element: Element) {
33
33
 
34
34
  function motionAllowed() {
35
35
  const motion = document.documentElement.getAttribute("data-motion");
36
- if (motion === "off" || motion === "reduced") return false;
37
- return !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
36
+ return motion !== "off" && motion !== "reduced";
38
37
  }
39
38
 
40
39
  function stop(element: Element) {
@@ -38,6 +38,41 @@ function freeze(media: HTMLVideoElement | HTMLCanvasElement, copy: Element) {
38
38
  copy.replaceWith(canvas);
39
39
  }
40
40
 
41
+ function lockScroll() {
42
+ const root = document.querySelector("[data-scroll-root]");
43
+ if (root instanceof HTMLElement) {
44
+ const top = root.scrollTop;
45
+ const left = root.scrollLeft;
46
+ return () => {
47
+ root.scrollTop = top;
48
+ root.scrollLeft = left;
49
+ };
50
+ }
51
+ const top = window.scrollY;
52
+ const left = window.scrollX;
53
+ const body = document.body;
54
+ const prev = {
55
+ position: body.style.position,
56
+ top: body.style.top,
57
+ left: body.style.left,
58
+ right: body.style.right,
59
+ width: body.style.width,
60
+ };
61
+ body.style.position = "fixed";
62
+ body.style.top = `-${top}px`;
63
+ body.style.left = "0";
64
+ body.style.right = "0";
65
+ body.style.width = "100%";
66
+ return () => {
67
+ body.style.position = prev.position;
68
+ body.style.top = prev.top;
69
+ body.style.left = prev.left;
70
+ body.style.right = prev.right;
71
+ body.style.width = prev.width;
72
+ window.scrollTo(left, top);
73
+ };
74
+ }
75
+
41
76
  function holdPage() {
42
77
  const root = document.documentElement;
43
78
  root.setAttribute("data-theme-switching", "");
@@ -160,9 +195,7 @@ export function ThemeToggle({
160
195
  if (switching) return;
161
196
  const root = document.documentElement;
162
197
  const next = root.getAttribute("data-mode") === "dark" ? "light" : "dark";
163
- const reduce =
164
- window.matchMedia("(prefers-reduced-motion: reduce)").matches || root.getAttribute("data-motion") === "off";
165
- if (reduce) {
198
+ if (root.getAttribute("data-motion") === "off") {
166
199
  swap(next);
167
200
  return;
168
201
  }
@@ -172,8 +205,10 @@ export function ThemeToggle({
172
205
  const current = next === "dark" ? "light" : "dark";
173
206
  const inward = next === "dark";
174
207
  const layer = snapshot(inward ? current : next);
208
+ const unlock = lockScroll();
175
209
  const finish = () => {
176
210
  layer.remove();
211
+ unlock();
177
212
  requestAnimationFrame(() => {
178
213
  requestAnimationFrame(() => {
179
214
  release();
@@ -3,7 +3,6 @@
3
3
  import {
4
4
  Alert02Icon,
5
5
  FullScreenIcon,
6
- MinimizeScreenIcon,
7
6
  PauseIcon,
8
7
  PictureInPictureOnIcon,
9
8
  PlayIcon,
@@ -23,6 +22,7 @@ import {
23
22
  type RefObject,
24
23
  } from "react";
25
24
  import { cn } from "../lib/cn";
25
+ import { CollapseScreenIcon } from "./collapse-screen-icon";
26
26
  import { Icon, type AppIcon } from "./icon";
27
27
  import { Popover, PopoverContent, PopoverTrigger } from "./popover";
28
28
  import { Slider } from "./slider";
@@ -549,7 +549,7 @@ export function VideoPlayer({
549
549
  <Control label="Picture in picture" icon={PictureInPictureOnIcon} onClick={togglePip} />
550
550
  <Control
551
551
  label={fullscreen ? "Exit fullscreen" : "Fullscreen"}
552
- icon={fullscreen ? MinimizeScreenIcon : FullScreenIcon}
552
+ icon={fullscreen ? CollapseScreenIcon : FullScreenIcon}
553
553
  onClick={toggleFullscreen}
554
554
  />
555
555
  </div>
package/src/styles.css CHANGED
@@ -61,6 +61,8 @@ body {
61
61
  color: var(--fg);
62
62
  font-family: var(--font-sans);
63
63
  font-size: var(--text-base);
64
+ min-height: 100%;
65
+ min-height: 100dvh;
64
66
  -webkit-font-smoothing: antialiased;
65
67
  text-rendering: optimizeLegibility;
66
68
  }
@@ -328,11 +330,6 @@ nav,
328
330
  to { opacity: 1; transform: scale(1); }
329
331
  }
330
332
 
331
- html[data-theme-switching],
332
- html[data-theme-switching] body {
333
- overflow: hidden !important;
334
- }
335
-
336
333
  html[data-theme-switching] body {
337
334
  pointer-events: none !important;
338
335
  }
@@ -432,12 +429,3 @@ button.hogoshi-grab:disabled {
432
429
  z-index: 0;
433
430
  }
434
431
 
435
- @media (prefers-reduced-motion: reduce) {
436
- *,
437
- *::before,
438
- *::after {
439
- animation-duration: 1ms !important;
440
- animation-iteration-count: 1 !important;
441
- transition-duration: 1ms !important;
442
- }
443
- }