magic-pill 9.0.0 → 9.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.
Files changed (149) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +259 -15
  3. package/dist/MagicPill/MagicPill.d.mts +7 -1
  4. package/dist/MagicPill/MagicPill.d.ts +7 -1
  5. package/dist/MagicPill/MagicPill.js +40 -17
  6. package/dist/MagicPill/MagicPill.mjs +42 -19
  7. package/dist/MagicPill/choreography.js +1 -1
  8. package/dist/MagicPill/choreography.mjs +1 -1
  9. package/dist/Pill/Pill.js +53 -17
  10. package/dist/Pill/Pill.mjs +54 -18
  11. package/dist/Pill/PillContext.js +3 -1
  12. package/dist/Pill/PillContext.mjs +3 -1
  13. package/dist/Pill/PillPanel.d.mts +5 -5
  14. package/dist/Pill/PillPanel.d.ts +5 -5
  15. package/dist/Pill/PillPanel.js +28 -20
  16. package/dist/Pill/PillPanel.mjs +28 -20
  17. package/dist/Pill/morph.js +25 -7
  18. package/dist/Pill/morph.mjs +22 -8
  19. package/dist/Pill/scene.js +90 -0
  20. package/dist/Pill/scene.mjs +89 -0
  21. package/dist/Pill/themed.js +36 -0
  22. package/dist/Pill/themed.mjs +34 -0
  23. package/dist/Pill/types.d.mts +50 -0
  24. package/dist/Pill/types.d.ts +50 -0
  25. package/dist/Pill/zone.js +160 -0
  26. package/dist/Pill/zone.mjs +159 -0
  27. package/dist/PillForm/Calendar.d.mts +15 -0
  28. package/dist/PillForm/Calendar.d.ts +16 -0
  29. package/dist/PillForm/Calendar.js +371 -0
  30. package/dist/PillForm/Calendar.mjs +370 -0
  31. package/dist/PillForm/FormContext.d.mts +2 -0
  32. package/dist/PillForm/FormContext.d.ts +2 -0
  33. package/dist/PillForm/FormContext.js +8 -0
  34. package/dist/PillForm/FormContext.mjs +8 -0
  35. package/dist/PillForm/PillCheckbox.d.mts +8 -0
  36. package/dist/PillForm/PillCheckbox.d.ts +8 -0
  37. package/dist/PillForm/PillCheckbox.js +45 -0
  38. package/dist/PillForm/PillCheckbox.mjs +45 -0
  39. package/dist/PillForm/PillChoices.d.mts +39 -0
  40. package/dist/PillForm/PillChoices.d.ts +39 -0
  41. package/dist/PillForm/PillChoices.js +103 -0
  42. package/dist/PillForm/PillChoices.mjs +103 -0
  43. package/dist/PillForm/PillCode.d.mts +12 -0
  44. package/dist/PillForm/PillCode.d.ts +12 -0
  45. package/dist/PillForm/PillCode.js +60 -0
  46. package/dist/PillForm/PillCode.mjs +60 -0
  47. package/dist/PillForm/PillColor.d.mts +10 -0
  48. package/dist/PillForm/PillColor.d.ts +10 -0
  49. package/dist/PillForm/PillColor.js +56 -0
  50. package/dist/PillForm/PillColor.mjs +56 -0
  51. package/dist/PillForm/PillDate.d.mts +44 -0
  52. package/dist/PillForm/PillDate.d.ts +44 -0
  53. package/dist/PillForm/PillDate.js +193 -0
  54. package/dist/PillForm/PillDate.mjs +193 -0
  55. package/dist/PillForm/PillField.d.mts +38 -0
  56. package/dist/PillForm/PillField.d.ts +38 -0
  57. package/dist/PillForm/PillField.js +81 -0
  58. package/dist/PillForm/PillField.mjs +80 -0
  59. package/dist/PillForm/PillFields.d.mts +11 -0
  60. package/dist/PillForm/PillFields.d.ts +11 -0
  61. package/dist/PillForm/PillFields.js +21 -0
  62. package/dist/PillForm/PillFields.mjs +21 -0
  63. package/dist/PillForm/PillFile.d.mts +8 -0
  64. package/dist/PillForm/PillFile.d.ts +8 -0
  65. package/dist/PillForm/PillFile.js +55 -0
  66. package/dist/PillForm/PillFile.mjs +55 -0
  67. package/dist/PillForm/PillForm.d.mts +29 -0
  68. package/dist/PillForm/PillForm.d.ts +29 -0
  69. package/dist/PillForm/PillForm.js +66 -0
  70. package/dist/PillForm/PillForm.mjs +65 -0
  71. package/dist/PillForm/PillFormPanel.d.mts +24 -0
  72. package/dist/PillForm/PillFormPanel.d.ts +24 -0
  73. package/dist/PillForm/PillFormPanel.js +53 -0
  74. package/dist/PillForm/PillFormPanel.mjs +53 -0
  75. package/dist/PillForm/PillInput.d.mts +20 -0
  76. package/dist/PillForm/PillInput.d.ts +20 -0
  77. package/dist/PillForm/PillInput.js +84 -0
  78. package/dist/PillForm/PillInput.mjs +84 -0
  79. package/dist/PillForm/PillSelect.d.mts +23 -0
  80. package/dist/PillForm/PillSelect.d.ts +23 -0
  81. package/dist/PillForm/PillSelect.js +87 -0
  82. package/dist/PillForm/PillSelect.mjs +87 -0
  83. package/dist/PillForm/PillSlider.d.mts +17 -0
  84. package/dist/PillForm/PillSlider.d.ts +17 -0
  85. package/dist/PillForm/PillSlider.js +61 -0
  86. package/dist/PillForm/PillSlider.mjs +61 -0
  87. package/dist/PillForm/PillStepper.d.mts +13 -0
  88. package/dist/PillForm/PillStepper.d.ts +13 -0
  89. package/dist/PillForm/PillStepper.js +84 -0
  90. package/dist/PillForm/PillStepper.mjs +84 -0
  91. package/dist/PillForm/PillSubmit.d.mts +14 -0
  92. package/dist/PillForm/PillSubmit.d.ts +14 -0
  93. package/dist/PillForm/PillSubmit.js +90 -0
  94. package/dist/PillForm/PillSubmit.mjs +89 -0
  95. package/dist/PillForm/PillSwitch.d.mts +5 -0
  96. package/dist/PillForm/PillSwitch.d.ts +5 -0
  97. package/dist/PillForm/PillSwitch.js +38 -0
  98. package/dist/PillForm/PillSwitch.mjs +38 -0
  99. package/dist/PillForm/PillTextarea.d.mts +5 -0
  100. package/dist/PillForm/PillTextarea.d.ts +5 -0
  101. package/dist/PillForm/PillTextarea.js +49 -0
  102. package/dist/PillForm/PillTextarea.mjs +49 -0
  103. package/dist/PillForm/dates.d.mts +1 -0
  104. package/dist/PillForm/dates.d.ts +1 -0
  105. package/dist/PillForm/dates.js +155 -0
  106. package/dist/PillForm/dates.mjs +139 -0
  107. package/dist/PillForm/glyphs.js +65 -0
  108. package/dist/PillForm/glyphs.mjs +56 -0
  109. package/dist/PillForm/keyboard.js +34 -0
  110. package/dist/PillForm/keyboard.mjs +34 -0
  111. package/dist/PillForm/popover.js +84 -0
  112. package/dist/PillForm/popover.mjs +83 -0
  113. package/dist/PillForm/send.d.mts +6 -0
  114. package/dist/PillForm/send.d.ts +6 -0
  115. package/dist/PillForm/send.js +44 -0
  116. package/dist/PillForm/send.mjs +44 -0
  117. package/dist/PillForm/validity.js +74 -0
  118. package/dist/PillForm/validity.mjs +72 -0
  119. package/dist/PillNavbar/PillNavbar.d.mts +29 -6
  120. package/dist/PillNavbar/PillNavbar.d.ts +29 -6
  121. package/dist/PillNavbar/PillNavbar.js +35 -11
  122. package/dist/PillNavbar/PillNavbar.mjs +36 -12
  123. package/dist/PillNavbar/room.js +84 -0
  124. package/dist/PillNavbar/room.mjs +83 -0
  125. package/dist/PillNotification/PillNotification.d.mts +6 -0
  126. package/dist/PillNotification/PillNotification.d.ts +6 -0
  127. package/dist/PillNotification/PillNotification.js +3 -0
  128. package/dist/PillNotification/PillNotification.mjs +3 -0
  129. package/dist/PillOptics/PillOptics.d.mts +8 -0
  130. package/dist/PillOptics/PillOptics.d.ts +8 -0
  131. package/dist/PillOptics/PillOptics.js +195 -0
  132. package/dist/PillOptics/PillOptics.mjs +195 -0
  133. package/dist/PillOptics/adaptive.js +212 -0
  134. package/dist/PillOptics/adaptive.mjs +208 -0
  135. package/dist/PillOptics/lens.js +77 -0
  136. package/dist/PillOptics/lens.mjs +73 -0
  137. package/dist/PillOptics/light.js +37 -0
  138. package/dist/PillOptics/light.mjs +36 -0
  139. package/dist/calendar.css +499 -0
  140. package/dist/forms.css +1452 -0
  141. package/dist/index.d.mts +24 -3
  142. package/dist/index.d.ts +24 -3
  143. package/dist/index.js +36 -0
  144. package/dist/index.mjs +19 -1
  145. package/dist/styles.css +169 -19
  146. package/dist/themes.css +449 -0
  147. package/dist/utils/visuallyHidden.js +18 -0
  148. package/dist/utils/visuallyHidden.mjs +18 -0
  149. package/package.json +4 -1
@@ -0,0 +1,72 @@
1
+ "use client";
2
+
3
+ import { useContext, useEffect, useState } from "react";
4
+ import { FormContext } from "./FormContext.mjs";
5
+
6
+ // src/PillForm/validity.ts
7
+ const isControl = (element) => element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement;
8
+ /** Whether the person has changed this control (or tried to submit it) and it's wrong. */
9
+ function isUserInvalid(control) {
10
+ try {
11
+ return control.matches(":user-invalid");
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
16
+ /** Runs after the form this control belongs to has been reset. */
17
+ function useFormReset(controlRef, onReset) {
18
+ useEffect(() => {
19
+ const form = controlRef.current?.form;
20
+ if (!form) return;
21
+ let timer;
22
+ const listener = () => {
23
+ timer = setTimeout(onReset);
24
+ };
25
+ form.addEventListener("reset", listener);
26
+ return () => {
27
+ clearTimeout(timer);
28
+ form.removeEventListener("reset", listener);
29
+ };
30
+ });
31
+ }
32
+ /**
33
+ * The browser's own validation, to show in the page rather than in its bubble:
34
+ * on an attempt to submit, or on leaving a field that was changed and is wrong.
35
+ * The message goes as soon as the value is right. The app's own error wins.
36
+ */
37
+ function useValidity(error, controlRef) {
38
+ const { errors } = useContext(FormContext);
39
+ const [message, setMessage] = useState("");
40
+ useFormReset(controlRef, () => setMessage(""));
41
+ return {
42
+ error: error || message || void 0,
43
+ handlers: {
44
+ onInvalid: (event) => {
45
+ const control = event.target;
46
+ if (errors === "native" || !isControl(control)) return;
47
+ event.preventDefault();
48
+ setMessage(control.validationMessage);
49
+ if ([...control.form?.elements ?? []].find((element) => isControl(element) && element.willValidate && !element.validity.valid) === control) control.focus();
50
+ },
51
+ onInput: (event) => {
52
+ const control = event.target;
53
+ if (!isControl(control)) return;
54
+ setMessage((shown) => shown && !control.validity.valid ? control.validationMessage : "");
55
+ },
56
+ onBlur: (event) => {
57
+ const control = event.target;
58
+ if (errors === "native" || !isControl(control)) return;
59
+ if (isUserInvalid(control)) setMessage(control.validationMessage);
60
+ }
61
+ }
62
+ };
63
+ }
64
+ /** Both handlers, the app's after ours. */
65
+ function both(ours, theirs) {
66
+ return (event) => {
67
+ ours?.(event);
68
+ theirs?.(event);
69
+ };
70
+ }
71
+
72
+ export { both, useFormReset, useValidity };
@@ -1,17 +1,39 @@
1
- import { ComponentPropsWithoutRef, ReactNode } from "react";
1
+ import { ComponentPropsWithoutRef, MouseEvent, ReactNode } from "react";
2
2
  import { LinkComponent } from "../Pill/types.mjs";
3
3
  import { NavMatch } from "./matchPath.mjs";
4
- export interface NavItem {
5
- href: string;
4
+ interface NavItemBase {
6
5
  label: string;
7
6
  icon?: ReactNode;
7
+ }
8
+ /** A link to a page: the current one shows its label. */
9
+ export interface NavLinkItem extends NavItemBase {
10
+ href: string;
8
11
  /**
9
12
  * How the item matches the current `pathname`. Default `prefix`, on whole
10
13
  * path segments (`/blog` matches `/blog/post`, not `/blogroll`); `/` is
11
14
  * always exact. The longest match wins, so only one item is active.
12
15
  */
13
16
  match?: NavMatch;
17
+ onClick?: undefined;
18
+ panel?: undefined;
19
+ }
20
+ /** A button. */
21
+ export interface NavActionItem extends NavItemBase {
22
+ onClick: (event: MouseEvent<HTMLButtonElement>) => void;
23
+ /** Always show the label, not only on hover and focus. */
24
+ expanded?: boolean;
25
+ href?: undefined;
26
+ panel?: undefined;
27
+ }
28
+ /** A button that opens the panel with that `name`, next to the navbar in the pill. */
29
+ export interface NavPanelItem extends NavItemBase {
30
+ panel: string;
31
+ /** Always show the label, not only on hover and focus. */
32
+ expanded?: boolean;
33
+ href?: undefined;
34
+ onClick?: undefined;
14
35
  }
36
+ export type NavItem = NavLinkItem | NavActionItem | NavPanelItem;
15
37
  export interface PillNavbarProps extends Omit<ComponentPropsWithoutRef<"nav">, "children"> {
16
38
  items: readonly NavItem[];
17
39
  /**
@@ -25,7 +47,8 @@ export interface PillNavbarProps extends Omit<ComponentPropsWithoutRef<"nav">, "
25
47
  "aria-label"?: string;
26
48
  }
27
49
  /**
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>.
50
+ * A <nav> of icon links, actions and panel triggers. The active link shows its
51
+ * label and gets `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
30
52
  */
31
- export declare const PillNavbar: import("react").ForwardRefExoticComponent<PillNavbarProps & import("react").RefAttributes<HTMLElement>>;
53
+ export declare const PillNavbar: import("react").ForwardRefExoticComponent<PillNavbarProps & import("react").RefAttributes<HTMLElement>>;
54
+ export {};
@@ -1,17 +1,39 @@
1
- import { ComponentPropsWithoutRef, ReactNode } from "react";
1
+ import { ComponentPropsWithoutRef, MouseEvent, ReactNode } from "react";
2
2
  import { LinkComponent } from "../Pill/types.js";
3
3
  import { NavMatch } from "./matchPath.js";
4
- export interface NavItem {
5
- href: string;
4
+ interface NavItemBase {
6
5
  label: string;
7
6
  icon?: ReactNode;
7
+ }
8
+ /** A link to a page: the current one shows its label. */
9
+ export interface NavLinkItem extends NavItemBase {
10
+ href: string;
8
11
  /**
9
12
  * How the item matches the current `pathname`. Default `prefix`, on whole
10
13
  * path segments (`/blog` matches `/blog/post`, not `/blogroll`); `/` is
11
14
  * always exact. The longest match wins, so only one item is active.
12
15
  */
13
16
  match?: NavMatch;
17
+ onClick?: undefined;
18
+ panel?: undefined;
19
+ }
20
+ /** A button. */
21
+ export interface NavActionItem extends NavItemBase {
22
+ onClick: (event: MouseEvent<HTMLButtonElement>) => void;
23
+ /** Always show the label, not only on hover and focus. */
24
+ expanded?: boolean;
25
+ href?: undefined;
26
+ panel?: undefined;
27
+ }
28
+ /** A button that opens the panel with that `name`, next to the navbar in the pill. */
29
+ export interface NavPanelItem extends NavItemBase {
30
+ panel: string;
31
+ /** Always show the label, not only on hover and focus. */
32
+ expanded?: boolean;
33
+ href?: undefined;
34
+ onClick?: undefined;
14
35
  }
36
+ export type NavItem = NavLinkItem | NavActionItem | NavPanelItem;
15
37
  export interface PillNavbarProps extends Omit<ComponentPropsWithoutRef<"nav">, "children"> {
16
38
  items: readonly NavItem[];
17
39
  /**
@@ -25,7 +47,8 @@ export interface PillNavbarProps extends Omit<ComponentPropsWithoutRef<"nav">, "
25
47
  "aria-label"?: string;
26
48
  }
27
49
  /**
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>.
50
+ * A <nav> of icon links, actions and panel triggers. The active link shows its
51
+ * label and gets `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
30
52
  */
31
- export declare const PillNavbar: import("react").ForwardRefExoticComponent<PillNavbarProps & import("react").RefAttributes<HTMLElement>>;
53
+ export declare const PillNavbar: import("react").ForwardRefExoticComponent<PillNavbarProps & import("react").RefAttributes<HTMLElement>>;
54
+ export {};
@@ -3,7 +3,10 @@
3
3
  let react = require("react");
4
4
  const require_parts = require("../Pill/parts.js");
5
5
  const require_PillAction = require("../Pill/PillAction.js");
6
+ const require_PillPanel = require("../Pill/PillPanel.js");
6
7
  const require_matchPath = require("./matchPath.js");
8
+ const require_room = require("./room.js");
9
+ const require_react = require("../utils/react.js");
7
10
  let react_jsx_runtime = require("react/jsx-runtime");
8
11
 
9
12
  // src/PillNavbar/PillNavbar.tsx
@@ -19,25 +22,46 @@ function useLocationPathname(enabled) {
19
22
  }, [enabled]);
20
23
  return pathname;
21
24
  }
25
+ const isLink = (item) => item.href !== void 0;
22
26
  /**
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>.
27
+ * A <nav> of icon links, actions and panel triggers. The active link shows its
28
+ * label and gets `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
25
29
  */
26
- const PillNavbar = (0, react.forwardRef)(function PillNavbar({ items, pathname, linkComponent, "aria-label": ariaLabel = "Main", ...rest }, ref) {
30
+ const PillNavbar = (0, react.forwardRef)(function PillNavbar({ items, pathname, linkComponent, "aria-label": ariaLabel = "Main", ...rest }, forwardedRef) {
31
+ const navRef = (0, react.useRef)(null);
32
+ const ref = (0, react.useMemo)(() => require_react.mergeRefs(navRef, forwardedRef), [forwardedRef]);
33
+ require_room.useRoom(navRef);
27
34
  const locationPathname = useLocationPathname(pathname === void 0);
28
- const activeIndex = require_matchPath.findActiveIndex(pathname ?? locationPathname, items);
35
+ const links = items.filter(isLink);
36
+ const active = links[require_matchPath.findActiveIndex(pathname ?? locationPathname, links)];
37
+ const renderItem = (item) => {
38
+ const { label, icon } = item;
39
+ if (item.panel !== void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillPanel.PillPanelTrigger, {
40
+ panel: item.panel,
41
+ icon,
42
+ label,
43
+ expanded: item.expanded
44
+ }, `panel ${item.panel}`);
45
+ if (item.onClick !== void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
46
+ icon,
47
+ label,
48
+ expanded: item.expanded,
49
+ onClick: item.onClick
50
+ }, `action ${label}`);
51
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
52
+ icon,
53
+ label,
54
+ href: item.href,
55
+ linkComponent,
56
+ "aria-current": item === active ? "page" : void 0
57
+ }, item.href);
58
+ };
29
59
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
30
60
  "aria-label": ariaLabel,
31
61
  ...rest,
32
62
  ref,
33
63
  "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)) })
64
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillActions, { children: items.map(renderItem) })
41
65
  });
42
66
  });
43
67
 
@@ -1,9 +1,12 @@
1
1
  "use client";
2
2
 
3
- import { forwardRef, useEffect, useState } from "react";
3
+ import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
4
4
  import { PillActions } from "../Pill/parts.mjs";
5
5
  import PillAction from "../Pill/PillAction.mjs";
6
+ import { PillPanelTrigger } from "../Pill/PillPanel.mjs";
6
7
  import { findActiveIndex } from "./matchPath.mjs";
8
+ import { useRoom } from "./room.mjs";
9
+ import { mergeRefs } from "../utils/react.mjs";
7
10
  import { jsx } from "react/jsx-runtime";
8
11
 
9
12
  // src/PillNavbar/PillNavbar.tsx
@@ -19,25 +22,46 @@ function useLocationPathname(enabled) {
19
22
  }, [enabled]);
20
23
  return pathname;
21
24
  }
25
+ const isLink = (item) => item.href !== void 0;
22
26
  /**
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>.
27
+ * A <nav> of icon links, actions and panel triggers. The active link shows its
28
+ * label and gets `aria-current="page"`. Render it inside a <Pill>, or as the base layer of a <MagicPill>.
25
29
  */
26
- const PillNavbar = forwardRef(function PillNavbar({ items, pathname, linkComponent, "aria-label": ariaLabel = "Main", ...rest }, ref) {
30
+ const PillNavbar = forwardRef(function PillNavbar({ items, pathname, linkComponent, "aria-label": ariaLabel = "Main", ...rest }, forwardedRef) {
31
+ const navRef = useRef(null);
32
+ const ref = useMemo(() => mergeRefs(navRef, forwardedRef), [forwardedRef]);
33
+ useRoom(navRef);
27
34
  const locationPathname = useLocationPathname(pathname === void 0);
28
- const activeIndex = findActiveIndex(pathname ?? locationPathname, items);
35
+ const links = items.filter(isLink);
36
+ const active = links[findActiveIndex(pathname ?? locationPathname, links)];
37
+ const renderItem = (item) => {
38
+ const { label, icon } = item;
39
+ if (item.panel !== void 0) return /* @__PURE__ */ jsx(PillPanelTrigger, {
40
+ panel: item.panel,
41
+ icon,
42
+ label,
43
+ expanded: item.expanded
44
+ }, `panel ${item.panel}`);
45
+ if (item.onClick !== void 0) return /* @__PURE__ */ jsx(PillAction, {
46
+ icon,
47
+ label,
48
+ expanded: item.expanded,
49
+ onClick: item.onClick
50
+ }, `action ${label}`);
51
+ return /* @__PURE__ */ jsx(PillAction, {
52
+ icon,
53
+ label,
54
+ href: item.href,
55
+ linkComponent,
56
+ "aria-current": item === active ? "page" : void 0
57
+ }, item.href);
58
+ };
29
59
  return /* @__PURE__ */ jsx("nav", {
30
60
  "aria-label": ariaLabel,
31
61
  ...rest,
32
62
  ref,
33
63
  "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)) })
64
+ children: /* @__PURE__ */ jsx(PillActions, { children: items.map(renderItem) })
41
65
  });
42
66
  });
43
67
 
@@ -0,0 +1,84 @@
1
+ "use client";
2
+
3
+ let react = require("react");
4
+
5
+ // src/PillNavbar/room.ts
6
+ const ACTION = "[data-mp=\"action\"]";
7
+ /**
8
+ * Whether the navbar still fits its pill with this item's label open. Laid out
9
+ * on a copy, removed before anything is painted: the labels on screen may be
10
+ * moving, and the app's own styles count.
11
+ */
12
+ function fitsWith(navbar, item) {
13
+ const pill = navbar.closest("[data-mp=\"pill\"]");
14
+ if (!pill) return true;
15
+ const index = [...navbar.querySelectorAll(ACTION)].indexOf(item);
16
+ const copy = pill.cloneNode(false);
17
+ for (const child of pill.children) if (child.getAttribute("data-mp") !== "panel") copy.append(child.cloneNode(true));
18
+ copy.querySelectorAll("[id], [name]").forEach((node) => {
19
+ node.removeAttribute("id");
20
+ node.removeAttribute("name");
21
+ });
22
+ const copiedNavbar = copy.querySelector("[data-mp=\"navbar\"]");
23
+ if (!copiedNavbar) return true;
24
+ copiedNavbar.removeAttribute("data-tight");
25
+ copiedNavbar.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
26
+ copy.querySelectorAll("[data-mp=\"navbar\"], [data-mp=\"actions\"], [data-mp=\"action\"]").forEach((node) => {
27
+ node.style.flexShrink = "0";
28
+ });
29
+ copy.inert = true;
30
+ copy.style.visibility = "hidden";
31
+ pill.after(copy);
32
+ const fits = isInside(copiedNavbar, copy);
33
+ copy.remove();
34
+ return fits;
35
+ }
36
+ /** Whether the navbar ends before the pill's padding does. */
37
+ function isInside(navbar, pill) {
38
+ const style = getComputedStyle(pill);
39
+ const room = pill.clientWidth - (parseFloat(style.paddingLeft) || 0) - (parseFloat(style.paddingRight) || 0);
40
+ return navbar.scrollWidth <= room + 1;
41
+ }
42
+ const isHorizontal = (navbar) => {
43
+ const pill = navbar.closest("[data-mp=\"pill\"]");
44
+ return pill?.dataset.orientation === "horizontal" && pill.dataset.unstyled === void 0;
45
+ };
46
+ /**
47
+ * Writes `data-tight` on the navbar while the item pointed at (or focused with
48
+ * the keyboard) has no room for its label next to the open ones.
49
+ */
50
+ function useRoom(ref) {
51
+ (0, react.useEffect)(() => {
52
+ const navbar = ref.current;
53
+ if (!navbar) return;
54
+ const release = () => navbar.removeAttribute("data-tight");
55
+ const open = (target) => {
56
+ const item = target instanceof Element ? target.closest(ACTION) : null;
57
+ if (!item) return;
58
+ if (item.matches("[aria-current=\"page\"], [aria-current=\"true\"], [data-expanded]") || !isHorizontal(navbar) || fitsWith(navbar, item)) release();
59
+ else navbar.setAttribute("data-tight", "");
60
+ };
61
+ const onPointerOver = (event) => {
62
+ if (event.pointerType !== "touch") open(event.target);
63
+ };
64
+ const onFocusIn = (event) => {
65
+ if (event.target instanceof Element && event.target.matches(":focus-visible")) open(event.target);
66
+ };
67
+ const onFocusOut = (event) => {
68
+ if (!navbar.contains(event.relatedTarget)) release();
69
+ };
70
+ navbar.addEventListener("pointerover", onPointerOver);
71
+ navbar.addEventListener("pointerleave", release);
72
+ navbar.addEventListener("focusin", onFocusIn);
73
+ navbar.addEventListener("focusout", onFocusOut);
74
+ return () => {
75
+ navbar.removeEventListener("pointerover", onPointerOver);
76
+ navbar.removeEventListener("pointerleave", release);
77
+ navbar.removeEventListener("focusin", onFocusIn);
78
+ navbar.removeEventListener("focusout", onFocusOut);
79
+ };
80
+ }, [ref]);
81
+ }
82
+
83
+ exports.fitsWith = fitsWith;
84
+ exports.useRoom = useRoom;
@@ -0,0 +1,83 @@
1
+ "use client";
2
+
3
+ import { useEffect } from "react";
4
+
5
+ // src/PillNavbar/room.ts
6
+ const ACTION = "[data-mp=\"action\"]";
7
+ /**
8
+ * Whether the navbar still fits its pill with this item's label open. Laid out
9
+ * on a copy, removed before anything is painted: the labels on screen may be
10
+ * moving, and the app's own styles count.
11
+ */
12
+ function fitsWith(navbar, item) {
13
+ const pill = navbar.closest("[data-mp=\"pill\"]");
14
+ if (!pill) return true;
15
+ const index = [...navbar.querySelectorAll(ACTION)].indexOf(item);
16
+ const copy = pill.cloneNode(false);
17
+ for (const child of pill.children) if (child.getAttribute("data-mp") !== "panel") copy.append(child.cloneNode(true));
18
+ copy.querySelectorAll("[id], [name]").forEach((node) => {
19
+ node.removeAttribute("id");
20
+ node.removeAttribute("name");
21
+ });
22
+ const copiedNavbar = copy.querySelector("[data-mp=\"navbar\"]");
23
+ if (!copiedNavbar) return true;
24
+ copiedNavbar.removeAttribute("data-tight");
25
+ copiedNavbar.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
26
+ copy.querySelectorAll("[data-mp=\"navbar\"], [data-mp=\"actions\"], [data-mp=\"action\"]").forEach((node) => {
27
+ node.style.flexShrink = "0";
28
+ });
29
+ copy.inert = true;
30
+ copy.style.visibility = "hidden";
31
+ pill.after(copy);
32
+ const fits = isInside(copiedNavbar, copy);
33
+ copy.remove();
34
+ return fits;
35
+ }
36
+ /** Whether the navbar ends before the pill's padding does. */
37
+ function isInside(navbar, pill) {
38
+ const style = getComputedStyle(pill);
39
+ const room = pill.clientWidth - (parseFloat(style.paddingLeft) || 0) - (parseFloat(style.paddingRight) || 0);
40
+ return navbar.scrollWidth <= room + 1;
41
+ }
42
+ const isHorizontal = (navbar) => {
43
+ const pill = navbar.closest("[data-mp=\"pill\"]");
44
+ return pill?.dataset.orientation === "horizontal" && pill.dataset.unstyled === void 0;
45
+ };
46
+ /**
47
+ * Writes `data-tight` on the navbar while the item pointed at (or focused with
48
+ * the keyboard) has no room for its label next to the open ones.
49
+ */
50
+ function useRoom(ref) {
51
+ useEffect(() => {
52
+ const navbar = ref.current;
53
+ if (!navbar) return;
54
+ const release = () => navbar.removeAttribute("data-tight");
55
+ const open = (target) => {
56
+ const item = target instanceof Element ? target.closest(ACTION) : null;
57
+ if (!item) return;
58
+ if (item.matches("[aria-current=\"page\"], [aria-current=\"true\"], [data-expanded]") || !isHorizontal(navbar) || fitsWith(navbar, item)) release();
59
+ else navbar.setAttribute("data-tight", "");
60
+ };
61
+ const onPointerOver = (event) => {
62
+ if (event.pointerType !== "touch") open(event.target);
63
+ };
64
+ const onFocusIn = (event) => {
65
+ if (event.target instanceof Element && event.target.matches(":focus-visible")) open(event.target);
66
+ };
67
+ const onFocusOut = (event) => {
68
+ if (!navbar.contains(event.relatedTarget)) release();
69
+ };
70
+ navbar.addEventListener("pointerover", onPointerOver);
71
+ navbar.addEventListener("pointerleave", release);
72
+ navbar.addEventListener("focusin", onFocusIn);
73
+ navbar.addEventListener("focusout", onFocusOut);
74
+ return () => {
75
+ navbar.removeEventListener("pointerover", onPointerOver);
76
+ navbar.removeEventListener("pointerleave", release);
77
+ navbar.removeEventListener("focusin", onFocusIn);
78
+ navbar.removeEventListener("focusout", onFocusOut);
79
+ };
80
+ }, [ref]);
81
+ }
82
+
83
+ export { fitsWith, useRoom };
@@ -21,7 +21,11 @@ export type NotificationAction = {
21
21
  };
22
22
  export interface NotificationPanel {
23
23
  title?: ReactNode;
24
+ /** At the end of the title's row, e.g. a <PillAction>. */
25
+ titleAction?: ReactNode;
24
26
  content: ReactNode;
27
+ /** In the footer, before the close button, e.g. a <PillAction>. */
28
+ footer?: ReactNode;
25
29
  /** The action that opens the panel. Default `{ icon: <PlusIcon />, label: "Learn more" }`. */
26
30
  trigger?: {
27
31
  icon?: ReactNode;
@@ -30,6 +34,8 @@ export interface NotificationPanel {
30
34
  };
31
35
  /** Default "Close". */
32
36
  closeLabel?: string;
37
+ /** Always show the close button's label, not only on hover and focus. */
38
+ closeExpanded?: boolean;
33
39
  }
34
40
  export interface PillNotificationClassNames {
35
41
  icon?: string;
@@ -21,7 +21,11 @@ export type NotificationAction = {
21
21
  };
22
22
  export interface NotificationPanel {
23
23
  title?: ReactNode;
24
+ /** At the end of the title's row, e.g. a <PillAction>. */
25
+ titleAction?: ReactNode;
24
26
  content: ReactNode;
27
+ /** In the footer, before the close button, e.g. a <PillAction>. */
28
+ footer?: ReactNode;
25
29
  /** The action that opens the panel. Default `{ icon: <PlusIcon />, label: "Learn more" }`. */
26
30
  trigger?: {
27
31
  icon?: ReactNode;
@@ -30,6 +34,8 @@ export interface NotificationPanel {
30
34
  };
31
35
  /** Default "Close". */
32
36
  closeLabel?: string;
37
+ /** Always show the close button's label, not only on hover and focus. */
38
+ closeExpanded?: boolean;
33
39
  }
34
40
  export interface PillNotificationClassNames {
35
41
  icon?: string;
@@ -51,7 +51,10 @@ function NotificationContent({ icon, message, action, panel, linkComponent, clas
51
51
  }),
52
52
  panel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillPanel.PillPanel, {
53
53
  title: panel.title,
54
+ titleAction: panel.titleAction,
55
+ footer: panel.footer,
54
56
  closeLabel: panel.closeLabel,
57
+ closeExpanded: panel.closeExpanded,
55
58
  className: classNames.panel,
56
59
  children: panel.content
57
60
  })
@@ -51,7 +51,10 @@ function NotificationContent({ icon, message, action, panel, linkComponent, clas
51
51
  }),
52
52
  panel && /* @__PURE__ */ jsx(PillPanel, {
53
53
  title: panel.title,
54
+ titleAction: panel.titleAction,
55
+ footer: panel.footer,
54
56
  closeLabel: panel.closeLabel,
57
+ closeExpanded: panel.closeExpanded,
55
58
  className: classNames.panel,
56
59
  children: panel.content
57
60
  })
@@ -0,0 +1,8 @@
1
+ /**
2
+ * What themes can't do in CSS. Render it once, anywhere: the tokens of each
3
+ * themed pill decide. It draws the refraction of the glass (in the browsers
4
+ * that can: Chromium), makes the actions of the same glass
5
+ * (`--mp-action-glass`), has the light follow the pointer (`--mp-light-follow`),
6
+ * and tints the pill after what's behind it (`--mp-adaptive`).
7
+ */
8
+ export declare function PillOptics(): import("react").JSX.Element | null;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * What themes can't do in CSS. Render it once, anywhere: the tokens of each
3
+ * themed pill decide. It draws the refraction of the glass (in the browsers
4
+ * that can: Chromium), makes the actions of the same glass
5
+ * (`--mp-action-glass`), has the light follow the pointer (`--mp-light-follow`),
6
+ * and tints the pill after what's behind it (`--mp-adaptive`).
7
+ */
8
+ export declare function PillOptics(): import("react").JSX.Element | null;