diff --git a/package-lock.json b/package-lock.json index d5e3f2040..01c028846 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ebury/chameleon-components", - "version": "2.2.44", + "version": "2.2.45", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ebury/chameleon-components", - "version": "2.2.44", + "version": "2.2.45", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 1ede575f6..47b0acbb7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ebury/chameleon-components", - "version": "2.2.44", + "version": "2.2.45", "main": "src/main.js", "sideEffects": false, "author": "Ebury Team (http://labs.ebury.rocks/)", diff --git a/src/components/ec-smart-table/ec-smart-table.spec.js b/src/components/ec-smart-table/ec-smart-table.spec.js index 26815ea46..42bd2fde5 100644 --- a/src/components/ec-smart-table/ec-smart-table.spec.js +++ b/src/components/ec-smart-table/ec-smart-table.spec.js @@ -1,7 +1,7 @@ import { mount } from '@vue/test-utils'; import { h, markRaw } from 'vue'; -import * as SortDirection from '../../enums/sort-direction'; +import { SortDirection } from '../../enums'; import EcSmartTable from './ec-smart-table.vue'; describe('EcSmartTable', () => { diff --git a/src/components/ec-smart-table/ec-smart-table.story.js b/src/components/ec-smart-table/ec-smart-table.story.js index eb188484d..ff266ac76 100644 --- a/src/components/ec-smart-table/ec-smart-table.story.js +++ b/src/components/ec-smart-table/ec-smart-table.story.js @@ -4,7 +4,7 @@ import { computed, markRaw, onBeforeUnmount, ref, } from 'vue'; -import * as SortDirection from '../../enums/sort-direction'; +import { SortDirection } from '../../enums'; import * as SortDirectionCycle from '../../enums/sort-direction-cycle'; import EcDateRangeFilter from '../ec-date-range-filter'; import EcIcon from '../ec-icon'; diff --git a/src/components/ec-smart-table/ec-smart-table.vue b/src/components/ec-smart-table/ec-smart-table.vue index a8e2dbb78..8a047a46b 100644 --- a/src/components/ec-smart-table/ec-smart-table.vue +++ b/src/components/ec-smart-table/ec-smart-table.vue @@ -123,7 +123,7 @@ import { import useEcPagination from '../../composables/use-ec-pagination'; import useEcSorting from '../../composables/use-ec-sorting'; -import * as SortDirection from '../../enums/sort-direction'; +import { SortDirection } from '../../enums'; import * as SortDirectionCycle from '../../enums/sort-direction-cycle'; import EcLoading from '../ec-loading'; import EcSmartTableHeading from '../ec-smart-table-heading'; @@ -225,3 +225,4 @@ function getEcTableSlots() { return tableSlots; } +../../enums diff --git a/src/components/ec-table-head/ec-table-head.spec.js b/src/components/ec-table-head/ec-table-head.spec.js index 72999602b..193fa9e6b 100644 --- a/src/components/ec-table-head/ec-table-head.spec.js +++ b/src/components/ec-table-head/ec-table-head.spec.js @@ -1,7 +1,7 @@ import { mount } from '@vue/test-utils'; import { withMockedConsole } from '../../../tests/utils/console'; -import * as SortDirection from '../../enums/sort-direction'; +import { SortDirection } from '../../enums'; import EcTableHead from './ec-table-head.vue'; describe('EcTableHead', () => { diff --git a/src/components/ec-table-sort/__snapshots__/ec-table-sort.spec.js.snap b/src/components/ec-table-sort/__snapshots__/ec-table-sort.spec.ts.snap similarity index 100% rename from src/components/ec-table-sort/__snapshots__/ec-table-sort.spec.js.snap rename to src/components/ec-table-sort/__snapshots__/ec-table-sort.spec.ts.snap diff --git a/src/components/ec-table-sort/ec-table-sort.spec.js b/src/components/ec-table-sort/ec-table-sort.spec.ts similarity index 74% rename from src/components/ec-table-sort/ec-table-sort.spec.js rename to src/components/ec-table-sort/ec-table-sort.spec.ts index b7da6c259..2c3c153ca 100644 --- a/src/components/ec-table-sort/ec-table-sort.spec.js +++ b/src/components/ec-table-sort/ec-table-sort.spec.ts @@ -1,15 +1,16 @@ -import { mount } from '@vue/test-utils'; +import { type ComponentMountingOptions, mount } from '@vue/test-utils'; -import { withMockedConsole } from '../../../tests/utils/console'; -import * as SortDirection from '../../enums/sort-direction'; +import type { CVueWrapper } from '../../../tests/utils/global'; +import { SortDirection } from '../../enums'; import EcTableSort from './ec-table-sort.vue'; +import type { TableSortProps } from './types'; describe('EcTableSort', () => { - function mountEcTableSort(props, mountOpts) { + function mountEcTableSort(props?: TableSortProps, mountOpts?: ComponentMountingOptions) { return mount(EcTableSort, { props, ...mountOpts, - }); + }) as unknown as CVueWrapper; } it('should render as expected', () => { @@ -37,14 +38,6 @@ describe('EcTableSort', () => { const wrapper = mountEcTableSort({ direction: SortDirection.DESC }); expect(wrapper.element).toMatchSnapshot(); }); - - it('should validate direction prop', () => { - withMockedConsole((errorSpy, warnSpy) => { - mountEcTableSort({ direction: 'invalid' }); - expect(warnSpy).toHaveBeenCalledTimes(1); - expect(warnSpy.mock.calls[0][0]).toContain('Invalid prop: custom validator check failed for prop "direction"'); - }); - }); }); describe('@events', () => { diff --git a/src/components/ec-table-sort/ec-table-sort.vue b/src/components/ec-table-sort/ec-table-sort.vue index 431cb1c52..ce7c68900 100644 --- a/src/components/ec-table-sort/ec-table-sort.vue +++ b/src/components/ec-table-sort/ec-table-sort.vue @@ -23,22 +23,24 @@ - @@ -94,3 +96,4 @@ function onSort() { } } +../../enums diff --git a/src/components/ec-table-sort/index.js b/src/components/ec-table-sort/index.ts similarity index 100% rename from src/components/ec-table-sort/index.js rename to src/components/ec-table-sort/index.ts diff --git a/src/components/ec-table-sort/types.ts b/src/components/ec-table-sort/types.ts new file mode 100644 index 000000000..5959e3cc5 --- /dev/null +++ b/src/components/ec-table-sort/types.ts @@ -0,0 +1,15 @@ +import type { SortDirection } from '../../enums'; + +export type SortDirectionType = SortDirection | '' | null; + +export enum TableSortEvent { + SORT = 'sort', +} + +export interface TableSortEvents { + [TableSortEvent.SORT]: SortDirectionType, +} + +export interface TableSortProps { + direction?: SortDirectionType, +} diff --git a/src/components/ec-table/ec-table.spec.js b/src/components/ec-table/ec-table.spec.js index 42977914c..4400549f3 100644 --- a/src/components/ec-table/ec-table.spec.js +++ b/src/components/ec-table/ec-table.spec.js @@ -2,7 +2,7 @@ import { mount } from '@vue/test-utils'; import { defineComponent, h } from 'vue'; import { withMockedConsole } from '../../../tests/utils/console'; -import * as SortDirection from '../../enums/sort-direction'; +import { SortDirection } from '../../enums'; import EcTable from './ec-table.vue'; function mountEcTable(props, mountOpts) { diff --git a/src/components/ec-table/ec-table.story.js b/src/components/ec-table/ec-table.story.js index 0a0d3b9bd..c3160d8cb 100644 --- a/src/components/ec-table/ec-table.story.js +++ b/src/components/ec-table/ec-table.story.js @@ -1,6 +1,6 @@ import { action } from '@storybook/addon-actions'; -import * as SortDirection from '../../enums/sort-direction'; +import { SortDirection } from '../../enums'; import EcIcon from '../ec-icon/ec-icon.vue'; import EcOptionCard from '../ec-option-card'; import EcTable from './ec-table.vue'; diff --git a/src/composables/use-ec-sorting/use-ec-sorting.js b/src/composables/use-ec-sorting/use-ec-sorting.js index 5bd7f77a5..ada0af996 100644 --- a/src/composables/use-ec-sorting/use-ec-sorting.js +++ b/src/composables/use-ec-sorting/use-ec-sorting.js @@ -1,6 +1,6 @@ import { ref, unref } from 'vue'; -import * as SortDirection from '../../enums/sort-direction'; +import { SortDirection } from '../../enums'; import * as SortDirectionCycle from '../../enums/sort-direction-cycle'; export default function useEcSorting({ diff --git a/src/composables/use-ec-sorting/use-ec-sorting.spec.js b/src/composables/use-ec-sorting/use-ec-sorting.spec.js index e7ca401c3..754852a0b 100644 --- a/src/composables/use-ec-sorting/use-ec-sorting.spec.js +++ b/src/composables/use-ec-sorting/use-ec-sorting.spec.js @@ -1,4 +1,4 @@ -import * as SortDirection from '../../enums/sort-direction'; +import { SortDirection } from '../../enums'; import * as SortDirectionCycle from '../../enums/sort-direction-cycle'; import useEcSorting from './use-ec-sorting'; diff --git a/src/enums/index.ts b/src/enums/index.ts new file mode 100644 index 000000000..99554e087 --- /dev/null +++ b/src/enums/index.ts @@ -0,0 +1,4 @@ +export enum SortDirection { + ASC = 'asc', + DESC = 'desc', +} diff --git a/src/enums/sort-direction-cycle.js b/src/enums/sort-direction-cycle.js index 066301070..3a019e252 100644 --- a/src/enums/sort-direction-cycle.js +++ b/src/enums/sort-direction-cycle.js @@ -1,4 +1,4 @@ -import * as SortDirection from './sort-direction'; +import { SortDirection } from '.'; export const LOWEST_FIRST = [SortDirection.ASC, SortDirection.DESC]; export const HIGHEST_FIRST = [SortDirection.DESC, SortDirection.ASC]; diff --git a/src/enums/sort-direction.js b/src/enums/sort-direction.js deleted file mode 100644 index 500ccc809..000000000 --- a/src/enums/sort-direction.js +++ /dev/null @@ -1,2 +0,0 @@ -export const ASC = 'asc'; -export const DESC = 'desc'; diff --git a/src/main.js b/src/main.js index 7b8c991f5..d568a49a5 100644 --- a/src/main.js +++ b/src/main.js @@ -1,4 +1,4 @@ -import * as SortDirection from './enums/sort-direction'; +import { SortDirection } from './enums'; import * as SortDirectionCycle from './enums/sort-direction-cycle'; import * as TooltipPlacement from './enums/tooltip-placement';