From 2f527c35e24bbc4281e9b29437379f918bb56a95 Mon Sep 17 00:00:00 2001 From: callmeroot Date: Thu, 30 May 2024 21:18:04 +0530 Subject: [PATCH 01/78] Initialisating KTable Component --- docs/pages/ktable.vue | 3 ++ docs/tableOfContents.js | 5 ++++ lib/KTable.vue | 56 ++++++++++++++++++++++++++++++++++++ lib/KThemePlugin.js | 2 ++ lib/__tests__/KTable.spec.js | 37 ++++++++++++++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 docs/pages/ktable.vue create mode 100644 lib/KTable.vue create mode 100644 lib/__tests__/KTable.spec.js diff --git a/docs/pages/ktable.vue b/docs/pages/ktable.vue new file mode 100644 index 000000000..180c372c0 --- /dev/null +++ b/docs/pages/ktable.vue @@ -0,0 +1,3 @@ + diff --git a/docs/tableOfContents.js b/docs/tableOfContents.js index c6aa32e34..ba939da0d 100644 --- a/docs/tableOfContents.js +++ b/docs/tableOfContents.js @@ -321,6 +321,11 @@ export default [ isCode: true, keywords: ['button'], }), + new Page({ + path: '/ktable', + title: 'KTable', + isCode: true, + }), new Page({ path: '/kgrid', title: 'KGrid', diff --git a/lib/KTable.vue b/lib/KTable.vue new file mode 100644 index 000000000..5f979a743 --- /dev/null +++ b/lib/KTable.vue @@ -0,0 +1,56 @@ + + + \ No newline at end of file diff --git a/lib/KThemePlugin.js b/lib/KThemePlugin.js index 9e189f875..bc8af3ed9 100644 --- a/lib/KThemePlugin.js +++ b/lib/KThemePlugin.js @@ -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'; @@ -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); diff --git a/lib/__tests__/KTable.spec.js b/lib/__tests__/KTable.spec.js new file mode 100644 index 000000000..211de44dc --- /dev/null +++ b/lib/__tests__/KTable.spec.js @@ -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) + }) +}) \ No newline at end of file From 523168e4d15f38f2b645cb4dda5d175e871ae0b4 Mon Sep 17 00:00:00 2001 From: callmeroot Date: Thu, 30 May 2024 23:04:12 +0530 Subject: [PATCH 02/78] Initialised KTable (fixed linting) --- docs/pages/ktable.vue | 2 ++ lib/KThemePlugin.js | 2 +- lib/__tests__/KTable.spec.js | 70 ++++++++++++++++++------------------ 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/docs/pages/ktable.vue b/docs/pages/ktable.vue index 180c372c0..d6135544e 100644 --- a/docs/pages/ktable.vue +++ b/docs/pages/ktable.vue @@ -1,3 +1,5 @@ diff --git a/lib/KThemePlugin.js b/lib/KThemePlugin.js index bc8af3ed9..cc021fc54 100644 --- a/lib/KThemePlugin.js +++ b/lib/KThemePlugin.js @@ -26,7 +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 KTable from './KTable'; import KTabs from './tabs/KTabs'; import KTabsList from './tabs/KTabsList'; import KTabsPanel from './tabs/KTabsPanel'; diff --git a/lib/__tests__/KTable.spec.js b/lib/__tests__/KTable.spec.js index 211de44dc..04e62f3a0 100644 --- a/lib/__tests__/KTable.spec.js +++ b/lib/__tests__/KTable.spec.js @@ -1,37 +1,37 @@ -import {shallowMount} from '@vue/test-utils' +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) - }) -}) \ No newline at end of file +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); + }); +}); From 9109552587cb1f594d505be831c5b3dc10f6880e Mon Sep 17 00:00:00 2001 From: callmeroot Date: Thu, 30 May 2024 23:10:31 +0530 Subject: [PATCH 03/78] Fixed linting errors --- lib/KTable.vue | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/KTable.vue b/lib/KTable.vue index 5f979a743..e9400fd25 100644 --- a/lib/KTable.vue +++ b/lib/KTable.vue @@ -20,6 +20,8 @@ + + + + \ No newline at end of file diff --git a/lib/KTable/KTableGridItem.vue b/lib/KTable/KTableGridItem.vue new file mode 100644 index 000000000..08540978c --- /dev/null +++ b/lib/KTable/KTableGridItem.vue @@ -0,0 +1,49 @@ + + + + + + + \ No newline at end of file diff --git a/lib/KThemePlugin.js b/lib/KThemePlugin.js index cc021fc54..d9115a87b 100644 --- a/lib/KThemePlugin.js +++ b/lib/KThemePlugin.js @@ -26,7 +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 KTable from './KTable/KTable'; import KTabs from './tabs/KTabs'; import KTabsList from './tabs/KTabsList'; import KTabsPanel from './tabs/KTabsPanel'; diff --git a/lib/__tests__/KTable.spec.js b/lib/__tests__/KTable.spec.js index 27ddf58c4..6e8b2ad4c 100644 --- a/lib/__tests__/KTable.spec.js +++ b/lib/__tests__/KTable.spec.js @@ -1,5 +1,5 @@ import { shallowMount } from '@vue/test-utils'; -import KTable from '../../lib/KTable.vue'; +import KTable from '../../lib/KTable/KTable.vue'; describe('KTable.vue', () => { it('should mount the component', () => { From b85a6d38fe983904448ba33ff48f5ffa846665ef Mon Sep 17 00:00:00 2001 From: callmeroot Date: Mon, 3 Jun 2024 20:51:43 +0530 Subject: [PATCH 06/78] organised file structure --- lib/KTable.vue | 60 -------------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 lib/KTable.vue diff --git a/lib/KTable.vue b/lib/KTable.vue deleted file mode 100644 index e9400fd25..000000000 --- a/lib/KTable.vue +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - \ No newline at end of file From 2784a078d9f40c9a3a7277ddf801f1f1178837e1 Mon Sep 17 00:00:00 2001 From: callmeroot Date: Mon, 3 Jun 2024 21:03:59 +0530 Subject: [PATCH 07/78] added ktable to playground --- docs/pages/playground.vue | 27 +++- lib/KTable/KTable.vue | 289 +++++++++++++++++++------------------- 2 files changed, 169 insertions(+), 147 deletions(-) diff --git a/docs/pages/playground.vue b/docs/pages/playground.vue index 686423285..cce540ba7 100644 --- a/docs/pages/playground.vue +++ b/docs/pages/playground.vue @@ -21,6 +21,8 @@ { text: 'Level 2 ', link: { path: '#' } }, ]" /> --> + + @@ -36,12 +38,29 @@ so you can also use `data`, `methods`, etc. as usual if helpful */ + import KTable from '../../lib/KTable/KTable.vue'; + export default { name: 'Playground', - data() { - return {}; - }, - methods: {}, + components: { + KTable, + }, + data() { + return { + tableHeaders: [ + { label: 'Name', dataType: 'string' }, + { label: 'Age', dataType: 'numeric' }, + { label: 'Birth Date', dataType: 'date' }, + { label: 'City', dataType: 'string' }, + { label: 'Misc', dataType: 'others' }, + ], + tableRows: [ + ['Alice', 25, '1999-05-12', 'New York', 'Example'], + ['Bob', 30, '1994-02-22', 'San Francisco', 'Example'], + ['Charlie', 35, '1989-12-15', 'Chicago', 'Example'], + ], + }; + }, }; diff --git a/lib/KTable/KTable.vue b/lib/KTable/KTable.vue index 1ada93645..5cb0bc3c0 100644 --- a/lib/KTable/KTable.vue +++ b/lib/KTable/KTable.vue @@ -1,4 +1,5 @@ From 058e4c8b82181df03ef30b0642ce58f2c88928af Mon Sep 17 00:00:00 2001 From: callmeroot Date: Mon, 3 Jun 2024 21:57:13 +0530 Subject: [PATCH 08/78] fixed linting errors --- docs/pages/playground.vue | 48 +++++++++++++++++------------------ lib/KTable/KTable.vue | 7 ----- lib/KTable/KTableGridItem.vue | 4 +++ 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/docs/pages/playground.vue b/docs/pages/playground.vue index cce540ba7..554129b6d 100644 --- a/docs/pages/playground.vue +++ b/docs/pages/playground.vue @@ -22,7 +22,7 @@ ]" /> --> - + @@ -34,33 +34,33 @@ diff --git a/lib/KTable/KTable.vue b/lib/KTable/KTable.vue index 5cb0bc3c0..8d855e3a0 100644 --- a/lib/KTable/KTable.vue +++ b/lib/KTable/KTable.vue @@ -54,13 +54,6 @@ headers: { type: Array, required: true, - validator: function(value) { - return value.every( - header => - ['label', 'dataType'].every(key => key in header) && - ['string', 'numeric', 'date', 'others'].includes(header.dataType) - ); - }, }, rows: { type: Array, diff --git a/lib/KTable/KTableGridItem.vue b/lib/KTable/KTableGridItem.vue index 08540978c..2f65a0597 100644 --- a/lib/KTable/KTableGridItem.vue +++ b/lib/KTable/KTableGridItem.vue @@ -1,11 +1,14 @@ From b8db731b10a5f5aacb4cc2ebb27260dd413ce765 Mon Sep 17 00:00:00 2001 From: callmeroot Date: Mon, 3 Jun 2024 22:28:02 +0530 Subject: [PATCH 09/78] fixed linting errors --- lib/KTable/KTable.vue | 1 + lib/KTable/KTableGridItem.vue | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/KTable/KTable.vue b/lib/KTable/KTable.vue index 8d855e3a0..747f0776c 100644 --- a/lib/KTable/KTable.vue +++ b/lib/KTable/KTable.vue @@ -41,6 +41,7 @@ + - - + + \ No newline at end of file diff --git a/lib/KTable/KTableGridItem.vue b/lib/KTable/KTableGridItem.vue index 4e7eec564..fe3264eb3 100644 --- a/lib/KTable/KTableGridItem.vue +++ b/lib/KTable/KTableGridItem.vue @@ -1,7 +1,9 @@ @@ -16,22 +18,27 @@ type: [String, Number], required: true, }, - align: { + dataType: { type: String, - default: 'left', + default: 'string', }, rowIndex: { type: Number, required: true, }, - cellIndex: { + colIndex: { type: Number, required: true, }, }, + computed: { + textAlign() { + return this.dataType === 'numeric' ? 'right' : 'left'; + }, + }, methods: { onKeydown(event) { - this.$emit('keydown', event, this.rowIndex, this.cellIndex); + this.$emit('keydown', event, this.rowIndex, this.colIndex); }, }, }; @@ -40,14 +47,10 @@ \ No newline at end of file diff --git a/lib/KTable/index.vue b/lib/KTable/index.vue new file mode 100644 index 000000000..ab8a8a22e --- /dev/null +++ b/lib/KTable/index.vue @@ -0,0 +1,247 @@ + + + + + + + \ No newline at end of file diff --git a/lib/KTable/useSorting.js b/lib/KTable/useSorting.js new file mode 100644 index 000000000..97cbab03d --- /dev/null +++ b/lib/KTable/useSorting.js @@ -0,0 +1,55 @@ +import { ref, computed } from '@vue/composition-api'; + +export const SORT_ORDER_ASC = 'asc'; +export const SORT_ORDER_DESC = 'desc'; +export const DATA_TYPE_STRING = 'string'; +export const DATA_TYPE_NUMERIC = 'numeric'; +export const DATA_TYPE_DATE = 'date'; +export const DATA_TYPE_OTHERS = 'others'; + +export default function useSorting(headers, rows, useLocalSorting) { + const sortKey = ref(null); + const sortOrder = ref(null); + + const sortedRows = computed(() => { + if (!useLocalSorting.value || sortKey.value === null) return rows.value; + + return [...rows.value].sort((a, b) => { + const aValue = a[sortKey.value]; + const bValue = b[sortKey.value]; + + if (sortOrder.value === SORT_ORDER_ASC) { + return aValue > bValue ? 1 : aValue < bValue ? -1 : 0; + } else { + return aValue < bValue ? 1 : aValue > bValue ? -1 : 0; + } + }); + }); + + const handleSort = index => { + if (headers.value[index].dataType === DATA_TYPE_OTHERS) return; + + if (sortKey.value === index) { + sortOrder.value = sortOrder.value === SORT_ORDER_ASC ? SORT_ORDER_DESC : SORT_ORDER_ASC; + } else { + sortKey.value = index; + sortOrder.value = SORT_ORDER_ASC; + } + }; + + const getAriaSort = index => { + if (sortKey.value === index) { + return sortOrder.value === SORT_ORDER_ASC ? 'ascending' : 'descending'; + } else { + return 'none'; + } + }; + + return { + sortKey, + sortOrder, + sortedRows, + handleSort, + getAriaSort, + }; +} diff --git a/lib/KThemePlugin.js b/lib/KThemePlugin.js index d9115a87b..cc021fc54 100644 --- a/lib/KThemePlugin.js +++ b/lib/KThemePlugin.js @@ -26,7 +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/KTable'; +import KTable from './KTable'; import KTabs from './tabs/KTabs'; import KTabsList from './tabs/KTabsList'; import KTabsPanel from './tabs/KTabsPanel'; diff --git a/lib/__tests__/KTable.spec.js b/lib/__tests__/KTable.spec.js index 6e8b2ad4c..df85c5259 100644 --- a/lib/__tests__/KTable.spec.js +++ b/lib/__tests__/KTable.spec.js @@ -1,5 +1,5 @@ import { shallowMount } from '@vue/test-utils'; -import KTable from '../../lib/KTable/KTable.vue'; +import KTable from '../../lib/KTable'; describe('KTable.vue', () => { it('should mount the component', () => { From de583df11384fabd731888274965997a78bbf25f Mon Sep 17 00:00:00 2001 From: callmeroot Date: Sun, 9 Jun 2024 17:16:14 +0530 Subject: [PATCH 12/78] removed unnecessary validator --- lib/KTable/index.vue | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/KTable/index.vue b/lib/KTable/index.vue index ab8a8a22e..aa92f84d5 100644 --- a/lib/KTable/index.vue +++ b/lib/KTable/index.vue @@ -97,13 +97,6 @@ headers: { type: Array, required: true, - validator: function(value) { - return value.every( - header => - ['label', 'dataType'].every(key => key in header) && - ['string', 'numeric', 'date', 'others'].includes(header.dataType) - ); - }, }, rows: { type: Array, From 583999a91deeed6559fe23711efc184af2690a8c Mon Sep 17 00:00:00 2001 From: callmeroot Date: Thu, 13 Jun 2024 23:47:21 +0530 Subject: [PATCH 13/78] added changesort event handler and tests --- docs/pages/playground.vue | 83 ++++++++++++----------- lib/KTable/KTableGridItem.vue | 4 +- lib/KTable/index.vue | 46 ++++++++++--- lib/__tests__/KTable.spec.js | 41 ++++++++++- lib/{KTable => composables}/useSorting.js | 0 5 files changed, 121 insertions(+), 53 deletions(-) rename lib/{KTable => composables}/useSorting.js (100%) diff --git a/docs/pages/playground.vue b/docs/pages/playground.vue index 6dee4f386..8a14e7c15 100644 --- a/docs/pages/playground.vue +++ b/docs/pages/playground.vue @@ -1,37 +1,17 @@ @@ -66,10 +44,10 @@ + + \ No newline at end of file diff --git a/lib/KTable/KTableGridItem.vue b/lib/KTable/KTableGridItem.vue index fe3264eb3..90db97d25 100644 --- a/lib/KTable/KTableGridItem.vue +++ b/lib/KTable/KTableGridItem.vue @@ -11,6 +11,8 @@ + \ No newline at end of file From b8b752e98999d84b21855ae605bdd06c8be70363 Mon Sep 17 00:00:00 2001 From: callmeroot Date: Fri, 21 Jun 2024 07:47:45 +0530 Subject: [PATCH 16/78] enhanced keyboard nav --- lib/KTable/index.vue | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/lib/KTable/index.vue b/lib/KTable/index.vue index dcc5dd8ec..c049cd0de 100644 --- a/lib/KTable/index.vue +++ b/lib/KTable/index.vue @@ -151,25 +151,29 @@ switch (key) { case 'ArrowUp': - if (rowIndex === 0) { - this.focusHeader(colIndex); - return; - } else if (rowIndex > 0) { - nextRowIndex = rowIndex - 1; + if (rowIndex === -1) { + nextRowIndex = totalRows - 1; } else { - return; + nextRowIndex = rowIndex - 1; } break; case 'ArrowDown': if (rowIndex === -1) { nextRowIndex = 0; + } else if (rowIndex === totalRows - 1) { + nextRowIndex = -1; } else { nextRowIndex = (rowIndex + 1) % totalRows; } break; case 'ArrowLeft': if (rowIndex === -1) { - nextColIndex = colIndex > 0 ? colIndex - 1 : totalCols - 1; + if (colIndex > 0) { + nextColIndex = colIndex - 1; + } else { + nextColIndex = totalCols - 1; + nextRowIndex = totalRows - 1; + } } else if (colIndex > 0) { nextColIndex = colIndex - 1; } else { @@ -178,18 +182,16 @@ } break; case 'ArrowRight': - if (rowIndex === -1) { - if (colIndex < totalCols - 1) { - nextColIndex = colIndex + 1; + if (colIndex === totalCols - 1) { + if (rowIndex === totalRows - 1) { + nextColIndex = 0; + nextRowIndex = -1; } else { - nextRowIndex = 0; nextColIndex = 0; + nextRowIndex = rowIndex + 1; } - } else if (colIndex < totalCols - 1) { - nextColIndex = colIndex + 1; } else { - nextColIndex = 0; - nextRowIndex = (rowIndex + 1) % totalRows; + nextColIndex = colIndex + 1; } break; case 'Enter': @@ -200,16 +202,9 @@ default: return; } - this.focusCell(nextRowIndex, nextColIndex); event.preventDefault(); }, - focusHeader(colIndex) { - const nextHeader = this.$el.querySelector(`thead th:nth-child(${colIndex + 1})`); - if (nextHeader) { - nextHeader.focus(); - } - }, focusCell(rowIndex, colIndex) { let nextCell; if (rowIndex === -1) { From 091e7f2f76b374260b99e3f55380ab7884eae7b5 Mon Sep 17 00:00:00 2001 From: callmeroot Date: Thu, 11 Jul 2024 19:52:34 +0530 Subject: [PATCH 17/78] fixed firefox accessibility issues --- lib/KTable/KTableGridItem.vue | 2 +- lib/KTable/index.vue | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/KTable/KTableGridItem.vue b/lib/KTable/KTableGridItem.vue index 90db97d25..5a90ef158 100644 --- a/lib/KTable/KTableGridItem.vue +++ b/lib/KTable/KTableGridItem.vue @@ -1,6 +1,6 @@