magic-pill 9.2.0 → 9.4.0-next.1
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 +25 -0
- package/MIGRATING.md +2 -0
- package/README.md +158 -17
- package/dist/MagicPill/MagicPill.d.mts +43 -1
- package/dist/MagicPill/MagicPill.d.ts +43 -1
- package/dist/MagicPill/MagicPill.js +53 -6
- package/dist/MagicPill/MagicPill.mjs +56 -9
- package/dist/MagicPill/flag.js +1 -59
- package/dist/MagicPill/flag.mjs +1 -58
- package/dist/MagicPill/useChoreography.js +2 -1
- package/dist/MagicPill/useChoreography.mjs +3 -2
- package/dist/Pill/PillProgress.d.mts +12 -0
- package/dist/Pill/PillProgress.d.ts +12 -0
- package/dist/Pill/PillProgress.js +42 -0
- package/dist/Pill/PillProgress.mjs +42 -0
- package/dist/Pill/goo.js +353 -0
- package/dist/Pill/goo.mjs +347 -0
- package/dist/Pill/modal.js +2 -1
- package/dist/Pill/modal.mjs +3 -2
- package/dist/Pill/morph.js +7 -4
- package/dist/Pill/morph.mjs +8 -5
- package/dist/Pill/travel.js +2 -1
- package/dist/Pill/travel.mjs +3 -2
- package/dist/Pill/zone.js +3 -2
- package/dist/Pill/zone.mjs +4 -3
- package/dist/PillForm/PillSubmit.js +1 -1
- package/dist/PillForm/PillSubmit.mjs +3 -3
- package/dist/PillForm/popover.js +2 -1
- package/dist/PillForm/popover.mjs +3 -2
- package/dist/PillNavbar/PillNavbar.d.mts +8 -0
- package/dist/PillNavbar/PillNavbar.d.ts +8 -0
- package/dist/PillNavbar/PillNavbar.js +3 -2
- package/dist/PillNavbar/PillNavbar.mjs +3 -2
- package/dist/PillNavbar/room.d.mts +3 -0
- package/dist/PillNavbar/room.d.ts +2 -0
- package/dist/PillNavbar/room.js +89 -17
- package/dist/PillNavbar/room.mjs +89 -18
- package/dist/PillOptics/PillOptics.js +2 -1
- package/dist/PillOptics/PillOptics.mjs +3 -2
- package/dist/forms.css +2 -1
- package/dist/index.d.mts +30 -15
- package/dist/index.d.ts +30 -15
- package/dist/index.js +40 -12
- package/dist/index.mjs +40 -13
- package/dist/satellites/Actions.d.mts +12 -0
- package/dist/satellites/Actions.d.ts +11 -0
- package/dist/satellites/Actions.js +59 -0
- package/dist/satellites/Actions.mjs +56 -0
- package/dist/satellites/Orbitals.js +554 -0
- package/dist/satellites/Orbitals.mjs +554 -0
- package/dist/satellites/Satellites.js +400 -0
- package/dist/satellites/Satellites.mjs +400 -0
- package/dist/satellites/layout.js +156 -0
- package/dist/satellites/layout.mjs +156 -0
- package/dist/satellites/measure.js +25 -0
- package/dist/satellites/measure.mjs +24 -0
- package/dist/satellites/orbits.js +139 -0
- package/dist/satellites/orbits.mjs +136 -0
- package/dist/satellites/types.d.mts +54 -0
- package/dist/satellites/types.d.ts +54 -0
- package/dist/satellites.d.mts +5 -0
- package/dist/satellites.d.ts +5 -0
- package/dist/satellites.js +14 -0
- package/dist/satellites.mjs +12 -0
- package/dist/store/store.d.mts +103 -0
- package/dist/store/store.d.ts +103 -0
- package/dist/store/store.js +52 -1
- package/dist/store/store.mjs +52 -2
- package/dist/styles.css +174 -10
- package/dist/utils/react.js +8 -1
- package/dist/utils/react.mjs +8 -2
- package/package.json +12 -2
- package/dist/icons/ArrowIcon.d.mts +0 -4
- package/dist/icons/ArrowIcon.d.ts +0 -4
- package/dist/icons/BoxIcon.d.mts +0 -4
- package/dist/icons/BoxIcon.d.ts +0 -4
- package/dist/icons/CheckIcon.d.mts +0 -4
- package/dist/icons/CheckIcon.d.ts +0 -4
- package/dist/icons/CloseIcon.d.mts +0 -4
- package/dist/icons/CloseIcon.d.ts +0 -4
- package/dist/icons/CouponIcon.d.mts +0 -4
- package/dist/icons/CouponIcon.d.ts +0 -4
- package/dist/icons/DocumentIcon.d.mts +0 -4
- package/dist/icons/DocumentIcon.d.ts +0 -4
- package/dist/icons/HelpIcon.d.mts +0 -4
- package/dist/icons/HelpIcon.d.ts +0 -4
- package/dist/icons/InfoIcon.d.mts +0 -4
- package/dist/icons/InfoIcon.d.ts +0 -4
- package/dist/icons/MailIcon.d.mts +0 -4
- package/dist/icons/MailIcon.d.ts +0 -4
- package/dist/icons/PhoneIcon.d.mts +0 -4
- package/dist/icons/PhoneIcon.d.ts +0 -4
- package/dist/icons/PlusIcon.d.mts +0 -4
- package/dist/icons/PlusIcon.d.ts +0 -4
- package/dist/icons/UndoIcon.d.mts +0 -4
- package/dist/icons/UndoIcon.d.ts +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
### Added
|
|
6
|
+
- **Beta:** the Electron, in an optional entry, `magic-pill/satellites`: a small round pill that splits out of the host to keep a background activity in reach. `pill().electron()`, `updateElectron()` and `endElectron()`; on `<MagicPill>`, `satellites`, `pathname`, `electronSide`, `electronLine`, `keepElectronsOut`, `electronEnding` and `arrange`. It's tucked into the pill on the page that started it and while a notification has the pill, a tap goes back to that page, and the pill and its electrons stay centred as a group
|
|
7
|
+
- **Beta:** an electron's orbitals, its quick actions fanned out around it (`orbitals` on `pill().electron()`): opened by a long press (slide to one and release to run it), hovering with a mouse, or a tap (`orbitalsOpenOn`, with a first orbital going back), and the keyboard as a menu. On an arc away from the screen's edge, clear of the pill and the other electrons; when they don't all fit, a wheel that turns with the mouse wheel, a drag along it or the arrow keys, and stays open until a tap away. `orbitalLabels`, `orbitalsStayOpen`, `backLabel`, and the tokens `--mp-orbital-size`, `--mp-orbital-distance`, `--mp-orbital-spread`, `--mp-orbital-stagger`, `--mp-hover-delay` and `--mp-long-press`
|
|
8
|
+
- **Beta:** the page's actions, the design's wide atom: `usePillActions()` (from `magic-pill/satellites`) and `pill().setActions()` set one or more actions for the current page, next to the pill. `actionsStyle` (`"detached"`, a pill of their own that comes out of the host with the goo, or `"inside"`, after a divider), `actionsSide` (`"start"`, `"end"` or `"beside"`), `actionsOrientation` (`"auto"`, turning across when room runs out, `"horizontal"`, `"vertical"`) and `actionsLabel` on `<MagicPill>`
|
|
9
|
+
- `labels` on `<PillNavbar>`: which labels show at rest. `"auto"` (the default) shows the current page's while the pill has room for it and folds it when it doesn't, `"current"` always shows it, `"closed"` shows none. An electron stays in the pill's row when the navbar can fold to make room, and only goes above it when it still doesn't fit
|
|
10
|
+
- `PillProgress`: a progress ring around a value or an icon, in the text colour (`--mp-progress-size`, `--mp-progress-width`)
|
|
11
|
+
- The split's tokens, for a sidebar's flag: `--mp-duration-split` and `--mp-duration-join` (the enter and exit durations by default), `--mp-ease-split` (`bouncy`, the default, `pop`, `smooth` or any CSS easing), `--mp-goo` (`12`; `0` for no neck) and `--mp-electron-start` (`1`)
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- A navbar whose current page's label has no room folds it (`labels="auto"`, the new default), instead of the pill cutting its last items off. `labels="current"` keeps the old behaviour
|
|
15
|
+
- A sidebar's flag comes out of the sidebar's edge as a droplet, with goo: a neck forms between them, stretches and snaps, on a bouncy curve, and it goes back into the sidebar the same way. It no longer pops in at its spot with a short bridge, nor scales in and out. With reduced motion it still fades. On the glass themes, its blur waits until it's clear of the sidebar
|
|
16
|
+
|
|
17
|
+
## [9.3.0] - 2026-11-27
|
|
18
|
+
A token for the content's fade, the built-in icons deprecated, and two fixes. Nothing to change in your code: the icons still work as before, and leaving them can wait until the next major version.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
- `--mp-duration-fade` (`150ms`): how long the content takes to fade out before the pill shrinks, and in once it has grown, like the other duration tokens
|
|
22
|
+
|
|
23
|
+
### Deprecated
|
|
24
|
+
- The twelve built-in icons (`ArrowIcon`, `BoxIcon`, `CheckIcon`, `CloseIcon`, `CouponIcon`, `DocumentIcon`, `HelpIcon`, `InfoIcon`, `MailIcon`, `PhoneIcon`, `PlusIcon`, `UndoIcon`) and `IconProps`: bring your own icons, any React content fits an icon slot (README, "Icons"). They still work, unchanged, and go in the next major version. The defaults the library draws itself stay
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
- React 18 no longer warns about `useLayoutEffect` when the pills render on the server (L31)
|
|
28
|
+
- An `<img>` in an icon slot (a notification's, an action's, a field's) is sized like an `<svg>`, 1em square, instead of its file's own size
|
|
29
|
+
|
|
5
30
|
## [9.2.0] - 2026-11-26
|
|
6
31
|
Placement changes through the circle, and new layouts for notifications: in rows on any host, and as cards or flags in a sidebar. One default changes: a pill whose placement changes now closes to a circle, travels, and opens at its new place; `moveThroughCircle={false}` keeps the old travel at full size. Nothing else to change in your code.
|
|
7
32
|
|
package/MIGRATING.md
CHANGED
|
@@ -139,6 +139,8 @@ The active item also changes: an item is active on its own path and below, on wh
|
|
|
139
139
|
## 4. Icons
|
|
140
140
|
Icons are components now, and any React content works as an icon.
|
|
141
141
|
|
|
142
|
+
> **The built-in icons below are deprecated since 9.3** (they still work, and go in the next major version): you can also pass your own icons right away, any SVG, image or icon component ([README, "Icons"](./README.md#icons)). The table is the quickest way off 8.x.
|
|
143
|
+
|
|
142
144
|
| 8.x name | 9 component |
|
|
143
145
|
|---|---|
|
|
144
146
|
| `info` | `InfoIcon` |
|
package/README.md
CHANGED
|
@@ -3,10 +3,7 @@ Let it empower you.
|
|
|
3
3
|
|
|
4
4
|
> **9.0.0 is the first stable release of Magic Pill**; earlier versions are deprecated. Upgrading from 8.x? Read the [migration guide](./MIGRATING.md). 8.x is documented in the [8.1.0 README](https://github.com/CedricTheveneau/Magic-Pill/tree/v8.1.0#readme).
|
|
5
5
|
|
|
6
|
-
**[Try it on the live demo](https://cedrictheveneau.github.io/Magic-Pill/)**: the playground, the templates
|
|
7
|
-
|
|
8
|
-
#### Thank you !!
|
|
9
|
-
Thank you for your patience and to all people who already have shown interest in Magic Pill, it's my very first npm package and I couldn't ask for a better reception of my package after only a few days after its initial release.
|
|
6
|
+
**[Try it on the live demo](https://cedrictheveneau.github.io/Magic-Pill/)**: the playground, the templates, the building blocks, and [the docs](https://cedrictheveneau.github.io/Magic-Pill/docs/) with live examples.
|
|
10
7
|
|
|
11
8
|
## Badges
|
|
12
9
|

|
|
@@ -18,7 +15,7 @@ Thank you for your patience and to all people who already have shown interest in
|
|
|
18
15
|
## Introduction
|
|
19
16
|
Magic Pill is **a design primitive, not just a notification library.** At its core is *the pill*: a dark, fully rounded, elevated container with a strong design language, and you can put anything inside it.
|
|
20
17
|
|
|
21
|
-
On top of it come ready-made **templates** (a notification, a navbar) and a **controller** you can call from anywhere: `pill().notify(...)`. Use one pill as a discreet assistant at the bottom of the page, or several pills together (a sidebar, a navbar, a modal) to build a whole interface.
|
|
18
|
+
On top of it come ready-made **templates** (a notification, a navbar, a form panel) and a **controller** you can call from anywhere: `pill().notify(...)`. Use one pill as a discreet assistant at the bottom of the page, or several pills together (a sidebar, a navbar, a modal) to build a whole interface.
|
|
22
19
|
|
|
23
20
|
## Features
|
|
24
21
|
- [X] Two lines to get started: mount `<MagicPill />`, then call `pill().notify(...)` from anywhere, even outside React
|
|
@@ -26,11 +23,14 @@ On top of it come ready-made **templates** (a notification, a navbar) and a **co
|
|
|
26
23
|
- [X] Several named pills on one page, at any edge or corner, inline, or as a modal; pills that share a spot line up instead of overlapping
|
|
27
24
|
- [X] Anything inside: messages, icons and panels are React content; build your own templates from the same parts
|
|
28
25
|
- [X] Shape-changing animations (circle ↔ pill ↔ panel) at the pill's real size, notifications that slide into each other, a pill that travels when its placement changes, all respecting reduced motion
|
|
26
|
+
- [X] Notifications laid out the way the pill is: in one row, in rows, and in a sidebar as cards or as a flag out of its edge
|
|
27
|
+
- [X] **Beta:** the Electron, a small round pill that splits out of the main one to keep a background activity (a timer, an upload) in reach anywhere in the app (optional)
|
|
29
28
|
- [X] Forms: fields on native controls, in a panel or in the pill, validated by the browser, and a calendar (optional)
|
|
29
|
+
- [X] Themes (optional): glass and Liquid Glass, with refraction, a pointer light and adaptive tinting, or a theme of your own from the tokens
|
|
30
30
|
- [X] Accessible: screen reader announcements, keyboard focus pauses the countdown, focus handling for panels and modals
|
|
31
31
|
- [X] Works in any React 18+ app, including React Server Components (Next.js App Router), with any router
|
|
32
32
|
- [X] Styles you can override without `!important`, design tokens, no fonts loaded behind your back
|
|
33
|
-
- [X] Tiny: the quick start adds about **
|
|
33
|
+
- [X] Tiny: the quick start adds about **19 kB gzipped** to your app (15.5 kB of JavaScript + 3.7 kB of CSS, minified by your bundler), checked in CI. Unused parts are tree-shaken.
|
|
34
34
|
- [X] Written in TypeScript, zero runtime dependencies
|
|
35
35
|
|
|
36
36
|
## Installation
|
|
@@ -74,6 +74,8 @@ pill().notify({ icon: <CheckIcon />, message: "Saved!", variant: "success" });
|
|
|
74
74
|
|
|
75
75
|
That's it. The pill pops in at the bottom of the page, stays for 5 seconds, then goes away.
|
|
76
76
|
|
|
77
|
+
> **Icons:** the examples use the built-in icons (`CheckIcon`…), which are **deprecated**: they still work, and go in the next major version. Any icon works instead, from your own SVGs to Lucide or Font Awesome: see [Icons](#icons).
|
|
78
|
+
|
|
77
79
|
### Fonts
|
|
78
80
|
Magic Pill loads no fonts: it uses your page's fonts. For the signature look, an italic serif for messages (**Overlock**) and a bold sans for action labels (**Lexend**), point the two font tokens at them.
|
|
79
81
|
|
|
@@ -231,7 +233,7 @@ export function AppPill() {
|
|
|
231
233
|
</MagicPill>
|
|
232
234
|
```
|
|
233
235
|
|
|
234
|
-
- **The active link** shows its label and gets `aria-current="page"`.
|
|
236
|
+
- **The active link** shows its label and gets `aria-current="page"`. `labels` says which labels show at rest: `"auto"` (the default) shows the current page's while the pill has room for it, and folds it when it doesn't (next to an electron on a phone, or on a very narrow screen, where the pill used to cut its last items off); `"current"` always shows it; `"closed"` shows none. An item pointed at or focused shows its label in every case. A folded navbar has `data-folded`.
|
|
235
237
|
- **Without `pathname`**, the navbar reads `window.location.pathname` after mounting and on back/forward navigation. That misses client-side navigations, so pass `pathname` when you use a client-side router.
|
|
236
238
|
- **On a narrow screen**, when there's no room for the current page's label and the one you point at (or focus), the current one folds meanwhile. A label that still has no room ends with an ellipsis.
|
|
237
239
|
- **`aria-label`** defaults to `"Main"`.
|
|
@@ -265,7 +267,111 @@ pill("assistant").notify({ icon: <HelpIcon />, message: "Need a hand?", duration
|
|
|
265
267
|
```
|
|
266
268
|
A sidebar's notifications are pills like the others: it turns horizontal for them while it's a circle, and back once they're gone. Between its base layer and a notification it goes through the circle, even with `swap="always"`, unless the notification is in `rows` (it slides, turning as it goes) or a `card`: a card stays in the sidebar's column, and slides like any other content.
|
|
267
269
|
|
|
268
|
-
**A flag** (`notificationLayout="flag"`, `left`/`right` sidebars) leaves the sidebar where it is, usable: the notification comes out of its edge as a pill of its own (`[data-layout="flag"]`), next to the section it's about (`at`), and goes back into it. Pointing at it or focusing it pauses it; the next one slides in it, and it moves to its own section. Its panel opens beside the sidebar, in the middle of the screen.
|
|
270
|
+
**A flag** (`notificationLayout="flag"`, `left`/`right` sidebars) leaves the sidebar where it is, usable: the notification comes out of its edge as a pill of its own (`[data-layout="flag"]`), next to the section it's about (`at`), and goes back into it. Pointing at it or focusing it pauses it; the next one slides in it, and it moves to its own section. Its panel opens beside the sidebar, in the middle of the screen. It comes out of the sidebar's edge as a droplet (a neck forms between them, stretches and snaps) and goes back into it the same way: `--mp-duration-split` and `--mp-duration-join` time it, `--mp-ease-split` picks its curve (`bouncy`, the default, `pop`, `smooth` or any CSS easing), `--mp-goo` how sticky it is (`0`: no neck), `--mp-electron-start` the size it starts at.
|
|
271
|
+
|
|
272
|
+
## The Electron (beta)
|
|
273
|
+
A small round pill that splits out of the host to keep a background activity in reach while the person goes elsewhere in the app: a timer, a call, an upload. It's tucked into the pill on the page that started it, and comes out as a droplet (with the goo, like a sidebar's flag) anywhere else; a tap goes back to that page. **Beta:** it ships in `9.4.0-next` releases, and its API may still change.
|
|
274
|
+
|
|
275
|
+
It's optional: import `satellites` and give it to the host, with the current path.
|
|
276
|
+
|
|
277
|
+
```tsx
|
|
278
|
+
"use client";
|
|
279
|
+
import { MagicPill, PillNavbar } from "magic-pill";
|
|
280
|
+
import { satellites } from "magic-pill/satellites";
|
|
281
|
+
|
|
282
|
+
<MagicPill pathname={pathname} satellites={satellites} linkComponent={Link}>
|
|
283
|
+
<PillNavbar items={items} pathname={pathname} linkComponent={Link} />
|
|
284
|
+
</MagicPill>
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
// Anywhere in the app
|
|
289
|
+
const id = pill().electron({ label: "Focus timer", value: "25:00", valueText: "25 minutes left", progress: 0 });
|
|
290
|
+
pill().updateElectron(id, { value: "24:59", progress: 1 / 1500 }); // every second
|
|
291
|
+
pill().endElectron(id); // it goes back into the pill
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
| Option | Type | Notes |
|
|
295
|
+
|---|---|---|
|
|
296
|
+
| `label` | `string` | Required: its accessible name ("Focus timer"). |
|
|
297
|
+
| `value` / `valueText` | `string` | A short live text ("4:34", "64%"), and what screen readers read for it ("5 minutes left", default: `value`). Round `valueText`, so the name doesn't change every second. |
|
|
298
|
+
| `progress` | `number` (0 to 1) | Draws a progress ring around its content (`PillProgress`, which you can use in any pill). |
|
|
299
|
+
| `icon` | `ReactNode` | With `progress` and no `value`, it sits inside the ring. |
|
|
300
|
+
| `render` | `() => ReactNode` | Your own content instead of the ring, the value and the icon. |
|
|
301
|
+
| `href` | `string` | Where a tap goes back to (with the host's `linkComponent`). Default: the path it was started on. |
|
|
302
|
+
| `onClick` | `(event) => void` | Instead of going back: a button. |
|
|
303
|
+
| `hideOnOrigin` | `boolean` | Tucked into the pill while the current path is its `href` (or a page under it). Default `true`. |
|
|
304
|
+
| `variant` | as a pill's | Default: the host's. |
|
|
305
|
+
| `ending` | `"join"` · `"pop"` | How it leaves when it ends: back into the pill, or scaling out like any pill. Default: the host's `electronEnding` (`"join"`). |
|
|
306
|
+
| `announce` | `string` | Said once by screen readers whenever it changes, for a milestone ("Break time"). Its value is never announced on its own. |
|
|
307
|
+
| `orbitals` | `{ icon, label, onClick?, href?, id? }[]` | Its quick actions, fanned out around it (see below). |
|
|
308
|
+
| `backLabel` | `string` | With `orbitalsOpenOn="tap"`: the label of the first orbital, which goes back. Default `"Back"`. |
|
|
309
|
+
| `id` | `string` | Starting an electron with an id that's there updates it in place. |
|
|
310
|
+
|
|
311
|
+
| Host prop | Default | Notes |
|
|
312
|
+
|---|---|---|
|
|
313
|
+
| `satellites` | none | `satellites` from `magic-pill/satellites`. Without it, `pill().electron()` warns in development and shows nothing. |
|
|
314
|
+
| `pathname` | none | The current path, as for the navbar: an electron tucks in on its page. |
|
|
315
|
+
| `electronSide` | `"after"` | `"after"` (further along the edge), `"before"`, or `"beside"` (one row towards the page: above a bottom pill, next to a sidebar). |
|
|
316
|
+
| `electronLine` | `"along"` | Several electrons line up `"along"` the pill or stack `"across"` it. |
|
|
317
|
+
| `keepElectronsOut` | `false` | They tuck in while a notification has the pill (and come back once it has its base layer again); `true` keeps them out. |
|
|
318
|
+
| `electronEnding` | `"join"` | `"join"` or `"pop"`. |
|
|
319
|
+
| `arrange` | `"gather"` | `"gather"`: the pill and its electrons are centred as a group (or at the edge, for a `-start` or `-end` placement). `"spread"`: the pill stays where it is, the electrons go to the screen's edge (under the thumb on a tablet). |
|
|
320
|
+
| `orbitalsOpenOn` | `"press-hover"` | What opens an electron's orbitals: a long press, or hovering it with a mouse; `"press"`, a long press only; `"tap"`, a tap, with a first orbital going back. |
|
|
321
|
+
| `orbitalLabels` | `true` | The orbital under the finger, the pointer or the focus shows its label next to it. |
|
|
322
|
+
| `orbitalsStayOpen` | `true` | They stay open after one of them runs (Pause becomes Resume in place). |
|
|
323
|
+
|
|
324
|
+
**Orbitals** are an electron's quick actions, small round pills that bulge out of it with the goo:
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
pill().electron({
|
|
328
|
+
label: "Focus timer",
|
|
329
|
+
value: "4:34",
|
|
330
|
+
orbitals: [
|
|
331
|
+
{ icon: <PlusIcon />, label: "+1 min", onClick: addMinute },
|
|
332
|
+
{ icon: <PauseIcon />, label: "Pause", onClick: pause },
|
|
333
|
+
{ icon: <SkipIcon />, label: "Skip to the break", onClick: skip },
|
|
334
|
+
],
|
|
335
|
+
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
- A long press opens them. Keep pressing, slide to one (it's picked by its angle from the electron) and release to run it; released on none, they stay open until a tap away. With a mouse, hovering opens them too, and they close once the pointer leaves them.
|
|
339
|
+
- They fan out on an arc away from the screen's edge, clear of the pill, the other electrons and the screen's edges, moving out a little if they must. **When they don't all fit, they're a wheel:** the arc shows what fits and turns to show the others, with the mouse wheel, a drag along it, or the arrow keys (it brings the focused one into view). One past an end fades out (it peeks out faintly where its spot is clear). A wheel stays open until a tap away or Escape. `--mp-orbital-size` (an action's size), `--mp-orbital-distance` (`0.875rem`), `--mp-orbital-spread` (`auto`, or an angle such as `120deg`), `--mp-orbital-stagger` (`30ms`), `--mp-hover-delay` (`300ms`) and `--mp-long-press` (`450ms`) tune them.
|
|
340
|
+
- The keyboard opens them with the arrow pointing away from the edge, Shift+F10 or the context-menu key, and goes round them with the arrows, Home and End; Escape closes them and gives the focus back. An ARIA menu named after the electron.
|
|
341
|
+
|
|
342
|
+
**How it behaves:**
|
|
343
|
+
- **Short of room** (the pill and its electrons wider than the screen), a navbar folds its labels first (`labels="auto"`, its default); if they still don't fit, the last ones go beside the pill, one row towards the page, like the ladder.
|
|
344
|
+
- It splits and joins with the goo, on the split's tokens (`--mp-duration-split`, `--mp-duration-join`, `--mp-ease-split`, `--mp-goo`, `--mp-electron-start`, see [Styling](#styling)); `--mp-electron-gap` (`--mp-gap` by default) keeps it apart from the pill. With reduced motion, it fades.
|
|
345
|
+
- It's a link (or a button, or an image for neither) named after its `label` and `valueText`, with its own focus ring.
|
|
346
|
+
|
|
347
|
+
### The page's actions (beta)
|
|
348
|
+
The design's wide atom: one or more actions for the current page, next to the pill. A page sets them while it's mounted, and they go with it:
|
|
349
|
+
|
|
350
|
+
```tsx
|
|
351
|
+
"use client";
|
|
352
|
+
import { usePillActions } from "magic-pill/satellites";
|
|
353
|
+
|
|
354
|
+
const ACTIONS = [
|
|
355
|
+
{ icon: <PenIcon />, label: "Write", onClick: compose },
|
|
356
|
+
{ icon: <CheckIcon />, label: "Mark all as read", href: "/inbox/read" },
|
|
357
|
+
];
|
|
358
|
+
|
|
359
|
+
export function InboxPage() {
|
|
360
|
+
usePillActions(ACTIONS); // a stable array: a constant, or useMemo
|
|
361
|
+
return …;
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
`pill().setActions(items)` does the same from anywhere (`null` or none: they go). Each one is `{ icon, label, onClick?, href?, expanded?, id? }`, shown like the pill's own actions: the label on hover and focus, or all the time with `expanded`.
|
|
366
|
+
|
|
367
|
+
| Host prop | Default | Notes |
|
|
368
|
+
|---|---|---|
|
|
369
|
+
| `actionsStyle` | `"detached"` | `"detached"`: a pill of their own, which comes out of the host with the goo and goes back into it when the page has none (or while a notification has the pill). `"inside"`: in the pill itself, after a divider. |
|
|
370
|
+
| `actionsSide` | `"start"` | `"start"` or `"end"` (following the text direction: under the thumb you want), or `"beside"` (one row towards the page). |
|
|
371
|
+
| `actionsOrientation` | `"auto"` | `"auto"`: like the pill, turning across it when they'd leave the pill too little room (a column next to a bottom pill), and back once they're beside it. `"horizontal"` or `"vertical"`, always. |
|
|
372
|
+
| `actionsLabel` | `"Page actions"` | Their accessible name. |
|
|
373
|
+
|
|
374
|
+
Short of room, the actions turn across first (`"auto"`), then the last electrons, the actions and the first electron go beside the pill, in that order.
|
|
269
375
|
|
|
270
376
|
## The primitive
|
|
271
377
|
Everything above is built from `<Pill>` and its parts, and you can use them directly. A `<Pill>` you write yourself isn't connected to `pill()`: you control it with props.
|
|
@@ -483,9 +589,35 @@ With the keyboard: the arrows, Home and End (the week), Page Up and Page Down (t
|
|
|
483
589
|
> **Your app's resets:** CSS like `input { border: 1px solid }` that isn't in a layer also reaches the pill's fields. Their look is on what surrounds the controls, so they only need to stay bare: scope such rules, or put them in a layer. A global `:focus-visible` outline is the exception, already handled: the focus ring is drawn around the field, for the keyboard only (not after a click or a tap), and the bare control never draws one of its own.
|
|
484
590
|
|
|
485
591
|
## Icons
|
|
486
|
-
|
|
592
|
+
Bring your own: every `icon` (a notification's, an action's, a navbar item's, a field's, `idleIcon`, a panel's `trigger`) and `<PillIcon>` take any React content. The slot sizes and colours it for you:
|
|
593
|
+
|
|
594
|
+
- an `<svg>` or an `<img>` is drawn 1em square, whatever its own `width` and `height` (1.25rem in an action, larger as the leading icon);
|
|
595
|
+
- a font icon (Font Awesome's `<i>`, an emoji) takes the slot's font size;
|
|
596
|
+
- it's in the pill's text colour: draw your SVGs in `currentColor` to follow it (most icon libraries do);
|
|
597
|
+
- it's decorative (`aria-hidden`): the action's label or the message says what it means. Give `<PillIcon>` a `label` when the icon carries meaning of its own.
|
|
598
|
+
|
|
599
|
+
```tsx
|
|
600
|
+
import { ShoppingCart } from "lucide-react"; // or Heroicons, Phosphor, Material…
|
|
601
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
602
|
+
import { faTruck } from "@fortawesome/free-solid-svg-icons";
|
|
603
|
+
|
|
604
|
+
pill().notify({ icon: <ShoppingCart />, message: "Added to your cart" });
|
|
605
|
+
pill().notify({ icon: <FontAwesomeIcon icon={faTruck} />, message: "Shipped today" });
|
|
606
|
+
pill().notify({ icon: <i className="fa-solid fa-truck" />, message: "Shipped today" }); // Font Awesome's web font
|
|
607
|
+
pill().notify({ icon: <img src="/icons/cart.svg" alt="" />, message: "Added to your cart" });
|
|
608
|
+
pill().notify({
|
|
609
|
+
icon: (
|
|
610
|
+
<svg viewBox="0 0 24 24" fill="currentColor">
|
|
611
|
+
<path d="M12 2 2 22h20L12 2Z" />
|
|
612
|
+
</svg>
|
|
613
|
+
),
|
|
614
|
+
message: "Your own SVG",
|
|
615
|
+
});
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
An `<img>` keeps its file's colours: `currentColor` only reaches inline SVGs and font icons.
|
|
487
619
|
|
|
488
|
-
`ArrowIcon` · `BoxIcon` · `CheckIcon` · `CloseIcon` · `CouponIcon` · `DocumentIcon` · `HelpIcon` · `InfoIcon` · `MailIcon` · `PhoneIcon` · `PlusIcon` · `UndoIcon`
|
|
620
|
+
**The twelve built-in icons are deprecated** (`ArrowIcon` · `BoxIcon` · `CheckIcon` · `CloseIcon` · `CouponIcon` · `DocumentIcon` · `HelpIcon` · `InfoIcon` · `MailIcon` · `PhoneIcon` · `PlusIcon` · `UndoIcon`, and `IconProps`). They still work, unchanged, and editors strike them through; they go in the next major version. The library keeps the three it uses as defaults (the panel's trigger, its close button, the submit's tick), so nothing changes when you don't pass your own. To keep one of them, copy its SVG from `src/icons/` (MIT).
|
|
489
621
|
|
|
490
622
|
## Styling
|
|
491
623
|
- **Easy to override:** every rule sits in a `magic-pill` cascade layer. Any CSS of yours that isn't in a layer wins, whatever its specificity, with no `!important`.
|
|
@@ -526,6 +658,13 @@ Twelve built-in icons, drawn in `currentColor` and decorative by default (`aria-
|
|
|
526
658
|
| `--mp-offset` / `--mp-z-index` | `1.5rem` from the viewport edges (plus safe areas) / `50` |
|
|
527
659
|
| `--mp-backdrop` / `--mp-backdrop-blur` | the overlay's backdrop: `rgb(20 20 20 / 0.4)` / no blur |
|
|
528
660
|
| `--mp-duration-enter` / `--mp-duration-change` / `--mp-duration-exit` | `500ms` / `250ms` / `300ms` |
|
|
661
|
+
| `--mp-duration-fade` | `150ms`: the content fades out before the pill shrinks, and in once it has grown |
|
|
662
|
+
| `--mp-duration-split` / `--mp-duration-join` | `--mp-duration-enter` / `--mp-duration-exit`: a sidebar's flag coming out of the sidebar and going back |
|
|
663
|
+
| `--mp-ease-split` | `bouncy`: the split's curve, `bouncy`, `pop`, `smooth` or any CSS easing (the join is always smooth) |
|
|
664
|
+
| `--mp-goo` | `12`: how sticky the split is, the blur behind the neck in px. `0`: a plain split, no neck |
|
|
665
|
+
| `--mp-electron-start` | `1`: the size a flag or an electron starts at as it comes out. `1`: full size, hidden behind the pill's edge. Lower: it starts small and grows on its way out |
|
|
666
|
+
| `--mp-electron-gap` | `--mp-gap`: between the pill and its electrons (beta) |
|
|
667
|
+
| `--mp-progress-size` / `--mp-progress-width` | `3.375rem` / `3.5`: `PillProgress`'s ring, and its stroke |
|
|
529
668
|
| `--mp-scale-origin` | `center`: where the pill pops in from and scales out to (e.g. `bottom` to come out of the edge) |
|
|
530
669
|
| `--mp-align` | How a vertical pill lines up its items: `start`, `center` or `end` (following the text direction). By default, along the screen edge for a `left` or `right` pill, centred otherwise |
|
|
531
670
|
|
|
@@ -615,7 +754,7 @@ import { MagicPill, PillOptics } from "magic-pill";
|
|
|
615
754
|
- **Safe links:** links only render relative, `http(s):`, `mailto:` and `tel:` URLs. Anything else, such as `javascript:`, renders without a link (with a warning in development). React 18 doesn't block those URLs by itself.
|
|
616
755
|
|
|
617
756
|
## TypeScript
|
|
618
|
-
Everything is typed. The main types are `NotifyOptions`, `NotifyInput`, `PillController`, `
|
|
757
|
+
Everything is typed, and every component's props are exported as `<Component>Props` (`MagicPillProps`, `PillProps`, `PillFormPanelProps`, `PillInputProps`…). The other main types are `NotifyOptions`, `NotifyInput`, `PillController`, `PillPresence`, `PillPlacement`, `PillVariant`, `PillTheme`, `NotificationLayout`, `NavItem`, `LinkComponent` and `SendHandler`.
|
|
619
758
|
|
|
620
759
|
## Build your own
|
|
621
760
|
Maybe what I brought to the table wasn't enough but you like the idea behind it, that's why Magic Pill is under [MIT License](https://www.tldrlegal.com/license/mit-license), which means you can pretty much do whatever you want and build upon my own version of Magic Pill to bring it to new heights or just make it your own.
|
|
@@ -660,10 +799,12 @@ You can also send me emails anytime at [theveneaucedricpro@gmail.com](mailto:the
|
|
|
660
799
|
Magic Pill is distributed under the [MIT License](https://www.tldrlegal.com/license/mit-license).
|
|
661
800
|
|
|
662
801
|
## What's next?
|
|
663
|
-
| Coming next | Done in 9.
|
|
802
|
+
| Coming next | Done in 9.x |
|
|
664
803
|
|-----------|-----------|
|
|
665
|
-
|
|
|
666
|
-
|
|
|
667
|
-
|
|
|
668
|
-
|
|
|
669
|
-
| |
|
|
804
|
+
| The Electron: a small circle that splits off the pill to keep an activity (a timer, a call, an upload) within reach | A documentation site with live examples |
|
|
805
|
+
| Toolbox and carousel indicator templates | Themes: glass, Liquid Glass, your own |
|
|
806
|
+
| More layouts for vertical pills | Forms and a calendar |
|
|
807
|
+
| Performance presets for the glass | Notification layouts: rows, cards, flags |
|
|
808
|
+
| Usage from a CDN | Pills that share a spot line up instead of overlapping |
|
|
809
|
+
| | Animated morphing between contents, panels and placements, through the circle |
|
|
810
|
+
| | Any icon (any React content), actions with `onClick` or `href`, full documentation, tests |
|
|
@@ -2,6 +2,7 @@ import { ReactNode } from "react";
|
|
|
2
2
|
import { LinkComponent, PillProps } from "../Pill/types.mjs";
|
|
3
3
|
import { NotificationLayout, PillNotificationClassNames } from "../PillNotification/PillNotification.mjs";
|
|
4
4
|
import { SwapMode } from "./choreography.mjs";
|
|
5
|
+
import { ActionsOrientation, ActionsSide, ActionsStyle, ElectronEnding, ElectronLine, ElectronSide, OrbitalsOpenOn, PillSatellites, SatelliteArrangement } from "../satellites/types.mjs";
|
|
5
6
|
export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPresence" | "onPresenceChange" | "children" | "scene" | "sceneChange"> {
|
|
6
7
|
/** Default "main". Two hosts with the same name warn in development. */
|
|
7
8
|
name?: string;
|
|
@@ -36,9 +37,50 @@ export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPre
|
|
|
36
37
|
* in one row. A notification's own `layout` wins.
|
|
37
38
|
*/
|
|
38
39
|
notificationLayout?: NotificationLayout;
|
|
39
|
-
/** Passed to notification actions that have an `href
|
|
40
|
+
/** Passed to notification actions that have an `href`, and to electrons going back. */
|
|
40
41
|
linkComponent?: LinkComponent;
|
|
41
42
|
classNames?: PillNotificationClassNames;
|
|
43
|
+
/**
|
|
44
|
+
* The current path, as for the navbar: an electron is tucked in while the
|
|
45
|
+
* person is on its page (beta).
|
|
46
|
+
*/
|
|
47
|
+
pathname?: string;
|
|
48
|
+
/**
|
|
49
|
+
* The electrons and the other satellites (beta): `satellites` from
|
|
50
|
+
* `magic-pill/satellites`. Without it, `pill().electron()` does nothing.
|
|
51
|
+
*/
|
|
52
|
+
satellites?: PillSatellites;
|
|
53
|
+
/** Where electrons go: further along the edge (default), before the pill, or beside it, one row towards the page (beta). */
|
|
54
|
+
electronSide?: ElectronSide;
|
|
55
|
+
/** Several electrons line up along the pill (default) or stack across it (beta). */
|
|
56
|
+
electronLine?: ElectronLine;
|
|
57
|
+
/** Electrons stay out while a notification shows. Default false: they tuck in (beta). */
|
|
58
|
+
keepElectronsOut?: boolean;
|
|
59
|
+
/** How an electron leaves when it ends: back into the pill (default) or scaling out (beta). */
|
|
60
|
+
electronEnding?: ElectronEnding;
|
|
61
|
+
/** Satellites gathered around the pill (default) or spread to the screen's edges (beta). */
|
|
62
|
+
arrange?: SatelliteArrangement;
|
|
63
|
+
/**
|
|
64
|
+
* What opens an electron's orbitals: a long press, or hovering it with a
|
|
65
|
+
* mouse (default); a long press only; or a tap, which then adds a first
|
|
66
|
+
* orbital going back (beta).
|
|
67
|
+
*/
|
|
68
|
+
orbitalsOpenOn?: OrbitalsOpenOn;
|
|
69
|
+
/** The label of the orbital under the finger, the pointer or the focus shows next to it. Default true (beta). */
|
|
70
|
+
orbitalLabels?: boolean;
|
|
71
|
+
/** Orbitals stay open after one of them runs. Default true (beta). */
|
|
72
|
+
orbitalsStayOpen?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* The current page's actions (`usePillActions()`): a pill of their own
|
|
75
|
+
* (default), or in the pill itself, after a divider (beta).
|
|
76
|
+
*/
|
|
77
|
+
actionsStyle?: ActionsStyle;
|
|
78
|
+
/** Where the page's actions go: the start side (default), the end side, or beside the pill (beta). */
|
|
79
|
+
actionsSide?: ActionsSide;
|
|
80
|
+
/** The page's actions run like the pill, turning across when room runs out (default), or horizontal, or vertical (beta). */
|
|
81
|
+
actionsOrientation?: ActionsOrientation;
|
|
82
|
+
/** The page's actions' accessible name. Default "Page actions" (beta). */
|
|
83
|
+
actionsLabel?: string;
|
|
42
84
|
}
|
|
43
85
|
/**
|
|
44
86
|
* The batteries-included pill: a <Pill> with a base layer, a queue of
|
|
@@ -2,6 +2,7 @@ import { ReactNode } from "react";
|
|
|
2
2
|
import { LinkComponent, PillProps } from "../Pill/types.js";
|
|
3
3
|
import { NotificationLayout, PillNotificationClassNames } from "../PillNotification/PillNotification.js";
|
|
4
4
|
import { SwapMode } from "./choreography.js";
|
|
5
|
+
import { ActionsOrientation, ActionsSide, ActionsStyle, ElectronEnding, ElectronLine, ElectronSide, OrbitalsOpenOn, PillSatellites, SatelliteArrangement } from "../satellites/types.js";
|
|
5
6
|
export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPresence" | "onPresenceChange" | "children" | "scene" | "sceneChange"> {
|
|
6
7
|
/** Default "main". Two hosts with the same name warn in development. */
|
|
7
8
|
name?: string;
|
|
@@ -36,9 +37,50 @@ export interface MagicPillProps extends Omit<PillProps, "presence" | "defaultPre
|
|
|
36
37
|
* in one row. A notification's own `layout` wins.
|
|
37
38
|
*/
|
|
38
39
|
notificationLayout?: NotificationLayout;
|
|
39
|
-
/** Passed to notification actions that have an `href
|
|
40
|
+
/** Passed to notification actions that have an `href`, and to electrons going back. */
|
|
40
41
|
linkComponent?: LinkComponent;
|
|
41
42
|
classNames?: PillNotificationClassNames;
|
|
43
|
+
/**
|
|
44
|
+
* The current path, as for the navbar: an electron is tucked in while the
|
|
45
|
+
* person is on its page (beta).
|
|
46
|
+
*/
|
|
47
|
+
pathname?: string;
|
|
48
|
+
/**
|
|
49
|
+
* The electrons and the other satellites (beta): `satellites` from
|
|
50
|
+
* `magic-pill/satellites`. Without it, `pill().electron()` does nothing.
|
|
51
|
+
*/
|
|
52
|
+
satellites?: PillSatellites;
|
|
53
|
+
/** Where electrons go: further along the edge (default), before the pill, or beside it, one row towards the page (beta). */
|
|
54
|
+
electronSide?: ElectronSide;
|
|
55
|
+
/** Several electrons line up along the pill (default) or stack across it (beta). */
|
|
56
|
+
electronLine?: ElectronLine;
|
|
57
|
+
/** Electrons stay out while a notification shows. Default false: they tuck in (beta). */
|
|
58
|
+
keepElectronsOut?: boolean;
|
|
59
|
+
/** How an electron leaves when it ends: back into the pill (default) or scaling out (beta). */
|
|
60
|
+
electronEnding?: ElectronEnding;
|
|
61
|
+
/** Satellites gathered around the pill (default) or spread to the screen's edges (beta). */
|
|
62
|
+
arrange?: SatelliteArrangement;
|
|
63
|
+
/**
|
|
64
|
+
* What opens an electron's orbitals: a long press, or hovering it with a
|
|
65
|
+
* mouse (default); a long press only; or a tap, which then adds a first
|
|
66
|
+
* orbital going back (beta).
|
|
67
|
+
*/
|
|
68
|
+
orbitalsOpenOn?: OrbitalsOpenOn;
|
|
69
|
+
/** The label of the orbital under the finger, the pointer or the focus shows next to it. Default true (beta). */
|
|
70
|
+
orbitalLabels?: boolean;
|
|
71
|
+
/** Orbitals stay open after one of them runs. Default true (beta). */
|
|
72
|
+
orbitalsStayOpen?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* The current page's actions (`usePillActions()`): a pill of their own
|
|
75
|
+
* (default), or in the pill itself, after a divider (beta).
|
|
76
|
+
*/
|
|
77
|
+
actionsStyle?: ActionsStyle;
|
|
78
|
+
/** Where the page's actions go: the start side (default), the end side, or beside the pill (beta). */
|
|
79
|
+
actionsSide?: ActionsSide;
|
|
80
|
+
/** The page's actions run like the pill, turning across when room runs out (default), or horizontal, or vertical (beta). */
|
|
81
|
+
actionsOrientation?: ActionsOrientation;
|
|
82
|
+
/** The page's actions' accessible name. Default "Page actions" (beta). */
|
|
83
|
+
actionsLabel?: string;
|
|
42
84
|
}
|
|
43
85
|
/**
|
|
44
86
|
* The batteries-included pill: a <Pill> with a base layer, a queue of
|
|
@@ -12,6 +12,7 @@ const require_timing = require("../utils/timing.js");
|
|
|
12
12
|
const require_visuallyHidden = require("../utils/visuallyHidden.js");
|
|
13
13
|
const require_choreography = require("./choreography.js");
|
|
14
14
|
const require_flag = require("./flag.js");
|
|
15
|
+
const require_goo = require("../Pill/goo.js");
|
|
15
16
|
const require_useChoreography = require("./useChoreography.js");
|
|
16
17
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
17
18
|
|
|
@@ -82,13 +83,29 @@ const notificationIn = ({ scene, presence }) => scene.kind === "notification" &&
|
|
|
82
83
|
* The batteries-included pill: a <Pill> with a base layer, a queue of
|
|
83
84
|
* notifications fed by pill(name), and a live region that announces them.
|
|
84
85
|
*/
|
|
85
|
-
const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", children, scene, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, swap = "queue", notificationLayout = "pill", linkComponent, classNames, placement = "bottom", orientation, moveThroughCircle, variant, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }, forwardedRef) {
|
|
86
|
+
const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", children, scene, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, swap = "queue", notificationLayout = "pill", linkComponent, classNames, pathname, satellites, electronSide = "after", electronLine = "along", keepElectronsOut = false, electronEnding = "join", arrange = "gather", orbitalsOpenOn = "press-hover", orbitalLabels = true, orbitalsStayOpen = true, actionsStyle = "detached", actionsSide = "start", actionsOrientation = "auto", actionsLabel = "Page actions", placement = "bottom", orientation, moveThroughCircle, variant, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }, forwardedRef) {
|
|
86
87
|
const store = require_store.getStore(name);
|
|
87
88
|
const { current } = require_usePillQueue.usePillQueue(name);
|
|
88
89
|
const rootRef = (0, react.useRef)(null);
|
|
89
90
|
const ref = (0, react.useMemo)(() => require_react.mergeRefs(rootRef, forwardedRef), [forwardedRef]);
|
|
90
91
|
const flagRef = (0, react.useRef)(null);
|
|
91
92
|
(0, react.useEffect)(() => store.registerHost(), [store]);
|
|
93
|
+
(0, react.useEffect)(() => {
|
|
94
|
+
if (satellites) return;
|
|
95
|
+
const check = () => {
|
|
96
|
+
if (store.getElectrons().length > 0) {
|
|
97
|
+
require_react.devWarn(`pill("${name}").electron() needs the satellites: <MagicPill satellites={satellites}>, from "magic-pill/satellites".`);
|
|
98
|
+
unsubscribe();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const unsubscribe = store.subscribe(check);
|
|
102
|
+
check();
|
|
103
|
+
return unsubscribe;
|
|
104
|
+
}, [
|
|
105
|
+
store,
|
|
106
|
+
satellites,
|
|
107
|
+
name
|
|
108
|
+
]);
|
|
92
109
|
(0, react.useEffect)(require_inputModality.trackInputModality, []);
|
|
93
110
|
const hasBase = hasContent(children);
|
|
94
111
|
const lastBase = (0, react.useRef)(children);
|
|
@@ -159,7 +176,7 @@ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", chil
|
|
|
159
176
|
}
|
|
160
177
|
});
|
|
161
178
|
const flagY = flagDisplayed.presence === "panel" ? void 0 : flagSpot.y;
|
|
162
|
-
|
|
179
|
+
require_react.useIsomorphicLayoutEffect(() => {
|
|
163
180
|
const from = flagFrom.current;
|
|
164
181
|
flagFrom.current = null;
|
|
165
182
|
const flag = flagRef.current;
|
|
@@ -175,18 +192,18 @@ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", chil
|
|
|
175
192
|
});
|
|
176
193
|
}, [flagSpot, flagY]);
|
|
177
194
|
const flagPresence = (0, react.useRef)(flagDisplayed.presence);
|
|
178
|
-
|
|
195
|
+
require_react.useIsomorphicLayoutEffect(() => {
|
|
179
196
|
const previous = flagPresence.current;
|
|
180
197
|
flagPresence.current = flagDisplayed.presence;
|
|
181
198
|
const sidebar = rootRef.current;
|
|
182
199
|
const flag = flagRef.current;
|
|
183
200
|
if (!sidebar || !flag || previous === flagDisplayed.presence) return;
|
|
184
201
|
const { enter, fade, change, exit } = require_choreography.readTimings(flag);
|
|
185
|
-
if (previous === "hidden" && flagDisplayed.presence === "rest")
|
|
202
|
+
if (previous === "hidden" && flagDisplayed.presence === "rest") require_goo.playSplit(sidebar, flag, "split", {
|
|
186
203
|
delay: 0,
|
|
187
204
|
duration: enter
|
|
188
205
|
});
|
|
189
|
-
else if (flagDisplayed.presence === "hidden")
|
|
206
|
+
else if (flagDisplayed.presence === "hidden") require_goo.playSplit(sidebar, flag, "join", {
|
|
190
207
|
delay: fade + change,
|
|
191
208
|
duration: exit
|
|
192
209
|
});
|
|
@@ -235,9 +252,38 @@ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", chil
|
|
|
235
252
|
presence: next
|
|
236
253
|
});
|
|
237
254
|
};
|
|
255
|
+
const satelliteHost = satellites ? {
|
|
256
|
+
name,
|
|
257
|
+
store,
|
|
258
|
+
rootRef,
|
|
259
|
+
placement,
|
|
260
|
+
vertical: isVertical,
|
|
261
|
+
pathname,
|
|
262
|
+
notifying: target.kind === "notification" || displayed.scene.kind === "notification" || hasBase && !require_choreography.isOpen(displayed.presence),
|
|
263
|
+
linkComponent,
|
|
264
|
+
variant,
|
|
265
|
+
theme: rest.theme,
|
|
266
|
+
electronSide,
|
|
267
|
+
electronLine,
|
|
268
|
+
keepElectronsOut,
|
|
269
|
+
electronEnding,
|
|
270
|
+
arrange,
|
|
271
|
+
orbitalsOpenOn,
|
|
272
|
+
orbitalLabels,
|
|
273
|
+
orbitalsStayOpen,
|
|
274
|
+
actionsStyle,
|
|
275
|
+
actionsSide,
|
|
276
|
+
actionsOrientation,
|
|
277
|
+
actionsLabel
|
|
278
|
+
} : void 0;
|
|
279
|
+
const inside = satellites && satelliteHost && actionsStyle === "inside" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(satellites.Inside, { host: satelliteHost }) : null;
|
|
238
280
|
const renderScene = (shownScene) => {
|
|
239
281
|
switch (shownScene.kind) {
|
|
240
|
-
case "base": return /* @__PURE__ */ (0, react_jsx_runtime.
|
|
282
|
+
case "base": return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react.Fragment, { children: [
|
|
283
|
+
actionsSide !== "end" && inside,
|
|
284
|
+
lastScenes.current.get(shownScene.key)?.children ?? lastBase.current,
|
|
285
|
+
actionsSide === "end" && inside
|
|
286
|
+
] }, shownScene.key);
|
|
241
287
|
case "idle": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillIcon, { children: idleIcon });
|
|
242
288
|
case "notification": {
|
|
243
289
|
const { id, input } = shownScene.item;
|
|
@@ -319,6 +365,7 @@ const MagicPill = (0, react.forwardRef)(function MagicPill({ name = "main", chil
|
|
|
319
365
|
...flagPause.handlers,
|
|
320
366
|
children: renderScene(flagDisplayed.scene)
|
|
321
367
|
}),
|
|
368
|
+
satellites && satelliteHost && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(satellites.Layer, { host: satelliteHost }),
|
|
322
369
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
323
370
|
role: "status",
|
|
324
371
|
"aria-live": "polite",
|