Skip to content

Commit

Permalink
refactor: remove checkbox prop
Browse files Browse the repository at this point in the history
Implicitly conveyed via the `selectedRows` prop
  • Loading branch information
jamesgeorge007 committed Mar 1, 2024
1 parent 53c54f9 commit dba62f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
13 changes: 4 additions & 9 deletions src/components/smart/Table.vue
Expand Up @@ -31,7 +31,7 @@
<tr
class="border-b border-dividerDark bg-primaryLight text-left text-sm text-secondary"
>
<th v-if="checkbox" class="w-24">
<th v-if="selectedRows" class="w-24">
<input
ref="selectAllCheckbox"
type="checkbox"
Expand Down Expand Up @@ -81,7 +81,7 @@
:class="{ 'divide-x divide-divider': showYBorder }"
@click="onRowClicked(rowData)"
>
<td v-if="checkbox">
<td v-if="selectedRows">
<input
type="checkbox"
:checked="isRowSelected(rowData)"
Expand Down Expand Up @@ -142,10 +142,6 @@ const props = withDefaults(
list: Item[]
/** The headings of the table */
headings?: CellHeading[]
/** Whether to show the checkbox column
* This will be overriden if custom implementation for body slot is provided
*/
checkbox?: boolean

selectedRows?: Item[]
/** Whether to enable sorting */
Expand All @@ -165,7 +161,6 @@ const props = withDefaults(
}>(),
{
showYBorder: false,
checkbox: false,
sort: undefined,
selectedRows: undefined,
loading: false,
Expand Down Expand Up @@ -208,7 +203,7 @@ const workingList = useVModel(props, "list", emit)
const selectedRows = useVModel(props, "selectedRows", emit)

watch(workingList.value, (updatedList) => {
if (props.checkbox) {
if (props.selectedRows) {
updatedList = updatedList.map((item) => ({
...item,
selected: false,
Expand Down Expand Up @@ -288,6 +283,6 @@ watch(
)

const columnSpan = computed(
() => (props.headings?.length ?? 0) + (props.checkbox ? 1 : 0),
() => (props.headings?.length ?? 0) + (props.selectedRows ? 1 : 0),
)
</script>
7 changes: 3 additions & 4 deletions src/stories/Table.story.vue
Expand Up @@ -5,7 +5,6 @@
:headings="headings"
:loading="loading"
:list="finalList"
:checkbox="true"
:selected-rows="selectedRows"
:pagination="{ totalPages: 2 }"
@page-number="handlePageChange"
Expand Down Expand Up @@ -59,7 +58,6 @@
:headings="headings"
:loading="loading"
:list="extensionList"
:checkbox="true"
:selected-rows="selectedRows"
:sort="{ key: 'name', direction: sortDirection }"
@page-number="handlePageChange"
Expand Down Expand Up @@ -90,10 +88,11 @@

<script setup lang="ts">
import { computed, onMounted, ref, Ref } from "vue"

import { CellHeading, Direction } from "~/components/smart/Table.vue"
import IconArrowUpDown from "~icons/lucide/arrow-up-down"
import { HoppButtonPrimary, HoppSmartInput } from ".."
import { HoppSmartTable, HoppSmartSpinner } from "../components/smart"
import { HoppSmartSpinner, HoppSmartTable } from "../components/smart"

type List = {
id: string
Expand Down Expand Up @@ -148,10 +147,10 @@ const secondaryList: List[] = [
onMounted(async () => {
loading.value = true

// Simulate network call
await new Promise((resolve) => setTimeout(resolve, 1000))

finalList.value = primaryList

loading.value = false
})

Expand Down

0 comments on commit dba62f1

Please sign in to comment.