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

Feat/table expandable row add the click event to the entire line #264

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
1 change: 1 addition & 0 deletions packages/components/table/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface PuikTableHeader {
align?: 'left' | 'center' | 'right'
width?: string
sortable?: boolean
preventExpand?: boolean
}

export const tableProps = buildProps({
Expand Down
7 changes: 7 additions & 0 deletions packages/components/table/src/table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
`puik-table__body__row__item puik-table__body__row__item--${
header.align ?? 'left'
}`,
{
'puik-table__body__row__item--expand-row':
expandable && !header?.preventExpand,
},
{ 'puik-table__body__row__item--sticky': isSticky(colIndex) },
{
'puik-table__body__row__item--sticky-scroll':
Expand All @@ -162,6 +166,9 @@
ScrollBarPosition == PuikTableScrollBarPosistion.Right,
},
]"
@click="
expandable && !header?.preventExpand ? expandRow(rowIndex) : ''
"
>
<div class="puik-table__body__row__item__container">
<div class="puik-table__body__row__item__content">
Expand Down
35 changes: 19 additions & 16 deletions packages/components/table/stories/table.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,23 @@ export default {
width: string | undefined
align: 'left' | 'center' | 'right' | undefined
sortable: boolean | undefined
preventExpand: boolean | undefined
}
`,
},
},
},
selectable: {
expandable: {
control: 'boolean',
description: 'Makes rows selectable',
description: 'Makes rows expandable',
table: {
type: { summary: 'boolean' },
defaultValue: { summary: 'false' },
},
},
expandable: {
selectable: {
control: 'boolean',
description: 'Makes rows expandable',
description: 'Makes rows selectable',
table: {
type: { summary: 'boolean' },
defaultValue: { summary: 'false' },
Expand Down Expand Up @@ -241,6 +242,7 @@ const Template: StoryFn = (args: Args) => ({
{
value: 'actions',
size: 'sm',
preventExpand: true,
},
]
return { args, headers, items, selection }
Expand Down Expand Up @@ -656,6 +658,7 @@ export const Expandable: StoryObj = {
{
value: 'actions',
size: 'sm',
preventExpand: true,
},
]

Expand Down Expand Up @@ -688,10 +691,10 @@ export const Expandable: StoryObj = {
<div class="puik-icon" style="font-size: 24px;">keyboard_arrow_down</div>
</div>
</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left">lastname0</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left">firstname0</td>
<td class="puik-table__body__row__item puik-table__body__row__item--center">40</td>
<td class="puik-table__body__row__item puik-table__body__row__item--right">[email protected]</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left puik-table__body__row__item--expand-row">lastname0</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left puik-table__body__row__item--expand-row">firstname0</td>
<td class="puik-table__body__row__item puik-table__body__row__item--center puik-table__body__row__item--expand-row">40</td>
<td class="puik-table__body__row__item puik-table__body__row__item--right puik-table__body__row__item--expand-row">[email protected]</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left">
<button class="puik-button puik-button--text puik-button--md" aria-label="Delete item">
<div class="puik-icon puik-button__right-icon" style="font-size: 1.25rem;">delete</div>
Expand All @@ -705,10 +708,10 @@ export const Expandable: StoryObj = {
<div class="puik-icon" style="font-size: 24px;">keyboard_arrow_down</div>
</div>
</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left">lastname1</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left">firstname1</td>
<td class="puik-table__body__row__item puik-table__body__row__item--center">40</td>
<td class="puik-table__body__row__item puik-table__body__row__item--right">[email protected]</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left puik-table__body__row__item--expand-row">lastname1</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left puik-table__body__row__item--expand-row">firstname1</td>
<td class="puik-table__body__row__item puik-table__body__row__item--center puik-table__body__row__item--expand-row">40</td>
<td class="puik-table__body__row__item puik-table__body__row__item--right puik-table__body__row__item--expand-row">[email protected]</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left">
<button class="puik-button puik-button--text puik-button--md" aria-label="Delete item">
<div class="puik-icon puik-button__right-icon" style="font-size: 1.25rem;">delete</div>
Expand All @@ -721,10 +724,10 @@ export const Expandable: StoryObj = {
<div class="puik-icon" style="font-size: 24px;">keyboard_arrow_down</div>
</div>
</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left">lastname2</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left">firstname2</td>
<td class="puik-table__body__row__item puik-table__body__row__item--center">40</td>
<td class="puik-table__body__row__item puik-table__body__row__item--right">[email protected]</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left puik-table__body__row__item--expand-row">lastname2</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left puik-table__body__row__item--expand-row">firstname2</td>
<td class="puik-table__body__row__item puik-table__body__row__item--center puik-table__body__row__item--expand-row">40</td>
<td class="puik-table__body__row__item puik-table__body__row__item--right puik-table__body__row__item--expand-row">[email protected]</td>
<td class="puik-table__body__row__item puik-table__body__row__item--left">
<button class="puik-button puik-button--text puik-button--md" aria-label="Delete item">
<div class="puik-icon puik-button__right-icon" style="font-size: 1.25rem;">delete</div>
Expand Down
4 changes: 4 additions & 0 deletions packages/theme/src/table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,8 @@
.puik-table__head__row__item--right.puik-table__head__row__item--sortable {
@apply pr-2;
}

.puik-table__body__row__item--expand-row {
@apply cursor-pointer;
}
}
Loading