@nexxtmove/ui 0.1.35 → 0.1.36

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nexxtmove/ui",
3
3
  "type": "module",
4
- "version": "0.1.35",
4
+ "version": "0.1.36",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -46,6 +46,7 @@ const {
46
46
  :class="{ 'pointer-events-none opacity-50': disabled }"
47
47
  >
48
48
  <PaginationFirst
49
+ v-if="items.some((item) => item.type === 'ellipsis')"
49
50
  class="flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg bg-transparent transition hover:bg-cornflower-blue-50 disabled:cursor-not-allowed disabled:opacity-50"
50
51
  :disabled="disabled"
51
52
  >
@@ -83,6 +84,7 @@ const {
83
84
  <NexxtIcon name="chevron-right" />
84
85
  </PaginationNext>
85
86
  <PaginationLast
87
+ v-if="items.some((item) => item.type === 'ellipsis')"
86
88
  class="flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg bg-transparent transition hover:bg-cornflower-blue-50 disabled:cursor-not-allowed disabled:opacity-50"
87
89
  :disabled="disabled"
88
90
  >
@@ -13,25 +13,23 @@ export interface TableColumn<K extends string = string> {
13
13
  export interface NexxtTableProps<TKey extends string = string> {
14
14
  columns: TableColumn<TKey>[]
15
15
  rows: Record<TKey, unknown>[]
16
- sortKey?: TKey
17
- sortDirection?: 'asc' | 'desc'
18
16
  selectable?: boolean
19
- modelValue?: number[]
20
17
  }
21
18
 
22
19
  const INTERACTIVE = ['a', 'button', 'input', 'select', 'textarea', 'label']
23
20
 
24
21
  defineOptions({ name: 'NexxtTable' })
25
22
 
26
- const props = withDefaults(defineProps<NexxtTableProps<TKey>>(), {
27
- sortDirection: 'asc',
28
- })
23
+ const props = defineProps<NexxtTableProps<TKey>>()
29
24
  const emit = defineEmits<{
30
- sort: [key: string, direction: 'asc' | 'desc']
31
- 'update:modelValue': [selected: number[]]
25
+ 'row-click': [row: Record<TKey, unknown>]
32
26
  }>()
33
27
 
34
- const selected = computed(() => props.modelValue ?? [])
28
+ const selected = defineModel<Record<TKey, unknown>[]>({ default: () => [] })
29
+ const sortKey = defineModel<TKey>('sortKey')
30
+ const sortDirection = defineModel<'asc' | 'desc'>('sortDirection', { default: 'asc' })
31
+
32
+ const rowRefs = ref<HTMLElement[]>([])
35
33
 
36
34
  const allSelected = computed(
37
35
  () => props.rows.length > 0 && selected.value.length === props.rows.length,
@@ -40,15 +38,16 @@ const someSelected = computed(
40
38
  () => selected.value.length > 0 && selected.value.length < props.rows.length,
41
39
  )
42
40
 
41
+ const isRowSelected = (row: Record<TKey, unknown>) => selected.value.includes(row)
42
+
43
43
  const toggleAll = () => {
44
- emit('update:modelValue', allSelected.value ? [] : props.rows.map((_, i) => i))
44
+ selected.value = allSelected.value ? [] : [...props.rows]
45
45
  }
46
46
 
47
- const toggleRow = (index: number) => {
48
- const next = selected.value.includes(index)
49
- ? selected.value.filter((i) => i !== index)
50
- : [...selected.value, index]
51
- emit('update:modelValue', next)
47
+ const toggleRow = (row: Record<TKey, unknown>) => {
48
+ selected.value = isRowSelected(row)
49
+ ? selected.value.filter((r) => r !== row)
50
+ : [...selected.value, row]
52
51
  }
53
52
 
54
53
  const columnTemplate = computed(() =>
@@ -61,32 +60,30 @@ const gridTemplate = computed(() =>
61
60
 
62
61
  const handleSort = (column: TableColumn) => {
63
62
  if (!column.sortable) return
64
- const newDirection =
65
- props.sortKey === column.key && props.sortDirection === 'asc' ? 'desc' : 'asc'
66
- emit('sort', column.key, newDirection)
63
+ sortDirection.value =
64
+ sortKey.value === column.key && sortDirection.value === 'asc' ? 'desc' : 'asc'
65
+ sortKey.value = column.key as TKey
67
66
  }
68
67
 
69
68
  const handleRowClick = (event: MouseEvent, rowIndex: number) => {
70
- if (!props.selectable) return
71
69
  const path = event.composedPath() as Element[]
72
70
  const isInteractive = path.some(
73
71
  (el) => el.tagName && INTERACTIVE.includes(el.tagName.toLowerCase()),
74
72
  )
75
- if (!isInteractive) toggleRow(rowIndex)
73
+ if (isInteractive) return
74
+ emit('row-click', props.rows[rowIndex])
76
75
  }
77
76
 
78
77
  const getRowRoundedClass = (rowIndex: number) => {
79
- if (!props.selectable || !selected.value.includes(rowIndex)) return ''
80
- const prevSelected = selected.value.includes(rowIndex - 1)
81
- const nextSelected = selected.value.includes(rowIndex + 1)
78
+ if (!props.selectable || !isRowSelected(props.rows[rowIndex])) return ''
79
+ const prevSelected = rowIndex > 0 && isRowSelected(props.rows[rowIndex - 1])
80
+ const nextSelected = rowIndex < props.rows.length - 1 && isRowSelected(props.rows[rowIndex + 1])
82
81
  if (!prevSelected && !nextSelected) return 'rounded-md'
83
82
  if (!prevSelected) return 'rounded-t-md'
84
83
  if (!nextSelected) return 'rounded-b-md'
85
84
  return ''
86
85
  }
87
86
 
88
- const rowRefs = ref<HTMLElement[]>([])
89
-
90
87
  const handleRowKeydown = (event: KeyboardEvent, rowIndex: number) => {
91
88
  if (event.key === 'ArrowDown') {
92
89
  event.preventDefault()
@@ -176,18 +173,20 @@ const handleRowKeydown = (event: KeyboardEvent, rowIndex: number) => {
176
173
  v-for="(row, rowIndex) in rows"
177
174
  :key="rowIndex"
178
175
  ref="rowRefs"
179
- class="grid border-b border-gray-100 transition-colors duration-150 focus-visible:bg-slate-50 focus-visible:ring-2 focus-visible:ring-cornflower-blue-500 focus-visible:outline-none focus-visible:ring-inset"
176
+ class="grid border-b border-gray-100 transition-colors duration-150 hover:bg-cornflower-blue-50 focus-visible:bg-slate-50 focus-visible:ring-2 focus-visible:ring-cornflower-blue-500 focus-visible:outline-none focus-visible:ring-inset"
180
177
  :class="[
181
178
  {
182
- 'hover:bg-slate-50': selectable,
183
- 'border-white/80 bg-cornflower-blue-50': selectable && selected.includes(rowIndex),
179
+ 'hover:rounded-md': !isRowSelected(rows[rowIndex]),
180
+ 'border-white/80 bg-cornflower-blue-100':
181
+ selectable && isRowSelected(rows[rowIndex]),
182
+ 'border-transparent': selectable && isRowSelected(rows[rowIndex + 1]),
184
183
  },
185
184
  getRowRoundedClass(rowIndex),
186
185
  ]"
187
186
  :style="{ gridTemplateColumns: gridTemplate }"
188
187
  role="row"
189
188
  :aria-rowindex="rowIndex + 2"
190
- :aria-selected="selectable ? selected.includes(rowIndex) : undefined"
189
+ :aria-selected="selectable ? isRowSelected(row) : undefined"
191
190
  tabindex="0"
192
191
  @click="handleRowClick($event, rowIndex)"
193
192
  @keydown="handleRowKeydown($event, rowIndex)"
@@ -199,9 +198,9 @@ const handleRowKeydown = (event: KeyboardEvent, rowIndex: number) => {
199
198
  :aria-colindex="1"
200
199
  >
201
200
  <Checkbox
202
- :model-value="selected.includes(rowIndex)"
201
+ :model-value="isRowSelected(row)"
203
202
  :aria-label="`Select row ${rowIndex + 1}`"
204
- @update:model-value="toggleRow(rowIndex)"
203
+ @update:model-value="toggleRow(row)"
205
204
  />
206
205
  </div>
207
206
  <div