Merge pull request #114 from assasin0076/feat_table
feat: added table component
This commit is contained in:
@@ -1,104 +1,29 @@
|
||||
<template>
|
||||
<div class="relative overflow-x-auto shadow-md sm:rounded-lg">
|
||||
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400">
|
||||
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3">
|
||||
Product name
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3">
|
||||
Color
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3">
|
||||
Category
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3">
|
||||
Price
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3">
|
||||
<span class="sr-only">Edit</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700">
|
||||
<th scope="row" class="px-6 py-4 font-medium text-gray-900 dark:text-white whitespace-nowrap">
|
||||
Apple MacBook Pro 17"
|
||||
</th>
|
||||
<td class="px-6 py-4">
|
||||
Sliver
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
Laptop
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
$2999
|
||||
</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<a href="#" class="font-medium text-blue-600 dark:text-blue-500 hover:underline">Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700">
|
||||
<th scope="row" class="px-6 py-4 font-medium text-gray-900 dark:text-white whitespace-nowrap">
|
||||
Microsoft Surface Pro
|
||||
</th>
|
||||
<td class="px-6 py-4">
|
||||
White
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
Laptop PC
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
$1999
|
||||
</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<a href="#" class="font-medium text-blue-600 dark:text-blue-500 hover:underline">Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="bg-white dark:bg-gray-800">
|
||||
<th scope="row" class="px-6 py-4 font-medium text-gray-900 dark:text-white whitespace-nowrap">
|
||||
Magic Mouse 2
|
||||
</th>
|
||||
<td class="px-6 py-4">
|
||||
Black
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
Accessories
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
$99
|
||||
</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<a href="#" class="font-medium text-blue-600 dark:text-blue-500 hover:underline">Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<slot></slot>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { computed, toRefs } from 'vue'
|
||||
import type { PropType } from 'vue'
|
||||
import { provide } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
children: {
|
||||
type: Array,
|
||||
default() {
|
||||
return []
|
||||
},
|
||||
},
|
||||
striped: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
stripedColumns: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
hoverable: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
className: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
})
|
||||
|
||||
provide('striped', props.striped)
|
||||
provide('hoverable', props.hoverable)
|
||||
provide('stripedColumns', props.stripedColumns)
|
||||
</script>
|
||||
|
||||
7
src/components/Table/TableBody.vue
Normal file
7
src/components/Table/TableBody.vue
Normal file
@@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<tbody>
|
||||
<slot></slot>
|
||||
</tbody>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
</script>
|
||||
11
src/components/Table/TableCell.vue
Normal file
11
src/components/Table/TableCell.vue
Normal file
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<td :class="tableCellClasses">
|
||||
<slot></slot>
|
||||
</td>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
|
||||
import { useTableCellClasses } from '@/components/Table/composables/useTableCellClasses'
|
||||
|
||||
const { tableCellClasses } = useTableCellClasses()
|
||||
</script>
|
||||
9
src/components/Table/TableHead.vue
Normal file
9
src/components/Table/TableHead.vue
Normal file
@@ -0,0 +1,9 @@
|
||||
<template>
|
||||
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
||||
<tr>
|
||||
<slot></slot>
|
||||
</tr>
|
||||
</thead>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
</script>
|
||||
10
src/components/Table/TableHeadCell.vue
Normal file
10
src/components/Table/TableHeadCell.vue
Normal file
@@ -0,0 +1,10 @@
|
||||
<template>
|
||||
<th scope="col" :class="tableHeadCellClasses">
|
||||
<slot></slot>
|
||||
</th>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { useTableHeadCellClasses } from '@/components/Table/composables/useTableHeadCellClasses'
|
||||
|
||||
const { tableHeadCellClasses } = useTableHeadCellClasses()
|
||||
</script>
|
||||
10
src/components/Table/TableRow.vue
Normal file
10
src/components/Table/TableRow.vue
Normal file
@@ -0,0 +1,10 @@
|
||||
<template>
|
||||
<tr :class="tableRowClasses">
|
||||
<slot></slot>
|
||||
</tr>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { useTableRowClasses } from '@/components/Table/composables/useTableRowClasses'
|
||||
|
||||
const { tableRowClasses } = useTableRowClasses()
|
||||
</script>
|
||||
20
src/components/Table/composables/useTableCellClasses.ts
Normal file
20
src/components/Table/composables/useTableCellClasses.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { computed, inject } from 'vue'
|
||||
import type { Ref } from 'vue'
|
||||
import classNames from 'classnames'
|
||||
|
||||
const baseClasses = 'px-6 py-4 first:font-medium first:text-gray-900 first:dark:text-white first:whitespace-nowrap last:text-right'
|
||||
const stripedCellClasses = 'even:bg-gray-white even:dark:bg-gray-900 odd:dark:bg-gray-800 odd:bg-gray-50'
|
||||
|
||||
export function useTableCellClasses(): { tableCellClasses: Ref<string> } {
|
||||
const isColumnsStriped = inject('stripedColumns')
|
||||
|
||||
const tableCellClasses = computed(() => {
|
||||
return classNames(baseClasses, {
|
||||
[stripedCellClasses]: isColumnsStriped,
|
||||
})
|
||||
})
|
||||
|
||||
return {
|
||||
tableCellClasses,
|
||||
}
|
||||
}
|
||||
20
src/components/Table/composables/useTableHeadCellClasses.ts
Normal file
20
src/components/Table/composables/useTableHeadCellClasses.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { computed, inject } from 'vue'
|
||||
import type { Ref } from 'vue'
|
||||
import classNames from 'classnames'
|
||||
|
||||
const baseClasses = 'px-6 py-3 text-xs uppercase'
|
||||
const stripedHeadCellClasses = 'even:bg-white even:dark:bg-gray-900 odd:dark:bg-gray-800 odd:bg-gray-50'
|
||||
|
||||
export function useTableHeadCellClasses(): { tableHeadCellClasses: Ref<string> } {
|
||||
const isColumnsStriped = inject('stripedColumns')
|
||||
|
||||
const tableHeadCellClasses = computed(() => {
|
||||
return classNames(baseClasses, {
|
||||
[stripedHeadCellClasses]: isColumnsStriped,
|
||||
})
|
||||
})
|
||||
|
||||
return {
|
||||
tableHeadCellClasses,
|
||||
}
|
||||
}
|
||||
23
src/components/Table/composables/useTableRowClasses.ts
Normal file
23
src/components/Table/composables/useTableRowClasses.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
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'
|
||||
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,
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,11 @@ export { default as Progress } from './components/Progress/Progress.vue'
|
||||
export { default as Rating } from './components/Rating/Rating.vue'
|
||||
export { default as Sidebar } from './components/Sidebar/Sidebar.vue'
|
||||
export { default as Table } from './components/Table/Table.vue'
|
||||
export { default as TableHead } from './components/Table/TableHead.vue'
|
||||
export { default as TableBody } from './components/Table/TableBody.vue'
|
||||
export { default as TableHeadCell } from './components/Table/TableHeadCell.vue'
|
||||
export { default as TableRow } from './components/Table/TableRow.vue'
|
||||
export { default as TableCell } from './components/Table/TableCell.vue'
|
||||
export { default as Timeline } from './components/Timeline/Timeline.vue'
|
||||
export { default as Toast } from './components/Toast/Toast.vue'
|
||||
export { default as ToastProvider } from './components/Toast/components/ToastProvider/ToastProvider.vue'
|
||||
|
||||
Reference in New Issue
Block a user