Skip to content

Commit

Permalink
Initialisating KTable Component
Browse files Browse the repository at this point in the history
  • Loading branch information
BabyElias committed May 30, 2024
1 parent 3af2e28 commit 2f527c3
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/pages/ktable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<DocsPageTemplate apiDocs />
</template>
5 changes: 5 additions & 0 deletions docs/tableOfContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ export default [
isCode: true,
keywords: ['button'],
}),
new Page({
path: '/ktable',
title: 'KTable',
isCode: true,
}),
new Page({
path: '/kgrid',
title: 'KGrid',
Expand Down
56 changes: 56 additions & 0 deletions lib/KTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<template>

<div class="k-table">
<table>
<thead>
<tr>
<th v-for="(header,index) in headers" :key="index">
{{ header }}
</th>
</tr>
</thead>
<tbody>
<tr v-for="(row,index) in rows" :key="index">
<td v-for="(cell,cellIndex) in row" :key="cellIndex">
{{ cell }}
</td>
</tr>
</tbody>
</table>
</div>

</template>
<script>
export default {
name: 'KTable',
props: {
headers: {
type: Array,
required: true,
},
rows: {
type: Array,
required: true,
},
},
};
</script>
<style scoped>
.k-table{
margin:20px;
border-collapse:collapse;
}
.k-table table{
width:100%;
border:2px solid #ccc;
border-collapse:separate;
border-spacing:0;
}
.k-table th, .k-table td{
padding: 10px;
text-align:left;
}
</style>
2 changes: 2 additions & 0 deletions lib/KThemePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import KRadioButton from './KRadioButton';
import KRouterLink from './buttons-and-links/KRouterLink';
import KSelect from './KSelect';
import KSwitch from './KSwitch';
import KTable from './KTable'
import KTabs from './tabs/KTabs';
import KTabsList from './tabs/KTabsList';
import KTabsPanel from './tabs/KTabsPanel';
Expand Down Expand Up @@ -120,6 +121,7 @@ export default function KThemePlugin(Vue) {
Vue.component('KRouterLink', KRouterLink);
Vue.component('KSelect', KSelect);
Vue.component('KSwitch', KSwitch);
Vue.component('KTable', KTable);
Vue.component('KTabs', KTabs);
Vue.component('KTabsList', KTabsList);
Vue.component('KTabsPanel', KTabsPanel);
Expand Down
37 changes: 37 additions & 0 deletions lib/__tests__/KTable.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {shallowMount} from '@vue/test-utils'
import KTable from '../../lib/KTable.vue';

describe('KTable.vue',()=>{
it('should mount the component',()=>{
const headers=['Name','Age','City']
const rows=[
['Alice',25,'New York'],
['Bob',30,'Los Angeles'],
['Charlie',35,'San Francisco']
]
const wrapper=shallowMount(KTable,{
propsData:{
headers,
rows
}
})
const thElements=wrapper.findAll('th')
expect(thElements.length).toBe(headers.length)
})
it('should render correct number of rows',()=>{
const headers=['Name','Age','City']
const rows=[
['Alice',25,'New York'],
['Bob',30,'Los Angeles'],
['Charlie',35,'San Francisco']
]
const wrapper=shallowMount(KTable,{
propsData:{
headers,
rows
}
})
const trElements=wrapper.findAll('tbody tr')
expect(trElements.length).toBe(rows.length+1)
})
})

0 comments on commit 2f527c3

Please sign in to comment.