-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #727 from BabyElias/gsoc-table-develop
Initial Implementation Of KTable Component
- Loading branch information
Showing
12 changed files
with
1,167 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<template> | ||
|
||
<DocsPageTemplate apiDocs> | ||
<DocsPageSection title="Overview" anchor="#overview"> | ||
<p> | ||
The <code>KTable</code> component is an accessible and customizable table component designed to handle a variety of data presentation needs. The component is suitable for both simple and complex data tables. It offers: | ||
<ul> | ||
<li>Offers built-in sorting by default</li> | ||
<li>Integrates with already sorted data</li> | ||
<li>Keyboard navigation</li> | ||
<li>Dynamic column resizing</li> | ||
<li>Sticky headers</li> | ||
</ul> | ||
</p> | ||
</DocsPageSection> | ||
<DocsPageSection title="Usage" anchor="#usage"> | ||
<!--Non-Sortable Table--> | ||
<h3>Table without sorting functionality</h3> | ||
<p> | ||
This is an example to show how <code>KTable</code> can be used without any sorting functionality, as a simple table. Use of slots is optional. | ||
</p> | ||
<!-- eslint-disable --> | ||
<DocsShowCode language="html"> | ||
<KTable | ||
:headers="headers" | ||
:rows="rows" | ||
caption="Non Sortable Table" | ||
> | ||
|
||
<template #header="{ header, colIndex }"> | ||
<span>{ header.label } (Backend)</span> | ||
</template> | ||
<template #cell="{ content, rowIndex, colIndex }"> | ||
<span v-if="colIndex === 2">{ content } (City)</span> | ||
<span v-else>{ content }</span> | ||
</template> | ||
</KTable> | ||
|
||
</DocsShowCode> | ||
|
||
<DocsShowCode language="javascript"> | ||
data() { | ||
return { | ||
headers: [ | ||
{ label: 'Name', dataType: 'string' }, | ||
{ label: 'Age', dataType: 'number' }, | ||
{ label: 'City', dataType: 'string' }, | ||
], | ||
rows: [ | ||
['John Doe', 28, 'New York'], | ||
['Jane Smith', 34, 'Los Angeles'], | ||
['Samuel Green', 22, 'Chicago'], | ||
['Alice Johnson', 30, 'Houston'], | ||
['Michael Brown', 45, 'Phoenix'], | ||
['Emily Davis', 27, 'Philadelphia'], | ||
] | ||
}; | ||
}, | ||
</DocsShowCode> | ||
|
||
<DocsShow block> | ||
<KTable | ||
:headers="headers" | ||
:rows="rows" | ||
caption="Non-sortable table" | ||
> | ||
<template #header="{ header, colIndex }"> | ||
<span>{{ header.label }} (Backend)</span> | ||
</template> | ||
<template #cell="{ content, rowIndex, colIndex }"> | ||
<span v-if="colIndex === 2">{{ content }} (City)</span> | ||
<span v-else>{{ content }}</span> | ||
</template> | ||
</KTable> | ||
</DocsShow> | ||
|
||
<!-- Frontend Sorting Example--> | ||
<h3>Table with Default Sorting</h3> | ||
<p> | ||
The <code>KTable</code> can be used with default sorting functionality, allowing you to sort data on the client side without the need for server requests. There are 4 permissible data types - <code>string</code>,<code>number</code>,<code>date</code> and <code>undefined</code>. Columns declared with <code>undefined</code> data type are not sortable. This example demonstrates a table with default sorting enabled. | ||
</p> | ||
|
||
<DocsShowCode language="html"> | ||
<KTable | ||
:headers="headers" | ||
:rows="rows" | ||
caption="Table with built-in sorting" | ||
sortable | ||
/> | ||
|
||
</DocsShowCode> | ||
|
||
<DocsShowCode language="javascript"> | ||
data() { | ||
return { | ||
headers: [ | ||
{ label: 'Name', dataType: 'string' }, | ||
{ label: 'Age', dataType: 'number' }, | ||
{ label: 'City', dataType: 'string' }, | ||
], | ||
rows: [ | ||
['John Doe', 28, 'New York'], | ||
['Jane Smith', 34, 'Los Angeles'], | ||
['Samuel Green', 22, 'Chicago'], | ||
['Alice Johnson', 30, 'Houston'], | ||
['Michael Brown', 45, 'Phoenix'], | ||
['Emily Davis', 27, 'Philadelphia'], | ||
] | ||
}; | ||
}, | ||
</DocsShowCode> | ||
<DocsShow block> | ||
<KTable | ||
:headers="headers" | ||
:rows="rows" | ||
caption="Local Sorting Table" | ||
sortable | ||
/> | ||
<!-- eslint-enable --> | ||
</DocsShow> | ||
|
||
</DocsPageSection> | ||
|
||
|
||
</DocsPageTemplate> | ||
|
||
</template> | ||
|
||
|
||
<script> | ||
export default { | ||
name: 'DocsKTable', | ||
data() { | ||
return { | ||
headers: [ | ||
{ label: 'Name', dataType: 'string' }, | ||
{ label: 'Age', dataType: 'number' }, | ||
{ label: 'City', dataType: 'string' }, | ||
], | ||
rows: [ | ||
['John Doe', 28, 'New York'], | ||
['Jane Smith', 34, 'Los Angeles'], | ||
['Samuel Green', 22, 'Chicago'], | ||
['Alice Johnson', 30, 'Houston'], | ||
['Michael Brown', 45, 'Phoenix'], | ||
['Emily Davis', 27, 'Philadelphia'], | ||
], | ||
}; | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<template> | ||
|
||
<svg viewBox="0 0 24 24" role="presentation" focusable="false" width="24" height="25" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12.178 4.154l5.177 5.523H7l5.177-5.523zM12.177 20.654L7 15.13h10.354l-5.177 5.524z" fill="#000"/></svg> | ||
|
||
</template> | ||
|
||
|
||
<script> | ||
export default {"name":"icon-804c4e229f501f72a23ba2f5a5cc42d5"} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<template> | ||
|
||
<td | ||
:class="$computedClass(coreOutlineFocus)" | ||
:style="{ textAlign: textAlign, minWidth: minWidth, width: width }" | ||
tabindex="0" | ||
data-focus="true" | ||
role="gridcell" | ||
@keydown="onKeydown" | ||
> | ||
<slot :content="content"> | ||
{{ content }} | ||
</slot> | ||
</td> | ||
|
||
</template> | ||
|
||
|
||
<script> | ||
export default { | ||
name: 'KTableGridItem', | ||
props: { | ||
content: { | ||
type: [String, Number, Boolean, Object, Array], | ||
required: true, | ||
}, | ||
rowIndex: { | ||
type: Number, | ||
required: true, | ||
}, | ||
colIndex: { | ||
type: Number, | ||
required: true, | ||
}, | ||
minWidth: { | ||
type: String, | ||
default: 'auto', | ||
}, | ||
width: { | ||
type: String, | ||
default: 'auto', | ||
}, | ||
textAlign: { | ||
type: String, | ||
required: true, | ||
}, | ||
}, | ||
computed: { | ||
coreOutlineFocus() { | ||
return { | ||
':focus': { | ||
...this.$coreOutline, | ||
outlineOffset: '-2px', | ||
}, | ||
}; | ||
}, | ||
}, | ||
methods: { | ||
onKeydown(event) { | ||
// Ensures that clickable elements within a table cell, such as buttons and links, can be clicked with ENTER key. | ||
const focusedElement = event.target; | ||
if ( | ||
event.key === 'Enter' && | ||
(focusedElement.tagName === 'BUTTON' || focusedElement.tagName === 'A') | ||
) { | ||
focusedElement.click(); | ||
} else { | ||
this.$emit('keydown', event, this.rowIndex, this.colIndex); | ||
} | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
|
||
<style scoped> | ||
td { | ||
word-wrap: break-word; | ||
white-space: normal; | ||
} | ||
</style> |
Oops, something went wrong.