shelving 1.295.3 → 1.296.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shelving",
3
- "version": "1.295.3",
3
+ "version": "1.296.0",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,6 +36,7 @@ import { LOADING_NOTICE } from "shelving/ui";
36
36
  | `--notice-color` | Text colour | `var(--tint-50)` |
37
37
  | `--notice-border` | Border shorthand | `var(--notice-stroke) solid var(--tint-80)` |
38
38
  | `--notice-stroke` | Border thickness | `var(--stroke-normal)` (2px) |
39
+ | `--notice-shadow` | Drop shadow, for example `var(--shadow-small)` | `none` |
39
40
  | `--notice-radius` | Corner radius | `var(--radius-xsmall)` |
40
41
  | `--notice-padding` | Inner top and bottom padding (one length) | `var(--space-small)` (12px) |
41
42
  | `--notice-indent` | Inner left and right padding (one length) | `var(--space-small)` (12px) |
@@ -15,6 +15,7 @@
15
15
 
16
16
  /* Style */
17
17
  background: var(--notice-background, var(--tint-90));
18
+ box-shadow: var(--notice-shadow, none);
18
19
  color: var(--notice-color, var(--tint-50));
19
20
 
20
21
  /* Text */
@@ -3,19 +3,31 @@ import { type FlexVariants } from "../style/Flex.js";
3
3
  import type { ClassProps } from "../util/props.js";
4
4
  import "./NoticesTransition.css";
5
5
  /**
6
- * Props for `<Notices>` — flex styling variants for the notices container.
6
+ * Corner of the screen where `<Notices>` shows the list of notices.
7
+ *
8
+ * @see https://shelving.cc/ui/NoticesPosition
9
+ */
10
+ export type NoticesPosition = "top-left" | "top-right" | "bottom-left" | "bottom-right";
11
+ /**
12
+ * Props for `<Notices>` — the corner for the list, and flex styling variants for the notices container.
7
13
  *
8
14
  * @see https://shelving.cc/ui/NoticesProps
9
15
  */
10
16
  export interface NoticesProps extends FlexVariants, ClassProps {
17
+ /**
18
+ * Corner of the screen for the list. New notices slide in from this side.
19
+ * @default "bottom-right"
20
+ */
21
+ position?: NoticesPosition | undefined;
11
22
  }
12
23
  /**
13
24
  * Render the global list of notices and subscribe to incoming `"notice"` events.
14
25
  * - Listens for `"notice"` events on `window` (or that bubble up to `window`) and shows them in the global notice list.
15
26
  * - This is how e.g. `<Button>` and `<FormNotify>` components send notices into the global list.
16
- * - Each notice slides in and out in its own view transition. The other notices move to their new places in the same transition.
27
+ * - Shows the list in the bottom-right corner, or in the corner that `position` sets.
28
+ * - Each notice slides in and out in its own view transition, from the side of its corner. The other notices move to their new places in the same transition.
17
29
  *
18
30
  * @kind component
19
31
  * @see https://shelving.cc/ui/Notices
20
32
  */
21
- export declare function Notices({ className, ...props }: NoticesProps): ReactElement;
33
+ export declare function Notices({ position, className, ...props }: NoticesProps): ReactElement;
@@ -13,24 +13,28 @@ const NOTICES_CLASS = getModuleClass(NOTICES_CSS, "notices");
13
13
  * Render the global list of notices and subscribe to incoming `"notice"` events.
14
14
  * - Listens for `"notice"` events on `window` (or that bubble up to `window`) and shows them in the global notice list.
15
15
  * - This is how e.g. `<Button>` and `<FormNotify>` components send notices into the global list.
16
- * - Each notice slides in and out in its own view transition. The other notices move to their new places in the same transition.
16
+ * - Shows the list in the bottom-right corner, or in the corner that `position` sets.
17
+ * - Each notice slides in and out in its own view transition, from the side of its corner. The other notices move to their new places in the same transition.
17
18
  *
18
19
  * @kind component
19
20
  * @see https://shelving.cc/ui/Notices
20
21
  */
21
- export function Notices({ className, ...props }) {
22
+ export function Notices({ position = "bottom-right", className, ...props }) {
22
23
  const notices = useTransitionValue(NOTICES);
23
24
  useEffect(() => {
24
25
  // Subscribe to global notices.
25
26
  return subscribeNotices((message, status) => NOTICES.show(message, status));
26
27
  });
27
- return (_jsx("aside", { className: getClass(NOTICES_CLASS, getFlexClass(props), className), children: notices.map(notice => (_jsx(NoticeItem, { notice: notice }, notice.key))) }));
28
+ const [vertical, horizontal] = position.split("-");
29
+ return (_jsx("aside", { className: getClass(NOTICES_CLASS, getModuleClass(NOTICES_CSS, vertical, horizontal), getFlexClass(props), className), children: notices.map(notice => (_jsx(NoticeItem, { notice: notice, position: position }, notice.key))) }));
28
30
  }
29
31
  /**
30
32
  * Render one notice in its own view transition, and re-render when the notice changes in place.
31
33
  * - Module-private, but named without the `_` prefix: React and the hooks lint rule only treat a capitalised name as a component.
32
34
  */
33
- function NoticeItem({ notice }) {
35
+ function NoticeItem({ notice, position }) {
34
36
  const { children, status } = useTransitionValue(notice);
35
- return (_jsx(ViewTransition, { enter: "notice", exit: "notice", update: "notice-update", children: _jsx(Notice, { status: status, children: children }) }));
37
+ // New and closed notices slide from the side of the corner. A notice that changes in place is drawn from the corner itself.
38
+ const side = position.endsWith("left") ? "left" : "right";
39
+ return (_jsx(ViewTransition, { enter: `notice-${side}`, exit: `notice-${side}`, update: `notice-update-${position}`, children: _jsx(Notice, { status: status, children: children }) }));
36
40
  }
@@ -7,7 +7,8 @@ Renders the global list of active notices and subscribes to incoming `"notice"`
7
7
  - Mount `<Notices>` once near the root of your app. It renders at that point in the DOM and listens automatically — no context required.
8
8
  - Notices auto-dismiss after a short delay unless they carry a `"loading"` status.
9
9
  - Backed by the `NOTICES` store singleton; for advanced use you can keep a reference to a notice to update or close it manually.
10
- - Notices animate with [view transitions](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API). A new notice slides in from the right, and a closed notice slides out to the right. The other notices move to their new places. A notice that changes in place (for example from loading to success) changes at once, with no animation.
10
+ - The list shows in the bottom-right corner. Set `position` to `"top-left"`, `"top-right"`, `"bottom-left"`, or `"bottom-right"` to choose a different corner.
11
+ - Notices animate with [view transitions](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API). A new notice slides in from the side of its corner, and a closed notice slides out to that side. The other notices move to their new places. A notice that changes in place (for example from loading to success) changes at once, with no animation.
11
12
  - With reduced motion, notices fade in and out in place, and the others move at once. A browser without view transitions shows the changes at once.
12
13
 
13
14
  ## Usage
@@ -27,6 +28,12 @@ export function AppLayout({ children }) {
27
28
  }
28
29
  ```
29
30
 
31
+ Show the list in the top-left corner:
32
+
33
+ ```tsx
34
+ <Notices position="top-left" />
35
+ ```
36
+
30
37
  Dispatch notices from anywhere — no context required:
31
38
 
32
39
  ```tsx
@@ -56,13 +63,14 @@ notice.close(); // Or close it immediately.
56
63
 
57
64
  ## Styling
58
65
 
59
- `Notices` positions the list in the bottom-right corner. Each notice is only as wide as its content and is right-aligned. The list is never wider than `--notices-width`, and keeps `--notices-offset` clear at both sides on a narrow screen. Clicks pass through the gaps between notices to the page. Each item is a `<Notice>`, which has its own hooks. Override these hooks at `:root` (or any ancestor scope) to retheme.
66
+ `Notices` positions the list in the corner that `position` sets. Each notice is only as wide as its content and is aligned to the side of that corner. The list is never wider than `--notices-width`, and keeps `--notices-offset` clear at both sides on a narrow screen. The offset also adds the safe area of the device (`env(safe-area-inset-*)`). Clicks pass through the gaps between notices to the page. Each item is a `<Notice>`, which has its own hooks. Override these hooks at `:root` (or any ancestor scope) to retheme.
60
67
 
61
68
  | Variable | Styles | Default |
62
69
  |---|---|---|
63
- | `--notices-offset` | Distance of the list from the bottom, right, and left edges | `var(--space-normal)` (16px) |
70
+ | `--notices-offset` | Distance of the list from the top or bottom edge, and from the left and right edges | `var(--space-normal)` (16px) |
64
71
  | `--notices-width` | Maximum width of the list and of each notice | `var(--width-narrow)` |
72
+ | `--notices-shadow` | Drop shadow under each notice in the list (sets `--notice-shadow`) | `var(--shadow-small)` |
65
73
  | `--notices-gap` | Gap between notices | `var(--space-small)` (12px) |
66
74
  | `--notices-transition-duration` | Length of the slide in, slide out, and move | `var(--duration-fast)` (150ms) |
67
75
 
68
- **Global tokens it reads** — move these to retheme broadly: `--space-normal`, `--space-small`, `--width-narrow`, and `--duration-fast`.
76
+ **Global tokens it reads** — move these to retheme broadly: `--space-normal`, `--space-small`, `--shadow-small`, `--width-narrow`, and `--duration-fast`.
@@ -1,29 +1,49 @@
1
1
  @import url("../style/layers.css");
2
+ @import url("../style/Shadow.module.css");
2
3
  @import url("../style/Space.module.css");
3
4
  @import url("../style/Width.module.css");
4
5
 
5
6
  @layer components {
6
7
  .notices {
7
8
  position: fixed;
8
- right: var(--notices-offset, var(--space-normal));
9
- bottom: var(--notices-offset, var(--space-normal));
10
- left: var(--notices-offset, var(--space-normal));
9
+ right: calc(var(--notices-offset, var(--space-normal)) + env(safe-area-inset-right, 0px));
10
+ left: calc(var(--notices-offset, var(--space-normal)) + env(safe-area-inset-left, 0px));
11
11
  z-index: 1000;
12
12
  display: flex;
13
- margin-left: auto;
14
13
  max-width: var(--notices-width, var(--width-narrow));
15
14
  flex-direction: column;
16
- align-items: flex-end;
17
15
  gap: var(--notices-gap, var(--space-small));
18
16
 
19
17
  /* The list is as wide as `--notices-width`, so let clicks pass through the gaps to the page. */
20
18
  pointer-events: none;
21
19
 
22
- /* Each notice is only as wide as its content, and stays on the right. */
20
+ /* Each notice is only as wide as its content, and stays on the side of the list's corner. */
23
21
  & > * {
24
22
  inline-size: auto;
25
23
  max-width: 100%;
26
24
  pointer-events: auto;
25
+
26
+ /* Floating notices sit above the page, so give each one a shadow. */
27
+ --notice-shadow: var(--notices-shadow, var(--shadow-small));
27
28
  }
28
29
  }
30
+
31
+ /* Corners. The list keeps `--notices-offset` clear of the edges, plus the safe area of the device. */
32
+ .top {
33
+ top: calc(var(--notices-offset, var(--space-normal)) + env(safe-area-inset-top, 0px));
34
+ }
35
+
36
+ .bottom {
37
+ bottom: calc(var(--notices-offset, var(--space-normal)) + env(safe-area-inset-bottom, 0px));
38
+ }
39
+
40
+ .left {
41
+ margin-right: auto;
42
+ align-items: flex-start;
43
+ }
44
+
45
+ .right {
46
+ margin-left: auto;
47
+ align-items: flex-end;
48
+ }
29
49
  }
@@ -14,31 +14,46 @@ import { NOTICES } from "./NoticesStore.js";
14
14
  const NOTICES_CLASS = getModuleClass(NOTICES_CSS, "notices");
15
15
 
16
16
  /**
17
- * Props for `<Notices>` — flex styling variants for the notices container.
17
+ * Corner of the screen where `<Notices>` shows the list of notices.
18
+ *
19
+ * @see https://shelving.cc/ui/NoticesPosition
20
+ */
21
+ export type NoticesPosition = "top-left" | "top-right" | "bottom-left" | "bottom-right";
22
+
23
+ /**
24
+ * Props for `<Notices>` — the corner for the list, and flex styling variants for the notices container.
18
25
  *
19
26
  * @see https://shelving.cc/ui/NoticesProps
20
27
  */
21
- export interface NoticesProps extends FlexVariants, ClassProps {}
28
+ export interface NoticesProps extends FlexVariants, ClassProps {
29
+ /**
30
+ * Corner of the screen for the list. New notices slide in from this side.
31
+ * @default "bottom-right"
32
+ */
33
+ position?: NoticesPosition | undefined;
34
+ }
22
35
 
23
36
  /**
24
37
  * Render the global list of notices and subscribe to incoming `"notice"` events.
25
38
  * - Listens for `"notice"` events on `window` (or that bubble up to `window`) and shows them in the global notice list.
26
39
  * - This is how e.g. `<Button>` and `<FormNotify>` components send notices into the global list.
27
- * - Each notice slides in and out in its own view transition. The other notices move to their new places in the same transition.
40
+ * - Shows the list in the bottom-right corner, or in the corner that `position` sets.
41
+ * - Each notice slides in and out in its own view transition, from the side of its corner. The other notices move to their new places in the same transition.
28
42
  *
29
43
  * @kind component
30
44
  * @see https://shelving.cc/ui/Notices
31
45
  */
32
- export function Notices({ className, ...props }: NoticesProps): ReactElement {
46
+ export function Notices({ position = "bottom-right", className, ...props }: NoticesProps): ReactElement {
33
47
  const notices = useTransitionValue(NOTICES);
34
48
  useEffect(() => {
35
49
  // Subscribe to global notices.
36
50
  return subscribeNotices((message, status) => NOTICES.show(message, status));
37
51
  });
52
+ const [vertical, horizontal] = position.split("-");
38
53
  return (
39
- <aside className={getClass(NOTICES_CLASS, getFlexClass(props), className)}>
54
+ <aside className={getClass(NOTICES_CLASS, getModuleClass(NOTICES_CSS, vertical, horizontal), getFlexClass(props), className)}>
40
55
  {notices.map(notice => (
41
- <NoticeItem key={notice.key} notice={notice} />
56
+ <NoticeItem key={notice.key} notice={notice} position={position} />
42
57
  ))}
43
58
  </aside>
44
59
  );
@@ -48,10 +63,12 @@ export function Notices({ className, ...props }: NoticesProps): ReactElement {
48
63
  * Render one notice in its own view transition, and re-render when the notice changes in place.
49
64
  * - Module-private, but named without the `_` prefix: React and the hooks lint rule only treat a capitalised name as a component.
50
65
  */
51
- function NoticeItem({ notice }: { notice: NoticeStore<Status> }): ReactElement {
66
+ function NoticeItem({ notice, position }: { notice: NoticeStore<Status>; position: NoticesPosition }): ReactElement {
52
67
  const { children, status } = useTransitionValue(notice);
68
+ // New and closed notices slide from the side of the corner. A notice that changes in place is drawn from the corner itself.
69
+ const side = position.endsWith("left") ? "left" : "right";
53
70
  return (
54
- <ViewTransition enter="notice" exit="notice" update="notice-update">
71
+ <ViewTransition enter={`notice-${side}`} exit={`notice-${side}`} update={`notice-update-${position}`}>
55
72
  <Notice status={status}>{children}</Notice>
56
73
  </ViewTransition>
57
74
  );
@@ -9,6 +9,13 @@
9
9
  }
10
10
 
11
11
  /* Only `from` is set, so the keyframe ends at the snapshot's own position. The exit plays it in reverse. */
12
+ @keyframes notice-from-left {
13
+ from {
14
+ opacity: 0;
15
+ transform: translateX(-100%);
16
+ }
17
+ }
18
+
12
19
  @keyframes notice-from-right {
13
20
  from {
14
21
  opacity: 0;
@@ -22,46 +29,85 @@
22
29
  }
23
30
  }
24
31
 
25
- /* A new notice slides in from the right. `:only-child` stops Safari from also starting the animation on the missing image, which stops it later on the real one (see `FadeTransition.css`). */
26
- ::view-transition-new(.notice):only-child {
32
+ /*
33
+ * A new notice slides in from the side of its corner, and a closed notice slides out to that side.
34
+ * - `:only-child` stops Safari from also starting the animation on the missing image, which stops it later on the real one (see `FadeTransition.css`).
35
+ */
36
+ ::view-transition-new(.notice-left):only-child {
37
+ animation: notice-from-left var(--notices-transition-duration) ease-out both;
38
+ }
39
+
40
+ ::view-transition-old(.notice-left):only-child {
41
+ animation: notice-from-left var(--notices-transition-duration) ease-in reverse both;
42
+ }
43
+
44
+ ::view-transition-new(.notice-right):only-child {
27
45
  animation: notice-from-right var(--notices-transition-duration) ease-out both;
28
46
  }
29
47
 
30
- /* A closed notice slides out to the right. */
31
- ::view-transition-old(.notice):only-child {
48
+ ::view-transition-old(.notice-right):only-child {
32
49
  animation: notice-from-right var(--notices-transition-duration) ease-in reverse both;
33
50
  }
34
51
 
35
52
  /* The other notices move to their new places (the default group morph). */
36
- ::view-transition-group(.notice-update) {
53
+ ::view-transition-group(.notice-update-top-left),
54
+ ::view-transition-group(.notice-update-top-right),
55
+ ::view-transition-group(.notice-update-bottom-left),
56
+ ::view-transition-group(.notice-update-bottom-right) {
37
57
  animation-duration: var(--notices-transition-duration);
38
58
  }
39
59
 
40
60
  /*
41
61
  * A notice that changes in place does not animate: hide the old image, and show the new image at once at its own size.
42
- * - The group still morphs between the old and new size, so the new image is drawn unscaled from the bottom-right corner, which does not move.
62
+ * - The group still morphs between the old and new size, so the new image is drawn unscaled from the corner of the list, which does not move.
43
63
  * - For a notice that only moves, the old and new images are the same, so this changes nothing.
44
64
  */
45
- ::view-transition-old(.notice-update) {
65
+ ::view-transition-old(.notice-update-top-left),
66
+ ::view-transition-old(.notice-update-top-right),
67
+ ::view-transition-old(.notice-update-bottom-left),
68
+ ::view-transition-old(.notice-update-bottom-right) {
46
69
  animation: none;
47
70
  opacity: 0;
48
71
  }
49
72
 
50
- ::view-transition-new(.notice-update) {
73
+ ::view-transition-new(.notice-update-top-left),
74
+ ::view-transition-new(.notice-update-top-right),
75
+ ::view-transition-new(.notice-update-bottom-left),
76
+ ::view-transition-new(.notice-update-bottom-right) {
51
77
  animation: none;
52
- inset: auto 0 0 auto;
53
78
  width: auto;
54
79
  height: auto;
55
80
  }
56
81
 
82
+ ::view-transition-new(.notice-update-top-left) {
83
+ inset: 0 auto auto 0;
84
+ }
85
+
86
+ ::view-transition-new(.notice-update-top-right) {
87
+ inset: 0 0 auto auto;
88
+ }
89
+
90
+ ::view-transition-new(.notice-update-bottom-left) {
91
+ inset: auto auto 0 0;
92
+ }
93
+
94
+ ::view-transition-new(.notice-update-bottom-right) {
95
+ inset: auto 0 0 auto;
96
+ }
97
+
57
98
  /* Reduced motion: fade new and closed notices in place, and move the others at once. */
58
99
  @media (prefers-reduced-motion: reduce) {
59
- ::view-transition-new(.notice):only-child,
60
- ::view-transition-old(.notice):only-child {
100
+ ::view-transition-new(.notice-left):only-child,
101
+ ::view-transition-new(.notice-right):only-child,
102
+ ::view-transition-old(.notice-left):only-child,
103
+ ::view-transition-old(.notice-right):only-child {
61
104
  animation-name: notice-fade;
62
105
  }
63
106
 
64
- ::view-transition-group(.notice-update) {
107
+ ::view-transition-group(.notice-update-top-left),
108
+ ::view-transition-group(.notice-update-top-right),
109
+ ::view-transition-group(.notice-update-bottom-left),
110
+ ::view-transition-group(.notice-update-bottom-right) {
65
111
  animation: none;
66
112
  }
67
113
  }