magic-pill 8.1.0 → 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.
Files changed (259) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/MIGRATING.md +224 -0
  3. package/README.md +309 -257
  4. package/dist/MagicPill/MagicPill.d.mts +27 -0
  5. package/dist/MagicPill/MagicPill.d.ts +27 -0
  6. package/dist/MagicPill/MagicPill.js +2 -0
  7. package/dist/MagicPill/MagicPill.js.map +1 -0
  8. package/dist/MagicPill/MagicPill.mjs +2 -0
  9. package/dist/MagicPill/MagicPill.mjs.map +1 -0
  10. package/dist/MagicPill/choreography.js +2 -0
  11. package/dist/MagicPill/choreography.js.map +1 -0
  12. package/dist/MagicPill/choreography.mjs +2 -0
  13. package/dist/MagicPill/choreography.mjs.map +1 -0
  14. package/dist/Pill/Pill.d.mts +7 -0
  15. package/dist/Pill/Pill.d.ts +7 -0
  16. package/dist/Pill/Pill.js +2 -0
  17. package/dist/Pill/Pill.js.map +1 -0
  18. package/dist/Pill/Pill.mjs +2 -0
  19. package/dist/Pill/Pill.mjs.map +1 -0
  20. package/dist/Pill/PillAction.d.mts +7 -0
  21. package/dist/Pill/PillAction.d.ts +7 -0
  22. package/dist/Pill/PillAction.js +2 -0
  23. package/dist/Pill/PillAction.js.map +1 -0
  24. package/dist/Pill/PillAction.mjs +2 -0
  25. package/dist/Pill/PillAction.mjs.map +1 -0
  26. package/dist/Pill/PillContext.d.mts +3 -0
  27. package/dist/Pill/PillContext.d.ts +3 -0
  28. package/dist/Pill/PillContext.js +2 -0
  29. package/dist/Pill/PillContext.js.map +1 -0
  30. package/dist/Pill/PillContext.mjs +2 -0
  31. package/dist/Pill/PillContext.mjs.map +1 -0
  32. package/dist/Pill/PillPanel.d.mts +9 -0
  33. package/dist/Pill/PillPanel.d.ts +9 -0
  34. package/dist/Pill/PillPanel.js +2 -0
  35. package/dist/Pill/PillPanel.js.map +1 -0
  36. package/dist/Pill/PillPanel.mjs +2 -0
  37. package/dist/Pill/PillPanel.mjs.map +1 -0
  38. package/dist/Pill/parts.d.mts +10 -0
  39. package/dist/Pill/parts.d.ts +10 -0
  40. package/dist/Pill/parts.js +2 -0
  41. package/dist/Pill/parts.js.map +1 -0
  42. package/dist/Pill/parts.mjs +2 -0
  43. package/dist/Pill/parts.mjs.map +1 -0
  44. package/dist/Pill/types.d.mts +88 -0
  45. package/dist/Pill/types.d.ts +88 -0
  46. package/dist/PillNavbar/PillNavbar.d.mts +31 -0
  47. package/dist/PillNavbar/PillNavbar.d.ts +31 -0
  48. package/dist/PillNavbar/PillNavbar.js +2 -0
  49. package/dist/PillNavbar/PillNavbar.js.map +1 -0
  50. package/dist/PillNavbar/PillNavbar.mjs +2 -0
  51. package/dist/PillNavbar/PillNavbar.mjs.map +1 -0
  52. package/dist/PillNavbar/matchPath.d.mts +2 -0
  53. package/dist/PillNavbar/matchPath.d.ts +2 -0
  54. package/dist/PillNavbar/matchPath.js +2 -0
  55. package/dist/PillNavbar/matchPath.js.map +1 -0
  56. package/dist/PillNavbar/matchPath.mjs +2 -0
  57. package/dist/PillNavbar/matchPath.mjs.map +1 -0
  58. package/dist/PillNotification/PillNotification.d.mts +51 -0
  59. package/dist/PillNotification/PillNotification.d.ts +51 -0
  60. package/dist/PillNotification/PillNotification.js +2 -0
  61. package/dist/PillNotification/PillNotification.js.map +1 -0
  62. package/dist/PillNotification/PillNotification.mjs +2 -0
  63. package/dist/PillNotification/PillNotification.mjs.map +1 -0
  64. package/dist/icons/ArrowIcon.d.mts +4 -0
  65. package/dist/icons/ArrowIcon.d.ts +4 -0
  66. package/dist/icons/ArrowIcon.js +2 -0
  67. package/dist/icons/ArrowIcon.js.map +1 -0
  68. package/dist/icons/ArrowIcon.mjs +2 -0
  69. package/dist/icons/ArrowIcon.mjs.map +1 -0
  70. package/dist/icons/BoxIcon.d.mts +4 -0
  71. package/dist/icons/BoxIcon.d.ts +4 -0
  72. package/dist/icons/BoxIcon.js +2 -0
  73. package/dist/icons/BoxIcon.js.map +1 -0
  74. package/dist/icons/BoxIcon.mjs +2 -0
  75. package/dist/icons/BoxIcon.mjs.map +1 -0
  76. package/dist/icons/CheckIcon.d.mts +4 -0
  77. package/dist/icons/CheckIcon.d.ts +4 -0
  78. package/dist/icons/CheckIcon.js +2 -0
  79. package/dist/icons/CheckIcon.js.map +1 -0
  80. package/dist/icons/CheckIcon.mjs +2 -0
  81. package/dist/icons/CheckIcon.mjs.map +1 -0
  82. package/dist/icons/CloseIcon.d.mts +4 -0
  83. package/dist/icons/CloseIcon.d.ts +4 -0
  84. package/dist/icons/CloseIcon.js +2 -0
  85. package/dist/icons/CloseIcon.js.map +1 -0
  86. package/dist/icons/CloseIcon.mjs +2 -0
  87. package/dist/icons/CloseIcon.mjs.map +1 -0
  88. package/dist/icons/CouponIcon.d.mts +4 -0
  89. package/dist/icons/CouponIcon.d.ts +4 -0
  90. package/dist/icons/CouponIcon.js +2 -0
  91. package/dist/icons/CouponIcon.js.map +1 -0
  92. package/dist/icons/CouponIcon.mjs +2 -0
  93. package/dist/icons/CouponIcon.mjs.map +1 -0
  94. package/dist/icons/DocumentIcon.d.mts +4 -0
  95. package/dist/icons/DocumentIcon.d.ts +4 -0
  96. package/dist/icons/DocumentIcon.js +2 -0
  97. package/dist/icons/DocumentIcon.js.map +1 -0
  98. package/dist/icons/DocumentIcon.mjs +2 -0
  99. package/dist/icons/DocumentIcon.mjs.map +1 -0
  100. package/dist/icons/HelpIcon.d.mts +4 -0
  101. package/dist/icons/HelpIcon.d.ts +4 -0
  102. package/dist/icons/HelpIcon.js +2 -0
  103. package/dist/icons/HelpIcon.js.map +1 -0
  104. package/dist/icons/HelpIcon.mjs +2 -0
  105. package/dist/icons/HelpIcon.mjs.map +1 -0
  106. package/dist/icons/InfoIcon.d.mts +4 -0
  107. package/dist/icons/InfoIcon.d.ts +4 -0
  108. package/dist/icons/InfoIcon.js +2 -0
  109. package/dist/icons/InfoIcon.js.map +1 -0
  110. package/dist/icons/InfoIcon.mjs +2 -0
  111. package/dist/icons/InfoIcon.mjs.map +1 -0
  112. package/dist/icons/MailIcon.d.mts +4 -0
  113. package/dist/icons/MailIcon.d.ts +4 -0
  114. package/dist/icons/MailIcon.js +2 -0
  115. package/dist/icons/MailIcon.js.map +1 -0
  116. package/dist/icons/MailIcon.mjs +2 -0
  117. package/dist/icons/MailIcon.mjs.map +1 -0
  118. package/dist/icons/PhoneIcon.d.mts +4 -0
  119. package/dist/icons/PhoneIcon.d.ts +4 -0
  120. package/dist/icons/PhoneIcon.js +2 -0
  121. package/dist/icons/PhoneIcon.js.map +1 -0
  122. package/dist/icons/PhoneIcon.mjs +2 -0
  123. package/dist/icons/PhoneIcon.mjs.map +1 -0
  124. package/dist/icons/PlusIcon.d.mts +4 -0
  125. package/dist/icons/PlusIcon.d.ts +4 -0
  126. package/dist/icons/PlusIcon.js +2 -0
  127. package/dist/icons/PlusIcon.js.map +1 -0
  128. package/dist/icons/PlusIcon.mjs +2 -0
  129. package/dist/icons/PlusIcon.mjs.map +1 -0
  130. package/dist/icons/UndoIcon.d.mts +4 -0
  131. package/dist/icons/UndoIcon.d.ts +4 -0
  132. package/dist/icons/UndoIcon.js +2 -0
  133. package/dist/icons/UndoIcon.js.map +1 -0
  134. package/dist/icons/UndoIcon.mjs +2 -0
  135. package/dist/icons/UndoIcon.mjs.map +1 -0
  136. package/dist/icons/types.d.mts +3 -0
  137. package/dist/icons/types.d.ts +3 -0
  138. package/dist/index.d.mts +25 -8
  139. package/dist/index.d.ts +25 -9
  140. package/dist/index.js +1 -1
  141. package/dist/index.mjs +1 -1
  142. package/dist/store/store.d.mts +63 -0
  143. package/dist/store/store.d.ts +63 -0
  144. package/dist/store/store.js +2 -0
  145. package/dist/store/store.js.map +1 -0
  146. package/dist/store/store.mjs +2 -0
  147. package/dist/store/store.mjs.map +1 -0
  148. package/dist/store/usePillQueue.d.mts +6 -0
  149. package/dist/store/usePillQueue.d.ts +6 -0
  150. package/dist/store/usePillQueue.js +2 -0
  151. package/dist/store/usePillQueue.js.map +1 -0
  152. package/dist/store/usePillQueue.mjs +2 -0
  153. package/dist/store/usePillQueue.mjs.map +1 -0
  154. package/dist/styles.css +427 -0
  155. package/dist/utils/react.js +2 -0
  156. package/dist/utils/react.js.map +1 -0
  157. package/dist/utils/react.mjs +2 -0
  158. package/dist/utils/react.mjs.map +1 -0
  159. package/dist/utils/url.js +2 -0
  160. package/dist/utils/url.js.map +1 -0
  161. package/dist/utils/url.mjs +2 -0
  162. package/dist/utils/url.mjs.map +1 -0
  163. package/package.json +5 -3
  164. package/dist/MagicPill.d.mts +0 -6
  165. package/dist/MagicPill.d.ts +0 -7
  166. package/dist/MagicPill.js +0 -2
  167. package/dist/MagicPill.js.map +0 -1
  168. package/dist/MagicPill.mjs +0 -2
  169. package/dist/MagicPill.mjs.map +0 -1
  170. package/dist/Navbar/Navbar.js +0 -2
  171. package/dist/Navbar/Navbar.js.map +0 -1
  172. package/dist/Navbar/Navbar.mjs +0 -2
  173. package/dist/Navbar/Navbar.mjs.map +0 -1
  174. package/dist/Notification/Notification.js +0 -2
  175. package/dist/Notification/Notification.js.map +0 -1
  176. package/dist/Notification/Notification.mjs +0 -2
  177. package/dist/Notification/Notification.mjs.map +0 -1
  178. package/dist/defaultPillData.d.mts +0 -2
  179. package/dist/defaultPillData.d.ts +0 -3
  180. package/dist/defaultPillData.js +0 -7
  181. package/dist/defaultPillData.js.map +0 -1
  182. package/dist/defaultPillData.mjs +0 -7
  183. package/dist/defaultPillData.mjs.map +0 -1
  184. package/dist/icons/arrow_label.js +0 -2
  185. package/dist/icons/arrow_label.js.map +0 -1
  186. package/dist/icons/arrow_label.mjs +0 -2
  187. package/dist/icons/arrow_label.mjs.map +0 -1
  188. package/dist/icons/box_label.js +0 -2
  189. package/dist/icons/box_label.js.map +0 -1
  190. package/dist/icons/box_label.mjs +0 -2
  191. package/dist/icons/box_label.mjs.map +0 -1
  192. package/dist/icons/checkmark.js +0 -2
  193. package/dist/icons/checkmark.js.map +0 -1
  194. package/dist/icons/checkmark.mjs +0 -2
  195. package/dist/icons/checkmark.mjs.map +0 -1
  196. package/dist/icons/checkmark_label.js +0 -2
  197. package/dist/icons/checkmark_label.js.map +0 -1
  198. package/dist/icons/checkmark_label.mjs +0 -2
  199. package/dist/icons/checkmark_label.mjs.map +0 -1
  200. package/dist/icons/coupon.js +0 -2
  201. package/dist/icons/coupon.js.map +0 -1
  202. package/dist/icons/coupon.mjs +0 -2
  203. package/dist/icons/coupon.mjs.map +0 -1
  204. package/dist/icons/cross_label.js +0 -2
  205. package/dist/icons/cross_label.js.map +0 -1
  206. package/dist/icons/cross_label.mjs +0 -2
  207. package/dist/icons/cross_label.mjs.map +0 -1
  208. package/dist/icons/info.js +0 -2
  209. package/dist/icons/info.js.map +0 -1
  210. package/dist/icons/info.mjs +0 -2
  211. package/dist/icons/info.mjs.map +0 -1
  212. package/dist/icons/info_label.js +0 -2
  213. package/dist/icons/info_label.js.map +0 -1
  214. package/dist/icons/info_label.mjs +0 -2
  215. package/dist/icons/info_label.mjs.map +0 -1
  216. package/dist/icons/mail_label.js +0 -2
  217. package/dist/icons/mail_label.js.map +0 -1
  218. package/dist/icons/mail_label.mjs +0 -2
  219. package/dist/icons/mail_label.mjs.map +0 -1
  220. package/dist/icons/plus_label.js +0 -2
  221. package/dist/icons/plus_label.js.map +0 -1
  222. package/dist/icons/plus_label.mjs +0 -2
  223. package/dist/icons/plus_label.mjs.map +0 -1
  224. package/dist/icons/questionmark.js +0 -2
  225. package/dist/icons/questionmark.js.map +0 -1
  226. package/dist/icons/questionmark.mjs +0 -2
  227. package/dist/icons/questionmark.mjs.map +0 -1
  228. package/dist/icons/quotation_label.js +0 -2
  229. package/dist/icons/quotation_label.js.map +0 -1
  230. package/dist/icons/quotation_label.mjs +0 -2
  231. package/dist/icons/quotation_label.mjs.map +0 -1
  232. package/dist/icons/tel_label.js +0 -2
  233. package/dist/icons/tel_label.js.map +0 -1
  234. package/dist/icons/tel_label.mjs +0 -2
  235. package/dist/icons/tel_label.mjs.map +0 -1
  236. package/dist/icons/undo_label.js +0 -2
  237. package/dist/icons/undo_label.js.map +0 -1
  238. package/dist/icons/undo_label.mjs +0 -2
  239. package/dist/icons/undo_label.mjs.map +0 -1
  240. package/dist/magicpill.css +0 -315
  241. package/dist/types/index.d.ts +0 -4
  242. package/dist/types/magicPill.d.mts +0 -50
  243. package/dist/types/magicPill.d.ts +0 -50
  244. package/dist/types/navbar.d.mts +0 -27
  245. package/dist/types/navbar.d.ts +0 -28
  246. package/dist/types/notification.d.mts +0 -140
  247. package/dist/types/notification.d.ts +0 -141
  248. package/dist/utils/handlers.d.mts +0 -20
  249. package/dist/utils/handlers.d.ts +0 -21
  250. package/dist/utils/handlers.js +0 -2
  251. package/dist/utils/handlers.js.map +0 -1
  252. package/dist/utils/handlers.mjs +0 -2
  253. package/dist/utils/handlers.mjs.map +0 -1
  254. package/dist/utils/icons.d.mts +0 -20
  255. package/dist/utils/icons.d.ts +0 -20
  256. package/dist/utils/icons.js +0 -2
  257. package/dist/utils/icons.js.map +0 -1
  258. package/dist/utils/icons.mjs +0 -2
  259. package/dist/utils/icons.mjs.map +0 -1
package/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  # Magic Pill
2
2
  Let it empower you.
3
3
 
4
- ## Disclaimer
5
- Magic Pill 8.x is usable and maintained: it gets bug fixes and security updates.
6
- Please keep in mind that its API isn't final yet, though. The next major version will rework it (with breaking changes), and the documentation is still being improved.
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).
7
5
 
8
6
  #### Thank you !!
9
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.
@@ -14,296 +12,350 @@ Thank you for your patience and to all people who already have shown interest in
14
12
  [![DeepScan grade](https://deepscan.io/api/teams/23515/projects/28307/branches/911491/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=23515&pid=28307&bid=911491)
15
13
  [![Known Vulnerabilities](https://snyk.io/test/github/CedricTheveneau/Magic-Pill/badge.svg)](https://snyk.io/test/github/CedricTheveneau/Magic-Pill)
16
14
  [![install size](https://packagephobia.com/badge?p=magic-pill@latest)](https://packagephobia.com/result?p=magic-pill@latest)
17
- [<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)
18
- [<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)
19
15
 
20
16
  ## Introduction
21
- Magic Pill is a powerful React component that lets you show contextual information to your users in multiple ways. It can function as a notification system mimicking Apple's Dynamic Island, or as a dynamic navbar for seamless navigation. Built with TypeScript for enhanced type safety and developer experience.
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.
22
20
 
23
21
  ## Features
24
- - [X] Multiple modes: Notification system and Dynamic Navbar
25
- - [X] Written in TypeScript with comprehensive type definitions
26
- - [X] Highly customizable React component with strongly typed props
27
- - [X] Fully customized styling based on CSS variables for easy theme adaptation
28
- - [X] Works in any React 18+ app: Next.js (Server Components included), Vite, React Router…
29
- - [X] Zero runtime dependencies: React is the only peer dependency
30
- - [X] Accessible: announced by screen readers, pauses on hover and keyboard focus, respects reduced motion
31
- - [X] Lightweight and efficient
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
32
31
 
33
32
  ## Installation
34
- ### npm
35
- Magic Pill is available on npm, simply use the following command and you're ready to go!
36
33
  ```bash
37
- npm install magic-pill
34
+ npm install magic-pill@next
38
35
  ```
39
36
 
40
37
  ### Requirements
41
38
  - **React and React DOM 18 or later** (peer dependencies).
42
- - **Next.js is optional**: Magic Pill works in any React app.
39
+ - **Next.js is optional**: Magic Pill works in any React app (Vite, React Router, Remix…).
43
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
+ }
62
+ ```
63
+
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";
44
67
 
45
- > **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.
68
+ pill().notify({ icon: <CheckIcon />, message: "Saved!", variant: "success" });
69
+ ```
70
+
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" });
46
83
 
47
- ## How to use it?
48
- ### Import styles
49
- For it to work properly, you need to import styles in your app (we recommend importing it into your root layout or `App` file).
50
- ```typescript
51
- // Import in your Next.js or React project
52
- import "magic-pill/dist/magicpill.css";
53
- // or, equivalently
54
- import "magic-pill/magicpill.css";
84
+ // <html lang="en" className={`${overlock.variable} ${lexend.variable}`}>
55
85
  ```
56
86
 
57
- > **Fonts:** the stylesheet loads its fonts (Lexend and Overlock) from Google Fonts with a CSS `@import`. Next.js 16's default bundler, Turbopack, drops that `@import`. If the pill shows a generic font, load the fonts yourself (for example with `next/font`) or point `--mp__font-text` and `--mp__font-accent` to your own fonts (see [Customization](#customization)).
58
-
59
- ### Usage with React/Next.js
60
- Magic Pill is designed to be used with a Context to manage its state globally. Here's how to set it up:
61
-
62
- > `MagicPill` is a Client Component, so you can also render it directly from a Server Component. The Context below is what lets any part of your app change its content.
63
-
64
- 1. First, create a context for Magic Pill (e.g., in `app/contexts/magicPillContext.tsx`):
65
- ```typescript
66
- "use client"
67
- import React, { createContext, useContext, useState } from "react";
68
- import { MagicPillType, Mode, NotificationIcon, CTAIcon, MagicPillNavbarItem } from "magic-pill";
69
- import { updateMode, updateNotificationIcon, updateNotificationMessage, updateCTAIcon, updateCTALabel, updateCTALink, updateInfoTitle, updateInfoContent, updateInfoCloseLabel, updateNavItemLabel, updateNavItemLink, updateNavItemIcon, addNavItem, deleteNavItem } from "magic-pill";
70
-
71
- const defaultPillData: MagicPillType = {
72
- mode: "navbar",
73
- navbar: {
74
- navItems: [
75
- {
76
- icon: "arrow",
77
- label: "mp-test",
78
- link: "/mp-test"
79
- },
80
- {
81
- icon: "cross",
82
- label: "demo",
83
- link: "/demo"
84
- }
85
- ]
86
- }
87
- };
88
-
89
- interface MagicPillContextType {
90
- pillData: MagicPillType;
91
- setPillData: (data: MagicPillType) => void;
92
- // Direct data manipulation methods
93
- updateMode: (mode: Mode) => void;
94
- updateNotificationIcon: (icon: NotificationIcon) => void;
95
- updateNotificationMessage: (message: string) => void;
96
- updateCTAIcon: (icon: CTAIcon) => void;
97
- updateCTALabel: (label: string) => void;
98
- updateCTALink: (link: string) => void;
99
- updateInfoTitle: (title: string) => void;
100
- updateInfoContent: (content: string) => void;
101
- updateInfoCloseLabel: (closeLabel: string) => void;
102
- updateNavItemLabel: (label: string, index: number) => void;
103
- updateNavItemLink: (link: string, index: number) => void;
104
- updateNavItemIcon: (icon: CTAIcon, index: number) => void;
105
- addNavItem: (navItem: MagicPillNavbarItem) => void;
106
- 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;
107
92
  }
93
+ ```
108
94
 
109
- const MagicPillContext = createContext<MagicPillContextType>({
110
- pillData: defaultPillData,
111
- setPillData: () => {},
112
- updateMode: () => {},
113
- updateNotificationIcon: () => {},
114
- updateNotificationMessage: () => {},
115
- updateCTAIcon: () => {},
116
- updateCTALabel: () => {},
117
- updateCTALink: () => {},
118
- updateInfoTitle: () => {},
119
- updateInfoContent: () => {},
120
- updateInfoCloseLabel: () => {},
121
- updateNavItemLabel: () => {},
122
- updateNavItemLink: () => {},
123
- updateNavItemIcon: () => {},
124
- addNavItem: () => {},
125
- 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,
126
105
  });
106
+ ```
127
107
 
128
- export const useMagicPill = () => useContext(MagicPillContext);
129
-
130
- export const MagicPillProvider = ({
131
- children
132
- }: {
133
- children: React.ReactNode
134
- }) => {
135
- const [pillData, setPillData] = useState<MagicPillType>(defaultPillData);
136
-
137
- // Create wrapper functions that use the handlers with the local setPillData
138
- const contextValue: MagicPillContextType = {
139
- pillData,
140
- setPillData,
141
- updateMode: (mode: Mode) => updateMode(mode, setPillData),
142
- updateNotificationIcon: (icon: NotificationIcon) => updateNotificationIcon(icon, setPillData),
143
- updateNotificationMessage: (message: string) => updateNotificationMessage(message, setPillData),
144
- updateCTAIcon: (icon: CTAIcon) => updateCTAIcon(icon, setPillData),
145
- updateCTALabel: (label: string) => updateCTALabel(label, setPillData),
146
- updateCTALink: (link: string) => updateCTALink(link, setPillData),
147
- updateInfoTitle: (title: string) => updateInfoTitle(title, setPillData),
148
- updateInfoContent: (content: string) => updateInfoContent(content, setPillData),
149
- updateInfoCloseLabel: (closeLabel: string) => updateInfoCloseLabel(closeLabel, setPillData),
150
- updateNavItemLabel: (label: string, index: number) => updateNavItemLabel(label, index, setPillData),
151
- updateNavItemLink: (link: string, index: number) => updateNavItemLink(link, index, setPillData),
152
- updateNavItemIcon: (icon: CTAIcon, index: number) => updateNavItemIcon(icon, index, setPillData),
153
- addNavItem: (navItem: MagicPillNavbarItem) => addNavItem(navItem, setPillData),
154
- deleteNavItem: (index: number) => deleteNavItem(index, setPillData),
155
- };
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
+ ```
156
134
 
157
- return (
158
- <MagicPillContext.Provider value={contextValue}>
159
- {children}
160
- </MagicPillContext.Provider>
161
- );
162
- };
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
+ });
163
168
  ```
164
169
 
165
- 2. Wrap your app with the provider (in `app/layout.tsx`):
166
- ```typescript
167
- import "magic-pill/dist/magicpill.css";
168
- import { MagicPillProvider } from "./contexts/magicPillContext";
169
- import { MagicPillInitializer } from "./contexts/magicPillInitializer";
170
+ ## The host: `<MagicPill>`
171
+ `<MagicPill>` is a pill plus its queue. It takes every [`<Pill>` prop](#the-primitive) except `presence`, and adds:
170
172
 
171
- export default function RootLayout({ children }) {
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). |
172
183
 
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.
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() {
173
201
  return (
174
- <html lang="en">
175
- <body>
176
- <MagicPillProvider>
177
- {children}
178
- <MagicPillInitializer />
179
- </MagicPillProvider>
180
- </body>
181
- </html>
202
+ <MagicPill linkComponent={Link}>
203
+ <PillNavbar items={items} pathname={usePathname()} linkComponent={Link} />
204
+ </MagicPill>
182
205
  );
183
206
  }
184
207
  ```
185
208
 
186
- 3. Create an initializer file for Magic Pill (e.g., in `app/contexts/magicPillInitializer.tsx`):
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:
187
215
  ```tsx
188
- "use client"
189
- import { MagicPill } from "magic-pill";
190
- import { useMagicPill } from "./magicPillContext";
216
+ import { forwardRef, type AnchorHTMLAttributes } from "react";
217
+ import { Link, useLocation } from "react-router";
218
+ import type { LinkComponent } from "magic-pill";
191
219
 
192
- export const MagicPillInitializer = () => {
193
- const { pillData } = useMagicPill();
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
+ );
194
225
 
195
- return (
196
- <MagicPill pillData={pillData}/>
197
- )
198
- };
226
+ // <PillNavbar items={items} pathname={useLocation().pathname} linkComponent={RouterLink} />
199
227
  ```
200
- > **🎉 | At this point, if you launch you app, Magic Pill should appear in your view**
201
228
 
202
- 4. Use Magic Pill anywhere in your app (e.g., in `app/demo/page.tsx`):
203
- ```typescript
204
- "use client"
205
- import { useEffect } from "react";
206
- import { useMagicPill } from "../contexts/magicPillContext";
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
+ ```
207
241
 
208
- export default function MPTest() {
209
- const { setPillData } = useMagicPill();
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.
210
244
 
211
- useEffect(() => {
212
- setPillData({ mode: "notification", notification: { icon: "info", message: "Hello, world!" } });
213
- }, []);
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>
256
+ ```
214
257
 
215
- return (
216
- <h1>Magic Pill Demo Page</h1>
217
- );
218
- }
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` |
265
+
266
+ Any other prop (`className`, `aria-label`, `ref`…) goes to the element.
267
+
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.
274
+
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>
219
284
  ```
220
- > **It really is as simple as that, to use Magic Pill, once the setup is done**
221
-
222
- A notification appears as a small pill, expands after 2.5 s, and hides itself 5 s later (it stays open while hovered or focused). Setting a notification with different content shows the pill again.
223
-
224
- ### Update Magic Pill's content granularly
225
- Magic Pill, right from the start, has been thought out to be as highly customizable as possible.
226
- To help you use it in the best way possible, a collection of handlers is part of the package.
227
-
228
- - `updateMode` - Change Magic Pill's mode between "notification" and "navbar"
229
- - `updateNotificationIcon` - Change the main notification icon
230
- - `updateNotificationMessage` - Change the main notification message
231
- - `updateCTAIcon` - Change the notification's CTA (Call To Action) icon
232
- - `updateCTALabel` - Change the notification's CTA (Call To Action) label
233
- - `updateCTALink` - Change the notification's CTA (Call To Action) redirection link
234
- - `updateInfoTitle` - Change the notification's expanded info title
235
- - `updateInfoContent` - Change the notification's expanded info main content
236
- - `updateInfoCloseLabel` - Change the notification's expanded info close button's label
237
- - `updateNavItemLabel` - Change a navbar item's label
238
- - `updateNavItemLink` - Change a navbar item's link
239
- - `updateNavItemIcon` - Change a navbar item's icon
240
- - `handleActiveNavItem` - Automatically working handler directly used by the navbar to update the active link
241
- - `addNavItem` - Add an item to the navbar
242
- - `deleteNavItem` - Delete an item from the navbar
243
-
244
- ### ⚠️ Security: `info.content` is raw HTML
245
- The notification's expanded info content (`notification.info.content`, or `updateInfoContent`) is rendered as **raw HTML**, without any sanitising, so that you can format it.
246
-
247
- **Never put user input or any other untrusted text in it** (form values, URL parameters, data from an API or a database that users can write to…). Doing so lets anyone inject scripts into your page (XSS).
248
- - Only pass HTML that you wrote yourself.
249
- - If you really need to display external text there, sanitise it first with a dedicated library such as [DOMPurify](https://github.com/cure53/DOMPurify).
250
-
251
- The message, the info title and the labels are rendered as plain text, so they're safe. Links (`cta.link`, navbar `link`) go into an `href`: if they can come from users, only allow `http(s)` or relative URLs, because React 18 doesn't block `javascript:` URLs (React 19 does).
252
-
253
- A future major version will replace this HTML string with regular React content.
254
-
255
- ### Available Icons
256
- #### Notification Icons
257
- - `"info"` - Information icon
258
- - `"checkmark"` - Success/confirmation icon
259
- - `"questionmark"` - Help/question icon
260
- - `"coupon"` - Coupon/offer icon
261
- - `""` - No icon
262
-
263
- #### CTA (Call to Action) Icons
264
- - `"arrow"` - Arrow icon
265
- - `"box"` - Box icon
266
- - `"checkmark"` - Checkmark icon
267
- - `"cross"` - Cross/close icon
268
- - `"info"` - Information icon
269
- - `"mail"` - Mail/email icon
270
- - `"plus"` - Plus/add icon
271
- - `"quotation"` - Quote/speech icon
272
- - `"tel"` - Phone/telephone icon
273
- - `"undo"` - Undo/back icon
274
- - `""` - No icon
275
-
276
- ### Accessibility
277
- - Notifications are announced by screen readers (the pill is a polite live region).
278
- - The auto-hide pauses while the pill is hovered or holds keyboard focus.
279
- - With `prefers-reduced-motion: reduce`, the animations become short fades.
280
- - The info toggle exposes `aria-expanded` and `aria-controls`.
281
-
282
- ### Customization
283
- 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".
284
285
 
285
- ```css
286
- /* Font import */
287
- @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:
288
288
 
289
- /* CSS variables */
290
- :root {
291
- --mp__themeDark: #141414;
292
- --mp__themeLight: #F9F9F9;
293
- --mp__font-text: "Overlock", sans-serif;
294
- --mp__font-accent: "Lexend", sans-serif;
295
- --mp__normal: normal;
296
- --mp__italic: italic;
297
- --mp__medium: 400;
298
- --mp__bold: 700;
299
- --mp__black: 900;
300
- --mp__success: #3F7253;
301
- --mp__danger: #FC5D6A;
302
- --mp__textSize: 19.4px;
303
- --mp__titleSize: 31.42px;
304
- }
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
+ });
305
305
  ```
306
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
+
307
359
  ## Build your own
308
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.
309
361
 
@@ -339,16 +391,16 @@ npm link magic-pill
339
391
  ```
340
392
 
341
393
  ## Troubleshooting / Contact
342
- Magic Pill is still under development, you'll certainly encounter issues with it.
343
- You can send me emails anytime at [theveneaucedricpro@gmail.com](mailto:theveneaucedricpro@gmail.com), I'll try my best to help you out.
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.
344
396
 
345
397
  ## License
346
398
  Magic Pill is distributed under the [MIT License](https://www.tldrlegal.com/license/mit-license).
347
399
 
348
400
  ## What's next?
349
- | TODO | DOING |
401
+ | Coming next | Done in 9.0 |
350
402
  |-----------|-----------|
351
- | Support of custom svg icons | Animation fixes |
352
- | Transition between two modes | Responsive version + Proportions rework |
353
- | Implementation of function triggers on CTAs | Full documentation |
354
- | | Proper testing |
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 |