shelving 1.297.0 → 1.297.2

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": "shelving",
3
- "version": "1.297.0",
3
+ "version": "1.297.2",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",
package/ui/block/Card.md CHANGED
@@ -71,7 +71,7 @@ import { Card, Subheading } from "shelving/ui";
71
71
  | `--card-space` | Outer block margin (top + bottom) | `var(--space-paragraph)` (16px) |
72
72
  | `--card-shadow` | Drop shadow | `none` |
73
73
  | `--card-transition` | Transition | `all var(--duration-fast)` (150ms) |
74
- | `--card-focus-border` | Focus outline | `var(--stroke-focus) solid var(--color-focus)` |
74
+ | `--card-focus-border` | Focus outline, drawn on the navigable overlay so it shows above children like `<Panel>` | `var(--stroke-focus) solid var(--color-focus)` |
75
75
 
76
76
  **Global tokens it reads** — move these to retheme broadly rather than overriding ladder steps directly: the tint ladder `--tint-00` / `--tint-80` / `--tint-90` / `--tint-95`, plus `--space-normal`, `--space-paragraph`, `--radius-normal`, `--stroke-focus`, `--color-focus`, and `--duration-fast`.
77
77
 
@@ -33,8 +33,6 @@
33
33
  color: var(--card-color, var(--tint-00));
34
34
  box-shadow: var(--card-shadow, none);
35
35
  transition: var(--card-transition, all var(--duration-fast));
36
- outline: var(--card-focus-border, var(--stroke-focus) solid var(--color-focus));
37
- outline-offset: calc(0px - var(--stroke-focus)); /* Fully inset, so it sits inside the card edge. */
38
36
 
39
37
  /* Hover/focus affordance driven by the overlay link/button. */
40
38
  &:has(.overlay:hover) {
@@ -50,11 +48,15 @@
50
48
  inset: 0;
51
49
  z-index: 1;
52
50
  border: 0;
51
+ border-radius: inherit;
53
52
 
54
53
  /* Style */
55
54
  background: transparent;
56
55
  cursor: pointer;
57
- outline: 0;
56
+
57
+ /* Focus ring — drawn on the overlay so it paints above positioned children (e.g. `.panel`). The offset pushes it out over the card border, so it sits fully inside the card edge. */
58
+ outline: var(--card-focus-border, var(--stroke-focus) solid var(--color-focus));
59
+ outline-offset: calc(var(--card-stroke, 0px) - var(--stroke-focus));
58
60
 
59
61
  /* Typography — hide the link's text visually but keep it in the accessibility tree. */
60
62
  color: transparent;
@@ -67,9 +69,9 @@
67
69
  }
68
70
 
69
71
  @layer overrides {
70
- .card {
71
- /* Show the focus ring only while the navigable overlay is keyboard-focused; hide it otherwise (including non-clickable cards, which have no overlay). */
72
- &:not(:has(.overlay:focus-visible)) {
72
+ .card > .overlay {
73
+ /* Show the focus ring only while the overlay is keyboard-focused. */
74
+ &:not(:focus-visible) {
73
75
  outline-color: transparent;
74
76
  }
75
77
  }
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { XMarkIcon } from "@heroicons/react/24/solid";
3
- import { memo, Suspense, startTransition, useLayoutEffect, useRef, ViewTransition } from "react";
3
+ import { memo, Suspense, startTransition, ViewTransition } from "react";
4
4
  import { getButtonClass } from "../button/Button.js";
5
5
  import { getClass, getModuleClass } from "../util/css.js";
6
6
  import "../transition/FadeTransition.css";
@@ -18,12 +18,7 @@ import styles from "./Dialog.module.css";
18
18
  * @see https://shelving.cc/ui/Dialog
19
19
  */
20
20
  export const Dialog = memo(({ children, onClose, ...props }) => {
21
- const ref = useRef(null);
22
- // Open in a layout effect, not a passive effect. React runs layout effects inside the view transition's update, so the new snapshot shows the open dialog.
23
- useLayoutEffect(() => {
24
- ref.current?.showModal();
25
- }, []);
26
- return (_jsx(Suspense, { fallback: null, children: _jsx(ViewTransition, { enter: "fade", exit: "fade", children: _jsxs("dialog", { ref: ref, className: getModuleClass(styles, "dialog"), onClick: _closeOnBackdropClick, onCancel: e => {
21
+ return (_jsx(Suspense, { fallback: null, children: _jsx(ViewTransition, { enter: "fade", exit: "fade", children: _jsxs("dialog", { ref: _showModal, className: getModuleClass(styles, "dialog"), onClick: _closeOnBackdropClick, onCancel: e => {
27
22
  // Keep the dialog open and let the parent unmount it in a transition. An uncancelable request closes natively and fires `onClose` from the `close` event.
28
23
  if (!onClose || !e.cancelable)
29
24
  return;
@@ -31,6 +26,15 @@ export const Dialog = memo(({ children, onClose, ...props }) => {
31
26
  startTransition(() => onClose());
32
27
  }, onClose: onClose, ...props, children: [_jsx("div", { className: getModuleClass(styles, "content"), children: children }), _jsx("div", { className: getModuleClass(styles, "close"), children: _jsx(DialogCloseButton, {}) })] }) }) }));
33
28
  });
29
+ /**
30
+ * Open a `<dialog>` as a modal when React attaches it.
31
+ * - A ref callback, not a layout effect. React holds the layout effects of a view transition until its images are ready, and an image in a closed `<dialog>` is never ready, so a layout effect would never open a dialog with an image in it.
32
+ * - The ref callback still runs inside the view transition's update, so the new snapshot shows the open dialog.
33
+ */
34
+ function _showModal(dialog) {
35
+ if (dialog && !dialog.open)
36
+ dialog.showModal();
37
+ }
34
38
  /** When the user clicks anywhere on a `<dialog>` element (and the click isn't on a link etc), then close the dialog. */
35
39
  function _closeOnBackdropClick({ currentTarget, target }) {
36
40
  // Close the dialog when clicking on the dialog itself (but not its children).
@@ -1,5 +1,5 @@
1
1
  import { XMarkIcon } from "@heroicons/react/24/solid";
2
- import { type MouseEvent, memo, type ReactElement, Suspense, startTransition, useLayoutEffect, useRef, ViewTransition } from "react";
2
+ import { type MouseEvent, memo, type ReactElement, Suspense, startTransition, ViewTransition } from "react";
3
3
  import type { Callback } from "../../util/function.js";
4
4
  import { type ButtonVariants, getButtonClass } from "../button/Button.js";
5
5
  import { getClass, getModuleClass } from "../util/css.js";
@@ -30,20 +30,13 @@ export interface DialogProps extends OptionalChildProps {
30
30
  * @see https://shelving.cc/ui/Dialog
31
31
  */
32
32
  export const Dialog = memo(({ children, onClose, ...props }: DialogProps) => {
33
- const ref = useRef<HTMLDialogElement>(null);
34
-
35
- // Open in a layout effect, not a passive effect. React runs layout effects inside the view transition's update, so the new snapshot shows the open dialog.
36
- useLayoutEffect(() => {
37
- ref.current?.showModal();
38
- }, []);
39
-
40
33
  return (
41
34
  <Suspense fallback={null}>
42
35
  {/* The transition must wrap the `<dialog>`: React only animates a `<ViewTransition>` that comes before any DOM element in the inserted or deleted tree. Fade only on enter and exit, so an open dialog stays still while another dialog opens or closes. */}
43
36
  <ViewTransition enter="fade" exit="fade">
44
37
  {/** biome-ignore lint/a11y/useKeyWithClickEvents: Dialogs also show a close button. */}
45
38
  <dialog
46
- ref={ref}
39
+ ref={_showModal}
47
40
  className={getModuleClass(styles, "dialog")}
48
41
  onClick={_closeOnBackdropClick}
49
42
  onCancel={e => {
@@ -65,6 +58,15 @@ export const Dialog = memo(({ children, onClose, ...props }: DialogProps) => {
65
58
  );
66
59
  });
67
60
 
61
+ /**
62
+ * Open a `<dialog>` as a modal when React attaches it.
63
+ * - A ref callback, not a layout effect. React holds the layout effects of a view transition until its images are ready, and an image in a closed `<dialog>` is never ready, so a layout effect would never open a dialog with an image in it.
64
+ * - The ref callback still runs inside the view transition's update, so the new snapshot shows the open dialog.
65
+ */
66
+ function _showModal(dialog: HTMLDialogElement | null): void {
67
+ if (dialog && !dialog.open) dialog.showModal();
68
+ }
69
+
68
70
  /** When the user clicks anywhere on a `<dialog>` element (and the click isn't on a link etc), then close the dialog. */
69
71
  function _closeOnBackdropClick({ currentTarget, target }: MouseEvent<HTMLDialogElement>): void {
70
72
  // Close the dialog when clicking on the dialog itself (but not its children).