Skip to content

Commit

Permalink
feat(table): allow conditionally showing action items (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Nov 13, 2023
1 parent b465414 commit 63aa857
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
5 changes: 4 additions & 1 deletion docs/components/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,10 @@ interface TableCellActions {
labelMode?: ColorModes

// Callback function when the button is clicked.
onClick(value: any, record: any): void
onClick(record: any): void

// Whether to show the button for the record.
show?(record: any): boolean
}

type ColorModes =
Expand Down
1 change: 0 additions & 1 deletion lib/components/STableCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ const computedCell = computed<TableCell | undefined>(() =>
/>
<STableCellActions
v-else-if="computedCell.type === 'actions'"
:value="value"
:record="record"
:actions="computedCell.actions"
/>
Expand Down
26 changes: 13 additions & 13 deletions lib/components/STableCellActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import { type TableCellAction } from '../composables/Table'
import SButton from './SButton.vue'
defineProps<{
value: any
record: any
actions: TableCellAction[]
}>()
</script>

<template>
<div class="STableCellActions">
<SButton
v-for="(action, i) in actions"
:key="i"
size="mini"
type="text"
:mode="action.mode ?? 'mute'"
:icon="action.icon"
:icon-mode="action.iconMode"
:label="action.label"
:label-mode="action.labelMode"
@click="action.onClick(value, record)"
/>
<template v-for="(action, i) in actions" :key="i">
<SButton
v-if="action.show == null || action.show(record)"
size="mini"
type="text"
:mode="action.mode ?? 'mute'"
:icon="action.icon"
:icon-mode="action.iconMode"
:label="action.label"
:label-mode="action.labelMode"
@click="action.onClick(record)"
/>
</template>
</div>
</template>
Expand Down
3 changes: 2 additions & 1 deletion lib/composables/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ export interface TableCellAction {
iconMode?: Mode
label?: string
labelMode?: Mode
onClick(value: any, record: any): void
onClick(record: any): void
show?(record: any): boolean
}

export interface TableMenu {
Expand Down

0 comments on commit 63aa857

Please sign in to comment.