magic-pill 8.0.3 → 9.0.0-next.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/CHANGELOG.md +120 -31
- package/MIGRATING.md +224 -0
- package/README.md +322 -252
- package/dist/MagicPill/MagicPill.d.mts +27 -0
- package/dist/MagicPill/MagicPill.d.ts +27 -0
- package/dist/MagicPill/MagicPill.js +2 -0
- package/dist/MagicPill/MagicPill.js.map +1 -0
- package/dist/MagicPill/MagicPill.mjs +2 -0
- package/dist/MagicPill/MagicPill.mjs.map +1 -0
- package/dist/MagicPill/choreography.js +2 -0
- package/dist/MagicPill/choreography.js.map +1 -0
- package/dist/MagicPill/choreography.mjs +2 -0
- package/dist/MagicPill/choreography.mjs.map +1 -0
- package/dist/Pill/Pill.d.mts +7 -0
- package/dist/Pill/Pill.d.ts +7 -0
- package/dist/Pill/Pill.js +2 -0
- package/dist/Pill/Pill.js.map +1 -0
- package/dist/Pill/Pill.mjs +2 -0
- package/dist/Pill/Pill.mjs.map +1 -0
- package/dist/Pill/PillAction.d.mts +7 -0
- package/dist/Pill/PillAction.d.ts +7 -0
- package/dist/Pill/PillAction.js +2 -0
- package/dist/Pill/PillAction.js.map +1 -0
- package/dist/Pill/PillAction.mjs +2 -0
- package/dist/Pill/PillAction.mjs.map +1 -0
- package/dist/Pill/PillContext.d.mts +3 -0
- package/dist/Pill/PillContext.d.ts +3 -0
- package/dist/Pill/PillContext.js +2 -0
- package/dist/Pill/PillContext.js.map +1 -0
- package/dist/Pill/PillContext.mjs +2 -0
- package/dist/Pill/PillContext.mjs.map +1 -0
- package/dist/Pill/PillPanel.d.mts +9 -0
- package/dist/Pill/PillPanel.d.ts +9 -0
- package/dist/Pill/PillPanel.js +2 -0
- package/dist/Pill/PillPanel.js.map +1 -0
- package/dist/Pill/PillPanel.mjs +2 -0
- package/dist/Pill/PillPanel.mjs.map +1 -0
- package/dist/Pill/parts.d.mts +10 -0
- package/dist/Pill/parts.d.ts +10 -0
- package/dist/Pill/parts.js +2 -0
- package/dist/Pill/parts.js.map +1 -0
- package/dist/Pill/parts.mjs +2 -0
- package/dist/Pill/parts.mjs.map +1 -0
- package/dist/Pill/types.d.mts +88 -0
- package/dist/Pill/types.d.ts +88 -0
- package/dist/PillNavbar/PillNavbar.d.mts +31 -0
- package/dist/PillNavbar/PillNavbar.d.ts +31 -0
- package/dist/PillNavbar/PillNavbar.js +2 -0
- package/dist/PillNavbar/PillNavbar.js.map +1 -0
- package/dist/PillNavbar/PillNavbar.mjs +2 -0
- package/dist/PillNavbar/PillNavbar.mjs.map +1 -0
- package/dist/PillNavbar/matchPath.d.mts +2 -0
- package/dist/PillNavbar/matchPath.d.ts +2 -0
- package/dist/PillNavbar/matchPath.js +2 -0
- package/dist/PillNavbar/matchPath.js.map +1 -0
- package/dist/PillNavbar/matchPath.mjs +2 -0
- package/dist/PillNavbar/matchPath.mjs.map +1 -0
- package/dist/PillNotification/PillNotification.d.mts +51 -0
- package/dist/PillNotification/PillNotification.d.ts +51 -0
- package/dist/PillNotification/PillNotification.js +2 -0
- package/dist/PillNotification/PillNotification.js.map +1 -0
- package/dist/PillNotification/PillNotification.mjs +2 -0
- package/dist/PillNotification/PillNotification.mjs.map +1 -0
- package/dist/icons/ArrowIcon.d.mts +4 -0
- package/dist/icons/ArrowIcon.d.ts +4 -0
- package/dist/icons/ArrowIcon.js +2 -0
- package/dist/icons/ArrowIcon.js.map +1 -0
- package/dist/icons/ArrowIcon.mjs +2 -0
- package/dist/icons/ArrowIcon.mjs.map +1 -0
- package/dist/icons/BoxIcon.d.mts +4 -0
- package/dist/icons/BoxIcon.d.ts +4 -0
- package/dist/icons/BoxIcon.js +2 -0
- package/dist/icons/BoxIcon.js.map +1 -0
- package/dist/icons/BoxIcon.mjs +2 -0
- package/dist/icons/BoxIcon.mjs.map +1 -0
- package/dist/icons/CheckIcon.d.mts +4 -0
- package/dist/icons/CheckIcon.d.ts +4 -0
- package/dist/icons/CheckIcon.js +2 -0
- package/dist/icons/CheckIcon.js.map +1 -0
- package/dist/icons/CheckIcon.mjs +2 -0
- package/dist/icons/CheckIcon.mjs.map +1 -0
- package/dist/icons/CloseIcon.d.mts +4 -0
- package/dist/icons/CloseIcon.d.ts +4 -0
- package/dist/icons/CloseIcon.js +2 -0
- package/dist/icons/CloseIcon.js.map +1 -0
- package/dist/icons/CloseIcon.mjs +2 -0
- package/dist/icons/CloseIcon.mjs.map +1 -0
- package/dist/icons/CouponIcon.d.mts +4 -0
- package/dist/icons/CouponIcon.d.ts +4 -0
- package/dist/icons/CouponIcon.js +2 -0
- package/dist/icons/CouponIcon.js.map +1 -0
- package/dist/icons/CouponIcon.mjs +2 -0
- package/dist/icons/CouponIcon.mjs.map +1 -0
- package/dist/icons/DocumentIcon.d.mts +4 -0
- package/dist/icons/DocumentIcon.d.ts +4 -0
- package/dist/icons/DocumentIcon.js +2 -0
- package/dist/icons/DocumentIcon.js.map +1 -0
- package/dist/icons/DocumentIcon.mjs +2 -0
- package/dist/icons/DocumentIcon.mjs.map +1 -0
- package/dist/icons/HelpIcon.d.mts +4 -0
- package/dist/icons/HelpIcon.d.ts +4 -0
- package/dist/icons/HelpIcon.js +2 -0
- package/dist/icons/HelpIcon.js.map +1 -0
- package/dist/icons/HelpIcon.mjs +2 -0
- package/dist/icons/HelpIcon.mjs.map +1 -0
- package/dist/icons/InfoIcon.d.mts +4 -0
- package/dist/icons/InfoIcon.d.ts +4 -0
- package/dist/icons/InfoIcon.js +2 -0
- package/dist/icons/InfoIcon.js.map +1 -0
- package/dist/icons/InfoIcon.mjs +2 -0
- package/dist/icons/InfoIcon.mjs.map +1 -0
- package/dist/icons/MailIcon.d.mts +4 -0
- package/dist/icons/MailIcon.d.ts +4 -0
- package/dist/icons/MailIcon.js +2 -0
- package/dist/icons/MailIcon.js.map +1 -0
- package/dist/icons/MailIcon.mjs +2 -0
- package/dist/icons/MailIcon.mjs.map +1 -0
- package/dist/icons/PhoneIcon.d.mts +4 -0
- package/dist/icons/PhoneIcon.d.ts +4 -0
- package/dist/icons/PhoneIcon.js +2 -0
- package/dist/icons/PhoneIcon.js.map +1 -0
- package/dist/icons/PhoneIcon.mjs +2 -0
- package/dist/icons/PhoneIcon.mjs.map +1 -0
- package/dist/icons/PlusIcon.d.mts +4 -0
- package/dist/icons/PlusIcon.d.ts +4 -0
- package/dist/icons/PlusIcon.js +2 -0
- package/dist/icons/PlusIcon.js.map +1 -0
- package/dist/icons/PlusIcon.mjs +2 -0
- package/dist/icons/PlusIcon.mjs.map +1 -0
- package/dist/icons/UndoIcon.d.mts +4 -0
- package/dist/icons/UndoIcon.d.ts +4 -0
- package/dist/icons/UndoIcon.js +2 -0
- package/dist/icons/UndoIcon.js.map +1 -0
- package/dist/icons/UndoIcon.mjs +2 -0
- package/dist/icons/UndoIcon.mjs.map +1 -0
- package/dist/icons/types.d.mts +3 -0
- package/dist/icons/types.d.ts +3 -0
- package/dist/index.d.mts +25 -0
- package/dist/index.d.ts +25 -5
- package/dist/index.js +1 -2
- package/dist/index.mjs +1 -0
- package/dist/store/store.d.mts +63 -0
- package/dist/store/store.d.ts +63 -0
- package/dist/store/store.js +2 -0
- package/dist/store/store.js.map +1 -0
- package/dist/store/store.mjs +2 -0
- package/dist/store/store.mjs.map +1 -0
- package/dist/store/usePillQueue.d.mts +6 -0
- package/dist/store/usePillQueue.d.ts +6 -0
- package/dist/store/usePillQueue.js +2 -0
- package/dist/store/usePillQueue.js.map +1 -0
- package/dist/store/usePillQueue.mjs +2 -0
- package/dist/store/usePillQueue.mjs.map +1 -0
- package/dist/styles.css +427 -0
- package/dist/utils/react.js +2 -0
- package/dist/utils/react.js.map +1 -0
- package/dist/utils/react.mjs +2 -0
- package/dist/utils/react.mjs.map +1 -0
- package/dist/utils/url.js +2 -0
- package/dist/utils/url.js.map +1 -0
- package/dist/utils/url.mjs +2 -0
- package/dist/utils/url.mjs.map +1 -0
- package/package.json +37 -24
- package/dist/MagicPill.d.ts +0 -8
- package/dist/Navbar/Navbar.d.ts +0 -9
- package/dist/Notification/Notification.d.ts +0 -9
- package/dist/defaultPillData.d.ts +0 -2
- package/dist/icons/arrow_label.d.ts +0 -3
- package/dist/icons/box_label.d.ts +0 -3
- package/dist/icons/checkmark.d.ts +0 -3
- package/dist/icons/checkmark_label.d.ts +0 -3
- package/dist/icons/coupon.d.ts +0 -3
- package/dist/icons/cross_label.d.ts +0 -3
- package/dist/icons/info.d.ts +0 -3
- package/dist/icons/mail_label.d.ts +0 -3
- package/dist/icons/plus_label.d.ts +0 -3
- package/dist/icons/questionmark.d.ts +0 -3
- package/dist/icons/quotation_label.d.ts +0 -3
- package/dist/icons/tel_label.d.ts +0 -3
- package/dist/icons/undo_label.d.ts +0 -3
- package/dist/index.esm.js +0 -2
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/magicpill.css +0 -267
- package/dist/types/index.d.ts +0 -3
- package/dist/types/magicPill.d.ts +0 -50
- package/dist/types/navbar.d.ts +0 -27
- package/dist/types/notification.d.ts +0 -140
- package/dist/utils/handlers.d.ts +0 -19
- package/dist/utils/icons.d.ts +0 -18
package/README.md
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
# Magic Pill
|
|
2
2
|
Let it empower you.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
Even though Magic Pill is already available to everyone, please keep in mind that its development is not over yet.
|
|
6
|
-
You can technically use it but the documentation is still being improved.
|
|
7
|
-
I'll update this section once a real usable version is released.
|
|
4
|
+
> **Status:** Magic Pill 9 is the first version with a **stable, documented API**. While it's in pre-release, install it with `npm install magic-pill@next`. The `latest` tag is still 8.1.0, documented in the [8.1.0 README](https://github.com/CedricTheveneau/Magic-Pill/tree/v8.1.0#readme). Coming from 8.x? Read the [migration guide](./MIGRATING.md).
|
|
8
5
|
|
|
9
6
|
#### Thank you !!
|
|
10
7
|
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.
|
|
@@ -15,284 +12,350 @@ Thank you for your patience and to all people who already have shown interest in
|
|
|
15
12
|
[](https://deepscan.io/dashboard#view=project&tid=23515&pid=28307&bid=911491)
|
|
16
13
|
[](https://snyk.io/test/github/CedricTheveneau/Magic-Pill)
|
|
17
14
|
[](https://packagephobia.com/result?p=magic-pill@latest)
|
|
18
|
-
[<svg width=20 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 98 96"><path d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z"></path></svg>](https://github.com/CedricTheveneau/Magic-Pill)
|
|
19
|
-
[<svg width=20 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 7.334v8h6.666v1.332H12v-1.332h12v-8zm6.666 6.664H5.334v-4H3.999v4H1.335V8.667h5.331zm4 0v1.336H8.001V8.667h5.334v5.332zm12.001 0h-1.33v-4h-1.336v4h-1.335v-4h-1.33v4h-2.671V8.667h8.002z"></path><path d="M10.665 10H12v2.667h-1.335z"></path></svg>](https://www.npmjs.com/package/magic-pill)
|
|
20
15
|
|
|
21
16
|
## Introduction
|
|
22
|
-
Magic Pill is a
|
|
17
|
+
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.
|
|
18
|
+
|
|
19
|
+
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.
|
|
23
20
|
|
|
24
21
|
## Features
|
|
25
|
-
- [X]
|
|
26
|
-
- [X]
|
|
27
|
-
- [X]
|
|
28
|
-
- [X]
|
|
29
|
-
- [X]
|
|
30
|
-
- [X]
|
|
31
|
-
- [X]
|
|
32
|
-
- [X]
|
|
22
|
+
- [X] Two lines to get started: mount `<MagicPill />`, then call `pill().notify(...)` from anywhere, even outside React
|
|
23
|
+
- [X] A notification queue on top of a **base layer** (e.g. a navbar): notifications take the pill over, then hand it back
|
|
24
|
+
- [X] Several named pills on one page, at any edge or corner, inline, or as a modal
|
|
25
|
+
- [X] Anything inside: messages, icons and panels are React content; build your own templates from the same parts
|
|
26
|
+
- [X] Shape-changing animations (circle ↔ pill ↔ panel) that respect reduced motion
|
|
27
|
+
- [X] Accessible: screen reader announcements, keyboard focus pauses the countdown, focus handling for panels and modals
|
|
28
|
+
- [X] Works in any React 18+ app, including React Server Components (Next.js App Router), with any router
|
|
29
|
+
- [X] Styles you can override without `!important`, design tokens, no fonts loaded behind your back
|
|
30
|
+
- [X] Written in TypeScript, zero runtime dependencies
|
|
33
31
|
|
|
34
32
|
## Installation
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
#### jsDelivr
|
|
38
|
-
```html
|
|
39
|
-
<script src="https://cdn.jsdelivr.net/npm/magic-pill/dist/index.js"></script>
|
|
40
|
-
<link href="https://cdn.jsdelivr.net/npm/magic-pill@latest/dist/magicpill.css" rel="stylesheet" />
|
|
33
|
+
```bash
|
|
34
|
+
npm install magic-pill@next
|
|
41
35
|
```
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
|
|
37
|
+
### Requirements
|
|
38
|
+
- **React and React DOM 18 or later** (peer dependencies).
|
|
39
|
+
- **Next.js is optional**: Magic Pill works in any React app (Vite, React Router, Remix…).
|
|
40
|
+
- **TypeScript is optional**: the type definitions ship with the package.
|
|
41
|
+
- Browsers from 2023 onwards (the stylesheet uses CSS nesting and cascade layers).
|
|
42
|
+
|
|
43
|
+
> **No CDN build:** Magic Pill is published for bundlers (Next.js, Vite, webpack…) as ES modules and CommonJS. It has no UMD build, so it can't be loaded with a plain `<script>` tag yet.
|
|
44
|
+
|
|
45
|
+
## Quick start
|
|
46
|
+
**1. Import the stylesheet and mount the pill once**, e.g. in your root layout:
|
|
47
|
+
```tsx
|
|
48
|
+
// app/layout.tsx (Next.js App Router: this can stay a Server Component)
|
|
49
|
+
import "magic-pill/styles.css";
|
|
50
|
+
import { MagicPill } from "magic-pill";
|
|
51
|
+
|
|
52
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
53
|
+
return (
|
|
54
|
+
<html lang="en">
|
|
55
|
+
<body>
|
|
56
|
+
{children}
|
|
57
|
+
<MagicPill />
|
|
58
|
+
</body>
|
|
59
|
+
</html>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
46
62
|
```
|
|
47
63
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
64
|
+
**2. Notify from anywhere** in your client code: an event handler, a store, a fetch callback…
|
|
65
|
+
```tsx
|
|
66
|
+
import { pill, CheckIcon } from "magic-pill";
|
|
67
|
+
|
|
68
|
+
pill().notify({ icon: <CheckIcon />, message: "Saved!", variant: "success" });
|
|
52
69
|
```
|
|
53
70
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
That's it. The pill pops in at the bottom of the page, stays for 5 seconds, then goes away.
|
|
72
|
+
|
|
73
|
+
### Fonts
|
|
74
|
+
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.
|
|
75
|
+
|
|
76
|
+
With `next/font`, the `variable` option sets the tokens directly:
|
|
77
|
+
```tsx
|
|
78
|
+
// app/layout.tsx
|
|
79
|
+
import { Lexend, Overlock } from "next/font/google";
|
|
80
|
+
|
|
81
|
+
const overlock = Overlock({ subsets: ["latin"], style: "italic", weight: ["400", "700", "900"], variable: "--mp-font-text" });
|
|
82
|
+
const lexend = Lexend({ subsets: ["latin"], weight: "700", variable: "--mp-font-accent" });
|
|
83
|
+
|
|
84
|
+
// <html lang="en" className={`${overlock.variable} ${lexend.variable}`}>
|
|
60
85
|
```
|
|
61
86
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"use client"
|
|
68
|
-
import React, { createContext, useContext, useState } from "react";
|
|
69
|
-
import { MagicPillType, Mode, NotificationIcon, CTAIcon, MagicPillNavbarItem } from "magic-pill";
|
|
70
|
-
import { updateMode, updateNotificationIcon, updateNotificationMessage, updateCTAIcon, updateCTALabel, updateCTALink, updateInfoTitle, updateInfoContent, updateInfoCloseLabel, updateNavItemLabel, updateNavItemLink, updateNavItemIcon, addNavItem, deleteNavItem } from "magic-pill";
|
|
71
|
-
|
|
72
|
-
const defaultPillData: MagicPillType = {
|
|
73
|
-
mode: "navbar",
|
|
74
|
-
navbar: {
|
|
75
|
-
navItems: [
|
|
76
|
-
{
|
|
77
|
-
icon: "arrow",
|
|
78
|
-
label: "mp-test",
|
|
79
|
-
link: "/mp-test"
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
icon: "cross",
|
|
83
|
-
label: "demo",
|
|
84
|
-
link: "/demo"
|
|
85
|
-
}
|
|
86
|
-
]
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
interface MagicPillContextType {
|
|
91
|
-
pillData: MagicPillType;
|
|
92
|
-
setPillData: (data: MagicPillType) => void;
|
|
93
|
-
// Direct data manipulation methods
|
|
94
|
-
updateMode: (mode: Mode) => void;
|
|
95
|
-
updateNotificationIcon: (icon: NotificationIcon) => void;
|
|
96
|
-
updateNotificationMessage: (message: string) => void;
|
|
97
|
-
updateCTAIcon: (icon: CTAIcon) => void;
|
|
98
|
-
updateCTALabel: (label: string) => void;
|
|
99
|
-
updateCTALink: (link: string) => void;
|
|
100
|
-
updateInfoTitle: (title: string) => void;
|
|
101
|
-
updateInfoContent: (content: string) => void;
|
|
102
|
-
updateInfoCloseLabel: (closeLabel: string) => void;
|
|
103
|
-
updateNavItemLabel: (label: string, index: number) => void;
|
|
104
|
-
updateNavItemLink: (link: string, index: number) => void;
|
|
105
|
-
updateNavItemIcon: (icon: CTAIcon, index: number) => void;
|
|
106
|
-
addNavItem: (navItem: MagicPillNavbarItem) => void;
|
|
107
|
-
deleteNavItem: (index: number) => void;
|
|
87
|
+
Without Next.js, load the fonts however you like (self-hosted is best for privacy), then set the tokens:
|
|
88
|
+
```css
|
|
89
|
+
:root {
|
|
90
|
+
--mp-font-text: "Overlock", serif;
|
|
91
|
+
--mp-font-accent: "Lexend", sans-serif;
|
|
108
92
|
}
|
|
93
|
+
```
|
|
109
94
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
updateInfoContent: () => {},
|
|
121
|
-
updateInfoCloseLabel: () => {},
|
|
122
|
-
updateNavItemLabel: () => {},
|
|
123
|
-
updateNavItemLink: () => {},
|
|
124
|
-
updateNavItemIcon: () => {},
|
|
125
|
-
addNavItem: () => {},
|
|
126
|
-
deleteNavItem: () => {},
|
|
95
|
+
## Notifications
|
|
96
|
+
```tsx
|
|
97
|
+
import { pill, CheckIcon, UndoIcon } from "magic-pill";
|
|
98
|
+
|
|
99
|
+
const id = pill().notify({
|
|
100
|
+
variant: "success",
|
|
101
|
+
icon: <CheckIcon />,
|
|
102
|
+
message: "Item successfully removed from cart!",
|
|
103
|
+
action: { icon: <UndoIcon />, label: "Undo", onClick: restoreItem },
|
|
104
|
+
duration: 8000,
|
|
127
105
|
});
|
|
106
|
+
```
|
|
128
107
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
updateInfoContent: (content: string) => updateInfoContent(content, setPillData),
|
|
156
|
-
updateInfoCloseLabel: (closeLabel: string) => updateInfoCloseLabel(closeLabel, setPillData),
|
|
157
|
-
updateNavItemLabel: (label: string, index: number) => updateNavItemLabel(label, index, setPillData),
|
|
158
|
-
updateNavItemLink: (link: string, index: number) => updateNavItemLink(link, index, setPillData),
|
|
159
|
-
updateNavItemIcon: (icon: CTAIcon, index: number) => updateNavItemIcon(icon, index, setPillData),
|
|
160
|
-
addNavItem: (navItem: MagicPillNavbarItem) => addNavItem(navItem, setPillData),
|
|
161
|
-
deleteNavItem: (index: number) => deleteNavItem(index, setPillData),
|
|
162
|
-
};
|
|
108
|
+
| Option | Type | Notes |
|
|
109
|
+
|---|---|---|
|
|
110
|
+
| `message` | `ReactNode` | Required (unless you use `render`). Any content, e.g. `<>Total: <strong>768.99$</strong></>`. Never parsed as HTML. |
|
|
111
|
+
| `icon` | `ReactNode` | The leading icon, followed by the divider. |
|
|
112
|
+
| `action` | `{ icon?, label, onClick }` or `{ icon?, label, href }` | The round button. Its label shows on hover and focus. Clicking it dismisses the notification; call `event.preventDefault()` in `onClick` to keep it open. |
|
|
113
|
+
| `panel` | `{ title?, content, trigger?, closeLabel? }` | A "Learn more" action that grows the pill into a panel. `trigger` defaults to `{ icon: <PlusIcon />, label: "Learn more" }`, `closeLabel` to `"Close"`. |
|
|
114
|
+
| `variant` | `"neutral"` · `"success"` · `"danger"` · any string | Defaults to the host's variant. |
|
|
115
|
+
| `duration` | `number` (ms) | Defaults to the host's (5000). `Infinity` keeps it until dismissed. |
|
|
116
|
+
| `id` | `string` | Notifying again with the same id updates the notification in place. |
|
|
117
|
+
| `announce` | `string` · `false` | What screen readers hear. Defaults to the message's text. |
|
|
118
|
+
| `onDismiss` | `(id, reason) => void` | `reason` is `"timeout"`, `"action"`, `"dismissed"` or `"cleared"`. |
|
|
119
|
+
| `render` | `({ id, dismiss }) => ReactNode` | Your own content instead of the template, with the same queue, timing and animation. See [Your own templates](#your-own-templates). |
|
|
120
|
+
|
|
121
|
+
**How it behaves:**
|
|
122
|
+
- Notifications queue up and show one at a time, first in, first out.
|
|
123
|
+
- The countdown starts once the pill is fully shown. It pauses while the pill is hovered, holds keyboard focus or has its panel open, or while the browser tab is hidden, and it starts again from the full duration afterwards.
|
|
124
|
+
- Calls made before `<MagicPill>` mounts are kept, and shown once it mounts.
|
|
125
|
+
- `pill()` is for client code. Called on the server, it does nothing (it warns in development), so visitors never see each other's notifications.
|
|
126
|
+
|
|
127
|
+
**The controller:**
|
|
128
|
+
```ts
|
|
129
|
+
const id = pill().notify({ message: "Saving…", duration: Infinity });
|
|
130
|
+
pill().update(id, { message: "Saved", variant: "success", duration: 3000 }); // in place, countdown restarts
|
|
131
|
+
pill().dismiss(id); // or pill().dismiss() for the visible one
|
|
132
|
+
pill().clear(); // empty the queue
|
|
133
|
+
```
|
|
163
134
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
135
|
+
**More examples**, the templates from the design:
|
|
136
|
+
```tsx
|
|
137
|
+
// A question: the action is an answer
|
|
138
|
+
pill().notify({ icon: <HelpIcon />, message: "Do you need some help?", action: { icon: <CheckIcon />, label: "Yes", onClick: openHelp } });
|
|
139
|
+
|
|
140
|
+
// Live data, and a link (rendered with your router's link component, see below)
|
|
141
|
+
pill().notify({
|
|
142
|
+
icon: <InfoIcon />,
|
|
143
|
+
message: <>Your current cart total is: <strong>{total}$</strong></>,
|
|
144
|
+
action: { icon: <CheckIcon />, label: "Checkout", href: "/checkout" },
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// A promotion that stays open while it works
|
|
148
|
+
pill().notify({
|
|
149
|
+
icon: <CouponIcon />,
|
|
150
|
+
message: "Interested in 10% off your next purchase?",
|
|
151
|
+
action: {
|
|
152
|
+
icon: <ArrowIcon />,
|
|
153
|
+
label: "Activate the promo code",
|
|
154
|
+
onClick: (event) => {
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
activatePromo().then(() => pill().dismiss());
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// An expandable panel
|
|
162
|
+
pill().notify({
|
|
163
|
+
icon: <InfoIcon />,
|
|
164
|
+
message: "Discover the powers Magic Pill gives you!",
|
|
165
|
+
panel: { title: "Discover the powers Magic Pill gives you!", content: <p>Anything can go in a panel.</p> },
|
|
166
|
+
duration: Infinity,
|
|
167
|
+
});
|
|
171
168
|
```
|
|
172
169
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
170
|
+
## The host: `<MagicPill>`
|
|
171
|
+
`<MagicPill>` is a pill plus its queue. It takes every [`<Pill>` prop](#the-primitive) except `presence`, and adds:
|
|
172
|
+
|
|
173
|
+
| Prop | Default | Notes |
|
|
174
|
+
|---|---|---|
|
|
175
|
+
| `name` | `"main"` | Which `pill(name)` controls it. Mount one host per name. |
|
|
176
|
+
| `children` | none | The **base layer**: shown whenever no notification is. Without it, the pill hides between notifications. |
|
|
177
|
+
| `duration` | `5000` | Default display time for notifications. |
|
|
178
|
+
| `idle` | `"hidden"` | With no base layer and nothing queued: `"hidden"`, or `"rest"` for a small resting circle showing `idleIcon`. |
|
|
179
|
+
| `idleIcon` | none | The icon of the resting circle. |
|
|
180
|
+
| `linkComponent` | `<a>` | Renders notification actions that have an `href`, e.g. Next's `Link`. |
|
|
181
|
+
| `classNames` | none | Classes for the notification's parts: `icon`, `divider`, `message`, `actions`, `action`, `panel`. |
|
|
182
|
+
| `placement` | `"bottom"` | See [placements](#the-primitive). |
|
|
178
183
|
|
|
179
|
-
|
|
184
|
+
### A navbar as the base layer
|
|
185
|
+
Notifications take the pill over, then it goes back to the navbar. The navbar works with any router: give it the current `pathname` and your link component.
|
|
180
186
|
|
|
187
|
+
```tsx
|
|
188
|
+
// app/app-pill.tsx
|
|
189
|
+
"use client";
|
|
190
|
+
import Link from "next/link";
|
|
191
|
+
import { usePathname } from "next/navigation";
|
|
192
|
+
import { MagicPill, PillNavbar, BoxIcon, DocumentIcon, MailIcon } from "magic-pill";
|
|
193
|
+
|
|
194
|
+
const items = [
|
|
195
|
+
{ href: "/", label: "Home", icon: <BoxIcon /> },
|
|
196
|
+
{ href: "/blog", label: "Blog", icon: <DocumentIcon /> },
|
|
197
|
+
{ href: "/contact", label: "Contact", icon: <MailIcon /> },
|
|
198
|
+
];
|
|
199
|
+
|
|
200
|
+
export function AppPill() {
|
|
181
201
|
return (
|
|
182
|
-
<
|
|
183
|
-
<
|
|
184
|
-
|
|
185
|
-
{children}
|
|
186
|
-
<MagicPillInitializer />
|
|
187
|
-
</MagicPillProvider>
|
|
188
|
-
</body>
|
|
189
|
-
</html>
|
|
202
|
+
<MagicPill linkComponent={Link}>
|
|
203
|
+
<PillNavbar items={items} pathname={usePathname()} linkComponent={Link} />
|
|
204
|
+
</MagicPill>
|
|
190
205
|
);
|
|
191
206
|
}
|
|
192
207
|
```
|
|
193
208
|
|
|
194
|
-
|
|
209
|
+
- **Matching:** an item is active on its own path and below it, on whole segments: `/blog` is active on `/blog/my-post`, not on `/blogroll`. `/` is only active on `/`. When several items match, the longest `href` wins. Override with `match: "exact"` or `match: (pathname) => boolean`.
|
|
210
|
+
- **The active link** shows its label and gets `aria-current="page"`.
|
|
211
|
+
- **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.
|
|
212
|
+
- **`aria-label`** defaults to `"Main"`.
|
|
213
|
+
|
|
214
|
+
**React Router:** its `Link` takes `to` instead of `href`. Wrap it once:
|
|
195
215
|
```tsx
|
|
196
|
-
|
|
197
|
-
import {
|
|
198
|
-
import {
|
|
216
|
+
import { forwardRef, type AnchorHTMLAttributes } from "react";
|
|
217
|
+
import { Link, useLocation } from "react-router";
|
|
218
|
+
import type { LinkComponent } from "magic-pill";
|
|
199
219
|
|
|
200
|
-
export const
|
|
201
|
-
|
|
220
|
+
export const RouterLink: LinkComponent = forwardRef<HTMLAnchorElement, AnchorHTMLAttributes<HTMLAnchorElement> & { href: string }>(
|
|
221
|
+
function RouterLink({ href, ...props }, ref) {
|
|
222
|
+
return <Link to={href} {...props} ref={ref} />;
|
|
223
|
+
},
|
|
224
|
+
);
|
|
202
225
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
226
|
+
// <PillNavbar items={items} pathname={useLocation().pathname} linkComponent={RouterLink} />
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Several pills
|
|
230
|
+
Give each host a name, and target it with `pill(name)`:
|
|
231
|
+
```tsx
|
|
232
|
+
<MagicPill name="sidebar" placement="left">
|
|
233
|
+
<PillNavbar items={items} pathname={pathname} linkComponent={Link} />
|
|
234
|
+
</MagicPill>
|
|
235
|
+
<MagicPill name="assistant" placement="bottom-end" idle="rest" idleIcon={<HelpIcon />} />
|
|
236
|
+
```
|
|
237
|
+
```ts
|
|
238
|
+
pill("sidebar").notify({ message: "3 new posts" });
|
|
239
|
+
pill("assistant").notify({ icon: <HelpIcon />, message: "Need a hand?", duration: Infinity });
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## The primitive
|
|
243
|
+
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.
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
import { Pill, PillActions, PillAction, PhoneIcon, MailIcon, DocumentIcon } from "magic-pill";
|
|
247
|
+
|
|
248
|
+
// The toolbox from the design: only actions
|
|
249
|
+
<Pill placement="bottom" aria-label="Contact us">
|
|
250
|
+
<PillActions>
|
|
251
|
+
<PillAction icon={<PhoneIcon />} label="Call us" href="tel:+33100000000" />
|
|
252
|
+
<PillAction icon={<MailIcon />} label="Send an email" href="mailto:hello@example.com" />
|
|
253
|
+
<PillAction icon={<DocumentIcon />} label="Ask for a quotation" href="/quote" linkComponent={Link} />
|
|
254
|
+
</PillActions>
|
|
255
|
+
</Pill>
|
|
207
256
|
```
|
|
208
|
-
> **🎉 | At this point, if you launch you app, Magic Pill should appear in your view**
|
|
209
257
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
"
|
|
213
|
-
|
|
214
|
-
|
|
258
|
+
| `<Pill>` prop | Values | Default |
|
|
259
|
+
|---|---|---|
|
|
260
|
+
| `placement` | `"inline"` (in the page flow), `"top"`, `"bottom"`, `"left"`, `"right"`, `"top-start"`, `"top-end"`, `"bottom-start"`, `"bottom-end"` (fixed; `start`/`end` follow the text direction), `"overlay"` (a modal `<dialog>`) | `"inline"` |
|
|
261
|
+
| `presence` / `defaultPresence` / `onPresenceChange` | `"hidden"`, `"rest"` (a circle with the icon only), `"compact"`, `"expanded"` (every action label shown), `"panel"` | `"compact"` |
|
|
262
|
+
| `orientation` | `"horizontal"`, `"vertical"` | `"vertical"` for `left`/`right` |
|
|
263
|
+
| `variant` | `"neutral"`, `"success"`, `"danger"`, or any string (see [Styling](#styling)) | `"neutral"` |
|
|
264
|
+
| `unstyled` | `boolean`: keep the behaviour, drop the look | `false` |
|
|
215
265
|
|
|
216
|
-
|
|
217
|
-
const { setPillData } = useMagicPill();
|
|
266
|
+
Any other prop (`className`, `aria-label`, `ref`…) goes to the element.
|
|
218
267
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
268
|
+
**The parts:**
|
|
269
|
+
- `PillIcon`: the leading icon. Decorative unless you give it a `label`.
|
|
270
|
+
- `PillDivider`: the thin line after the icon.
|
|
271
|
+
- `PillMessage`: the message, in the italic serif.
|
|
272
|
+
- `PillActions` and `PillAction`: round buttons. `label` is required: it's the accessible name, and it shows on hover, on focus, with `expanded`, or at the `expanded` level. A `PillAction` is a `<button>` with `onClick`, or a link with `href` (through `linkComponent` if you pass one).
|
|
273
|
+
- `PillPanel` and `PillPanelTrigger`: content shown at the `panel` level, and the action that opens it. The panel takes the focus when it opens, closes on Escape or with its close button, and gives the focus back to the trigger. One panel per pill.
|
|
222
274
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
275
|
+
**A modal:** `placement="overlay"` renders a native modal `<dialog>`, which brings a focus trap, Escape and an inert page with it.
|
|
276
|
+
```tsx
|
|
277
|
+
<Pill placement="overlay" variant="danger" presence={open ? "compact" : "hidden"} onPresenceChange={(p) => setOpen(p !== "hidden")}>
|
|
278
|
+
<PillMessage>Delete this item?</PillMessage>
|
|
279
|
+
<PillActions>
|
|
280
|
+
<PillAction icon={<CheckIcon />} label="Delete" expanded onClick={confirmDelete} />
|
|
281
|
+
<PillAction icon={<CloseIcon />} label="Cancel" onClick={() => setOpen(false)} />
|
|
282
|
+
</PillActions>
|
|
283
|
+
</Pill>
|
|
227
284
|
```
|
|
228
|
-
> **It really is as simple as that, to use Magic Pill, once the setup is done**
|
|
229
|
-
|
|
230
|
-
### Update Magic Pill's content granularly
|
|
231
|
-
Magic Pill, right from the start, has been thought out to be as highly customizable as possible.
|
|
232
|
-
To help you use it in the best way possible, a collection of handlers is part of the package.
|
|
233
|
-
|
|
234
|
-
- `updateMode` - Change Magic Pill's mode between "notification" and "navbar"
|
|
235
|
-
- `updateNotificationIcon` - Change the main notification icon
|
|
236
|
-
- `updateNotificationMessage` - Change the main notification message
|
|
237
|
-
- `updateCTAIcon` - Change the notification's CTA (Call To Action) icon
|
|
238
|
-
- `updateCTALabel` - Change the notification's CTA (Call To Action) label
|
|
239
|
-
- `updateCTALink` - Change the notification's CTA (Call To Action) redirection link
|
|
240
|
-
- `updateInfoTitle` - Change the notification's expanded info title
|
|
241
|
-
- `updateInfoContent` - Change the notification's expanded info main content
|
|
242
|
-
- `updateInfoCloseLabel` - Change the notification's expanded info close button's label
|
|
243
|
-
- `updateNavItemLabel` - Change a navbar item's label
|
|
244
|
-
- `updateNavItemLink` - Change a navbar item's link
|
|
245
|
-
- `updateNavItemIcon` - Change a navbar item's icon
|
|
246
|
-
- `handleActiveNavItem` - Automatically working handler directly used by the navbar to update the active link
|
|
247
|
-
- `addNavItem` - Add an item to the navbar
|
|
248
|
-
- `deleteNavItem` - Delete an item to the navbar
|
|
249
|
-
|
|
250
|
-
### Available Icons
|
|
251
|
-
#### Notification Icons
|
|
252
|
-
- `"info"` - Information icon
|
|
253
|
-
- `"checkmark"` - Success/confirmation icon
|
|
254
|
-
- `"questionmark"` - Help/question icon
|
|
255
|
-
- `"coupon"` - Coupon/offer icon
|
|
256
|
-
- `""` - No icon
|
|
257
|
-
|
|
258
|
-
#### CTA (Call to Action) Icons
|
|
259
|
-
- `"arrow"` - Arrow icon
|
|
260
|
-
- `"box"` - Box icon
|
|
261
|
-
- `"checkmark"` - Checkmark icon
|
|
262
|
-
- `"cross"` - Cross/close icon
|
|
263
|
-
- `"info"` - Information icon
|
|
264
|
-
- `"mail"` - Mail/email icon
|
|
265
|
-
- `"plus"` - Plus/add icon
|
|
266
|
-
- `"quotation"` - Quote/speech icon
|
|
267
|
-
- `"tel"` - Phone/telephone icon
|
|
268
|
-
- `"undo"` - Undo/back icon
|
|
269
|
-
- `""` - No icon
|
|
270
|
-
|
|
271
|
-
### Customization
|
|
272
|
-
Magic Pill is easily customizable through CSS variables. Simply replace the theme colors or fonts by changing the values in the variables set in ":root".
|
|
273
285
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
@import url('https://fonts.googleapis.com/css2?family=Lexend:wght@100..900&family=Overlock:ital,wght@0,400;0,700;0,900;1,400;1,700;1,900&display=swap');
|
|
286
|
+
### Your own templates
|
|
287
|
+
Templates are plain arrangements of the parts, so yours work the same way. `usePill()` gives a part access to its pill (`presence`, `setPresence`, `placement`, `orientation`, `variant`). Inside a `<MagicPill>`, the `render` option puts your arrangement in the queue:
|
|
277
288
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
289
|
+
```tsx
|
|
290
|
+
pill().notify({
|
|
291
|
+
announce: "Incoming call from Alex",
|
|
292
|
+
duration: Infinity,
|
|
293
|
+
render: ({ dismiss }) => (
|
|
294
|
+
<>
|
|
295
|
+
<PillIcon><PhoneIcon /></PillIcon>
|
|
296
|
+
<PillDivider />
|
|
297
|
+
<PillMessage>Alex is calling</PillMessage>
|
|
298
|
+
<PillActions>
|
|
299
|
+
<PillAction icon={<CheckIcon />} label="Answer" onClick={() => { answer(); dismiss(); }} />
|
|
300
|
+
<PillAction icon={<CloseIcon />} label="Decline" onClick={dismiss} />
|
|
301
|
+
</PillActions>
|
|
302
|
+
</>
|
|
303
|
+
),
|
|
304
|
+
});
|
|
294
305
|
```
|
|
295
306
|
|
|
307
|
+
### React Server Components
|
|
308
|
+
- The parts, `PillAction`, `PillNotification`, the icons and `pill()` have no `"use client"`. A Server Component can render them (and pass `linkComponent={Link}`) without shipping them to the browser.
|
|
309
|
+
- `Pill`, `MagicPill`, `PillPanel`, `PillPanelTrigger`, `PillNavbar`, `usePill` and `usePillQueue` are Client Components. You can still render them from a Server Component.
|
|
310
|
+
- Call `pill()` from client code: event handlers, effects, client-side stores.
|
|
311
|
+
|
|
312
|
+
### Headless: `usePillQueue`
|
|
313
|
+
To build your own display on the same store: `const { current, queued } = usePillQueue("main");`.
|
|
314
|
+
|
|
315
|
+
## Icons
|
|
316
|
+
Twelve built-in icons, drawn in `currentColor` and decorative by default (`aria-hidden`). Any other icon or SVG works too: icons are just React content.
|
|
317
|
+
|
|
318
|
+
`ArrowIcon` · `BoxIcon` · `CheckIcon` · `CloseIcon` · `CouponIcon` · `DocumentIcon` · `HelpIcon` · `InfoIcon` · `MailIcon` · `PhoneIcon` · `PlusIcon` · `UndoIcon`
|
|
319
|
+
|
|
320
|
+
## Styling
|
|
321
|
+
- **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`.
|
|
322
|
+
- **No collisions:** parts are selected by `data-mp` attributes (`[data-mp="pill"]`, `"icon"`, `"divider"`, `"message"`, `"actions"`, `"action"`, `"action-icon"`, `"label"`, `"panel"`, `"panel-title"`, `"panel-body"`, `"panel-footer"`, `"navbar"`), and states by `data-presence`, `data-placement`, `data-orientation` and `data-variant`. There are no class names of ours to clash with yours.
|
|
323
|
+
- **Classes:** every part takes a `className`; templates and `<MagicPill>` take `classNames`.
|
|
324
|
+
- **Tailwind CSS v4:** declare the layer order once, before your imports, so utilities win: `@layer theme, base, magic-pill, components, utilities;`.
|
|
325
|
+
- **Your own variants:** `variant="brand"` gives `data-variant="brand"`, so you can write `[data-variant="brand"] { --mp-surface: #4b2bd6; }`.
|
|
326
|
+
|
|
327
|
+
**Tokens:** set them on `:root`, on one pill, or anywhere in between.
|
|
328
|
+
|
|
329
|
+
| Token | Default |
|
|
330
|
+
|---|---|
|
|
331
|
+
| `--mp-surface` / `--mp-on-surface` | `#141414` / `#f9f9f9` |
|
|
332
|
+
| `--mp-action` / `--mp-on-action` | `#f9f9f9` / `#141414` |
|
|
333
|
+
| `--mp-success` / `--mp-danger` | `#3f7253` / `#c2303e` |
|
|
334
|
+
| `--mp-font-text` / `--mp-font-accent` | `inherit` (see [Fonts](#fonts)) |
|
|
335
|
+
| `--mp-text-size` / `--mp-title-size` | fluid, about 1rem / 1.5–2rem |
|
|
336
|
+
| `--mp-padding` / `--mp-gap` / `--mp-action-size` | `0.875rem` / `1rem` / `2.75rem` |
|
|
337
|
+
| `--mp-max-width` / `--mp-message-width` / `--mp-panel-width` | `48rem` / `24rem` / `32rem` |
|
|
338
|
+
| `--mp-radius-panel` / `--mp-shadow` | `2.5rem` / a soft drop shadow |
|
|
339
|
+
| `--mp-offset` / `--mp-z-index` | `1.5rem` from the viewport edges (plus safe areas) / `50` |
|
|
340
|
+
| `--mp-backdrop` | the overlay's backdrop |
|
|
341
|
+
| `--mp-duration-enter` / `--mp-duration-change` / `--mp-duration-exit` | `500ms` / `250ms` / `300ms` |
|
|
342
|
+
|
|
343
|
+
The pill fits small screens: sizes are in `rem`, fixed pills stay inside the viewport and its safe areas, and long panels scroll.
|
|
344
|
+
|
|
345
|
+
## Accessibility
|
|
346
|
+
- **Announcements:** each `<MagicPill>` has a polite live region that reads notifications out (or your `announce` text). A hidden pill leaves the accessibility tree.
|
|
347
|
+
- **Time to act:** the countdown pauses on hover and keyboard focus, and while a panel is open.
|
|
348
|
+
- **Panels and modals:** they take and give back the focus, and close on Escape. The overlay is a native modal `<dialog>`.
|
|
349
|
+
- **Accessible names:** every action has one (`label` is required), and icons are hidden from assistive technology.
|
|
350
|
+
- **Motion and contrast:** with `prefers-reduced-motion`, shape changes become short fades. In forced-colours mode, the shapes keep visible outlines.
|
|
351
|
+
|
|
352
|
+
## Security
|
|
353
|
+
- **No HTML strings:** contents are React nodes and never parsed as HTML, so text from your users can't inject markup.
|
|
354
|
+
- **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.
|
|
355
|
+
|
|
356
|
+
## TypeScript
|
|
357
|
+
Everything is typed. The main types are `NotifyOptions`, `NotifyInput`, `PillController`, `MagicPillProps`, `PillProps`, `PillPresence`, `PillPlacement`, `PillVariant`, `NavItem` and `LinkComponent`.
|
|
358
|
+
|
|
296
359
|
## Build your own
|
|
297
360
|
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.
|
|
298
361
|
|
|
@@ -302,12 +365,20 @@ Here's how to proceed:
|
|
|
302
365
|
git clone https://github.com/CedricTheveneau/Magic-Pill.git
|
|
303
366
|
```
|
|
304
367
|
|
|
305
|
-
2.
|
|
368
|
+
2. Use the Node.js version from `.nvmrc` (Node 26) and install all dependencies:
|
|
306
369
|
```bash
|
|
370
|
+
nvm use
|
|
307
371
|
npm install
|
|
308
372
|
```
|
|
309
373
|
|
|
310
|
-
3.
|
|
374
|
+
3. Check that everything works:
|
|
375
|
+
```bash
|
|
376
|
+
npm run typecheck # TypeScript
|
|
377
|
+
npm test # Vitest test suite
|
|
378
|
+
npm run build # Builds dist/ with tsdown
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
4. You're good to go! For easier development, we recommend creating a Next.js app and creating a symbolic link between the app and the package. Now, when you're making changes to the code in src/, the changes should be reflected in your Next.js app.
|
|
311
382
|
```bash
|
|
312
383
|
# Create a new Next.js app
|
|
313
384
|
npx create-next-app@latest my-app --typescript
|
|
@@ -320,17 +391,16 @@ npm link magic-pill
|
|
|
320
391
|
```
|
|
321
392
|
|
|
322
393
|
## Troubleshooting / Contact
|
|
323
|
-
|
|
324
|
-
You can send me emails anytime at [
|
|
394
|
+
Found a bug or something unclear? Please [open an issue](https://github.com/CedricTheveneau/Magic-Pill/issues).
|
|
395
|
+
You can also send me emails anytime at [theveneaucedricpro@gmail.com](mailto:theveneaucedricpro@gmail.com), I'll try my best to help you out.
|
|
325
396
|
|
|
326
397
|
## License
|
|
327
398
|
Magic Pill is distributed under the [MIT License](https://www.tldrlegal.com/license/mit-license).
|
|
328
399
|
|
|
329
400
|
## What's next?
|
|
330
|
-
|
|
|
401
|
+
| Coming next | Done in 9.0 |
|
|
331
402
|
|-----------|-----------|
|
|
332
|
-
|
|
|
333
|
-
|
|
|
334
|
-
|
|
|
335
|
-
|
|
|
336
|
-
| Add new modes | |
|
|
403
|
+
| Toolbox and carousel indicator templates | Custom icons (any React content) |
|
|
404
|
+
| Animated morphing between contents | Transitions between the navbar and notifications |
|
|
405
|
+
| More built-in icons | Function triggers on actions (`onClick`) |
|
|
406
|
+
| A documentation site with live examples | Responsive styles, full documentation, tests |
|