@slotted/react 0.1.0-beta.42 → 0.1.0-beta.43

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 (298) hide show
  1. package/dist/{app-shell-D54YkU7E.js → app-shell-DsWhsSMU.js} +3 -2
  2. package/dist/app-shell.js +1 -1
  3. package/dist/attachment-TZykYNu5.js +300 -0
  4. package/dist/attachment.js +2 -2
  5. package/dist/{avatar-group-bJaZE1_C.js → avatar-group-Bzmmj2HI.js} +2 -1
  6. package/dist/avatar-group.js +1 -1
  7. package/dist/{carousel-B9nMK7Yf.js → carousel-CRNz-T3g.js} +1 -1
  8. package/dist/carousel.js +1 -1
  9. package/dist/{command-palette-C90CzfQi.js → command-palette-Bgf5tfCI.js} +160 -156
  10. package/dist/command-palette.js +1 -1
  11. package/dist/{data-grid-D106baPp.js → data-grid-DUft3rJb.js} +1 -1
  12. package/dist/data-grid.js +1 -1
  13. package/dist/{data-list-BA0xrySM.js → data-list-Dv3orBtf.js} +15 -15
  14. package/dist/data-list.js +1 -1
  15. package/dist/detail-panel-Cke3ZFU3.js +342 -0
  16. package/dist/detail-panel.js +2 -2
  17. package/dist/docs/action-bar.examples.md +768 -0
  18. package/dist/docs/action-bar.json +74 -50
  19. package/dist/docs/action-bar.md +49 -311
  20. package/dist/docs/app-shell.examples.md +1221 -64
  21. package/dist/docs/app-shell.json +92 -60
  22. package/dist/docs/app-shell.md +92 -57
  23. package/dist/docs/attachment.examples.md +689 -0
  24. package/dist/docs/attachment.json +69 -37
  25. package/dist/docs/attachment.md +44 -203
  26. package/dist/docs/avatar-group.json +111 -23
  27. package/dist/docs/avatar-group.md +487 -28
  28. package/dist/docs/button-group.json +98 -2
  29. package/dist/docs/button-group.md +411 -8
  30. package/dist/docs/calendar.examples.md +512 -0
  31. package/dist/docs/calendar.json +72 -24
  32. package/dist/docs/calendar.md +18 -147
  33. package/dist/docs/carousel.examples.md +868 -0
  34. package/dist/docs/carousel.json +58 -50
  35. package/dist/docs/carousel.md +66 -300
  36. package/dist/docs/cascader.examples.md +1269 -0
  37. package/dist/docs/cascader.json +72 -16
  38. package/dist/docs/cascader.md +78 -154
  39. package/dist/docs/chart.examples.md +734 -24
  40. package/dist/docs/chart.json +93 -13
  41. package/dist/docs/chart.md +28 -7
  42. package/dist/docs/clock.json +71 -15
  43. package/dist/docs/clock.md +326 -21
  44. package/dist/docs/code-block.json +79 -55
  45. package/dist/docs/code-block.md +417 -74
  46. package/dist/docs/color-picker.json +60 -12
  47. package/dist/docs/color-picker.md +245 -22
  48. package/dist/docs/column-manager.examples.md +764 -0
  49. package/dist/docs/column-manager.json +68 -12
  50. package/dist/docs/column-manager.md +44 -203
  51. package/dist/docs/command-palette.examples.md +747 -0
  52. package/dist/docs/command-palette.json +48 -24
  53. package/dist/docs/command-palette.md +60 -339
  54. package/dist/docs/currency-field.examples.md +355 -73
  55. package/dist/docs/currency-field.json +96 -64
  56. package/dist/docs/currency-field.md +57 -50
  57. package/dist/docs/dashboard-grid.examples.md +629 -0
  58. package/dist/docs/dashboard-grid.json +64 -16
  59. package/dist/docs/dashboard-grid.md +34 -152
  60. package/dist/docs/data-list.examples.md +1556 -0
  61. package/dist/docs/data-list.json +58 -18
  62. package/dist/docs/data-list.md +139 -224
  63. package/dist/docs/date-field.examples.md +543 -0
  64. package/dist/docs/date-field.json +64 -24
  65. package/dist/docs/date-field.md +22 -168
  66. package/dist/docs/datetime-field.examples.md +699 -0
  67. package/dist/docs/datetime-field.json +79 -31
  68. package/dist/docs/datetime-field.md +24 -269
  69. package/dist/docs/datetime-range-picker.examples.md +682 -0
  70. package/dist/docs/datetime-range-picker.json +117 -61
  71. package/dist/docs/datetime-range-picker.md +59 -224
  72. package/dist/docs/description-list.examples.md +652 -0
  73. package/dist/docs/description-list.json +49 -25
  74. package/dist/docs/description-list.md +33 -188
  75. package/dist/docs/detail-panel.examples.md +1177 -0
  76. package/dist/docs/detail-panel.json +69 -53
  77. package/dist/docs/detail-panel.md +114 -324
  78. package/dist/docs/entity-picker.examples.md +1037 -0
  79. package/dist/docs/entity-picker.json +66 -18
  80. package/dist/docs/entity-picker.md +56 -246
  81. package/dist/docs/event-calendar.examples.md +749 -49
  82. package/dist/docs/event-calendar.json +46 -22
  83. package/dist/docs/event-calendar.md +81 -11
  84. package/dist/docs/field-group.examples.md +554 -0
  85. package/dist/docs/field-group.json +98 -34
  86. package/dist/docs/field-group.md +55 -133
  87. package/dist/docs/filter-bar.examples.md +772 -0
  88. package/dist/docs/filter-bar.json +41 -25
  89. package/dist/docs/filter-bar.md +42 -246
  90. package/dist/docs/form.examples.md +579 -0
  91. package/dist/docs/form.json +87 -39
  92. package/dist/docs/form.md +53 -177
  93. package/dist/docs/fullscreen.examples.md +558 -0
  94. package/dist/docs/fullscreen.json +58 -18
  95. package/dist/docs/fullscreen.md +50 -169
  96. package/dist/docs/highlight.json +57 -25
  97. package/dist/docs/highlight.md +402 -50
  98. package/dist/docs/icon.json +85 -5
  99. package/dist/docs/icon.md +401 -10
  100. package/dist/docs/image.examples.md +670 -0
  101. package/dist/docs/image.json +44 -28
  102. package/dist/docs/image.md +24 -176
  103. package/dist/docs/import-export-center.examples.md +1280 -0
  104. package/dist/docs/import-export-center.json +67 -27
  105. package/dist/docs/import-export-center.md +121 -226
  106. package/dist/docs/list-item.examples.md +769 -0
  107. package/dist/docs/list-item.json +110 -38
  108. package/dist/docs/list-item.md +84 -201
  109. package/dist/docs/listbox.examples.md +858 -0
  110. package/dist/docs/listbox.json +76 -28
  111. package/dist/docs/listbox.md +41 -263
  112. package/dist/docs/markdown.json +79 -55
  113. package/dist/docs/markdown.md +581 -85
  114. package/dist/docs/media-viewer.examples.md +1038 -0
  115. package/dist/docs/media-viewer.json +70 -15
  116. package/dist/docs/media-viewer.md +84 -135
  117. package/dist/docs/message-scroller.examples.md +1193 -0
  118. package/dist/docs/message-scroller.json +41 -17
  119. package/dist/docs/message-scroller.md +80 -134
  120. package/dist/docs/message.examples.md +944 -0
  121. package/dist/docs/message.json +64 -16
  122. package/dist/docs/message.md +34 -326
  123. package/dist/docs/meter.json +58 -26
  124. package/dist/docs/meter.md +312 -32
  125. package/dist/docs/navigation-menu.examples.md +1107 -0
  126. package/dist/docs/navigation-menu.json +57 -41
  127. package/dist/docs/navigation-menu.md +105 -298
  128. package/dist/docs/notification-center.examples.md +1045 -0
  129. package/dist/docs/notification-center.json +71 -15
  130. package/dist/docs/notification-center.md +76 -266
  131. package/dist/docs/otp-input.examples.md +490 -0
  132. package/dist/docs/otp-input.json +65 -25
  133. package/dist/docs/otp-input.md +20 -191
  134. package/dist/docs/page-header.examples.md +1041 -0
  135. package/dist/docs/page-header.json +75 -43
  136. package/dist/docs/page-header.md +79 -291
  137. package/dist/docs/page.examples.md +633 -0
  138. package/dist/docs/page.json +48 -16
  139. package/dist/docs/page.md +62 -129
  140. package/dist/docs/prompt-composer.examples.md +630 -0
  141. package/dist/docs/prompt-composer.json +66 -18
  142. package/dist/docs/prompt-composer.md +35 -161
  143. package/dist/docs/prose.json +69 -37
  144. package/dist/docs/prose.md +393 -75
  145. package/dist/docs/rating.examples.md +525 -0
  146. package/dist/docs/rating.json +92 -28
  147. package/dist/docs/rating.md +27 -241
  148. package/dist/docs/saved-views.examples.md +1108 -0
  149. package/dist/docs/saved-views.json +53 -21
  150. package/dist/docs/saved-views.md +86 -171
  151. package/dist/docs/scroll-area.examples.md +837 -0
  152. package/dist/docs/scroll-area.json +64 -24
  153. package/dist/docs/scroll-area.md +57 -140
  154. package/dist/docs/section.examples.md +676 -0
  155. package/dist/docs/section.json +68 -20
  156. package/dist/docs/section.md +39 -162
  157. package/dist/docs/segmented-control.examples.md +480 -0
  158. package/dist/docs/segmented-control.json +76 -28
  159. package/dist/docs/segmented-control.md +20 -191
  160. package/dist/docs/side-navigation.examples.md +1468 -0
  161. package/dist/docs/side-navigation.json +53 -53
  162. package/dist/docs/side-navigation.md +79 -354
  163. package/dist/docs/slider.examples.md +505 -0
  164. package/dist/docs/slider.json +91 -51
  165. package/dist/docs/slider.md +47 -212
  166. package/dist/docs/sparkline.json +60 -36
  167. package/dist/docs/sparkline.md +447 -71
  168. package/dist/docs/split-button.examples.md +509 -0
  169. package/dist/docs/split-button.json +73 -41
  170. package/dist/docs/split-button.md +64 -194
  171. package/dist/docs/splitter.examples.md +921 -0
  172. package/dist/docs/splitter.json +94 -46
  173. package/dist/docs/splitter.md +75 -182
  174. package/dist/docs/stat-card.examples.md +725 -0
  175. package/dist/docs/stat-card.json +89 -41
  176. package/dist/docs/stat-card.md +55 -227
  177. package/dist/docs/status-indicator.json +80 -32
  178. package/dist/docs/status-indicator.md +409 -65
  179. package/dist/docs/stepper.json +53 -21
  180. package/dist/docs/stepper.md +369 -48
  181. package/dist/docs/table-of-contents.examples.md +550 -0
  182. package/dist/docs/table-of-contents.json +60 -28
  183. package/dist/docs/table-of-contents.md +70 -205
  184. package/dist/docs/tags-input.examples.md +541 -0
  185. package/dist/docs/tags-input.json +64 -16
  186. package/dist/docs/tags-input.md +15 -262
  187. package/dist/docs/time-field.examples.md +587 -0
  188. package/dist/docs/time-field.json +69 -29
  189. package/dist/docs/time-field.md +21 -223
  190. package/dist/docs/time-picker.json +117 -53
  191. package/dist/docs/time-picker.md +499 -54
  192. package/dist/docs/time-range-picker.examples.md +750 -0
  193. package/dist/docs/time-range-picker.json +139 -75
  194. package/dist/docs/time-range-picker.md +63 -225
  195. package/dist/docs/timeline.examples.md +617 -0
  196. package/dist/docs/timeline.json +44 -28
  197. package/dist/docs/timeline.md +34 -208
  198. package/dist/docs/toolbar.json +56 -16
  199. package/dist/docs/toolbar.md +357 -63
  200. package/dist/docs/top-navigation.examples.md +1206 -140
  201. package/dist/docs/top-navigation.json +49 -33
  202. package/dist/docs/top-navigation.md +87 -36
  203. package/dist/docs/tour.examples.md +960 -0
  204. package/dist/docs/tour.json +57 -25
  205. package/dist/docs/tour.md +60 -244
  206. package/dist/docs/transfer.examples.md +631 -0
  207. package/dist/docs/transfer.json +80 -16
  208. package/dist/docs/transfer.md +41 -170
  209. package/dist/docs/typography.json +96 -0
  210. package/dist/docs/typography.md +352 -4
  211. package/dist/docs/upload.examples.md +555 -53
  212. package/dist/docs/upload.json +62 -30
  213. package/dist/docs/upload.md +46 -11
  214. package/dist/docs/wizard.examples.md +1389 -0
  215. package/dist/docs/wizard.json +89 -49
  216. package/dist/docs/wizard.md +122 -263
  217. package/dist/{entity-picker-CC4VoC3p.js → entity-picker-C78f3Z0o.js} +9 -6
  218. package/dist/entity-picker.js +1 -1
  219. package/dist/{event-calendar-CjmF_e0H.js → event-calendar-DJPoCi-O.js} +1 -1
  220. package/dist/event-calendar.js +1 -1
  221. package/dist/{filter-bar-B3QJD7SZ.js → filter-bar-D61wiQFP.js} +1 -1
  222. package/dist/filter-bar.js +1 -1
  223. package/dist/{import-export-center-CW8YVZev.js → import-export-center-mqvmlzwB.js} +44 -36
  224. package/dist/import-export-center.js +1 -1
  225. package/dist/index.js +58 -58
  226. package/dist/{markdown-BdskE4-L.js → markdown-8CtV4k44.js} +2 -2
  227. package/dist/markdown.js +1 -1
  228. package/dist/{media-viewer-zEXcwfEY.js → media-viewer-C_cbuAq-.js} +64 -60
  229. package/dist/media-viewer.js +2 -2
  230. package/dist/message-P91bEGyV.js +455 -0
  231. package/dist/message.js +2 -2
  232. package/dist/{page-header-DmwBGwlm.js → page-header-jeAIQSZM.js} +103 -108
  233. package/dist/page-header.js +1 -1
  234. package/dist/section-CVTQdWBl.js +216 -0
  235. package/dist/section.js +2 -2
  236. package/dist/{segmented-control-CbK7SurB.js → segmented-control-BSMVjukr.js} +1 -1
  237. package/dist/segmented-control.js +1 -1
  238. package/dist/{side-navigation-CKRETc8E.js → side-navigation-BQzBxz2B.js} +179 -179
  239. package/dist/side-navigation.js +1 -1
  240. package/dist/{stat-card-CL3Xe6pV.js → stat-card-BpGZiFbG.js} +12 -14
  241. package/dist/stat-card.js +1 -1
  242. package/dist/{stepper-DHdrANZI.js → stepper-Cxb_tHnA.js} +130 -127
  243. package/dist/stepper.js +2 -2
  244. package/dist/styles/carousel.css +1 -1
  245. package/dist/styles/index.css +1 -1
  246. package/dist/styles.css +1 -1
  247. package/dist/{timeline-BiL2CXfn.js → timeline-ZngK6zLC.js} +9 -6
  248. package/dist/timeline.js +1 -1
  249. package/dist/top-navigation-YSEQzBhD.js +744 -0
  250. package/dist/top-navigation.js +2 -2
  251. package/dist/{transfer-sKUvmEKe.js → transfer-Cv5yQuTN.js} +1 -1
  252. package/dist/transfer.js +1 -1
  253. package/dist/types/attachment/attachment-parts.d.ts +24 -11
  254. package/dist/types/attachment/attachment-parts.d.ts.map +1 -1
  255. package/dist/types/attachment/attachment.d.ts +3 -3
  256. package/dist/types/attachment/attachment.d.ts.map +1 -1
  257. package/dist/types/avatar-group/avatar-group.d.ts.map +1 -1
  258. package/dist/types/carousel/carousel-parts.d.ts +2 -2
  259. package/dist/types/command-palette/command-palette.d.ts.map +1 -1
  260. package/dist/types/data-list/data-list.d.ts.map +1 -1
  261. package/dist/types/detail-panel/detail-panel-parts.d.ts +10 -3
  262. package/dist/types/detail-panel/detail-panel-parts.d.ts.map +1 -1
  263. package/dist/types/detail-panel/detail-panel.d.ts.map +1 -1
  264. package/dist/types/detail-panel/detail-panel.types.d.ts +7 -0
  265. package/dist/types/detail-panel/detail-panel.types.d.ts.map +1 -1
  266. package/dist/types/entity-picker/entity-picker.d.ts.map +1 -1
  267. package/dist/types/import-export-center/import-export-center.d.ts.map +1 -1
  268. package/dist/types/media-viewer/index.d.ts +2 -2
  269. package/dist/types/media-viewer/index.d.ts.map +1 -1
  270. package/dist/types/media-viewer/media-viewer-bar.d.ts +3 -1
  271. package/dist/types/media-viewer/media-viewer-bar.d.ts.map +1 -1
  272. package/dist/types/media-viewer/media-viewer.types.d.ts +1 -0
  273. package/dist/types/media-viewer/media-viewer.types.d.ts.map +1 -1
  274. package/dist/types/message/message-parts.d.ts +7 -0
  275. package/dist/types/message/message-parts.d.ts.map +1 -1
  276. package/dist/types/message/message.d.ts.map +1 -1
  277. package/dist/types/page-header/page-header-parts.d.ts.map +1 -1
  278. package/dist/types/section/section-parts.d.ts +16 -8
  279. package/dist/types/section/section-parts.d.ts.map +1 -1
  280. package/dist/types/section/section.d.ts.map +1 -1
  281. package/dist/types/segmented-control/segmented-control-parts.d.ts.map +1 -1
  282. package/dist/types/side-navigation/side-navigation-parts.d.ts.map +1 -1
  283. package/dist/types/stat-card/stat-card-delta.d.ts.map +1 -1
  284. package/dist/types/stat-card/stat-card-parts.d.ts +3 -3
  285. package/dist/types/stat-card/stat-card-parts.d.ts.map +1 -1
  286. package/dist/types/stepper/stepper-parts.d.ts +11 -2
  287. package/dist/types/stepper/stepper-parts.d.ts.map +1 -1
  288. package/dist/types/stepper/stepper.d.ts.map +1 -1
  289. package/dist/types/timeline/timeline-parts.d.ts.map +1 -1
  290. package/dist/types/top-navigation/top-navigation.d.ts.map +1 -1
  291. package/dist/{wizard-4c0X7Bx_.js → wizard-Dfryz1id.js} +214 -214
  292. package/dist/wizard.js +1 -1
  293. package/package.json +6 -6
  294. package/dist/attachment-MqczA38F.js +0 -292
  295. package/dist/detail-panel-EImAtksY.js +0 -327
  296. package/dist/message-D1Dd6Y2k.js +0 -452
  297. package/dist/section-D_qOfdxR.js +0 -213
  298. package/dist/top-navigation-D8IHPOmm.js +0 -744
@@ -0,0 +1,1108 @@
1
+ <!-- index: ./index.md -->
2
+ # saved-views
3
+
4
+ `data-ui="saved-views"` · Named, saved sets of filters for a list.
5
+
6
+ ## Examples
7
+
8
+ ### Playground
9
+
10
+ Open the trigger and apply My region: the line below changes to the view that was handed over. Press Sort by total to make the view in use differ from its saved form.
11
+
12
+ Excerpt — not a complete module
13
+
14
+ ```tsx
15
+ <SavedViews
16
+ builtIn={defaults}
17
+ columns={columns}
18
+ current={current}
19
+ defaultState={views}
20
+ onViewApply={(view) => setCurrent(view)}
21
+ />;
22
+ ```
23
+
24
+ ### Modified, and Revert
25
+
26
+ The view in use differs from Late orders by its sort: the trigger carries the dot and the word, Revert sits beside it, and Save in the panel is enabled. Revert hands the saved view back through onViewApply.
27
+
28
+ Excerpt — not a complete module
29
+
30
+ ```tsx
31
+ <SavedViews
32
+ builtIn={defaults}
33
+ current={{ ...late, query: { ...late.query, sort: byTotal } }}
34
+ defaultState={views}
35
+ onViewApply={(view, request) => {
36
+ if (request.action === 'revert') setCurrent(view);
37
+ }}
38
+ />;
39
+ ```
40
+
41
+ ### Save as a new view
42
+
43
+ Save as new view… opens a named field above the footer. An empty name and a name another view has — case aside, Default included — mark the field invalid with its message; a valid one creates the view from the current one and makes it the view in use.
44
+
45
+ Example
46
+
47
+ ```tsx
48
+ import {
49
+ emptyGridView,
50
+ serializeGridView,
51
+ type GridView,
52
+ type SavedViewsState,
53
+ } from '@slotted/core/grid';
54
+ import { Button } from '@slotted/react/button';
55
+ import { Inline } from '@slotted/react/inline';
56
+ import { SavedViews } from '@slotted/react/saved-views';
57
+ import { Stack } from '@slotted/react/stack';
58
+ import { Text } from '@slotted/react/typography';
59
+ import { useState } from 'react';
60
+
61
+ const builtIn: GridView = {
62
+ ...emptyGridView(),
63
+ query: { ...emptyGridView().query, sort: [{ column: 'id', direction: 'ascending' }] },
64
+ };
65
+
66
+ const late: GridView = {
67
+ ...builtIn,
68
+ query: { ...builtIn.query, search: 'Late', sort: [{ column: 'due', direction: 'ascending' }] },
69
+ };
70
+
71
+ const midwest: GridView = {
72
+ ...builtIn,
73
+ query: { ...builtIn.query, search: 'Midwest' },
74
+ };
75
+
76
+ const highValue: GridView = {
77
+ ...builtIn,
78
+ density: 'compact',
79
+ query: { ...builtIn.query, sort: [{ column: 'total', direction: 'descending' }] },
80
+ };
81
+
82
+ const views: SavedViewsState = {
83
+ views: [
84
+ { id: 'late', name: 'Late orders', view: serializeGridView(late) },
85
+ { id: 'midwest', name: 'Midwest accounts', view: serializeGridView(midwest) },
86
+ { id: 'high', name: 'High value', view: serializeGridView(highValue) },
87
+ ],
88
+ defaultId: null,
89
+ activeId: 'late',
90
+ };
91
+
92
+ function sortedByTotal(view: GridView): GridView {
93
+ return {
94
+ ...view,
95
+ query: { ...view.query, sort: [{ column: 'total', direction: 'descending' }] },
96
+ };
97
+ }
98
+
99
+ export default function SavedViewsSaveAs() {
100
+ const [current, setCurrent] = useState(sortedByTotal(late));
101
+ const [names, setNames] = useState(views.views.map((view) => view.name));
102
+
103
+ return (
104
+ <Stack gap={4}>
105
+ <Inline gap={3}>
106
+ <SavedViews
107
+ builtIn={builtIn}
108
+ current={current}
109
+ defaultState={views}
110
+ onStateChange={(state) => setNames(state.views.map((view) => view.name))}
111
+ onViewApply={(view) => setCurrent(view)}
112
+ />
113
+ <Button
114
+ onClick={() => setCurrent(sortedByTotal(current))}
115
+ size="sm"
116
+ tone="secondary"
117
+ variant="outline"
118
+ >
119
+ Sort by total
120
+ </Button>
121
+ </Inline>
122
+ <Text size="sm" tone="muted">
123
+ Views: {names.join(', ')}
124
+ </Text>
125
+ </Stack>
126
+ );
127
+ }
128
+ ```
129
+
130
+ ### Rename in the row
131
+
132
+ The row’s menu, then Rename: the row becomes the form holding the name, Enter submits with the reason submit and focus returns to the renamed row. Escape cancels the form and leaves the panel open.
133
+
134
+ Example
135
+
136
+ ```tsx
137
+ import {
138
+ emptyGridView,
139
+ serializeGridView,
140
+ type GridView,
141
+ type SavedViewsState,
142
+ } from '@slotted/core/grid';
143
+ import { Button } from '@slotted/react/button';
144
+ import { Inline } from '@slotted/react/inline';
145
+ import { SavedViews } from '@slotted/react/saved-views';
146
+ import { Stack } from '@slotted/react/stack';
147
+ import { Text } from '@slotted/react/typography';
148
+ import { useState } from 'react';
149
+
150
+ const builtIn: GridView = {
151
+ ...emptyGridView(),
152
+ query: { ...emptyGridView().query, sort: [{ column: 'id', direction: 'ascending' }] },
153
+ };
154
+
155
+ const late: GridView = {
156
+ ...builtIn,
157
+ query: { ...builtIn.query, search: 'Late', sort: [{ column: 'due', direction: 'ascending' }] },
158
+ };
159
+
160
+ const midwest: GridView = {
161
+ ...builtIn,
162
+ query: { ...builtIn.query, search: 'Midwest' },
163
+ };
164
+
165
+ const highValue: GridView = {
166
+ ...builtIn,
167
+ density: 'compact',
168
+ query: { ...builtIn.query, sort: [{ column: 'total', direction: 'descending' }] },
169
+ };
170
+
171
+ const views: SavedViewsState = {
172
+ views: [
173
+ { id: 'late', name: 'Late orders', view: serializeGridView(late) },
174
+ { id: 'midwest', name: 'Midwest accounts', view: serializeGridView(midwest) },
175
+ { id: 'high', name: 'High value', view: serializeGridView(highValue) },
176
+ ],
177
+ defaultId: null,
178
+ activeId: 'late',
179
+ };
180
+
181
+ function sortedByTotal(view: GridView): GridView {
182
+ return {
183
+ ...view,
184
+ query: { ...view.query, sort: [{ column: 'total', direction: 'descending' }] },
185
+ };
186
+ }
187
+
188
+ export default function SavedViewsRename() {
189
+ const [current, setCurrent] = useState(late);
190
+ const [last, setLast] = useState('none');
191
+
192
+ return (
193
+ <Stack gap={4}>
194
+ <Inline gap={3}>
195
+ <SavedViews
196
+ builtIn={builtIn}
197
+ current={current}
198
+ defaultState={views}
199
+ onStateChange={(_, request) => setLast(`${request.action} · ${request.reason}`)}
200
+ onViewApply={(view) => setCurrent(view)}
201
+ />
202
+ <Button
203
+ onClick={() => setCurrent(sortedByTotal(current))}
204
+ size="sm"
205
+ tone="secondary"
206
+ variant="outline"
207
+ >
208
+ Sort by total
209
+ </Button>
210
+ </Inline>
211
+ <Text size="sm" tone="muted">
212
+ Last request: {last}
213
+ </Text>
214
+ </Stack>
215
+ );
216
+ }
217
+ ```
218
+
219
+ ### Delete, confirmed in the row
220
+
221
+ Delete asks in place, naming the view, with focus on Cancel. Confirming carries the reason remove. Deleting the view in use leaves the built-in view in its place, and the grid keeps its arrangement — which then reads as modified.
222
+
223
+ Example
224
+
225
+ ```tsx
226
+ import {
227
+ emptyGridView,
228
+ serializeGridView,
229
+ type GridView,
230
+ type SavedViewsState,
231
+ } from '@slotted/core/grid';
232
+ import { Button } from '@slotted/react/button';
233
+ import { Inline } from '@slotted/react/inline';
234
+ import { SavedViews } from '@slotted/react/saved-views';
235
+ import { Stack } from '@slotted/react/stack';
236
+ import { Text } from '@slotted/react/typography';
237
+ import { useState } from 'react';
238
+
239
+ const builtIn: GridView = {
240
+ ...emptyGridView(),
241
+ query: { ...emptyGridView().query, sort: [{ column: 'id', direction: 'ascending' }] },
242
+ };
243
+
244
+ const late: GridView = {
245
+ ...builtIn,
246
+ query: { ...builtIn.query, search: 'Late', sort: [{ column: 'due', direction: 'ascending' }] },
247
+ };
248
+
249
+ const midwest: GridView = {
250
+ ...builtIn,
251
+ query: { ...builtIn.query, search: 'Midwest' },
252
+ };
253
+
254
+ const highValue: GridView = {
255
+ ...builtIn,
256
+ density: 'compact',
257
+ query: { ...builtIn.query, sort: [{ column: 'total', direction: 'descending' }] },
258
+ };
259
+
260
+ const views: SavedViewsState = {
261
+ views: [
262
+ { id: 'late', name: 'Late orders', view: serializeGridView(late) },
263
+ { id: 'midwest', name: 'Midwest accounts', view: serializeGridView(midwest) },
264
+ { id: 'high', name: 'High value', view: serializeGridView(highValue) },
265
+ ],
266
+ defaultId: null,
267
+ activeId: 'late',
268
+ };
269
+
270
+ function sortedByTotal(view: GridView): GridView {
271
+ return {
272
+ ...view,
273
+ query: { ...view.query, sort: [{ column: 'total', direction: 'descending' }] },
274
+ };
275
+ }
276
+
277
+ export default function SavedViewsDelete() {
278
+ const [current, setCurrent] = useState(late);
279
+ const [names, setNames] = useState(views.views.map((view) => view.name));
280
+
281
+ return (
282
+ <Stack gap={4}>
283
+ <Inline gap={3}>
284
+ <SavedViews
285
+ builtIn={builtIn}
286
+ current={current}
287
+ defaultState={views}
288
+ onStateChange={(state) => setNames(state.views.map((view) => view.name))}
289
+ onViewApply={(view) => setCurrent(view)}
290
+ />
291
+ <Button
292
+ onClick={() => setCurrent(sortedByTotal(current))}
293
+ size="sm"
294
+ tone="secondary"
295
+ variant="outline"
296
+ >
297
+ Sort by total
298
+ </Button>
299
+ </Inline>
300
+ <Text size="sm" tone="muted">
301
+ Views: {names.join(', ')}
302
+ </Text>
303
+ </Stack>
304
+ );
305
+ }
306
+ ```
307
+
308
+ ### The default view
309
+
310
+ Set as default moves the pin: that view is the one a visit opens on. With usePersistedSavedViews, a visit whose store holds no view in use opens on the default and hands it over once as openedDefault.
311
+
312
+ Example
313
+
314
+ ```tsx
315
+ import {
316
+ emptyGridView,
317
+ serializeGridView,
318
+ type GridView,
319
+ type SavedViewsState,
320
+ } from '@slotted/core/grid';
321
+ import { SavedViews } from '@slotted/react/saved-views';
322
+ import { Stack } from '@slotted/react/stack';
323
+ import { Text } from '@slotted/react/typography';
324
+ import { useState } from 'react';
325
+
326
+ const builtIn: GridView = {
327
+ ...emptyGridView(),
328
+ query: { ...emptyGridView().query, sort: [{ column: 'id', direction: 'ascending' }] },
329
+ };
330
+
331
+ const late: GridView = {
332
+ ...builtIn,
333
+ query: { ...builtIn.query, search: 'Late', sort: [{ column: 'due', direction: 'ascending' }] },
334
+ };
335
+
336
+ const midwest: GridView = {
337
+ ...builtIn,
338
+ query: { ...builtIn.query, search: 'Midwest' },
339
+ };
340
+
341
+ const highValue: GridView = {
342
+ ...builtIn,
343
+ density: 'compact',
344
+ query: { ...builtIn.query, sort: [{ column: 'total', direction: 'descending' }] },
345
+ };
346
+
347
+ const views: SavedViewsState = {
348
+ views: [
349
+ { id: 'late', name: 'Late orders', view: serializeGridView(late) },
350
+ { id: 'midwest', name: 'Midwest accounts', view: serializeGridView(midwest) },
351
+ { id: 'high', name: 'High value', view: serializeGridView(highValue) },
352
+ ],
353
+ defaultId: null,
354
+ activeId: 'late',
355
+ };
356
+
357
+ function opensOn(state: SavedViewsState): string {
358
+ return state.views.find((view) => view.id === state.defaultId)?.name ?? 'Default';
359
+ }
360
+
361
+ export default function SavedViewsDefaultView() {
362
+ const [current, setCurrent] = useState(late);
363
+ const [opens, setOpens] = useState('High value');
364
+
365
+ return (
366
+ <Stack gap={4}>
367
+ <SavedViews
368
+ builtIn={builtIn}
369
+ current={current}
370
+ defaultState={{ ...views, defaultId: 'high' }}
371
+ onStateChange={(state) => setOpens(opensOn(state))}
372
+ onViewApply={(view) => setCurrent(view)}
373
+ />
374
+ <Text size="sm" tone="muted">
375
+ A visit opens on: {opens}
376
+ </Text>
377
+ </Stack>
378
+ );
379
+ }
380
+ ```
381
+
382
+ ### The built-in view
383
+
384
+ Default is the application’s own arrangement: first in the list, never renamed, overwritten or deleted, and its menu holds Set as default alone. On it Save is disabled; Save as new view… is how a reader keeps a change.
385
+
386
+ Example
387
+
388
+ ```tsx
389
+ import {
390
+ emptyGridView,
391
+ serializeGridView,
392
+ type GridView,
393
+ type SavedViewsState,
394
+ } from '@slotted/core/grid';
395
+ import { Button } from '@slotted/react/button';
396
+ import { Inline } from '@slotted/react/inline';
397
+ import { SavedViews } from '@slotted/react/saved-views';
398
+ import { Stack } from '@slotted/react/stack';
399
+ import { TextField } from '@slotted/react/text-field';
400
+ import { useState } from 'react';
401
+
402
+ const builtIn: GridView = {
403
+ ...emptyGridView(),
404
+ query: { ...emptyGridView().query, sort: [{ column: 'id', direction: 'ascending' }] },
405
+ };
406
+
407
+ const late: GridView = {
408
+ ...builtIn,
409
+ query: { ...builtIn.query, search: 'Late', sort: [{ column: 'due', direction: 'ascending' }] },
410
+ };
411
+
412
+ const midwest: GridView = {
413
+ ...builtIn,
414
+ query: { ...builtIn.query, search: 'Midwest' },
415
+ };
416
+
417
+ const highValue: GridView = {
418
+ ...builtIn,
419
+ density: 'compact',
420
+ query: { ...builtIn.query, sort: [{ column: 'total', direction: 'descending' }] },
421
+ };
422
+
423
+ const views: SavedViewsState = {
424
+ views: [
425
+ { id: 'late', name: 'Late orders', view: serializeGridView(late) },
426
+ { id: 'midwest', name: 'Midwest accounts', view: serializeGridView(midwest) },
427
+ { id: 'high', name: 'High value', view: serializeGridView(highValue) },
428
+ ],
429
+ defaultId: null,
430
+ activeId: 'late',
431
+ };
432
+
433
+ function sortedByTotal(view: GridView): GridView {
434
+ return {
435
+ ...view,
436
+ query: { ...view.query, sort: [{ column: 'total', direction: 'descending' }] },
437
+ };
438
+ }
439
+
440
+ export default function SavedViewsBuiltIn() {
441
+ const [current, setCurrent] = useState(builtIn);
442
+
443
+ return (
444
+ <Stack gap={4}>
445
+ <Inline gap={3}>
446
+ <SavedViews
447
+ builtIn={builtIn}
448
+ current={current}
449
+ defaultState={{ ...views, activeId: null }}
450
+ messages={{ builtIn: 'Standard layout', label: 'Order views' }}
451
+ onViewApply={(view) => setCurrent(view)}
452
+ />
453
+ <Button
454
+ onClick={() => setCurrent(sortedByTotal(current))}
455
+ size="sm"
456
+ tone="secondary"
457
+ variant="outline"
458
+ >
459
+ Sort by total
460
+ </Button>
461
+ </Inline>
462
+ <TextField
463
+ aria-label="The view in use, as it is kept"
464
+ mono
465
+ readOnly
466
+ value={serializeGridView(current)}
467
+ />
468
+ </Stack>
469
+ );
470
+ }
471
+ ```
472
+
473
+ ### Kept across visits
474
+
475
+ usePersistedSavedViews reads the store once with parseSavedViews — total, so a malformed entry is no views — and writes serializeSavedViews after each change. The line shows the entry as it is written. A store that throws leaves the views in memory.
476
+
477
+ Example
478
+
479
+ ```tsx
480
+ import {
481
+ emptyGridView,
482
+ serializeGridView,
483
+ serializeSavedViews,
484
+ type GridView,
485
+ type GridViewStorage,
486
+ type SavedViewsState,
487
+ } from '@slotted/core/grid';
488
+ import { Button } from '@slotted/react/button';
489
+ import { Inline } from '@slotted/react/inline';
490
+ import { SavedViews, usePersistedSavedViews } from '@slotted/react/saved-views';
491
+ import { Stack } from '@slotted/react/stack';
492
+ import { TextField } from '@slotted/react/text-field';
493
+ import { useState } from 'react';
494
+
495
+ const builtIn: GridView = {
496
+ ...emptyGridView(),
497
+ query: { ...emptyGridView().query, sort: [{ column: 'id', direction: 'ascending' }] },
498
+ };
499
+
500
+ const late: GridView = {
501
+ ...builtIn,
502
+ query: { ...builtIn.query, search: 'Late', sort: [{ column: 'due', direction: 'ascending' }] },
503
+ };
504
+
505
+ const midwest: GridView = {
506
+ ...builtIn,
507
+ query: { ...builtIn.query, search: 'Midwest' },
508
+ };
509
+
510
+ const highValue: GridView = {
511
+ ...builtIn,
512
+ density: 'compact',
513
+ query: { ...builtIn.query, sort: [{ column: 'total', direction: 'descending' }] },
514
+ };
515
+
516
+ const views: SavedViewsState = {
517
+ views: [
518
+ { id: 'late', name: 'Late orders', view: serializeGridView(late) },
519
+ { id: 'midwest', name: 'Midwest accounts', view: serializeGridView(midwest) },
520
+ { id: 'high', name: 'High value', view: serializeGridView(highValue) },
521
+ ],
522
+ defaultId: null,
523
+ activeId: 'late',
524
+ };
525
+
526
+ function sortedByTotal(view: GridView): GridView {
527
+ return {
528
+ ...view,
529
+ query: { ...view.query, sort: [{ column: 'total', direction: 'descending' }] },
530
+ };
531
+ }
532
+
533
+ export default function SavedViewsPersistence() {
534
+ const [current, setCurrent] = useState(sortedByTotal(late));
535
+ const [entry, setEntry] = useState(serializeSavedViews(views));
536
+ const [storage] = useState<GridViewStorage>(() => ({
537
+ getItem: () => serializeSavedViews(views),
538
+ setItem: (_key, value) => setEntry(value),
539
+ removeItem: () => setEntry(''),
540
+ }));
541
+ const persisted = usePersistedSavedViews({ key: 'orders:views', storage });
542
+
543
+ return (
544
+ <Stack gap={4}>
545
+ <Inline gap={3}>
546
+ <SavedViews
547
+ builtIn={builtIn}
548
+ current={current}
549
+ onStateChange={persisted.onStateChange}
550
+ onViewApply={(view) => setCurrent(view)}
551
+ state={persisted.state}
552
+ />
553
+ <Button
554
+ onClick={() => setCurrent(sortedByTotal(current))}
555
+ size="sm"
556
+ tone="secondary"
557
+ variant="outline"
558
+ >
559
+ Sort by total
560
+ </Button>
561
+ </Inline>
562
+ <TextField aria-label="The stored entry" mono readOnly value={entry} />
563
+ </Stack>
564
+ );
565
+ }
566
+ ```
567
+
568
+ ### Over a data grid
569
+
570
+ SavedViews above a DataGrid bound through usePersistedGridView: the store opens on Late orders, the default. Sort a column, hide one or change the search, and the trigger says Modified; apply High value and the grid takes its sort and its compact density.
571
+
572
+ Example
573
+
574
+ ```tsx
575
+ import {
576
+ emptyGridView,
577
+ serializeGridView,
578
+ serializeSavedViews,
579
+ type GridColumn,
580
+ type GridView,
581
+ type GridViewStorage,
582
+ type SavedViewsState,
583
+ } from '@slotted/core/grid';
584
+ import { DataGrid, usePersistedGridView } from '@slotted/react/data-grid';
585
+ import { SavedViews, usePersistedSavedViews } from '@slotted/react/saved-views';
586
+ import { Stack } from '@slotted/react/stack';
587
+ import { useState } from 'react';
588
+
589
+ const builtIn: GridView = {
590
+ ...emptyGridView(),
591
+ query: { ...emptyGridView().query, sort: [{ column: 'id', direction: 'ascending' }] },
592
+ };
593
+
594
+ const late: GridView = {
595
+ ...builtIn,
596
+ query: { ...builtIn.query, search: 'Late', sort: [{ column: 'due', direction: 'ascending' }] },
597
+ };
598
+
599
+ const midwest: GridView = {
600
+ ...builtIn,
601
+ query: { ...builtIn.query, search: 'Midwest' },
602
+ };
603
+
604
+ const highValue: GridView = {
605
+ ...builtIn,
606
+ density: 'compact',
607
+ query: { ...builtIn.query, sort: [{ column: 'total', direction: 'descending' }] },
608
+ };
609
+
610
+ const views: SavedViewsState = {
611
+ views: [
612
+ { id: 'late', name: 'Late orders', view: serializeGridView(late) },
613
+ { id: 'midwest', name: 'Midwest accounts', view: serializeGridView(midwest) },
614
+ { id: 'high', name: 'High value', view: serializeGridView(highValue) },
615
+ ],
616
+ defaultId: null,
617
+ activeId: 'late',
618
+ };
619
+
620
+ interface Order {
621
+ id: string;
622
+ customer: string;
623
+ region: string;
624
+ status: string;
625
+ total: number;
626
+ due: string;
627
+ }
628
+
629
+ const orders: Order[] = [
630
+ {
631
+ id: 'SO-2026-01842',
632
+ customer: 'Northwind Fabrication',
633
+ region: 'Midwest',
634
+ status: 'Late',
635
+ total: 12480,
636
+ due: '2026-09-15',
637
+ },
638
+ {
639
+ id: 'SO-2026-01843',
640
+ customer: 'Helios Automation GmbH',
641
+ region: 'Europe',
642
+ status: 'Open',
643
+ total: 4120,
644
+ due: '2026-09-28',
645
+ },
646
+ {
647
+ id: 'SO-2026-01844',
648
+ customer: 'Meridian Controls Group',
649
+ region: 'Midwest',
650
+ status: 'Open',
651
+ total: 18900,
652
+ due: '2026-10-02',
653
+ },
654
+ {
655
+ id: 'SO-2026-01845',
656
+ customer: 'Aurora Textiles',
657
+ region: 'Northeast',
658
+ status: 'Late',
659
+ total: 2310,
660
+ due: '2026-09-12',
661
+ },
662
+ {
663
+ id: 'SO-2026-01846',
664
+ customer: 'Columbus Tool & Die',
665
+ region: 'Midwest',
666
+ status: 'Shipped',
667
+ total: 7640,
668
+ due: '2026-09-20',
669
+ },
670
+ {
671
+ id: 'SO-2026-01847',
672
+ customer: 'Pacific Rim Logistics',
673
+ region: 'West',
674
+ status: 'Late',
675
+ total: 31200,
676
+ due: '2026-09-18',
677
+ },
678
+ {
679
+ id: 'SO-2026-01848',
680
+ customer: 'Blue Ridge Components',
681
+ region: 'Southeast',
682
+ status: 'Open',
683
+ total: 960,
684
+ due: '2026-10-06',
685
+ },
686
+ {
687
+ id: 'SO-2026-01849',
688
+ customer: 'Great Lakes Hydraulics',
689
+ region: 'Midwest',
690
+ status: 'Late',
691
+ total: 15325,
692
+ due: '2026-09-10',
693
+ },
694
+ ];
695
+
696
+ const USD = new Intl.NumberFormat('en-US', { currency: 'USD', style: 'currency' });
697
+
698
+ const columns: GridColumn<Order>[] = [
699
+ { id: 'id', label: 'Order', accessor: 'id', rowHeader: true, width: 150, sortable: true },
700
+ { id: 'customer', label: 'Customer', accessor: 'customer', width: 220, sortable: true },
701
+ { id: 'region', label: 'Region', accessor: 'region', width: 130, sortable: true },
702
+ { id: 'status', label: 'Status', accessor: 'status', width: 110, sortable: true },
703
+ {
704
+ id: 'total',
705
+ label: 'Total',
706
+ accessor: 'total',
707
+ numeric: true,
708
+ width: 120,
709
+ sortable: true,
710
+ format: (value) => USD.format(value as number),
711
+ },
712
+ { id: 'due', label: 'Due', accessor: 'due', kind: 'date', width: 130, sortable: true },
713
+ ];
714
+
715
+ export default function SavedViewsWithDataGrid() {
716
+ const [storage] = useState<GridViewStorage>(() => {
717
+ const held: Record<string, string> = {
718
+ 'orders:views': serializeSavedViews({ ...views, activeId: null, defaultId: 'late' }),
719
+ };
720
+
721
+ return {
722
+ getItem: (key) => held[key] ?? null,
723
+ setItem: (key, value) => {
724
+ held[key] = value;
725
+ },
726
+ removeItem: (key) => {
727
+ delete held[key];
728
+ },
729
+ };
730
+ });
731
+ const saved = usePersistedSavedViews({ key: 'orders:views', storage, columns });
732
+ const opened = saved.openedDefault ?? builtIn;
733
+ const grid = usePersistedGridView({
734
+ key: 'orders:grid',
735
+ columns,
736
+ storage,
737
+ defaultQuery: opened.query,
738
+ defaultColumnState: opened.columns,
739
+ defaultDensity: opened.density,
740
+ });
741
+ const current: GridView = { columns: grid.columnState, query: grid.query, density: grid.density };
742
+
743
+ return (
744
+ <Stack gap={4}>
745
+ <SavedViews
746
+ builtIn={builtIn}
747
+ columns={columns}
748
+ current={current}
749
+ onStateChange={saved.onStateChange}
750
+ onViewApply={(view) => grid.setView(view)}
751
+ state={saved.state}
752
+ />
753
+ <DataGrid
754
+ aria-label="Orders"
755
+ columnState={grid.columnState}
756
+ columns={columns}
757
+ density={grid.density}
758
+ height="22rem"
759
+ onColumnStateChange={grid.onColumnStateChange}
760
+ onQueryChange={grid.onQueryChange}
761
+ query={grid.query}
762
+ rowKey="id"
763
+ rows={orders}
764
+ />
765
+ </Stack>
766
+ );
767
+ }
768
+ ```
769
+
770
+ ### Keyboard
771
+
772
+ Tab to the trigger and press Enter: focus lands on the view in use. Tab walks apply and actions row by row, then the footer. In a form Enter submits and Escape cancels the form without closing the panel; a second Escape closes it and focus returns to the trigger.
773
+
774
+ Excerpt — not a complete module
775
+
776
+ ```tsx
777
+ const views = useRef<SavedViewsHandle>(null);
778
+
779
+ useHotkey('Mod+Shift+V', () => views.current?.open());
780
+ ```
781
+
782
+ ### What a reader hears
783
+
784
+ The root is a group named Views; the trigger says the view and Modified; the view in use carries aria-current; the default reads “default” after its name. Applying, saving, renaming, deleting and moving the default are announced politely.
785
+
786
+ Excerpt — not a complete module
787
+
788
+ ```tsx
789
+ <SavedViews aria-label="Order views" builtIn={defaults} current={current} />;
790
+ ```
791
+
792
+ ### Long names
793
+
794
+ A name longer than the trigger is cut with an ellipsis there, with the whole name in title and in the accessible name; in the list it wraps, and a single unbroken reference breaks anywhere rather than pushing the actions out of the row.
795
+
796
+ Example
797
+
798
+ ```tsx
799
+ import {
800
+ emptyGridView,
801
+ serializeGridView,
802
+ type GridView,
803
+ type SavedViewsState,
804
+ } from '@slotted/core/grid';
805
+ import { SavedViews } from '@slotted/react/saved-views';
806
+
807
+ const builtIn: GridView = {
808
+ ...emptyGridView(),
809
+ query: { ...emptyGridView().query, sort: [{ column: 'id', direction: 'ascending' }] },
810
+ };
811
+
812
+ const late: GridView = {
813
+ ...builtIn,
814
+ query: { ...builtIn.query, search: 'Late', sort: [{ column: 'due', direction: 'ascending' }] },
815
+ };
816
+
817
+ const highValue: GridView = {
818
+ ...builtIn,
819
+ density: 'compact',
820
+ query: { ...builtIn.query, sort: [{ column: 'total', direction: 'descending' }] },
821
+ };
822
+
823
+ const longNames: SavedViewsState = {
824
+ views: [
825
+ {
826
+ id: 'midwest',
827
+ name: 'Late orders from the Midwest distributors awaiting carrier confirmation',
828
+ view: serializeGridView(late),
829
+ },
830
+ {
831
+ id: 'reference',
832
+ name: 'SO-2026-Q3-HELIOS-AUTOMATION-GMBH-PREPAID-OVER-10000-USD',
833
+ view: serializeGridView(highValue),
834
+ },
835
+ ],
836
+ defaultId: 'midwest',
837
+ activeId: 'midwest',
838
+ };
839
+
840
+ export default function SavedViewsLongNames() {
841
+ return <SavedViews builtIn={builtIn} current={late} defaultState={longNames} />;
842
+ }
843
+ ```
844
+
845
+ ### controlled.tsx
846
+
847
+ Example
848
+
849
+ ```tsx
850
+ import {
851
+ emptyGridView,
852
+ serializeGridView,
853
+ type GridView,
854
+ type SavedViewsState,
855
+ } from '@slotted/core/grid';
856
+ import { SavedViews, type SavedViewsRequest } from '@slotted/react/saved-views';
857
+ import { Stack } from '@slotted/react/stack';
858
+ import { Text } from '@slotted/react/typography';
859
+ import { useState } from 'react';
860
+
861
+ const builtIn: GridView = {
862
+ ...emptyGridView(),
863
+ query: { ...emptyGridView().query, sort: [{ column: 'id', direction: 'ascending' }] },
864
+ };
865
+
866
+ const late: GridView = {
867
+ ...builtIn,
868
+ query: { ...builtIn.query, search: 'Late', sort: [{ column: 'due', direction: 'ascending' }] },
869
+ };
870
+
871
+ const midwest: GridView = {
872
+ ...builtIn,
873
+ query: { ...builtIn.query, search: 'Midwest' },
874
+ };
875
+
876
+ const highValue: GridView = {
877
+ ...builtIn,
878
+ density: 'compact',
879
+ query: { ...builtIn.query, sort: [{ column: 'total', direction: 'descending' }] },
880
+ };
881
+
882
+ const views: SavedViewsState = {
883
+ views: [
884
+ { id: 'late', name: 'Late orders', view: serializeGridView(late) },
885
+ { id: 'midwest', name: 'Midwest accounts', view: serializeGridView(midwest) },
886
+ { id: 'high', name: 'High value', view: serializeGridView(highValue) },
887
+ ],
888
+ defaultId: null,
889
+ activeId: 'late',
890
+ };
891
+
892
+ export default function SavedViewsControlled() {
893
+ const [state, setState] = useState(views);
894
+ const [open, setOpen] = useState(false);
895
+ const [notice, setNotice] = useState(
896
+ 'Late orders is shared with the team and cannot be deleted.',
897
+ );
898
+
899
+ function handleStateChange(next: SavedViewsState, request: SavedViewsRequest) {
900
+ const removesShared =
901
+ request.action === 'delete' && next.views.every((view) => view.id !== 'late');
902
+ if (removesShared) {
903
+ request.cancel();
904
+ setNotice('The delete was refused: Late orders is shared with the team.');
905
+ return;
906
+ }
907
+
908
+ setState(next);
909
+ }
910
+
911
+ return (
912
+ <Stack gap={4}>
913
+ <SavedViews
914
+ builtIn={builtIn}
915
+ current={late}
916
+ onOpenChange={(next) => setOpen(next)}
917
+ onStateChange={handleStateChange}
918
+ open={open}
919
+ state={state}
920
+ />
921
+ <Text size="sm" tone="muted">
922
+ Layer: {open ? 'open' : 'closed'}. Views: {state.views.length}.
923
+ </Text>
924
+ <Text size="sm" tone="muted">
925
+ {notice}
926
+ </Text>
927
+ </Stack>
928
+ );
929
+ }
930
+ ```
931
+
932
+ ### handle.tsx
933
+
934
+ Example
935
+
936
+ ```tsx
937
+ import {
938
+ emptyGridView,
939
+ serializeGridView,
940
+ type GridView,
941
+ type SavedViewsState,
942
+ } from '@slotted/core/grid';
943
+ import { Button } from '@slotted/react/button';
944
+ import { Inline } from '@slotted/react/inline';
945
+ import { SavedViews, type SavedViewsHandle } from '@slotted/react/saved-views';
946
+ import { Stack } from '@slotted/react/stack';
947
+ import { Text } from '@slotted/react/typography';
948
+ import { useRef, useState } from 'react';
949
+
950
+ const builtIn: GridView = {
951
+ ...emptyGridView(),
952
+ query: { ...emptyGridView().query, sort: [{ column: 'id', direction: 'ascending' }] },
953
+ };
954
+
955
+ const late: GridView = {
956
+ ...builtIn,
957
+ query: { ...builtIn.query, search: 'Late', sort: [{ column: 'due', direction: 'ascending' }] },
958
+ };
959
+
960
+ const midwest: GridView = {
961
+ ...builtIn,
962
+ query: { ...builtIn.query, search: 'Midwest' },
963
+ };
964
+
965
+ const highValue: GridView = {
966
+ ...builtIn,
967
+ density: 'compact',
968
+ query: { ...builtIn.query, sort: [{ column: 'total', direction: 'descending' }] },
969
+ };
970
+
971
+ const views: SavedViewsState = {
972
+ views: [
973
+ { id: 'late', name: 'Late orders', view: serializeGridView(late) },
974
+ { id: 'midwest', name: 'Midwest accounts', view: serializeGridView(midwest) },
975
+ { id: 'high', name: 'High value', view: serializeGridView(highValue) },
976
+ ],
977
+ defaultId: null,
978
+ activeId: 'late',
979
+ };
980
+
981
+ export default function SavedViewsHandleExample() {
982
+ const [current, setCurrent] = useState(late);
983
+ const [applied, setApplied] = useState('none');
984
+ const handle = useRef<SavedViewsHandle>(null);
985
+
986
+ return (
987
+ <Stack gap={4}>
988
+ <Inline gap={3}>
989
+ <SavedViews
990
+ ref={handle}
991
+ builtIn={builtIn}
992
+ current={current}
993
+ defaultState={views}
994
+ onViewApply={(view, request) => {
995
+ setCurrent(view);
996
+ setApplied(`${request.action} · ${request.reason}`);
997
+ }}
998
+ />
999
+ <Button onClick={() => handle.current?.open()} size="sm" tone="secondary" variant="outline">
1000
+ Open the views
1001
+ </Button>
1002
+ <Button
1003
+ onClick={() => handle.current?.apply('high')}
1004
+ size="sm"
1005
+ tone="secondary"
1006
+ variant="outline"
1007
+ >
1008
+ Apply High value
1009
+ </Button>
1010
+ </Inline>
1011
+ <Text size="sm" tone="muted">
1012
+ Last applied: {applied}
1013
+ </Text>
1014
+ </Stack>
1015
+ );
1016
+ }
1017
+ ```
1018
+
1019
+ ### modified.tsx
1020
+
1021
+ Example
1022
+
1023
+ ```tsx
1024
+ import {
1025
+ emptyGridView,
1026
+ serializeGridView,
1027
+ type GridView,
1028
+ type SavedViewsState,
1029
+ } from '@slotted/core/grid';
1030
+ import { Button } from '@slotted/react/button';
1031
+ import { Inline } from '@slotted/react/inline';
1032
+ import { SavedViews, type SavedViewsRequest } from '@slotted/react/saved-views';
1033
+ import { Stack } from '@slotted/react/stack';
1034
+ import { Text } from '@slotted/react/typography';
1035
+ import { useState } from 'react';
1036
+
1037
+ const builtIn: GridView = {
1038
+ ...emptyGridView(),
1039
+ query: { ...emptyGridView().query, sort: [{ column: 'id', direction: 'ascending' }] },
1040
+ };
1041
+
1042
+ const late: GridView = {
1043
+ ...builtIn,
1044
+ query: { ...builtIn.query, search: 'Late', sort: [{ column: 'due', direction: 'ascending' }] },
1045
+ };
1046
+
1047
+ const midwest: GridView = {
1048
+ ...builtIn,
1049
+ query: { ...builtIn.query, search: 'Midwest' },
1050
+ };
1051
+
1052
+ const highValue: GridView = {
1053
+ ...builtIn,
1054
+ density: 'compact',
1055
+ query: { ...builtIn.query, sort: [{ column: 'total', direction: 'descending' }] },
1056
+ };
1057
+
1058
+ const views: SavedViewsState = {
1059
+ views: [
1060
+ { id: 'late', name: 'Late orders', view: serializeGridView(late) },
1061
+ { id: 'midwest', name: 'Midwest accounts', view: serializeGridView(midwest) },
1062
+ { id: 'high', name: 'High value', view: serializeGridView(highValue) },
1063
+ ],
1064
+ defaultId: null,
1065
+ activeId: 'late',
1066
+ };
1067
+
1068
+ function sortedByTotal(view: GridView): GridView {
1069
+ return {
1070
+ ...view,
1071
+ query: { ...view.query, sort: [{ column: 'total', direction: 'descending' }] },
1072
+ };
1073
+ }
1074
+
1075
+ export default function SavedViewsModified() {
1076
+ const [current, setCurrent] = useState(sortedByTotal(late));
1077
+ const [applied, setApplied] = useState('none');
1078
+
1079
+ function handleViewApply(view: GridView, request: SavedViewsRequest) {
1080
+ setCurrent(view);
1081
+ setApplied(`${request.action} · ${request.reason}`);
1082
+ }
1083
+
1084
+ return (
1085
+ <Stack gap={4}>
1086
+ <Inline gap={3}>
1087
+ <SavedViews
1088
+ builtIn={builtIn}
1089
+ current={current}
1090
+ defaultState={views}
1091
+ onViewApply={handleViewApply}
1092
+ />
1093
+ <Button
1094
+ onClick={() => setCurrent(sortedByTotal(current))}
1095
+ size="sm"
1096
+ tone="secondary"
1097
+ variant="outline"
1098
+ >
1099
+ Sort by total
1100
+ </Button>
1101
+ </Inline>
1102
+ <Text size="sm" tone="muted">
1103
+ Last applied: {applied}
1104
+ </Text>
1105
+ </Stack>
1106
+ );
1107
+ }
1108
+ ```