Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: PTable #1236

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions demo/sections/components/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,14 @@
const columns = computed<TableColumn<Data>[]>(() => [
{
property: 'first_name',
label: 'First Name',
label: 'First Name (or given name)',
minWidth: 'min-content',
width: '120px',
maxWidth: '400px',
},
{
property: 'last_name',
label: 'Last Name',
label: 'Last Name (or family name)',
width: '120px',
},
{
Expand Down
12 changes: 6 additions & 6 deletions src/components/Table/PTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</template>

<template v-for="column in visibleColumns" :key="column">
<PTableHeader :style="getColumnStyle(column)">
<PTableHeader :style="getColumnStyle(column)" :title="column.label">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the way these slots are implemented, these title attributes will always work off the passed label and won't display any custom content - I think this is fine but open to pushback if that's not a clear devex.

<slot :name="`${kebabCase(column.label)}-heading`" v-bind="{ column }">
{{ column.label }}
</slot>
Expand All @@ -31,7 +31,7 @@
</template>

<template v-for="(column, columnIndex) in visibleColumns" :key="column">
<PTableData :class="getColumnClasses(column, getValue(row, column.property), columnIndex, row, rowIndex)">
<PTableData :class="getColumnClasses(column, getValue(row, column.property), columnIndex, row, rowIndex)" :title="getValue(row, column.property)">
<slot :name="kebabCase(column.label)" :value="getValue(row, column.property)" v-bind="{ column, row }">
{{ getValue(row, column.property) }}
</slot>
Expand Down Expand Up @@ -118,12 +118,10 @@
const visibleColumns = computed<TColumn[]>(() => columns.value.filter(column => column.visible ?? true))

function getColumnStyle(column: TColumn): StyleValue {
if (column.width === undefined) {
return ''
}

return {
width: column.width,
minWidth: column.minWidth ?? column.width ?? 0,
maxWidth: column.maxWidth ?? column.width,
}
}

Expand Down Expand Up @@ -177,6 +175,8 @@
overflow-hidden
overflow-x-auto
rounded-default
border
border-divider
}

.p-table__table { @apply
Expand Down
3 changes: 2 additions & 1 deletion src/components/Table/PTableData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
.p-table-data { @apply
whitespace-nowrap
px-3
py-4
py-3
text-sm
truncate
}
</style>
2 changes: 1 addition & 1 deletion src/components/Table/PTableHead.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<thead class="p-table-head p-background">
<thead class="p-table-head">
<slot>
<PTableRow>
<slot name="row" />
Expand Down
5 changes: 3 additions & 2 deletions src/components/Table/PTableHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<style>
.p-table-header { @apply
px-3
py-3.5
py-3
text-sm
font-semibold
font-bold
whitespace-nowrap
truncate
text-left
}
</style>
2 changes: 2 additions & 0 deletions src/types/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export type TableData = Record<string, any>
export type TableColumn<T extends TableData = Record<never, never>> = {
label: string,
property?: T extends T ? keyof T : never,
maxWidth?: string,
minWidth?: string,
width?: string,
visible?: boolean,
disabled?: boolean,
Expand Down
Loading