macbetter 0.0.0-stage → 0.1.0-beta.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 (251) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +92 -2
  3. package/dist/components/accessory-tile.d.ts +50 -0
  4. package/dist/components/accessory-tile.js +46 -0
  5. package/dist/components/activity-indicator.d.ts +15 -0
  6. package/dist/components/activity-indicator.js +15 -0
  7. package/dist/components/alert.d.ts +29 -0
  8. package/dist/components/alert.js +30 -0
  9. package/dist/components/artwork.d.ts +44 -0
  10. package/dist/components/artwork.js +935 -0
  11. package/dist/components/automation-row.d.ts +24 -0
  12. package/dist/components/automation-row.js +12 -0
  13. package/dist/components/avatar.d.ts +33 -0
  14. package/dist/components/avatar.js +45 -0
  15. package/dist/components/badge.d.ts +24 -0
  16. package/dist/components/badge.js +19 -0
  17. package/dist/components/button.d.ts +20 -0
  18. package/dist/components/button.js +10 -0
  19. package/dist/components/calendar.d.ts +30 -0
  20. package/dist/components/calendar.js +47 -0
  21. package/dist/components/camera-view.d.ts +40 -0
  22. package/dist/components/camera-view.js +44 -0
  23. package/dist/components/card.d.ts +14 -0
  24. package/dist/components/card.js +21 -0
  25. package/dist/components/carousel.d.ts +18 -0
  26. package/dist/components/carousel.js +33 -0
  27. package/dist/components/checkbox.d.ts +13 -0
  28. package/dist/components/checkbox.js +16 -0
  29. package/dist/components/code-field.d.ts +16 -0
  30. package/dist/components/code-field.js +29 -0
  31. package/dist/components/color-well.d.ts +23 -0
  32. package/dist/components/color-well.js +27 -0
  33. package/dist/components/combo-box.d.ts +42 -0
  34. package/dist/components/combo-box.js +102 -0
  35. package/dist/components/command-palette.d.ts +33 -0
  36. package/dist/components/command-palette.js +55 -0
  37. package/dist/components/context-menu.d.ts +9 -0
  38. package/dist/components/context-menu.js +15 -0
  39. package/dist/components/date-picker.d.ts +53 -0
  40. package/dist/components/date-picker.js +86 -0
  41. package/dist/components/device-frame.d.ts +18 -0
  42. package/dist/components/device-frame.js +16 -0
  43. package/dist/components/dialog.d.ts +27 -0
  44. package/dist/components/dialog.js +35 -0
  45. package/dist/components/disclosure.d.ts +32 -0
  46. package/dist/components/disclosure.js +35 -0
  47. package/dist/components/dock.d.ts +28 -0
  48. package/dist/components/dock.js +80 -0
  49. package/dist/components/door-control.d.ts +20 -0
  50. package/dist/components/door-control.js +43 -0
  51. package/dist/components/energy-readout.d.ts +32 -0
  52. package/dist/components/energy-readout.js +27 -0
  53. package/dist/components/field.d.ts +28 -0
  54. package/dist/components/field.js +32 -0
  55. package/dist/components/gauge.d.ts +25 -0
  56. package/dist/components/gauge.js +42 -0
  57. package/dist/components/glass.d.ts +34 -0
  58. package/dist/components/glass.js +31 -0
  59. package/dist/components/home-backdrop.d.ts +23 -0
  60. package/dist/components/home-backdrop.js +12 -0
  61. package/dist/components/home-section.d.ts +19 -0
  62. package/dist/components/home-section.js +21 -0
  63. package/dist/components/home-status.d.ts +24 -0
  64. package/dist/components/home-status.js +14 -0
  65. package/dist/components/hover-card.d.ts +14 -0
  66. package/dist/components/hover-card.js +16 -0
  67. package/dist/components/level-control.d.ts +19 -0
  68. package/dist/components/level-control.js +13 -0
  69. package/dist/components/light-color-picker.d.ts +33 -0
  70. package/dist/components/light-color-picker.js +56 -0
  71. package/dist/components/list.d.ts +42 -0
  72. package/dist/components/list.js +42 -0
  73. package/dist/components/listbox.d.ts +16 -0
  74. package/dist/components/listbox.js +28 -0
  75. package/dist/components/lock-control.d.ts +20 -0
  76. package/dist/components/lock-control.js +35 -0
  77. package/dist/components/menu-bar.d.ts +14 -0
  78. package/dist/components/menu-bar.js +16 -0
  79. package/dist/components/menu.d.ts +40 -0
  80. package/dist/components/menu.js +54 -0
  81. package/dist/components/navigation-bar.d.ts +24 -0
  82. package/dist/components/navigation-bar.js +54 -0
  83. package/dist/components/outline.d.ts +21 -0
  84. package/dist/components/outline.js +40 -0
  85. package/dist/components/page-control.d.ts +10 -0
  86. package/dist/components/page-control.js +8 -0
  87. package/dist/components/popover.d.ts +16 -0
  88. package/dist/components/popover.js +24 -0
  89. package/dist/components/progress.d.ts +27 -0
  90. package/dist/components/progress.js +27 -0
  91. package/dist/components/radio.d.ts +16 -0
  92. package/dist/components/radio.js +13 -0
  93. package/dist/components/rating.d.ts +10 -0
  94. package/dist/components/rating.js +12 -0
  95. package/dist/components/scene-tile.d.ts +22 -0
  96. package/dist/components/scene-tile.js +13 -0
  97. package/dist/components/scroll-view.d.ts +21 -0
  98. package/dist/components/scroll-view.js +13 -0
  99. package/dist/components/search-field.d.ts +16 -0
  100. package/dist/components/search-field.js +12 -0
  101. package/dist/components/secure-field.d.ts +23 -0
  102. package/dist/components/secure-field.js +21 -0
  103. package/dist/components/segmented-control.d.ts +12 -0
  104. package/dist/components/segmented-control.js +10 -0
  105. package/dist/components/select.d.ts +45 -0
  106. package/dist/components/select.js +79 -0
  107. package/dist/components/sensor-readout.d.ts +29 -0
  108. package/dist/components/sensor-readout.js +12 -0
  109. package/dist/components/separator.d.ts +14 -0
  110. package/dist/components/separator.js +11 -0
  111. package/dist/components/setup-code.d.ts +29 -0
  112. package/dist/components/setup-code.js +47 -0
  113. package/dist/components/sheet.d.ts +31 -0
  114. package/dist/components/sheet.js +51 -0
  115. package/dist/components/sidebar.d.ts +30 -0
  116. package/dist/components/sidebar.js +26 -0
  117. package/dist/components/slider.d.ts +27 -0
  118. package/dist/components/slider.js +43 -0
  119. package/dist/components/split-view.d.ts +11 -0
  120. package/dist/components/split-view.js +13 -0
  121. package/dist/components/squircle.d.ts +41 -0
  122. package/dist/components/squircle.js +63 -0
  123. package/dist/components/stepper.d.ts +30 -0
  124. package/dist/components/stepper.js +28 -0
  125. package/dist/components/switch.d.ts +10 -0
  126. package/dist/components/switch.js +10 -0
  127. package/dist/components/tab-bar.d.ts +20 -0
  128. package/dist/components/tab-bar.js +17 -0
  129. package/dist/components/table.d.ts +49 -0
  130. package/dist/components/table.js +179 -0
  131. package/dist/components/tabs.d.ts +16 -0
  132. package/dist/components/tabs.js +19 -0
  133. package/dist/components/text-area.d.ts +14 -0
  134. package/dist/components/text-area.js +9 -0
  135. package/dist/components/text-field.d.ts +26 -0
  136. package/dist/components/text-field.js +23 -0
  137. package/dist/components/thermostat-control.d.ts +30 -0
  138. package/dist/components/thermostat-control.js +139 -0
  139. package/dist/components/toast.d.ts +30 -0
  140. package/dist/components/toast.js +114 -0
  141. package/dist/components/toggle.d.ts +21 -0
  142. package/dist/components/toggle.js +19 -0
  143. package/dist/components/token-field.d.ts +31 -0
  144. package/dist/components/token-field.js +78 -0
  145. package/dist/components/toolbar.d.ts +27 -0
  146. package/dist/components/toolbar.js +39 -0
  147. package/dist/components/tooltip.d.ts +11 -0
  148. package/dist/components/tooltip.js +18 -0
  149. package/dist/components/window.d.ts +56 -0
  150. package/dist/components/window.js +61 -0
  151. package/dist/index.d.ts +78 -0
  152. package/dist/index.js +79 -0
  153. package/dist/lib/cx.d.ts +9 -0
  154. package/dist/lib/cx.js +14 -0
  155. package/dist/lib/derive.d.ts +53 -0
  156. package/dist/lib/derive.js +255 -0
  157. package/dist/lib/field-glyphs.d.ts +13 -0
  158. package/dist/lib/field-glyphs.js +28 -0
  159. package/dist/lib/menu-glyphs.d.ts +6 -0
  160. package/dist/lib/menu-glyphs.js +15 -0
  161. package/dist/lib/platform.d.ts +18 -0
  162. package/dist/lib/platform.js +17 -0
  163. package/dist/lib/squircle.d.ts +23 -0
  164. package/dist/lib/squircle.js +69 -0
  165. package/dist/lib/theme.d.ts +42 -0
  166. package/dist/lib/theme.js +62 -0
  167. package/dist/styles/base.css +115 -0
  168. package/dist/styles/components/accessory-tile.css +461 -0
  169. package/dist/styles/components/activity-indicator.css +63 -0
  170. package/dist/styles/components/alert.css +433 -0
  171. package/dist/styles/components/artwork.css +380 -0
  172. package/dist/styles/components/automation-row.css +52 -0
  173. package/dist/styles/components/avatar.css +230 -0
  174. package/dist/styles/components/badge.css +204 -0
  175. package/dist/styles/components/button.css +298 -0
  176. package/dist/styles/components/calendar.css +287 -0
  177. package/dist/styles/components/camera-view.css +239 -0
  178. package/dist/styles/components/card.css +100 -0
  179. package/dist/styles/components/carousel.css +210 -0
  180. package/dist/styles/components/checkbox.css +212 -0
  181. package/dist/styles/components/code-field.css +163 -0
  182. package/dist/styles/components/color-well.css +452 -0
  183. package/dist/styles/components/combo-box.css +222 -0
  184. package/dist/styles/components/command-palette.css +379 -0
  185. package/dist/styles/components/context-menu.css +43 -0
  186. package/dist/styles/components/date-picker.css +356 -0
  187. package/dist/styles/components/device-frame.css +194 -0
  188. package/dist/styles/components/dialog.css +366 -0
  189. package/dist/styles/components/disclosure.css +197 -0
  190. package/dist/styles/components/dock.css +404 -0
  191. package/dist/styles/components/door-control.css +187 -0
  192. package/dist/styles/components/energy-readout.css +161 -0
  193. package/dist/styles/components/field.css +175 -0
  194. package/dist/styles/components/gauge.css +239 -0
  195. package/dist/styles/components/glass.css +113 -0
  196. package/dist/styles/components/home-backdrop.css +81 -0
  197. package/dist/styles/components/home-section.css +100 -0
  198. package/dist/styles/components/home-status.css +215 -0
  199. package/dist/styles/components/hover-card.css +145 -0
  200. package/dist/styles/components/index.css +75 -0
  201. package/dist/styles/components/level-control.css +247 -0
  202. package/dist/styles/components/light-color-picker.css +94 -0
  203. package/dist/styles/components/list.css +411 -0
  204. package/dist/styles/components/listbox.css +168 -0
  205. package/dist/styles/components/lock-control.css +164 -0
  206. package/dist/styles/components/menu-bar.css +94 -0
  207. package/dist/styles/components/menu.css +454 -0
  208. package/dist/styles/components/navigation-bar.css +248 -0
  209. package/dist/styles/components/outline.css +248 -0
  210. package/dist/styles/components/page-control.css +127 -0
  211. package/dist/styles/components/popover.css +186 -0
  212. package/dist/styles/components/progress.css +228 -0
  213. package/dist/styles/components/radio.css +281 -0
  214. package/dist/styles/components/rating.css +122 -0
  215. package/dist/styles/components/scene-tile.css +295 -0
  216. package/dist/styles/components/scroll-view.css +195 -0
  217. package/dist/styles/components/search-field.css +128 -0
  218. package/dist/styles/components/secure-field.css +189 -0
  219. package/dist/styles/components/segmented-control.css +183 -0
  220. package/dist/styles/components/select.css +290 -0
  221. package/dist/styles/components/sensor-readout.css +231 -0
  222. package/dist/styles/components/separator.css +62 -0
  223. package/dist/styles/components/setup-code.css +138 -0
  224. package/dist/styles/components/sheet.css +345 -0
  225. package/dist/styles/components/sidebar.css +261 -0
  226. package/dist/styles/components/slider.css +208 -0
  227. package/dist/styles/components/split-view.css +75 -0
  228. package/dist/styles/components/squircle.css +44 -0
  229. package/dist/styles/components/stepper.css +278 -0
  230. package/dist/styles/components/switch.css +115 -0
  231. package/dist/styles/components/tab-bar.css +223 -0
  232. package/dist/styles/components/table.css +313 -0
  233. package/dist/styles/components/tabs.css +262 -0
  234. package/dist/styles/components/text-area.css +94 -0
  235. package/dist/styles/components/text-field.css +294 -0
  236. package/dist/styles/components/thermostat-control.css +214 -0
  237. package/dist/styles/components/toast.css +418 -0
  238. package/dist/styles/components/toggle.css +312 -0
  239. package/dist/styles/components/token-field.css +193 -0
  240. package/dist/styles/components/toolbar.css +370 -0
  241. package/dist/styles/components/tooltip.css +69 -0
  242. package/dist/styles/components/window.css +428 -0
  243. package/dist/styles/index.css +17 -0
  244. package/dist/styles/materials.css +263 -0
  245. package/dist/styles/platforms.css +214 -0
  246. package/dist/styles/themes/ember.css +24 -0
  247. package/dist/styles/themes/graphite.css +16 -0
  248. package/dist/styles/themes/nebula.css +16 -0
  249. package/dist/styles/themes/system.css +28 -0
  250. package/dist/styles/tokens.css +299 -0
  251. package/package.json +82 -3
@@ -0,0 +1,179 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { createChange, createRovingFocus, createSelection, definePrimitive, } from "@ui-sdk/core";
4
+ import { createParts } from "@ui-sdk/react/primitive";
5
+ import { cx, join } from "../lib/cx.js";
6
+ const table = definePrimitive({
7
+ name: "table",
8
+ options: {
9
+ selectionMode: "string",
10
+ value: "list",
11
+ defaultValue: "list",
12
+ onValueChange: "callback",
13
+ sort: "value",
14
+ defaultSort: "value",
15
+ onSortChange: "callback",
16
+ onAction: "callback",
17
+ },
18
+ controlled: ["value", "sort"],
19
+ state: (options) => ({
20
+ mode: options.selectionMode ?? "none",
21
+ value: options.value ?? options.defaultValue ?? [],
22
+ sort: options.sort ?? options.defaultSort ?? null,
23
+ focused: null,
24
+ }),
25
+ sync: (options) => ({
26
+ mode: options.selectionMode ?? "none",
27
+ ...(options.value === undefined ? {} : { value: options.value }),
28
+ ...(options.sort === undefined ? {} : { sort: options.sort }),
29
+ }),
30
+ api: (context) => {
31
+ const change = createChange(context);
32
+ const roving = createRovingFocus(context, {
33
+ slot: "row",
34
+ key: "focused",
35
+ preferred: (row) => context.store.get().value.includes(row.key),
36
+ });
37
+ const selection = createSelection(context, {
38
+ key: "value",
39
+ set: (value, details) => change("value", value, details),
40
+ order: () => roving.items().map((row) => row.key),
41
+ multiple: () => context.store.get().mode === "multiple",
42
+ });
43
+ return {
44
+ roving,
45
+ selection,
46
+ press(key, event) {
47
+ if (context.store.get().mode === "none")
48
+ return;
49
+ const mouse = event;
50
+ const details = { reason: "item-press", event };
51
+ if (mouse?.shiftKey)
52
+ selection.extend(key, { ...details, from: context.store.get().focused });
53
+ else if (mouse?.metaKey || mouse?.ctrlKey)
54
+ selection.toggle(key, details);
55
+ else
56
+ selection.choose(key, details);
57
+ },
58
+ keydown(event, el, key) {
59
+ const { mode } = context.store.get();
60
+ if (mode === "multiple" && (event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "a") {
61
+ event.preventDefault();
62
+ // Command-A always selects everything on macOS; it never clears a full selection.
63
+ const all = roving.items().map((row) => row.key);
64
+ const { value } = context.store.get();
65
+ if (!all.every((row) => value.includes(row)))
66
+ change("value", all, { reason: "list-navigation", event });
67
+ return;
68
+ }
69
+ if (event.key === " " && mode !== "none") {
70
+ event.preventDefault();
71
+ selection.toggle(key, { reason: "item-press", event });
72
+ return;
73
+ }
74
+ if (event.key === "Enter") {
75
+ context.options().onAction?.(key);
76
+ return;
77
+ }
78
+ if ((event.metaKey || event.ctrlKey) && (event.key === "ArrowUp" || event.key === "ArrowDown")) {
79
+ // Roving focus ignores modified arrows, so move focus here without touching the selection (APG multi-select).
80
+ const rows = roving.items();
81
+ const at = rows.findIndex((row) => row.key === key);
82
+ const next = rows[at + (event.key === "ArrowDown" ? 1 : -1)];
83
+ if (next) {
84
+ event.preventDefault();
85
+ next.el.focus();
86
+ }
87
+ return;
88
+ }
89
+ const moved = roving.keydown(event, el);
90
+ if (!moved || mode === "none" || moved.key === moved.from)
91
+ return;
92
+ // macOS tables move the selection with the arrows; Command or Control moves focus alone.
93
+ if (moved.shift)
94
+ selection.extend(moved.key, { from: moved.from, reason: "list-navigation", event });
95
+ else if (!(event.metaKey || event.ctrlKey))
96
+ selection.choose(moved.key, { reason: "list-navigation", event });
97
+ },
98
+ action(key) {
99
+ context.options().onAction?.(key);
100
+ },
101
+ sortBy(column, event) {
102
+ const current = context.store.get().sort;
103
+ const direction = current?.column === column && current.direction === "ascending" ? "descending" : "ascending";
104
+ change("sort", { column, direction }, { reason: "item-press", event });
105
+ },
106
+ };
107
+ },
108
+ slots: (slot) => ({
109
+ root: slot({
110
+ role: (state) => (state.mode === "none" ? undefined : "grid"),
111
+ roles: ["grid"],
112
+ keys: { none: "Each row handles its own keys." },
113
+ attrs: (state) => ({
114
+ "aria-multiselectable": state.mode === "multiple" ? "true" : undefined,
115
+ "data-selection-mode": state.mode,
116
+ }),
117
+ }),
118
+ row: slot({
119
+ props: { value: "string" },
120
+ state: (state, part) => ({ selected: state.value.includes(part.key) }),
121
+ attrs: (state, part) => ({
122
+ tabindex: state.mode === "none" ? undefined : part.api.roving.tabIndex(state, part),
123
+ "aria-selected": state.mode === "none" ? undefined : String(state.value.includes(part.key)),
124
+ "data-selected": state.value.includes(part.key) ? "" : undefined,
125
+ }),
126
+ on: {
127
+ keydown: (event, { el, api, key }) => {
128
+ if (el)
129
+ api.keydown(event, el, key);
130
+ },
131
+ click: (event, { api, key }) => api.press(key, event),
132
+ dblclick: (_event, { api, key }) => api.action(key),
133
+ },
134
+ bind: (el, part) => part.api.roving.bind(el, part),
135
+ }),
136
+ column: slot({
137
+ props: { value: "string", sortable: "boolean" },
138
+ attrs: (state, part) => {
139
+ const sorted = part.props.sortable && state.sort?.column === part.key ? state.sort.direction : undefined;
140
+ return {
141
+ "aria-sort": part.props.sortable ? (sorted ?? "none") : undefined,
142
+ "data-sorted": sorted,
143
+ };
144
+ },
145
+ }),
146
+ sort: slot({
147
+ props: { value: "string" },
148
+ attrs: () => ({ type: "button" }),
149
+ press: ({ api, key }, event) => api.sortBy(key, event),
150
+ }),
151
+ }),
152
+ agent: { actions: ["sortBy"] },
153
+ });
154
+ const parts = createParts(table, {
155
+ root: "table",
156
+ row: "tr",
157
+ column: "th",
158
+ sort: "button",
159
+ });
160
+ function Table({ alternating, className, ...props }) {
161
+ return (_jsx(parts.Root, { "data-alternating": alternating ? "" : undefined, className: cx("mb-table", className), ...props }));
162
+ }
163
+ function TableHeader({ className, children, ...props }) {
164
+ return (_jsx("thead", { className: join("mb-table-header", className), ...props, children: _jsx("tr", { className: "mb-table-header-row", children: children }) }));
165
+ }
166
+ function TableColumn({ value, align = "start", className, children, ...props }) {
167
+ const sortable = value !== undefined;
168
+ return (_jsx(parts.Column, { value: value ?? "", sortable: sortable, scope: "col", "data-align": align, className: cx("mb-table-column", className), ...props, children: sortable ? (_jsxs(parts.Sort, { value: value, className: "mb-table-sort", children: [_jsx("span", { className: "mb-table-sort-label", children: children }), _jsx("svg", { className: "mb-table-sort-indicator", viewBox: "0 0 10 6", "aria-hidden": "true", children: _jsx("path", { d: "M1 1.25 5 4.75l4-3.5" }) })] })) : (children) }));
169
+ }
170
+ function TableBody({ className, ...props }) {
171
+ return _jsx("tbody", { className: join("mb-table-body", className), ...props });
172
+ }
173
+ function TableRow({ className, ...props }) {
174
+ return _jsx(parts.Row, { className: cx("mb-table-row", className), ...props });
175
+ }
176
+ function TableCell({ align = "start", secondary, className, ...props }) {
177
+ return (_jsx("td", { "data-align": align, "data-secondary": secondary ? "" : undefined, className: join("mb-table-cell", className), ...props }));
178
+ }
179
+ export { Table, TableBody, TableCell, TableColumn, TableHeader, TableRow };
@@ -0,0 +1,16 @@
1
+ import { Tabs as TabsPrimitive, TabsList as TabsListPrimitive, TabsPanel as TabsPanelPrimitive, TabsTab as TabsTabPrimitive, TabsTabIcon as TabsTabIconPrimitive } from "@ui-sdk/react/tabs";
2
+ import type * as React from "react";
3
+ type TabsProps = React.ComponentProps<typeof TabsPrimitive> & {
4
+ /** `bordered` is the macOS tab view: a segmented strip on the edge of a framed panel. `plain` has no frame. */
5
+ variant?: "bordered" | "plain";
6
+ };
7
+ declare function Tabs({ variant, className, ...props }: TabsProps): React.JSX.Element;
8
+ type TabsListProps = Omit<React.ComponentProps<typeof TabsListPrimitive>, "children"> & {
9
+ children?: React.ReactNode;
10
+ };
11
+ declare function TabsList({ className, children, ...props }: TabsListProps): React.JSX.Element;
12
+ declare function TabsTab({ className, ...props }: React.ComponentProps<typeof TabsTabPrimitive>): React.JSX.Element;
13
+ declare function TabsTabIcon({ className, ...props }: React.ComponentProps<typeof TabsTabIconPrimitive>): React.JSX.Element;
14
+ declare function TabsPanel({ className, ...props }: React.ComponentProps<typeof TabsPanelPrimitive>): React.JSX.Element;
15
+ export { Tabs, TabsList, TabsPanel, TabsTab, TabsTabIcon };
16
+ export type { TabsListProps, TabsProps };
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Tabs as TabsPrimitive, TabsIndicator, TabsList as TabsListPrimitive, TabsPanel as TabsPanelPrimitive, TabsTab as TabsTabPrimitive, TabsTabIcon as TabsTabIconPrimitive, } from "@ui-sdk/react/tabs";
3
+ import { cx } from "../lib/cx.js";
4
+ function Tabs({ variant = "bordered", className, ...props }) {
5
+ return _jsx(TabsPrimitive, { "data-variant": variant, className: cx("mb-tabs", className), ...props });
6
+ }
7
+ function TabsList({ className, children, ...props }) {
8
+ return (_jsxs(TabsListPrimitive, { className: cx("mb-tabs-list", className), ...props, children: [_jsx(TabsIndicator, { className: "mb-tabs-indicator" }), children] }));
9
+ }
10
+ function TabsTab({ className, ...props }) {
11
+ return _jsx(TabsTabPrimitive, { className: cx("mb-tabs-tab", className), ...props });
12
+ }
13
+ function TabsTabIcon({ className, ...props }) {
14
+ return _jsx(TabsTabIconPrimitive, { className: cx("mb-tabs-tab-icon", className), ...props });
15
+ }
16
+ function TabsPanel({ className, ...props }) {
17
+ return _jsx(TabsPanelPrimitive, { className: cx("mb-tabs-panel", className), ...props });
18
+ }
19
+ export { Tabs, TabsList, TabsPanel, TabsTab, TabsTabIcon };
@@ -0,0 +1,14 @@
1
+ import { Textarea } from "@ui-sdk/react/textarea";
2
+ import type * as React from "react";
3
+ type TextAreaProps = React.ComponentProps<typeof Textarea> & {
4
+ /** `auto` is bordered on macOS and filled on touch, like `TextField`. */
5
+ variant?: "auto" | "bordered" | "filled" | "plain";
6
+ /** The fewest lines it shows. */
7
+ minRows?: number;
8
+ /** The most lines it grows to before it scrolls. */
9
+ maxRows?: number;
10
+ };
11
+ /** Several lines of text. It grows with what's typed, from `minRows` to `maxRows`. */
12
+ declare function TextArea({ variant, autoResize, minRows, maxRows, className, style, ...props }: TextAreaProps): React.JSX.Element;
13
+ export { TextArea };
14
+ export type { TextAreaProps };
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Textarea } from "@ui-sdk/react/textarea";
3
+ import { cx } from "../lib/cx.js";
4
+ /** Several lines of text. It grows with what's typed, from `minRows` to `maxRows`. */
5
+ function TextArea({ variant = "auto", autoResize = true, minRows = 3, maxRows = 10, className, style, ...props }) {
6
+ const rows = { "--mb-text-area-min-rows": minRows, "--mb-text-area-max-rows": maxRows };
7
+ return (_jsx(Textarea, { autoResize: autoResize, rows: minRows, "data-variant": variant, className: cx("mb-text-area", className), style: typeof style === "function" ? (state) => ({ ...rows, ...style(state) }) : { ...rows, ...style }, ...props }));
8
+ }
9
+ export { TextArea };
@@ -0,0 +1,26 @@
1
+ import { Input, InputClear, InputGroup } from "@ui-sdk/react/input";
2
+ import type * as React from "react";
3
+ type TextFieldSize = "sm" | "md" | "lg";
4
+ /** `bordered` is the macOS field; `filled` is the iOS gray field; `plain` has no chrome, for list rows. */
5
+ type TextFieldVariant = "auto" | "bordered" | "filled" | "plain";
6
+ type TextFieldProps = Omit<React.ComponentProps<typeof Input>, "size"> & {
7
+ size?: TextFieldSize;
8
+ /** `auto` is bordered on macOS and filled on touch. */
9
+ variant?: TextFieldVariant;
10
+ };
11
+ /**
12
+ * A single line of text. On its own it draws the field; inside a
13
+ * `TextFieldGroup` the group draws it, around adornments and a clear button.
14
+ */
15
+ declare function TextField({ size, variant, className, ...props }: TextFieldProps): React.JSX.Element;
16
+ type TextFieldGroupProps = React.ComponentProps<typeof InputGroup> & {
17
+ size?: TextFieldSize;
18
+ variant?: TextFieldVariant;
19
+ };
20
+ declare function TextFieldGroup({ size, variant, className, ...props }: TextFieldGroupProps): React.JSX.Element;
21
+ /** Text or an icon beside the input, like a unit, a prefix or a symbol. Pressing it focuses the input. */
22
+ declare function TextFieldAdornment({ className, ...props }: React.ComponentProps<"span">): React.JSX.Element;
23
+ /** The clear button: xmark.circle.fill, shown only while there's text. */
24
+ declare function TextFieldClear({ className, children, "aria-label": label, ...props }: React.ComponentProps<typeof InputClear>): React.JSX.Element;
25
+ export { TextField, TextFieldAdornment, TextFieldClear, TextFieldGroup };
26
+ export type { TextFieldGroupProps, TextFieldProps, TextFieldSize, TextFieldVariant };
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Input, InputClear, InputGroup } from "@ui-sdk/react/input";
3
+ import { cx, join } from "../lib/cx.js";
4
+ import { ClearGlyph } from "../lib/field-glyphs.js";
5
+ /**
6
+ * A single line of text. On its own it draws the field; inside a
7
+ * `TextFieldGroup` the group draws it, around adornments and a clear button.
8
+ */
9
+ function TextField({ size = "md", variant = "auto", className, ...props }) {
10
+ return _jsx(Input, { "data-size": size, "data-variant": variant, className: cx("mb-text-field", className), ...props });
11
+ }
12
+ function TextFieldGroup({ size = "md", variant = "auto", className, ...props }) {
13
+ return (_jsx(InputGroup, { "data-size": size, "data-variant": variant, className: cx("mb-text-field-group", className), ...props }));
14
+ }
15
+ /** Text or an icon beside the input, like a unit, a prefix or a symbol. Pressing it focuses the input. */
16
+ function TextFieldAdornment({ className, ...props }) {
17
+ return _jsx("span", { className: join("mb-text-field-adornment", className), ...props });
18
+ }
19
+ /** The clear button: xmark.circle.fill, shown only while there's text. */
20
+ function TextFieldClear({ className, children, "aria-label": label = "Clear text", ...props }) {
21
+ return (_jsx(InputClear, { "aria-label": label, className: cx("mb-text-field-clear", className), ...props, children: children ?? _jsx(ClearGlyph, {}) }));
22
+ }
23
+ export { TextField, TextFieldAdornment, TextFieldClear, TextFieldGroup };
@@ -0,0 +1,30 @@
1
+ import * as React from "react";
2
+ type ThermostatMode = "off" | "heat" | "cool" | "auto";
3
+ type ThermostatState = "idle" | "heating" | "cooling";
4
+ type ThermostatControlProps = Omit<React.ComponentProps<"div">, "children"> & {
5
+ mode: ThermostatMode;
6
+ onModeChange?: (mode: ThermostatMode) => void;
7
+ /** The target in degrees Celsius, as HomeKit stores it. Used in heat and cool. */
8
+ target?: number;
9
+ onTargetChange?: (celsius: number) => void;
10
+ /** Heating and cooling thresholds in degrees Celsius, used in auto. */
11
+ range?: [number, number];
12
+ onRangeChange?: (celsius: [number, number]) => void;
13
+ /** The measured temperature, in degrees Celsius. */
14
+ current: number;
15
+ /** What the system is doing now, from HomeKit's current heating cooling state. */
16
+ state?: ThermostatState;
17
+ /** How temperatures read. Values in and out stay in Celsius. */
18
+ unit?: "celsius" | "fahrenheit";
19
+ min?: number;
20
+ max?: number;
21
+ /** One step, in the display unit. Defaults to 0.5 °C or 1 °F. */
22
+ step?: number;
23
+ /** Names the control, like "Hallway thermostat". */
24
+ name?: string;
25
+ modes?: ThermostatMode[];
26
+ hideModes?: boolean;
27
+ };
28
+ declare function ThermostatControl({ mode, onModeChange, target, onTargetChange, range, onRangeChange, current, state, unit, min, max, step, name, modes, hideModes, className, ...props }: ThermostatControlProps): React.JSX.Element;
29
+ export { ThermostatControl };
30
+ export type { ThermostatControlProps, ThermostatMode, ThermostatState };
@@ -0,0 +1,139 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // Client-only: it keeps the dial in step with the slider and maps pointer angles to values.
4
+ import { createSliderController, Slider as SliderPrimitive, SliderControl as SliderControlPrimitive, SliderThumb as SliderThumbPrimitive, SliderTrack as SliderTrackPrimitive, } from "@ui-sdk/react/slider";
5
+ import * as React from "react";
6
+ import { join } from "../lib/cx.js";
7
+ import { SegmentedControl, SegmentedControlItem } from "./segmented-control.js";
8
+ const MODE_LABELS = { off: "Off", heat: "Heat", cool: "Cool", auto: "Auto" };
9
+ // The dial runs 270°, clockwise from the lower left, leaving the gap at the bottom.
10
+ const START = 135;
11
+ const SWEEP = 270;
12
+ const SIZE = 240;
13
+ const CENTER = SIZE / 2;
14
+ const RADIUS = 100;
15
+ function polar(angle, radius = RADIUS) {
16
+ const rad = (angle * Math.PI) / 180;
17
+ return { x: CENTER + radius * Math.cos(rad), y: CENTER + radius * Math.sin(rad) };
18
+ }
19
+ function arc(from, to) {
20
+ const a = polar(START + SWEEP * from);
21
+ const b = polar(START + SWEEP * Math.max(to, from + 0.0001));
22
+ const large = SWEEP * (to - from) > 180 ? 1 : 0;
23
+ return `M${a.x.toFixed(2)} ${a.y.toFixed(2)}A${RADIUS} ${RADIUS} 0 ${large} 1 ${b.x.toFixed(2)} ${b.y.toFixed(2)}`;
24
+ }
25
+ const toF = (c) => (c * 9) / 5 + 32;
26
+ const toC = (f) => ((f - 32) * 5) / 9;
27
+ function ThermostatControl({ mode, onModeChange, target = 21, onTargetChange, range = [19, 24], onRangeChange, current, state = "idle", unit = "celsius", min = 10, max = 32, step, name = "Thermostat", modes = ["off", "heat", "cool", "auto"], hideModes, className, ...props }) {
28
+ const fahrenheit = unit === "fahrenheit";
29
+ const unitStep = step ?? (fahrenheit ? 1 : 0.5);
30
+ const snap = (value) => Math.round(value / unitStep) * unitStep;
31
+ const toDisplay = (c) => snap(fahrenheit ? toF(c) : c);
32
+ const fromDisplay = (d) => Math.round((fahrenheit ? toC(d) : d) * 100) / 100;
33
+ const lo = toDisplay(min);
34
+ const hi = toDisplay(max);
35
+ const gap = unitStep * (fahrenheit ? 3 : 2);
36
+ // Follows the props, and moves on its own when nobody controls it.
37
+ const [inner, setInner] = React.useState({ mode, target, range });
38
+ React.useEffect(() => setInner((s) => ({ ...s, mode })), [mode]);
39
+ React.useEffect(() => setInner((s) => ({ ...s, target })), [target]);
40
+ const [r0, r1] = range;
41
+ React.useEffect(() => setInner((s) => ({ ...s, range: [r0, r1] })), [r0, r1]);
42
+ const activeMode = inner.mode;
43
+ const auto = activeMode === "auto";
44
+ const off = activeMode === "off";
45
+ const value = auto
46
+ ? [toDisplay(inner.range[0]), toDisplay(inner.range[1])]
47
+ : toDisplay(inner.target);
48
+ const values = Array.isArray(value) ? value : [value];
49
+ const fraction = (d) => Math.min(1, Math.max(0, (d - lo) / (hi - lo)));
50
+ const [controller] = React.useState(() => createSliderController());
51
+ const drag = React.useRef(null);
52
+ const setDisplay = (next) => {
53
+ if (Array.isArray(next)) {
54
+ const celsius = [fromDisplay(next[0]), fromDisplay(next[1])];
55
+ setInner((s) => ({ ...s, range: celsius }));
56
+ onRangeChange?.(celsius);
57
+ }
58
+ else {
59
+ const celsius = fromDisplay(next);
60
+ setInner((s) => ({ ...s, target: celsius }));
61
+ onTargetChange?.(celsius);
62
+ }
63
+ };
64
+ const valueAt = (event) => {
65
+ const box = event.currentTarget.getBoundingClientRect();
66
+ const x = ((event.clientX - box.left) / box.width) * SIZE - CENTER;
67
+ const y = ((event.clientY - box.top) / box.height) * SIZE - CENTER;
68
+ let angle = ((Math.atan2(y, x) * 180) / Math.PI - START + 720) % 360;
69
+ if (angle > SWEEP)
70
+ angle = angle > SWEEP + (360 - SWEEP) / 2 ? 0 : SWEEP;
71
+ return snap(lo + (angle / SWEEP) * (hi - lo));
72
+ };
73
+ const moveTo = (event, thumb) => {
74
+ const d = valueAt(event);
75
+ if (!auto) {
76
+ controller.setValue(d, { reason: "drag", event: event.nativeEvent });
77
+ return;
78
+ }
79
+ const [heat, cool] = values;
80
+ const next = thumb === 0 ? [Math.min(d, cool - gap), cool] : [heat, Math.max(d, heat + gap)];
81
+ controller.setValue(next, { reason: "drag", event: event.nativeEvent });
82
+ };
83
+ const onPointerDown = (event) => {
84
+ if (off || event.button !== 0)
85
+ return;
86
+ const d = valueAt(event);
87
+ const thumb = auto ? (Math.abs(d - values[0]) <= Math.abs(d - values[1]) ? 0 : 1) : 0;
88
+ drag.current = thumb;
89
+ event.currentTarget.setPointerCapture(event.pointerId);
90
+ event.preventDefault();
91
+ controller.focus(thumb);
92
+ moveTo(event, thumb);
93
+ };
94
+ const format = (d) => `${d.toLocaleString(undefined, { maximumFractionDigits: fahrenheit ? 0 : 1 })}°`;
95
+ const now = toDisplay(current);
96
+ const caption = off
97
+ ? "Currently"
98
+ : auto
99
+ ? state === "heating"
100
+ ? "Heating"
101
+ : state === "cooling"
102
+ ? "Cooling"
103
+ : "Auto"
104
+ : activeMode === "heat"
105
+ ? state === "heating"
106
+ ? "Heating to"
107
+ : "Heat to"
108
+ : state === "cooling"
109
+ ? "Cooling to"
110
+ : "Cool to";
111
+ const big = off ? format(now) : auto ? `${format(values[0]).slice(0, -1)}–${format(values[1])}` : format(values[0]);
112
+ const footer = off ? "Off" : `Currently ${format(now)}`;
113
+ const status = state === "heating" ? "Heating" : state === "cooling" ? "Cooling" : "Idle";
114
+ const nowAngle = START + SWEEP * fraction(now);
115
+ const tickIn = polar(nowAngle, RADIUS - 15);
116
+ const tickOut = polar(nowAngle, RADIUS + 15);
117
+ const [f0, f1] = [fraction(values[0]), fraction(values[values.length - 1])];
118
+ const middle = (f0 + f1) / 2;
119
+ return (_jsxs("div", { "data-mode": activeMode, "data-state": off ? undefined : state, className: join("mb-thermostat-control", className), ...props, children: [_jsxs("div", { className: "mb-thermostat-control-dial", children: [_jsxs("svg", { viewBox: `0 0 ${SIZE} ${SIZE}`, "aria-hidden": "true", className: "mb-thermostat-control-svg", onPointerDown: onPointerDown, onPointerMove: (event) => {
120
+ if (drag.current !== null)
121
+ moveTo(event, drag.current);
122
+ }, onPointerUp: () => {
123
+ drag.current = null;
124
+ }, onPointerCancel: () => {
125
+ drag.current = null;
126
+ }, children: [_jsx("path", { d: arc(0, 1), className: "mb-thermostat-control-track" }), off ? null : auto ? (_jsxs(_Fragment, { children: [_jsx("path", { d: arc(f0, middle), className: "mb-thermostat-control-arc", "data-tone": "heat" }), _jsx("path", { d: arc(middle, f1), className: "mb-thermostat-control-arc", "data-tone": "cool" })] })) : activeMode === "heat" ? (_jsx("path", { d: arc(0, f0), className: "mb-thermostat-control-arc", "data-tone": "heat" })) : (_jsx("path", { d: arc(f0, 1), className: "mb-thermostat-control-arc", "data-tone": "cool" })), _jsx("line", { x1: tickIn.x, y1: tickIn.y, x2: tickOut.x, y2: tickOut.y, className: "mb-thermostat-control-current" }), off
127
+ ? null
128
+ : values.map((d, index) => {
129
+ const point = polar(START + SWEEP * fraction(d));
130
+ return (_jsx("circle", { cx: point.x, cy: point.y, r: 14, "data-thumb": index, className: "mb-thermostat-control-knob" }, index));
131
+ })] }), _jsxs("div", { className: "mb-thermostat-control-readout", children: [_jsx("span", { className: "mb-thermostat-control-caption", children: caption }), _jsx("span", { className: "mb-thermostat-control-target", "data-range": auto ? "" : undefined, children: big }), _jsx("span", { className: "mb-thermostat-control-now", children: footer })] }), _jsx(SliderPrimitive, { "aria-label": name, controller: controller, value: value, onValueChange: (next) => setDisplay(next), min: lo, max: hi, step: unitStep, minStepsBetweenThumbs: auto ? Math.round(gap / unitStep) : undefined, disabled: off, format: { style: "unit", unit: fahrenheit ? "fahrenheit" : "celsius", maximumFractionDigits: 1 }, className: "mb-thermostat-control-slider", children: _jsx(SliderControlPrimitive, { className: "mb-thermostat-control-slider-control", children: _jsx(SliderTrackPrimitive, { className: "mb-thermostat-control-slider-track", children: auto ? (_jsxs(_Fragment, { children: [_jsx(SliderThumbPrimitive, { index: 0, "data-thumb": 0, "aria-label": "Heat to", className: "mb-thermostat-control-thumb" }), _jsx(SliderThumbPrimitive, { index: 1, "data-thumb": 1, "aria-label": "Cool to", className: "mb-thermostat-control-thumb" })] })) : (_jsx(SliderThumbPrimitive, { "data-thumb": 0, "aria-label": activeMode === "cool" ? "Cool to" : "Heat to", className: "mb-thermostat-control-thumb" })) }) }) })] }), off ? null : (_jsxs("span", { className: "mb-thermostat-control-status", "data-state": state, children: [_jsx("span", { "aria-hidden": "true", className: "mb-thermostat-control-status-dot" }), status] })), hideModes ? null : (_jsx(SegmentedControl, { "aria-label": "Mode", block: true, value: activeMode, onValueChange: (next) => {
132
+ if (!next)
133
+ return;
134
+ const nextMode = next;
135
+ setInner((s) => ({ ...s, mode: nextMode }));
136
+ onModeChange?.(nextMode);
137
+ }, className: "mb-thermostat-control-modes", children: modes.map((item) => (_jsx(SegmentedControlItem, { value: item, children: MODE_LABELS[item] }, item))) }))] }));
138
+ }
139
+ export { ThermostatControl };
@@ -0,0 +1,30 @@
1
+ import { Toast as ToastPrimitive, ToastAction as ToastActionPrimitive, ToastClose as ToastClosePrimitive, ToastDescription as ToastDescriptionPrimitive, ToastRegion, ToastTitle as ToastTitlePrimitive } from "@ui-sdk/react/toast";
2
+ import * as React from "react";
3
+ /** What a notification can carry in `data`, beyond its title and description. */
4
+ type NotificationData = {
5
+ /** The app icon, about 32pt on macOS and 38pt on iOS. Defaults to a glyph for the toast's type. */
6
+ icon?: React.ReactNode;
7
+ /** When it happened, shown at the trailing edge, like "now" or "2m ago". */
8
+ time?: React.ReactNode;
9
+ };
10
+ declare function Toast({ className, ...props }: React.ComponentProps<typeof ToastPrimitive>): React.JSX.Element;
11
+ declare function ToastTitle({ className, ...props }: React.ComponentProps<typeof ToastTitlePrimitive>): React.JSX.Element;
12
+ declare function ToastDescription({ className, ...props }: React.ComponentProps<typeof ToastDescriptionPrimitive>): React.JSX.Element;
13
+ declare function ToastAction({ className, ...props }: React.ComponentProps<typeof ToastActionPrimitive>): React.JSX.Element;
14
+ declare function ToastClose({ className, children, ...props }: React.ComponentProps<typeof ToastClosePrimitive>): React.JSX.Element;
15
+ /** A rounded app-icon tile, for an icon you pass in `data.icon` or the glyph of the toast's type. */
16
+ declare function ToastIcon({ className, ...props }: React.ComponentProps<"span">): React.JSX.Element;
17
+ type ToasterProps = Omit<React.ComponentProps<typeof ToastRegion>, "children"> & {
18
+ /** Renders each toast. Defaults to a system notification: icon, title, time, description, action and close. */
19
+ children?: React.ComponentProps<typeof ToastRegion>["children"];
20
+ };
21
+ /**
22
+ * The notification host. Mount it once near the root and call `toast()` from
23
+ * anywhere: notifications drop in at the top right on the Mac and as banners
24
+ * at the top of the screen on iPhone and iPad.
25
+ */
26
+ declare function Toaster({ align, side, className, children, ...props }: ToasterProps): React.JSX.Element;
27
+ export { createToaster, toast } from "@ui-sdk/react/toast";
28
+ export type { ToastData, ToastType, Toaster as ToasterQueue } from "@ui-sdk/react/toast";
29
+ export { Toast, ToastAction, ToastClose, ToastDescription, Toaster, ToastIcon, ToastTitle };
30
+ export type { NotificationData, ToasterProps };
@@ -0,0 +1,114 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Toast as ToastPrimitive, ToastAction as ToastActionPrimitive, ToastClose as ToastClosePrimitive, ToastDescription as ToastDescriptionPrimitive, ToastRegion, ToastTitle as ToastTitlePrimitive, } from "@ui-sdk/react/toast";
4
+ import * as React from "react";
5
+ import { cx, join } from "../lib/cx.js";
6
+ function Toast({ className, ...props }) {
7
+ return _jsx(ToastPrimitive, { className: cx("mb-toast", className), ...props });
8
+ }
9
+ function ToastTitle({ className, ...props }) {
10
+ return _jsx(ToastTitlePrimitive, { className: cx("mb-toast-title", className), ...props });
11
+ }
12
+ function ToastDescription({ className, ...props }) {
13
+ return _jsx(ToastDescriptionPrimitive, { className: cx("mb-toast-description", className), ...props });
14
+ }
15
+ function ToastAction({ className, ...props }) {
16
+ return _jsx(ToastActionPrimitive, { className: cx("mb-toast-action", className), ...props });
17
+ }
18
+ function ToastClose({ className, children, ...props }) {
19
+ return (_jsx(ToastClosePrimitive, { "aria-label": "Close", className: cx("mb-toast-close", className), ...props, children: children ?? (_jsx("svg", { viewBox: "0 0 10 10", "aria-hidden": "true", children: _jsx("path", { d: "M2.5 2.5l5 5m0-5l-5 5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" }) })) }));
20
+ }
21
+ /** A rounded app-icon tile, for an icon you pass in `data.icon` or the glyph of the toast's type. */
22
+ function ToastIcon({ className, ...props }) {
23
+ return _jsx("span", { "aria-hidden": "true", className: join("mb-toast-icon", className), ...props });
24
+ }
25
+ const typeGlyphs = {
26
+ success: _jsx("path", { d: "M6.5 12.5l3.5 3.5 7.5-8", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round" }),
27
+ error: _jsx("path", { d: "M8 8l8 8m0-8l-8 8", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round" }),
28
+ warning: (_jsxs(_Fragment, { children: [_jsx("path", { d: "M12 6.5v7", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round" }), _jsx("circle", { cx: "12", cy: "17.25", r: "1.5", fill: "currentColor" })] })),
29
+ info: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "12", cy: "7", r: "1.5", fill: "currentColor" }), _jsx("path", { d: "M12 11v6.5", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round" })] })),
30
+ };
31
+ function defaultIcon(type) {
32
+ if (type === "loading")
33
+ return _jsx("span", { className: "mb-toast-spinner" });
34
+ const glyph = type ? typeGlyphs[type] : undefined;
35
+ return glyph ? _jsx("svg", { viewBox: "0 0 24 24", children: glyph }) : null;
36
+ }
37
+ function Notification({ toast }) {
38
+ const data = (toast.data ?? {});
39
+ const icon = data.icon ?? defaultIcon(toast.type);
40
+ return (_jsxs(Toast, { children: [icon ? _jsx(ToastIcon, { "data-type": data.icon ? undefined : toast.type, children: icon }) : null, _jsxs("div", { className: "mb-toast-content", children: [_jsxs("div", { className: "mb-toast-header", children: [_jsx(ToastTitle, {}), _jsx("span", { className: "mb-toast-time", children: data.time ?? "now" })] }), _jsx(ToastDescription, {})] }), toast.action ? _jsx(ToastAction, {}) : null, _jsx(ToastClose, {})] }));
41
+ }
42
+ /** Reads the platform of the nearest `data-platform`, so a notification host inside a phone preview acts like one. */
43
+ function usePlatform(ref) {
44
+ const [platform, setPlatform] = React.useState("macos");
45
+ React.useEffect(() => {
46
+ const host = ref.current?.closest("[data-platform]");
47
+ if (!host)
48
+ return;
49
+ const read = () => setPlatform(host.dataset.platform ?? "macos");
50
+ read();
51
+ const observer = new MutationObserver(read);
52
+ observer.observe(host, { attributes: true, attributeFilter: ["data-platform"] });
53
+ return () => observer.disconnect();
54
+ }, [ref]);
55
+ return platform;
56
+ }
57
+ /**
58
+ * The region lives in the top layer, positioned against the viewport. Inside a
59
+ * nested platform preview (a phone on a Mac page) it treats that preview's box
60
+ * as its screen instead, by writing the preview's distances from each edge.
61
+ */
62
+ function useNestedScreen(ref) {
63
+ React.useEffect(() => {
64
+ const sentinel = ref.current;
65
+ const host = sentinel?.parentElement?.closest("[data-platform]");
66
+ const region = sentinel?.nextElementSibling;
67
+ if (!host || host === document.documentElement || !(region instanceof HTMLElement))
68
+ return;
69
+ let frame = 0;
70
+ const write = () => {
71
+ frame = 0;
72
+ const box = host.getBoundingClientRect();
73
+ const rtl = getComputedStyle(region).direction === "rtl";
74
+ const left = box.left;
75
+ const right = window.innerWidth - box.right;
76
+ region.style.setProperty("--mb-toaster-top", `${box.top}px`);
77
+ region.style.setProperty("--mb-toaster-bottom", `${window.innerHeight - box.bottom}px`);
78
+ region.style.setProperty("--mb-toaster-inline-start", `${rtl ? right : left}px`);
79
+ region.style.setProperty("--mb-toaster-inline-end", `${rtl ? left : right}px`);
80
+ region.style.setProperty("--mb-toaster-screen-width", `${box.width}px`);
81
+ };
82
+ const schedule = () => {
83
+ if (!frame)
84
+ frame = requestAnimationFrame(write);
85
+ };
86
+ write();
87
+ const resize = new ResizeObserver(schedule);
88
+ resize.observe(host);
89
+ window.addEventListener("scroll", schedule, { capture: true, passive: true });
90
+ window.addEventListener("resize", schedule);
91
+ return () => {
92
+ cancelAnimationFrame(frame);
93
+ resize.disconnect();
94
+ window.removeEventListener("scroll", schedule, { capture: true });
95
+ window.removeEventListener("resize", schedule);
96
+ for (const name of ["top", "bottom", "inline-start", "inline-end", "screen-width"]) {
97
+ region.style.removeProperty(`--mb-toaster-${name}`);
98
+ }
99
+ };
100
+ }, [ref]);
101
+ }
102
+ /**
103
+ * The notification host. Mount it once near the root and call `toast()` from
104
+ * anywhere: notifications drop in at the top right on the Mac and as banners
105
+ * at the top of the screen on iPhone and iPad.
106
+ */
107
+ function Toaster({ align, side = "top", className, children, ...props }) {
108
+ const sentinel = React.useRef(null);
109
+ const platform = usePlatform(sentinel);
110
+ useNestedScreen(sentinel);
111
+ return (_jsxs(_Fragment, { children: [_jsx("span", { ref: sentinel, hidden: true }), _jsx(ToastRegion, { side: side, align: align ?? (platform === "macos" ? "end" : "center"), className: cx("mb-toaster", className), ...props, children: children ?? ((toast) => _jsx(Notification, { toast: toast })) })] }));
112
+ }
113
+ export { createToaster, toast } from "@ui-sdk/react/toast";
114
+ export { Toast, ToastAction, ToastClose, ToastDescription, Toaster, ToastIcon, ToastTitle };
@@ -0,0 +1,21 @@
1
+ import { Toggle as TogglePrimitive, ToggleGroup as ToggleGroupPrimitive, ToggleIcon as ToggleIconPrimitive } from "@ui-sdk/react/toggle";
2
+ import * as React from "react";
3
+ type ToggleVariant = "plain" | "bezeled";
4
+ type ToggleSize = "sm" | "md" | "lg";
5
+ type ToggleProps = React.ComponentProps<typeof TogglePrimitive> & {
6
+ /** `plain` is a toolbar button; `bezeled` is a push-on/push-off button in content. */
7
+ variant?: ToggleVariant;
8
+ /** `accent` tints the pressed content with the accent color, as Xcode's navigator buttons do. */
9
+ tone?: "neutral" | "accent";
10
+ size?: ToggleSize;
11
+ };
12
+ declare function Toggle({ variant, tone, size, className, children, ...props }: ToggleProps): React.JSX.Element;
13
+ declare function ToggleIcon({ className, ...props }: React.ComponentProps<typeof ToggleIconPrimitive>): React.JSX.Element;
14
+ type ToggleGroupProps = React.ComponentProps<typeof ToggleGroupPrimitive> & {
15
+ /** `bezeled` joins the toggles into one raised control, like a "select any" segmented control on macOS. */
16
+ variant?: ToggleVariant;
17
+ size?: ToggleSize;
18
+ };
19
+ declare function ToggleGroup({ variant, size, className, ...props }: ToggleGroupProps): React.JSX.Element;
20
+ export { Toggle, ToggleGroup, ToggleIcon };
21
+ export type { ToggleGroupProps, ToggleProps, ToggleSize, ToggleVariant };