magic-pill 8.0.2 → 8.1.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 +82 -31
- package/README.md +69 -51
- package/dist/MagicPill.d.mts +6 -0
- package/dist/MagicPill.d.ts +5 -6
- package/dist/MagicPill.js +2 -0
- package/dist/MagicPill.js.map +1 -0
- package/dist/MagicPill.mjs +2 -0
- package/dist/MagicPill.mjs.map +1 -0
- package/dist/Navbar/Navbar.js +2 -0
- package/dist/Navbar/Navbar.js.map +1 -0
- package/dist/Navbar/Navbar.mjs +2 -0
- package/dist/Navbar/Navbar.mjs.map +1 -0
- package/dist/Notification/Notification.js +2 -0
- package/dist/Notification/Notification.js.map +1 -0
- package/dist/Notification/Notification.mjs +2 -0
- package/dist/Notification/Notification.mjs.map +1 -0
- package/dist/defaultPillData.d.mts +2 -0
- package/dist/defaultPillData.d.ts +3 -2
- package/dist/defaultPillData.js +7 -0
- package/dist/defaultPillData.js.map +1 -0
- package/dist/defaultPillData.mjs +7 -0
- package/dist/defaultPillData.mjs.map +1 -0
- package/dist/icons/arrow_label.js +2 -0
- package/dist/icons/arrow_label.js.map +1 -0
- package/dist/icons/arrow_label.mjs +2 -0
- package/dist/icons/arrow_label.mjs.map +1 -0
- package/dist/icons/box_label.js +2 -0
- package/dist/icons/box_label.js.map +1 -0
- package/dist/icons/box_label.mjs +2 -0
- package/dist/icons/box_label.mjs.map +1 -0
- package/dist/icons/checkmark.js +2 -0
- package/dist/icons/checkmark.js.map +1 -0
- package/dist/icons/checkmark.mjs +2 -0
- package/dist/icons/checkmark.mjs.map +1 -0
- package/dist/icons/checkmark_label.js +2 -0
- package/dist/icons/checkmark_label.js.map +1 -0
- package/dist/icons/checkmark_label.mjs +2 -0
- package/dist/icons/checkmark_label.mjs.map +1 -0
- package/dist/icons/coupon.js +2 -0
- package/dist/icons/coupon.js.map +1 -0
- package/dist/icons/coupon.mjs +2 -0
- package/dist/icons/coupon.mjs.map +1 -0
- package/dist/icons/cross_label.js +2 -0
- package/dist/icons/cross_label.js.map +1 -0
- package/dist/icons/cross_label.mjs +2 -0
- package/dist/icons/cross_label.mjs.map +1 -0
- package/dist/icons/info.js +2 -0
- package/dist/icons/info.js.map +1 -0
- package/dist/icons/info.mjs +2 -0
- package/dist/icons/info.mjs.map +1 -0
- package/dist/icons/info_label.js +2 -0
- package/dist/icons/info_label.js.map +1 -0
- package/dist/icons/info_label.mjs +2 -0
- package/dist/icons/info_label.mjs.map +1 -0
- package/dist/icons/mail_label.js +2 -0
- package/dist/icons/mail_label.js.map +1 -0
- package/dist/icons/mail_label.mjs +2 -0
- package/dist/icons/mail_label.mjs.map +1 -0
- package/dist/icons/plus_label.js +2 -0
- package/dist/icons/plus_label.js.map +1 -0
- package/dist/icons/plus_label.mjs +2 -0
- package/dist/icons/plus_label.mjs.map +1 -0
- package/dist/icons/questionmark.js +2 -0
- package/dist/icons/questionmark.js.map +1 -0
- package/dist/icons/questionmark.mjs +2 -0
- package/dist/icons/questionmark.mjs.map +1 -0
- package/dist/icons/quotation_label.js +2 -0
- package/dist/icons/quotation_label.js.map +1 -0
- package/dist/icons/quotation_label.mjs +2 -0
- package/dist/icons/quotation_label.mjs.map +1 -0
- package/dist/icons/tel_label.js +2 -0
- package/dist/icons/tel_label.js.map +1 -0
- package/dist/icons/tel_label.mjs +2 -0
- package/dist/icons/tel_label.mjs.map +1 -0
- package/dist/icons/undo_label.js +2 -0
- package/dist/icons/undo_label.js.map +1 -0
- package/dist/icons/undo_label.mjs +2 -0
- package/dist/icons/undo_label.mjs.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.js +1 -2
- package/dist/index.mjs +1 -0
- package/dist/magicpill.css +91 -43
- package/dist/types/index.d.ts +4 -3
- package/dist/types/magicPill.d.mts +50 -0
- package/dist/types/magicPill.d.ts +9 -9
- package/dist/types/navbar.d.mts +27 -0
- package/dist/types/navbar.d.ts +7 -6
- package/dist/types/notification.d.mts +140 -0
- package/dist/types/notification.d.ts +22 -21
- package/dist/utils/handlers.d.mts +20 -0
- package/dist/utils/handlers.d.ts +5 -3
- package/dist/utils/handlers.js +2 -0
- package/dist/utils/handlers.js.map +1 -0
- package/dist/utils/handlers.mjs +2 -0
- package/dist/utils/handlers.mjs.map +1 -0
- package/dist/utils/icons.d.mts +20 -0
- package/dist/utils/icons.d.ts +16 -14
- package/dist/utils/icons.js +2 -0
- package/dist/utils/icons.js.map +1 -0
- package/dist/utils/icons.mjs +2 -0
- package/dist/utils/icons.mjs.map +1 -0
- package/package.json +35 -24
- package/dist/Navbar/Navbar.d.ts +0 -9
- package/dist/Notification/Notification.d.ts +0 -9
- 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/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [8.0
|
|
3
|
+
## [8.1.0] - 2026-11-19
|
|
4
|
+
A maintenance release: bug fixes, accessibility, a modern build and an up-to-date toolchain. Imports, props and the documented stylesheet path are unchanged.
|
|
5
|
+
|
|
6
|
+
### Added
|
|
7
|
+
- Accessibility: screen readers announce notifications (the pill is a polite live region, with `role="status"` in notification mode)
|
|
8
|
+
- Accessibility: the auto-hide also pauses while the pill holds keyboard focus, not only on hover
|
|
9
|
+
- Accessibility: with `prefers-reduced-motion: reduce`, the entry and exit animations become short fades without the overshoot, and size transitions are instant
|
|
10
|
+
- Accessibility: the info toggle exposes `aria-expanded` and `aria-controls`
|
|
11
|
+
- 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`
|
|
12
|
+
- `"sideEffects": ["*.css"]`, so bundlers can tree-shake the JavaScript while keeping the stylesheet
|
|
13
|
+
- README: requirements, an accessibility section, and a note on the Google Fonts `@import`, which Next.js 16's default bundler (Turbopack) drops
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- `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
|
|
17
|
+
- 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`
|
|
18
|
+
- 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
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- 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
|
|
22
|
+
- 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
|
|
23
|
+
- 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
|
|
24
|
+
- `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
|
|
25
|
+
- The missing `info` CTA icon: it was a valid `CTAIcon` value but rendered nothing
|
|
26
|
+
- Icon components (`Icons`, `CTAIcons`) now accept SVG props (`className`, `aria-*`, `width`…) and pass them to the `<svg>`
|
|
27
|
+
- The shipped `dist/magicpill.css` is always the real stylesheet, copied as-is from the source
|
|
28
|
+
- 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
|
|
29
|
+
|
|
30
|
+
### Security
|
|
31
|
+
- 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)
|
|
32
|
+
- 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
|
|
33
|
+
- 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
|
|
34
|
+
|
|
35
|
+
### Maintenance
|
|
36
|
+
- Build: tsdown replaces Rollup 2 and Babel, with TypeScript 6.0 and the automatic JSX runtime
|
|
37
|
+
- Tests: a Vitest test suite, run in CI and before every publish
|
|
38
|
+
- 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
|
|
39
|
+
- Dependabot version updates for the library, the demo and the GitHub Actions, and an `.nvmrc` (Node 26) for contributors
|
|
40
|
+
- Demo app tooling upgraded to Next.js 16, React 19 and ESLint 9. It still showcases v7
|
|
41
|
+
- 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`
|
|
42
|
+
|
|
43
|
+
## [8.0.3] - 2025-06-28
|
|
44
|
+
### Changed
|
|
45
|
+
- Added prefix to Magic Pill's CSS variables to prevent conflicts with generic variable names
|
|
46
|
+
- Updated `README.md` with fixes to file setup instructions
|
|
47
|
+
|
|
48
|
+
### Fixed
|
|
49
|
+
- Changed `handleActiveNavItem` handler behavior to be less restrictive - anchors now count as active navbar items
|
|
50
|
+
|
|
51
|
+
## [8.0.2] - 2025-06-26
|
|
52
|
+
### Fixed
|
|
53
|
+
- Fixed type export issue
|
|
54
|
+
|
|
55
|
+
## [8.0.1] - 2025-06-26
|
|
4
56
|
### Added
|
|
5
57
|
- Added `*.tsbuildinfo` to `.gitignore`
|
|
6
58
|
|
|
@@ -31,7 +83,6 @@
|
|
|
31
83
|
- Improved code organization with feature-based directory structure
|
|
32
84
|
- Enhanced type definitions for better developer experience
|
|
33
85
|
- Updated documentation to reflect TypeScript support
|
|
34
|
-
- Improved error messages with type-aware validation
|
|
35
86
|
- Refactored component props for better type inference
|
|
36
87
|
- Updated all examples in documentation to use TypeScript
|
|
37
88
|
|
|
@@ -48,8 +99,8 @@
|
|
|
48
99
|
- Changed some prop types to be more strict
|
|
49
100
|
- Removed support for untyped icon strings
|
|
50
101
|
|
|
51
|
-
## [7.1.3]
|
|
52
|
-
###
|
|
102
|
+
## [7.1.3] - 2024-11-17
|
|
103
|
+
### Changed
|
|
53
104
|
- Updated the "Disclaimer" and "What's next ?" sections of the README file
|
|
54
105
|
|
|
55
106
|
### Added
|
|
@@ -59,78 +110,78 @@
|
|
|
59
110
|
- Fixed a layout shift when going from collapsed info to expanded info
|
|
60
111
|
- Added a min-width to Magic Pill when info is expanded to keep it looking good
|
|
61
112
|
|
|
62
|
-
## [7.1.1] -> [7.1.2]
|
|
113
|
+
## [7.1.1] -> [7.1.2] - 2024-11-17
|
|
63
114
|
### Fixed
|
|
64
115
|
- Fixed the default style of CTA with a link. It no longer is underlined and blue
|
|
65
116
|
|
|
66
|
-
## [7.1.0]
|
|
117
|
+
## [7.1.0] - 2024-11-17
|
|
67
118
|
### Fixed
|
|
68
|
-
- Reworked the way
|
|
119
|
+
- Reworked the way the conditional CTA and button rendering works
|
|
69
120
|
|
|
70
|
-
## [7.0.1]
|
|
121
|
+
## [7.0.1] - 2024-11-16
|
|
71
122
|
### Fixed
|
|
72
|
-
- Removed
|
|
123
|
+
- Removed defaultProps, as it will no longer be supported in future versions of React
|
|
73
124
|
|
|
74
|
-
## [7.0.
|
|
125
|
+
## [7.0.0] - 2024-11-16
|
|
75
126
|
### Fixed
|
|
76
127
|
- Fixed version compatibility issues with NextJS / React
|
|
77
128
|
|
|
78
|
-
## [6.1.28]
|
|
129
|
+
## [6.1.28] - 2024-11-16
|
|
79
130
|
### Fixed
|
|
80
131
|
- Fixed a wrong display condition for info panel
|
|
81
132
|
|
|
82
|
-
## [6.1.27]
|
|
133
|
+
## [6.1.27] - 2024-11-16
|
|
83
134
|
### Fixed
|
|
84
135
|
- Fixed the issue with stuttering exit animation
|
|
85
136
|
|
|
86
|
-
## [6.1.26]
|
|
137
|
+
## [6.1.26] - 2024-11-15
|
|
87
138
|
### Fixed
|
|
88
139
|
- Backtracked to V6.1.20 after various fails. V6.1.20 was the closest to actually being usable
|
|
89
140
|
|
|
90
|
-
## [6.1.22] -> [6.1.25]
|
|
141
|
+
## [6.1.22] -> [6.1.25] - 2024-11-15
|
|
91
142
|
### Fixed
|
|
92
143
|
- Refined a bit more the logic regarding classes applied to Magic Pill upon animations to prevent buggy visuals (still in progress)
|
|
93
144
|
|
|
94
|
-
## [6.1.21]
|
|
145
|
+
## [6.1.21] - 2024-11-15
|
|
95
146
|
### Fixed
|
|
96
147
|
- Refined a bit more the logic regarding entry and exit animations to prevent buggy visuals (still in progress)
|
|
97
148
|
|
|
98
|
-
## [6.1.20]
|
|
149
|
+
## [6.1.20] - 2024-11-15
|
|
99
150
|
### Fixed
|
|
100
151
|
- Implemented a more refined logic to prevent animation on hover and resume it on mouse leave (still in progress)
|
|
101
152
|
- Simplified the info div animation and removed the ::after pseudo-element
|
|
102
153
|
- Added a new animation for the CTA : when the info div is expanded, the button moves to the center of Magic Pill
|
|
103
154
|
|
|
104
|
-
## [6.1.19]
|
|
155
|
+
## [6.1.19] - 2024-11-15
|
|
105
156
|
### Fixed
|
|
106
157
|
- Added the import of useRef, which I forgot in the previous release
|
|
107
158
|
|
|
108
|
-
## [6.1.18]
|
|
159
|
+
## [6.1.18] - 2024-11-15
|
|
109
160
|
### Fixed
|
|
110
161
|
- Reworked the logic regarding animation pausing on hover (still a work in progress)
|
|
111
162
|
|
|
112
|
-
## [6.1.17]
|
|
163
|
+
## [6.1.17] - 2024-11-15
|
|
113
164
|
### Added
|
|
114
165
|
- 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
166
|
- Added a LICENSE file
|
|
116
167
|
- Added a NOTICE file
|
|
117
168
|
- LICENSE and NOTICE files will be added to the package
|
|
118
169
|
|
|
119
|
-
###
|
|
170
|
+
### Changed
|
|
120
171
|
- README file
|
|
121
172
|
|
|
122
|
-
## [6.1.16]
|
|
173
|
+
## [6.1.16] - 2024-11-15
|
|
123
174
|
### Fixed
|
|
124
175
|
- Fixed various display issues
|
|
125
176
|
- Improved layout breaks
|
|
126
177
|
- Started fixing info pop-up display issues
|
|
127
178
|
- Fixed z-index issues
|
|
128
179
|
|
|
129
|
-
## [6.1.15]
|
|
180
|
+
## [6.1.15] - 2024-11-15
|
|
130
181
|
### Fixed
|
|
131
182
|
- 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
183
|
|
|
133
|
-
## [6.1.14]
|
|
184
|
+
## [6.1.14] - 2024-11-15
|
|
134
185
|
### Added
|
|
135
186
|
- Added a default props, so that Magic Pill displays a friendly default message if there is an issue with the given props
|
|
136
187
|
|
|
@@ -141,27 +192,27 @@
|
|
|
141
192
|
- Fixed some specificity issues in CSS by wrapping Magic Pill inside html and body to raise its style priority
|
|
142
193
|
- Changed the name of the "entry" keyframes to "magicPillEntry" to avoid any issue, considering "entry" is a popular term for keyframes
|
|
143
194
|
|
|
144
|
-
## [6.1.13]
|
|
195
|
+
## [6.1.13] - 2024-11-15
|
|
145
196
|
### Fixed
|
|
146
|
-
- Fixed the definition of CSS
|
|
197
|
+
- 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
198
|
|
|
148
|
-
## [6.1.12]
|
|
199
|
+
## [6.1.12] - 2024-11-15
|
|
149
200
|
### Fixed
|
|
150
201
|
- Fixed a wrong import line in the README file
|
|
151
202
|
|
|
152
203
|
### Removed
|
|
153
|
-
- Removed
|
|
204
|
+
- Removed preferred theme based light/dark mode as it was conflicting with the rest of the project's stylesheet
|
|
154
205
|
|
|
155
|
-
## [6.1.11]
|
|
206
|
+
## [6.1.11] - 2024-11-15
|
|
156
207
|
### Added
|
|
157
|
-
- Added
|
|
208
|
+
- Added preferred theme based light/dark mode
|
|
158
209
|
|
|
159
210
|
### Fixed
|
|
160
211
|
- Fixed a display issue regarding CTA labels
|
|
161
212
|
|
|
162
|
-
## [6.1.10]
|
|
213
|
+
## [6.1.10] - 2024-11-15
|
|
163
214
|
### Added
|
|
164
215
|
- Added the changelog file to the package
|
|
165
216
|
|
|
166
217
|
### Fixed
|
|
167
|
-
- Fixed issues with useStates and reworked the timing of the exit of Magic Pill
|
|
218
|
+
- Fixed issues with useStates and reworked the timing of the exit of Magic Pill
|
package/README.md
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Let it empower you.
|
|
3
3
|
|
|
4
4
|
## Disclaimer
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
I'll update this section once a real usable version is released.
|
|
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.
|
|
8
7
|
|
|
9
8
|
#### Thank you !!
|
|
10
9
|
Thank you for your patience and to all people who already have shown interest in Magic Pill, it's my very first npm package and I couldn't ask for a better reception of my package after only a few days after its initial release.
|
|
@@ -26,43 +25,43 @@ Magic Pill is a powerful React component that lets you show contextual informati
|
|
|
26
25
|
- [X] Written in TypeScript with comprehensive type definitions
|
|
27
26
|
- [X] Highly customizable React component with strongly typed props
|
|
28
27
|
- [X] Fully customized styling based on CSS variables for easy theme adaptation
|
|
29
|
-
- [X]
|
|
30
|
-
- [X]
|
|
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
31
|
- [X] Lightweight and efficient
|
|
32
|
-
- [X] Full TypeScript support with proper type checking
|
|
33
32
|
|
|
34
33
|
## Installation
|
|
35
|
-
### CDN
|
|
36
|
-
Want to quickly give it a try? Add Magic Pill to any React/NextJS project within 10 seconds with our CDN links!
|
|
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" />
|
|
41
|
-
```
|
|
42
|
-
#### unpkg
|
|
43
|
-
```html
|
|
44
|
-
<script src="https://unpkg.com/magic-pill@latest/dist/index.js"></script>
|
|
45
|
-
<link href="https://unpkg.com/magic-pill@latest/dist/magicpill.css" rel="stylesheet" />
|
|
46
|
-
```
|
|
47
|
-
|
|
48
34
|
### npm
|
|
49
35
|
Magic Pill is available on npm, simply use the following command and you're ready to go!
|
|
50
36
|
```bash
|
|
51
37
|
npm install magic-pill
|
|
52
38
|
```
|
|
53
39
|
|
|
40
|
+
### Requirements
|
|
41
|
+
- **React and React DOM 18 or later** (peer dependencies).
|
|
42
|
+
- **Next.js is optional**: Magic Pill works in any React app.
|
|
43
|
+
- **TypeScript is optional**: the type definitions ship with the package.
|
|
44
|
+
|
|
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.
|
|
46
|
+
|
|
54
47
|
## How to use it?
|
|
55
48
|
### Import styles
|
|
56
|
-
For it to work properly, you need to import styles in your app (we recommend importing it into your
|
|
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).
|
|
57
50
|
```typescript
|
|
58
51
|
// Import in your Next.js or React project
|
|
59
52
|
import "magic-pill/dist/magicpill.css";
|
|
53
|
+
// or, equivalently
|
|
54
|
+
import "magic-pill/magicpill.css";
|
|
60
55
|
```
|
|
61
56
|
|
|
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
|
+
|
|
62
59
|
### Usage with React/Next.js
|
|
63
60
|
Magic Pill is designed to be used with a Context to manage its state globally. Here's how to set it up:
|
|
64
61
|
|
|
65
|
-
|
|
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`):
|
|
66
65
|
```typescript
|
|
67
66
|
"use client"
|
|
68
67
|
import React, { createContext, useContext, useState } from "react";
|
|
@@ -108,7 +107,7 @@ interface MagicPillContextType {
|
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
const MagicPillContext = createContext<MagicPillContextType>({
|
|
111
|
-
pillData:
|
|
110
|
+
pillData: defaultPillData,
|
|
112
111
|
setPillData: () => {},
|
|
113
112
|
updateMode: () => {},
|
|
114
113
|
updateNotificationIcon: () => {},
|
|
@@ -126,13 +125,7 @@ const MagicPillContext = createContext<MagicPillContextType>({
|
|
|
126
125
|
deleteNavItem: () => {},
|
|
127
126
|
});
|
|
128
127
|
|
|
129
|
-
export const useMagicPill = () =>
|
|
130
|
-
const context = useContext(MagicPillContext);
|
|
131
|
-
if (!context) {
|
|
132
|
-
throw new Error("useMagicPill must be used within a MagicPillProvider");
|
|
133
|
-
}
|
|
134
|
-
return context;
|
|
135
|
-
};
|
|
128
|
+
export const useMagicPill = () => useContext(MagicPillContext);
|
|
136
129
|
|
|
137
130
|
export const MagicPillProvider = ({
|
|
138
131
|
children
|
|
@@ -164,7 +157,6 @@ export const MagicPillProvider = ({
|
|
|
164
157
|
return (
|
|
165
158
|
<MagicPillContext.Provider value={contextValue}>
|
|
166
159
|
{children}
|
|
167
|
-
{pillData && <div id="magic-pill-root" />}
|
|
168
160
|
</MagicPillContext.Provider>
|
|
169
161
|
);
|
|
170
162
|
};
|
|
@@ -179,7 +171,7 @@ import { MagicPillInitializer } from "./contexts/magicPillInitializer";
|
|
|
179
171
|
export default function RootLayout({ children }) {
|
|
180
172
|
|
|
181
173
|
return (
|
|
182
|
-
<html lang="
|
|
174
|
+
<html lang="en">
|
|
183
175
|
<body>
|
|
184
176
|
<MagicPillProvider>
|
|
185
177
|
{children}
|
|
@@ -194,7 +186,7 @@ export default function RootLayout({ children }) {
|
|
|
194
186
|
3. Create an initializer file for Magic Pill (e.g., in `app/contexts/magicPillInitializer.tsx`):
|
|
195
187
|
```tsx
|
|
196
188
|
"use client"
|
|
197
|
-
import MagicPill from "magic-pill";
|
|
189
|
+
import { MagicPill } from "magic-pill";
|
|
198
190
|
import { useMagicPill } from "./magicPillContext";
|
|
199
191
|
|
|
200
192
|
export const MagicPillInitializer = () => {
|
|
@@ -227,6 +219,8 @@ export default function MPTest() {
|
|
|
227
219
|
```
|
|
228
220
|
> **It really is as simple as that, to use Magic Pill, once the setup is done**
|
|
229
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
|
+
|
|
230
224
|
### Update Magic Pill's content granularly
|
|
231
225
|
Magic Pill, right from the start, has been thought out to be as highly customizable as possible.
|
|
232
226
|
To help you use it in the best way possible, a collection of handlers is part of the package.
|
|
@@ -245,7 +239,18 @@ To help you use it in the best way possible, a collection of handlers is part of
|
|
|
245
239
|
- `updateNavItemIcon` - Change a navbar item's icon
|
|
246
240
|
- `handleActiveNavItem` - Automatically working handler directly used by the navbar to update the active link
|
|
247
241
|
- `addNavItem` - Add an item to the navbar
|
|
248
|
-
- `deleteNavItem` - Delete an item
|
|
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.
|
|
249
254
|
|
|
250
255
|
### Available Icons
|
|
251
256
|
#### Notification Icons
|
|
@@ -268,6 +273,12 @@ To help you use it in the best way possible, a collection of handlers is part of
|
|
|
268
273
|
- `"undo"` - Undo/back icon
|
|
269
274
|
- `""` - No icon
|
|
270
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
|
+
|
|
271
282
|
### Customization
|
|
272
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".
|
|
273
284
|
|
|
@@ -277,19 +288,19 @@ Magic Pill is easily customizable through CSS variables. Simply replace the them
|
|
|
277
288
|
|
|
278
289
|
/* CSS variables */
|
|
279
290
|
:root {
|
|
280
|
-
--
|
|
281
|
-
--
|
|
282
|
-
--
|
|
283
|
-
--
|
|
284
|
-
--
|
|
285
|
-
--
|
|
286
|
-
--
|
|
287
|
-
--
|
|
288
|
-
--
|
|
289
|
-
--
|
|
290
|
-
--
|
|
291
|
-
--
|
|
292
|
-
--
|
|
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;
|
|
293
304
|
}
|
|
294
305
|
```
|
|
295
306
|
|
|
@@ -302,12 +313,20 @@ Here's how to proceed:
|
|
|
302
313
|
git clone https://github.com/CedricTheveneau/Magic-Pill.git
|
|
303
314
|
```
|
|
304
315
|
|
|
305
|
-
2.
|
|
316
|
+
2. Use the Node.js version from `.nvmrc` (Node 26) and install all dependencies:
|
|
306
317
|
```bash
|
|
318
|
+
nvm use
|
|
307
319
|
npm install
|
|
308
320
|
```
|
|
309
321
|
|
|
310
|
-
3.
|
|
322
|
+
3. Check that everything works:
|
|
323
|
+
```bash
|
|
324
|
+
npm run typecheck # TypeScript
|
|
325
|
+
npm test # Vitest test suite
|
|
326
|
+
npm run build # Builds dist/ with tsdown
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
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
330
|
```bash
|
|
312
331
|
# Create a new Next.js app
|
|
313
332
|
npx create-next-app@latest my-app --typescript
|
|
@@ -321,7 +340,7 @@ npm link magic-pill
|
|
|
321
340
|
|
|
322
341
|
## Troubleshooting / Contact
|
|
323
342
|
Magic Pill is still under development, you'll certainly encounter issues with it.
|
|
324
|
-
You can send me emails anytime at [
|
|
343
|
+
You can send me emails anytime at [theveneaucedricpro@gmail.com](mailto:theveneaucedricpro@gmail.com), I'll try my best to help you out.
|
|
325
344
|
|
|
326
345
|
## License
|
|
327
346
|
Magic Pill is distributed under the [MIT License](https://www.tldrlegal.com/license/mit-license).
|
|
@@ -332,5 +351,4 @@ Magic Pill is distributed under the [MIT License](https://www.tldrlegal.com/lice
|
|
|
332
351
|
| Support of custom svg icons | Animation fixes |
|
|
333
352
|
| Transition between two modes | Responsive version + Proportions rework |
|
|
334
353
|
| Implementation of function triggers on CTAs | Full documentation |
|
|
335
|
-
|
|
|
336
|
-
| Add new modes | |
|
|
354
|
+
| | Proper testing |
|
package/dist/MagicPill.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./
|
|
3
|
-
import { MagicPillType } from "./types";
|
|
1
|
+
import { MagicPillType } from "./types/magicPill.js";
|
|
2
|
+
import "./types/index.js";
|
|
4
3
|
interface MagicPillProps {
|
|
5
|
-
|
|
4
|
+
pillData: MagicPillType;
|
|
6
5
|
}
|
|
7
|
-
declare const MagicPill: ({ pillData }: MagicPillProps) =>
|
|
8
|
-
export
|
|
6
|
+
declare const MagicPill: ({ pillData }: MagicPillProps) => import("react").JSX.Element;
|
|
7
|
+
export = MagicPill;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";let e=require("react");const t=require("./Notification/Notification.js"),n=require("./Navbar/Navbar.js");let r=require("react/jsx-runtime");const i=({pillData:i})=>{let[a,o]=(0,e.useState)(!1),[s,c]=(0,e.useState)(!0),l=(0,e.useRef)(null),u=(0,e.useRef)(null),d=(0,e.useRef)(!1),f=(0,e.useRef)(!1),p=()=>d.current||f.current,m=()=>{l.current&&(clearTimeout(l.current),l.current=null)},h=()=>{u.current&&(clearTimeout(u.current),u.current=null)},g=()=>{h(),u.current=setTimeout(()=>{o(!1),c(!0)},5e3)},_=()=>{c(!1),m(),l.current=setTimeout(()=>{l.current=null,o(!0),p()||g()},2500)},v=i.mode===`notification`?i.notification:void 0;(0,e.useEffect)(()=>(i.mode===`notification`?_():(o(!0),c(!1)),()=>{m(),h()}),[i.mode,v?.icon,v?.message,v?.cta?.icon,v?.cta?.label,v?.cta?.link,v?.info?.title,v?.info?.content,v?.info?.closeLabel]);let y=()=>{i.mode===`notification`&&h()},b=()=>{i.mode===`notification`&&a&&!p()&&g()};return/* @__PURE__ */ (0,r.jsx)(`div`,{className:s?`magicPill out`:a?`magicPill active`:`magicPill entry`,"aria-live":`polite`,"aria-atomic":`false`,role:i.mode===`notification`?`status`:void 0,onMouseEnter:()=>{d.current=!0,y()},onMouseLeave:()=>{d.current=!1,b()},onFocus:()=>{f.current=!0,y()},onBlur:e=>{f.current=e.currentTarget.contains(e.relatedTarget),b()},children:i.mode===`notification`?/* @__PURE__ */ (0,r.jsx)(t,{...i}):i.mode===`navbar`?/* @__PURE__ */ (0,r.jsx)(n,{...i}):null})};module.exports=i;
|
|
2
|
+
//# sourceMappingURL=MagicPill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MagicPill.js","names":["useState","useRef","useEffect","Notification","Navbar","react","require_Notification","require_Navbar","react_jsx_runtime","MagicPill","pillData","active","setActive","exit","setExit","entryTimeoutRef","exitTimeoutRef","hoveringRef","focusedRef","isPaused","clearEntryAnimation","clearExitAnimation","startExitAnimation","displayMagicPill","notification","pauseExitAnimation","resumeExitAnimation","event"],"sources":["../src/MagicPill.tsx"],"sourcesContent":["\"use client\"\nimport { useEffect, useState, useRef, type FocusEvent } from \"react\";\n\nimport Notification from \"./Notification/Notification\"\nimport Navbar from \"./Navbar/Navbar\";\n\nimport { MagicPillType } from \"./types\";\n\ninterface MagicPillProps {\n pillData: MagicPillType;\n}\n\nconst MagicPill = ({ pillData }: MagicPillProps) => {\n const [active, setActive] = useState<boolean>(false);\n const [exit, setExit] = useState<boolean>(true);\n const entryTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const exitTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n // The auto-hide pauses while the pill is hovered (L15) or holds keyboard focus (Y3).\n // Tracked in every mode: the pointer or focus may already be on the pill when a notification arrives.\n const hoveringRef = useRef<boolean>(false);\n const focusedRef = useRef<boolean>(false);\n const isPaused = () => hoveringRef.current || focusedRef.current;\n\n const clearEntryAnimation = () => {\n if (entryTimeoutRef.current) {\n clearTimeout(entryTimeoutRef.current);\n entryTimeoutRef.current = null;\n }\n };\n\n const clearExitAnimation = () => {\n if (exitTimeoutRef.current) {\n clearTimeout(exitTimeoutRef.current);\n exitTimeoutRef.current = null;\n }\n };\n\n const startExitAnimation = () => {\n clearExitAnimation();\n exitTimeoutRef.current = setTimeout(() => {\n setActive(false);\n setExit(true);\n }, 5000);\n };\n\n // Only called in notification mode. The effect cleanup clears this timer\n // whenever the mode changes or the pill unmounts, so the callback can't\n // act on a mode that is no longer current (L5).\n const displayMagicPill = () => {\n setExit(false);\n clearEntryAnimation();\n entryTimeoutRef.current = setTimeout(() => {\n entryTimeoutRef.current = null;\n setActive(true);\n // While paused, the exit timer starts when the pointer and focus have left\n if (!isPaused()) {\n startExitAnimation();\n }\n }, 2500);\n };\n\n // Every visible field of the notification, as primitives: new content\n // replays the pill, while the same content in a new object doesn't (L1)\n const notification = pillData.mode === \"notification\" ? pillData.notification : undefined;\n\n useEffect(() => {\n if (pillData.mode === \"notification\") {\n displayMagicPill();\n } else {\n setActive(true);\n setExit(false);\n }\n\n return () => {\n clearEntryAnimation();\n clearExitAnimation();\n };\n }, [\n pillData.mode,\n notification?.icon,\n notification?.message,\n notification?.cta?.icon,\n notification?.cta?.label,\n notification?.cta?.link,\n notification?.info?.title,\n notification?.info?.content,\n notification?.info?.closeLabel,\n ]);\n\n const pauseExitAnimation = () => {\n if (pillData.mode === \"notification\") {\n clearExitAnimation();\n }\n };\n\n const resumeExitAnimation = () => {\n if (pillData.mode === \"notification\" && active && !isPaused()) {\n startExitAnimation();\n }\n };\n\n const handleMouseEnter = () => {\n hoveringRef.current = true;\n pauseExitAnimation();\n };\n\n const handleMouseLeave = () => {\n hoveringRef.current = false;\n resumeExitAnimation();\n };\n\n const handleFocus = () => {\n focusedRef.current = true;\n pauseExitAnimation();\n };\n\n const handleBlur = (event: FocusEvent<HTMLDivElement>) => {\n // Focus moving between elements inside the pill keeps it paused\n focusedRef.current = event.currentTarget.contains(event.relatedTarget as Node | null);\n resumeExitAnimation();\n };\n\n return (\n <div\n className={\n exit ? \"magicPill out\" : active ? \"magicPill active\" : \"magicPill entry\"\n }\n // Live region (Y1): always registered, so screen readers pick up a\n // notification that replaces the navbar; non-atomic, so only what\n // changed is read out\n aria-live=\"polite\"\n aria-atomic=\"false\"\n role={pillData.mode === \"notification\" ? \"status\" : undefined}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleFocus}\n onBlur={handleBlur}\n >\n {pillData.mode === \"notification\" ? (\n <Notification {...pillData} />\n ) : pillData.mode === \"navbar\" ? (\n <Navbar {...pillData} />\n ) : null}\n </div>\n );\n};\n\nexport default MagicPill;\n"],"mappings":"A,yJAYA,MAAMS,GAAa,CAAEC,cAA+B,CAClD,GAAM,CAACC,EAAQC,IAAA,EAAaZ,EAAAA,SAAAA,CAAkB,EAAK,EAC7C,CAACa,EAAMC,IAAA,EAAWd,EAAAA,SAAAA,CAAkB,EAAI,EACxCe,GAAA,EAAkBd,EAAAA,OAAAA,CAA6C,IAAI,EACnEe,GAAA,EAAiBf,EAAAA,OAAAA,CAA6C,IAAI,EAGlEgB,GAAA,EAAchB,EAAAA,OAAAA,CAAgB,EAAK,EACnCiB,GAAA,EAAajB,EAAAA,OAAAA,CAAgB,EAAK,EAClCkB,MAAiBF,EAAY,SAAWC,EAAW,QAEnDE,MAA4B,CAC5BL,EAAgB,UAClB,aAAaA,EAAgB,OAAO,EACpCA,EAAgB,QAAU,KAE9B,EAEMM,MAA2B,CAC3BL,EAAe,UACjB,aAAaA,EAAe,OAAO,EACnCA,EAAe,QAAU,KAE7B,EAEMM,MAA2B,CAC/BD,EAAmB,EACnBL,EAAe,QAAU,eAAiB,CACxCJ,EAAU,EAAK,EACfE,EAAQ,EAAI,CACd,EAAG,GAAI,CACT,EAKMS,MAAyB,CAC7BT,EAAQ,EAAK,EACbM,EAAoB,EACpBL,EAAgB,QAAU,eAAiB,CACzCA,EAAgB,QAAU,KAC1BH,EAAU,EAAI,EAETO,EAAS,GACZG,EAAmB,CAEvB,EAAG,IAAI,CACT,EAIME,EAAed,EAAS,OAAS,eAAiBA,EAAS,aAAe,IAAA,IAEhFR,EAAAA,EAAAA,UAAAA,MACMQ,EAAS,OAAS,eACpBa,EAAiB,GAEjBX,EAAU,EAAI,EACdE,EAAQ,EAAK,OAGF,CACXM,EAAoB,EACpBC,EAAmB,CACrB,GACC,CACDX,EAAS,KACTc,GAAc,KACdA,GAAc,QACdA,GAAc,KAAK,KACnBA,GAAc,KAAK,MACnBA,GAAc,KAAK,KACnBA,GAAc,MAAM,MACpBA,GAAc,MAAM,QACpBA,GAAc,MAAM,UACtB,CAAC,EAED,IAAMC,MAA2B,CAC3Bf,EAAS,OAAS,gBACpBW,EAAmB,CAEvB,EAEMK,MAA4B,CAC5BhB,EAAS,OAAS,gBAAkBC,GAAU,CAACQ,EAAS,GAC1DG,EAAmB,CAEvB,EAuBA,MACE,iBAAA,EAAAd,EAAA,IAAA,CAAC,MAAD,CACE,UACEK,EAAO,gBAAkBF,EAAS,mBAAqB,kBAKzD,YAAU,SACV,cAAY,QACZ,KAAMD,EAAS,OAAS,eAAiB,SAAW,IAAA,GACpD,iBAhC2B,CAC7BO,EAAY,QAAU,GACtBQ,EAAmB,CACrB,EA8BI,iBA5B2B,CAC7BR,EAAY,QAAU,GACtBS,EAAoB,CACtB,EA0BI,YAxBsB,CACxBR,EAAW,QAAU,GACrBO,EAAmB,CACrB,EAsBI,OApBgBE,GAAsC,CAExDT,EAAW,QAAUS,EAAM,cAAc,SAASA,EAAM,aAA4B,EACpFD,EAAoB,CACtB,EAkBK,SAAAhB,EAAS,OAAS,eACjB,iBAAA,EAAAF,EAAA,IAAA,CAACL,EAAD,CAAc,GAAIO,CAAW,CAAA,EAC3BA,EAAS,OAAS,SACpB,iBAAA,EAAAF,EAAA,IAAA,CAACJ,EAAD,CAAQ,GAAIM,CAAW,CAAA,EACrB,IACD,CAAA,CAET,E"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{useEffect as e,useRef as t,useState as n}from"react";import r from"./Notification/Notification.mjs";import i from"./Navbar/Navbar.mjs";import{jsx as a}from"react/jsx-runtime";const o=({pillData:o})=>{let[s,c]=n(!1),[l,u]=n(!0),d=t(null),f=t(null),p=t(!1),m=t(!1),h=()=>p.current||m.current,g=()=>{d.current&&(clearTimeout(d.current),d.current=null)},_=()=>{f.current&&(clearTimeout(f.current),f.current=null)},v=()=>{_(),f.current=setTimeout(()=>{c(!1),u(!0)},5e3)},y=()=>{u(!1),g(),d.current=setTimeout(()=>{d.current=null,c(!0),h()||v()},2500)},b=o.mode===`notification`?o.notification:void 0;e(()=>(o.mode===`notification`?y():(c(!0),u(!1)),()=>{g(),_()}),[o.mode,b?.icon,b?.message,b?.cta?.icon,b?.cta?.label,b?.cta?.link,b?.info?.title,b?.info?.content,b?.info?.closeLabel]);let x=()=>{o.mode===`notification`&&_()},S=()=>{o.mode===`notification`&&s&&!h()&&v()};return/* @__PURE__ */ a(`div`,{className:l?`magicPill out`:s?`magicPill active`:`magicPill entry`,"aria-live":`polite`,"aria-atomic":`false`,role:o.mode===`notification`?`status`:void 0,onMouseEnter:()=>{p.current=!0,x()},onMouseLeave:()=>{p.current=!1,S()},onFocus:()=>{m.current=!0,x()},onBlur:e=>{m.current=e.currentTarget.contains(e.relatedTarget),S()},children:o.mode===`notification`?/* @__PURE__ */ a(r,{...o}):o.mode===`navbar`?/* @__PURE__ */ a(i,{...o}):null})};export{o as default};
|
|
2
|
+
//# sourceMappingURL=MagicPill.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MagicPill.mjs","names":["useEffect","useRef","useState","Notification","Navbar","jsx","MagicPill","pillData","active","setActive","exit","setExit","entryTimeoutRef","exitTimeoutRef","hoveringRef","focusedRef","isPaused","clearEntryAnimation","clearExitAnimation","startExitAnimation","displayMagicPill","notification","pauseExitAnimation","resumeExitAnimation","event"],"sources":["../src/MagicPill.tsx"],"sourcesContent":["\"use client\"\nimport { useEffect, useState, useRef, type FocusEvent } from \"react\";\n\nimport Notification from \"./Notification/Notification\"\nimport Navbar from \"./Navbar/Navbar\";\n\nimport { MagicPillType } from \"./types\";\n\ninterface MagicPillProps {\n pillData: MagicPillType;\n}\n\nconst MagicPill = ({ pillData }: MagicPillProps) => {\n const [active, setActive] = useState<boolean>(false);\n const [exit, setExit] = useState<boolean>(true);\n const entryTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const exitTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n // The auto-hide pauses while the pill is hovered (L15) or holds keyboard focus (Y3).\n // Tracked in every mode: the pointer or focus may already be on the pill when a notification arrives.\n const hoveringRef = useRef<boolean>(false);\n const focusedRef = useRef<boolean>(false);\n const isPaused = () => hoveringRef.current || focusedRef.current;\n\n const clearEntryAnimation = () => {\n if (entryTimeoutRef.current) {\n clearTimeout(entryTimeoutRef.current);\n entryTimeoutRef.current = null;\n }\n };\n\n const clearExitAnimation = () => {\n if (exitTimeoutRef.current) {\n clearTimeout(exitTimeoutRef.current);\n exitTimeoutRef.current = null;\n }\n };\n\n const startExitAnimation = () => {\n clearExitAnimation();\n exitTimeoutRef.current = setTimeout(() => {\n setActive(false);\n setExit(true);\n }, 5000);\n };\n\n // Only called in notification mode. The effect cleanup clears this timer\n // whenever the mode changes or the pill unmounts, so the callback can't\n // act on a mode that is no longer current (L5).\n const displayMagicPill = () => {\n setExit(false);\n clearEntryAnimation();\n entryTimeoutRef.current = setTimeout(() => {\n entryTimeoutRef.current = null;\n setActive(true);\n // While paused, the exit timer starts when the pointer and focus have left\n if (!isPaused()) {\n startExitAnimation();\n }\n }, 2500);\n };\n\n // Every visible field of the notification, as primitives: new content\n // replays the pill, while the same content in a new object doesn't (L1)\n const notification = pillData.mode === \"notification\" ? pillData.notification : undefined;\n\n useEffect(() => {\n if (pillData.mode === \"notification\") {\n displayMagicPill();\n } else {\n setActive(true);\n setExit(false);\n }\n\n return () => {\n clearEntryAnimation();\n clearExitAnimation();\n };\n }, [\n pillData.mode,\n notification?.icon,\n notification?.message,\n notification?.cta?.icon,\n notification?.cta?.label,\n notification?.cta?.link,\n notification?.info?.title,\n notification?.info?.content,\n notification?.info?.closeLabel,\n ]);\n\n const pauseExitAnimation = () => {\n if (pillData.mode === \"notification\") {\n clearExitAnimation();\n }\n };\n\n const resumeExitAnimation = () => {\n if (pillData.mode === \"notification\" && active && !isPaused()) {\n startExitAnimation();\n }\n };\n\n const handleMouseEnter = () => {\n hoveringRef.current = true;\n pauseExitAnimation();\n };\n\n const handleMouseLeave = () => {\n hoveringRef.current = false;\n resumeExitAnimation();\n };\n\n const handleFocus = () => {\n focusedRef.current = true;\n pauseExitAnimation();\n };\n\n const handleBlur = (event: FocusEvent<HTMLDivElement>) => {\n // Focus moving between elements inside the pill keeps it paused\n focusedRef.current = event.currentTarget.contains(event.relatedTarget as Node | null);\n resumeExitAnimation();\n };\n\n return (\n <div\n className={\n exit ? \"magicPill out\" : active ? \"magicPill active\" : \"magicPill entry\"\n }\n // Live region (Y1): always registered, so screen readers pick up a\n // notification that replaces the navbar; non-atomic, so only what\n // changed is read out\n aria-live=\"polite\"\n aria-atomic=\"false\"\n role={pillData.mode === \"notification\" ? \"status\" : undefined}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleFocus}\n onBlur={handleBlur}\n >\n {pillData.mode === \"notification\" ? (\n <Notification {...pillData} />\n ) : pillData.mode === \"navbar\" ? (\n <Navbar {...pillData} />\n ) : null}\n </div>\n );\n};\n\nexport default MagicPill;\n"],"mappings":"A,mMAYA,MAAMM,GAAa,CAAEC,cAA+B,CAClD,GAAM,CAACC,EAAQC,GAAaP,EAAkB,EAAK,EAC7C,CAACQ,EAAMC,GAAWT,EAAkB,EAAI,EACxCU,EAAkBX,EAA6C,IAAI,EACnEY,EAAiBZ,EAA6C,IAAI,EAGlEa,EAAcb,EAAgB,EAAK,EACnCc,EAAad,EAAgB,EAAK,EAClCe,MAAiBF,EAAY,SAAWC,EAAW,QAEnDE,MAA4B,CAC5BL,EAAgB,UAClB,aAAaA,EAAgB,OAAO,EACpCA,EAAgB,QAAU,KAE9B,EAEMM,MAA2B,CAC3BL,EAAe,UACjB,aAAaA,EAAe,OAAO,EACnCA,EAAe,QAAU,KAE7B,EAEMM,MAA2B,CAC/BD,EAAmB,EACnBL,EAAe,QAAU,eAAiB,CACxCJ,EAAU,EAAK,EACfE,EAAQ,EAAI,CACd,EAAG,GAAI,CACT,EAKMS,MAAyB,CAC7BT,EAAQ,EAAK,EACbM,EAAoB,EACpBL,EAAgB,QAAU,eAAiB,CACzCA,EAAgB,QAAU,KAC1BH,EAAU,EAAI,EAETO,EAAS,GACZG,EAAmB,CAEvB,EAAG,IAAI,CACT,EAIME,EAAed,EAAS,OAAS,eAAiBA,EAAS,aAAe,IAAA,GAEhFP,OACMO,EAAS,OAAS,eACpBa,EAAiB,GAEjBX,EAAU,EAAI,EACdE,EAAQ,EAAK,OAGF,CACXM,EAAoB,EACpBC,EAAmB,CACrB,GACC,CACDX,EAAS,KACTc,GAAc,KACdA,GAAc,QACdA,GAAc,KAAK,KACnBA,GAAc,KAAK,MACnBA,GAAc,KAAK,KACnBA,GAAc,MAAM,MACpBA,GAAc,MAAM,QACpBA,GAAc,MAAM,UACtB,CAAC,EAED,IAAMC,MAA2B,CAC3Bf,EAAS,OAAS,gBACpBW,EAAmB,CAEvB,EAEMK,MAA4B,CAC5BhB,EAAS,OAAS,gBAAkBC,GAAU,CAACQ,EAAS,GAC1DG,EAAmB,CAEvB,EAuBA,MACEd,kBAAC,MAAD,CACE,UACEK,EAAO,gBAAkBF,EAAS,mBAAqB,kBAKzD,YAAU,SACV,cAAY,QACZ,KAAMD,EAAS,OAAS,eAAiB,SAAW,IAAA,GACpD,iBAhC2B,CAC7BO,EAAY,QAAU,GACtBQ,EAAmB,CACrB,EA8BI,iBA5B2B,CAC7BR,EAAY,QAAU,GACtBS,EAAoB,CACtB,EA0BI,YAxBsB,CACxBR,EAAW,QAAU,GACrBO,EAAmB,CACrB,EAsBI,OApBgBE,GAAsC,CAExDT,EAAW,QAAUS,EAAM,cAAc,SAASA,EAAM,aAA4B,EACpFD,EAAoB,CACtB,EAkBK,SAAAhB,EAAS,OAAS,eACjBF,kBAACF,EAAD,CAAc,GAAII,CAAW,CAAA,EAC3BA,EAAS,OAAS,SACpBF,kBAACD,EAAD,CAAQ,GAAIG,CAAW,CAAA,EACrB,IACD,CAAA,CAET,E"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";let e=require("react");const t=require("../utils/icons.js"),n=require("../utils/handlers.js");let r=require("react/jsx-runtime");const i=({navbar:i})=>{let{navItems:a}=i||{},[o,s]=(0,e.useState)(``);return(0,e.useEffect)(()=>{let e=typeof window<`u`?window.location.pathname:``,t=n.handleActiveNavItem(e,a);s(t)},[a]),/* @__PURE__ */ (0,r.jsx)(`nav`,{className:`navbar`,children:/* @__PURE__ */ (0,r.jsx)(`ul`,{className:`navbarList`,children:a?.map((e,n)=>{let i=t.getIconComponent(e.icon,t.CTAIcons),a=o===e.label;return/* @__PURE__ */ (0,r.jsx)(`li`,{className:`navbarItem`,children:/* @__PURE__ */ (0,r.jsxs)(`a`,{className:a?`CTA active`:`CTA`,href:e.link,children:[i&&/* @__PURE__ */ (0,r.jsx)(i,{className:`label`}),/* @__PURE__ */ (0,r.jsx)(`span`,{children:e.label})]})},n)})})})};module.exports=i;
|
|
2
|
+
//# sourceMappingURL=Navbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Navbar.js","names":["useState","useEffect","handleActiveNavItem","getIconComponent","CTAIcons","react","require_icons","require_handlers","react_jsx_runtime","Navbar","navbar","navItems","active","setActive","currentPath","matchingLabel","item","index","IconComponent","isActive"],"sources":["../../src/Navbar/Navbar.tsx"],"sourcesContent":["\"use client\"\nimport { useState, useEffect } from \"react\";\n\nimport { MagicPillNavbar, MagicPillNavbarItem } from \"../types\";\nimport { getIconComponent, CTAIcons } from \"../utils/icons\";\nimport { handleActiveNavItem } from \"../utils/handlers\";\n\ninterface NavItemsProps {\n mode: \"navbar\";\n navbar: MagicPillNavbar;\n}\n\nconst Navbar = ({ navbar }: NavItemsProps) => {\n const { navItems } = navbar || {};\n const [active, setActive] = useState(\"\");\n\n useEffect(() => {\n const currentPath = typeof window !== 'undefined' ? window.location.pathname : '';\n const matchingLabel = handleActiveNavItem(currentPath, navItems);\n setActive(matchingLabel);\n }, [navItems]);\n\n return (\n <nav className=\"navbar\">\n <ul className=\"navbarList\">\n {navItems?.map((item: MagicPillNavbarItem, index: number) => {\n const IconComponent = getIconComponent(item.icon, CTAIcons);\n const isActive = active === item.label;\n\n return (\n <li key={index} className=\"navbarItem\">\n <a \n className={isActive ? \"CTA active\" : \"CTA\"} \n href={item.link}\n >\n {IconComponent && <IconComponent className=\"label\" />}\n <span>{item.label}</span>\n </a>\n </li>\n );\n })}\n </ul>\n </nav>\n );\n};\n\nexport default Navbar;\n"],"mappings":"A,8IAYA,MAAMS,GAAU,CAAEC,YAA4B,CAC5C,GAAM,CAAEC,YAAaD,GAAU,CAAC,EAC1B,CAACE,EAAQC,IAAA,EAAab,EAAAA,SAAAA,CAAS,EAAE,EAQvC,OANAC,EAAAA,EAAAA,UAAAA,KAAgB,CACd,IAAMa,EAAc,OAAO,OAAW,IAAc,OAAO,SAAS,SAAW,GACzEC,EAAgBb,EAAAA,oBAAoBY,EAAaH,CAAQ,EAC/DE,EAAUE,CAAa,CACzB,EAAG,CAACJ,CAAQ,CAAC,EAGX,iBAAA,EAAAH,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,SACb,SAAA,iBAAA,EAAAA,EAAA,IAAA,CAAC,KAAD,CAAI,UAAU,aACX,SAAAG,GAAU,KAAKK,EAA2BC,IAAkB,CAC3D,IAAMC,EAAgBf,EAAAA,iBAAiBa,EAAK,KAAMZ,EAAAA,QAAQ,EACpDe,EAAWP,IAAWI,EAAK,MAEjC,MACE,iBAAA,EAAAR,EAAA,IAAA,CAAC,KAAD,CAAgB,UAAU,aACxB,SAAA,iBAAA,EAAAA,EAAA,KAAA,CAAC,IAAD,CACA,UAAWW,EAAW,aAAe,MACrC,KAAMH,EAAK,KAFX,SAAA,CAICE,GAAiB,iBAAA,EAAAV,EAAA,IAAA,CAACU,EAAD,CAAe,UAAU,OAAS,CAAA,EACpD,iBAAA,EAAAV,EAAA,IAAA,CAAC,OAAD,CAAA,SAAOQ,EAAK,KAAY,CAAA,CACvB,C,EACC,EARKC,CAQL,CAER,CAAC,CACC,CAAA,CACD,CAAA,CAET,E"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{useEffect as e,useState as t}from"react";import{CTAIcons as n,getIconComponent as r}from"../utils/icons.mjs";import{handleActiveNavItem as i}from"../utils/handlers.mjs";import{jsx as a,jsxs as o}from"react/jsx-runtime";const s=({navbar:s})=>{let{navItems:c}=s||{},[l,u]=t(``);return e(()=>{let e=typeof window<`u`?window.location.pathname:``,t=i(e,c);u(t)},[c]),/* @__PURE__ */ a(`nav`,{className:`navbar`,children:/* @__PURE__ */ a(`ul`,{className:`navbarList`,children:c?.map((e,t)=>{let i=r(e.icon,n),s=l===e.label;return/* @__PURE__ */ a(`li`,{className:`navbarItem`,children:/* @__PURE__ */ o(`a`,{className:s?`CTA active`:`CTA`,href:e.link,children:[i&&/* @__PURE__ */ a(i,{className:`label`}),/* @__PURE__ */ a(`span`,{children:e.label})]})},t)})})})};export{s as default};
|
|
2
|
+
//# sourceMappingURL=Navbar.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Navbar.mjs","names":["useEffect","useState","CTAIcons","getIconComponent","handleActiveNavItem","jsx","jsxs","Navbar","navbar","navItems","active","setActive","currentPath","matchingLabel","item","index","IconComponent","isActive"],"sources":["../../src/Navbar/Navbar.tsx"],"sourcesContent":["\"use client\"\nimport { useState, useEffect } from \"react\";\n\nimport { MagicPillNavbar, MagicPillNavbarItem } from \"../types\";\nimport { getIconComponent, CTAIcons } from \"../utils/icons\";\nimport { handleActiveNavItem } from \"../utils/handlers\";\n\ninterface NavItemsProps {\n mode: \"navbar\";\n navbar: MagicPillNavbar;\n}\n\nconst Navbar = ({ navbar }: NavItemsProps) => {\n const { navItems } = navbar || {};\n const [active, setActive] = useState(\"\");\n\n useEffect(() => {\n const currentPath = typeof window !== 'undefined' ? window.location.pathname : '';\n const matchingLabel = handleActiveNavItem(currentPath, navItems);\n setActive(matchingLabel);\n }, [navItems]);\n\n return (\n <nav className=\"navbar\">\n <ul className=\"navbarList\">\n {navItems?.map((item: MagicPillNavbarItem, index: number) => {\n const IconComponent = getIconComponent(item.icon, CTAIcons);\n const isActive = active === item.label;\n\n return (\n <li key={index} className=\"navbarItem\">\n <a \n className={isActive ? \"CTA active\" : \"CTA\"} \n href={item.link}\n >\n {IconComponent && <IconComponent className=\"label\" />}\n <span>{item.label}</span>\n </a>\n </li>\n );\n })}\n </ul>\n </nav>\n );\n};\n\nexport default Navbar;\n"],"mappings":"A,+OAYA,MAAMO,GAAU,CAAEC,YAA4B,CAC5C,GAAM,CAAEC,YAAaD,GAAU,CAAC,EAC1B,CAACE,EAAQC,GAAaV,EAAS,EAAE,EAQvC,OANAD,MAAgB,CACd,IAAMY,EAAc,OAAO,OAAW,IAAc,OAAO,SAAS,SAAW,GACzEC,EAAgBT,EAAoBQ,EAAaH,CAAQ,EAC/DE,EAAUE,CAAa,CACzB,EAAG,CAACJ,CAAQ,CAAC,EAGXJ,kBAAC,MAAD,CAAK,UAAU,SACb,SAAAA,kBAAC,KAAD,CAAI,UAAU,aACX,SAAAI,GAAU,KAAKK,EAA2BC,IAAkB,CAC3D,IAAMC,EAAgBb,EAAiBW,EAAK,KAAMZ,CAAQ,EACpDe,EAAWP,IAAWI,EAAK,MAEjC,MACET,kBAAC,KAAD,CAAgB,UAAU,aACxB,SAAAC,kBAAC,IAAD,CACA,UAAWW,EAAW,aAAe,MACrC,KAAMH,EAAK,KAFX,SAAA,CAICE,GAAiBX,kBAACW,EAAD,CAAe,UAAU,OAAS,CAAA,EACpDX,kBAAC,OAAD,CAAA,SAAOS,EAAK,KAAY,CAAA,CACvB,C,EACC,EARKC,CAQL,CAER,CAAC,CACC,CAAA,CACD,CAAA,CAET,E"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";let e=require("react");const t=require("../utils/icons.js");let n=require("react/jsx-runtime");const r=({notification:r})=>{let[i,a]=(0,e.useState)(!1),o=(0,e.useId)(),{icon:s,message:c,cta:l,info:u}=r||{},{icon:d,label:f,link:p}=l||{},{title:m,content:h,closeLabel:g}=u||{},_=t.getIconComponent(s||``,t.Icons),v=t.getIconComponent((i?`cross`:d)||``,t.CTAIcons);return/* @__PURE__ */ (0,n.jsxs)(n.Fragment,{children:[_?/* @__PURE__ */ (0,n.jsx)(_,{className:`icon`}):null,/* @__PURE__ */ (0,n.jsx)(`p`,{className:`message`,children:c}),p&&/* @__PURE__ */ (0,n.jsxs)(`a`,{className:`CTA`,href:p,children:[v&&/* @__PURE__ */ (0,n.jsx)(v,{className:`label`}),/* @__PURE__ */ (0,n.jsx)(`span`,{children:f})]}),u&&!p&&/* @__PURE__ */ (0,n.jsxs)(`button`,{className:`CTA`,"aria-expanded":i,"aria-controls":o,onClick:()=>a(!i),children:[v&&/* @__PURE__ */ (0,n.jsx)(v,{className:`label`}),/* @__PURE__ */ (0,n.jsx)(`span`,{children:i?g:f})]}),u&&/* @__PURE__ */ (0,n.jsxs)(`div`,{id:o,className:i?`info active`:`info`,children:[/* @__PURE__ */ (0,n.jsx)(`p`,{className:`title`,children:m}),/* @__PURE__ */ (0,n.jsx)(`div`,{className:`content`,dangerouslySetInnerHTML:{__html:h||``}})]})]})};module.exports=r;
|
|
2
|
+
//# sourceMappingURL=Notification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Notification.js","names":["useState","useId","getIconComponent","Icons","CTAIcons","react","require_icons","react_jsx_runtime","Notification","notification","isInfoExpanded","setIsInfoExpanded","infoId","icon","message","cta","info","ctaIcon","ctaLabel","ctaLink","title","content","closeLabel","IconComponent","CTAIconComponent"],"sources":["../../src/Notification/Notification.tsx"],"sourcesContent":["\"use client\"\nimport { useId, useState } from \"react\";\n\nimport { MagicPillNotification } from \"../types\";\n\nimport { getIconComponent, Icons, CTAIcons } from \"../utils/icons\";\n\ninterface NotificationProps {\n mode: \"notification\";\n notification: MagicPillNotification;\n}\n\nconst Notification = ({ notification }: NotificationProps) => {\n const [isInfoExpanded, setIsInfoExpanded] = useState(false);\n const infoId = useId();\n \n const { icon, message, cta, info } = notification || {};\n const { icon: ctaIcon, label: ctaLabel, link: ctaLink } = cta || {};\n const { title, content, closeLabel } = info || {};\n\n const IconComponent = getIconComponent(icon || \"\", Icons);\n\n const currentCTAIcon = isInfoExpanded ? \"cross\" : ctaIcon;\n const CTAIconComponent = getIconComponent(currentCTAIcon || \"\", CTAIcons);\n\n return (\n <>\n {IconComponent ? <IconComponent className=\"icon\" /> : null}\n <p className=\"message\">{message}</p>\n\n {ctaLink && (\n <a className=\"CTA\" href={ctaLink}>\n {CTAIconComponent && <CTAIconComponent className=\"label\" />}\n <span>{ctaLabel}</span>\n </a>\n )}\n\n {info && !ctaLink && (\n <button\n className=\"CTA\"\n aria-expanded={isInfoExpanded}\n aria-controls={infoId}\n onClick={() => setIsInfoExpanded(!isInfoExpanded)}\n >\n {CTAIconComponent && <CTAIconComponent className=\"label\" />}\n <span>{!isInfoExpanded ? ctaLabel : closeLabel}</span>\n </button>\n )}\n {info && (\n <div id={infoId} className={isInfoExpanded ? \"info active\" : \"info\"}>\n <p className=\"title\">{title}</p>\n <div\n className=\"content\"\n dangerouslySetInnerHTML={{ __html: content || \"\" }}\n ></div>\n </div>\n )}\n </>\n );\n};\n\nexport default Notification;\n"],"mappings":"A,4GAYA,MAAMQ,GAAgB,CAAEC,kBAAsC,CAC5D,GAAM,CAACC,EAAgBC,IAAA,EAAqBX,EAAAA,SAAAA,CAAS,EAAK,EACpDY,GAAA,EAASX,EAAAA,MAAAA,CAAM,EAEf,CAAEY,OAAMC,UAASC,MAAKC,QAASP,GAAgB,CAAC,EAChD,CAAE,KAAMQ,EAAS,MAAOC,EAAU,KAAMC,GAAYJ,GAAO,CAAC,EAC5D,CAAEK,QAAOC,UAASC,cAAeN,GAAQ,CAAC,EAE1CO,EAAgBrB,EAAAA,iBAAiBW,GAAQ,GAAIV,EAAAA,KAAK,EAGlDqB,EAAmBtB,EAAAA,kBADFQ,EAAiB,QAAUO,IACU,GAAIb,EAAAA,QAAQ,EAExE,MACC,iBAAA,EAAAG,EAAA,KAAA,CAAAA,EAAA,SAAA,CAAA,SAAA,CACIgB,EAAgB,iBAAA,EAAAhB,EAAA,IAAA,CAACgB,EAAD,CAAe,UAAU,MAAQ,CAAA,EAAI,KACtD,iBAAA,EAAAhB,EAAA,IAAA,CAAC,IAAD,CAAG,UAAU,UAAW,SAAAO,CAAW,CAAA,EAElCK,GACC,iBAAA,EAAAZ,EAAA,KAAA,CAAC,IAAD,CAAG,UAAU,MAAM,KAAMY,EAAzB,SAAA,CACGK,GAAoB,iBAAA,EAAAjB,EAAA,IAAA,CAACiB,EAAD,CAAkB,UAAU,OAAS,CAAA,EAC1D,iBAAA,EAAAjB,EAAA,IAAA,CAAC,OAAD,CAAA,SAAOW,CAAe,CAAA,CACrB,C,GAGJF,GAAQ,CAACG,GACR,iBAAA,EAAAZ,EAAA,KAAA,CAAC,SAAD,CACE,UAAU,MACV,gBAAeG,EACf,gBAAeE,EACf,YAAeD,EAAkB,CAACD,CAAc,EAJlD,SAAA,CAMGc,GAAoB,iBAAA,EAAAjB,EAAA,IAAA,CAACiB,EAAD,CAAkB,UAAU,OAAS,CAAA,EAC1D,iBAAA,EAAAjB,EAAA,IAAA,CAAC,OAAD,CAAA,SAAQG,EAA4BY,EAAXJ,CAA4B,CAAA,CAC/C,C,GAETF,GACC,iBAAA,EAAAT,EAAA,KAAA,CAAC,MAAD,CAAK,GAAIK,EAAQ,UAAWF,EAAiB,cAAgB,OAA7D,SAAA,CACE,iBAAA,EAAAH,EAAA,IAAA,CAAC,IAAD,CAAG,UAAU,QAAS,SAAAa,CAAS,CAAA,EAC/B,iBAAA,EAAAb,EAAA,IAAA,CAAC,MAAD,CACE,UAAU,UACV,wBAAyB,CAAE,OAAQc,GAAW,EAAG,CAC7C,CAAA,CACH,C,EAEL,CAAA,CAAA,CAER,E"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{useId as e,useState as t}from"react";import{CTAIcons as n,Icons as r,getIconComponent as i}from"../utils/icons.mjs";import{Fragment as a,jsx as o,jsxs as s}from"react/jsx-runtime";const c=({notification:c})=>{let[l,u]=t(!1),d=e(),{icon:f,message:p,cta:m,info:h}=c||{},{icon:g,label:_,link:v}=m||{},{title:y,content:b,closeLabel:x}=h||{},S=i(f||``,r),C=i((l?`cross`:g)||``,n);return/* @__PURE__ */ s(a,{children:[S?/* @__PURE__ */ o(S,{className:`icon`}):null,/* @__PURE__ */ o(`p`,{className:`message`,children:p}),v&&/* @__PURE__ */ s(`a`,{className:`CTA`,href:v,children:[C&&/* @__PURE__ */ o(C,{className:`label`}),/* @__PURE__ */ o(`span`,{children:_})]}),h&&!v&&/* @__PURE__ */ s(`button`,{className:`CTA`,"aria-expanded":l,"aria-controls":d,onClick:()=>u(!l),children:[C&&/* @__PURE__ */ o(C,{className:`label`}),/* @__PURE__ */ o(`span`,{children:l?x:_})]}),h&&/* @__PURE__ */ s(`div`,{id:d,className:l?`info active`:`info`,children:[/* @__PURE__ */ o(`p`,{className:`title`,children:y}),/* @__PURE__ */ o(`div`,{className:`content`,dangerouslySetInnerHTML:{__html:b||``}})]})]})};export{c as default};
|
|
2
|
+
//# sourceMappingURL=Notification.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Notification.mjs","names":["useId","useState","CTAIcons","Icons","getIconComponent","Fragment","jsx","jsxs","Notification","notification","isInfoExpanded","setIsInfoExpanded","infoId","icon","message","cta","info","ctaIcon","ctaLabel","ctaLink","title","content","closeLabel","IconComponent","CTAIconComponent"],"sources":["../../src/Notification/Notification.tsx"],"sourcesContent":["\"use client\"\nimport { useId, useState } from \"react\";\n\nimport { MagicPillNotification } from \"../types\";\n\nimport { getIconComponent, Icons, CTAIcons } from \"../utils/icons\";\n\ninterface NotificationProps {\n mode: \"notification\";\n notification: MagicPillNotification;\n}\n\nconst Notification = ({ notification }: NotificationProps) => {\n const [isInfoExpanded, setIsInfoExpanded] = useState(false);\n const infoId = useId();\n \n const { icon, message, cta, info } = notification || {};\n const { icon: ctaIcon, label: ctaLabel, link: ctaLink } = cta || {};\n const { title, content, closeLabel } = info || {};\n\n const IconComponent = getIconComponent(icon || \"\", Icons);\n\n const currentCTAIcon = isInfoExpanded ? \"cross\" : ctaIcon;\n const CTAIconComponent = getIconComponent(currentCTAIcon || \"\", CTAIcons);\n\n return (\n <>\n {IconComponent ? <IconComponent className=\"icon\" /> : null}\n <p className=\"message\">{message}</p>\n\n {ctaLink && (\n <a className=\"CTA\" href={ctaLink}>\n {CTAIconComponent && <CTAIconComponent className=\"label\" />}\n <span>{ctaLabel}</span>\n </a>\n )}\n\n {info && !ctaLink && (\n <button\n className=\"CTA\"\n aria-expanded={isInfoExpanded}\n aria-controls={infoId}\n onClick={() => setIsInfoExpanded(!isInfoExpanded)}\n >\n {CTAIconComponent && <CTAIconComponent className=\"label\" />}\n <span>{!isInfoExpanded ? ctaLabel : closeLabel}</span>\n </button>\n )}\n {info && (\n <div id={infoId} className={isInfoExpanded ? \"info active\" : \"info\"}>\n <p className=\"title\">{title}</p>\n <div\n className=\"content\"\n dangerouslySetInnerHTML={{ __html: content || \"\" }}\n ></div>\n </div>\n )}\n </>\n );\n};\n\nexport default Notification;\n"],"mappings":"A,wMAYA,MAAMQ,GAAgB,CAAEC,kBAAsC,CAC5D,GAAM,CAACC,EAAgBC,GAAqBV,EAAS,EAAK,EACpDW,EAASZ,EAAM,EAEf,CAAEa,OAAMC,UAASC,MAAKC,QAASP,GAAgB,CAAC,EAChD,CAAE,KAAMQ,EAAS,MAAOC,EAAU,KAAMC,GAAYJ,GAAO,CAAC,EAC5D,CAAEK,QAAOC,UAASC,cAAeN,GAAQ,CAAC,EAE1CO,EAAgBnB,EAAiBS,GAAQ,GAAIV,CAAK,EAGlDqB,EAAmBpB,GADFM,EAAiB,QAAUO,IACU,GAAIf,CAAQ,EAExE,MACCK,kBAAAF,EAAA,CAAA,SAAA,CACIkB,EAAgBjB,kBAACiB,EAAD,CAAe,UAAU,MAAQ,CAAA,EAAI,KACtDjB,kBAAC,IAAD,CAAG,UAAU,UAAW,SAAAQ,CAAW,CAAA,EAElCK,GACCZ,kBAAC,IAAD,CAAG,UAAU,MAAM,KAAMY,EAAzB,SAAA,CACGK,GAAoBlB,kBAACkB,EAAD,CAAkB,UAAU,OAAS,CAAA,EAC1DlB,kBAAC,OAAD,CAAA,SAAOY,CAAe,CAAA,CACrB,C,GAGJF,GAAQ,CAACG,GACRZ,kBAAC,SAAD,CACE,UAAU,MACV,gBAAeG,EACf,gBAAeE,EACf,YAAeD,EAAkB,CAACD,CAAc,EAJlD,SAAA,CAMGc,GAAoBlB,kBAACkB,EAAD,CAAkB,UAAU,OAAS,CAAA,EAC1DlB,kBAAC,OAAD,CAAA,SAAQI,EAA4BY,EAAXJ,CAA4B,CAAA,CAC/C,C,GAETF,GACCT,kBAAC,MAAD,CAAK,GAAIK,EAAQ,UAAWF,EAAiB,cAAgB,OAA7D,SAAA,CACEJ,kBAAC,IAAD,CAAG,UAAU,QAAS,SAAAc,CAAS,CAAA,EAC/Bd,kBAAC,MAAD,CACE,UAAU,UACV,wBAAyB,CAAE,OAAQe,GAAW,EAAG,CAC7C,CAAA,CACH,C,EAEL,CAAA,CAAA,CAER,E"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { MagicPillType } from "./types";
|
|
2
|
-
|
|
1
|
+
import { MagicPillType } from "./types/magicPill.js";
|
|
2
|
+
import "./types/index.js";
|
|
3
|
+
export declare const defaultPillData: MagicPillType;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const e={mode:`notification`,notification:{icon:`checkmark`,message:`Hey! I'm Magic Pill, your omnipotent toolbox!`,cta:{icon:`arrow`,label:`Discover what I can do`,link:void 0},info:{title:`I'm Magic Pill, let me empower you!`,content:`
|
|
2
|
+
<p>I'll appear sometimes, depending on context, either to send you notifications
|
|
3
|
+
regarding your experience on this website or to give you indications and hints
|
|
4
|
+
at what you can do!</p>
|
|
5
|
+
<p>See you around!</p>
|
|
6
|
+
`,closeLabel:`Close`}}};exports.defaultPillData=e;
|
|
7
|
+
//# sourceMappingURL=defaultPillData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultPillData.js","names":["defaultPillData"],"sources":["../src/defaultPillData.ts"],"sourcesContent":["import { MagicPillNotification, MagicPillType } from \"./types\";\n\nconst defaultPillDataNotification: MagicPillNotification = {\n icon: \"checkmark\",\n message: \"Hey! I'm Magic Pill, your omnipotent toolbox!\",\n cta: {\n icon: \"arrow\",\n label: \"Discover what I can do\",\n link: undefined, // No link by default\n },\n info: {\n title: \"I'm Magic Pill, let me empower you!\",\n content: `\n <p>I'll appear sometimes, depending on context, either to send you notifications \n regarding your experience on this website or to give you indications and hints \n at what you can do!</p>\n <p>See you around!</p>\n `,\n closeLabel: \"Close\",\n },\n};\n\nexport const defaultPillData: MagicPillType = {\n mode: \"notification\",\n notification: defaultPillDataNotification,\n};"],"mappings":"AAsBA,MAAaA,EAAiC,CAC5C,KAAM,eACN,aAAc,CArBd,KAAM,YACN,QAAS,gDACT,IAAK,CACH,KAAM,QACN,MAAO,yBACP,KAAM,IAAA,EACR,EACA,KAAM,CACJ,MAAO,sCACP,QAAS;;;;;MAMT,WAAY,OACd,CAKc,CAChB,E"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const e={mode:`notification`,notification:{icon:`checkmark`,message:`Hey! I'm Magic Pill, your omnipotent toolbox!`,cta:{icon:`arrow`,label:`Discover what I can do`,link:void 0},info:{title:`I'm Magic Pill, let me empower you!`,content:`
|
|
2
|
+
<p>I'll appear sometimes, depending on context, either to send you notifications
|
|
3
|
+
regarding your experience on this website or to give you indications and hints
|
|
4
|
+
at what you can do!</p>
|
|
5
|
+
<p>See you around!</p>
|
|
6
|
+
`,closeLabel:`Close`}}};export{e as defaultPillData};
|
|
7
|
+
//# sourceMappingURL=defaultPillData.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultPillData.mjs","names":["defaultPillData"],"sources":["../src/defaultPillData.ts"],"sourcesContent":["import { MagicPillNotification, MagicPillType } from \"./types\";\n\nconst defaultPillDataNotification: MagicPillNotification = {\n icon: \"checkmark\",\n message: \"Hey! I'm Magic Pill, your omnipotent toolbox!\",\n cta: {\n icon: \"arrow\",\n label: \"Discover what I can do\",\n link: undefined, // No link by default\n },\n info: {\n title: \"I'm Magic Pill, let me empower you!\",\n content: `\n <p>I'll appear sometimes, depending on context, either to send you notifications \n regarding your experience on this website or to give you indications and hints \n at what you can do!</p>\n <p>See you around!</p>\n `,\n closeLabel: \"Close\",\n },\n};\n\nexport const defaultPillData: MagicPillType = {\n mode: \"notification\",\n notification: defaultPillDataNotification,\n};"],"mappings":"AAsBA,MAAaA,EAAiC,CAC5C,KAAM,eACN,aAAc,CArBd,KAAM,YACN,QAAS,gDACT,IAAK,CACH,KAAM,QACN,MAAO,yBACP,KAAM,IAAA,EACR,EACA,KAAM,CACJ,MAAO,sCACP,QAAS;;;;;MAMT,WAAY,OACd,CAKc,CAChB,E"}
|