Skip to content

Commit

Permalink
feat(table): add onClick option to TableCellAvatar (#291) (#292)
Browse files Browse the repository at this point in the history
close #291

---------

Co-authored-by: Kia King Ishii <kia.king.08@gmail.com>
  • Loading branch information
NozomuIkuta and kiaking committed May 31, 2023
1 parent 8fb554d commit ab0111c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/components/STableCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const computedCell = computed<TableCell | undefined>(() =>
:name="computedCell.name"
:link="computedCell.link"
:color="computedCell.color"
:on-click="computedCell.onClick"
/>
<STableCellAvatars
v-else-if="computedCell.type === 'avatars'"
Expand Down
10 changes: 8 additions & 2 deletions lib/components/STableCellAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const props = defineProps<{
name?: string | null | ((value: any, record: any) => string | null | undefined)
link?: string | null | ((value: any, record: any) => string | null | undefined)
color?: 'neutral' | 'soft' | 'mute'
onClick?(value: any, record: any): void
}>()
const _image = computed(() => resolve(props.image))
Expand All @@ -30,8 +31,13 @@ function resolve(
</script>

<template>
<div class="STableCellAvatar" :class="[{ link }, color]">
<SLink class="container" :href="_link ?? undefined">
<div class="STableCellAvatar" :class="[{ link: link || onClick }, color]">
<SLink
class="container"
:href="_link ?? undefined"
:role="onClick ? 'button' : null"
@click="() => onClick?.(value, record)"
>
<div v-if="_image" class="avatar">
<SAvatar size="mini" :avatar="_image" :name="_name" />
</div>
Expand Down
1 change: 1 addition & 0 deletions lib/composables/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export interface TableCellAvatar extends TableCellBase {
name?: string | null | ((value: any, record: any) => string | null | undefined)
link?: string | null | ((value: any, record: any) => string | null | undefined)
color?: 'neutral' | 'soft' | 'mute'
onClick?(value: any, record: any): void
}

export interface TableCellAvatars extends TableCellBase {
Expand Down

0 comments on commit ab0111c

Please sign in to comment.