feat: added hoverable and striped states
This commit is contained in:
@@ -6,13 +6,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { provide } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
children: {
|
|
||||||
type: Array,
|
|
||||||
default() {
|
|
||||||
return []
|
|
||||||
},
|
|
||||||
},
|
|
||||||
striped: {
|
striped: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
@@ -21,10 +17,8 @@ const props = defineProps({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
className: {
|
|
||||||
type: String,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
provide('striped', props.striped)
|
||||||
|
provide('hoverable', props.hoverable)
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<tr class="bg-white dark:bg-gray-800 [&:not(:last-child)]:border-b [&:not(:last-child)]:dark:border-gray-700">
|
<tr :class="tableRowClasses">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</tr>
|
</tr>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
|
||||||
|
import { useTableRowClasses } from '@/components/Table/composables/tableRowClasses'
|
||||||
|
|
||||||
|
const { tableRowClasses } = useTableRowClasses()
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
26
src/components/Table/composables/tableRowClasses.ts
Normal file
26
src/components/Table/composables/tableRowClasses.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { computed, inject } from 'vue'
|
||||||
|
import type { Ref } from 'vue'
|
||||||
|
import classNames from 'classnames'
|
||||||
|
|
||||||
|
const baseClasses = 'bg-white dark:bg-gray-800 [&:not(:last-child)]:border-b [&:not(:last-child)]:dark:border-gray-700'
|
||||||
|
const stripedClasses = 'odd:bg-white even:bg-gray-50 odd:dark:bg-gray-800 even:dark:bg-gray-700 bg-white dark:border-gray-700 dark:bg-gray-800'
|
||||||
|
const hoverableClasses = 'hover:bg-gray-50 dark:hover:bg-gray-600'
|
||||||
|
|
||||||
|
export function useTableRowClasses(): { tableRowClasses: Ref<string> } {
|
||||||
|
const isStriped = inject('striped')
|
||||||
|
const isHoverable = inject('hoverable')
|
||||||
|
|
||||||
|
const tableRowClasses = computed(() => {
|
||||||
|
return classNames(
|
||||||
|
baseClasses,
|
||||||
|
{
|
||||||
|
[stripedClasses]: isStriped,
|
||||||
|
[hoverableClasses]: isHoverable,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
tableRowClasses,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user