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.
Files changed (190) hide show
  1. package/CHANGELOG.md +120 -31
  2. package/MIGRATING.md +224 -0
  3. package/README.md +322 -252
  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 -0
  139. package/dist/index.d.ts +25 -5
  140. package/dist/index.js +1 -2
  141. package/dist/index.mjs +1 -0
  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 +37 -24
  164. package/dist/MagicPill.d.ts +0 -8
  165. package/dist/Navbar/Navbar.d.ts +0 -9
  166. package/dist/Notification/Notification.d.ts +0 -9
  167. package/dist/defaultPillData.d.ts +0 -2
  168. package/dist/icons/arrow_label.d.ts +0 -3
  169. package/dist/icons/box_label.d.ts +0 -3
  170. package/dist/icons/checkmark.d.ts +0 -3
  171. package/dist/icons/checkmark_label.d.ts +0 -3
  172. package/dist/icons/coupon.d.ts +0 -3
  173. package/dist/icons/cross_label.d.ts +0 -3
  174. package/dist/icons/info.d.ts +0 -3
  175. package/dist/icons/mail_label.d.ts +0 -3
  176. package/dist/icons/plus_label.d.ts +0 -3
  177. package/dist/icons/questionmark.d.ts +0 -3
  178. package/dist/icons/quotation_label.d.ts +0 -3
  179. package/dist/icons/tel_label.d.ts +0 -3
  180. package/dist/icons/undo_label.d.ts +0 -3
  181. package/dist/index.esm.js +0 -2
  182. package/dist/index.esm.js.map +0 -1
  183. package/dist/index.js.map +0 -1
  184. package/dist/magicpill.css +0 -267
  185. package/dist/types/index.d.ts +0 -3
  186. package/dist/types/magicPill.d.ts +0 -50
  187. package/dist/types/navbar.d.ts +0 -27
  188. package/dist/types/notification.d.ts +0 -140
  189. package/dist/utils/handlers.d.ts +0 -19
  190. package/dist/utils/icons.d.ts +0 -18
package/CHANGELOG.md CHANGED
@@ -1,6 +1,96 @@
1
1
  # Changelog
2
2
 
3
- ## [8.0.1] - 2024-03-21
3
+ ## [Unreleased]
4
+ Work towards 9.0.0, the first release with a stable API. It's a breaking release: see [MIGRATING.md](./MIGRATING.md) to move from 8.x.
5
+
6
+ ### Added
7
+ - The pill primitive: `Pill` with its parts `PillIcon`, `PillDivider`, `PillMessage`, `PillActions`, `PillAction`, `PillPanel` and `PillPanelTrigger`, plus the `usePill()` hook to write your own templates
8
+ - Presence levels (`hidden`, `rest`, `compact`, `expanded`, `panel`), controlled or not
9
+ - Placements: `inline`, fixed at an edge or corner, or `overlay` (a native modal `<dialog>`)
10
+ - Horizontal or vertical orientation, and `neutral`, `success`, `danger` or custom variants
11
+ - Stateless parts and `PillAction` can be rendered by React Server Components without becoming client code
12
+ - Link actions take a `linkComponent` (e.g. Next's `Link`) and only render relative, `http(s):`, `mailto:` and `tel:` URLs. Any other scheme, such as `javascript:`, renders no link
13
+ - Templates built from those parts:
14
+ - `PillNotification`: icon, message, an action (`onClick` or `href`) and an optional expandable panel. Every content is a React node, so nothing is parsed as HTML any more
15
+ - `PillNavbar`: a `<nav>` of icon links for any router (`pathname`, `linkComponent`). Items match whole path segments, the longest match wins, and the active link gets `aria-current="page"`
16
+ - `<MagicPill>` and `pill(name)`: mount the host once, then call `pill().notify({...})` from anywhere, including outside React. This replaces the 8.x Context, Provider and Initializer (about 135 lines of user code)
17
+ - Notifications queue first in, first out, take the pill over, then hand it back to the host's **base layer** (its children, e.g. a `PillNavbar`), so navbar and notifications are no longer exclusive
18
+ - `update(id, patch)`, `dismiss(id?)`, `clear()`, and `notify()` with an existing `id` to update in place
19
+ - `duration` per notification or on the host (`Infinity` keeps it). The countdown pauses on hover, keyboard focus, an open panel and a hidden browser tab
20
+ - Action clicks dismiss the notification unless the handler calls `event.preventDefault()`; `onDismiss(id, reason)` reports `timeout`, `action`, `dismissed` or `cleared`
21
+ - `render` for your own template, which keeps the queue, timing and animation
22
+ - Several named hosts per page (`<MagicPill name="sidebar">`), and `idle="rest"` for a discreet resting circle
23
+ - Shape changes: the pill collapses to a circle, swaps its content there and grows back; with reduced motion, it fades instead
24
+ - Announcements go through a separate live region, so a hidden pill can leave the accessibility tree
25
+ - On the server, `pill()` does nothing (it warns in development), so requests never share notifications
26
+ - `usePillQueue(name)`: the queue as a hook, to build your own host
27
+ - Twelve icons as components (`ArrowIcon`, `BoxIcon`, `CheckIcon`, `CloseIcon`, `CouponIcon`, `DocumentIcon`, `HelpIcon`, `InfoIcon`, `MailIcon`, `PhoneIcon`, `PlusIcon`, `UndoIcon`): drawn in `currentColor`, decorative by default
28
+ - A new stylesheet, `magic-pill/styles.css`:
29
+ - every rule sits in a `magic-pill` cascade layer and targets `data-mp` attributes, so your own CSS overrides it without `!important` and no class names collide;
30
+ - it loads no fonts (it uses your page's fonts unless you set `--mp-font-text`/`--mp-font-accent`);
31
+ - it's sized in `rem`, fits phone screens and safe areas, and supports reduced motion and forced colours
32
+
33
+ - A migration guide from 8.x, [MIGRATING.md](./MIGRATING.md), shipped in the package
34
+ - The README is rewritten for v9: quick start, notifications, the host and its base layer, the primitive, React Server Components, styling and tokens, accessibility and security
35
+
36
+ ### Removed
37
+ - The 8.x API: the `pillData` prop and `mode`, the types (`MagicPillType`, `Mode`, `NotificationIcon`, `CTAIcon`, `MagicPillNotification*`, `MagicPillNavbar*`), the 15 handlers (`updateMode` … `handleActiveNavItem`), `Icons`, `CTAIcons`, `getIconComponent` and `defaultPillData`
38
+ - The 8.x stylesheet: its `.magicPill`/`.CTA`/… classes, the `--mp__*` variables and the Google Fonts `@import`. The `magic-pill/magicpill.css` and `magic-pill/dist/magicpill.css` paths now serve the new stylesheet
39
+ - Raw HTML content: `info.content` was injected with `dangerouslySetInnerHTML`. Contents are React nodes now
40
+
41
+ ## [8.1.0] - 2026-11-19
42
+ A maintenance release: bug fixes, accessibility, a modern build and an up-to-date toolchain. Imports, props and the documented stylesheet path are unchanged.
43
+
44
+ ### Added
45
+ - Accessibility: screen readers announce notifications (the pill is a polite live region, with `role="status"` in notification mode)
46
+ - Accessibility: the auto-hide also pauses while the pill holds keyboard focus, not only on hover
47
+ - Accessibility: with `prefers-reduced-motion: reduce`, the entry and exit animations become short fades without the overshoot, and size transitions are instant
48
+ - Accessibility: the info toggle exposes `aria-expanded` and `aria-controls`
49
+ - An `exports` map: `magic-pill`, the stylesheet at the existing `magic-pill/dist/magicpill.css` and at `magic-pill/magicpill.css`, and `magic-pill/package.json`
50
+ - `"sideEffects": ["*.css"]`, so bundlers can tree-shake the JavaScript while keeping the stylesheet
51
+ - README: requirements, an accessibility section, and a note on the Google Fonts `@import`, which Next.js 16's default bundler (Turbopack) drops
52
+
53
+ ### Changed
54
+ - `react` and `react-dom` (>= 18) are now the only peer dependencies. `next` and `typescript` were never needed at runtime, and listing them caused peer warnings in plain React apps
55
+ - The ESM build is now `dist/index.mjs`, with its own typings (`dist/index.d.mts`), instead of `dist/index.esm.js`, so Node.js never mistakes it for CommonJS. `module` points to it, and the CommonJS build stays at `dist/index.js`
56
+ - Because of the `exports` map, files inside the package can no longer be imported directly (e.g. `magic-pill/dist/index.js`), apart from the stylesheet
57
+
58
+ ### Fixed
59
+ - A notification shows up again when its content changes (message, icon, CTA or info panel). Before, only a change of `mode` replayed it, so every notification after the first one stayed hidden
60
+ - The pill no longer hides itself while hovered when the pointer arrived during the entry animation, or was already on the navbar when a notification replaced it
61
+ - Switching from a notification to the navbar during the entry animation no longer makes the navbar hide itself 7.5 s later, and no timer keeps running after `MagicPill` unmounts
62
+ - `MagicPill` can be rendered directly from a React Server Component (Next.js App Router): each component keeps its `"use client"` directive, which the old build stripped
63
+ - The missing `info` CTA icon: it was a valid `CTAIcon` value but rendered nothing
64
+ - Icon components (`Icons`, `CTAIcons`) now accept SVG props (`className`, `aria-*`, `width`…) and pass them to the `<svg>`
65
+ - The shipped `dist/magicpill.css` is always the real stylesheet, copied as-is from the source
66
+ - README: the setup guide's code samples (wrong import path, a check that could never fire, an unused element), the CDN snippets that couldn't work (there's no UMD build), the contact address and several typos
67
+
68
+ ### Security
69
+ - Releases are built and uploaded by GitHub Actions with npm Trusted Publishing, with a provenance attestation, instead of a long-lived access token. They're staged on npm and only go live once a maintainer approves them with 2FA (staged publishing)
70
+ - The development dependency tree has no known advisories any more (`npm audit`: 16 advisories, including 1 critical, down to 0), and CI fails on new high or critical ones
71
+ - README: a warning that `info.content` is rendered as raw HTML and must never contain user input, and that links from users should be restricted to `http(s)` or relative URLs
72
+
73
+ ### Maintenance
74
+ - Build: tsdown replaces Rollup 2 and Babel, with TypeScript 6.0 and the automatic JSX runtime
75
+ - Tests: a Vitest test suite, run in CI and before every publish
76
+ - CI: typecheck, test and build on Node 22, 24 and 26 for every pull request. The publish workflow runs on Node 26, builds once, typechecks and tests first, and has a dry-run trigger. GitHub Actions are pinned to commit SHAs
77
+ - Dependabot version updates for the library, the demo and the GitHub Actions, and an `.nvmrc` (Node 26) for contributors
78
+ - Demo app tooling upgraded to Next.js 16, React 19 and ESLint 9. It still showcases v7
79
+ - Housekeeping: changelog dates fixed and entries backfilled, the demo app no longer ignored by the root `.gitignore`, a typo in the publish workflow's name, unused repository secrets removed, and the unused `cdn` field removed from `package.json`
80
+
81
+ ## [8.0.3] - 2025-06-28
82
+ ### Changed
83
+ - Added prefix to Magic Pill's CSS variables to prevent conflicts with generic variable names
84
+ - Updated `README.md` with fixes to file setup instructions
85
+
86
+ ### Fixed
87
+ - Changed `handleActiveNavItem` handler behavior to be less restrictive - anchors now count as active navbar items
88
+
89
+ ## [8.0.2] - 2025-06-26
90
+ ### Fixed
91
+ - Fixed type export issue
92
+
93
+ ## [8.0.1] - 2025-06-26
4
94
  ### Added
5
95
  - Added `*.tsbuildinfo` to `.gitignore`
6
96
 
@@ -31,7 +121,6 @@
31
121
  - Improved code organization with feature-based directory structure
32
122
  - Enhanced type definitions for better developer experience
33
123
  - Updated documentation to reflect TypeScript support
34
- - Improved error messages with type-aware validation
35
124
  - Refactored component props for better type inference
36
125
  - Updated all examples in documentation to use TypeScript
37
126
 
@@ -48,8 +137,8 @@
48
137
  - Changed some prop types to be more strict
49
138
  - Removed support for untyped icon strings
50
139
 
51
- ## [7.1.3]
52
- ### Updated
140
+ ## [7.1.3] - 2024-11-17
141
+ ### Changed
53
142
  - Updated the "Disclaimer" and "What's next ?" sections of the README file
54
143
 
55
144
  ### Added
@@ -59,78 +148,78 @@
59
148
  - Fixed a layout shift when going from collapsed info to expanded info
60
149
  - Added a min-width to Magic Pill when info is expanded to keep it looking good
61
150
 
62
- ## [7.1.1] -> [7.1.2]
151
+ ## [7.1.1] -> [7.1.2] - 2024-11-17
63
152
  ### Fixed
64
153
  - Fixed the default style of CTA with a link. It no longer is underlined and blue
65
154
 
66
- ## [7.1.0]
155
+ ## [7.1.0] - 2024-11-17
67
156
  ### Fixed
68
- - Reworked the way condiotionned CTA and Button rendering work
157
+ - Reworked the way the conditional CTA and button rendering works
69
158
 
70
- ## [7.0.1]
159
+ ## [7.0.1] - 2024-11-16
71
160
  ### Fixed
72
- - Removed efault.props as it will not longer be supported in future versions of React
161
+ - Removed defaultProps, as it will no longer be supported in future versions of React
73
162
 
74
- ## [7.0.8]
163
+ ## [7.0.0] - 2024-11-16
75
164
  ### Fixed
76
165
  - Fixed version compatibility issues with NextJS / React
77
166
 
78
- ## [6.1.28]
167
+ ## [6.1.28] - 2024-11-16
79
168
  ### Fixed
80
169
  - Fixed a wrong display condition for info panel
81
170
 
82
- ## [6.1.27]
171
+ ## [6.1.27] - 2024-11-16
83
172
  ### Fixed
84
173
  - Fixed the issue with stuttering exit animation
85
174
 
86
- ## [6.1.26]
175
+ ## [6.1.26] - 2024-11-15
87
176
  ### Fixed
88
177
  - Backtracked to V6.1.20 after various fails. V6.1.20 was the closest to actually being usable
89
178
 
90
- ## [6.1.22] -> [6.1.25]
179
+ ## [6.1.22] -> [6.1.25] - 2024-11-15
91
180
  ### Fixed
92
181
  - Refined a bit more the logic regarding classes applied to Magic Pill upon animations to prevent buggy visuals (still in progress)
93
182
 
94
- ## [6.1.21]
183
+ ## [6.1.21] - 2024-11-15
95
184
  ### Fixed
96
185
  - Refined a bit more the logic regarding entry and exit animations to prevent buggy visuals (still in progress)
97
186
 
98
- ## [6.1.20]
187
+ ## [6.1.20] - 2024-11-15
99
188
  ### Fixed
100
189
  - Implemented a more refined logic to prevent animation on hover and resume it on mouse leave (still in progress)
101
190
  - Simplified the info div animation and removed the ::after pseudo-element
102
191
  - Added a new animation for the CTA : when the info div is expanded, the button moves to the center of Magic Pill
103
192
 
104
- ## [6.1.19]
193
+ ## [6.1.19] - 2024-11-15
105
194
  ### Fixed
106
195
  - Added the import of useRef, which I forgot in the previous release
107
196
 
108
- ## [6.1.18]
197
+ ## [6.1.18] - 2024-11-15
109
198
  ### Fixed
110
199
  - Reworked the logic regarding animation pausing on hover (still a work in progress)
111
200
 
112
- ## [6.1.17]
201
+ ## [6.1.17] - 2024-11-15
113
202
  ### Added
114
203
  - Added logic to prevent exit animation when the mouse enters Magic Pill. Once the mouse leaves, a five seconds timer starts, if the mouse hasn't entered, it triggers the exit animation, if it enters again, the timer is reset to five seconds.
115
204
  - Added a LICENSE file
116
205
  - Added a NOTICE file
117
206
  - LICENSE and NOTICE files will be added to the package
118
207
 
119
- ### Updated
208
+ ### Changed
120
209
  - README file
121
210
 
122
- ## [6.1.16]
211
+ ## [6.1.16] - 2024-11-15
123
212
  ### Fixed
124
213
  - Fixed various display issues
125
214
  - Improved layout breaks
126
215
  - Started fixing info pop-up display issues
127
216
  - Fixed z-index issues
128
217
 
129
- ## [6.1.15]
218
+ ## [6.1.15] - 2024-11-15
130
219
  ### Fixed
131
220
  - Fixed an issue regarding the useEffect which could create errors leading to crashes because of bad syntax. It's now fixed and the component should render correctly without causing crashes
132
221
 
133
- ## [6.1.14]
222
+ ## [6.1.14] - 2024-11-15
134
223
  ### Added
135
224
  - Added a default props, so that Magic Pill displays a friendly default message if there is an issue with the given props
136
225
 
@@ -141,27 +230,27 @@
141
230
  - Fixed some specificity issues in CSS by wrapping Magic Pill inside html and body to raise its style priority
142
231
  - Changed the name of the "entry" keyframes to "magicPillEntry" to avoid any issue, considering "entry" is a popular term for keyframes
143
232
 
144
- ## [6.1.13]
233
+ ## [6.1.13] - 2024-11-15
145
234
  ### Fixed
146
- - Fixed the definition of CSS vairables which conflicted with the project's global stylesheet, now everything only extends to the scope of the Magic Pill
235
+ - Fixed the definition of CSS variables which conflicted with the project's global stylesheet, now everything only extends to the scope of the Magic Pill
147
236
 
148
- ## [6.1.12]
237
+ ## [6.1.12] - 2024-11-15
149
238
  ### Fixed
150
239
  - Fixed a wrong import line in the README file
151
240
 
152
241
  ### Removed
153
- - Removed prefered theme based light/dark mode as it was conflincting with the rest of the project's stylesheet
242
+ - Removed preferred theme based light/dark mode as it was conflicting with the rest of the project's stylesheet
154
243
 
155
- ## [6.1.11]
244
+ ## [6.1.11] - 2024-11-15
156
245
  ### Added
157
- - Added prefered theme based light/dark mode
246
+ - Added preferred theme based light/dark mode
158
247
 
159
248
  ### Fixed
160
249
  - Fixed a display issue regarding CTA labels
161
250
 
162
- ## [6.1.10]
251
+ ## [6.1.10] - 2024-11-15
163
252
  ### Added
164
253
  - Added the changelog file to the package
165
254
 
166
255
  ### Fixed
167
- - Fixed issues with useStates and reworked the timing of the exit of Magic Pill
256
+ - Fixed issues with useStates and reworked the timing of the exit of Magic Pill
package/MIGRATING.md ADDED
@@ -0,0 +1,224 @@
1
+ # Migrating from Magic Pill 8 to 9
2
+
3
+ Magic Pill 9 is the first version with a stable, documented API. It's a breaking release, but most apps get **shorter**: the Context, Provider and Initializer that 8.x asked you to write (about 135 lines) go away.
4
+
5
+ ## Why it changed
6
+ In 8.x, your app owned the pill's state. You kept a `pillData` object in your own Context and changed it with 14 setters. The pill showed either a notification or a navbar, never both, and content was a fixed list of icon names, strings and raw HTML.
7
+
8
+ In 9, the package owns its state, and the API has three layers:
9
+ 1. **A primitive**, `<Pill>`, with parts (`PillIcon`, `PillMessage`, `PillAction`…) that take any React content.
10
+ 2. **Templates** made of those parts: `PillNotification` and `PillNavbar`.
11
+ 3. **A host and a controller**: mount `<MagicPill />` once, then call `pill().notify(...)` from anywhere. Notifications queue on top of a **base layer** (your navbar) instead of replacing it.
12
+
13
+ ## 1. Replace your Context with `<MagicPill />`
14
+ **Delete** the files the 8.x README had you create (`magicPillContext.tsx`, `magicPillInitializer.tsx`), the `<MagicPillProvider>` wrapper, and the `useMagicPill()` calls. Then mount the host once:
15
+
16
+ ```tsx
17
+ // app/layout.tsx
18
+ import "magic-pill/styles.css";
19
+ import { MagicPill } from "magic-pill";
20
+
21
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
22
+ return (
23
+ <html lang="en">
24
+ <body>
25
+ {children}
26
+ <MagicPill />
27
+ </body>
28
+ </html>
29
+ );
30
+ }
31
+ ```
32
+
33
+ `MagicPill` keeps its name, but it no longer takes `pillData`. TypeScript flags every old call site.
34
+
35
+ ## 2. Notifications
36
+ Where you used to set the notification mode, call `pill().notify()`:
37
+
38
+ ```tsx
39
+ // 8.x
40
+ setPillData({
41
+ mode: "notification",
42
+ notification: {
43
+ icon: "checkmark",
44
+ message: "Order confirmed",
45
+ cta: { icon: "arrow", label: "Track", link: "/orders" },
46
+ },
47
+ });
48
+
49
+ // 9
50
+ import { pill, CheckIcon, ArrowIcon } from "magic-pill";
51
+
52
+ pill().notify({
53
+ icon: <CheckIcon />,
54
+ message: "Order confirmed",
55
+ action: { icon: <ArrowIcon />, label: "Track", href: "/orders" },
56
+ });
57
+ ```
58
+
59
+ | 8.x | 9 |
60
+ |---|---|
61
+ | `notification.icon: "checkmark"` | `icon: <CheckIcon />` (any React content) |
62
+ | `notification.message: string` | `message: ReactNode` |
63
+ | `cta: { icon, label, link }` | `action: { icon, label, href }` |
64
+ | (no callbacks) | `action: { icon, label, onClick }` |
65
+ | `cta` + `info: { title, content, closeLabel }` | `panel: { trigger: { icon, label }, title, content, closeLabel }` |
66
+ | `info.content` (an HTML string) | `panel.content` (React content) |
67
+ | `updateNotificationMessage(…)`, `updateCTALabel(…)`… | `pill().update(id, { message: … })`, or `notify` again with the same `id` |
68
+ | a fixed 5 s | `duration` per notification, or on `<MagicPill duration>` |
69
+
70
+ **The expandable info panel:**
71
+ ```tsx
72
+ // 8.x
73
+ notification: {
74
+ icon: "info",
75
+ message: "Discover the powers Magic Pill gives you!",
76
+ cta: { icon: "plus", label: "Learn more" },
77
+ info: { title: "Discover", content: "<p>Magic Pill gives you <b>powers</b>.</p>", closeLabel: "Close" },
78
+ }
79
+
80
+ // 9
81
+ pill().notify({
82
+ icon: <InfoIcon />,
83
+ message: "Discover the powers Magic Pill gives you!",
84
+ panel: {
85
+ title: "Discover",
86
+ content: <p>Magic Pill gives you <b>powers</b>.</p>,
87
+ // trigger and closeLabel default to "+ Learn more" and "Close"
88
+ },
89
+ });
90
+ ```
91
+
92
+ > **HTML strings are gone.** If you have HTML you **trust** (never anything from your users), render it yourself: `content: <div dangerouslySetInnerHTML={{ __html: trustedHtml }} />`.
93
+
94
+ **What behaves differently:**
95
+ - **Every notification shows.** In 8.x, a notification only animated in again when its content changed. In 9, each `notify()` call is queued and shown in turn.
96
+ - **The animation is shorter and shape-based:** the pill pops in as a circle, then grows (about 0.75 s, against 2.5 s in 8.x). The 5 s countdown starts once the pill is fully shown.
97
+ - **Actions dismiss** the notification when clicked. Call `event.preventDefault()` in `onClick` to keep it open.
98
+ - **Pauses:** as in 8.1, hover and keyboard focus pause the countdown. An open panel and a hidden browser tab now pause it too.
99
+
100
+ ## 3. Navbar
101
+ The navbar is now the host's **base layer**: it stays mounted, notifications take the pill over, and then it comes back. Switching `mode` doesn't clear your items any more.
102
+
103
+ ```tsx
104
+ // 8.x
105
+ setPillData({
106
+ mode: "navbar",
107
+ navbar: { navItems: [{ icon: "arrow", label: "Home", link: "/" }, { icon: "mail", label: "Contact", link: "/contact" }] },
108
+ });
109
+
110
+ // 9: a client component, rendered once (e.g. from your layout)
111
+ "use client";
112
+ import Link from "next/link";
113
+ import { usePathname } from "next/navigation";
114
+ import { MagicPill, PillNavbar, ArrowIcon, MailIcon } from "magic-pill";
115
+
116
+ const items = [
117
+ { icon: <ArrowIcon />, label: "Home", href: "/" },
118
+ { icon: <MailIcon />, label: "Contact", href: "/contact" },
119
+ ];
120
+
121
+ export function AppPill() {
122
+ return (
123
+ <MagicPill linkComponent={Link}>
124
+ <PillNavbar items={items} pathname={usePathname()} linkComponent={Link} />
125
+ </MagicPill>
126
+ );
127
+ }
128
+ ```
129
+
130
+ | 8.x | 9 |
131
+ |---|---|
132
+ | `navItems: [{ icon, label?, link }]` | `items: [{ icon, label, href, match? }]`. **`label` is now required**: it's the link's accessible name. |
133
+ | `addNavItem`, `deleteNavItem`, `updateNavItem*` | Change the `items` array (your own React state) |
134
+ | `handleActiveNavItem` + `window.location`, matched by label | `pathname` prop + `match`, matched by `href` |
135
+ | Plain `<a>` (full page reloads in Next.js) | `linkComponent={Link}` |
136
+
137
+ The active item also changes: an item is active on its own path and below, on whole segments. In 8.x, a `/` item was active everywhere, and `/blog` matched `/blogroll`.
138
+
139
+ ## 4. Icons
140
+ Icons are components now, and any React content works as an icon.
141
+
142
+ | 8.x name | 9 component |
143
+ |---|---|
144
+ | `info` | `InfoIcon` |
145
+ | `checkmark` | `CheckIcon` |
146
+ | `questionmark` | `HelpIcon` |
147
+ | `coupon` | `CouponIcon` |
148
+ | `arrow` | `ArrowIcon` |
149
+ | `box` | `BoxIcon` |
150
+ | `cross` | `CloseIcon` |
151
+ | `mail` | `MailIcon` |
152
+ | `plus` | `PlusIcon` |
153
+ | `quotation` | `DocumentIcon` |
154
+ | `tel` | `PhoneIcon` |
155
+ | `undo` | `UndoIcon` |
156
+ | `""` (no icon) | leave `icon` out |
157
+
158
+ `Icons`, `CTAIcons` and `getIconComponent` are removed.
159
+
160
+ ## 5. Styling
161
+ **The stylesheet:** `import "magic-pill/styles.css"`. The 8.x paths (`magic-pill/magicpill.css`, `magic-pill/dist/magicpill.css`) still work and serve the new stylesheet.
162
+
163
+ **Fonts are no longer loaded for you.** 8.x imported Lexend and Overlock from Google Fonts. That sent your visitors' IP addresses to Google, and Turbopack dropped the import anyway. 9 uses your page's fonts. To keep the 8.x look, set the font tokens, e.g. with `next/font`:
164
+
165
+ ```tsx
166
+ import { Lexend, Overlock } from "next/font/google";
167
+
168
+ const overlock = Overlock({ subsets: ["latin"], style: "italic", weight: ["400", "700", "900"], variable: "--mp-font-text" });
169
+ const lexend = Lexend({ subsets: ["latin"], weight: "700", variable: "--mp-font-accent" });
170
+ // <html className={`${overlock.variable} ${lexend.variable}`}>
171
+ ```
172
+
173
+ **Tokens:**
174
+
175
+ | 8.x | 9 |
176
+ |---|---|
177
+ | `--mp__themeDark` | `--mp-surface` (the pill) and `--mp-on-action` (text on buttons) |
178
+ | `--mp__themeLight` | `--mp-on-surface` (text on the pill) and `--mp-action` (buttons) |
179
+ | `--mp__font-text` / `--mp__font-accent` | `--mp-font-text` / `--mp-font-accent` (default: `inherit`) |
180
+ | `--mp__success` | `--mp-success` |
181
+ | `--mp__danger` | `--mp-danger`. The default is now `#c2303e`: 8.x's `#fc5d6a` was too light for white text. |
182
+ | `--mp__textSize` / `--mp__titleSize` | `--mp-text-size` / `--mp-title-size` (fluid `rem` defaults instead of px) |
183
+ | `--mp__normal`, `--mp__italic`, `--mp__medium`, `--mp__bold`, `--mp__black` | Removed. Style the parts directly, e.g. `[data-mp="message"] { font-style: normal; }` |
184
+
185
+ 9 also adds spacing, size, radius, shadow, offset and duration tokens. See the README's [Styling](./README.md#styling) section.
186
+
187
+ **Selectors:** 8.x used class names under `html > body`, and overriding them took high specificity or `!important`. 9 uses `data-mp` attributes inside a cascade layer, so any rule of yours wins:
188
+
189
+ | 8.x | 9 |
190
+ |---|---|
191
+ | `.magicPill` | `[data-mp="pill"]` |
192
+ | `.magicPill.out` / `.entry` / `.active` | `[data-presence="hidden"]` / `"rest"` / `"compact"` (also `"expanded"`, `"panel"`) |
193
+ | `.message` | `[data-mp="message"]` |
194
+ | `.CTA` | `[data-mp="action"]` (its label: `[data-mp="label"]`) |
195
+ | `.CTA.active` (navbar) | `[data-mp="action"][aria-current="page"]` |
196
+ | `.info` / `.info .title` / `.info .content` | `[data-mp="panel"]` / `[data-mp="panel-title"]` / `[data-mp="panel-body"]` |
197
+ | `.navbar` | `[data-mp="navbar"]` |
198
+
199
+ **Responsive:** 8.x needed your own mobile CSS (the demo had some). 9 fits small screens by itself, so you can probably delete those overrides.
200
+
201
+ ## 6. Security
202
+ - **No raw HTML:** content isn't parsed as HTML any more (see the note in step 2).
203
+ - **Safe links:** links only render relative, `http(s):`, `mailto:` and `tel:` URLs. A `javascript:` URL now renders without a link (with a warning in development), even on React 18, which doesn't block it.
204
+
205
+ ## 7. Removed exports
206
+ `pillData`, `MagicPillType`, `Mode`, `NotificationIcon`, `CTAIcon`, `MagicPillNotification`, `MagicPillNotificationCTA`, `MagicPillNotificationInfo`, `MagicPillNavbar`, `MagicPillNavbarItem`, `updateMode`, `updateNotificationIcon`, `updateNotificationMessage`, `updateCTAIcon`, `updateCTALabel`, `updateCTALink`, `updateInfoTitle`, `updateInfoContent`, `updateInfoCloseLabel`, `updateNavItemLabel`, `updateNavItemLink`, `updateNavItemIcon`, `addNavItem`, `deleteNavItem`, `handleActiveNavItem`, `Icons`, `CTAIcons`, `getIconComponent`, `defaultPillData`.
207
+
208
+ ## Checklist
209
+ Search your code for leftovers:
210
+
211
+ ```bash
212
+ # 8.x API
213
+ grep -rnE "pillData|useMagicPill|MagicPillProvider|update(Mode|Notification|CTA|Info|NavItem)|(add|delete)NavItem|handleActiveNavItem|getIconComponent|CTAIcons|defaultPillData|MagicPillType|NotificationIcon|CTAIcon" src app
214
+
215
+ # 8.x styles
216
+ grep -rnE "\.magicPill|\.CTA|--mp__" --include="*.css" --include="*.scss" .
217
+ ```
218
+
219
+ Then check that:
220
+ - [ ] `<MagicPill />` is mounted once (per name), and `magic-pill/styles.css` is imported.
221
+ - [ ] Notifications go through `pill().notify()`, and the navbar is a `PillNavbar` inside `<MagicPill>`.
222
+ - [ ] Every nav item has a `label`.
223
+ - [ ] The fonts are set, if you want the Overlock + Lexend look.
224
+ - [ ] Custom CSS targets `data-mp` attributes and `--mp-*` tokens.