@krizaka/ui 2.10.0 → 3.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 (264) hide show
  1. package/README.md +4 -2
  2. package/dist/audio-player.js +1 -1
  3. package/dist/{chunk-EUPTXKH7.js → chunk-BRKMQ6JV.js} +2 -1
  4. package/dist/chunk-FDCMBWUU.js +168 -0
  5. package/dist/chunk-FDCMBWUU.js.map +1 -0
  6. package/dist/chunk-HCNOOPZE.js +210 -0
  7. package/dist/chunk-HCNOOPZE.js.map +1 -0
  8. package/dist/{chunk-X6TW3X6Y.js → chunk-LCZXS6AK.js} +2 -2
  9. package/dist/chunk-OGJI5X4W.js +157 -0
  10. package/dist/chunk-OGJI5X4W.js.map +1 -0
  11. package/dist/combobox.js +2 -2
  12. package/dist/data-table.d.ts +284 -24
  13. package/dist/data-table.js +914 -121
  14. package/dist/data-table.js.map +1 -1
  15. package/dist/date-picker.js +1 -1
  16. package/dist/filter-bar.d.ts +12 -12
  17. package/dist/filter-bar.js +9 -145
  18. package/dist/filter-bar.js.map +1 -1
  19. package/dist/form/server.d.ts +96 -0
  20. package/dist/form/server.js +82 -0
  21. package/dist/form/server.js.map +1 -0
  22. package/dist/form.d.ts +503 -0
  23. package/dist/form.js +760 -0
  24. package/dist/form.js.map +1 -0
  25. package/dist/image-cropper.js +1 -1
  26. package/dist/media-capture.js +1 -1
  27. package/dist/native/form.d.ts +376 -0
  28. package/dist/native/form.js +650 -0
  29. package/dist/native/form.js.map +1 -0
  30. package/dist/native/list.d.ts +95 -0
  31. package/dist/native/list.js +135 -0
  32. package/dist/native/list.js.map +1 -0
  33. package/dist/native.d.ts +113 -2
  34. package/dist/native.js +618 -388
  35. package/dist/native.js.map +1 -1
  36. package/dist/search-field.js +6 -160
  37. package/dist/search-field.js.map +1 -1
  38. package/dist/tag-input.js +2 -2
  39. package/dist/video-player.js +1 -1
  40. package/dist/video-trimmer.js +1 -1
  41. package/dist/virtual.d.ts +140 -0
  42. package/dist/virtual.js +19 -0
  43. package/dist/virtual.js.map +1 -0
  44. package/package.json +111 -8
  45. package/registry/achievement.json +1 -1
  46. package/registry/action-bar.json +1 -1
  47. package/registry/alert.json +1 -1
  48. package/registry/app-shell.json +1 -1
  49. package/registry/argument-card.json +1 -1
  50. package/registry/audio-player.json +1 -1
  51. package/registry/auth-layout.json +1 -1
  52. package/registry/avatar.json +1 -1
  53. package/registry/badge.json +1 -1
  54. package/registry/button.json +1 -1
  55. package/registry/card-grid.json +1 -1
  56. package/registry/card.json +1 -1
  57. package/registry/catalogue-page.json +1 -1
  58. package/registry/changelog-page.json +1 -1
  59. package/registry/checkbox.json +89 -4
  60. package/registry/chip-link.json +1 -1
  61. package/registry/chip.json +1 -1
  62. package/registry/choice-grid.json +1 -1
  63. package/registry/code-block.json +1 -1
  64. package/registry/combobox.json +1 -1
  65. package/registry/command.json +1 -1
  66. package/registry/component-page.json +1 -1
  67. package/registry/confirm-button.json +1 -1
  68. package/registry/contact-page.json +1 -1
  69. package/registry/continue-prompt.json +1 -1
  70. package/registry/countdown.json +1 -1
  71. package/registry/cta-panel.json +1 -1
  72. package/registry/dashboard-layout.json +1 -1
  73. package/registry/data-table.json +643 -49
  74. package/registry/date-picker.json +142 -4
  75. package/registry/decision-list.json +1 -1
  76. package/registry/detail-layout.json +1 -1
  77. package/registry/dialog.json +1 -1
  78. package/registry/docs-article-page.json +1 -1
  79. package/registry/docs-hub-page.json +1 -1
  80. package/registry/docs-layout.json +1 -1
  81. package/registry/dropdown-menu.json +1 -1
  82. package/registry/empty-state.json +1 -1
  83. package/registry/error-page.json +1 -1
  84. package/registry/examples/checkbox/native/terms.d.ts +4 -0
  85. package/registry/examples/checkbox/native/terms.dark.png +0 -0
  86. package/registry/examples/checkbox/native/terms.js +26 -0
  87. package/registry/examples/checkbox/native/terms.light.png +0 -0
  88. package/registry/examples/checkbox/native/terms.tsx +28 -0
  89. package/registry/examples/data-table/details.d.ts +4 -0
  90. package/registry/examples/data-table/details.js +33 -0
  91. package/registry/examples/data-table/details.tsx +31 -0
  92. package/registry/examples/data-table/filters.d.ts +4 -0
  93. package/registry/examples/data-table/filters.js +40 -0
  94. package/registry/examples/data-table/filters.tsx +40 -0
  95. package/registry/examples/data-table/grouped.d.ts +4 -0
  96. package/registry/examples/data-table/grouped.js +24 -0
  97. package/registry/examples/data-table/grouped.tsx +23 -0
  98. package/registry/examples/data-table/paginated.d.ts +4 -0
  99. package/registry/examples/data-table/paginated.js +23 -0
  100. package/registry/examples/data-table/paginated.tsx +22 -0
  101. package/registry/examples/data-table/pinned.d.ts +4 -0
  102. package/registry/examples/data-table/pinned.js +26 -0
  103. package/registry/examples/data-table/pinned.tsx +25 -0
  104. package/registry/examples/data-table/server.d.ts +4 -0
  105. package/registry/examples/data-table/server.js +40 -0
  106. package/registry/examples/data-table/server.tsx +40 -0
  107. package/registry/examples/data-table/virtualized.js +2 -2
  108. package/registry/examples/data-table/virtualized.tsx +3 -3
  109. package/registry/examples/date-picker/native/birth-date.d.ts +4 -0
  110. package/registry/examples/date-picker/native/birth-date.dark.png +0 -0
  111. package/registry/examples/date-picker/native/birth-date.js +30 -0
  112. package/registry/examples/date-picker/native/birth-date.light.png +0 -0
  113. package/registry/examples/date-picker/native/birth-date.tsx +27 -0
  114. package/registry/examples/field/native/default.d.ts +4 -0
  115. package/registry/examples/field/native/default.dark.png +0 -0
  116. package/registry/examples/field/native/default.js +29 -0
  117. package/registry/examples/field/native/default.light.png +0 -0
  118. package/registry/examples/field/native/default.tsx +23 -0
  119. package/registry/examples/form/amount.d.ts +4 -0
  120. package/registry/examples/form/amount.js +30 -0
  121. package/registry/examples/form/amount.tsx +36 -0
  122. package/registry/examples/form/audience.d.ts +4 -0
  123. package/registry/examples/form/audience.js +29 -0
  124. package/registry/examples/form/audience.tsx +31 -0
  125. package/registry/examples/form/native/amount.d.ts +4 -0
  126. package/registry/examples/form/native/amount.dark.png +0 -0
  127. package/registry/examples/form/native/amount.js +26 -0
  128. package/registry/examples/form/native/amount.light.png +0 -0
  129. package/registry/examples/form/native/amount.tsx +30 -0
  130. package/registry/examples/form/native/audience.d.ts +4 -0
  131. package/registry/examples/form/native/audience.dark.png +0 -0
  132. package/registry/examples/form/native/audience.js +24 -0
  133. package/registry/examples/form/native/audience.light.png +0 -0
  134. package/registry/examples/form/native/audience.tsx +24 -0
  135. package/registry/examples/form/native/profile.d.ts +4 -0
  136. package/registry/examples/form/native/profile.dark.png +0 -0
  137. package/registry/examples/form/native/profile.js +33 -0
  138. package/registry/examples/form/native/profile.light.png +0 -0
  139. package/registry/examples/form/native/profile.tsx +36 -0
  140. package/registry/examples/form/native/settings.d.ts +4 -0
  141. package/registry/examples/form/native/settings.dark.png +0 -0
  142. package/registry/examples/form/native/settings.js +25 -0
  143. package/registry/examples/form/native/settings.light.png +0 -0
  144. package/registry/examples/form/native/settings.tsx +23 -0
  145. package/registry/examples/form/native/sign-up.d.ts +4 -0
  146. package/registry/examples/form/native/sign-up.dark.png +0 -0
  147. package/registry/examples/form/native/sign-up.js +38 -0
  148. package/registry/examples/form/native/sign-up.light.png +0 -0
  149. package/registry/examples/form/native/sign-up.tsx +34 -0
  150. package/registry/examples/form/native/upload.d.ts +4 -0
  151. package/registry/examples/form/native/upload.dark.png +0 -0
  152. package/registry/examples/form/native/upload.js +23 -0
  153. package/registry/examples/form/native/upload.light.png +0 -0
  154. package/registry/examples/form/native/upload.tsx +22 -0
  155. package/registry/examples/form/profile.d.ts +4 -0
  156. package/registry/examples/form/profile.js +35 -0
  157. package/registry/examples/form/profile.tsx +40 -0
  158. package/registry/examples/form/report.d.ts +4 -0
  159. package/registry/examples/form/report.js +30 -0
  160. package/registry/examples/form/report.tsx +30 -0
  161. package/registry/examples/form/settings.d.ts +4 -0
  162. package/registry/examples/form/settings.js +30 -0
  163. package/registry/examples/form/settings.tsx +31 -0
  164. package/registry/examples/form/sign-up.d.ts +4 -0
  165. package/registry/examples/form/sign-up.js +38 -0
  166. package/registry/examples/form/sign-up.tsx +37 -0
  167. package/registry/examples/form/upload.d.ts +4 -0
  168. package/registry/examples/form/upload.js +32 -0
  169. package/registry/examples/form/upload.tsx +32 -0
  170. package/registry/examples/list/native/default.d.ts +4 -0
  171. package/registry/examples/list/native/default.dark.png +0 -0
  172. package/registry/examples/list/native/default.js +33 -0
  173. package/registry/examples/list/native/default.light.png +0 -0
  174. package/registry/examples/list/native/default.tsx +31 -0
  175. package/registry/examples/list/native/infinite.d.ts +4 -0
  176. package/registry/examples/list/native/infinite.dark.png +0 -0
  177. package/registry/examples/list/native/infinite.js +30 -0
  178. package/registry/examples/list/native/infinite.light.png +0 -0
  179. package/registry/examples/list/native/infinite.tsx +35 -0
  180. package/registry/examples/list/native/states.d.ts +4 -0
  181. package/registry/examples/list/native/states.dark.png +0 -0
  182. package/registry/examples/list/native/states.js +26 -0
  183. package/registry/examples/list/native/states.light.png +0 -0
  184. package/registry/examples/list/native/states.tsx +21 -0
  185. package/registry/examples/virtual/feed.d.ts +4 -0
  186. package/registry/examples/virtual/feed.js +26 -0
  187. package/registry/examples/virtual/feed.tsx +24 -0
  188. package/registry/examples/virtual/gallery.d.ts +4 -0
  189. package/registry/examples/virtual/gallery.js +31 -0
  190. package/registry/examples/virtual/gallery.tsx +28 -0
  191. package/registry/examples/virtual/messages.d.ts +4 -0
  192. package/registry/examples/virtual/messages.js +28 -0
  193. package/registry/examples/virtual/messages.tsx +28 -0
  194. package/registry/field.json +104 -4
  195. package/registry/file-upload.json +1 -1
  196. package/registry/filter-bar.json +1 -1
  197. package/registry/form.json +2940 -0
  198. package/registry/gallery-page.json +1 -1
  199. package/registry/glow-card.json +1 -1
  200. package/registry/goal-gauge.json +1 -1
  201. package/registry/how-it-works-page.json +1 -1
  202. package/registry/image-cropper.json +1 -1
  203. package/registry/index.json +86 -11
  204. package/registry/iso.json +1 -1
  205. package/registry/kbd.json +1 -1
  206. package/registry/landing-page.json +1 -1
  207. package/registry/landscape.json +1 -1
  208. package/registry/legal-page.json +1 -1
  209. package/registry/link-card.json +1 -1
  210. package/registry/list.json +249 -0
  211. package/registry/loader.json +1 -1
  212. package/registry/longform-page.json +1 -1
  213. package/registry/marketing-layout.json +1 -1
  214. package/registry/marquee.json +1 -1
  215. package/registry/mascot-quote.json +1 -1
  216. package/registry/mascot-state.json +2 -2
  217. package/registry/mascots.json +2 -2
  218. package/registry/media-capture.json +1 -1
  219. package/registry/meter.json +1 -1
  220. package/registry/nav-bar.json +1 -1
  221. package/registry/number-ticker.json +1 -1
  222. package/registry/page-header.json +1 -1
  223. package/registry/page-hero.json +1 -1
  224. package/registry/page.json +1 -1
  225. package/registry/pagination.json +1 -1
  226. package/registry/pointer-light.json +1 -1
  227. package/registry/popover.json +1 -1
  228. package/registry/pricing-page.json +1 -1
  229. package/registry/product-page.json +1 -1
  230. package/registry/profile-card.json +1 -1
  231. package/registry/progress.json +1 -1
  232. package/registry/promise-card.json +1 -1
  233. package/registry/radio-group.json +1 -1
  234. package/registry/scroll-stage.json +1 -1
  235. package/registry/search-field.json +1 -1
  236. package/registry/section-backdrop.json +1 -1
  237. package/registry/separator.json +1 -1
  238. package/registry/settings-layout.json +1 -1
  239. package/registry/skeleton.json +1 -1
  240. package/registry/slider.json +1 -1
  241. package/registry/slot.json +1 -1
  242. package/registry/spinner.json +1 -1
  243. package/registry/split-view.json +1 -1
  244. package/registry/stage-banner.json +1 -1
  245. package/registry/stat.json +1 -1
  246. package/registry/status-page.json +1 -1
  247. package/registry/stepper.json +1 -1
  248. package/registry/switch.json +1 -1
  249. package/registry/tabs.json +1 -1
  250. package/registry/tag-input.json +1 -1
  251. package/registry/terminal-replay.json +1 -1
  252. package/registry/theme.json +1 -1
  253. package/registry/toast.json +1 -1
  254. package/registry/toc.json +1 -1
  255. package/registry/tooltip.json +1 -1
  256. package/registry/video-player.json +1 -1
  257. package/registry/video-trimmer.json +1 -1
  258. package/registry/virtual.json +569 -0
  259. package/skills/data-table/SKILL.md +56 -0
  260. package/skills/form/SKILL.md +44 -0
  261. package/skills/native-list/SKILL.md +39 -0
  262. package/skills/virtual/SKILL.md +35 -0
  263. /package/dist/{chunk-EUPTXKH7.js.map → chunk-BRKMQ6JV.js.map} +0 -0
  264. /package/dist/{chunk-X6TW3X6Y.js.map → chunk-LCZXS6AK.js.map} +0 -0
@@ -0,0 +1,569 @@
1
+ {
2
+ "name": "virtual",
3
+ "type": "primitive",
4
+ "title": "Virtual",
5
+ "summary": "Long lists and galleries rendered by what is in view, on TanStack Virtual: a list in its own region or the page's, a grid that fits the width, measured items, the end announced for infinite loading.",
6
+ "description": "Long lists and galleries rendered by what is in view, on TanStack Virtual: a list in its own region or the page's, a grid that fits the width, measured items, the end announced for infinite loading.",
7
+ "status": "beta",
8
+ "category": "data-display",
9
+ "platforms": "web",
10
+ "whenToUse": [
11
+ "A list of hundreds to millions of items loaded at once or page by page: messages, comments, logs, notifications.",
12
+ "A gallery that grows as the person scrolls: videos, photos, products (`VirtualGrid`).",
13
+ "A feed that scrolls the page itself rather than a box (`scroll=\"window\"`)."
14
+ ],
15
+ "whenNotToUse": [
16
+ {
17
+ "when": "For records compared on columns: the data table has its own windowing.",
18
+ "use": "data-table"
19
+ },
20
+ {
21
+ "when": "For a short list (under a hundred items): render it whole, with no scrolling region.",
22
+ "use": "card-grid"
23
+ },
24
+ {
25
+ "when": "In a React Native app: FlashList, through the native list.",
26
+ "use": "list"
27
+ }
28
+ ],
29
+ "bestPractices": [
30
+ "Give `getKey` (an id): measurements stay with their item when the list changes.",
31
+ "Estimate the size close to the average (`estimateSize`): items are measured anyway, a close guess keeps the scrollbar steady.",
32
+ "Load the next page in `onEndReached` (a `useInfiniteQuery` of @krizaka/query) and show a spinner in `footer`.",
33
+ "Name the list (`label`): it names the focusable scrolling region, so keyboard people can scroll it.",
34
+ "Need the raw engine? `useVirtualizer` and `useWindowVirtualizer` come through this entry — never import `@tanstack/*` in a product."
35
+ ],
36
+ "accessibility": {
37
+ "keyboard": [
38
+ {
39
+ "keys": "Tab",
40
+ "action": "Reaches the scrolling region (then the links and buttons of the items in view)."
41
+ },
42
+ {
43
+ "keys": "Arrow keys",
44
+ "action": "Scroll the focused region; Page Up / Page Down and Home / End move by a screen or to the ends."
45
+ }
46
+ ],
47
+ "notes": [
48
+ "The scrolling region is focusable (`tabIndex=0`) and named by `label`.",
49
+ "Items are a `role=\"list\"` of `listitem`s carrying `aria-setsize` and `aria-posinset`: a screen reader says “item 4,812 of 50,000” though only twenty exist in the page.",
50
+ "`scrollToIndex` (through `ref`) scrolls smoothly, or at once when the person asked for less motion."
51
+ ]
52
+ },
53
+ "related": [
54
+ "data-table",
55
+ "list",
56
+ "card",
57
+ "spinner"
58
+ ],
59
+ "web": {
60
+ "entry": "@krizaka/ui/virtual",
61
+ "import": "import { VirtualList, VirtualGrid, useWindowVirtualizer, useVirtualizer } from \"@krizaka/ui/virtual\";",
62
+ "props": [
63
+ {
64
+ "component": "VirtualGrid",
65
+ "description": "A gallery rendered by the rows in view: as many columns as the width allows (or a fixed number), measured rows.",
66
+ "props": [
67
+ {
68
+ "name": "estimateRowHeight",
69
+ "type": "number",
70
+ "default": null,
71
+ "description": "The height of a row in px (a guess: rows are measured).",
72
+ "required": true
73
+ },
74
+ {
75
+ "name": "items",
76
+ "type": "readonly T[]",
77
+ "default": null,
78
+ "description": "The items, all of them: only the rows in view are rendered.",
79
+ "required": true
80
+ },
81
+ {
82
+ "name": "label",
83
+ "type": "string",
84
+ "default": null,
85
+ "description": "The accessible name of the grid of items (\"Videos\"), passed translated.",
86
+ "required": true
87
+ },
88
+ {
89
+ "name": "renderItem",
90
+ "type": "(item: T, index: number) => ReactNode",
91
+ "default": null,
92
+ "description": "Draws one cell (a card, a thumbnail).",
93
+ "required": true
94
+ },
95
+ {
96
+ "name": "className",
97
+ "type": "string",
98
+ "default": null,
99
+ "description": "Classes merged on the scrolling region.",
100
+ "required": false
101
+ },
102
+ {
103
+ "name": "columns",
104
+ "type": "number",
105
+ "default": null,
106
+ "description": "A fixed number of columns. Without it, as many columns of at least `minItemWidth` as the width allows.",
107
+ "required": false
108
+ },
109
+ {
110
+ "name": "empty",
111
+ "type": "ReactNode",
112
+ "default": null,
113
+ "description": "Shown instead of the grid when there is no item.",
114
+ "required": false
115
+ },
116
+ {
117
+ "name": "footer",
118
+ "type": "ReactNode",
119
+ "default": null,
120
+ "description": "Shown after the last row.",
121
+ "required": false
122
+ },
123
+ {
124
+ "name": "gap",
125
+ "type": "number",
126
+ "default": "16",
127
+ "description": "Space between cells, in px. Default 16.",
128
+ "required": false
129
+ },
130
+ {
131
+ "name": "getKey",
132
+ "type": "((item: T, index: number) => string | number)",
133
+ "default": null,
134
+ "description": "A stable key per item. Default: the index.",
135
+ "required": false
136
+ },
137
+ {
138
+ "name": "height",
139
+ "type": "string | number",
140
+ "default": "480",
141
+ "description": "The height of the scrolling region: px or any CSS length. Default 480.",
142
+ "required": false
143
+ },
144
+ {
145
+ "name": "minItemWidth",
146
+ "type": "number",
147
+ "default": "220",
148
+ "description": "The narrowest a cell may be, in px, when `columns` is not set. Default 220.",
149
+ "required": false
150
+ },
151
+ {
152
+ "name": "onEndReached",
153
+ "type": "(() => void)",
154
+ "default": null,
155
+ "description": "Called when the last rows come near (load the next page).",
156
+ "required": false
157
+ },
158
+ {
159
+ "name": "overscan",
160
+ "type": "number",
161
+ "default": "3",
162
+ "description": "Rows rendered beyond the visible ones. Default 3.",
163
+ "required": false
164
+ },
165
+ {
166
+ "name": "ref",
167
+ "type": "Ref<VirtualHandle>",
168
+ "default": null,
169
+ "description": "`scrollToIndex` (of an item) from outside.",
170
+ "required": false
171
+ }
172
+ ]
173
+ },
174
+ {
175
+ "component": "VirtualList",
176
+ "description": "A long list rendered by what is in view: fixed or measured sizes, its own scrolling region or the page's, the end\nannounced for infinite loading, items placed in the whole for assistive technology.",
177
+ "props": [
178
+ {
179
+ "name": "estimateSize",
180
+ "type": "Size",
181
+ "default": null,
182
+ "description": "The size of an item in px, or a guess per index; each item is then measured (dynamic sizes).",
183
+ "required": true
184
+ },
185
+ {
186
+ "name": "items",
187
+ "type": "readonly T[]",
188
+ "default": null,
189
+ "description": "The items, all of them: only those in view (and `overscan` around) are rendered.",
190
+ "required": true
191
+ },
192
+ {
193
+ "name": "label",
194
+ "type": "string",
195
+ "default": null,
196
+ "description": "The accessible name of the list (\"Messages\", \"Events\"), passed translated.",
197
+ "required": true
198
+ },
199
+ {
200
+ "name": "renderItem",
201
+ "type": "(item: T, index: number) => ReactNode",
202
+ "default": null,
203
+ "description": "Draws one item.",
204
+ "required": true
205
+ },
206
+ {
207
+ "name": "className",
208
+ "type": "string",
209
+ "default": null,
210
+ "description": "Classes merged on the scrolling region (`self`) or the list (`window`).",
211
+ "required": false
212
+ },
213
+ {
214
+ "name": "empty",
215
+ "type": "ReactNode",
216
+ "default": null,
217
+ "description": "Shown instead of the list when there is no item.",
218
+ "required": false
219
+ },
220
+ {
221
+ "name": "endReachedThreshold",
222
+ "type": "number",
223
+ "default": "5",
224
+ "description": "How many items before the end `onEndReached` fires. Default 5.",
225
+ "required": false
226
+ },
227
+ {
228
+ "name": "footer",
229
+ "type": "ReactNode",
230
+ "default": null,
231
+ "description": "Shown after the last item (a spinner while the next page loads).",
232
+ "required": false
233
+ },
234
+ {
235
+ "name": "gap",
236
+ "type": "number",
237
+ "default": "0",
238
+ "description": "Space between two items, in px. Default 0.",
239
+ "required": false
240
+ },
241
+ {
242
+ "name": "getKey",
243
+ "type": "((item: T, index: number) => string | number)",
244
+ "default": null,
245
+ "description": "A stable key per item (an id): keeps measurements on the right item when the list changes. Default: the index.",
246
+ "required": false
247
+ },
248
+ {
249
+ "name": "height",
250
+ "type": "string | number",
251
+ "default": "400",
252
+ "description": "The height of the scrolling region (`self`): px or any CSS length. Default 400.",
253
+ "required": false
254
+ },
255
+ {
256
+ "name": "onEndReached",
257
+ "type": "(() => void)",
258
+ "default": null,
259
+ "description": "Called when the end comes near (load the next page): once per length of `items`.",
260
+ "required": false
261
+ },
262
+ {
263
+ "name": "overscan",
264
+ "type": "number",
265
+ "default": "6",
266
+ "description": "Items rendered beyond the visible ones, on each side. Default 6.",
267
+ "required": false
268
+ },
269
+ {
270
+ "name": "ref",
271
+ "type": "Ref<VirtualHandle>",
272
+ "default": null,
273
+ "description": "`scrollToIndex` from outside.",
274
+ "required": false
275
+ },
276
+ {
277
+ "name": "scroll",
278
+ "type": "\"self\" | \"window\"",
279
+ "default": "self",
280
+ "description": "`self` (default): the list scrolls in its own region of `height`. `window`: the page scrolls (a feed).",
281
+ "required": false
282
+ }
283
+ ]
284
+ }
285
+ ],
286
+ "examples": [
287
+ {
288
+ "name": "messages",
289
+ "title": "50,000 messages",
290
+ "description": "A `VirtualList` of items of different heights, each measured.",
291
+ "path": "examples/virtual/messages.tsx",
292
+ "module": "@krizaka/ui/registry/examples/virtual/messages",
293
+ "code": "\"use client\";\n\nimport { VirtualList } from \"@krizaka/ui/virtual\";\n\ntype Message = { id: string; author: string; text: string };\nconst LINES = [\"On my way.\", \"Can you send the cut from yesterday? The second take, with the sunset over the river and the drone shot at the end.\", \"Done!\", \"Thanks — looks great, posting it tonight at eight. I'll tag you.\"];\nconst messages: Message[] = Array.from({ length: 50_000 }, (_, i) => ({ id: `m${i}`, author: i % 2 ? \"Elena\" : \"Noah\", text: LINES[i % LINES.length]! }));\n\n// 50,000 messages of different heights: each one measured, ~15 in the page, the scrollbar right from the start.\nexport default function VirtualMessages() {\n return (\n <VirtualList\n items={messages}\n getKey={(m) => m.id}\n estimateSize={64}\n gap={8}\n height={360}\n label=\"Messages\"\n className=\"border border-border-default bg-surface-1 p-3\"\n renderItem={(m) => (\n <div className=\"rounded-lg bg-surface-2 px-3 py-2 text-sm text-fg\">\n <p className=\"text-xs font-semibold text-fg-secondary\">{m.author}</p>\n <p>{m.text}</p>\n </div>\n )}\n />\n );\n}\n"
294
+ },
295
+ {
296
+ "name": "gallery",
297
+ "title": "A gallery",
298
+ "description": "A `VirtualGrid` of 50,000 clips: as many columns as the width allows.",
299
+ "path": "examples/virtual/gallery.tsx",
300
+ "module": "@krizaka/ui/registry/examples/virtual/gallery",
301
+ "code": "\"use client\";\n\nimport { VirtualGrid } from \"@krizaka/ui/virtual\";\n\ntype Clip = { id: string; title: string; minutes: number };\nconst clips: Clip[] = Array.from({ length: 50_000 }, (_, i) => ({ id: `c${i}`, title: `Clip ${i + 1}`, minutes: 1 + (i % 12) }));\n\n// A gallery of 50,000 clips: as many columns as the width allows, only the rows in view rendered.\nexport default function VirtualGallery() {\n return (\n <VirtualGrid\n items={clips}\n getKey={(c) => c.id}\n estimateRowHeight={148}\n minItemWidth={160}\n gap={12}\n height={420}\n label=\"Clips\"\n renderItem={(c) => (\n <article className=\"flex flex-col gap-2\">\n <div className=\"aspect-video rounded-lg bg-surface-3\" aria-hidden />\n <p className=\"truncate text-sm font-semibold text-fg\">{c.title}</p>\n <p className=\"text-xs text-fg-secondary\">{c.minutes} min</p>\n </article>\n )}\n />\n );\n}\n"
302
+ },
303
+ {
304
+ "name": "feed",
305
+ "title": "A feed",
306
+ "description": "`scroll=\"window\"`: the page scrolls, 20 more posts each time the end comes near.",
307
+ "path": "examples/virtual/feed.tsx",
308
+ "module": "@krizaka/ui/registry/examples/virtual/feed",
309
+ "code": "\"use client\";\n\nimport { VirtualList } from \"@krizaka/ui/virtual\";\nimport { useState } from \"react\";\n\ntype Post = { id: string; text: string };\nconst page = (from: number): Post[] => Array.from({ length: 20 }, (_, i) => ({ id: `p${from + i}`, text: `Post ${from + i + 1}` }));\n\n// A feed that scrolls the page itself (`scroll=\"window\"`): 20 more posts each time the end comes near.\nexport default function VirtualFeed() {\n const [posts, setPosts] = useState(() => page(0));\n return (\n <VirtualList\n items={posts}\n getKey={(p) => p.id}\n estimateSize={72}\n gap={8}\n scroll=\"window\"\n label=\"Feed\"\n onEndReached={() => setPosts((all) => [...all, ...page(all.length)])}\n renderItem={(p) => <div className=\"rounded-xl border border-border-default bg-surface-1 p-4 text-sm text-fg\">{p.text}</div>}\n />\n );\n}\n"
310
+ }
311
+ ]
312
+ },
313
+ "native": null,
314
+ "files": [
315
+ {
316
+ "path": "media.ts",
317
+ "content": "// Shared by the data and media primitives (client): the clock format, the reduced-motion preference, the\n// in-view observer, a debounced callback. Never an entry of its own.\nimport * as React from \"react\";\n\n/** Seconds as a clock: `75` → `1:15`, `3725` → `1:02:05`. Negative or unknown values read `0:00`. */\nexport function formatClock(seconds: number): string {\n const s = Number.isFinite(seconds) && seconds > 0 ? Math.floor(seconds) : 0;\n const h = Math.floor(s / 3600);\n const m = Math.floor((s % 3600) / 60);\n const rest = String(s % 60).padStart(2, \"0\");\n return h > 0 ? `${h}:${String(m).padStart(2, \"0\")}:${rest}` : `${m}:${rest}`;\n}\n\n/** Clamps `value` between `min` and `max`. */\nexport const clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));\n\nconst REDUCE = \"(prefers-reduced-motion: reduce)\";\nconst subscribeReduce = (notify: () => void) => {\n if (typeof window === \"undefined\" || !window.matchMedia) return () => undefined;\n const query = window.matchMedia(REDUCE);\n query.addEventListener?.(\"change\", notify);\n return () => query.removeEventListener?.(\"change\", notify);\n};\n\n/** `true` when the person asked for less motion (`prefers-reduced-motion: reduce`); follows a change of the setting. */\nexport function usePrefersReducedMotion(): boolean {\n return React.useSyncExternalStore(\n subscribeReduce,\n () => (typeof window !== \"undefined\" && window.matchMedia ? window.matchMedia(REDUCE).matches : false),\n () => false,\n );\n}\n\n/** The latest value of a callback, for an effect or an event that must not re-subscribe when it changes. */\nexport function useLatest<T>(value: T) {\n const ref = React.useRef(value);\n React.useLayoutEffect(() => {\n ref.current = value;\n });\n return ref;\n}\n\n/** Calls `onChange(visible)` when at least `threshold` of the element enters or leaves the viewport. */\nexport function useInView(ref: React.RefObject<Element | null>, onChange: (visible: boolean) => void, enabled = true, threshold = 0.25) {\n const latest = useLatest(onChange);\n React.useEffect(() => {\n const element = ref.current;\n if (!enabled || !element || typeof IntersectionObserver === \"undefined\") return;\n const observer = new IntersectionObserver(([entry]) => entry && latest.current(entry.isIntersecting), { threshold });\n observer.observe(element);\n return () => observer.disconnect();\n }, [ref, enabled, threshold, latest]);\n}\n\n/** A stable function that runs `callback` once `delay` ms have passed without a new call; `cancel()` drops the pending one. */\nexport function useDebouncedCallback<A extends unknown[]>(callback: (...args: A) => void, delay: number) {\n const latest = useLatest(callback);\n const [debounced] = React.useState(() => {\n let timer: ReturnType<typeof setTimeout> | undefined;\n let wait = delay;\n const run = (...args: A) => {\n clearTimeout(timer);\n if (wait <= 0) latest.current(...args);\n else timer = setTimeout(() => latest.current(...args), wait);\n };\n return Object.assign(run, {\n cancel: () => clearTimeout(timer),\n setDelay: (next: number) => {\n wait = next;\n },\n });\n });\n React.useEffect(() => debounced.setDelay(delay), [debounced, delay]);\n React.useEffect(() => () => debounced.cancel(), [debounced]);\n return debounced;\n}\n\n/** A value controlled by a prop when it is given, held inside otherwise; `set` calls `onChange` either way. */\nexport function useControllable<T>(value: T | undefined, defaultValue: T, onChange?: (next: T) => void) {\n const [inner, setInner] = React.useState(defaultValue);\n const controlled = value !== undefined;\n const current = controlled ? value : inner;\n const set = React.useCallback(\n (next: T) => {\n if (!controlled) setInner(next);\n onChange?.(next);\n },\n [controlled, onChange],\n );\n return [current, set] as const;\n}\n\n/** Starts a media element without an unhandled rejection (autoplay refused, the source replaced meanwhile). */\nexport function playSafely(media: HTMLMediaElement | null | undefined) {\n try {\n const started = media?.play() as Promise<void> | undefined;\n started?.catch?.(() => undefined);\n } catch {\n // Not playable here (no media support): the controls stay as they are.\n }\n}\n"
318
+ },
319
+ {
320
+ "path": "meta.ts",
321
+ "content": "// The documentation of a component, carried by its code: each primitive has a `meta.ts` beside its source\n// (`src/<name>/meta.ts`; a component that exists only in React Native: `src/native/meta/<name>.ts`). Never built into\n// the package: `scripts/build-registry.mjs` reads them into `registry/<name>.json`, which krizaka.com renders as\n// /docs/ui/<name>, and `scripts/registry.test.mjs` fails when one is missing or incomplete.\n//\n// Why a typed module and not JSDoc tags: the fields are lists and links (`related`, `whenNotToUse[].use`, examples),\n// which a type checks and a comment does not; the file is plain data (erasable TypeScript), so Node reads it without a\n// compiler, and an editor completes it.\n\n/** Every documented component: the web primitives (one entry of the package each) and the native-only ones. */\nexport type ComponentName =\n | \"achievement\"\n | \"action-bar\"\n | \"alert\"\n | \"app-shell\"\n | \"argument-card\"\n | \"audio-player\"\n | \"auth-layout\"\n | \"avatar\"\n | \"badge\"\n | \"button\"\n | \"card\"\n | \"card-grid\"\n | \"catalogue-page\"\n | \"changelog-page\"\n | \"checkbox\"\n | \"chip\"\n | \"chip-link\"\n | \"choice-grid\"\n | \"cn\"\n | \"code-block\"\n | \"combobox\"\n | \"command\"\n | \"component-page\"\n | \"confirm-button\"\n | \"contact-page\"\n | \"continue-prompt\"\n | \"countdown\"\n | \"cta-panel\"\n | \"dashboard-layout\"\n | \"data-table\"\n | \"date-picker\"\n | \"decision-list\"\n | \"detail-layout\"\n | \"dialog\"\n | \"docs-article-page\"\n | \"docs-hub-page\"\n | \"docs-layout\"\n | \"dropdown-menu\"\n | \"empty-state\"\n | \"error-page\"\n | \"field\"\n | \"file-upload\"\n | \"filter-bar\"\n | \"form\"\n | \"gallery-page\"\n | \"glow-card\"\n | \"goal-gauge\"\n | \"how-it-works-page\"\n | \"image-cropper\"\n | \"iso\"\n | \"kbd\"\n | \"landing-page\"\n | \"landscape\"\n | \"legal-page\"\n | \"link-card\"\n | \"list\"\n | \"loader\"\n | \"longform-page\"\n | \"marketing-layout\"\n | \"marquee\"\n | \"mascot-quote\"\n | \"mascot-state\"\n | \"mascots\"\n | \"media-capture\"\n | \"meter\"\n | \"nav-bar\"\n | \"number-ticker\"\n | \"page\"\n | \"page-header\"\n | \"page-hero\"\n | \"pagination\"\n | \"pointer-light\"\n | \"popover\"\n | \"pricing-page\"\n | \"product-page\"\n | \"profile-card\"\n | \"progress\"\n | \"promise-card\"\n | \"radio-group\"\n | \"scroll-stage\"\n | \"search-field\"\n | \"section-backdrop\"\n | \"segmented\"\n | \"separator\"\n | \"settings-layout\"\n | \"skeleton\"\n | \"slider\"\n | \"slot\"\n | \"spinner\"\n | \"split-view\"\n | \"stage-banner\"\n | \"stat\"\n | \"status-page\"\n | \"stepper\"\n | \"switch\"\n | \"tabs\"\n | \"tag-input\"\n | \"terminal-replay\"\n | \"theme\"\n | \"toast\"\n | \"toc\"\n | \"tooltip\"\n | \"txt\"\n | \"video-player\"\n | \"video-trimmer\"\n | \"virtual\";\n\n/** Where a component exists: `@krizaka/ui/<name>` (web), `@krizaka/ui/native` (React Native), or both. */\nexport type Platform = \"web\" | \"native\" | \"both\";\n\n/** `stable`: its API only changes in a major. `beta`: it may still change in a minor. */\nexport type Status = \"stable\" | \"beta\";\n\n/**\n * The group of the catalogue. `media`: video, sound, camera, files, cropping. `blocks`: the page blocks — the frame,\n * the hero, sections, cards that lead or argue, decisions, code, calls to act — that every page of a site is made of.\n * `layouts`: the shells of whole screens — an application, a dashboard, settings, sign-in, an object, a list and its\n * item, a site's page, a documentation page — each with its screens. `templates`: the page templates — whole pages of a\n * site (a landing, a product, a docs hub, a long read, a changelog, pricing, status, an error…), each a distinct\n * composition of the blocks, words and content as props.\n */\nexport type Category = \"actions\" | \"forms\" | \"navigation\" | \"overlays\" | \"feedback\" | \"data-display\" | \"media\" | \"blocks\" | \"layouts\" | \"templates\" | \"layout\" | \"foundations\";\n\n/**\n * A named example: the file `registry/examples/<component>/<name>.tsx` (web) or\n * `registry/examples/<component>/native/<name>.tsx` (React Native) — at most 40 lines, imported by the stories and\n * shown (live, with its code) by the documentation.\n */\nexport interface Example {\n /** The file name, kebab-case (`primary`, `icon-button`). */\n readonly name: string;\n /** A short title (`Primary`, `Icon button`). */\n readonly title: string;\n /** One or two sentences: when this variant is the right one. */\n readonly description: string;\n /**\n * A template: a whole screen of a product composed from the platform (a layout and its blocks, real words, its phone\n * version thought out), copied as a starting point — at most 160 lines, listed on krizaka.com/docs/ui/templates.\n */\n readonly template?: boolean;\n}\n\n/** One platform's side of a component. */\nexport interface PlatformDocs {\n /** The names to import (`[\"Button\", \"IconButton\"]`): from `@krizaka/ui/<name>` on the web, `@krizaka/ui/native` in React Native. */\n readonly imports: readonly string[];\n /** The examples, in reading order; the first one is the component's preview. */\n readonly examples: readonly Example[];\n}\n\n/** The React Native side: the same concept, and what differs from the web API. */\nexport interface NativeDocs extends PlatformDocs {\n /**\n * The entry to import from when it is not `@krizaka/ui/native`: a component that needs an Expo module (an optional\n * peer) has its own, `@krizaka/ui/native/<name>`, so an app that does not use it never installs the module.\n */\n readonly entry?: string;\n /** What differs from the web API (`label` instead of children…); empty for a native-only component. */\n readonly differences: readonly string[];\n}\n\nexport interface KeyboardInteraction {\n /** The keys, as written on a keyboard: `Space`, `Enter`, `Arrow keys`, `Esc`, `Tab`. */\n readonly keys: string;\n /** What they do. */\n readonly action: string;\n}\n\nexport interface ComponentMeta {\n /** The display name: `Button`, `Dropdown menu`. */\n readonly title: string;\n /** One sentence: what it is. */\n readonly summary: string;\n readonly status: Status;\n readonly category: Category;\n /** Must match the sides below: `both` ⇔ `web` and `native`. */\n readonly platforms: Platform;\n /** When to reach for it: concrete situations, one per item. */\n readonly whenToUse: readonly string[];\n /** When not to — and what to use instead (`use`), when another component is the answer. */\n readonly whenNotToUse: readonly { readonly when: string; readonly use?: ComponentName }[];\n /** How to use it well: wording, placement, composition. */\n readonly bestPractices: readonly string[];\n readonly accessibility: {\n /** The keyboard, when it does more than Tab and Enter. */\n readonly keyboard: readonly KeyboardInteraction[];\n /** Roles, names and announcements: what the component does, what the app must provide. */\n readonly notes: readonly string[];\n };\n /** The components a reader of this page should know about. */\n readonly related: readonly ComponentName[];\n readonly web?: PlatformDocs;\n readonly native?: NativeDocs;\n}\n"
322
+ },
323
+ {
324
+ "path": "virtual/index.ts",
325
+ "content": "/** @krizaka/ui/virtual — `VirtualList` (its own region or the page's), `VirtualGrid` (a gallery), `useWindowVirtualizer` and `useVirtualizer` (TanStack Virtual, through the facade), `virtual` (the slots). Client (\"use client\"). */\nexport {\n columnsFor,\n useVirtualizer,\n useWindowVirtualizer,\n virtual,\n VirtualGrid,\n type VirtualGridProps,\n type VirtualHandle,\n type VirtualItem,\n type Virtualizer,\n VirtualList,\n type VirtualListProps,\n} from \"./virtual\";\n"
326
+ },
327
+ {
328
+ "path": "virtual/meta.ts",
329
+ "content": "import type { ComponentMeta } from \"../meta\";\n\nexport const meta = {\n title: \"Virtual\",\n summary: \"Long lists and galleries rendered by what is in view, on TanStack Virtual: a list in its own region or the page's, a grid that fits the width, measured items, the end announced for infinite loading.\",\n status: \"beta\",\n category: \"data-display\",\n platforms: \"web\",\n whenToUse: [\n \"A list of hundreds to millions of items loaded at once or page by page: messages, comments, logs, notifications.\",\n \"A gallery that grows as the person scrolls: videos, photos, products (`VirtualGrid`).\",\n \"A feed that scrolls the page itself rather than a box (`scroll=\\\"window\\\"`).\",\n ],\n whenNotToUse: [\n { when: \"For records compared on columns: the data table has its own windowing.\", use: \"data-table\" },\n { when: \"For a short list (under a hundred items): render it whole, with no scrolling region.\", use: \"card-grid\" },\n { when: \"In a React Native app: FlashList, through the native list.\", use: \"list\" },\n ],\n bestPractices: [\n \"Give `getKey` (an id): measurements stay with their item when the list changes.\",\n \"Estimate the size close to the average (`estimateSize`): items are measured anyway, a close guess keeps the scrollbar steady.\",\n \"Load the next page in `onEndReached` (a `useInfiniteQuery` of @krizaka/query) and show a spinner in `footer`.\",\n \"Name the list (`label`): it names the focusable scrolling region, so keyboard people can scroll it.\",\n \"Need the raw engine? `useVirtualizer` and `useWindowVirtualizer` come through this entry — never import `@tanstack/*` in a product.\",\n ],\n accessibility: {\n keyboard: [\n { keys: \"Tab\", action: \"Reaches the scrolling region (then the links and buttons of the items in view).\" },\n { keys: \"Arrow keys\", action: \"Scroll the focused region; Page Up / Page Down and Home / End move by a screen or to the ends.\" },\n ],\n notes: [\n \"The scrolling region is focusable (`tabIndex=0`) and named by `label`.\",\n \"Items are a `role=\\\"list\\\"` of `listitem`s carrying `aria-setsize` and `aria-posinset`: a screen reader says “item 4,812 of 50,000” though only twenty exist in the page.\",\n \"`scrollToIndex` (through `ref`) scrolls smoothly, or at once when the person asked for less motion.\",\n ],\n },\n related: [\"data-table\", \"list\", \"card\", \"spinner\"],\n web: {\n imports: [\"VirtualList\", \"VirtualGrid\", \"useWindowVirtualizer\", \"useVirtualizer\"],\n examples: [\n { name: \"messages\", title: \"50,000 messages\", description: \"A `VirtualList` of items of different heights, each measured.\" },\n { name: \"gallery\", title: \"A gallery\", description: \"A `VirtualGrid` of 50,000 clips: as many columns as the width allows.\" },\n { name: \"feed\", title: \"A feed\", description: \"`scroll=\\\"window\\\"`: the page scrolls, 20 more posts each time the end comes near.\" },\n ],\n },\n} satisfies ComponentMeta;\n"
330
+ },
331
+ {
332
+ "path": "virtual/virtual.tsx",
333
+ "content": "// Client (a scroll position, measured items). Long lists and galleries rendered by what is in view, on TanStack Virtual\n// v3 behind the Krizaka facade (ADR-001: a product imports `@krizaka/ui/virtual`, never `@tanstack/*`). A list is a\n// focusable scrolling region holding a `role=\"list\"` whose items say where they stand in the whole (`aria-setsize`,\n// `aria-posinset`), so a screen reader knows \"item 4,812 of 50,000\" though only twenty exist in the page.\nimport {\n measureElement as measureTanStack,\n observeElementRect,\n type ReactVirtualizer,\n useVirtualizer as useTanStackVirtualizer,\n useWindowVirtualizer as useTanStackWindowVirtualizer,\n type VirtualItem,\n type Virtualizer as TanStackVirtualizer,\n} from \"@tanstack/react-virtual\";\nimport * as React from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { useLatest, usePrefersReducedMotion } from \"../media\";\n\nexport type { VirtualItem };\n\nexport const virtual = tv({\n slots: {\n viewport:\n \"relative w-full overflow-auto overscroll-contain rounded-xl focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring\",\n list: \"relative w-full\",\n item: \"absolute top-0 left-0 w-full\",\n row: \"absolute top-0 left-0 grid w-full\",\n empty: \"px-4 py-10 text-center text-sm text-fg-secondary\",\n },\n});\n\n/** What a list or a grid can be asked to do from outside (`ref`). */\nexport type VirtualHandle = {\n /** Scrolls the item at `index` into view — smoothly, unless the person asked for less motion. */\n scrollToIndex: (index: number, align?: \"start\" | \"center\" | \"end\" | \"auto\") => void;\n};\n\n/** The window virtualizer of TanStack Virtual (a feed that scrolls the page), re-exported through the facade. */\nexport const useWindowVirtualizer = useTanStackWindowVirtualizer;\n/** The element virtualizer of TanStack Virtual (anything the components do not cover), re-exported through the facade. */\nexport const useVirtualizer = useTanStackVirtualizer;\nexport type Virtualizer<S extends Element | Window = Element, I extends Element = Element> = ReactVirtualizer<S, I>;\n\ntype Size = number | ((index: number) => number);\n\n/**\n * TanStack's observer of the scrolling element's size, falling back to the declared height while the element has no\n * layout (not yet in the page, in a hidden tab, under a DOM without layout such as a test): the rows of the first\n * screen are rendered at once instead of none.\n */\n/** TanStack's measure of an item, falling back to the estimate while it has no layout (0 px). */\nexport const measureWithFallback =\n (estimate: (index: number) => number) =>\n <S extends Element | Window, I extends Element>(element: I, entry: ResizeObserverEntry | undefined, instance: TanStackVirtualizer<S, I>) => {\n const size = measureTanStack(element, entry, instance);\n return size > 0 ? size : estimate(Number(element.getAttribute(\"data-index\") ?? 0));\n };\n\n/** The fallbacks as stable options (a new function at each render would re-observe the element at each render). */\nexport function useLayoutFallbacks(height: number, estimate: Size) {\n const estimateOf = sizeOf(estimate);\n const key = typeof estimate === \"number\" ? estimate : 0;\n // eslint-disable-next-line react-hooks/exhaustive-deps -- a function estimate is read through its latest value\n return React.useMemo(() => ({ observeElementRect: observeRectWithFallback(height), measureElement: measureWithFallback(estimateOf) }), [height, key]);\n}\n\nexport const observeRectWithFallback =\n (height: number) =>\n <S extends Element, I extends Element>(instance: TanStackVirtualizer<S, I>, callback: (rect: { width: number; height: number }) => void) =>\n observeElementRect(instance, (rect) => callback(rect.height > 0 ? rect : { width: rect.width, height }));\nconst sizeOf = (size: Size) => (typeof size === \"number\" ? () => size : size);\n\n/** Calls `onEndReached` once each time the last rendered item comes within `threshold` items of the end. */\nfunction useEndReached(items: readonly VirtualItem[], count: number, threshold: number, onEndReached: (() => void) | undefined) {\n const latest = useLatest(onEndReached);\n const last = items.at(-1)?.index ?? -1;\n const reached = count > 0 && last >= count - 1 - threshold;\n const firedAt = React.useRef(-1);\n React.useEffect(() => {\n if (!reached || firedAt.current === count) return;\n firedAt.current = count;\n latest.current?.();\n }, [reached, count, latest]);\n}\n\nfunction useHandle(ref: React.Ref<VirtualHandle> | undefined, virtualizer: { scrollToIndex: (index: number, options: { align: \"start\" | \"center\" | \"end\" | \"auto\"; behavior: ScrollBehavior }) => void }, toIndex: (i: number) => number) {\n const reduce = usePrefersReducedMotion();\n React.useImperativeHandle(\n ref,\n () => ({ scrollToIndex: (index, align = \"auto\") => virtualizer.scrollToIndex(toIndex(index), { align, behavior: reduce ? \"auto\" : \"smooth\" }) }),\n [virtualizer, reduce, toIndex],\n );\n}\n\nexport type VirtualListProps<T> = {\n /** The items, all of them: only those in view (and `overscan` around) are rendered. */\n items: readonly T[];\n /** Draws one item. */\n renderItem: (item: T, index: number) => React.ReactNode;\n /** A stable key per item (an id): keeps measurements on the right item when the list changes. Default: the index. */\n getKey?: (item: T, index: number) => string | number;\n /** The size of an item in px, or a guess per index; each item is then measured (dynamic sizes). */\n estimateSize: Size;\n /** The accessible name of the list (\"Messages\", \"Events\"), passed translated. */\n label: string;\n /** `self` (default): the list scrolls in its own region of `height`. `window`: the page scrolls (a feed). */\n scroll?: \"self\" | \"window\";\n /** The height of the scrolling region (`self`): px or any CSS length. Default 400. */\n height?: number | string;\n /** Items rendered beyond the visible ones, on each side. Default 6. */\n overscan?: number;\n /** Space between two items, in px. Default 0. */\n gap?: number;\n /** Called when the end comes near (load the next page): once per length of `items`. */\n onEndReached?: () => void;\n /** How many items before the end `onEndReached` fires. Default 5. */\n endReachedThreshold?: number;\n /** Shown instead of the list when there is no item. */\n empty?: React.ReactNode;\n /** Shown after the last item (a spinner while the next page loads). */\n footer?: React.ReactNode;\n /** `scrollToIndex` from outside. */\n ref?: React.Ref<VirtualHandle>;\n /** Classes merged on the scrolling region (`self`) or the list (`window`). */\n className?: string;\n};\n\n/**\n * A long list rendered by what is in view: fixed or measured sizes, its own scrolling region or the page's, the end\n * announced for infinite loading, items placed in the whole for assistive technology.\n */\nexport function VirtualList<T>({\n items,\n renderItem,\n getKey,\n estimateSize,\n label,\n scroll = \"self\",\n height = 400,\n overscan = 6,\n gap = 0,\n onEndReached,\n endReachedThreshold = 5,\n empty,\n footer,\n ref,\n className,\n}: VirtualListProps<T>) {\n const s = virtual();\n const viewport = React.useRef<HTMLDivElement>(null);\n const list = React.useRef<HTMLDivElement>(null);\n const [margin, setMargin] = React.useState(0);\n const fallbacks = useLayoutFallbacks(typeof height === \"number\" ? height : 400, estimateSize);\n const common = {\n measureElement: fallbacks.measureElement,\n count: items.length,\n estimateSize: sizeOf(estimateSize),\n overscan,\n gap,\n getItemKey: (index: number) => (getKey ? getKey(items[index] as T, index) : index),\n };\n // Both hooks run on every render (the rules of hooks); the unused one is disabled. TanStack Virtual's instance is\n // mutable by design: React Compiler skips this component, which re-renders on the virtualizer's own updates.\n // eslint-disable-next-line react-hooks/incompatible-library -- the virtualizer drives the renders of this component\n const self = useTanStackVirtualizer({\n ...common,\n getScrollElement: () => viewport.current,\n initialRect: { width: 0, height: typeof height === \"number\" ? height : 400 },\n observeElementRect: fallbacks.observeElementRect,\n enabled: scroll === \"self\",\n });\n const page = useTanStackWindowVirtualizer({\n ...common,\n scrollMargin: margin,\n initialRect: { width: 0, height: typeof window === \"undefined\" ? 800 : window.innerHeight },\n enabled: scroll === \"window\",\n });\n const virtualizer = scroll === \"window\" ? page : self;\n React.useLayoutEffect(() => {\n if (scroll === \"window\" && list.current) setMargin(list.current.getBoundingClientRect().top + window.scrollY);\n }, [scroll]);\n const virtualItems = virtualizer.getVirtualItems();\n useEndReached(virtualItems, items.length, endReachedThreshold, onEndReached);\n useHandle(ref, virtualizer, React.useCallback((i: number) => i, []));\n\n const offset = scroll === \"window\" ? virtualizer.options.scrollMargin : 0;\n const body =\n items.length === 0 && empty ? (\n <div className={s.empty()}>{empty}</div>\n ) : (\n <div ref={list} role=\"list\" aria-label={scroll === \"window\" ? label : undefined} className={s.list({ className: scroll === \"window\" ? className : undefined })} style={{ height: virtualizer.getTotalSize() }}>\n {virtualItems.map((item) => (\n <div\n role=\"listitem\"\n key={item.key}\n data-index={item.index}\n ref={virtualizer.measureElement}\n aria-setsize={items.length}\n aria-posinset={item.index + 1}\n className={s.item()}\n style={{ transform: `translateY(${item.start - offset}px)` }}\n >\n {renderItem(items[item.index] as T, item.index)}\n </div>\n ))}\n </div>\n );\n\n if (scroll === \"window\")\n return (\n <>\n {body}\n {footer}\n </>\n );\n return (\n // A scrolling region the keyboard can reach: Tab lands on it, the arrows and Page keys scroll it.\n <div ref={viewport} tabIndex={0} role=\"region\" aria-label={label} className={s.viewport({ className })} style={{ height }}>\n {body}\n {footer}\n </div>\n );\n}\n\nexport type VirtualGridProps<T> = {\n /** The items, all of them: only the rows in view are rendered. */\n items: readonly T[];\n /** Draws one cell (a card, a thumbnail). */\n renderItem: (item: T, index: number) => React.ReactNode;\n /** A stable key per item. Default: the index. */\n getKey?: (item: T, index: number) => string | number;\n /** The height of a row in px (a guess: rows are measured). */\n estimateRowHeight: number;\n /** The accessible name of the grid of items (\"Videos\"), passed translated. */\n label: string;\n /** A fixed number of columns. Without it, as many columns of at least `minItemWidth` as the width allows. */\n columns?: number;\n /** The narrowest a cell may be, in px, when `columns` is not set. Default 220. */\n minItemWidth?: number;\n /** The height of the scrolling region: px or any CSS length. Default 480. */\n height?: number | string;\n /** Space between cells, in px. Default 16. */\n gap?: number;\n /** Rows rendered beyond the visible ones. Default 3. */\n overscan?: number;\n /** Called when the last rows come near (load the next page). */\n onEndReached?: () => void;\n /** Shown instead of the grid when there is no item. */\n empty?: React.ReactNode;\n /** Shown after the last row. */\n footer?: React.ReactNode;\n /** `scrollToIndex` (of an item) from outside. */\n ref?: React.Ref<VirtualHandle>;\n /** Classes merged on the scrolling region. */\n className?: string;\n};\n\n/** The number of columns a width holds at `minItemWidth` each (at least one). */\nexport const columnsFor = (width: number, minItemWidth: number, gap: number) => Math.max(1, Math.floor((width + gap) / (minItemWidth + gap)));\n\n/** A gallery rendered by the rows in view: as many columns as the width allows (or a fixed number), measured rows. */\nexport function VirtualGrid<T>({\n items,\n renderItem,\n getKey,\n estimateRowHeight,\n label,\n columns: fixed,\n minItemWidth = 220,\n height = 480,\n gap = 16,\n overscan = 3,\n onEndReached,\n empty,\n footer,\n ref,\n className,\n}: VirtualGridProps<T>) {\n const s = virtual();\n const viewport = React.useRef<HTMLDivElement>(null);\n const [width, setWidth] = React.useState(0);\n React.useLayoutEffect(() => {\n const element = viewport.current;\n if (!element || fixed) return;\n setWidth(element.clientWidth);\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(([entry]) => entry && setWidth(entry.contentRect.width));\n observer.observe(element);\n return () => observer.disconnect();\n }, [fixed]);\n const columns = fixed ?? (width > 0 ? columnsFor(width, minItemWidth, gap) : 1);\n const rows = Math.ceil(items.length / columns);\n const fallbacks = useLayoutFallbacks(typeof height === \"number\" ? height : 480, estimateRowHeight);\n // eslint-disable-next-line react-hooks/incompatible-library -- the virtualizer drives the renders of this component\n const virtualizer = useTanStackVirtualizer({\n ...fallbacks,\n count: rows,\n estimateSize: () => estimateRowHeight,\n overscan,\n gap,\n getScrollElement: () => viewport.current,\n initialRect: { width: 0, height: typeof height === \"number\" ? height : 480 },\n getItemKey: (row) => (getKey && items[row * columns] !== undefined ? getKey(items[row * columns] as T, row * columns) : row),\n });\n const virtualRows = virtualizer.getVirtualItems();\n useEndReached(virtualRows, rows, 1, onEndReached);\n useHandle(ref, virtualizer, React.useCallback((i: number) => Math.floor(i / columns), [columns]));\n\n return (\n <div ref={viewport} tabIndex={0} role=\"region\" aria-label={label} className={s.viewport({ className })} style={{ height }}>\n {items.length === 0 && empty ? (\n <div className={s.empty()}>{empty}</div>\n ) : (\n <div role=\"list\" className={s.list()} style={{ height: virtualizer.getTotalSize() }}>\n {virtualRows.map((row) => (\n <div\n key={row.key}\n data-index={row.index}\n ref={virtualizer.measureElement}\n className={s.row()}\n style={{ transform: `translateY(${row.start}px)`, gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`, gap }}\n >\n {items.slice(row.index * columns, row.index * columns + columns).map((item, i) => {\n const index = row.index * columns + i;\n return (\n <div role=\"listitem\" key={getKey ? getKey(item, index) : index} aria-setsize={items.length} aria-posinset={index + 1} className=\"min-w-0\">\n {renderItem(item, index)}\n </div>\n );\n })}\n </div>\n ))}\n </div>\n )}\n {footer}\n </div>\n );\n}\n"
334
+ }
335
+ ],
336
+ "dependencies": [
337
+ "@tanstack/react-virtual@3.14.15",
338
+ "tailwind-variants@^3.3.1"
339
+ ],
340
+ "registryDependencies": [],
341
+ "demo": {
342
+ "path": "examples/virtual/messages.tsx",
343
+ "content": "\"use client\";\n\nimport { VirtualList } from \"@krizaka/ui/virtual\";\n\ntype Message = { id: string; author: string; text: string };\nconst LINES = [\"On my way.\", \"Can you send the cut from yesterday? The second take, with the sunset over the river and the drone shot at the end.\", \"Done!\", \"Thanks — looks great, posting it tonight at eight. I'll tag you.\"];\nconst messages: Message[] = Array.from({ length: 50_000 }, (_, i) => ({ id: `m${i}`, author: i % 2 ? \"Elena\" : \"Noah\", text: LINES[i % LINES.length]! }));\n\n// 50,000 messages of different heights: each one measured, ~15 in the page, the scrollbar right from the start.\nexport default function VirtualMessages() {\n return (\n <VirtualList\n items={messages}\n getKey={(m) => m.id}\n estimateSize={64}\n gap={8}\n height={360}\n label=\"Messages\"\n className=\"border border-border-default bg-surface-1 p-3\"\n renderItem={(m) => (\n <div className=\"rounded-lg bg-surface-2 px-3 py-2 text-sm text-fg\">\n <p className=\"text-xs font-semibold text-fg-secondary\">{m.author}</p>\n <p>{m.text}</p>\n </div>\n )}\n />\n );\n}\n"
344
+ },
345
+ "props": [
346
+ {
347
+ "component": "VirtualGrid",
348
+ "description": "A gallery rendered by the rows in view: as many columns as the width allows (or a fixed number), measured rows.",
349
+ "props": [
350
+ {
351
+ "name": "estimateRowHeight",
352
+ "type": "number",
353
+ "default": null,
354
+ "description": "The height of a row in px (a guess: rows are measured).",
355
+ "required": true
356
+ },
357
+ {
358
+ "name": "items",
359
+ "type": "readonly T[]",
360
+ "default": null,
361
+ "description": "The items, all of them: only the rows in view are rendered.",
362
+ "required": true
363
+ },
364
+ {
365
+ "name": "label",
366
+ "type": "string",
367
+ "default": null,
368
+ "description": "The accessible name of the grid of items (\"Videos\"), passed translated.",
369
+ "required": true
370
+ },
371
+ {
372
+ "name": "renderItem",
373
+ "type": "(item: T, index: number) => ReactNode",
374
+ "default": null,
375
+ "description": "Draws one cell (a card, a thumbnail).",
376
+ "required": true
377
+ },
378
+ {
379
+ "name": "className",
380
+ "type": "string",
381
+ "default": null,
382
+ "description": "Classes merged on the scrolling region.",
383
+ "required": false
384
+ },
385
+ {
386
+ "name": "columns",
387
+ "type": "number",
388
+ "default": null,
389
+ "description": "A fixed number of columns. Without it, as many columns of at least `minItemWidth` as the width allows.",
390
+ "required": false
391
+ },
392
+ {
393
+ "name": "empty",
394
+ "type": "ReactNode",
395
+ "default": null,
396
+ "description": "Shown instead of the grid when there is no item.",
397
+ "required": false
398
+ },
399
+ {
400
+ "name": "footer",
401
+ "type": "ReactNode",
402
+ "default": null,
403
+ "description": "Shown after the last row.",
404
+ "required": false
405
+ },
406
+ {
407
+ "name": "gap",
408
+ "type": "number",
409
+ "default": "16",
410
+ "description": "Space between cells, in px. Default 16.",
411
+ "required": false
412
+ },
413
+ {
414
+ "name": "getKey",
415
+ "type": "((item: T, index: number) => string | number)",
416
+ "default": null,
417
+ "description": "A stable key per item. Default: the index.",
418
+ "required": false
419
+ },
420
+ {
421
+ "name": "height",
422
+ "type": "string | number",
423
+ "default": "480",
424
+ "description": "The height of the scrolling region: px or any CSS length. Default 480.",
425
+ "required": false
426
+ },
427
+ {
428
+ "name": "minItemWidth",
429
+ "type": "number",
430
+ "default": "220",
431
+ "description": "The narrowest a cell may be, in px, when `columns` is not set. Default 220.",
432
+ "required": false
433
+ },
434
+ {
435
+ "name": "onEndReached",
436
+ "type": "(() => void)",
437
+ "default": null,
438
+ "description": "Called when the last rows come near (load the next page).",
439
+ "required": false
440
+ },
441
+ {
442
+ "name": "overscan",
443
+ "type": "number",
444
+ "default": "3",
445
+ "description": "Rows rendered beyond the visible ones. Default 3.",
446
+ "required": false
447
+ },
448
+ {
449
+ "name": "ref",
450
+ "type": "Ref<VirtualHandle>",
451
+ "default": null,
452
+ "description": "`scrollToIndex` (of an item) from outside.",
453
+ "required": false
454
+ }
455
+ ]
456
+ },
457
+ {
458
+ "component": "VirtualList",
459
+ "description": "A long list rendered by what is in view: fixed or measured sizes, its own scrolling region or the page's, the end\nannounced for infinite loading, items placed in the whole for assistive technology.",
460
+ "props": [
461
+ {
462
+ "name": "estimateSize",
463
+ "type": "Size",
464
+ "default": null,
465
+ "description": "The size of an item in px, or a guess per index; each item is then measured (dynamic sizes).",
466
+ "required": true
467
+ },
468
+ {
469
+ "name": "items",
470
+ "type": "readonly T[]",
471
+ "default": null,
472
+ "description": "The items, all of them: only those in view (and `overscan` around) are rendered.",
473
+ "required": true
474
+ },
475
+ {
476
+ "name": "label",
477
+ "type": "string",
478
+ "default": null,
479
+ "description": "The accessible name of the list (\"Messages\", \"Events\"), passed translated.",
480
+ "required": true
481
+ },
482
+ {
483
+ "name": "renderItem",
484
+ "type": "(item: T, index: number) => ReactNode",
485
+ "default": null,
486
+ "description": "Draws one item.",
487
+ "required": true
488
+ },
489
+ {
490
+ "name": "className",
491
+ "type": "string",
492
+ "default": null,
493
+ "description": "Classes merged on the scrolling region (`self`) or the list (`window`).",
494
+ "required": false
495
+ },
496
+ {
497
+ "name": "empty",
498
+ "type": "ReactNode",
499
+ "default": null,
500
+ "description": "Shown instead of the list when there is no item.",
501
+ "required": false
502
+ },
503
+ {
504
+ "name": "endReachedThreshold",
505
+ "type": "number",
506
+ "default": "5",
507
+ "description": "How many items before the end `onEndReached` fires. Default 5.",
508
+ "required": false
509
+ },
510
+ {
511
+ "name": "footer",
512
+ "type": "ReactNode",
513
+ "default": null,
514
+ "description": "Shown after the last item (a spinner while the next page loads).",
515
+ "required": false
516
+ },
517
+ {
518
+ "name": "gap",
519
+ "type": "number",
520
+ "default": "0",
521
+ "description": "Space between two items, in px. Default 0.",
522
+ "required": false
523
+ },
524
+ {
525
+ "name": "getKey",
526
+ "type": "((item: T, index: number) => string | number)",
527
+ "default": null,
528
+ "description": "A stable key per item (an id): keeps measurements on the right item when the list changes. Default: the index.",
529
+ "required": false
530
+ },
531
+ {
532
+ "name": "height",
533
+ "type": "string | number",
534
+ "default": "400",
535
+ "description": "The height of the scrolling region (`self`): px or any CSS length. Default 400.",
536
+ "required": false
537
+ },
538
+ {
539
+ "name": "onEndReached",
540
+ "type": "(() => void)",
541
+ "default": null,
542
+ "description": "Called when the end comes near (load the next page): once per length of `items`.",
543
+ "required": false
544
+ },
545
+ {
546
+ "name": "overscan",
547
+ "type": "number",
548
+ "default": "6",
549
+ "description": "Items rendered beyond the visible ones, on each side. Default 6.",
550
+ "required": false
551
+ },
552
+ {
553
+ "name": "ref",
554
+ "type": "Ref<VirtualHandle>",
555
+ "default": null,
556
+ "description": "`scrollToIndex` from outside.",
557
+ "required": false
558
+ },
559
+ {
560
+ "name": "scroll",
561
+ "type": "\"self\" | \"window\"",
562
+ "default": "self",
563
+ "description": "`self` (default): the list scrolls in its own region of `height`. `window`: the page scrolls (a feed).",
564
+ "required": false
565
+ }
566
+ ]
567
+ }
568
+ ]
569
+ }