@invopop/popui 0.1.40 → 0.1.42

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.
@@ -3,7 +3,7 @@
3
3
  import type { TableSortBy, DrawerOption, BaseTableHeaderOrderByProps } from './types.js'
4
4
  import DrawerContext from './DrawerContext.svelte'
5
5
 
6
- let { isActive = false, sortDirection, onOrderBy, onHide, onFilter, onFreeze, isFrozen = false, showSortOptions = true, showFilterOption = true }: BaseTableHeaderOrderByProps = $props()
6
+ let { isActive = false, sortDirection, onOrderBy, onHide, onFilter, onFreeze, isFrozen = false, showSortOptions = true, showFilterOption = true, showHideOption = true }: BaseTableHeaderOrderByProps = $props()
7
7
 
8
8
  let items = $derived([
9
9
  ...(showSortOptions ? [
@@ -26,8 +26,10 @@
26
26
  { label: '', value: 'sep-2', separator: true }
27
27
  ] : []),
28
28
  { icon: Lock, label: isFrozen ? 'Unfreeze column' : 'Freeze column', value: 'freeze' },
29
- { label: '', value: 'sep-3', separator: true },
30
- { icon: Preview, label: 'Hide column', value: 'hide' }
29
+ ...(showHideOption ? [
30
+ { label: '', value: 'sep-3', separator: true },
31
+ { icon: Preview, label: 'Hide column', value: 'hide' }
32
+ ] : [])
31
33
  ] as DrawerOption[])
32
34
  </script>
33
35
 
@@ -126,6 +126,7 @@
126
126
  isFrozen={frozenColumns.has(column.id)}
127
127
  showSortOptions={column.getCanSort()}
128
128
  showFilterOption={!column.columnDef.meta?.disableColumnFilter}
129
+ showHideOption={column.getCanHide()}
129
130
  onOrderBy={(direction) => {
130
131
  column.toggleSorting(direction === 'desc')
131
132
  if (onSortingChange) {
@@ -20,7 +20,8 @@
20
20
  data,
21
21
  rowCount,
22
22
  manualPagination,
23
- disabled = false
23
+ disabled = false,
24
+ disableJumpToPage = false
24
25
  }: DataTablePaginationProps<any> = $props()
25
26
 
26
27
  let currentPage = $derived(table.getState().pagination.pageIndex + 1)
@@ -78,28 +79,32 @@
78
79
  className
79
80
  )}
80
81
  >
81
- <div class={clsx('flex items-center gap-3', {
82
- 'pointer-events-none opacity-30': disabled
83
- })}>
82
+ <div
83
+ class={clsx('flex items-center gap-3', {
84
+ 'pointer-events-none opacity-30': disabled
85
+ })}
86
+ >
84
87
  <div class="flex items-center gap-2">
85
88
  <div class="flex items-center gap-1.5">
86
89
  <div class="flex items-center">
87
- <Button
88
- variant="ghost"
89
- size="md"
90
- icon={ScrollLeft}
91
- onclick={() => {
92
- if (manualPagination) {
93
- table.setPagination({ pageIndex: 0, pageSize: rowsPerPage })
94
- } else {
95
- table.setPageIndex(0)
96
- }
97
- onPageChange?.(1)
98
- }}
99
- disabled={currentPage === 1}
100
- class={cn(currentPage === 1 && 'pointer-events-none opacity-30')}
101
- aria-label="First page"
102
- />
90
+ {#if !disableJumpToPage}
91
+ <Button
92
+ variant="ghost"
93
+ size="md"
94
+ icon={ScrollLeft}
95
+ onclick={() => {
96
+ if (manualPagination) {
97
+ table.setPagination({ pageIndex: 0, pageSize: rowsPerPage })
98
+ } else {
99
+ table.setPageIndex(0)
100
+ }
101
+ onPageChange?.(1)
102
+ }}
103
+ disabled={currentPage === 1}
104
+ class={cn(currentPage === 1 && 'pointer-events-none opacity-30')}
105
+ aria-label="First page"
106
+ />
107
+ {/if}
103
108
  <Button
104
109
  variant="ghost"
105
110
  size="md"
@@ -132,6 +137,7 @@
132
137
  size="sm"
133
138
  oninput={handlePageInput}
134
139
  onblur={handlePageBlur}
140
+ disabled={disableJumpToPage}
135
141
  />
136
142
  </div>
137
143
  <span class="text-base text-foreground-default-secondary whitespace-nowrap">
@@ -158,22 +164,24 @@
158
164
  class={cn(currentPage === totalPages && 'pointer-events-none opacity-30')}
159
165
  aria-label="Next page"
160
166
  />
161
- <Button
162
- variant="ghost"
163
- size="md"
164
- icon={ScrollRight}
165
- onclick={() => {
166
- if (manualPagination) {
167
- table.setPagination({ pageIndex: totalPages - 1, pageSize: rowsPerPage })
168
- } else {
169
- table.setPageIndex(totalPages - 1)
170
- }
171
- onPageChange?.(totalPages)
172
- }}
173
- disabled={currentPage === totalPages}
174
- class={cn(currentPage === totalPages && 'pointer-events-none opacity-30')}
175
- aria-label="Last page"
176
- />
167
+ {#if !disableJumpToPage}
168
+ <Button
169
+ variant="ghost"
170
+ size="md"
171
+ icon={ScrollRight}
172
+ onclick={() => {
173
+ if (manualPagination) {
174
+ table.setPagination({ pageIndex: totalPages - 1, pageSize: rowsPerPage })
175
+ } else {
176
+ table.setPageIndex(totalPages - 1)
177
+ }
178
+ onPageChange?.(totalPages)
179
+ }}
180
+ disabled={currentPage === totalPages}
181
+ class={cn(currentPage === totalPages && 'pointer-events-none opacity-30')}
182
+ aria-label="Last page"
183
+ />
184
+ {/if}
177
185
  </div>
178
186
  </div>
179
187
  {#if showRowsPerPage}
@@ -190,7 +198,6 @@
190
198
  table.setPageSize(size)
191
199
  table.setPageIndex(0)
192
200
  onPageSizeChange?.(size)
193
- onPageChange?.(1)
194
201
  }}
195
202
  placeholder="Rows per page"
196
203
  disablePlaceholder={true}
@@ -93,6 +93,7 @@ export interface DataTablePaginationProps<T> {
93
93
  rowCount?: number;
94
94
  manualPagination?: boolean;
95
95
  disabled?: boolean;
96
+ disableJumpToPage?: boolean;
96
97
  }
97
98
  export interface DataTableRowProps<TData> {
98
99
  row: Row<TData>;
@@ -117,6 +118,7 @@ export interface DataTableProps<TData> {
117
118
  disablePagination?: boolean;
118
119
  disableKeyboardNavigation?: boolean;
119
120
  disableControls?: boolean;
121
+ disableJumpToPage?: boolean;
120
122
  rowActions?: TableAction[];
121
123
  getRowActions?: (row: TData) => TableAction[];
122
124
  onRowAction?: (action: AnyProp, row: TData) => void;
@@ -47,6 +47,7 @@
47
47
  disablePagination = false,
48
48
  disableKeyboardNavigation = false,
49
49
  disableControls = false,
50
+ disableJumpToPage = false,
50
51
  rowActions = [],
51
52
  getRowActions,
52
53
  onRowAction,
@@ -196,7 +197,14 @@
196
197
  tableRenderKey++
197
198
  },
198
199
  setSorting: (value) => (sorting = value),
199
- setPagination: (value) => (pagination = value),
200
+ setPagination: (value) => {
201
+ const pageChanged = pagination.pageIndex !== value.pageIndex
202
+ pagination = value
203
+ // Clear selection when page changes
204
+ if (pageChanged && Object.keys(rowSelection).length > 0) {
205
+ rowSelection = {}
206
+ }
207
+ },
200
208
  setColumnSizing: (value) => {
201
209
  columnSizing = value
202
210
  if (onColumnResize && Object.keys(value).length > 0) {
@@ -417,6 +425,7 @@
417
425
  {manualPagination}
418
426
  {onPageChange}
419
427
  {onPageSizeChange}
428
+ {disableJumpToPage}
420
429
  disabled={disableControls || loading}
421
430
  >
422
431
  {#if paginationSlot}
package/dist/types.d.ts CHANGED
@@ -240,6 +240,7 @@ export interface BaseTableHeaderOrderByProps {
240
240
  isFrozen?: boolean;
241
241
  showSortOptions?: boolean;
242
242
  showFilterOption?: boolean;
243
+ showHideOption?: boolean;
243
244
  }
244
245
  export interface BreadcrumbProps {
245
246
  breadcrumb: Breadcrumb;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@invopop/popui",
3
3
  "license": "MIT",
4
- "version": "0.1.40",
4
+ "version": "0.1.42",
5
5
  "repository": {
6
6
  "url": "https://github.com/invopop/popui"
7
7
  },