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.
Files changed (207) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/MIGRATING.md +224 -0
  3. package/README.md +312 -257
  4. package/dist/MagicPill/MagicPill.d.mts +27 -0
  5. package/dist/MagicPill/MagicPill.d.ts +27 -0
  6. package/dist/MagicPill/MagicPill.js +185 -0
  7. package/dist/MagicPill/MagicPill.mjs +185 -0
  8. package/dist/MagicPill/choreography.js +91 -0
  9. package/dist/MagicPill/choreography.mjs +85 -0
  10. package/dist/Pill/Pill.d.mts +7 -0
  11. package/dist/Pill/Pill.d.ts +7 -0
  12. package/dist/Pill/Pill.js +106 -0
  13. package/dist/Pill/Pill.mjs +106 -0
  14. package/dist/Pill/PillAction.d.mts +7 -0
  15. package/dist/Pill/PillAction.d.ts +7 -0
  16. package/dist/Pill/PillAction.js +67 -0
  17. package/dist/Pill/PillAction.mjs +67 -0
  18. package/dist/Pill/PillContext.d.mts +3 -0
  19. package/dist/Pill/PillContext.d.ts +3 -0
  20. package/dist/Pill/PillContext.js +26 -0
  21. package/dist/Pill/PillContext.mjs +24 -0
  22. package/dist/Pill/PillPanel.d.mts +9 -0
  23. package/dist/Pill/PillPanel.d.ts +9 -0
  24. package/dist/Pill/PillPanel.js +88 -0
  25. package/dist/Pill/PillPanel.mjs +87 -0
  26. package/dist/Pill/parts.d.mts +10 -0
  27. package/dist/Pill/parts.d.ts +10 -0
  28. package/dist/Pill/parts.js +46 -0
  29. package/dist/Pill/parts.mjs +43 -0
  30. package/dist/Pill/types.d.mts +88 -0
  31. package/dist/Pill/types.d.ts +88 -0
  32. package/dist/PillNavbar/PillNavbar.d.mts +31 -0
  33. package/dist/PillNavbar/PillNavbar.d.ts +31 -0
  34. package/dist/PillNavbar/PillNavbar.js +44 -0
  35. package/dist/PillNavbar/PillNavbar.mjs +44 -0
  36. package/dist/PillNavbar/matchPath.d.mts +2 -0
  37. package/dist/PillNavbar/matchPath.d.ts +2 -0
  38. package/dist/PillNavbar/matchPath.js +34 -0
  39. package/dist/PillNavbar/matchPath.mjs +34 -0
  40. package/dist/PillNotification/PillNotification.d.mts +51 -0
  41. package/dist/PillNotification/PillNotification.d.ts +51 -0
  42. package/dist/PillNotification/PillNotification.js +64 -0
  43. package/dist/PillNotification/PillNotification.mjs +63 -0
  44. package/dist/icons/ArrowIcon.d.mts +4 -0
  45. package/dist/icons/ArrowIcon.d.ts +4 -0
  46. package/dist/icons/ArrowIcon.js +21 -0
  47. package/dist/icons/ArrowIcon.mjs +21 -0
  48. package/dist/icons/BoxIcon.d.mts +4 -0
  49. package/dist/icons/BoxIcon.d.ts +4 -0
  50. package/dist/icons/BoxIcon.js +21 -0
  51. package/dist/icons/BoxIcon.mjs +21 -0
  52. package/dist/icons/CheckIcon.d.mts +4 -0
  53. package/dist/icons/CheckIcon.d.ts +4 -0
  54. package/dist/icons/CheckIcon.js +17 -0
  55. package/dist/icons/CheckIcon.mjs +17 -0
  56. package/dist/icons/CloseIcon.d.mts +4 -0
  57. package/dist/icons/CloseIcon.d.ts +4 -0
  58. package/dist/icons/CloseIcon.js +17 -0
  59. package/dist/icons/CloseIcon.mjs +17 -0
  60. package/dist/icons/CouponIcon.d.mts +4 -0
  61. package/dist/icons/CouponIcon.d.ts +4 -0
  62. package/dist/icons/CouponIcon.js +17 -0
  63. package/dist/icons/CouponIcon.mjs +17 -0
  64. package/dist/icons/DocumentIcon.d.mts +4 -0
  65. package/dist/icons/DocumentIcon.d.ts +4 -0
  66. package/dist/icons/DocumentIcon.js +17 -0
  67. package/dist/icons/DocumentIcon.mjs +17 -0
  68. package/dist/icons/HelpIcon.d.mts +4 -0
  69. package/dist/icons/HelpIcon.d.ts +4 -0
  70. package/dist/icons/HelpIcon.js +17 -0
  71. package/dist/icons/HelpIcon.mjs +17 -0
  72. package/dist/icons/InfoIcon.d.mts +4 -0
  73. package/dist/icons/InfoIcon.d.ts +4 -0
  74. package/dist/icons/InfoIcon.js +17 -0
  75. package/dist/icons/InfoIcon.mjs +17 -0
  76. package/dist/icons/MailIcon.d.mts +4 -0
  77. package/dist/icons/MailIcon.d.ts +4 -0
  78. package/dist/icons/MailIcon.js +17 -0
  79. package/dist/icons/MailIcon.mjs +17 -0
  80. package/dist/icons/PhoneIcon.d.mts +4 -0
  81. package/dist/icons/PhoneIcon.d.ts +4 -0
  82. package/dist/icons/PhoneIcon.js +21 -0
  83. package/dist/icons/PhoneIcon.mjs +21 -0
  84. package/dist/icons/PlusIcon.d.mts +4 -0
  85. package/dist/icons/PlusIcon.d.ts +4 -0
  86. package/dist/icons/PlusIcon.js +17 -0
  87. package/dist/icons/PlusIcon.mjs +17 -0
  88. package/dist/icons/UndoIcon.d.mts +4 -0
  89. package/dist/icons/UndoIcon.d.ts +4 -0
  90. package/dist/icons/UndoIcon.js +21 -0
  91. package/dist/icons/UndoIcon.mjs +21 -0
  92. package/dist/icons/types.d.mts +3 -0
  93. package/dist/icons/types.d.ts +3 -0
  94. package/dist/index.d.mts +25 -8
  95. package/dist/index.d.ts +25 -9
  96. package/dist/index.js +50 -1
  97. package/dist/index.mjs +24 -1
  98. package/dist/store/store.d.mts +63 -0
  99. package/dist/store/store.d.ts +63 -0
  100. package/dist/store/store.js +104 -0
  101. package/dist/store/store.mjs +102 -0
  102. package/dist/store/usePillQueue.d.mts +6 -0
  103. package/dist/store/usePillQueue.d.ts +6 -0
  104. package/dist/store/usePillQueue.js +17 -0
  105. package/dist/store/usePillQueue.mjs +17 -0
  106. package/dist/styles.css +456 -0
  107. package/dist/utils/react.js +23 -0
  108. package/dist/utils/react.mjs +21 -0
  109. package/dist/utils/url.js +22 -0
  110. package/dist/utils/url.mjs +22 -0
  111. package/package.json +7 -4
  112. package/dist/MagicPill.d.mts +0 -6
  113. package/dist/MagicPill.d.ts +0 -7
  114. package/dist/MagicPill.js +0 -2
  115. package/dist/MagicPill.js.map +0 -1
  116. package/dist/MagicPill.mjs +0 -2
  117. package/dist/MagicPill.mjs.map +0 -1
  118. package/dist/Navbar/Navbar.js +0 -2
  119. package/dist/Navbar/Navbar.js.map +0 -1
  120. package/dist/Navbar/Navbar.mjs +0 -2
  121. package/dist/Navbar/Navbar.mjs.map +0 -1
  122. package/dist/Notification/Notification.js +0 -2
  123. package/dist/Notification/Notification.js.map +0 -1
  124. package/dist/Notification/Notification.mjs +0 -2
  125. package/dist/Notification/Notification.mjs.map +0 -1
  126. package/dist/defaultPillData.d.mts +0 -2
  127. package/dist/defaultPillData.d.ts +0 -3
  128. package/dist/defaultPillData.js +0 -7
  129. package/dist/defaultPillData.js.map +0 -1
  130. package/dist/defaultPillData.mjs +0 -7
  131. package/dist/defaultPillData.mjs.map +0 -1
  132. package/dist/icons/arrow_label.js +0 -2
  133. package/dist/icons/arrow_label.js.map +0 -1
  134. package/dist/icons/arrow_label.mjs +0 -2
  135. package/dist/icons/arrow_label.mjs.map +0 -1
  136. package/dist/icons/box_label.js +0 -2
  137. package/dist/icons/box_label.js.map +0 -1
  138. package/dist/icons/box_label.mjs +0 -2
  139. package/dist/icons/box_label.mjs.map +0 -1
  140. package/dist/icons/checkmark.js +0 -2
  141. package/dist/icons/checkmark.js.map +0 -1
  142. package/dist/icons/checkmark.mjs +0 -2
  143. package/dist/icons/checkmark.mjs.map +0 -1
  144. package/dist/icons/checkmark_label.js +0 -2
  145. package/dist/icons/checkmark_label.js.map +0 -1
  146. package/dist/icons/checkmark_label.mjs +0 -2
  147. package/dist/icons/checkmark_label.mjs.map +0 -1
  148. package/dist/icons/coupon.js +0 -2
  149. package/dist/icons/coupon.js.map +0 -1
  150. package/dist/icons/coupon.mjs +0 -2
  151. package/dist/icons/coupon.mjs.map +0 -1
  152. package/dist/icons/cross_label.js +0 -2
  153. package/dist/icons/cross_label.js.map +0 -1
  154. package/dist/icons/cross_label.mjs +0 -2
  155. package/dist/icons/cross_label.mjs.map +0 -1
  156. package/dist/icons/info.js +0 -2
  157. package/dist/icons/info.js.map +0 -1
  158. package/dist/icons/info.mjs +0 -2
  159. package/dist/icons/info.mjs.map +0 -1
  160. package/dist/icons/info_label.js +0 -2
  161. package/dist/icons/info_label.js.map +0 -1
  162. package/dist/icons/info_label.mjs +0 -2
  163. package/dist/icons/info_label.mjs.map +0 -1
  164. package/dist/icons/mail_label.js +0 -2
  165. package/dist/icons/mail_label.js.map +0 -1
  166. package/dist/icons/mail_label.mjs +0 -2
  167. package/dist/icons/mail_label.mjs.map +0 -1
  168. package/dist/icons/plus_label.js +0 -2
  169. package/dist/icons/plus_label.js.map +0 -1
  170. package/dist/icons/plus_label.mjs +0 -2
  171. package/dist/icons/plus_label.mjs.map +0 -1
  172. package/dist/icons/questionmark.js +0 -2
  173. package/dist/icons/questionmark.js.map +0 -1
  174. package/dist/icons/questionmark.mjs +0 -2
  175. package/dist/icons/questionmark.mjs.map +0 -1
  176. package/dist/icons/quotation_label.js +0 -2
  177. package/dist/icons/quotation_label.js.map +0 -1
  178. package/dist/icons/quotation_label.mjs +0 -2
  179. package/dist/icons/quotation_label.mjs.map +0 -1
  180. package/dist/icons/tel_label.js +0 -2
  181. package/dist/icons/tel_label.js.map +0 -1
  182. package/dist/icons/tel_label.mjs +0 -2
  183. package/dist/icons/tel_label.mjs.map +0 -1
  184. package/dist/icons/undo_label.js +0 -2
  185. package/dist/icons/undo_label.js.map +0 -1
  186. package/dist/icons/undo_label.mjs +0 -2
  187. package/dist/icons/undo_label.mjs.map +0 -1
  188. package/dist/magicpill.css +0 -315
  189. package/dist/types/index.d.ts +0 -4
  190. package/dist/types/magicPill.d.mts +0 -50
  191. package/dist/types/magicPill.d.ts +0 -50
  192. package/dist/types/navbar.d.mts +0 -27
  193. package/dist/types/navbar.d.ts +0 -28
  194. package/dist/types/notification.d.mts +0 -140
  195. package/dist/types/notification.d.ts +0 -141
  196. package/dist/utils/handlers.d.mts +0 -20
  197. package/dist/utils/handlers.d.ts +0 -21
  198. package/dist/utils/handlers.js +0 -2
  199. package/dist/utils/handlers.js.map +0 -1
  200. package/dist/utils/handlers.mjs +0 -2
  201. package/dist/utils/handlers.mjs.map +0 -1
  202. package/dist/utils/icons.d.mts +0 -20
  203. package/dist/utils/icons.d.ts +0 -20
  204. package/dist/utils/icons.js +0 -2
  205. package/dist/utils/icons.js.map +0 -1
  206. package/dist/utils/icons.mjs +0 -2
  207. package/dist/utils/icons.mjs.map +0 -1
@@ -0,0 +1,46 @@
1
+ let react = require("react");
2
+ let react_jsx_runtime = require("react/jsx-runtime");
3
+
4
+ // src/Pill/parts.tsx
5
+ /** The leading icon. Decorative (`aria-hidden`) unless you give it a `label`. */
6
+ const PillIcon = (0, react.forwardRef)(function PillIcon({ label, ...rest }, ref) {
7
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
8
+ ...label ? {
9
+ role: "img",
10
+ "aria-label": label
11
+ } : { "aria-hidden": true },
12
+ ...rest,
13
+ ref,
14
+ "data-mp": "icon"
15
+ });
16
+ });
17
+ /** The thin line between the icon and the message. */
18
+ const PillDivider = (0, react.forwardRef)(function PillDivider(props, ref) {
19
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
20
+ "aria-hidden": "true",
21
+ ...props,
22
+ ref,
23
+ "data-mp": "divider"
24
+ });
25
+ });
26
+ /** The message, in the italic serif. Accepts any content. */
27
+ const PillMessage = (0, react.forwardRef)(function PillMessage(props, ref) {
28
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
29
+ ...props,
30
+ ref,
31
+ "data-mp": "message"
32
+ });
33
+ });
34
+ /** A row (or a column, in a vertical pill) of actions. */
35
+ const PillActions = (0, react.forwardRef)(function PillActions(props, ref) {
36
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
37
+ ...props,
38
+ ref,
39
+ "data-mp": "actions"
40
+ });
41
+ });
42
+
43
+ exports.PillActions = PillActions;
44
+ exports.PillDivider = PillDivider;
45
+ exports.PillIcon = PillIcon;
46
+ exports.PillMessage = PillMessage;
@@ -0,0 +1,43 @@
1
+ import { forwardRef } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+
4
+ // src/Pill/parts.tsx
5
+ /** The leading icon. Decorative (`aria-hidden`) unless you give it a `label`. */
6
+ const PillIcon = forwardRef(function PillIcon({ label, ...rest }, ref) {
7
+ return /* @__PURE__ */ jsx("span", {
8
+ ...label ? {
9
+ role: "img",
10
+ "aria-label": label
11
+ } : { "aria-hidden": true },
12
+ ...rest,
13
+ ref,
14
+ "data-mp": "icon"
15
+ });
16
+ });
17
+ /** The thin line between the icon and the message. */
18
+ const PillDivider = forwardRef(function PillDivider(props, ref) {
19
+ return /* @__PURE__ */ jsx("span", {
20
+ "aria-hidden": "true",
21
+ ...props,
22
+ ref,
23
+ "data-mp": "divider"
24
+ });
25
+ });
26
+ /** The message, in the italic serif. Accepts any content. */
27
+ const PillMessage = forwardRef(function PillMessage(props, ref) {
28
+ return /* @__PURE__ */ jsx("div", {
29
+ ...props,
30
+ ref,
31
+ "data-mp": "message"
32
+ });
33
+ });
34
+ /** A row (or a column, in a vertical pill) of actions. */
35
+ const PillActions = forwardRef(function PillActions(props, ref) {
36
+ return /* @__PURE__ */ jsx("div", {
37
+ ...props,
38
+ ref,
39
+ "data-mp": "actions"
40
+ });
41
+ });
42
+
43
+ export { PillActions, PillDivider, PillIcon, PillMessage };
@@ -0,0 +1,88 @@
1
+ import { AnchorHTMLAttributes, ComponentPropsWithoutRef, ComponentType, ReactNode, Ref } from "react";
2
+ /**
3
+ * How much room the pill takes. The pill animates between levels.
4
+ * - `hidden`: not shown, and out of the accessibility tree
5
+ * - `rest`: a circle showing only the leading icon
6
+ * - `compact`: the pill; actions show their icon only
7
+ * - `expanded`: the pill; every action shows icon + label
8
+ * - `panel`: the pill grows into a panel showing its <PillPanel>
9
+ */
10
+ export type PillPresence = "hidden" | "rest" | "compact" | "expanded" | "panel";
11
+ /**
12
+ * Where the pill sits.
13
+ * - Edges are `position: fixed`; `start`/`end` follow the text direction.
14
+ * - `inline` stays in the normal page flow.
15
+ * - `overlay` is a modal: a native <dialog> opened with showModal().
16
+ */
17
+ export type PillPlacement = "top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "left" | "right" | "inline" | "overlay";
18
+ /** Defaults to `vertical` for `left`/`right`, `horizontal` everywhere else. */
19
+ export type PillOrientation = "horizontal" | "vertical";
20
+ /**
21
+ * Colour scheme. Any other string is written to `data-variant` so you can
22
+ * define your own: `[data-mp="pill"][data-variant="brand"] { --mp-surface: … }`.
23
+ */
24
+ export type PillVariant = "neutral" | "success" | "danger" | (string & {});
25
+ /**
26
+ * A component that renders a link from an `href`, such as Next's `Link`.
27
+ * React Router's `Link` takes `to`: wrap it.
28
+ */
29
+ export type LinkComponent = ComponentType<AnchorHTMLAttributes<HTMLAnchorElement> & {
30
+ href: string;
31
+ ref?: Ref<HTMLAnchorElement>;
32
+ }>;
33
+ export interface PillProps extends Omit<ComponentPropsWithoutRef<"div">, "children"> {
34
+ children?: ReactNode;
35
+ /** Controlled presence. */
36
+ presence?: PillPresence;
37
+ /** Uncontrolled initial presence. Default `compact`. */
38
+ defaultPresence?: PillPresence;
39
+ /** Called when the pill asks to change level (panel trigger, close button, Escape). */
40
+ onPresenceChange?: (presence: PillPresence) => void;
41
+ /** Default `inline`. */
42
+ placement?: PillPlacement;
43
+ orientation?: PillOrientation;
44
+ /** Default `neutral`. */
45
+ variant?: PillVariant;
46
+ /** Keeps the behaviour and the data attributes, drops the visual styles. */
47
+ unstyled?: boolean;
48
+ }
49
+ interface PillActionBase {
50
+ /** Shown at every level. */
51
+ icon?: ReactNode;
52
+ /**
53
+ * Always required: it's the accessible name when only the icon shows.
54
+ * Visible on hover and focus, when `aria-current`/`expanded` is set, or at
55
+ * the `expanded` and `panel` levels.
56
+ */
57
+ label: string;
58
+ /** Force the label to show. */
59
+ expanded?: boolean;
60
+ }
61
+ /** An action that runs code: renders a <button>. */
62
+ export interface PillButtonActionProps extends PillActionBase, Omit<ComponentPropsWithoutRef<"button">, "children"> {
63
+ href?: undefined;
64
+ }
65
+ /**
66
+ * An action that navigates: renders `linkComponent` (default <a>).
67
+ * Only relative, `http(s):`, `mailto:` and `tel:` URLs are rendered.
68
+ */
69
+ export interface PillLinkActionProps extends PillActionBase, Omit<ComponentPropsWithoutRef<"a">, "children" | "href"> {
70
+ href: string;
71
+ linkComponent?: LinkComponent;
72
+ }
73
+ export type PillActionProps = PillButtonActionProps | PillLinkActionProps;
74
+ export interface PillPanelProps extends Omit<ComponentPropsWithoutRef<"div">, "title"> {
75
+ title?: ReactNode;
76
+ /** Default "Close". */
77
+ closeLabel?: string;
78
+ /** Default <CloseIcon />. */
79
+ closeIcon?: ReactNode;
80
+ }
81
+ export interface PillContextValue {
82
+ presence: PillPresence;
83
+ setPresence: (presence: PillPresence) => void;
84
+ placement: PillPlacement;
85
+ orientation: PillOrientation;
86
+ variant: PillVariant;
87
+ }
88
+ export {};
@@ -0,0 +1,88 @@
1
+ import { AnchorHTMLAttributes, ComponentPropsWithoutRef, ComponentType, ReactNode, Ref } from "react";
2
+ /**
3
+ * How much room the pill takes. The pill animates between levels.
4
+ * - `hidden`: not shown, and out of the accessibility tree
5
+ * - `rest`: a circle showing only the leading icon
6
+ * - `compact`: the pill; actions show their icon only
7
+ * - `expanded`: the pill; every action shows icon + label
8
+ * - `panel`: the pill grows into a panel showing its <PillPanel>
9
+ */
10
+ export type PillPresence = "hidden" | "rest" | "compact" | "expanded" | "panel";
11
+ /**
12
+ * Where the pill sits.
13
+ * - Edges are `position: fixed`; `start`/`end` follow the text direction.
14
+ * - `inline` stays in the normal page flow.
15
+ * - `overlay` is a modal: a native <dialog> opened with showModal().
16
+ */
17
+ export type PillPlacement = "top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "left" | "right" | "inline" | "overlay";
18
+ /** Defaults to `vertical` for `left`/`right`, `horizontal` everywhere else. */
19
+ export type PillOrientation = "horizontal" | "vertical";
20
+ /**
21
+ * Colour scheme. Any other string is written to `data-variant` so you can
22
+ * define your own: `[data-mp="pill"][data-variant="brand"] { --mp-surface: … }`.
23
+ */
24
+ export type PillVariant = "neutral" | "success" | "danger" | (string & {});
25
+ /**
26
+ * A component that renders a link from an `href`, such as Next's `Link`.
27
+ * React Router's `Link` takes `to`: wrap it.
28
+ */
29
+ export type LinkComponent = ComponentType<AnchorHTMLAttributes<HTMLAnchorElement> & {
30
+ href: string;
31
+ ref?: Ref<HTMLAnchorElement>;
32
+ }>;
33
+ export interface PillProps extends Omit<ComponentPropsWithoutRef<"div">, "children"> {
34
+ children?: ReactNode;
35
+ /** Controlled presence. */
36
+ presence?: PillPresence;
37
+ /** Uncontrolled initial presence. Default `compact`. */
38
+ defaultPresence?: PillPresence;
39
+ /** Called when the pill asks to change level (panel trigger, close button, Escape). */
40
+ onPresenceChange?: (presence: PillPresence) => void;
41
+ /** Default `inline`. */
42
+ placement?: PillPlacement;
43
+ orientation?: PillOrientation;
44
+ /** Default `neutral`. */
45
+ variant?: PillVariant;
46
+ /** Keeps the behaviour and the data attributes, drops the visual styles. */
47
+ unstyled?: boolean;
48
+ }
49
+ interface PillActionBase {
50
+ /** Shown at every level. */
51
+ icon?: ReactNode;
52
+ /**
53
+ * Always required: it's the accessible name when only the icon shows.
54
+ * Visible on hover and focus, when `aria-current`/`expanded` is set, or at
55
+ * the `expanded` and `panel` levels.
56
+ */
57
+ label: string;
58
+ /** Force the label to show. */
59
+ expanded?: boolean;
60
+ }
61
+ /** An action that runs code: renders a <button>. */
62
+ export interface PillButtonActionProps extends PillActionBase, Omit<ComponentPropsWithoutRef<"button">, "children"> {
63
+ href?: undefined;
64
+ }
65
+ /**
66
+ * An action that navigates: renders `linkComponent` (default <a>).
67
+ * Only relative, `http(s):`, `mailto:` and `tel:` URLs are rendered.
68
+ */
69
+ export interface PillLinkActionProps extends PillActionBase, Omit<ComponentPropsWithoutRef<"a">, "children" | "href"> {
70
+ href: string;
71
+ linkComponent?: LinkComponent;
72
+ }
73
+ export type PillActionProps = PillButtonActionProps | PillLinkActionProps;
74
+ export interface PillPanelProps extends Omit<ComponentPropsWithoutRef<"div">, "title"> {
75
+ title?: ReactNode;
76
+ /** Default "Close". */
77
+ closeLabel?: string;
78
+ /** Default <CloseIcon />. */
79
+ closeIcon?: ReactNode;
80
+ }
81
+ export interface PillContextValue {
82
+ presence: PillPresence;
83
+ setPresence: (presence: PillPresence) => void;
84
+ placement: PillPlacement;
85
+ orientation: PillOrientation;
86
+ variant: PillVariant;
87
+ }
88
+ export {};
@@ -0,0 +1,31 @@
1
+ import { ComponentPropsWithoutRef, ReactNode } from "react";
2
+ import { LinkComponent } from "../Pill/types.mjs";
3
+ import { NavMatch } from "./matchPath.mjs";
4
+ export interface NavItem {
5
+ href: string;
6
+ label: string;
7
+ icon?: ReactNode;
8
+ /**
9
+ * How the item matches the current `pathname`. Default `prefix`, on whole
10
+ * path segments (`/blog` matches `/blog/post`, not `/blogroll`); `/` is
11
+ * always exact. The longest match wins, so only one item is active.
12
+ */
13
+ match?: NavMatch;
14
+ }
15
+ export interface PillNavbarProps extends Omit<ComponentPropsWithoutRef<"nav">, "children"> {
16
+ items: readonly NavItem[];
17
+ /**
18
+ * The current path, e.g. Next's `usePathname()`. Without it, the navbar
19
+ * reads `window.location.pathname` after mounting and on `popstate`, which
20
+ * misses client-side navigations.
21
+ */
22
+ pathname?: string;
23
+ linkComponent?: LinkComponent;
24
+ /** Default "Main". */
25
+ "aria-label"?: string;
26
+ }
27
+ /**
28
+ * A <nav> of icon links. The active one shows its label and gets
29
+ * `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
30
+ */
31
+ export declare const PillNavbar: import("react").ForwardRefExoticComponent<PillNavbarProps & import("react").RefAttributes<HTMLElement>>;
@@ -0,0 +1,31 @@
1
+ import { ComponentPropsWithoutRef, ReactNode } from "react";
2
+ import { LinkComponent } from "../Pill/types.js";
3
+ import { NavMatch } from "./matchPath.js";
4
+ export interface NavItem {
5
+ href: string;
6
+ label: string;
7
+ icon?: ReactNode;
8
+ /**
9
+ * How the item matches the current `pathname`. Default `prefix`, on whole
10
+ * path segments (`/blog` matches `/blog/post`, not `/blogroll`); `/` is
11
+ * always exact. The longest match wins, so only one item is active.
12
+ */
13
+ match?: NavMatch;
14
+ }
15
+ export interface PillNavbarProps extends Omit<ComponentPropsWithoutRef<"nav">, "children"> {
16
+ items: readonly NavItem[];
17
+ /**
18
+ * The current path, e.g. Next's `usePathname()`. Without it, the navbar
19
+ * reads `window.location.pathname` after mounting and on `popstate`, which
20
+ * misses client-side navigations.
21
+ */
22
+ pathname?: string;
23
+ linkComponent?: LinkComponent;
24
+ /** Default "Main". */
25
+ "aria-label"?: string;
26
+ }
27
+ /**
28
+ * A <nav> of icon links. The active one shows its label and gets
29
+ * `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
30
+ */
31
+ export declare const PillNavbar: import("react").ForwardRefExoticComponent<PillNavbarProps & import("react").RefAttributes<HTMLElement>>;
@@ -0,0 +1,44 @@
1
+ "use client";
2
+
3
+ let react = require("react");
4
+ const require_parts = require("../Pill/parts.js");
5
+ const require_PillAction = require("../Pill/PillAction.js");
6
+ const require_matchPath = require("./matchPath.js");
7
+ let react_jsx_runtime = require("react/jsx-runtime");
8
+
9
+ // src/PillNavbar/PillNavbar.tsx
10
+ /** Without a `pathname` prop: the browser's path, read after mounting (no hydration mismatch). */
11
+ function useLocationPathname(enabled) {
12
+ const [pathname, setPathname] = (0, react.useState)(void 0);
13
+ (0, react.useEffect)(() => {
14
+ if (!enabled) return;
15
+ const update = () => setPathname(window.location.pathname);
16
+ update();
17
+ window.addEventListener("popstate", update);
18
+ return () => window.removeEventListener("popstate", update);
19
+ }, [enabled]);
20
+ return pathname;
21
+ }
22
+ /**
23
+ * A <nav> of icon links. The active one shows its label and gets
24
+ * `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
25
+ */
26
+ const PillNavbar = (0, react.forwardRef)(function PillNavbar({ items, pathname, linkComponent, "aria-label": ariaLabel = "Main", ...rest }, ref) {
27
+ const locationPathname = useLocationPathname(pathname === void 0);
28
+ const activeIndex = require_matchPath.findActiveIndex(pathname ?? locationPathname, items);
29
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
30
+ "aria-label": ariaLabel,
31
+ ...rest,
32
+ ref,
33
+ "data-mp": "navbar",
34
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillActions, { children: items.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
35
+ icon: item.icon,
36
+ label: item.label,
37
+ href: item.href,
38
+ linkComponent,
39
+ "aria-current": index === activeIndex ? "page" : void 0
40
+ }, item.href)) })
41
+ });
42
+ });
43
+
44
+ exports.PillNavbar = PillNavbar;
@@ -0,0 +1,44 @@
1
+ "use client";
2
+
3
+ import { forwardRef, useEffect, useState } from "react";
4
+ import { PillActions } from "../Pill/parts.mjs";
5
+ import PillAction from "../Pill/PillAction.mjs";
6
+ import { findActiveIndex } from "./matchPath.mjs";
7
+ import { jsx } from "react/jsx-runtime";
8
+
9
+ // src/PillNavbar/PillNavbar.tsx
10
+ /** Without a `pathname` prop: the browser's path, read after mounting (no hydration mismatch). */
11
+ function useLocationPathname(enabled) {
12
+ const [pathname, setPathname] = useState(void 0);
13
+ useEffect(() => {
14
+ if (!enabled) return;
15
+ const update = () => setPathname(window.location.pathname);
16
+ update();
17
+ window.addEventListener("popstate", update);
18
+ return () => window.removeEventListener("popstate", update);
19
+ }, [enabled]);
20
+ return pathname;
21
+ }
22
+ /**
23
+ * A <nav> of icon links. The active one shows its label and gets
24
+ * `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
25
+ */
26
+ const PillNavbar = forwardRef(function PillNavbar({ items, pathname, linkComponent, "aria-label": ariaLabel = "Main", ...rest }, ref) {
27
+ const locationPathname = useLocationPathname(pathname === void 0);
28
+ const activeIndex = findActiveIndex(pathname ?? locationPathname, items);
29
+ return /* @__PURE__ */ jsx("nav", {
30
+ "aria-label": ariaLabel,
31
+ ...rest,
32
+ ref,
33
+ "data-mp": "navbar",
34
+ children: /* @__PURE__ */ jsx(PillActions, { children: items.map((item, index) => /* @__PURE__ */ jsx(PillAction, {
35
+ icon: item.icon,
36
+ label: item.label,
37
+ href: item.href,
38
+ linkComponent,
39
+ "aria-current": index === activeIndex ? "page" : void 0
40
+ }, item.href)) })
41
+ });
42
+ });
43
+
44
+ export { PillNavbar };
@@ -0,0 +1,2 @@
1
+ /** How a nav item matches the current path (L8). */
2
+ export type NavMatch = "exact" | "prefix" | ((pathname: string) => boolean);
@@ -0,0 +1,2 @@
1
+ /** How a nav item matches the current path (L8). */
2
+ export type NavMatch = "exact" | "prefix" | ((pathname: string) => boolean);
@@ -0,0 +1,34 @@
1
+ // src/PillNavbar/matchPath.ts
2
+ /** "/blog/?q=1#top" → "/blog": no query, no hash, no trailing slash (except the root). */
3
+ function normalisePath(path) {
4
+ const withoutSuffix = path.split(/[?#]/, 1)[0];
5
+ return withoutSuffix.length > 1 ? withoutSuffix.replace(/\/+$/, "") || "/" : withoutSuffix;
6
+ }
7
+ function matches(pathname, item) {
8
+ if (typeof item.match === "function") return item.match(pathname);
9
+ if (!item.href.startsWith("/") || item.href.startsWith("//")) return false;
10
+ const path = normalisePath(pathname);
11
+ const href = normalisePath(item.href);
12
+ if (item.match === "exact" || href === "/") return path === href;
13
+ return path === href || path.startsWith(`${href}/`);
14
+ }
15
+ /**
16
+ * The index of the active item, or -1. Several items can match ("/blog" and
17
+ * "/blog/drafts" on "/blog/drafts/1"): the longest href wins, so exactly one
18
+ * item is active.
19
+ */
20
+ function findActiveIndex(pathname, items) {
21
+ if (pathname === void 0) return -1;
22
+ let activeIndex = -1;
23
+ let activeLength = -1;
24
+ items.forEach((item, index) => {
25
+ const length = normalisePath(item.href).length;
26
+ if (length > activeLength && matches(pathname, item)) {
27
+ activeIndex = index;
28
+ activeLength = length;
29
+ }
30
+ });
31
+ return activeIndex;
32
+ }
33
+
34
+ exports.findActiveIndex = findActiveIndex;
@@ -0,0 +1,34 @@
1
+ // src/PillNavbar/matchPath.ts
2
+ /** "/blog/?q=1#top" → "/blog": no query, no hash, no trailing slash (except the root). */
3
+ function normalisePath(path) {
4
+ const withoutSuffix = path.split(/[?#]/, 1)[0];
5
+ return withoutSuffix.length > 1 ? withoutSuffix.replace(/\/+$/, "") || "/" : withoutSuffix;
6
+ }
7
+ function matches(pathname, item) {
8
+ if (typeof item.match === "function") return item.match(pathname);
9
+ if (!item.href.startsWith("/") || item.href.startsWith("//")) return false;
10
+ const path = normalisePath(pathname);
11
+ const href = normalisePath(item.href);
12
+ if (item.match === "exact" || href === "/") return path === href;
13
+ return path === href || path.startsWith(`${href}/`);
14
+ }
15
+ /**
16
+ * The index of the active item, or -1. Several items can match ("/blog" and
17
+ * "/blog/drafts" on "/blog/drafts/1"): the longest href wins, so exactly one
18
+ * item is active.
19
+ */
20
+ function findActiveIndex(pathname, items) {
21
+ if (pathname === void 0) return -1;
22
+ let activeIndex = -1;
23
+ let activeLength = -1;
24
+ items.forEach((item, index) => {
25
+ const length = normalisePath(item.href).length;
26
+ if (length > activeLength && matches(pathname, item)) {
27
+ activeIndex = index;
28
+ activeLength = length;
29
+ }
30
+ });
31
+ return activeIndex;
32
+ }
33
+
34
+ export { findActiveIndex };
@@ -0,0 +1,51 @@
1
+ import { MouseEvent, ReactNode } from "react";
2
+ import { LinkComponent } from "../Pill/types.mjs";
3
+ /** Same rules as the matching <PillAction> props. */
4
+ export type NotificationAction = {
5
+ icon?: ReactNode;
6
+ label: string;
7
+ /**
8
+ * Inside a <MagicPill>, clicking an action dismisses the notification.
9
+ * Call `event.preventDefault()` to keep it open.
10
+ */
11
+ onClick: (event: MouseEvent<HTMLButtonElement>) => void;
12
+ href?: undefined;
13
+ } | {
14
+ icon?: ReactNode;
15
+ label: string;
16
+ href: string;
17
+ onClick?: undefined;
18
+ };
19
+ export interface NotificationPanel {
20
+ title?: ReactNode;
21
+ content: ReactNode;
22
+ /** The action that opens the panel. Default `{ icon: <PlusIcon />, label: "Learn more" }`. */
23
+ trigger?: {
24
+ icon?: ReactNode;
25
+ label: string;
26
+ };
27
+ /** Default "Close". */
28
+ closeLabel?: string;
29
+ }
30
+ export interface PillNotificationClassNames {
31
+ icon?: string;
32
+ divider?: string;
33
+ message?: string;
34
+ actions?: string;
35
+ action?: string;
36
+ panel?: string;
37
+ }
38
+ export interface PillNotificationProps {
39
+ icon?: ReactNode;
40
+ /** Any content: strings, emphasis, live data. Never parsed as HTML (L3). */
41
+ message: ReactNode;
42
+ action?: NotificationAction;
43
+ panel?: NotificationPanel;
44
+ linkComponent?: LinkComponent;
45
+ classNames?: PillNotificationClassNames;
46
+ }
47
+ /**
48
+ * Icon · divider · message · action, with an optional expandable panel.
49
+ * Render it inside a <Pill>, or let <MagicPill> render it for pill().notify().
50
+ */
51
+ export declare const PillNotification: (props: PillNotificationProps) => ReactNode;
@@ -0,0 +1,51 @@
1
+ import { MouseEvent, ReactNode } from "react";
2
+ import { LinkComponent } from "../Pill/types.js";
3
+ /** Same rules as the matching <PillAction> props. */
4
+ export type NotificationAction = {
5
+ icon?: ReactNode;
6
+ label: string;
7
+ /**
8
+ * Inside a <MagicPill>, clicking an action dismisses the notification.
9
+ * Call `event.preventDefault()` to keep it open.
10
+ */
11
+ onClick: (event: MouseEvent<HTMLButtonElement>) => void;
12
+ href?: undefined;
13
+ } | {
14
+ icon?: ReactNode;
15
+ label: string;
16
+ href: string;
17
+ onClick?: undefined;
18
+ };
19
+ export interface NotificationPanel {
20
+ title?: ReactNode;
21
+ content: ReactNode;
22
+ /** The action that opens the panel. Default `{ icon: <PlusIcon />, label: "Learn more" }`. */
23
+ trigger?: {
24
+ icon?: ReactNode;
25
+ label: string;
26
+ };
27
+ /** Default "Close". */
28
+ closeLabel?: string;
29
+ }
30
+ export interface PillNotificationClassNames {
31
+ icon?: string;
32
+ divider?: string;
33
+ message?: string;
34
+ actions?: string;
35
+ action?: string;
36
+ panel?: string;
37
+ }
38
+ export interface PillNotificationProps {
39
+ icon?: ReactNode;
40
+ /** Any content: strings, emphasis, live data. Never parsed as HTML (L3). */
41
+ message: ReactNode;
42
+ action?: NotificationAction;
43
+ panel?: NotificationPanel;
44
+ linkComponent?: LinkComponent;
45
+ classNames?: PillNotificationClassNames;
46
+ }
47
+ /**
48
+ * Icon · divider · message · action, with an optional expandable panel.
49
+ * Render it inside a <Pill>, or let <MagicPill> render it for pill().notify().
50
+ */
51
+ export declare const PillNotification: (props: PillNotificationProps) => ReactNode;
@@ -0,0 +1,64 @@
1
+ const require_parts = require("../Pill/parts.js");
2
+ const require_PillAction = require("../Pill/PillAction.js");
3
+ const require_PillPanel = require("../Pill/PillPanel.js");
4
+ const require_PlusIcon = require("../icons/PlusIcon.js");
5
+ let react_jsx_runtime = require("react/jsx-runtime");
6
+
7
+ // src/PillNotification/PillNotification.tsx
8
+ /** The implementation, with the host-only `onAction` hook. */
9
+ function NotificationContent({ icon, message, action, panel, linkComponent, classNames = {}, onAction }) {
10
+ const hasIcon = icon !== void 0 && icon !== null;
11
+ const renderAction = (notificationAction) => {
12
+ const { icon: actionIcon, label } = notificationAction;
13
+ if (notificationAction.href !== void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
14
+ icon: actionIcon,
15
+ label,
16
+ href: notificationAction.href,
17
+ linkComponent,
18
+ className: classNames.action,
19
+ onClick: onAction
20
+ });
21
+ const { onClick } = notificationAction;
22
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
23
+ icon: actionIcon,
24
+ label,
25
+ className: classNames.action,
26
+ onClick: (event) => {
27
+ onClick(event);
28
+ onAction?.(event);
29
+ }
30
+ });
31
+ };
32
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
33
+ hasIcon && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillIcon, {
34
+ className: classNames.icon,
35
+ children: icon
36
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillDivider, { className: classNames.divider })] }),
37
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillMessage, {
38
+ className: classNames.message,
39
+ children: message
40
+ }),
41
+ (action || panel) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_parts.PillActions, {
42
+ className: classNames.actions,
43
+ children: [action && renderAction(action), panel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillPanel.PillPanelTrigger, {
44
+ icon: panel.trigger ? panel.trigger.icon : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PlusIcon, {}),
45
+ label: panel.trigger?.label ?? "Learn more",
46
+ className: classNames.action
47
+ })]
48
+ }),
49
+ panel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillPanel.PillPanel, {
50
+ title: panel.title,
51
+ closeLabel: panel.closeLabel,
52
+ className: classNames.panel,
53
+ children: panel.content
54
+ })
55
+ ] });
56
+ }
57
+ /**
58
+ * Icon · divider · message · action, with an optional expandable panel.
59
+ * Render it inside a <Pill>, or let <MagicPill> render it for pill().notify().
60
+ */
61
+ const PillNotification = NotificationContent;
62
+
63
+ exports.NotificationContent = NotificationContent;
64
+ exports.PillNotification = PillNotification;