@multiplatform.one/table 7.10.0 → 7.11.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 (84) hide show
  1. package/README.md +60 -0
  2. package/dist/cjs/components/DataTable/DataTableCardControls.cjs +90 -54
  3. package/dist/cjs/components/DataTable/DataTableCardControls.native.js +93 -56
  4. package/dist/cjs/components/DataTable/DataTableCardControls.native.js.map +1 -1
  5. package/dist/cjs/components/DataTable/DataTableRoot.cjs +51 -8
  6. package/dist/cjs/components/DataTable/DataTableRoot.native.js +53 -9
  7. package/dist/cjs/components/DataTable/DataTableRoot.native.js.map +1 -1
  8. package/dist/cjs/components/DataTableFilterButton/index.cjs +14 -0
  9. package/dist/cjs/components/DataTableFilterButton/index.native.js +15 -0
  10. package/dist/cjs/components/DataTableFilterButton/index.native.js.map +1 -1
  11. package/dist/cjs/components/DataTableToolbar/index.cjs +178 -101
  12. package/dist/cjs/components/DataTableToolbar/index.native.js +187 -109
  13. package/dist/cjs/components/DataTableToolbar/index.native.js.map +1 -1
  14. package/dist/cjs/hooks/useDataTable.cjs +32 -1
  15. package/dist/cjs/hooks/useDataTable.native.js +37 -1
  16. package/dist/cjs/hooks/useDataTable.native.js.map +1 -1
  17. package/dist/esm/components/DataTable/DataTableCardControls.mjs +89 -54
  18. package/dist/esm/components/DataTable/DataTableCardControls.mjs.map +1 -1
  19. package/dist/esm/components/DataTable/DataTableCardControls.native.js +92 -56
  20. package/dist/esm/components/DataTable/DataTableCardControls.native.js.map +1 -1
  21. package/dist/esm/components/DataTable/DataTableRoot.mjs +53 -10
  22. package/dist/esm/components/DataTable/DataTableRoot.mjs.map +1 -1
  23. package/dist/esm/components/DataTable/DataTableRoot.native.js +55 -11
  24. package/dist/esm/components/DataTable/DataTableRoot.native.js.map +1 -1
  25. package/dist/esm/components/DataTableFilterButton/index.mjs +14 -1
  26. package/dist/esm/components/DataTableFilterButton/index.mjs.map +1 -1
  27. package/dist/esm/components/DataTableFilterButton/index.native.js +15 -1
  28. package/dist/esm/components/DataTableFilterButton/index.native.js.map +1 -1
  29. package/dist/esm/components/DataTableToolbar/index.mjs +180 -104
  30. package/dist/esm/components/DataTableToolbar/index.mjs.map +1 -1
  31. package/dist/esm/components/DataTableToolbar/index.native.js +189 -112
  32. package/dist/esm/components/DataTableToolbar/index.native.js.map +1 -1
  33. package/dist/esm/hooks/useDataTable.mjs +32 -1
  34. package/dist/esm/hooks/useDataTable.mjs.map +1 -1
  35. package/dist/esm/hooks/useDataTable.native.js +37 -1
  36. package/dist/esm/hooks/useDataTable.native.js.map +1 -1
  37. package/dist/jsx/components/DataTable/DataTableCardControls.mjs +89 -54
  38. package/dist/jsx/components/DataTable/DataTableCardControls.mjs.map +1 -1
  39. package/dist/jsx/components/DataTable/DataTableCardControls.native.js +93 -56
  40. package/dist/jsx/components/DataTable/DataTableCardControls.native.js.map +1 -1
  41. package/dist/jsx/components/DataTable/DataTableRoot.mjs +53 -10
  42. package/dist/jsx/components/DataTable/DataTableRoot.mjs.map +1 -1
  43. package/dist/jsx/components/DataTable/DataTableRoot.native.js +53 -9
  44. package/dist/jsx/components/DataTable/DataTableRoot.native.js.map +1 -1
  45. package/dist/jsx/components/DataTableFilterButton/index.mjs +14 -1
  46. package/dist/jsx/components/DataTableFilterButton/index.mjs.map +1 -1
  47. package/dist/jsx/components/DataTableFilterButton/index.native.js +15 -0
  48. package/dist/jsx/components/DataTableFilterButton/index.native.js.map +1 -1
  49. package/dist/jsx/components/DataTableToolbar/index.mjs +180 -104
  50. package/dist/jsx/components/DataTableToolbar/index.mjs.map +1 -1
  51. package/dist/jsx/components/DataTableToolbar/index.native.js +187 -109
  52. package/dist/jsx/components/DataTableToolbar/index.native.js.map +1 -1
  53. package/dist/jsx/hooks/useDataTable.mjs +32 -1
  54. package/dist/jsx/hooks/useDataTable.mjs.map +1 -1
  55. package/dist/jsx/hooks/useDataTable.native.js +37 -1
  56. package/dist/jsx/hooks/useDataTable.native.js.map +1 -1
  57. package/package.json +14 -14
  58. package/src/components/DataTable/DataTable.stories.tsx +59 -0
  59. package/src/components/DataTable/DataTableCardControls.stories.tsx +61 -2
  60. package/src/components/DataTable/DataTableCardControls.tsx +92 -66
  61. package/src/components/DataTable/DataTableRoot.tsx +82 -14
  62. package/src/components/DataTable/cardLayout.spec.tsx +4 -3
  63. package/src/components/DataTable/cardToolbar.spec.tsx +238 -0
  64. package/src/components/DataTable/chromeInterplay.spec.tsx +7 -5
  65. package/src/components/DataTable/columnWidthLayout.spec.tsx +189 -0
  66. package/src/components/DataTable/dataTableCardControls.spec.tsx +3 -2
  67. package/src/components/DataTable/footerLayout.spec.tsx +250 -0
  68. package/src/components/DataTable/pinningGeometry.spec.tsx +66 -1
  69. package/src/components/DataTableExport/DataTableExport.spec.tsx +42 -18
  70. package/src/components/DataTableFilterButton/index.tsx +9 -0
  71. package/src/components/DataTableToolbar/index.tsx +184 -105
  72. package/src/hooks/useDataTable.spec.ts +114 -0
  73. package/src/hooks/useDataTable.ts +23 -1
  74. package/src/types.ts +14 -12
  75. package/types/components/DataTable/DataTableCardControls.d.ts +3 -0
  76. package/types/components/DataTable/DataTableCardControls.d.ts.map +1 -1
  77. package/types/components/DataTable/DataTableRoot.d.ts.map +1 -1
  78. package/types/components/DataTableFilterButton/index.d.ts +2 -1
  79. package/types/components/DataTableFilterButton/index.d.ts.map +1 -1
  80. package/types/components/DataTableToolbar/index.d.ts +1 -0
  81. package/types/components/DataTableToolbar/index.d.ts.map +1 -1
  82. package/types/hooks/useDataTable.d.ts.map +1 -1
  83. package/types/types.d.ts +14 -12
  84. package/types/types.d.ts.map +1 -1
@@ -22,6 +22,7 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
22
22
  }), mod);
23
23
  var DataTableToolbar_exports = {};
24
24
  __export(DataTableToolbar_exports, {
25
+ DataTableCardToolbar: () => DataTableCardToolbar,
25
26
  DataTableToolbar: () => DataTableToolbar
26
27
  });
27
28
  module.exports = __toCommonJS(DataTableToolbar_exports);
@@ -39,6 +40,20 @@ var import_DataTableExport = require("../DataTableExport/index.cjs");
39
40
  var import_DataTableFilterButton = require("../DataTableFilterButton/index.cjs");
40
41
  var import_jsx_runtime = require("react/jsx-runtime");
41
42
  function DataTableToolbar(props) {
43
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToolbarLayout, {
44
+ ...props
45
+ });
46
+ }
47
+ function DataTableCardToolbar(props) {
48
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToolbarLayout, {
49
+ ...props,
50
+ cardLayout: true
51
+ });
52
+ }
53
+ function ToolbarLayout({
54
+ cardLayout = false,
55
+ ...props
56
+ }) {
42
57
  const ctx = (0, import_DataTableStateContext.useDataTableState)();
43
58
  const globalFilter = props.globalFilter ?? ctx?.state.globalFilter ?? "";
44
59
  const onGlobalFilterChange = props.onGlobalFilterChange ?? ctx?.actions.setGlobalFilter ?? (() => {});
@@ -86,8 +101,123 @@ function DataTableToolbar(props) {
86
101
  const showSave = enableViews && showViewSelector;
87
102
  const showActionCluster = Boolean(customActions || showFilterButton || showViewPicker || showSave || enableExport);
88
103
  const hasTrailing = showActionCluster || isFetching;
104
+ const viewPickerContent = showViewPicker && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_components.DropdownMenu, {
105
+ closeOnSelect: true,
106
+ placement: "bottom-end",
107
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.DropdownMenu.Trigger, {
108
+ asChild: true,
109
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
110
+ focusable: true,
111
+ asChild: true,
112
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
113
+ chromeless: true,
114
+ size: controlSize,
115
+ iconAfter: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.CaretDownIcon, {
116
+ size: iconPx
117
+ }),
118
+ "aria-label": (0, import_t.t)("Saved views"),
119
+ ...(cardLayout ? {
120
+ minWidth: 0,
121
+ maxWidth: "100%"
122
+ } : {}),
123
+ "aria-haspopup": "menu",
124
+ children: activeView?.name ?? (0, import_t.t)("Views")
125
+ })
126
+ })
127
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.DropdownMenu.Content, {
128
+ children: views.map(view => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.DropdownMenu.CheckboxItem, {
129
+ checked: view.id === activeViewId,
130
+ closeOnSelect: true,
131
+ onSelect: () => onLoadView(view.id),
132
+ children: view.name
133
+ }, view.id))
134
+ })]
135
+ });
136
+ const viewPicker = cardLayout && showViewPicker ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
137
+ minWidth: 0,
138
+ maxWidth: "100%",
139
+ flexBasis: "auto",
140
+ flexGrow: 0,
141
+ flexShrink: 1,
142
+ children: viewPickerContent
143
+ }) : viewPickerContent;
144
+ const saveView = showSave && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.Popover, {
145
+ open: showSaveViewDialog,
146
+ onOpenChange: setShowSaveViewDialog,
147
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Popover.Trigger, {
148
+ asChild: true,
149
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
150
+ focusable: true,
151
+ asChild: true,
152
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
153
+ chromeless: true,
154
+ size: controlSize,
155
+ icon: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.FloppyDiskIcon, {
156
+ size: iconPx
157
+ }),
158
+ "aria-label": (0, import_t.t)("Save view")
159
+ })
160
+ })
161
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Popover.Content, {
162
+ ...knobProps.elevatedSurface,
163
+ ...knobProps.borderRadius,
164
+ borderColor: "$color6",
165
+ transition: knobProps.transition,
166
+ enterStyle: {
167
+ x: 0,
168
+ y: -10,
169
+ opacity: 0
170
+ },
171
+ exitStyle: {
172
+ x: 0,
173
+ y: -10,
174
+ opacity: 0
175
+ },
176
+ "data-dismiss-class": "compose",
177
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
178
+ ...knobProps.gap,
179
+ ...knobProps.panelPadding,
180
+ minWidth: 240,
181
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Input, {
182
+ placeholder: (0, import_t.t)("View name"),
183
+ value: newViewName,
184
+ onChangeText: setNewViewName,
185
+ size: searchSize,
186
+ ...(compact === void 0 ? {} : {
187
+ compact
188
+ }),
189
+ inputProps: {
190
+ "aria-label": (0, import_t.t)("View name"),
191
+ onKeyDown: e => {
192
+ if (e.key === "Enter") handleSaveView();
193
+ }
194
+ }
195
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
196
+ ...knobProps.gap,
197
+ justifyContent: "flex-end",
198
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
199
+ size: controlSize,
200
+ onPress: () => setShowSaveViewDialog(false),
201
+ children: (0, import_t.t)("Cancel")
202
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
203
+ size: controlSize,
204
+ onPress: handleSaveView,
205
+ disabled: !newViewName.trim(),
206
+ disabledReason: (0, import_t.t)("Enter a view name"),
207
+ children: (0, import_t.t)("Save")
208
+ })]
209
+ })]
210
+ })
211
+ })]
212
+ });
213
+ const showSecondary = showViewPicker || showSave || enableExport || isFetching;
89
214
  return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
90
- alignItems: "center",
215
+ alignItems: cardLayout ? "stretch" : "center",
216
+ flexDirection: cardLayout ? "column" : "row",
217
+ ...(cardLayout ? {
218
+ width: "100%",
219
+ minWidth: 0
220
+ } : {}),
91
221
  paddingVertical: knobProps.panelPadding.padding,
92
222
  paddingHorizontal: 0,
93
223
  ...knobProps.gap,
@@ -99,9 +229,9 @@ function DataTableToolbar(props) {
99
229
  "aria-label": (0, import_t.t)("Table toolbar"),
100
230
  "aria-busy": isFetching || void 0,
101
231
  children: [enableGlobalSearch && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
102
- flex: 1,
103
- minWidth: 160,
104
- maxWidth: searchMaxWidth,
232
+ flex: cardLayout ? void 0 : 1,
233
+ minWidth: cardLayout ? 0 : 160,
234
+ maxWidth: cardLayout ? void 0 : searchMaxWidth,
105
235
  flexShrink: 1,
106
236
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.SearchInput, {
107
237
  value: globalFilter,
@@ -114,7 +244,49 @@ function DataTableToolbar(props) {
114
244
  }),
115
245
  size: searchSize
116
246
  })
117
- }), hasTrailing && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
247
+ }), cardLayout ? /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
248
+ children: [(showFilterButton || customActions) && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup, {
249
+ orientation: "horizontal",
250
+ loop: true,
251
+ asChild: true,
252
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
253
+ "data-table-card-primary": "",
254
+ width: "100%",
255
+ minWidth: 0,
256
+ alignItems: "center",
257
+ flexWrap: "nowrap",
258
+ ...knobProps.gap,
259
+ children: [showFilterButton && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
260
+ flexShrink: 0,
261
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DataTableFilterButton.DataTableCardFilterButton, {})
262
+ }), customActions]
263
+ })
264
+ }), showSecondary && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup, {
265
+ orientation: "horizontal",
266
+ loop: true,
267
+ asChild: true,
268
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
269
+ "data-table-card-secondary": "",
270
+ width: "100%",
271
+ minWidth: 0,
272
+ flexWrap: "wrap",
273
+ alignItems: "center",
274
+ ...knobProps.gap,
275
+ children: [enableExport && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
276
+ maxWidth: "100%",
277
+ minWidth: 0,
278
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DataTableExport.DataTableExport, {})
279
+ }), viewPicker, saveView, isFetching && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
280
+ alignItems: "center",
281
+ "aria-live": "polite",
282
+ "data-table-fetching": "true",
283
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Spinner, {
284
+ size: "small"
285
+ })
286
+ })]
287
+ })
288
+ })]
289
+ }) : hasTrailing && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
118
290
  alignItems: "center",
119
291
  ...knobProps.gap,
120
292
  flexShrink: 0,
@@ -126,102 +298,7 @@ function DataTableToolbar(props) {
126
298
  children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
127
299
  alignItems: "center",
128
300
  ...knobProps.gap,
129
- children: [showFilterButton && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DataTableFilterButton.DataTableFilterButton, {}), enableExport && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DataTableExport.DataTableExport, {}), customActions, showViewPicker && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_components.DropdownMenu, {
130
- closeOnSelect: true,
131
- placement: "bottom-end",
132
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.DropdownMenu.Trigger, {
133
- asChild: true,
134
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
135
- focusable: true,
136
- asChild: true,
137
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
138
- chromeless: true,
139
- size: controlSize,
140
- iconAfter: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.CaretDownIcon, {
141
- size: iconPx
142
- }),
143
- "aria-label": (0, import_t.t)("Saved views"),
144
- "aria-haspopup": "menu",
145
- children: activeView?.name ?? (0, import_t.t)("Views")
146
- })
147
- })
148
- }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.DropdownMenu.Content, {
149
- children: views.map(view => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.DropdownMenu.CheckboxItem, {
150
- checked: view.id === activeViewId,
151
- closeOnSelect: true,
152
- onSelect: () => onLoadView(view.id),
153
- children: view.name
154
- }, view.id))
155
- })]
156
- }), showSave && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.Popover, {
157
- open: showSaveViewDialog,
158
- onOpenChange: setShowSaveViewDialog,
159
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Popover.Trigger, {
160
- asChild: true,
161
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
162
- focusable: true,
163
- asChild: true,
164
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
165
- chromeless: true,
166
- size: controlSize,
167
- icon: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.FloppyDiskIcon, {
168
- size: iconPx
169
- }),
170
- "aria-label": (0, import_t.t)("Save view")
171
- })
172
- })
173
- }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Popover.Content, {
174
- ...knobProps.elevatedSurface,
175
- ...knobProps.borderRadius,
176
- borderColor: "$color6",
177
- transition: knobProps.transition,
178
- enterStyle: {
179
- x: 0,
180
- y: -10,
181
- opacity: 0
182
- },
183
- exitStyle: {
184
- x: 0,
185
- y: -10,
186
- opacity: 0
187
- },
188
- "data-dismiss-class": "compose",
189
- children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
190
- ...knobProps.gap,
191
- ...knobProps.panelPadding,
192
- minWidth: 240,
193
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Input, {
194
- placeholder: (0, import_t.t)("View name"),
195
- value: newViewName,
196
- onChangeText: setNewViewName,
197
- size: searchSize,
198
- ...(compact === void 0 ? {} : {
199
- compact
200
- }),
201
- inputProps: {
202
- "aria-label": (0, import_t.t)("View name"),
203
- onKeyDown: e => {
204
- if (e.key === "Enter") handleSaveView();
205
- }
206
- }
207
- }), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
208
- ...knobProps.gap,
209
- justifyContent: "flex-end",
210
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
211
- size: controlSize,
212
- onPress: () => setShowSaveViewDialog(false),
213
- children: (0, import_t.t)("Cancel")
214
- }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
215
- size: controlSize,
216
- onPress: handleSaveView,
217
- disabled: !newViewName.trim(),
218
- disabledReason: (0, import_t.t)("Enter a view name"),
219
- children: (0, import_t.t)("Save")
220
- })]
221
- })]
222
- })
223
- })]
224
- })]
301
+ children: [showFilterButton && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DataTableFilterButton.DataTableFilterButton, {}), enableExport && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DataTableExport.DataTableExport, {}), customActions, viewPicker, saveView]
225
302
  })
226
303
  }), isFetching && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
227
304
  alignItems: "center",
@@ -24,6 +24,7 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
24
24
  }), mod);
25
25
  var DataTableToolbar_exports = {};
26
26
  __export(DataTableToolbar_exports, {
27
+ DataTableCardToolbar: () => DataTableCardToolbar,
27
28
  DataTableToolbar: () => DataTableToolbar
28
29
  });
29
30
  module.exports = __toCommonJS(DataTableToolbar_exports);
@@ -41,6 +42,21 @@ var import_DataTableStateContext = require("../DataTable/DataTableStateContext.n
41
42
  var import_DataTableExport = require("../DataTableExport/index.native.js");
42
43
  var import_DataTableFilterButton = require("../DataTableFilterButton/index.native.js");
43
44
  function DataTableToolbar(props) {
45
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToolbarLayout, {
46
+ ...props
47
+ });
48
+ }
49
+ function DataTableCardToolbar(props) {
50
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToolbarLayout, {
51
+ ...props,
52
+ cardLayout: true
53
+ });
54
+ }
55
+ function ToolbarLayout(param) {
56
+ var {
57
+ cardLayout = false,
58
+ ...props
59
+ } = param;
44
60
  var _ref, _props_globalFilter, _ref1, _props_onGlobalFilterChange, _ref2, _props_onClearFilters, _ref3, _props_onSaveView, _ref4, _props_onLoadView, _ref5, _props_views, _props_activeViewId, _ref6, _ref7, _ref8;
45
61
  var _ctx_computed_filterFields, _ctx_computed;
46
62
  var ctx = (0, import_DataTableStateContext.useDataTableState)();
@@ -92,8 +108,131 @@ function DataTableToolbar(props) {
92
108
  var showSave = enableViews && showViewSelector;
93
109
  var showActionCluster = Boolean(customActions || showFilterButton || showViewPicker || showSave || enableExport);
94
110
  var hasTrailing = showActionCluster || isFetching;
111
+ var viewPickerContent = showViewPicker && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_components.DropdownMenu, {
112
+ closeOnSelect: true,
113
+ placement: "bottom-end",
114
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.DropdownMenu.Trigger, {
115
+ asChild: true,
116
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
117
+ focusable: true,
118
+ asChild: true,
119
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
120
+ chromeless: true,
121
+ size: controlSize,
122
+ iconAfter: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.CaretDownIcon, {
123
+ size: iconPx
124
+ }),
125
+ "aria-label": (0, import_t.t)("Saved views"),
126
+ ...(cardLayout ? {
127
+ minWidth: 0,
128
+ maxWidth: "100%"
129
+ } : {}),
130
+ "aria-haspopup": "menu",
131
+ children: (_ref8 = activeView === null || activeView === void 0 ? void 0 : activeView.name) !== null && _ref8 !== void 0 ? _ref8 : (0, import_t.t)("Views")
132
+ })
133
+ })
134
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.DropdownMenu.Content, {
135
+ children: views.map(function (view) {
136
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.DropdownMenu.CheckboxItem, {
137
+ checked: view.id === activeViewId,
138
+ closeOnSelect: true,
139
+ onSelect: function onSelect() {
140
+ return onLoadView(view.id);
141
+ },
142
+ children: view.name
143
+ }, view.id);
144
+ })
145
+ })]
146
+ });
147
+ var viewPicker = cardLayout && showViewPicker ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
148
+ minWidth: 0,
149
+ maxWidth: "100%",
150
+ flexBasis: "auto",
151
+ flexGrow: 0,
152
+ flexShrink: 1,
153
+ children: viewPickerContent
154
+ }) : viewPickerContent;
155
+ var saveView = showSave && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.Popover, {
156
+ open: showSaveViewDialog,
157
+ onOpenChange: setShowSaveViewDialog,
158
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Popover.Trigger, {
159
+ asChild: true,
160
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
161
+ focusable: true,
162
+ asChild: true,
163
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
164
+ chromeless: true,
165
+ size: controlSize,
166
+ icon: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.FloppyDiskIcon, {
167
+ size: iconPx
168
+ }),
169
+ "aria-label": (0, import_t.t)("Save view")
170
+ })
171
+ })
172
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Popover.Content, {
173
+ ...knobProps.elevatedSurface,
174
+ ...knobProps.borderRadius,
175
+ borderColor: "$color6",
176
+ // LC-24: enter/exitStyle need a `transition` driver on the
177
+ // same element ({...string} spread set nothing).
178
+ transition: knobProps.transition,
179
+ enterStyle: {
180
+ x: 0,
181
+ y: -10,
182
+ opacity: 0
183
+ },
184
+ exitStyle: {
185
+ x: 0,
186
+ y: -10,
187
+ opacity: 0
188
+ },
189
+ "data-dismiss-class": "compose",
190
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
191
+ ...knobProps.gap,
192
+ ...knobProps.panelPadding,
193
+ minWidth: 240,
194
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Input, {
195
+ placeholder: (0, import_t.t)("View name"),
196
+ value: newViewName,
197
+ onChangeText: setNewViewName,
198
+ size: searchSize,
199
+ ...(compact === void 0 ? {} : {
200
+ compact
201
+ }),
202
+ inputProps: {
203
+ "aria-label": (0, import_t.t)("View name"),
204
+ onKeyDown: function onKeyDown(e) {
205
+ if (e.key === "Enter") handleSaveView();
206
+ }
207
+ }
208
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
209
+ ...knobProps.gap,
210
+ justifyContent: "flex-end",
211
+ children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
212
+ size: controlSize,
213
+ onPress: function onPress() {
214
+ return setShowSaveViewDialog(false);
215
+ },
216
+ children: (0, import_t.t)("Cancel")
217
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
218
+ size: controlSize,
219
+ onPress: handleSaveView,
220
+ disabled: !newViewName.trim(),
221
+ disabledReason: (0, import_t.t)("Enter a view name"),
222
+ children: (0, import_t.t)("Save")
223
+ })]
224
+ })]
225
+ })
226
+ })]
227
+ });
228
+ var showSecondary = showViewPicker || showSave || enableExport || isFetching;
95
229
  return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
96
- alignItems: "center",
230
+ alignItems: cardLayout ? "stretch" : "center",
231
+ flexDirection: cardLayout ? "column" : "row",
232
+ ...(cardLayout ? {
233
+ width: "100%",
234
+ minWidth: 0
235
+ } : {}),
97
236
  // LC-39: flush band — no painted panel, so no horizontal inset.
98
237
  paddingVertical: knobProps.panelPadding.padding,
99
238
  paddingHorizontal: 0,
@@ -106,9 +245,9 @@ function DataTableToolbar(props) {
106
245
  "aria-label": (0, import_t.t)("Table toolbar"),
107
246
  "aria-busy": isFetching || void 0,
108
247
  children: [enableGlobalSearch && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
109
- flex: 1,
110
- minWidth: 160,
111
- maxWidth: searchMaxWidth,
248
+ flex: cardLayout ? void 0 : 1,
249
+ minWidth: cardLayout ? 0 : 160,
250
+ maxWidth: cardLayout ? void 0 : searchMaxWidth,
112
251
  flexShrink: 1,
113
252
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.SearchInput, {
114
253
  value: globalFilter,
@@ -128,7 +267,49 @@ function DataTableToolbar(props) {
128
267
  }),
129
268
  size: searchSize
130
269
  })
131
- }), hasTrailing && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
270
+ }), cardLayout ? /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
271
+ children: [(showFilterButton || customActions) && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup, {
272
+ orientation: "horizontal",
273
+ loop: true,
274
+ asChild: true,
275
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
276
+ "data-table-card-primary": "",
277
+ width: "100%",
278
+ minWidth: 0,
279
+ alignItems: "center",
280
+ flexWrap: "nowrap",
281
+ ...knobProps.gap,
282
+ children: [showFilterButton && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
283
+ flexShrink: 0,
284
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DataTableFilterButton.DataTableCardFilterButton, {})
285
+ }), customActions]
286
+ })
287
+ }), showSecondary && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup, {
288
+ orientation: "horizontal",
289
+ loop: true,
290
+ asChild: true,
291
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
292
+ "data-table-card-secondary": "",
293
+ width: "100%",
294
+ minWidth: 0,
295
+ flexWrap: "wrap",
296
+ alignItems: "center",
297
+ ...knobProps.gap,
298
+ children: [enableExport && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
299
+ maxWidth: "100%",
300
+ minWidth: 0,
301
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DataTableExport.DataTableExport, {})
302
+ }), viewPicker, saveView, isFetching && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
303
+ alignItems: "center",
304
+ "aria-live": "polite",
305
+ "data-table-fetching": "true",
306
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Spinner, {
307
+ size: "small"
308
+ })
309
+ })]
310
+ })
311
+ })]
312
+ }) : hasTrailing && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
132
313
  alignItems: "center",
133
314
  ...knobProps.gap,
134
315
  flexShrink: 0,
@@ -140,110 +321,7 @@ function DataTableToolbar(props) {
140
321
  children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
141
322
  alignItems: "center",
142
323
  ...knobProps.gap,
143
- children: [showFilterButton && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DataTableFilterButton.DataTableFilterButton, {}), enableExport && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DataTableExport.DataTableExport, {}), customActions, showViewPicker && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_components.DropdownMenu, {
144
- closeOnSelect: true,
145
- placement: "bottom-end",
146
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.DropdownMenu.Trigger, {
147
- asChild: true,
148
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
149
- focusable: true,
150
- asChild: true,
151
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
152
- chromeless: true,
153
- size: controlSize,
154
- iconAfter: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.CaretDownIcon, {
155
- size: iconPx
156
- }),
157
- "aria-label": (0, import_t.t)("Saved views"),
158
- "aria-haspopup": "menu",
159
- children: (_ref8 = activeView === null || activeView === void 0 ? void 0 : activeView.name) !== null && _ref8 !== void 0 ? _ref8 : (0, import_t.t)("Views")
160
- })
161
- })
162
- }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.DropdownMenu.Content, {
163
- children: views.map(function (view) {
164
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.DropdownMenu.CheckboxItem, {
165
- checked: view.id === activeViewId,
166
- closeOnSelect: true,
167
- onSelect: function onSelect() {
168
- return onLoadView(view.id);
169
- },
170
- children: view.name
171
- }, view.id);
172
- })
173
- })]
174
- }), showSave && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.Popover, {
175
- open: showSaveViewDialog,
176
- onOpenChange: setShowSaveViewDialog,
177
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Popover.Trigger, {
178
- asChild: true,
179
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
180
- focusable: true,
181
- asChild: true,
182
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
183
- chromeless: true,
184
- size: controlSize,
185
- icon: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.FloppyDiskIcon, {
186
- size: iconPx
187
- }),
188
- "aria-label": (0, import_t.t)("Save view")
189
- })
190
- })
191
- }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Popover.Content, {
192
- ...knobProps.elevatedSurface,
193
- ...knobProps.borderRadius,
194
- borderColor: "$color6",
195
- // LC-24: enter/exitStyle need a `transition` driver on the
196
- // same element ({...string} spread set nothing).
197
- transition: knobProps.transition,
198
- enterStyle: {
199
- x: 0,
200
- y: -10,
201
- opacity: 0
202
- },
203
- exitStyle: {
204
- x: 0,
205
- y: -10,
206
- opacity: 0
207
- },
208
- "data-dismiss-class": "compose",
209
- children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
210
- ...knobProps.gap,
211
- ...knobProps.panelPadding,
212
- minWidth: 240,
213
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Input, {
214
- placeholder: (0, import_t.t)("View name"),
215
- value: newViewName,
216
- onChangeText: setNewViewName,
217
- size: searchSize,
218
- ...(compact === void 0 ? {} : {
219
- compact
220
- }),
221
- inputProps: {
222
- "aria-label": (0, import_t.t)("View name"),
223
- onKeyDown: function onKeyDown(e) {
224
- if (e.key === "Enter") handleSaveView();
225
- }
226
- }
227
- }), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
228
- ...knobProps.gap,
229
- justifyContent: "flex-end",
230
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
231
- size: controlSize,
232
- onPress: function onPress() {
233
- return setShowSaveViewDialog(false);
234
- },
235
- children: (0, import_t.t)("Cancel")
236
- }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Button, {
237
- size: controlSize,
238
- onPress: handleSaveView,
239
- disabled: !newViewName.trim(),
240
- disabledReason: (0, import_t.t)("Enter a view name"),
241
- children: (0, import_t.t)("Save")
242
- })]
243
- })]
244
- })
245
- })]
246
- })]
324
+ children: [showFilterButton && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DataTableFilterButton.DataTableFilterButton, {}), enableExport && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DataTableExport.DataTableExport, {}), customActions, viewPicker, saveView]
247
325
  })
248
326
  }), isFetching && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
249
327
  alignItems: "center",