@middag-io/react 0.45.0 → 0.45.2

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 (320) hide show
  1. package/docs/public/schemas/ai-contract-manifest.json +1820 -0
  2. package/docs/public/schemas/blocks.json +445 -0
  3. package/docs/public/schemas/components.json +166 -0
  4. package/docs/public/schemas/connectors.json +97 -0
  5. package/docs/public/schemas/fragment.json +2329 -0
  6. package/docs/public/schemas/manifest.json +119 -0
  7. package/docs/public/schemas/navigation.json +72 -0
  8. package/docs/public/schemas/page-contract.json +2329 -0
  9. package/docs/public/schemas/shared-props.json +118 -0
  10. package/docs/public/schemas/theme-defaults.json +253 -0
  11. package/docs/public/schemas/theme.json +401 -0
  12. package/package.json +109 -3
  13. package/src/assets/lottie/calendar/schedule-1.json +1 -0
  14. package/src/assets/lottie/calendar/schedule-2.json +1 -0
  15. package/src/assets/lottie/celebration/confetti-1.json +1 -0
  16. package/src/assets/lottie/celebration/confetti-2.json +1 -0
  17. package/src/assets/lottie/celebration/confetti-3.json +1 -0
  18. package/src/assets/lottie/cloud/cloud-1.json +1 -0
  19. package/src/assets/lottie/cloud/cloud-2.json +1 -0
  20. package/src/assets/lottie/connection/network-1.json +1 -0
  21. package/src/assets/lottie/connection/network-2.json +1 -0
  22. package/src/assets/lottie/connection/network-3.json +1 -0
  23. package/src/assets/lottie/dashboard/analytics-1.json +1 -0
  24. package/src/assets/lottie/dashboard/analytics-2.json +1 -0
  25. package/src/assets/lottie/dashboard/analytics-3.json +1 -0
  26. package/src/assets/lottie/email/mail-1.json +1 -0
  27. package/src/assets/lottie/email/mail-2.json +1 -0
  28. package/src/assets/lottie/email/mail-3.json +1 -0
  29. package/src/assets/lottie/empty-state/empty-1.json +1 -0
  30. package/src/assets/lottie/empty-state/empty-2.json +1 -0
  31. package/src/assets/lottie/empty-state/empty-3.json +1 -0
  32. package/src/assets/lottie/error/warning-1.json +1 -0
  33. package/src/assets/lottie/error/warning-2.json +1 -0
  34. package/src/assets/lottie/error/warning-3.json +1 -0
  35. package/src/assets/lottie/index.ts +49 -0
  36. package/src/assets/lottie/loading/spinner-1.json +1 -0
  37. package/src/assets/lottie/loading/spinner-2.json +1 -0
  38. package/src/assets/lottie/loading/spinner-3.json +1 -0
  39. package/src/assets/lottie/maintenance/construction-1.json +1 -0
  40. package/src/assets/lottie/maintenance/construction-2.json +1 -0
  41. package/src/assets/lottie/maintenance/construction-3.json +1 -0
  42. package/src/assets/lottie/not-found/404-1.json +1 -0
  43. package/src/assets/lottie/not-found/404-2.json +1 -0
  44. package/src/assets/lottie/not-found/404-3.json +1 -0
  45. package/src/assets/lottie/notification/bell-1.json +1 -0
  46. package/src/assets/lottie/notification/bell-2.json +1 -0
  47. package/src/assets/lottie/notification/bell-3.json +1 -0
  48. package/src/assets/lottie/onboarding/welcome-1.json +1 -0
  49. package/src/assets/lottie/onboarding/welcome-2.json +1 -0
  50. package/src/assets/lottie/onboarding/welcome-3.json +1 -0
  51. package/src/assets/lottie/payment/wallet-1.json +1 -0
  52. package/src/assets/lottie/payment/wallet-2.json +1 -0
  53. package/src/assets/lottie/payment/wallet-3.json +1 -0
  54. package/src/assets/lottie/search/search-1.json +1 -0
  55. package/src/assets/lottie/search/search-2.json +1 -0
  56. package/src/assets/lottie/search/search-3.json +1 -0
  57. package/src/assets/lottie/security/lock-1.json +1 -0
  58. package/src/assets/lottie/security/lock-2.json +1 -0
  59. package/src/assets/lottie/security/lock-3.json +1 -0
  60. package/src/assets/lottie/settings/gear-1.json +1 -0
  61. package/src/assets/lottie/settings/gear-2.json +1 -0
  62. package/src/assets/lottie/settings/gear-3.json +1 -0
  63. package/src/assets/lottie/success/check-1.json +1 -0
  64. package/src/assets/lottie/success/check-2.json +1 -0
  65. package/src/assets/lottie/success/check-3.json +1 -0
  66. package/src/assets/lottie/upload/upload-1.json +1 -0
  67. package/src/assets/lottie/upload/upload-2.json +1 -0
  68. package/src/assets/lottie/upload/upload-3.json +1 -0
  69. package/src/assets/lottie/user/profile-1.json +1 -0
  70. package/src/assets/lottie/user/profile-2.json +1 -0
  71. package/src/assets/lottie/user/profile-3.json +1 -0
  72. package/src/base/blocks/ActionGridBlock.tsx +151 -0
  73. package/src/base/blocks/ActivityTimelineBlock.tsx +180 -0
  74. package/src/base/blocks/CardGridBlock.tsx +384 -0
  75. package/src/base/blocks/ChartBlock.tsx +81 -0
  76. package/src/base/blocks/DenseTableBlock.tsx +403 -0
  77. package/src/base/blocks/DetailPanelBlock.tsx +189 -0
  78. package/src/base/blocks/EmptyStateBlock.tsx +46 -0
  79. package/src/base/blocks/FormPanelBlock.lazy.tsx +38 -0
  80. package/src/base/blocks/FormPanelBlock.tsx +480 -0
  81. package/src/base/blocks/LinkListBlock.tsx +94 -0
  82. package/src/base/blocks/MarkdownPanelBlock.tsx +60 -0
  83. package/src/base/blocks/MetricCardBlock.tsx +128 -0
  84. package/src/base/blocks/StatusStripBlock.tsx +43 -0
  85. package/src/base/blocks/TabsBlock.tsx +94 -0
  86. package/src/base/form/FormField.tsx +607 -0
  87. package/src/base/form/fields/CheckboxField.tsx +56 -0
  88. package/src/base/form/fields/ColorField.tsx +76 -0
  89. package/src/base/form/fields/CurrencyField.tsx +126 -0
  90. package/src/base/form/fields/DateField.tsx +168 -0
  91. package/src/base/form/fields/DateRangeField.tsx +66 -0
  92. package/src/base/form/fields/DocumentField.tsx +222 -0
  93. package/src/base/form/fields/EntityPickerField.tsx +244 -0
  94. package/src/base/form/fields/FileUploadField.tsx +253 -0
  95. package/src/base/form/fields/MultiSelectField.tsx +286 -0
  96. package/src/base/form/fields/NativeSelectField.tsx +67 -0
  97. package/src/base/form/fields/NumberField.tsx +67 -0
  98. package/src/base/form/fields/OtpField.tsx +88 -0
  99. package/src/base/form/fields/PasswordField.tsx +69 -0
  100. package/src/base/form/fields/PhoneField.tsx +64 -0
  101. package/src/base/form/fields/RadioField.tsx +66 -0
  102. package/src/base/form/fields/RatingField.tsx +52 -0
  103. package/src/base/form/fields/SelectField.tsx +76 -0
  104. package/src/base/form/fields/SliderField.tsx +77 -0
  105. package/src/base/form/fields/SlugField.tsx +114 -0
  106. package/src/base/form/fields/StaticField.tsx +25 -0
  107. package/src/base/form/fields/SwitchField.tsx +56 -0
  108. package/src/base/form/fields/TagsField.tsx +128 -0
  109. package/src/base/form/fields/TextField.tsx +55 -0
  110. package/src/base/form/fields/TextareaField.tsx +55 -0
  111. package/src/base/form/fields/document-validation.ts +126 -0
  112. package/src/base/form/fields/field-registry.ts +53 -0
  113. package/src/base/form/fields/register-default-fields.ts +86 -0
  114. package/src/base/form/form-schema-builder.ts +192 -0
  115. package/src/base/form/form-utils.ts +71 -0
  116. package/src/base/hooks/useIsDark.ts +50 -0
  117. package/src/base/hooks/useLazyTabs.ts +98 -0
  118. package/src/base/hooks/usePolling.ts +43 -0
  119. package/src/base/hooks/useRemember.ts +58 -0
  120. package/src/base/hooks/useToast.ts +27 -0
  121. package/src/base/layout/BlockRegion.tsx +39 -0
  122. package/src/base/layout/DashboardLayout.tsx +110 -0
  123. package/src/base/layout/SidebarLayout.tsx +38 -0
  124. package/src/base/layout/StackLayout.tsx +32 -0
  125. package/src/base/layout/WizardLayout.tsx +49 -0
  126. package/src/base/partials/ActionBar/index.tsx +115 -0
  127. package/src/base/partials/ConfirmationDialog/index.tsx +128 -0
  128. package/src/base/partials/DataTable/cell-registry.ts +50 -0
  129. package/src/base/partials/DataTable/cell-renderers.tsx +372 -0
  130. package/src/base/partials/DataTable/index.tsx +1282 -0
  131. package/src/base/partials/DataTable/register-default-cells.ts +37 -0
  132. package/src/base/partials/DataTable/sanitize-html.ts +45 -0
  133. package/src/base/partials/DataTable/types.ts +229 -0
  134. package/src/base/partials/DetailSection/index.tsx +316 -0
  135. package/src/base/partials/EmptyPlaceholder/index.tsx +162 -0
  136. package/src/base/partials/EntityItem/index.tsx +154 -0
  137. package/src/base/partials/FilterBar/index.tsx +256 -0
  138. package/src/base/partials/FormSection/index.tsx +87 -0
  139. package/src/base/partials/LogViewer/JsonBlock.tsx +39 -0
  140. package/src/base/partials/LogViewer/LogEntry.tsx +68 -0
  141. package/src/base/partials/LogViewer/LogViewerToolbar.tsx +71 -0
  142. package/src/base/partials/LogViewer/index.tsx +110 -0
  143. package/src/base/partials/LogViewer/types.ts +28 -0
  144. package/src/base/partials/MarkdownContent/index.tsx +307 -0
  145. package/src/base/partials/MenuBar/index.tsx +80 -0
  146. package/src/base/partials/QuickRecordSheet/index.tsx +59 -0
  147. package/src/base/partials/ResizableSidebar/index.tsx +70 -0
  148. package/src/base/partials/StatRow/index.tsx +28 -0
  149. package/src/base/partials/StatusBar/index.tsx +126 -0
  150. package/src/base/partials/StatusIndicator/index.tsx +61 -0
  151. package/src/base/partials/StepIndicator/index.tsx +63 -0
  152. package/src/base/partials/TableOfContents/index.tsx +78 -0
  153. package/src/base/partials/TimelineList/index.tsx +273 -0
  154. package/src/base/partials/ToggleGroupControl/index.tsx +100 -0
  155. package/src/base/partials/TreeView/index.tsx +75 -0
  156. package/src/base/partials/index.ts +23 -0
  157. package/src/base/shell/AuthShell.tsx +54 -0
  158. package/src/base/shell/BasicShell.tsx +286 -0
  159. package/src/base/shell/ImmersiveShell.tsx +85 -0
  160. package/src/base/shell/partials/EditablePanelContext.tsx +82 -0
  161. package/src/base/shell/partials/EditablePanelProvider.tsx +122 -0
  162. package/src/base/shell/partials/InlineEditablePanel.tsx +239 -0
  163. package/src/base/shell/partials/InspectorContext.tsx +173 -0
  164. package/src/base/shell/partials/InspectorPanel.tsx +65 -0
  165. package/src/base/shell/partials/NavErrorBoundary.tsx +82 -0
  166. package/src/base/shell/partials/OverlayScreen.tsx +67 -0
  167. package/src/base/shell/partials/PageActionButton.tsx +203 -0
  168. package/src/base/theme/appearance.ts +133 -0
  169. package/src/base/theme/host-layout-detector.ts +119 -0
  170. package/src/base/theme/host-theme-detector.ts +146 -0
  171. package/src/base/theme/sidebar-safelist.txt +20 -0
  172. package/src/base/theme/tailwind-theme.css +136 -0
  173. package/src/base/theme/theme-bridge.css +164 -0
  174. package/src/base/theme/theme-context.tsx +142 -0
  175. package/src/base/theme/themes/classic.css +174 -0
  176. package/src/base/theme/tokens.css +290 -0
  177. package/src/base/theme/useHostTheme.ts +95 -0
  178. package/src/base/utils/clipboard.ts +39 -0
  179. package/src/base/utils/conditions.ts +27 -0
  180. package/src/base/utils/icon-registry.ts +78 -0
  181. package/src/base/utils/icons.ts +31 -0
  182. package/src/base/utils/interpolate.ts +9 -0
  183. package/src/base/utils/register-default-icons.ts +163 -0
  184. package/src/base/utils/storage.ts +65 -0
  185. package/src/base/utils/time.ts +139 -0
  186. package/src/contracts/block-data/actions.ts +73 -0
  187. package/src/contracts/block-data/data-display.ts +343 -0
  188. package/src/contracts/block-data/form.ts +164 -0
  189. package/src/contracts/block-data/index.ts +15 -0
  190. package/src/contracts/block-data/interactive.ts +34 -0
  191. package/src/contracts/block-data/shared.ts +44 -0
  192. package/src/contracts/connectors.ts +60 -0
  193. package/src/contracts/generated/contract-schema.ts +1237 -0
  194. package/src/contracts/generated/contract-types.ts +675 -0
  195. package/src/contracts/generated/index.ts +15 -0
  196. package/src/contracts/navigation.ts +59 -0
  197. package/src/contracts/page-contract-schema.ts +40 -0
  198. package/src/contracts/page-contract.ts +79 -0
  199. package/src/contracts/shared-props.ts +92 -0
  200. package/src/engine/ContractPage.tsx +178 -0
  201. package/src/engine/EntityRoutes.tsx +72 -0
  202. package/src/engine/HostSlot.tsx +126 -0
  203. package/src/engine/LazyBlock.tsx +92 -0
  204. package/src/engine/bootstrap.tsx +20 -0
  205. package/src/engine/providers/auth.tsx +87 -0
  206. package/src/engine/providers/error-reporter.tsx +89 -0
  207. package/src/engine/providers/flash.tsx +44 -0
  208. package/src/engine/providers/index.ts +18 -0
  209. package/src/engine/providers/inertia-error-reporter.tsx +61 -0
  210. package/src/engine/providers/progress.tsx +56 -0
  211. package/src/engine/providers/scope.tsx +51 -0
  212. package/src/engine/register-defaults.ts +88 -0
  213. package/src/engine/registries.ts +96 -0
  214. package/src/i18n/I18nProvider.tsx +53 -0
  215. package/src/i18n/MANIFEST.md +101 -0
  216. package/src/i18n/host-resolver.ts +18 -0
  217. package/src/i18n/instance.ts +69 -0
  218. package/src/i18n/locales/en/ui.json +277 -0
  219. package/src/i18n/locales/en/validators.json +13 -0
  220. package/src/i18n/locales/pt-BR/ui.json +277 -0
  221. package/src/i18n/locales/pt-BR/validators.json +13 -0
  222. package/src/i18n/register-strings.ts +10 -0
  223. package/src/i18n/render-label.ts +33 -0
  224. package/src/i18n/resolve-field-error.ts +29 -0
  225. package/src/i18n/useHostString.ts +50 -0
  226. package/src/i18n/useTranslation.ts +83 -0
  227. package/src/lib/actions/resolve-action-target.ts +151 -0
  228. package/src/lib/hooks/use-copy-to-clipboard.ts +37 -0
  229. package/src/lib/hooks/use-file-upload.ts +406 -0
  230. package/src/lib/hooks/use-mobile.ts +21 -0
  231. package/src/lib/host-pending.ts +76 -0
  232. package/src/lib/portal-container.ts +16 -0
  233. package/src/lib/test-ids.ts +40 -0
  234. package/src/lib/utils.ts +6 -0
  235. package/src/primitives/reui/MANIFEST.md +97 -0
  236. package/src/primitives/reui/accordion.tsx +64 -0
  237. package/src/primitives/reui/alert-dialog.tsx +196 -0
  238. package/src/primitives/reui/alert.tsx +92 -0
  239. package/src/primitives/reui/aspect-ratio.tsx +9 -0
  240. package/src/primitives/reui/autocomplete.tsx +343 -0
  241. package/src/primitives/reui/avatar.tsx +109 -0
  242. package/src/primitives/reui/badge.tsx +94 -0
  243. package/src/primitives/reui/breadcrumb.tsx +109 -0
  244. package/src/primitives/reui/button-group.tsx +83 -0
  245. package/src/primitives/reui/button.tsx +64 -0
  246. package/src/primitives/reui/calendar.tsx +220 -0
  247. package/src/primitives/reui/card.tsx +92 -0
  248. package/src/primitives/reui/carousel.tsx +239 -0
  249. package/src/primitives/reui/chart.tsx +388 -0
  250. package/src/primitives/reui/checkbox.tsx +30 -0
  251. package/src/primitives/reui/collapsible.tsx +31 -0
  252. package/src/primitives/reui/combobox.tsx +308 -0
  253. package/src/primitives/reui/command.tsx +182 -0
  254. package/src/primitives/reui/context-menu.tsx +250 -0
  255. package/src/primitives/reui/data-grid/data-grid-column-filter.tsx +172 -0
  256. package/src/primitives/reui/data-grid/data-grid-column-header.tsx +420 -0
  257. package/src/primitives/reui/data-grid/data-grid-column-visibility.tsx +51 -0
  258. package/src/primitives/reui/data-grid/data-grid-pagination.tsx +235 -0
  259. package/src/primitives/reui/data-grid/data-grid-scroll-area.tsx +427 -0
  260. package/src/primitives/reui/data-grid/data-grid-table-dnd-rows.tsx +308 -0
  261. package/src/primitives/reui/data-grid/data-grid-table-dnd.tsx +318 -0
  262. package/src/primitives/reui/data-grid/data-grid-table-virtual.tsx +491 -0
  263. package/src/primitives/reui/data-grid/data-grid-table.tsx +1430 -0
  264. package/src/primitives/reui/data-grid/data-grid.tsx +269 -0
  265. package/src/primitives/reui/data-grid-pagination.tsx +235 -0
  266. package/src/primitives/reui/date-selector.tsx +1353 -0
  267. package/src/primitives/reui/dialog.tsx +158 -0
  268. package/src/primitives/reui/drawer.tsx +133 -0
  269. package/src/primitives/reui/dropdown-menu.tsx +257 -0
  270. package/src/primitives/reui/empty.tsx +104 -0
  271. package/src/primitives/reui/field.tsx +246 -0
  272. package/src/primitives/reui/filters.tsx +1891 -0
  273. package/src/primitives/reui/frame.tsx +170 -0
  274. package/src/primitives/reui/hover-card.tsx +42 -0
  275. package/src/primitives/reui/icon-placeholder.tsx +39 -0
  276. package/src/primitives/reui/index.ts +98 -0
  277. package/src/primitives/reui/input-group.tsx +170 -0
  278. package/src/primitives/reui/input-otp.tsx +75 -0
  279. package/src/primitives/reui/input.tsx +21 -0
  280. package/src/primitives/reui/item.tsx +193 -0
  281. package/src/primitives/reui/kanban.tsx +743 -0
  282. package/src/primitives/reui/kbd.tsx +28 -0
  283. package/src/primitives/reui/label.tsx +22 -0
  284. package/src/primitives/reui/menubar.tsx +274 -0
  285. package/src/primitives/reui/native-select.tsx +62 -0
  286. package/src/primitives/reui/navigation-menu.tsx +168 -0
  287. package/src/primitives/reui/number-field.tsx +250 -0
  288. package/src/primitives/reui/pagination.tsx +127 -0
  289. package/src/primitives/reui/phone-input.tsx +231 -0
  290. package/src/primitives/reui/popover.tsx +87 -0
  291. package/src/primitives/reui/progress.tsx +31 -0
  292. package/src/primitives/reui/radio-group.tsx +43 -0
  293. package/src/primitives/reui/rating.tsx +177 -0
  294. package/src/primitives/reui/resizable.tsx +51 -0
  295. package/src/primitives/reui/scroll-area.tsx +58 -0
  296. package/src/primitives/reui/scrollspy.tsx +240 -0
  297. package/src/primitives/reui/select.tsx +188 -0
  298. package/src/primitives/reui/separator.tsx +28 -0
  299. package/src/primitives/reui/sheet.tsx +141 -0
  300. package/src/primitives/reui/sidebar.tsx +732 -0
  301. package/src/primitives/reui/skeleton.tsx +13 -0
  302. package/src/primitives/reui/slider.tsx +61 -0
  303. package/src/primitives/reui/sonner.tsx +47 -0
  304. package/src/primitives/reui/sortable.tsx +414 -0
  305. package/src/primitives/reui/spinner.tsx +16 -0
  306. package/src/primitives/reui/stepper.tsx +484 -0
  307. package/src/primitives/reui/svgs/claudeAiIcon.tsx +12 -0
  308. package/src/primitives/reui/svgs/gemini.tsx +171 -0
  309. package/src/primitives/reui/svgs/openai.tsx +9 -0
  310. package/src/primitives/reui/svgs/openaiDark.tsx +12 -0
  311. package/src/primitives/reui/switch.tsx +33 -0
  312. package/src/primitives/reui/table.tsx +114 -0
  313. package/src/primitives/reui/tabs.tsx +91 -0
  314. package/src/primitives/reui/textarea.tsx +18 -0
  315. package/src/primitives/reui/timeline.tsx +219 -0
  316. package/src/primitives/reui/toggle-group.tsx +83 -0
  317. package/src/primitives/reui/toggle.tsx +45 -0
  318. package/src/primitives/reui/tooltip.tsx +55 -0
  319. package/src/primitives/reui/tree.tsx +247 -0
  320. package/src/theme.css +71 -0
@@ -0,0 +1,247 @@
1
+ import {
2
+ ButtonHTMLAttributes,
3
+ createContext,
4
+ CSSProperties,
5
+ Fragment,
6
+ HTMLAttributes,
7
+ useContext,
8
+ } from "react";
9
+ import { ItemInstance } from "@headless-tree/core";
10
+ import { Slot } from "radix-ui";
11
+
12
+ import { cn } from "@/lib/utils";
13
+ import { HugeiconsIcon } from "@hugeicons/react";
14
+ import {
15
+ MinusSignIcon,
16
+ PlusSignIcon,
17
+ ArrowDown01Icon,
18
+ } from "@hugeicons/core-free-icons";
19
+
20
+ type ToggleIconType = "chevron" | "plus-minus";
21
+
22
+ interface TreeContextValue<T = any> {
23
+ indent: number;
24
+ currentItem?: ItemInstance<T>;
25
+ tree?: any;
26
+ toggleIconType?: ToggleIconType;
27
+ }
28
+
29
+ const TreeContext = createContext<TreeContextValue>({
30
+ indent: 20,
31
+ currentItem: undefined,
32
+ tree: undefined,
33
+ toggleIconType: "plus-minus",
34
+ });
35
+
36
+ function useTreeContext<T = any>() {
37
+ return useContext(TreeContext) as TreeContextValue<T>;
38
+ }
39
+
40
+ interface TreeProps extends HTMLAttributes<HTMLDivElement> {
41
+ indent?: number;
42
+ tree?: any;
43
+ toggleIconType?: ToggleIconType;
44
+ asChild?: boolean;
45
+ }
46
+
47
+ function Tree({
48
+ indent = 20,
49
+ tree,
50
+ className,
51
+ toggleIconType = "chevron",
52
+ asChild = false,
53
+ ...props
54
+ }: TreeProps) {
55
+ const containerProps =
56
+ tree && typeof tree.getContainerProps === "function"
57
+ ? tree.getContainerProps()
58
+ : {};
59
+ const mergedProps = { ...props, ...containerProps };
60
+
61
+ // Extract style from mergedProps to merge with our custom styles
62
+ const { style: propStyle, ...otherProps } = mergedProps;
63
+
64
+ // Merge styles
65
+ const mergedStyle = {
66
+ ...propStyle,
67
+ "--tree-indent": `${indent}px`,
68
+ } as CSSProperties;
69
+
70
+ const Comp = asChild ? Slot.Root : "div";
71
+
72
+ return (
73
+ <TreeContext.Provider value={{ indent, tree, toggleIconType }}>
74
+ <Comp
75
+ data-slot="tree"
76
+ style={mergedStyle}
77
+ className={cn("flex flex-col", className)}
78
+ {...otherProps}
79
+ />
80
+ </TreeContext.Provider>
81
+ );
82
+ }
83
+
84
+ interface TreeItemProps<T = any> extends Omit<
85
+ ButtonHTMLAttributes<HTMLButtonElement>,
86
+ "indent"
87
+ > {
88
+ item: ItemInstance<T>;
89
+ indent?: number;
90
+ asChild?: boolean;
91
+ }
92
+
93
+ function TreeItem<T = any>({
94
+ item,
95
+ className,
96
+ asChild = false,
97
+ children,
98
+ ...props
99
+ }: TreeItemProps<T>) {
100
+ const parentContext = useTreeContext<T>();
101
+ const { indent } = parentContext;
102
+
103
+ const itemProps = typeof item.getProps === "function" ? item.getProps() : {};
104
+ const mergedProps = { ...props, children, ...itemProps };
105
+
106
+ // Extract style from mergedProps to merge with our custom styles
107
+ const { style: propStyle, ...otherProps } = mergedProps;
108
+
109
+ // Merge styles
110
+ const mergedStyle = {
111
+ ...propStyle,
112
+ "--tree-padding": `${item.getItemMeta().level * indent}px`,
113
+ } as CSSProperties;
114
+
115
+ const defaultProps = {
116
+ "data-slot": "tree-item",
117
+ style: mergedStyle,
118
+ className: cn(
119
+ "z-10 ps-(--tree-padding) outline-hidden select-none not-last:pb-0.5 focus:z-20 data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
120
+ className,
121
+ ),
122
+ "data-focus":
123
+ typeof item.isFocused === "function"
124
+ ? item.isFocused() || false
125
+ : undefined,
126
+ "data-folder":
127
+ typeof item.isFolder === "function"
128
+ ? item.isFolder() || false
129
+ : undefined,
130
+ "data-selected":
131
+ typeof item.isSelected === "function"
132
+ ? item.isSelected() || false
133
+ : undefined,
134
+ "data-drag-target":
135
+ typeof item.isDragTarget === "function"
136
+ ? item.isDragTarget() || false
137
+ : undefined,
138
+ "data-search-match":
139
+ typeof item.isMatchingSearch === "function"
140
+ ? item.isMatchingSearch() || false
141
+ : undefined,
142
+ "aria-expanded": item.isExpanded(),
143
+ };
144
+
145
+ const Comp = asChild ? Slot.Root : "button";
146
+
147
+ return (
148
+ <TreeContext.Provider value={{ ...parentContext, currentItem: item }}>
149
+ <Comp {...defaultProps} {...otherProps}>
150
+ {children}
151
+ </Comp>
152
+ </TreeContext.Provider>
153
+ );
154
+ }
155
+
156
+ interface TreeItemLabelProps<T = any> extends HTMLAttributes<HTMLSpanElement> {
157
+ item?: ItemInstance<T>;
158
+ asChild?: boolean;
159
+ }
160
+
161
+ function TreeItemLabel<T = any>({
162
+ item: propItem,
163
+ children,
164
+ className,
165
+ asChild = false,
166
+ ...props
167
+ }: TreeItemLabelProps<T>) {
168
+ const { currentItem, toggleIconType } = useTreeContext<T>();
169
+ const item = propItem || currentItem;
170
+
171
+ if (!item) {
172
+ console.warn("TreeItemLabel: No item provided via props or context");
173
+ return null;
174
+ }
175
+
176
+ const Comp = asChild ? Slot.Root : "span";
177
+
178
+ return (
179
+ <Comp
180
+ data-slot="tree-item-label"
181
+ className={cn(
182
+ "in-focus-visible:ring-ring/50 bg-background hover:bg-accent in-data-[selected=true]:bg-accent in-data-[selected=true]:text-accent-foreground in-data-[drag-target=true]:bg-accent flex items-center gap-1 transition-colors not-in-data-[folder=true]:ps-7 in-focus-visible:ring-[3px] in-data-[search-match=true]:bg-blue-50! [&_svg]:pointer-events-none [&_svg]:shrink-0",
183
+ "rounded-sm",
184
+ "py-1.5",
185
+ "px-2",
186
+ "text-sm",
187
+ className,
188
+ )}
189
+ {...props}
190
+ >
191
+ <Fragment>
192
+ {item.isFolder() &&
193
+ (toggleIconType === "plus-minus" ? (
194
+ item.isExpanded() ? (
195
+ <HugeiconsIcon
196
+ icon={MinusSignIcon}
197
+ className="text-muted-foreground size-3.5"
198
+ stroke="currentColor"
199
+ strokeWidth={1}
200
+ />
201
+ ) : (
202
+ <HugeiconsIcon
203
+ icon={PlusSignIcon}
204
+ className="text-muted-foreground size-3.5"
205
+ stroke="currentColor"
206
+ strokeWidth={1}
207
+ />
208
+ )
209
+ ) : (
210
+ <HugeiconsIcon
211
+ icon={ArrowDown01Icon}
212
+ strokeWidth={2}
213
+ className="text-muted-foreground size-4 in-aria-[expanded=false]:-rotate-90"
214
+ />
215
+ ))}
216
+ {children ||
217
+ (typeof item.getItemName === "function" ? item.getItemName() : null)}
218
+ </Fragment>
219
+ </Comp>
220
+ );
221
+ }
222
+
223
+ function TreeDragLine({ className, ...props }: HTMLAttributes<HTMLDivElement>) {
224
+ const { tree } = useTreeContext();
225
+
226
+ if (!tree || typeof tree.getDragLineStyle !== "function") {
227
+ console.warn(
228
+ "TreeDragLine: No tree provided via context or tree does not have getDragLineStyle method",
229
+ );
230
+ return null;
231
+ }
232
+
233
+ const dragLine = tree.getDragLineStyle();
234
+ return (
235
+ <div
236
+ style={dragLine}
237
+ className={cn(
238
+ "bg-primary before:bg-background before:border-primary absolute z-30 -mt-px h-0.5 w-[unset] before:absolute before:-top-[3px] before:left-0 before:size-2 before:border-2",
239
+ "before:rounded-full",
240
+ className,
241
+ )}
242
+ {...props}
243
+ />
244
+ );
245
+ }
246
+
247
+ export { Tree, TreeItem, TreeItemLabel, TreeDragLine };
package/src/theme.css ADDED
@@ -0,0 +1,71 @@
1
+ /**
2
+ * MIDDAG Design Tokens + Tailwind Theme
3
+ *
4
+ * Import this in your tailwind.css to get all MIDDAG design tokens
5
+ * and Tailwind theme mappings:
6
+ *
7
+ * @import "tailwindcss";
8
+ * @import "@middag-io/react/theme.css";
9
+ *
10
+ * This provides:
11
+ * - CSS custom properties (:root) for all design tokens
12
+ * - Tailwind @theme mapping so utility classes resolve correctly
13
+ * - Dark mode variant
14
+ */
15
+
16
+ @import "./base/theme/tokens.css";
17
+
18
+ @custom-variant dark (&:is(.dark *));
19
+
20
+ @theme {
21
+ --color-background: var(--background);
22
+ --color-foreground: var(--foreground);
23
+ --color-primary: var(--middag-brand, var(--primary));
24
+ --color-primary-foreground: var(--primary-foreground);
25
+ --color-destructive: var(--destructive);
26
+ --color-destructive-foreground: var(--destructive-foreground);
27
+ --color-success: var(--success);
28
+ --color-success-foreground: var(--success-foreground);
29
+ --color-warning: var(--warning);
30
+ --color-warning-foreground: var(--warning-foreground);
31
+ --color-info: var(--info);
32
+ --color-info-foreground: var(--info-foreground);
33
+ --color-muted: var(--muted);
34
+ --color-muted-foreground: var(--muted-foreground);
35
+ --color-accent: var(--accent);
36
+ --color-accent-foreground: var(--accent-foreground);
37
+ --color-border: var(--border);
38
+ --color-input: var(--input);
39
+ --color-ring: var(--ring);
40
+ --color-card: var(--card);
41
+ --color-card-foreground: var(--card-foreground);
42
+ --color-popover: var(--popover);
43
+ --color-popover-foreground: var(--popover-foreground);
44
+ --color-secondary: var(--secondary);
45
+ --color-secondary-foreground: var(--secondary-foreground);
46
+
47
+ --color-sidebar: var(--sidebar);
48
+ --color-sidebar-foreground: var(--sidebar-foreground);
49
+ --color-sidebar-primary: var(--sidebar-primary);
50
+ --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
51
+ --color-sidebar-accent: var(--sidebar-accent);
52
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
53
+ --color-sidebar-hover: var(--sidebar-hover);
54
+ --color-sidebar-border: var(--sidebar-border);
55
+ --color-sidebar-ring: var(--ring);
56
+
57
+ --color-chart-1: var(--chart-1);
58
+ --color-chart-2: var(--chart-2);
59
+ --color-chart-3: var(--chart-3);
60
+ --color-chart-4: var(--chart-4);
61
+ --color-chart-5: var(--chart-5);
62
+
63
+ --font-sans: var(--font-sans);
64
+ --font-mono: var(--font-mono);
65
+
66
+ --radius-sm: calc(var(--radius) - 4px);
67
+ --radius-md: calc(var(--radius) - 2px);
68
+ --radius-lg: var(--radius);
69
+ --radius-xl: calc(var(--radius) + 4px);
70
+ --radius-2xl: calc(var(--radius) + 6px);
71
+ }