magic-pill 8.1.0 → 9.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/MIGRATING.md +224 -0
- package/README.md +312 -257
- package/dist/MagicPill/MagicPill.d.mts +27 -0
- package/dist/MagicPill/MagicPill.d.ts +27 -0
- package/dist/MagicPill/MagicPill.js +185 -0
- package/dist/MagicPill/MagicPill.mjs +185 -0
- package/dist/MagicPill/choreography.js +91 -0
- package/dist/MagicPill/choreography.mjs +85 -0
- package/dist/Pill/Pill.d.mts +7 -0
- package/dist/Pill/Pill.d.ts +7 -0
- package/dist/Pill/Pill.js +106 -0
- package/dist/Pill/Pill.mjs +106 -0
- package/dist/Pill/PillAction.d.mts +7 -0
- package/dist/Pill/PillAction.d.ts +7 -0
- package/dist/Pill/PillAction.js +67 -0
- package/dist/Pill/PillAction.mjs +67 -0
- package/dist/Pill/PillContext.d.mts +3 -0
- package/dist/Pill/PillContext.d.ts +3 -0
- package/dist/Pill/PillContext.js +26 -0
- package/dist/Pill/PillContext.mjs +24 -0
- package/dist/Pill/PillPanel.d.mts +9 -0
- package/dist/Pill/PillPanel.d.ts +9 -0
- package/dist/Pill/PillPanel.js +88 -0
- package/dist/Pill/PillPanel.mjs +87 -0
- package/dist/Pill/parts.d.mts +10 -0
- package/dist/Pill/parts.d.ts +10 -0
- package/dist/Pill/parts.js +46 -0
- package/dist/Pill/parts.mjs +43 -0
- package/dist/Pill/types.d.mts +88 -0
- package/dist/Pill/types.d.ts +88 -0
- package/dist/PillNavbar/PillNavbar.d.mts +31 -0
- package/dist/PillNavbar/PillNavbar.d.ts +31 -0
- package/dist/PillNavbar/PillNavbar.js +44 -0
- package/dist/PillNavbar/PillNavbar.mjs +44 -0
- package/dist/PillNavbar/matchPath.d.mts +2 -0
- package/dist/PillNavbar/matchPath.d.ts +2 -0
- package/dist/PillNavbar/matchPath.js +34 -0
- package/dist/PillNavbar/matchPath.mjs +34 -0
- package/dist/PillNotification/PillNotification.d.mts +51 -0
- package/dist/PillNotification/PillNotification.d.ts +51 -0
- package/dist/PillNotification/PillNotification.js +64 -0
- package/dist/PillNotification/PillNotification.mjs +63 -0
- package/dist/icons/ArrowIcon.d.mts +4 -0
- package/dist/icons/ArrowIcon.d.ts +4 -0
- package/dist/icons/ArrowIcon.js +21 -0
- package/dist/icons/ArrowIcon.mjs +21 -0
- package/dist/icons/BoxIcon.d.mts +4 -0
- package/dist/icons/BoxIcon.d.ts +4 -0
- package/dist/icons/BoxIcon.js +21 -0
- package/dist/icons/BoxIcon.mjs +21 -0
- package/dist/icons/CheckIcon.d.mts +4 -0
- package/dist/icons/CheckIcon.d.ts +4 -0
- package/dist/icons/CheckIcon.js +17 -0
- package/dist/icons/CheckIcon.mjs +17 -0
- package/dist/icons/CloseIcon.d.mts +4 -0
- package/dist/icons/CloseIcon.d.ts +4 -0
- package/dist/icons/CloseIcon.js +17 -0
- package/dist/icons/CloseIcon.mjs +17 -0
- package/dist/icons/CouponIcon.d.mts +4 -0
- package/dist/icons/CouponIcon.d.ts +4 -0
- package/dist/icons/CouponIcon.js +17 -0
- package/dist/icons/CouponIcon.mjs +17 -0
- package/dist/icons/DocumentIcon.d.mts +4 -0
- package/dist/icons/DocumentIcon.d.ts +4 -0
- package/dist/icons/DocumentIcon.js +17 -0
- package/dist/icons/DocumentIcon.mjs +17 -0
- package/dist/icons/HelpIcon.d.mts +4 -0
- package/dist/icons/HelpIcon.d.ts +4 -0
- package/dist/icons/HelpIcon.js +17 -0
- package/dist/icons/HelpIcon.mjs +17 -0
- package/dist/icons/InfoIcon.d.mts +4 -0
- package/dist/icons/InfoIcon.d.ts +4 -0
- package/dist/icons/InfoIcon.js +17 -0
- package/dist/icons/InfoIcon.mjs +17 -0
- package/dist/icons/MailIcon.d.mts +4 -0
- package/dist/icons/MailIcon.d.ts +4 -0
- package/dist/icons/MailIcon.js +17 -0
- package/dist/icons/MailIcon.mjs +17 -0
- package/dist/icons/PhoneIcon.d.mts +4 -0
- package/dist/icons/PhoneIcon.d.ts +4 -0
- package/dist/icons/PhoneIcon.js +21 -0
- package/dist/icons/PhoneIcon.mjs +21 -0
- package/dist/icons/PlusIcon.d.mts +4 -0
- package/dist/icons/PlusIcon.d.ts +4 -0
- package/dist/icons/PlusIcon.js +17 -0
- package/dist/icons/PlusIcon.mjs +17 -0
- package/dist/icons/UndoIcon.d.mts +4 -0
- package/dist/icons/UndoIcon.d.ts +4 -0
- package/dist/icons/UndoIcon.js +21 -0
- package/dist/icons/UndoIcon.mjs +21 -0
- package/dist/icons/types.d.mts +3 -0
- package/dist/icons/types.d.ts +3 -0
- package/dist/index.d.mts +25 -8
- package/dist/index.d.ts +25 -9
- package/dist/index.js +50 -1
- package/dist/index.mjs +24 -1
- package/dist/store/store.d.mts +63 -0
- package/dist/store/store.d.ts +63 -0
- package/dist/store/store.js +104 -0
- package/dist/store/store.mjs +102 -0
- package/dist/store/usePillQueue.d.mts +6 -0
- package/dist/store/usePillQueue.d.ts +6 -0
- package/dist/store/usePillQueue.js +17 -0
- package/dist/store/usePillQueue.mjs +17 -0
- package/dist/styles.css +456 -0
- package/dist/utils/react.js +23 -0
- package/dist/utils/react.mjs +21 -0
- package/dist/utils/url.js +22 -0
- package/dist/utils/url.mjs +22 -0
- package/package.json +7 -4
- package/dist/MagicPill.d.mts +0 -6
- package/dist/MagicPill.d.ts +0 -7
- package/dist/MagicPill.js +0 -2
- package/dist/MagicPill.js.map +0 -1
- package/dist/MagicPill.mjs +0 -2
- package/dist/MagicPill.mjs.map +0 -1
- package/dist/Navbar/Navbar.js +0 -2
- package/dist/Navbar/Navbar.js.map +0 -1
- package/dist/Navbar/Navbar.mjs +0 -2
- package/dist/Navbar/Navbar.mjs.map +0 -1
- package/dist/Notification/Notification.js +0 -2
- package/dist/Notification/Notification.js.map +0 -1
- package/dist/Notification/Notification.mjs +0 -2
- package/dist/Notification/Notification.mjs.map +0 -1
- package/dist/defaultPillData.d.mts +0 -2
- package/dist/defaultPillData.d.ts +0 -3
- package/dist/defaultPillData.js +0 -7
- package/dist/defaultPillData.js.map +0 -1
- package/dist/defaultPillData.mjs +0 -7
- package/dist/defaultPillData.mjs.map +0 -1
- package/dist/icons/arrow_label.js +0 -2
- package/dist/icons/arrow_label.js.map +0 -1
- package/dist/icons/arrow_label.mjs +0 -2
- package/dist/icons/arrow_label.mjs.map +0 -1
- package/dist/icons/box_label.js +0 -2
- package/dist/icons/box_label.js.map +0 -1
- package/dist/icons/box_label.mjs +0 -2
- package/dist/icons/box_label.mjs.map +0 -1
- package/dist/icons/checkmark.js +0 -2
- package/dist/icons/checkmark.js.map +0 -1
- package/dist/icons/checkmark.mjs +0 -2
- package/dist/icons/checkmark.mjs.map +0 -1
- package/dist/icons/checkmark_label.js +0 -2
- package/dist/icons/checkmark_label.js.map +0 -1
- package/dist/icons/checkmark_label.mjs +0 -2
- package/dist/icons/checkmark_label.mjs.map +0 -1
- package/dist/icons/coupon.js +0 -2
- package/dist/icons/coupon.js.map +0 -1
- package/dist/icons/coupon.mjs +0 -2
- package/dist/icons/coupon.mjs.map +0 -1
- package/dist/icons/cross_label.js +0 -2
- package/dist/icons/cross_label.js.map +0 -1
- package/dist/icons/cross_label.mjs +0 -2
- package/dist/icons/cross_label.mjs.map +0 -1
- package/dist/icons/info.js +0 -2
- package/dist/icons/info.js.map +0 -1
- package/dist/icons/info.mjs +0 -2
- package/dist/icons/info.mjs.map +0 -1
- package/dist/icons/info_label.js +0 -2
- package/dist/icons/info_label.js.map +0 -1
- package/dist/icons/info_label.mjs +0 -2
- package/dist/icons/info_label.mjs.map +0 -1
- package/dist/icons/mail_label.js +0 -2
- package/dist/icons/mail_label.js.map +0 -1
- package/dist/icons/mail_label.mjs +0 -2
- package/dist/icons/mail_label.mjs.map +0 -1
- package/dist/icons/plus_label.js +0 -2
- package/dist/icons/plus_label.js.map +0 -1
- package/dist/icons/plus_label.mjs +0 -2
- package/dist/icons/plus_label.mjs.map +0 -1
- package/dist/icons/questionmark.js +0 -2
- package/dist/icons/questionmark.js.map +0 -1
- package/dist/icons/questionmark.mjs +0 -2
- package/dist/icons/questionmark.mjs.map +0 -1
- package/dist/icons/quotation_label.js +0 -2
- package/dist/icons/quotation_label.js.map +0 -1
- package/dist/icons/quotation_label.mjs +0 -2
- package/dist/icons/quotation_label.mjs.map +0 -1
- package/dist/icons/tel_label.js +0 -2
- package/dist/icons/tel_label.js.map +0 -1
- package/dist/icons/tel_label.mjs +0 -2
- package/dist/icons/tel_label.mjs.map +0 -1
- package/dist/icons/undo_label.js +0 -2
- package/dist/icons/undo_label.js.map +0 -1
- package/dist/icons/undo_label.mjs +0 -2
- package/dist/icons/undo_label.mjs.map +0 -1
- package/dist/magicpill.css +0 -315
- package/dist/types/index.d.ts +0 -4
- package/dist/types/magicPill.d.mts +0 -50
- package/dist/types/magicPill.d.ts +0 -50
- package/dist/types/navbar.d.mts +0 -27
- package/dist/types/navbar.d.ts +0 -28
- package/dist/types/notification.d.mts +0 -140
- package/dist/types/notification.d.ts +0 -141
- package/dist/utils/handlers.d.mts +0 -20
- package/dist/utils/handlers.d.ts +0 -21
- package/dist/utils/handlers.js +0 -2
- package/dist/utils/handlers.js.map +0 -1
- package/dist/utils/handlers.mjs +0 -2
- package/dist/utils/handlers.mjs.map +0 -1
- package/dist/utils/icons.d.mts +0 -20
- package/dist/utils/icons.d.ts +0 -20
- package/dist/utils/icons.js +0 -2
- package/dist/utils/icons.js.map +0 -1
- package/dist/utils/icons.mjs +0 -2
- package/dist/utils/icons.mjs.map +0 -1
package/dist/styles.css
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Magic Pill v9 styles.
|
|
3
|
+
*
|
|
4
|
+
* - Every rule sits in the `magic-pill` cascade layer: any CSS of yours that
|
|
5
|
+
* isn't in a layer wins, whatever its specificity, without !important.
|
|
6
|
+
* With Tailwind v4, declare the order once, before your imports:
|
|
7
|
+
* @layer theme, base, magic-pill, components, utilities;
|
|
8
|
+
* - Parts are selected by [data-mp="…"] and states by data attributes.
|
|
9
|
+
* There are no class names of ours to collide with yours.
|
|
10
|
+
* - No fonts are loaded. The pill uses your page's fonts; set --mp-font-text
|
|
11
|
+
* and --mp-font-accent for the Magic Pill look (Overlock + Lexend).
|
|
12
|
+
* - Public tokens (--mp-*) are only read, with fallbacks, never declared
|
|
13
|
+
* here: set them on :root, on one pill, or anywhere in between.
|
|
14
|
+
* Private values start with --_mp-.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
@layer magic-pill {
|
|
18
|
+
/* Behaviour comes last, so it beats the look whatever the specificity:
|
|
19
|
+
a closed panel or a hidden pill stays hidden even if a visual rule
|
|
20
|
+
sets a display. Your own unlayered CSS still beats both. */
|
|
21
|
+
@layer look, behaviour;
|
|
22
|
+
|
|
23
|
+
@layer behaviour {
|
|
24
|
+
/* ─── Behaviour: kept by `unstyled` pills ──────────────────────────────── */
|
|
25
|
+
|
|
26
|
+
/* Hidden: invisible once the exit transition is over. React also makes it inert. */
|
|
27
|
+
[data-mp="pill"][data-presence="hidden"] {
|
|
28
|
+
visibility: hidden;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/* A closed <dialog> stays closed, whatever display the pill uses */
|
|
32
|
+
dialog[data-mp="pill"]:not([open]) {
|
|
33
|
+
display: none;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/* Resting circle: only the leading icon remains, for everyone */
|
|
37
|
+
[data-mp="pill"][data-presence="rest"] > :not([data-mp="icon"]) {
|
|
38
|
+
visibility: hidden;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* The panel replaces the pill's content while it's open */
|
|
42
|
+
[data-mp="panel"]:not([data-open]),
|
|
43
|
+
[data-mp="pill"][data-presence="panel"] > :not([data-mp="panel"]) {
|
|
44
|
+
display: none;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@layer look {
|
|
49
|
+
/* ─── Look ─────────────────────────────────────────────────────────────── */
|
|
50
|
+
|
|
51
|
+
[data-mp="pill"]:not([data-unstyled]) {
|
|
52
|
+
--_mp-surface: var(--mp-surface, #141414);
|
|
53
|
+
--_mp-on-surface: var(--mp-on-surface, #f9f9f9);
|
|
54
|
+
--_mp-action: var(--mp-action, #f9f9f9);
|
|
55
|
+
--_mp-on-action: var(--mp-on-action, #141414);
|
|
56
|
+
--_mp-offset: var(--mp-offset, 1.5rem);
|
|
57
|
+
--_mp-padding: var(--mp-padding, 0.875rem);
|
|
58
|
+
--_mp-gap: var(--mp-gap, 1rem);
|
|
59
|
+
--_mp-action-size: var(--mp-action-size, 2.75rem);
|
|
60
|
+
--_mp-rest-size: calc(var(--_mp-action-size) + 2 * var(--_mp-padding));
|
|
61
|
+
--_mp-max-size: min(var(--mp-max-width, 48rem), 100%);
|
|
62
|
+
--_mp-enter: var(--mp-duration-enter, 500ms);
|
|
63
|
+
--_mp-exit: var(--mp-duration-exit, 300ms);
|
|
64
|
+
--_mp-change: var(--mp-duration-change, 250ms);
|
|
65
|
+
/* The entry overshoot from the mockups' "pop" */
|
|
66
|
+
--_mp-ease-enter: cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
67
|
+
|
|
68
|
+
box-sizing: border-box;
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
gap: var(--_mp-gap);
|
|
72
|
+
inline-size: fit-content;
|
|
73
|
+
min-block-size: var(--_mp-rest-size);
|
|
74
|
+
max-inline-size: var(--_mp-max-size);
|
|
75
|
+
margin: 0;
|
|
76
|
+
padding: var(--_mp-padding);
|
|
77
|
+
overflow: hidden;
|
|
78
|
+
border: 0;
|
|
79
|
+
border-radius: 9999px;
|
|
80
|
+
background: var(--_mp-surface);
|
|
81
|
+
color: var(--_mp-on-surface);
|
|
82
|
+
box-shadow: var(--mp-shadow, 0 0.5rem 0.5rem rgb(20 20 20 / 0.45));
|
|
83
|
+
font-family: var(--mp-font-text, inherit);
|
|
84
|
+
font-size: var(--mp-text-size, clamp(0.9375rem, 0.875rem + 0.25vw, 1.0625rem));
|
|
85
|
+
line-height: 1.3;
|
|
86
|
+
scale: 1;
|
|
87
|
+
/* Lets the width animate from its real size (fit-content) to the
|
|
88
|
+
circle's, where supported; elsewhere max-inline-size does the work */
|
|
89
|
+
interpolate-size: allow-keywords;
|
|
90
|
+
transition:
|
|
91
|
+
scale var(--_mp-enter) var(--_mp-ease-enter),
|
|
92
|
+
inline-size var(--_mp-change) ease-in-out,
|
|
93
|
+
block-size var(--_mp-change) ease-in-out,
|
|
94
|
+
max-inline-size var(--_mp-change) ease-in-out,
|
|
95
|
+
max-block-size var(--_mp-change) ease-in-out,
|
|
96
|
+
border-radius var(--_mp-change) ease-in-out,
|
|
97
|
+
padding var(--_mp-change) ease-in-out,
|
|
98
|
+
background-color var(--_mp-change) ease-in-out,
|
|
99
|
+
visibility 0s;
|
|
100
|
+
|
|
101
|
+
& *,
|
|
102
|
+
& *::before,
|
|
103
|
+
& *::after {
|
|
104
|
+
box-sizing: border-box;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* Variants */
|
|
108
|
+
&[data-variant="success"] {
|
|
109
|
+
--_mp-surface: var(--mp-success, #3f7253);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/* Darker than 8.x's #fc5d6a, which had a 2.9:1 contrast with the light text */
|
|
113
|
+
&[data-variant="danger"] {
|
|
114
|
+
--_mp-surface: var(--mp-danger, #c2303e);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* Presence levels */
|
|
118
|
+
&[data-presence="hidden"] {
|
|
119
|
+
scale: 0;
|
|
120
|
+
inline-size: var(--_mp-rest-size);
|
|
121
|
+
max-inline-size: var(--_mp-rest-size);
|
|
122
|
+
max-block-size: var(--_mp-rest-size);
|
|
123
|
+
/* Shrink to a circle, then scale out, then stop being visible */
|
|
124
|
+
transition:
|
|
125
|
+
scale var(--_mp-exit) ease-in var(--_mp-change),
|
|
126
|
+
inline-size var(--_mp-change) ease-in-out,
|
|
127
|
+
block-size var(--_mp-change) ease-in-out,
|
|
128
|
+
max-inline-size var(--_mp-change) ease-in-out,
|
|
129
|
+
max-block-size var(--_mp-change) ease-in-out,
|
|
130
|
+
border-radius var(--_mp-change) ease-in-out,
|
|
131
|
+
padding var(--_mp-change) ease-in-out,
|
|
132
|
+
background-color var(--_mp-change) ease-in-out,
|
|
133
|
+
visibility 0s linear calc(var(--_mp-change) + var(--_mp-exit));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* A circle: both axes clamped, whatever the hidden content would need */
|
|
137
|
+
&[data-presence="rest"] {
|
|
138
|
+
inline-size: var(--_mp-rest-size);
|
|
139
|
+
max-inline-size: var(--_mp-rest-size);
|
|
140
|
+
max-block-size: var(--_mp-rest-size);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* The content stays while the pill closes over it, then hides. The
|
|
144
|
+
message unwraps at once when the pill shrinks, and may wrap again
|
|
145
|
+
only once the pill has grown (a discrete transition, where supported) */
|
|
146
|
+
& > :not([data-mp="icon"], [data-mp="panel"]) {
|
|
147
|
+
transition:
|
|
148
|
+
visibility 0s,
|
|
149
|
+
white-space 0s linear var(--_mp-change);
|
|
150
|
+
transition-behavior: allow-discrete;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
&:is([data-presence="rest"], [data-presence="hidden"]) > :not([data-mp="icon"], [data-mp="panel"]) {
|
|
154
|
+
transition:
|
|
155
|
+
visibility 0s linear var(--_mp-change),
|
|
156
|
+
white-space 0s;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
&:is([data-presence="rest"], [data-presence="hidden"]) > [data-mp="message"] {
|
|
160
|
+
white-space: nowrap;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
&[data-presence="panel"] {
|
|
164
|
+
--_mp-max-size: min(var(--mp-panel-width, 32rem), 100%);
|
|
165
|
+
display: block;
|
|
166
|
+
max-block-size: calc(100dvh - 2 * var(--_mp-offset));
|
|
167
|
+
padding: calc(var(--_mp-padding) * 2.5);
|
|
168
|
+
overflow-y: auto;
|
|
169
|
+
border-radius: var(--mp-radius-panel, 2.5rem);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/* Placements: fixed ones stay inside the viewport and its safe areas */
|
|
173
|
+
&:not([data-placement="inline"]) {
|
|
174
|
+
--_mp-max-size: min(var(--mp-max-width, 48rem), 100vw - 2 * var(--_mp-offset));
|
|
175
|
+
position: fixed;
|
|
176
|
+
z-index: var(--mp-z-index, 50);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
&[data-presence="panel"]:not([data-placement="inline"]) {
|
|
180
|
+
--_mp-max-size: min(var(--mp-panel-width, 32rem), 100vw - 2 * var(--_mp-offset));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
&[data-placement^="top"] {
|
|
184
|
+
inset-block-start: calc(var(--_mp-offset) + env(safe-area-inset-top, 0px));
|
|
185
|
+
transform-origin: top;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
&[data-placement^="bottom"] {
|
|
189
|
+
inset-block-end: calc(var(--_mp-offset) + env(safe-area-inset-bottom, 0px));
|
|
190
|
+
transform-origin: bottom;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/* Centred with auto margins, not left: 50% + translate, which would
|
|
194
|
+
leave the pill only half the viewport to size itself in */
|
|
195
|
+
&[data-placement="top"],
|
|
196
|
+
&[data-placement="bottom"] {
|
|
197
|
+
inset-inline: 0;
|
|
198
|
+
margin-inline: auto;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
&[data-placement$="-start"] {
|
|
202
|
+
inset-inline-start: var(--_mp-offset);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
&[data-placement$="-end"] {
|
|
206
|
+
inset-inline-end: var(--_mp-offset);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
&[data-placement="left"],
|
|
210
|
+
&[data-placement="right"] {
|
|
211
|
+
inset-block: 0;
|
|
212
|
+
margin-block: auto;
|
|
213
|
+
block-size: fit-content;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
&[data-placement="left"] {
|
|
217
|
+
left: calc(var(--_mp-offset) + env(safe-area-inset-left, 0px));
|
|
218
|
+
transform-origin: left;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
&[data-placement="right"] {
|
|
222
|
+
right: calc(var(--_mp-offset) + env(safe-area-inset-right, 0px));
|
|
223
|
+
transform-origin: right;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
&[data-placement="overlay"] {
|
|
227
|
+
inset: 0;
|
|
228
|
+
margin: auto;
|
|
229
|
+
block-size: fit-content;
|
|
230
|
+
max-block-size: calc(100dvh - 2 * var(--_mp-offset));
|
|
231
|
+
|
|
232
|
+
&::backdrop {
|
|
233
|
+
background: var(--mp-backdrop, rgb(20 20 20 / 0.4));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* Vertical pills (sidebars) */
|
|
238
|
+
&[data-orientation="vertical"] {
|
|
239
|
+
flex-direction: column;
|
|
240
|
+
inline-size: auto;
|
|
241
|
+
block-size: fit-content;
|
|
242
|
+
max-inline-size: none;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
&[data-orientation="vertical"]:not([data-presence="rest"], [data-presence="hidden"]) {
|
|
246
|
+
max-block-size: calc(100dvh - 2 * var(--_mp-offset));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
&[data-orientation="vertical"]:is([data-presence="rest"], [data-presence="hidden"]) {
|
|
250
|
+
block-size: var(--_mp-rest-size);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/* Parts */
|
|
254
|
+
& [data-mp="icon"] {
|
|
255
|
+
flex: none;
|
|
256
|
+
display: grid;
|
|
257
|
+
place-items: center;
|
|
258
|
+
inline-size: var(--_mp-action-size);
|
|
259
|
+
block-size: var(--_mp-action-size);
|
|
260
|
+
font-size: calc(var(--_mp-action-size) * 0.6);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
& [data-mp="divider"] {
|
|
264
|
+
flex: none;
|
|
265
|
+
align-self: center;
|
|
266
|
+
inline-size: 1px;
|
|
267
|
+
block-size: var(--_mp-action-size);
|
|
268
|
+
background: currentColor;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
&[data-orientation="vertical"] [data-mp="divider"] {
|
|
272
|
+
inline-size: var(--_mp-action-size);
|
|
273
|
+
block-size: 1px;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/* Its own width up to a cap, and it wraps when space runs out (phones,
|
|
277
|
+
narrow containers). While the pill grows it stays on one line (see
|
|
278
|
+
the presence rules), so the pill reveals it instead of it reflowing
|
|
279
|
+
word by word */
|
|
280
|
+
& [data-mp="message"] {
|
|
281
|
+
flex: 0 1 auto;
|
|
282
|
+
min-inline-size: 0;
|
|
283
|
+
inline-size: max-content;
|
|
284
|
+
max-inline-size: var(--mp-message-width, 24rem);
|
|
285
|
+
font-style: italic;
|
|
286
|
+
text-wrap-style: balance;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
& [data-mp="actions"] {
|
|
290
|
+
flex: none;
|
|
291
|
+
display: flex;
|
|
292
|
+
align-items: center;
|
|
293
|
+
gap: calc(var(--_mp-gap) * 0.75);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
&[data-orientation="vertical"] [data-mp="actions"] {
|
|
297
|
+
flex-direction: column;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/* The <a>/<button> stays neutral and the look lives on its inner body:
|
|
301
|
+
an app's global resets (a { color: inherit }, button { background:
|
|
302
|
+
none; padding: 0 }…) are unlayered, so they'd beat this layer on
|
|
303
|
+
the element, but they don't reach the body */
|
|
304
|
+
& [data-mp="action"] {
|
|
305
|
+
appearance: none;
|
|
306
|
+
flex: none;
|
|
307
|
+
display: inline-flex;
|
|
308
|
+
margin: 0;
|
|
309
|
+
padding: 0;
|
|
310
|
+
border: 0;
|
|
311
|
+
border-radius: 9999px;
|
|
312
|
+
background: transparent;
|
|
313
|
+
color: inherit;
|
|
314
|
+
font: inherit;
|
|
315
|
+
text-decoration: none;
|
|
316
|
+
cursor: pointer;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
& [data-mp="action-body"] {
|
|
320
|
+
display: inline-flex;
|
|
321
|
+
align-items: center;
|
|
322
|
+
block-size: var(--_mp-action-size);
|
|
323
|
+
min-inline-size: var(--_mp-action-size);
|
|
324
|
+
padding-inline: calc((var(--_mp-action-size) - 1.25rem) / 2);
|
|
325
|
+
overflow: hidden;
|
|
326
|
+
border-radius: 9999px;
|
|
327
|
+
background: var(--_mp-action);
|
|
328
|
+
color: var(--_mp-on-action);
|
|
329
|
+
font-family: var(--mp-font-accent, inherit);
|
|
330
|
+
font-style: normal;
|
|
331
|
+
font-weight: 700;
|
|
332
|
+
white-space: nowrap;
|
|
333
|
+
transition: padding var(--_mp-change) ease-in-out;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
& [data-mp="action"]:focus-visible {
|
|
337
|
+
outline: 2px solid var(--_mp-on-surface);
|
|
338
|
+
outline-offset: 2px;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
& [data-mp="action"][aria-disabled="true"] {
|
|
342
|
+
cursor: not-allowed;
|
|
343
|
+
opacity: 0.6;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
& [data-mp="action-icon"] {
|
|
347
|
+
flex: none;
|
|
348
|
+
display: grid;
|
|
349
|
+
place-items: center;
|
|
350
|
+
inline-size: 1.25rem;
|
|
351
|
+
block-size: 1.25rem;
|
|
352
|
+
font-size: 1.25rem;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
& [data-mp="icon"] > svg,
|
|
356
|
+
& [data-mp="action-icon"] > svg {
|
|
357
|
+
inline-size: 1em;
|
|
358
|
+
block-size: 1em;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/* Labels: folded away (but still the accessible name) until expanded */
|
|
362
|
+
& [data-mp="label"] {
|
|
363
|
+
max-inline-size: 0;
|
|
364
|
+
opacity: 0;
|
|
365
|
+
transition:
|
|
366
|
+
max-inline-size var(--_mp-change) ease-in-out,
|
|
367
|
+
opacity var(--_mp-change) ease-in-out,
|
|
368
|
+
margin var(--_mp-change) ease-in-out;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
& [data-mp="action"]:is(:hover, :focus-visible, [data-expanded], [aria-current="page"], [aria-current="true"]),
|
|
372
|
+
&:is([data-presence="expanded"], [data-presence="panel"]) [data-mp="action"] {
|
|
373
|
+
& [data-mp="action-body"] {
|
|
374
|
+
padding-inline-end: calc(var(--_mp-action-size) / 2.5);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
& [data-mp="label"] {
|
|
378
|
+
max-inline-size: 20rem;
|
|
379
|
+
opacity: 1;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
& [data-mp="action-icon"] + [data-mp="label"] {
|
|
383
|
+
margin-inline-start: 0.5rem;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/* Panel */
|
|
388
|
+
& [data-mp="panel"] {
|
|
389
|
+
display: grid;
|
|
390
|
+
gap: var(--_mp-gap);
|
|
391
|
+
outline: none;
|
|
392
|
+
opacity: 1;
|
|
393
|
+
transition: opacity var(--_mp-change) ease-out var(--_mp-change);
|
|
394
|
+
|
|
395
|
+
@starting-style {
|
|
396
|
+
opacity: 0;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
& [data-mp="panel-title"] {
|
|
401
|
+
font-size: var(--mp-title-size, clamp(1.5rem, 1.25rem + 1vw, 2rem));
|
|
402
|
+
font-style: italic;
|
|
403
|
+
font-weight: 900;
|
|
404
|
+
line-height: 1.15;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
& [data-mp="panel-body"] {
|
|
408
|
+
font-style: italic;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/* Stays in reach when a long panel scrolls */
|
|
412
|
+
& [data-mp="panel-footer"] {
|
|
413
|
+
position: sticky;
|
|
414
|
+
inset-block-end: 0;
|
|
415
|
+
display: flex;
|
|
416
|
+
justify-content: center;
|
|
417
|
+
padding-block-start: var(--_mp-gap);
|
|
418
|
+
background: linear-gradient(transparent, var(--_mp-surface) 50%);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/* ─── Preferences ──────────────────────────────────────────────────────── */
|
|
423
|
+
|
|
424
|
+
/* Reduced motion: short fades instead of scaling and resizing */
|
|
425
|
+
@media (prefers-reduced-motion: reduce) {
|
|
426
|
+
[data-mp="pill"]:not([data-unstyled]) {
|
|
427
|
+
transition:
|
|
428
|
+
opacity 150ms linear,
|
|
429
|
+
visibility 0s;
|
|
430
|
+
|
|
431
|
+
&[data-presence="hidden"] {
|
|
432
|
+
scale: 1;
|
|
433
|
+
opacity: 0;
|
|
434
|
+
transition:
|
|
435
|
+
opacity 150ms linear,
|
|
436
|
+
visibility 0s linear 150ms;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
& [data-mp="label"],
|
|
440
|
+
& [data-mp="action-body"],
|
|
441
|
+
& [data-mp="message"],
|
|
442
|
+
& [data-mp="panel"] {
|
|
443
|
+
transition: none;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/* Forced colours (e.g. Windows High Contrast): keep the shapes visible */
|
|
449
|
+
@media (forced-colors: active) {
|
|
450
|
+
[data-mp="pill"]:not([data-unstyled]),
|
|
451
|
+
[data-mp="pill"]:not([data-unstyled]) [data-mp="action-body"] {
|
|
452
|
+
border: 1px solid CanvasText;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
let react = require("react");
|
|
2
|
+
|
|
3
|
+
// src/utils/react.ts
|
|
4
|
+
/** Warn in development builds only. */
|
|
5
|
+
function devWarn(message) {
|
|
6
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") console.warn(`[magic-pill] ${message}`);
|
|
7
|
+
}
|
|
8
|
+
const INERT_VALUE = Number.parseInt(react.version, 10) >= 19 ? true : "";
|
|
9
|
+
/** Spread on an element to make it inert (unfocusable, hidden from assistive technology). */
|
|
10
|
+
function inertProps(inert) {
|
|
11
|
+
return inert ? { inert: INERT_VALUE } : {};
|
|
12
|
+
}
|
|
13
|
+
/** Combine refs (React 18 compatible: no ref cleanup functions). */
|
|
14
|
+
function mergeRefs(...refs) {
|
|
15
|
+
return (node) => {
|
|
16
|
+
for (const ref of refs) if (typeof ref === "function") ref(node);
|
|
17
|
+
else if (ref) ref.current = node;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.devWarn = devWarn;
|
|
22
|
+
exports.inertProps = inertProps;
|
|
23
|
+
exports.mergeRefs = mergeRefs;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { version } from "react";
|
|
2
|
+
|
|
3
|
+
// src/utils/react.ts
|
|
4
|
+
/** Warn in development builds only. */
|
|
5
|
+
function devWarn(message) {
|
|
6
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") console.warn(`[magic-pill] ${message}`);
|
|
7
|
+
}
|
|
8
|
+
const INERT_VALUE = Number.parseInt(version, 10) >= 19 ? true : "";
|
|
9
|
+
/** Spread on an element to make it inert (unfocusable, hidden from assistive technology). */
|
|
10
|
+
function inertProps(inert) {
|
|
11
|
+
return inert ? { inert: INERT_VALUE } : {};
|
|
12
|
+
}
|
|
13
|
+
/** Combine refs (React 18 compatible: no ref cleanup functions). */
|
|
14
|
+
function mergeRefs(...refs) {
|
|
15
|
+
return (node) => {
|
|
16
|
+
for (const ref of refs) if (typeof ref === "function") ref(node);
|
|
17
|
+
else if (ref) ref.current = node;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { devWarn, inertProps, mergeRefs };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/utils/url.ts
|
|
2
|
+
const ALLOWED_SCHEMES = /* @__PURE__ */ new Set([
|
|
3
|
+
"http",
|
|
4
|
+
"https",
|
|
5
|
+
"mailto",
|
|
6
|
+
"tel"
|
|
7
|
+
]);
|
|
8
|
+
/**
|
|
9
|
+
* Whether an href is safe to render: relative URLs (including `#…`, `?…`
|
|
10
|
+
* and `//host`), or absolute URLs with an `http(s):`, `mailto:` or `tel:` scheme.
|
|
11
|
+
*
|
|
12
|
+
* It normalises the URL the way browsers do before reading the scheme
|
|
13
|
+
* (leading spaces and control characters dropped, tabs and newlines removed),
|
|
14
|
+
* so `" java\tscript:…"` is caught too.
|
|
15
|
+
*/
|
|
16
|
+
function isSafeHref(href) {
|
|
17
|
+
const normalised = href.replace(/^[\x00-\x20]+/, "").replace(/[\t\n\r]/g, "");
|
|
18
|
+
const scheme = /^([a-z][a-z\d+.-]*):/i.exec(normalised);
|
|
19
|
+
return scheme === null || ALLOWED_SCHEMES.has(scheme[1].toLowerCase());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.isSafeHref = isSafeHref;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/utils/url.ts
|
|
2
|
+
const ALLOWED_SCHEMES = /* @__PURE__ */ new Set([
|
|
3
|
+
"http",
|
|
4
|
+
"https",
|
|
5
|
+
"mailto",
|
|
6
|
+
"tel"
|
|
7
|
+
]);
|
|
8
|
+
/**
|
|
9
|
+
* Whether an href is safe to render: relative URLs (including `#…`, `?…`
|
|
10
|
+
* and `//host`), or absolute URLs with an `http(s):`, `mailto:` or `tel:` scheme.
|
|
11
|
+
*
|
|
12
|
+
* It normalises the URL the way browsers do before reading the scheme
|
|
13
|
+
* (leading spaces and control characters dropped, tabs and newlines removed),
|
|
14
|
+
* so `" java\tscript:…"` is caught too.
|
|
15
|
+
*/
|
|
16
|
+
function isSafeHref(href) {
|
|
17
|
+
const normalised = href.replace(/^[\x00-\x20]+/, "").replace(/[\t\n\r]/g, "");
|
|
18
|
+
const scheme = /^([a-z][a-z\d+.-]*):/i.exec(normalised);
|
|
19
|
+
return scheme === null || ALLOWED_SCHEMES.has(scheme[1].toLowerCase());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { isSafeHref };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magic-pill",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-next.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
"default": "./dist/index.js"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
-
"./
|
|
20
|
-
"./
|
|
19
|
+
"./styles.css": "./dist/styles.css",
|
|
20
|
+
"./magicpill.css": "./dist/styles.css",
|
|
21
|
+
"./dist/magicpill.css": "./dist/styles.css",
|
|
21
22
|
"./package.json": "./package.json"
|
|
22
23
|
},
|
|
23
24
|
"sideEffects": [
|
|
@@ -32,7 +33,8 @@
|
|
|
32
33
|
"build": "tsdown",
|
|
33
34
|
"prepare": "npm run build",
|
|
34
35
|
"typecheck": "tsc --noEmit",
|
|
35
|
-
"test": "vitest run"
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"size": "node scripts/size.mjs"
|
|
36
38
|
},
|
|
37
39
|
"peerDependencies": {
|
|
38
40
|
"react": ">=18.0.0",
|
|
@@ -73,6 +75,7 @@
|
|
|
73
75
|
"files": [
|
|
74
76
|
"dist",
|
|
75
77
|
"CHANGELOG.md",
|
|
78
|
+
"MIGRATING.md",
|
|
76
79
|
"LICENSE.md",
|
|
77
80
|
"NOTICE.md"
|
|
78
81
|
]
|
package/dist/MagicPill.d.mts
DELETED
package/dist/MagicPill.d.ts
DELETED
package/dist/MagicPill.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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
|
package/dist/MagicPill.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/MagicPill.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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
|
package/dist/MagicPill.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/Navbar/Navbar.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/Navbar/Navbar.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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
|