-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Table): implement component (#2364)
- Loading branch information
1 parent
34bddd4
commit b54950e
Showing
40 changed files
with
4,000 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script setup lang="ts"> | ||
import type { PropertyMeta } from 'vue-component-meta' | ||
const props = defineProps<{ | ||
prop: PropertyMeta | ||
}>() | ||
const links = computed(() => props.prop.tags?.filter((tag: any) => tag.name === 'link')) | ||
</script> | ||
|
||
<template> | ||
<ProseUl v-if="links?.length"> | ||
<ProseLi v-for="link in links" :key="link.name"> | ||
<MDC :value="link.text ?? ''" class="my-1" /> | ||
</ProseLi> | ||
</ProseUl> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
docs/app/components/content/examples/table/TableColumnFiltersExample.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<script setup lang="ts"> | ||
import { h, resolveComponent } from 'vue' | ||
import type { TableColumn } from '@nuxt/ui' | ||
const UBadge = resolveComponent('UBadge') | ||
type Payment = { | ||
id: string | ||
date: string | ||
status: 'paid' | 'failed' | 'refunded' | ||
email: string | ||
amount: number | ||
} | ||
const data = ref<Payment[]>([{ | ||
id: '4600', | ||
date: '2024-03-11T15:30:00', | ||
status: 'paid', | ||
email: '[email protected]', | ||
amount: 594 | ||
}, { | ||
id: '4599', | ||
date: '2024-03-11T10:10:00', | ||
status: 'failed', | ||
email: '[email protected]', | ||
amount: 276 | ||
}, { | ||
id: '4598', | ||
date: '2024-03-11T08:50:00', | ||
status: 'refunded', | ||
email: '[email protected]', | ||
amount: 315 | ||
}, { | ||
id: '4597', | ||
date: '2024-03-10T19:45:00', | ||
status: 'paid', | ||
email: '[email protected]', | ||
amount: 529 | ||
}, { | ||
id: '4596', | ||
date: '2024-03-10T15:55:00', | ||
status: 'paid', | ||
email: '[email protected]', | ||
amount: 639 | ||
}]) | ||
const columns: TableColumn<Payment>[] = [{ | ||
accessorKey: 'id', | ||
header: '#', | ||
cell: ({ row }) => `#${row.getValue('id')}` | ||
}, { | ||
accessorKey: 'date', | ||
header: 'Date', | ||
cell: ({ row }) => { | ||
return new Date(row.getValue('date')).toLocaleString('en-US', { | ||
day: 'numeric', | ||
month: 'short', | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
hour12: false | ||
}) | ||
} | ||
}, { | ||
accessorKey: 'status', | ||
header: 'Status', | ||
cell: ({ row }) => { | ||
const color = ({ | ||
paid: 'success' as const, | ||
failed: 'error' as const, | ||
refunded: 'neutral' as const | ||
})[row.getValue('status') as string] | ||
return h(UBadge, { class: 'capitalize', variant: 'subtle', color }, () => row.getValue('status')) | ||
} | ||
}, { | ||
accessorKey: 'email', | ||
header: 'Email' | ||
}, { | ||
accessorKey: 'amount', | ||
header: () => h('div', { class: 'text-right' }, 'Amount'), | ||
cell: ({ row }) => { | ||
const amount = Number.parseFloat(row.getValue('amount')) | ||
const formatted = new Intl.NumberFormat('en-US', { | ||
style: 'currency', | ||
currency: 'EUR' | ||
}).format(amount) | ||
return h('div', { class: 'text-right font-medium' }, formatted) | ||
} | ||
}] | ||
const table = useTemplateRef('table') | ||
const columnFilters = ref([{ | ||
id: 'email', | ||
value: 'james' | ||
}]) | ||
</script> | ||
|
||
<template> | ||
<div class="flex flex-col flex-1"> | ||
<div class="flex px-4 py-3.5 border-b border-[var(--ui-border-accented)]"> | ||
<UInput | ||
:model-value="(table?.tableApi?.getColumn('email')?.getFilterValue() as string)" | ||
class="max-w-sm" | ||
placeholder="Filter emails..." | ||
@update:model-value="table?.tableApi?.getColumn('email')?.setFilterValue($event)" | ||
/> | ||
</div> | ||
|
||
<UTable | ||
ref="table" | ||
v-model:column-filters="columnFilters" | ||
:data="data" | ||
:columns="columns" | ||
/> | ||
</div> | ||
</template> |
114 changes: 114 additions & 0 deletions
114
docs/app/components/content/examples/table/TableColumnPinningExample.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<script setup lang="ts"> | ||
import { h, resolveComponent } from 'vue' | ||
import type { TableColumn } from '@nuxt/ui' | ||
import type { Column } from '@tanstack/vue-table' | ||
const UBadge = resolveComponent('UBadge') | ||
const UButton = resolveComponent('UButton') | ||
type Payment = { | ||
id: string | ||
date: string | ||
status: 'paid' | 'failed' | 'refunded' | ||
email: string | ||
amount: number | ||
} | ||
const data = ref<Payment[]>([{ | ||
id: '46000000000000000000000000000000000000000', | ||
date: '2024-03-11T15:30:00', | ||
status: 'paid', | ||
email: '[email protected]', | ||
amount: 594000 | ||
}, { | ||
id: '45990000000000000000000000000000000000000', | ||
date: '2024-03-11T10:10:00', | ||
status: 'failed', | ||
email: '[email protected]', | ||
amount: 276000 | ||
}, { | ||
id: '45980000000000000000000000000000000000000', | ||
date: '2024-03-11T08:50:00', | ||
status: 'refunded', | ||
email: '[email protected]', | ||
amount: 315000 | ||
}, { | ||
id: '45970000000000000000000000000000000000000', | ||
date: '2024-03-10T19:45:00', | ||
status: 'paid', | ||
email: '[email protected]', | ||
amount: 5290000 | ||
}, { | ||
id: '45960000000000000000000000000000000000000', | ||
date: '2024-03-10T15:55:00', | ||
status: 'paid', | ||
email: '[email protected]', | ||
amount: 639000 | ||
}]) | ||
const columns: TableColumn<Payment>[] = [{ | ||
accessorKey: 'id', | ||
header: ({ column }) => getHeader(column, 'ID', 'left'), | ||
cell: ({ row }) => `#${row.getValue('id')}` | ||
}, { | ||
accessorKey: 'date', | ||
header: ({ column }) => getHeader(column, 'Date', 'left') | ||
}, { | ||
accessorKey: 'status', | ||
header: ({ column }) => getHeader(column, 'Status', 'left'), | ||
cell: ({ row }) => { | ||
const color = ({ | ||
paid: 'success' as const, | ||
failed: 'error' as const, | ||
refunded: 'neutral' as const | ||
})[row.getValue('status') as string] | ||
return h(UBadge, { class: 'capitalize', variant: 'subtle', color }, () => row.getValue('status')) | ||
} | ||
}, { | ||
accessorKey: 'email', | ||
header: ({ column }) => getHeader(column, 'Email', 'left') | ||
}, { | ||
accessorKey: 'amount', | ||
header: ({ column }) => h('div', { class: 'text-right' }, getHeader(column, 'Amount', 'right')), | ||
cell: ({ row }) => { | ||
const amount = Number.parseFloat(row.getValue('amount')) | ||
const formatted = new Intl.NumberFormat('en-US', { | ||
style: 'currency', | ||
currency: 'EUR' | ||
}).format(amount) | ||
return h('div', { class: 'text-right font-medium' }, formatted) | ||
} | ||
}] | ||
function getHeader(column: Column<Payment>, label: string, position: 'left' | 'right') { | ||
const isPinned = column.getIsPinned() | ||
return h(UButton, { | ||
color: 'neutral', | ||
variant: 'ghost', | ||
label, | ||
icon: isPinned ? 'i-heroicons-star-20-solid' : 'i-heroicons-star', | ||
class: '-mx-2.5', | ||
onClick() { | ||
column.pin(isPinned === position ? false : position) | ||
} | ||
}) | ||
} | ||
const columnPinning = ref({ | ||
left: [], | ||
right: ['amount'] | ||
}) | ||
</script> | ||
|
||
<template> | ||
<UTable | ||
v-model:column-pinning="columnPinning" | ||
:data="data" | ||
:columns="columns" | ||
class="flex-1" | ||
/> | ||
</template> |
Oops, something went wrong.