@code-coaching/vuetiful 0.23.0 → 0.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/style.css +1 -1
- package/dist/types/components/VBootstrap.vue.d.ts +1 -1
- package/dist/types/components/atoms/VAvatar.vue.d.ts +1 -1
- package/dist/types/components/atoms/VLightSwitch.vue.d.ts +2 -2
- package/dist/types/components/atoms/index.d.ts +13 -13
- package/dist/types/components/index.d.ts +2 -2
- package/dist/types/components/molecules/VAlert.vue.d.ts +1 -1
- package/dist/types/components/molecules/VCodeBlock.vue.d.ts +2 -2
- package/dist/types/components/molecules/VDrawer.vue.d.ts +1 -1
- package/dist/types/components/molecules/VListbox/VListbox.vue.d.ts +1 -1
- package/dist/types/components/molecules/VRail/VRail.vue.d.ts +1 -1
- package/dist/types/components/molecules/VRail/VRailTile.vue.d.ts +1 -1
- package/dist/types/components/molecules/index.d.ts +21 -21
- package/dist/types/directives/clipboard.d.ts +1 -1
- package/dist/types/directives/index.d.ts +1 -1
- package/dist/types/index.d.ts +6 -6
- package/dist/types/props/props.d.ts +1 -1
- package/dist/types/services/dark-mode.service.d.ts +1 -1
- package/dist/types/services/drawer.service.d.ts +1 -1
- package/dist/types/services/index.d.ts +5 -5
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/utils/index.d.ts +2 -2
- package/dist/types/utils/theme/theme-switcher.vue.d.ts +23 -63
- package/dist/types/utils/theme/theme.service.d.ts +1 -1
- package/dist/vuetiful.es.mjs +82 -150
- package/dist/vuetiful.umd.js +7 -15
- package/package.json +1 -1
- package/src/assets/main.css +6 -6
- package/src/components/VBootstrap.vue +43 -43
- package/src/components/atoms/VAvatar.test.ts +71 -71
- package/src/components/atoms/VAvatar.vue +22 -23
- package/src/components/atoms/VBadge.test.ts +11 -11
- package/src/components/atoms/VBadge.vue +2 -2
- package/src/components/atoms/VButton.test.ts +82 -82
- package/src/components/atoms/VButton.vue +20 -21
- package/src/components/atoms/VChip.test.ts +11 -11
- package/src/components/atoms/VChip.vue +3 -3
- package/src/components/atoms/VLightSwitch.test.ts +6 -6
- package/src/components/atoms/VLightSwitch.vue +26 -31
- package/src/components/atoms/VRadio/VRadioDescription.test.ts +13 -13
- package/src/components/atoms/VRadio/VRadioDescription.vue +2 -2
- package/src/components/atoms/VRadio/VRadioGroup.test.ts +40 -40
- package/src/components/atoms/VRadio/VRadioGroup.vue +19 -22
- package/src/components/atoms/VRadio/VRadioItem.test.ts +67 -67
- package/src/components/atoms/VRadio/VRadioItem.vue +10 -13
- package/src/components/atoms/VRadio/VRadioLabel.test.ts +13 -13
- package/src/components/atoms/VRadio/VRadioLabel.vue +5 -3
- package/src/components/atoms/VSwitch/VSwitch.test.ts +33 -33
- package/src/components/atoms/VSwitch/VSwitch.vue +24 -27
- package/src/components/atoms/VSwitch/VSwitchDescription.test.ts +13 -13
- package/src/components/atoms/VSwitch/VSwitchDescription.vue +2 -2
- package/src/components/atoms/VSwitch/VSwitchGroup.test.ts +9 -9
- package/src/components/atoms/VSwitch/VSwitchGroup.vue +2 -2
- package/src/components/atoms/VSwitch/VSwitchLabel.test.ts +19 -19
- package/src/components/atoms/VSwitch/VSwitchLabel.vue +2 -2
- package/src/components/atoms/index.ts +13 -13
- package/src/components/index.test.ts +3 -3
- package/src/components/index.ts +2 -2
- package/src/components/molecules/VAccordion/VAccordion.test.ts +11 -17
- package/src/components/molecules/VAccordion/VAccordion.vue +3 -3
- package/src/components/molecules/VAccordion/VAccordionItem.test.ts +55 -55
- package/src/components/molecules/VAccordion/VAccordionItem.vue +9 -22
- package/src/components/molecules/VAlert.test.ts +38 -38
- package/src/components/molecules/VAlert.vue +25 -47
- package/src/components/molecules/VCard/VCard.test.ts +25 -25
- package/src/components/molecules/VCard/VCard.vue +13 -15
- package/src/components/molecules/VCard/VCardBody.test.ts +14 -14
- package/src/components/molecules/VCard/VCardBody.vue +4 -8
- package/src/components/molecules/VCard/VCardFooter.test.ts +22 -22
- package/src/components/molecules/VCard/VCardFooter.vue +10 -8
- package/src/components/molecules/VCard/VCardHeader.test.ts +25 -25
- package/src/components/molecules/VCard/VCardHeader.vue +7 -8
- package/src/components/molecules/VCodeBlock.test.ts +63 -63
- package/src/components/molecules/VCodeBlock.vue +27 -34
- package/src/components/molecules/VDrawer.test.ts +5 -5
- package/src/components/molecules/VDrawer.vue +10 -10
- package/src/components/molecules/VListbox/VListbox.test.ts +53 -53
- package/src/components/molecules/VListbox/VListbox.vue +31 -32
- package/src/components/molecules/VListbox/VListboxButton.test.ts +13 -13
- package/src/components/molecules/VListbox/VListboxButton.vue +5 -5
- package/src/components/molecules/VListbox/VListboxItem.test.ts +25 -25
- package/src/components/molecules/VListbox/VListboxItem.vue +7 -8
- package/src/components/molecules/VListbox/VListboxItems.test.ts +14 -14
- package/src/components/molecules/VListbox/VListboxItems.vue +9 -11
- package/src/components/molecules/VListbox/VListboxLabel.test.ts +10 -10
- package/src/components/molecules/VListbox/VListboxLabel.vue +2 -2
- package/src/components/molecules/VPreview.test.ts +26 -26
- package/src/components/molecules/VPreview.vue +22 -27
- package/src/components/molecules/VRail/VRail.test.ts +5 -5
- package/src/components/molecules/VRail/VRail.vue +7 -7
- package/src/components/molecules/VRail/VRailTile.test.ts +26 -28
- package/src/components/molecules/VRail/VRailTile.vue +13 -11
- package/src/components/molecules/VShell.test.ts +5 -5
- package/src/components/molecules/VShell.vue +11 -20
- package/src/components/molecules/VTabs/VTab.test.ts +48 -52
- package/src/components/molecules/VTabs/VTab.vue +13 -17
- package/src/components/molecules/VTabs/VTabPanel.test.ts +8 -8
- package/src/components/molecules/VTabs/VTabPanel.vue +1 -1
- package/src/components/molecules/VTabs/VTabs.test.ts +36 -36
- package/src/components/molecules/VTabs/VTabs.vue +18 -22
- package/src/components/molecules/index.ts +21 -21
- package/src/directives/clipboard.test.ts +9 -9
- package/src/directives/clipboard.ts +2 -2
- package/src/directives/index.ts +1 -1
- package/src/env.d.ts +2 -2
- package/src/index.test.ts +6 -6
- package/src/index.ts +7 -7
- package/src/props/index.ts +1 -1
- package/src/props/props.ts +44 -44
- package/src/services/dark-mode.service.test.ts +115 -93
- package/src/services/dark-mode.service.ts +9 -9
- package/src/services/drawer.service.test.ts +21 -21
- package/src/services/drawer.service.ts +10 -10
- package/src/services/highlight.service.test.ts +12 -12
- package/src/services/highlight.service.ts +1 -1
- package/src/services/index.ts +5 -5
- package/src/services/rail.service.test.ts +7 -7
- package/src/services/rail.service.ts +2 -2
- package/src/services/settings.service.test.ts +5 -5
- package/src/services/settings.service.ts +1 -1
- package/src/styles/all.css +7 -7
- package/src/styles/elements/buttons.css +1 -1
- package/src/styles/elements/forms.css +7 -7
- package/src/styles/elements.css +13 -13
- package/src/styles/transitions.css +2 -2
- package/src/styles/typography.css +5 -5
- package/src/themes/theme-rocket.css +10 -10
- package/src/themes/theme-sahara.css +13 -13
- package/src/themes/theme-seafoam.css +13 -13
- package/src/themes/theme-seasonal.css +4 -4
- package/src/themes/theme-skeleton.css +7 -7
- package/src/themes/theme-vintage.css +12 -12
- package/src/themes/theme-vuetiful-0.0.1.css +13 -13
- package/src/types/index.ts +46 -46
- package/src/types/tailwind.ts +2 -21
- package/src/utils/index.test.ts +3 -3
- package/src/utils/index.ts +2 -2
- package/src/utils/platform/platform.service.test.ts +6 -6
- package/src/utils/platform/platform.service.ts +1 -1
- package/src/utils/theme/callback.test.ts +6 -6
- package/src/utils/theme/remove.test.ts +8 -8
- package/src/utils/theme/theme-switcher.vue +58 -131
- package/src/utils/theme/theme.service.test.ts +69 -61
- package/src/utils/theme/theme.service.ts +19 -20
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from
|
|
2
|
-
import { DirectiveBinding } from
|
|
3
|
-
import { vClipboard } from
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { DirectiveBinding } from 'vue';
|
|
3
|
+
import { vClipboard } from '.';
|
|
4
4
|
|
|
5
5
|
const navigatorMock = {
|
|
6
6
|
clipboard: {
|
|
@@ -8,19 +8,19 @@ const navigatorMock = {
|
|
|
8
8
|
} as any,
|
|
9
9
|
} as any;
|
|
10
10
|
|
|
11
|
-
describe(
|
|
11
|
+
describe('clipboard', () => {
|
|
12
12
|
afterEach(() => {
|
|
13
13
|
vi.resetAllMocks();
|
|
14
14
|
});
|
|
15
|
-
describe(
|
|
16
|
-
it(
|
|
15
|
+
describe('given the v-clipboard directive is used', () => {
|
|
16
|
+
it('should copy text to the clipboard on click', () => {
|
|
17
17
|
window.navigator = navigatorMock;
|
|
18
18
|
|
|
19
|
-
const el = document.createElement(
|
|
20
|
-
vClipboard(el, { value:
|
|
19
|
+
const el = document.createElement('div');
|
|
20
|
+
vClipboard(el, { value: 'John Duck' } as DirectiveBinding);
|
|
21
21
|
el.click();
|
|
22
22
|
|
|
23
|
-
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
|
|
23
|
+
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('John Duck');
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
26
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DirectiveBinding } from
|
|
1
|
+
import { DirectiveBinding } from 'vue';
|
|
2
2
|
|
|
3
3
|
const clipboard = (el: HTMLElement, binding: DirectiveBinding) => {
|
|
4
|
-
el.addEventListener(
|
|
4
|
+
el.addEventListener('click', () => {
|
|
5
5
|
navigator.clipboard.writeText(binding.value);
|
|
6
6
|
});
|
|
7
7
|
};
|
package/src/directives/index.ts
CHANGED
package/src/env.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="vite/client" />
|
|
2
2
|
|
|
3
|
-
declare module
|
|
4
|
-
import { DefineComponent } from
|
|
3
|
+
declare module '*.vue' {
|
|
4
|
+
import { DefineComponent } from 'vue';
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
|
|
6
6
|
const component: DefineComponent<{}, {}, any>;
|
|
7
7
|
export default component;
|
package/src/index.test.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from
|
|
2
|
-
import * as components from
|
|
3
|
-
import plugin, * as index from
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import * as components from './components';
|
|
3
|
+
import plugin, * as index from './index';
|
|
4
4
|
|
|
5
|
-
describe(
|
|
5
|
+
describe('src', () => {
|
|
6
6
|
Object.entries(index).forEach(([key, value]) => {
|
|
7
7
|
it(`${key} is defined`, () => {
|
|
8
8
|
expect(value).toBeDefined();
|
|
9
9
|
});
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
describe(
|
|
13
|
-
it(
|
|
12
|
+
describe('given install is called', () => {
|
|
13
|
+
it('should register all components', () => {
|
|
14
14
|
const app = {
|
|
15
15
|
component: vi.fn(),
|
|
16
16
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as components from
|
|
1
|
+
import * as components from './components';
|
|
2
2
|
|
|
3
3
|
function install(app: any) {
|
|
4
4
|
for (const key in components) {
|
|
@@ -7,15 +7,15 @@ function install(app: any) {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
import
|
|
11
|
-
import
|
|
10
|
+
import './assets/main.css';
|
|
11
|
+
import './styles/tailwind.css';
|
|
12
12
|
|
|
13
13
|
export default { install };
|
|
14
14
|
|
|
15
|
-
export * from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
18
|
-
export * from
|
|
15
|
+
export * from './components';
|
|
16
|
+
export * from './utils';
|
|
17
|
+
export * from './directives';
|
|
18
|
+
export * from './services';
|
|
19
19
|
|
|
20
20
|
// This type alias is to identify CSS classes within component props, which enables Tailwind IntelliSense
|
|
21
21
|
export type CssClasses = string;
|
package/src/props/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './props';
|
|
1
|
+
export * from './props';
|
package/src/props/props.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Size, Variant } from
|
|
2
|
-
import { PropType } from
|
|
1
|
+
import { Size, Variant } from '@/types';
|
|
2
|
+
import { PropType } from 'vue';
|
|
3
3
|
|
|
4
4
|
const sizeProp = {
|
|
5
|
-
type: String as PropType<
|
|
5
|
+
type: String as PropType<'xs' | 'sm' | 'md' | 'lg' | 'xl'>,
|
|
6
6
|
default: Size.MD,
|
|
7
7
|
};
|
|
8
8
|
|
|
@@ -14,47 +14,47 @@ const unstyledProp = {
|
|
|
14
14
|
const variantProp = {
|
|
15
15
|
// explicit string union because TypeScript type won't throw error if invalid value is passed
|
|
16
16
|
type: String as PropType<
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
|
|
|
48
|
-
|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
|
|
|
53
|
-
|
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
17
|
+
| ''
|
|
18
|
+
| 'filled'
|
|
19
|
+
| 'filled-primary'
|
|
20
|
+
| 'filled-secondary'
|
|
21
|
+
| 'filled-tertiary'
|
|
22
|
+
| 'filled-success'
|
|
23
|
+
| 'filled-warning'
|
|
24
|
+
| 'filled-error'
|
|
25
|
+
| 'filled-surface'
|
|
26
|
+
| 'ringed'
|
|
27
|
+
| 'ringed-primary'
|
|
28
|
+
| 'ringed-secondary'
|
|
29
|
+
| 'ringed-tertiary'
|
|
30
|
+
| 'ringed-success'
|
|
31
|
+
| 'ringed-warning'
|
|
32
|
+
| 'ringed-error'
|
|
33
|
+
| 'ringed-surface'
|
|
34
|
+
| 'ghost'
|
|
35
|
+
| 'ghost-primary'
|
|
36
|
+
| 'ghost-secondary'
|
|
37
|
+
| 'ghost-tertiary'
|
|
38
|
+
| 'ghost-success'
|
|
39
|
+
| 'ghost-warning'
|
|
40
|
+
| 'ghost-error'
|
|
41
|
+
| 'ghost-surface'
|
|
42
|
+
| 'soft'
|
|
43
|
+
| 'soft-primary'
|
|
44
|
+
| 'soft-secondary'
|
|
45
|
+
| 'soft-tertiary'
|
|
46
|
+
| 'soft-success'
|
|
47
|
+
| 'soft-warning'
|
|
48
|
+
| 'soft-error'
|
|
49
|
+
| 'soft-surface'
|
|
50
|
+
| 'glass'
|
|
51
|
+
| 'glass-primary'
|
|
52
|
+
| 'glass-secondary'
|
|
53
|
+
| 'glass-tertiary'
|
|
54
|
+
| 'glass-success'
|
|
55
|
+
| 'glass-warning'
|
|
56
|
+
| 'glass-error'
|
|
57
|
+
| 'glass-surface'
|
|
58
58
|
>,
|
|
59
59
|
default: Variant.Filled,
|
|
60
60
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
3
|
const localStorageMock = {
|
|
4
4
|
getItem: vi.fn(),
|
|
@@ -6,47 +6,53 @@ const localStorageMock = {
|
|
|
6
6
|
};
|
|
7
7
|
const matchMediaMock = (matches: boolean) => vi.fn(() => ({ matches, onchange: vi.fn() }));
|
|
8
8
|
|
|
9
|
-
describe(
|
|
9
|
+
describe('useDarkMode', () => {
|
|
10
10
|
afterEach(() => {
|
|
11
11
|
vi.resetModules();
|
|
12
12
|
});
|
|
13
|
-
describe(
|
|
14
|
-
describe(
|
|
15
|
-
it(
|
|
16
|
-
const platform = await import(
|
|
17
|
-
vi.spyOn(platform,
|
|
13
|
+
describe('getModeUserPrefers', () => {
|
|
14
|
+
describe('given not in browser', () => {
|
|
15
|
+
it('should return default modeUserPrefers', async () => {
|
|
16
|
+
const platform = await import('../utils/platform/platform.service');
|
|
17
|
+
vi.spyOn(platform, 'usePlatform').mockReturnValueOnce({
|
|
18
|
+
isBrowser: false,
|
|
19
|
+
});
|
|
18
20
|
|
|
19
|
-
const { useDarkMode } = await import(
|
|
21
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
20
22
|
const { getModeUserPrefers } = useDarkMode();
|
|
21
23
|
expect(getModeUserPrefers()).toBe(undefined);
|
|
22
24
|
});
|
|
23
25
|
});
|
|
24
26
|
|
|
25
|
-
describe(
|
|
26
|
-
describe(
|
|
27
|
-
it(
|
|
28
|
-
const platform = await import(
|
|
29
|
-
vi.spyOn(platform,
|
|
27
|
+
describe('given in browser', () => {
|
|
28
|
+
describe('given no modeUserPrefers in localStorage', () => {
|
|
29
|
+
it('should return default modeUserPrefers', async () => {
|
|
30
|
+
const platform = await import('../utils/platform/platform.service');
|
|
31
|
+
vi.spyOn(platform, 'usePlatform').mockReturnValueOnce({
|
|
32
|
+
isBrowser: true,
|
|
33
|
+
});
|
|
30
34
|
|
|
31
|
-
const { useDarkMode } = await import(
|
|
35
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
32
36
|
const { getModeUserPrefers } = useDarkMode();
|
|
33
37
|
|
|
34
38
|
window.localStorage = localStorageMock as any;
|
|
35
|
-
vi.spyOn(window.localStorage,
|
|
39
|
+
vi.spyOn(window.localStorage, 'getItem').mockReturnValueOnce(null);
|
|
36
40
|
|
|
37
41
|
expect(getModeUserPrefers()).toBe(undefined);
|
|
38
42
|
});
|
|
39
43
|
});
|
|
40
|
-
describe(
|
|
41
|
-
it(
|
|
42
|
-
const platform = await import(
|
|
43
|
-
vi.spyOn(platform,
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
describe('given modeUserPrefers in localStorage', () => {
|
|
45
|
+
it('should return the value', async () => {
|
|
46
|
+
const platform = await import('../utils/platform/platform.service');
|
|
47
|
+
vi.spyOn(platform, 'usePlatform').mockReturnValueOnce({
|
|
48
|
+
isBrowser: true,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
46
52
|
const { getModeUserPrefers } = useDarkMode();
|
|
47
53
|
|
|
48
54
|
window.localStorage = localStorageMock as any;
|
|
49
|
-
vi.spyOn(window.localStorage,
|
|
55
|
+
vi.spyOn(window.localStorage, 'getItem').mockReturnValueOnce('true');
|
|
50
56
|
|
|
51
57
|
expect(getModeUserPrefers()).toBe(true);
|
|
52
58
|
});
|
|
@@ -54,87 +60,99 @@ describe("useDarkMode", () => {
|
|
|
54
60
|
});
|
|
55
61
|
});
|
|
56
62
|
|
|
57
|
-
describe(
|
|
58
|
-
describe(
|
|
59
|
-
it(
|
|
60
|
-
const platform = await import(
|
|
61
|
-
vi.spyOn(platform,
|
|
63
|
+
describe('getModeOsPrefers', () => {
|
|
64
|
+
describe('given not in browser', () => {
|
|
65
|
+
it('should return default modeOsPrefers', async () => {
|
|
66
|
+
const platform = await import('../utils/platform/platform.service');
|
|
67
|
+
vi.spyOn(platform, 'usePlatform').mockReturnValueOnce({
|
|
68
|
+
isBrowser: false,
|
|
69
|
+
});
|
|
62
70
|
|
|
63
|
-
const { useDarkMode } = await import(
|
|
71
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
64
72
|
const { getModeOsPrefers } = useDarkMode();
|
|
65
73
|
expect(getModeOsPrefers()).toBe(false);
|
|
66
74
|
});
|
|
67
75
|
});
|
|
68
76
|
|
|
69
|
-
describe(
|
|
70
|
-
describe(
|
|
71
|
-
it(
|
|
72
|
-
const platform = await import(
|
|
73
|
-
vi.spyOn(platform,
|
|
74
|
-
|
|
77
|
+
describe('given in browser', () => {
|
|
78
|
+
describe('given prefers-color-scheme: light', () => {
|
|
79
|
+
it('should return true', async () => {
|
|
80
|
+
const platform = await import('../utils/platform/platform.service');
|
|
81
|
+
vi.spyOn(platform, 'usePlatform').mockReturnValueOnce({
|
|
82
|
+
isBrowser: true,
|
|
83
|
+
});
|
|
84
|
+
const localStorageSpy = vi.spyOn(window.localStorage, 'setItem');
|
|
75
85
|
|
|
76
|
-
const { useDarkMode } = await import(
|
|
86
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
77
87
|
const { getModeOsPrefers, MODE } = useDarkMode();
|
|
78
88
|
|
|
79
89
|
window.matchMedia = matchMediaMock(MODE.LIGHT) as any;
|
|
80
90
|
expect(getModeOsPrefers()).toBe(MODE.LIGHT);
|
|
81
|
-
expect(localStorageSpy).toHaveBeenCalledWith(
|
|
91
|
+
expect(localStorageSpy).toHaveBeenCalledWith('modeOsPrefers', 'true');
|
|
82
92
|
});
|
|
83
93
|
});
|
|
84
|
-
describe(
|
|
85
|
-
it(
|
|
86
|
-
const platform = await import(
|
|
87
|
-
vi.spyOn(platform,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
94
|
+
describe('given prefers-color-scheme: dark', () => {
|
|
95
|
+
it('should return false', async () => {
|
|
96
|
+
const platform = await import('../utils/platform/platform.service');
|
|
97
|
+
vi.spyOn(platform, 'usePlatform').mockReturnValueOnce({
|
|
98
|
+
isBrowser: true,
|
|
99
|
+
});
|
|
100
|
+
const localStorageSpy = vi.spyOn(window.localStorage, 'setItem');
|
|
101
|
+
|
|
102
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
91
103
|
const { getModeOsPrefers, MODE } = useDarkMode();
|
|
92
104
|
|
|
93
105
|
window.matchMedia = matchMediaMock(MODE.DARK) as any;
|
|
94
106
|
expect(getModeOsPrefers()).toBe(MODE.DARK);
|
|
95
|
-
expect(localStorageSpy).toHaveBeenCalledWith(
|
|
107
|
+
expect(localStorageSpy).toHaveBeenCalledWith('modeOsPrefers', 'false');
|
|
96
108
|
});
|
|
97
109
|
});
|
|
98
110
|
});
|
|
99
111
|
});
|
|
100
112
|
|
|
101
|
-
describe(
|
|
102
|
-
describe(
|
|
103
|
-
it(
|
|
104
|
-
const platform = await import(
|
|
105
|
-
vi.spyOn(platform,
|
|
113
|
+
describe('getModeAutoPrefers', () => {
|
|
114
|
+
describe('given not in browser', () => {
|
|
115
|
+
it('should return default modeAutoPrefers', async () => {
|
|
116
|
+
const platform = await import('../utils/platform/platform.service');
|
|
117
|
+
vi.spyOn(platform, 'usePlatform').mockReturnValueOnce({
|
|
118
|
+
isBrowser: false,
|
|
119
|
+
});
|
|
106
120
|
|
|
107
|
-
const { useDarkMode } = await import(
|
|
121
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
108
122
|
const { getModeAutoPrefers } = useDarkMode();
|
|
109
123
|
expect(getModeAutoPrefers()).toBe(false);
|
|
110
124
|
});
|
|
111
125
|
});
|
|
112
126
|
|
|
113
|
-
describe(
|
|
114
|
-
describe(
|
|
115
|
-
it(
|
|
116
|
-
const platform = await import(
|
|
117
|
-
vi.spyOn(platform,
|
|
127
|
+
describe('given in browser', () => {
|
|
128
|
+
describe('given no modeUserPrefers in localStorage', () => {
|
|
129
|
+
it('should return default modeAutoPrefers', async () => {
|
|
130
|
+
const platform = await import('../utils/platform/platform.service');
|
|
131
|
+
vi.spyOn(platform, 'usePlatform').mockReturnValueOnce({
|
|
132
|
+
isBrowser: true,
|
|
133
|
+
});
|
|
118
134
|
|
|
119
|
-
const { useDarkMode } = await import(
|
|
135
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
120
136
|
const { getModeAutoPrefers } = useDarkMode();
|
|
121
137
|
|
|
122
138
|
window.localStorage = localStorageMock as any;
|
|
123
|
-
vi.spyOn(window.localStorage,
|
|
139
|
+
vi.spyOn(window.localStorage, 'getItem').mockReturnValueOnce(null);
|
|
124
140
|
|
|
125
141
|
expect(getModeAutoPrefers()).toBe(false);
|
|
126
142
|
});
|
|
127
143
|
});
|
|
128
|
-
describe(
|
|
129
|
-
it(
|
|
130
|
-
const platform = await import(
|
|
131
|
-
vi.spyOn(platform,
|
|
132
|
-
|
|
133
|
-
|
|
144
|
+
describe('given modeUserPrefers in localStorage', () => {
|
|
145
|
+
it('should return the value', async () => {
|
|
146
|
+
const platform = await import('../utils/platform/platform.service');
|
|
147
|
+
vi.spyOn(platform, 'usePlatform').mockReturnValueOnce({
|
|
148
|
+
isBrowser: true,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
134
152
|
const { getModeAutoPrefers } = useDarkMode();
|
|
135
153
|
|
|
136
154
|
window.localStorage = localStorageMock as any;
|
|
137
|
-
vi.spyOn(window.localStorage,
|
|
155
|
+
vi.spyOn(window.localStorage, 'getItem').mockReturnValueOnce('true');
|
|
138
156
|
|
|
139
157
|
expect(getModeAutoPrefers()).toBe(true);
|
|
140
158
|
});
|
|
@@ -142,14 +160,16 @@ describe("useDarkMode", () => {
|
|
|
142
160
|
});
|
|
143
161
|
});
|
|
144
162
|
|
|
145
|
-
describe(
|
|
146
|
-
describe(
|
|
147
|
-
it(
|
|
148
|
-
const platform = await import(
|
|
149
|
-
vi.spyOn(platform,
|
|
150
|
-
|
|
163
|
+
describe('setModeUserPrefers', () => {
|
|
164
|
+
describe('given not in browser', () => {
|
|
165
|
+
it('should set modeUserPrefers', async () => {
|
|
166
|
+
const platform = await import('../utils/platform/platform.service');
|
|
167
|
+
vi.spyOn(platform, 'usePlatform').mockReturnValueOnce({
|
|
168
|
+
isBrowser: false,
|
|
169
|
+
});
|
|
170
|
+
vi.spyOn(window.localStorage, 'setItem');
|
|
151
171
|
|
|
152
|
-
const { useDarkMode } = await import(
|
|
172
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
153
173
|
const { setModeUserPrefers, modeUserPrefers } = useDarkMode();
|
|
154
174
|
|
|
155
175
|
setModeUserPrefers(true);
|
|
@@ -158,45 +178,47 @@ describe("useDarkMode", () => {
|
|
|
158
178
|
});
|
|
159
179
|
});
|
|
160
180
|
|
|
161
|
-
describe(
|
|
162
|
-
it(
|
|
163
|
-
const platform = await import(
|
|
164
|
-
vi.spyOn(platform,
|
|
181
|
+
describe('given in browser', () => {
|
|
182
|
+
it('should set modeUserPrefers and localStorage', async () => {
|
|
183
|
+
const platform = await import('../utils/platform/platform.service');
|
|
184
|
+
vi.spyOn(platform, 'usePlatform').mockReturnValueOnce({
|
|
185
|
+
isBrowser: true,
|
|
186
|
+
});
|
|
165
187
|
|
|
166
|
-
const { useDarkMode } = await import(
|
|
188
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
167
189
|
const { setModeUserPrefers, modeUserPrefers } = useDarkMode();
|
|
168
190
|
|
|
169
|
-
const localStorageSpy = vi.spyOn(window.localStorage,
|
|
191
|
+
const localStorageSpy = vi.spyOn(window.localStorage, 'setItem');
|
|
170
192
|
|
|
171
193
|
setModeUserPrefers(true);
|
|
172
194
|
expect(modeUserPrefers.value).toBe(true);
|
|
173
|
-
expect(localStorageSpy).toHaveBeenCalledWith(
|
|
195
|
+
expect(localStorageSpy).toHaveBeenCalledWith('modeUserPrefers', 'true');
|
|
174
196
|
});
|
|
175
197
|
});
|
|
176
198
|
});
|
|
177
199
|
|
|
178
|
-
describe(
|
|
179
|
-
it(
|
|
180
|
-
const { useDarkMode } = await import(
|
|
200
|
+
describe('setModeCurrent', () => {
|
|
201
|
+
it('light mode set', async () => {
|
|
202
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
181
203
|
const { setModeCurrent, currentMode, MODE } = useDarkMode();
|
|
182
204
|
|
|
183
205
|
setModeCurrent(MODE.LIGHT);
|
|
184
206
|
expect(currentMode.value).toBe(MODE.LIGHT);
|
|
185
|
-
expect(document.documentElement.classList.contains(
|
|
207
|
+
expect(document.documentElement.classList.contains('dark')).toBe(false);
|
|
186
208
|
});
|
|
187
|
-
it(
|
|
188
|
-
const { useDarkMode } = await import(
|
|
209
|
+
it('dark mode set', async () => {
|
|
210
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
189
211
|
const { setModeCurrent, currentMode, MODE } = useDarkMode();
|
|
190
212
|
|
|
191
213
|
setModeCurrent(MODE.DARK);
|
|
192
214
|
expect(currentMode.value).toBe(MODE.DARK);
|
|
193
|
-
expect(document.documentElement.classList.contains(
|
|
215
|
+
expect(document.documentElement.classList.contains('dark')).toBe(true);
|
|
194
216
|
});
|
|
195
217
|
});
|
|
196
218
|
|
|
197
|
-
describe(
|
|
198
|
-
it(
|
|
199
|
-
const { useDarkMode } = await import(
|
|
219
|
+
describe('initializeMode', () => {
|
|
220
|
+
it('should set currentMode', async () => {
|
|
221
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
200
222
|
const { initializeMode, currentMode, getModeAutoPrefers } = useDarkMode();
|
|
201
223
|
|
|
202
224
|
const mode = getModeAutoPrefers();
|
|
@@ -205,10 +227,10 @@ describe("useDarkMode", () => {
|
|
|
205
227
|
});
|
|
206
228
|
});
|
|
207
229
|
|
|
208
|
-
describe(
|
|
209
|
-
describe(
|
|
210
|
-
it(
|
|
211
|
-
const { useDarkMode } = await import(
|
|
230
|
+
describe('autoModeWatcher', () => {
|
|
231
|
+
describe('given mode changes', () => {
|
|
232
|
+
it('should set modeCurrent', async () => {
|
|
233
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
212
234
|
const darkMode = useDarkMode();
|
|
213
235
|
|
|
214
236
|
const mql = {
|
|
@@ -217,7 +239,7 @@ describe("useDarkMode", () => {
|
|
|
217
239
|
darkMode.setModeCurrent(mql.matches);
|
|
218
240
|
},
|
|
219
241
|
};
|
|
220
|
-
vi.spyOn(window,
|
|
242
|
+
vi.spyOn(window, 'matchMedia').mockReturnValueOnce(mql as any);
|
|
221
243
|
|
|
222
244
|
darkMode.autoModeWatcher();
|
|
223
245
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { computed, readonly, Ref, ref } from
|
|
2
|
-
import { usePlatform } from
|
|
1
|
+
import { computed, readonly, Ref, ref } from 'vue';
|
|
2
|
+
import { usePlatform } from '../utils/platform/platform.service';
|
|
3
3
|
|
|
4
4
|
const { isBrowser } = usePlatform();
|
|
5
5
|
|
|
@@ -16,15 +16,15 @@ const isDark = computed(() => currentMode.value === MODE.DARK);
|
|
|
16
16
|
const useDarkMode = () => {
|
|
17
17
|
const getModeOsPrefers = (): boolean => {
|
|
18
18
|
let prefersLightMode = false;
|
|
19
|
-
if (isBrowser) prefersLightMode = window.matchMedia(
|
|
19
|
+
if (isBrowser) prefersLightMode = window.matchMedia('(prefers-color-scheme: light)').matches;
|
|
20
20
|
setModeOsPrefers(prefersLightMode);
|
|
21
21
|
return prefersLightMode;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
const getModeUserPrefers = (): boolean | undefined => {
|
|
25
25
|
if (isBrowser) {
|
|
26
|
-
const mode = localStorage.getItem(
|
|
27
|
-
if (mode !== null) modeUserPrefers.value = mode ===
|
|
26
|
+
const mode = localStorage.getItem('modeUserPrefers');
|
|
27
|
+
if (mode !== null) modeUserPrefers.value = mode === 'true';
|
|
28
28
|
}
|
|
29
29
|
return modeUserPrefers.value;
|
|
30
30
|
};
|
|
@@ -39,19 +39,19 @@ const useDarkMode = () => {
|
|
|
39
39
|
const setModeOsPrefers = (value: boolean) => {
|
|
40
40
|
modeOsPrefers.value = value;
|
|
41
41
|
if (isBrowser) {
|
|
42
|
-
localStorage.setItem(
|
|
42
|
+
localStorage.setItem('modeOsPrefers', value.toString());
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
const setModeUserPrefers = (value: boolean): void => {
|
|
46
46
|
modeUserPrefers.value = value;
|
|
47
47
|
if (isBrowser) {
|
|
48
|
-
localStorage.setItem(
|
|
48
|
+
localStorage.setItem('modeUserPrefers', value.toString());
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
const setModeCurrent = (value: boolean) => {
|
|
53
53
|
const elemHtmlClasses = document.documentElement.classList;
|
|
54
|
-
const classDark =
|
|
54
|
+
const classDark = 'dark';
|
|
55
55
|
value === MODE.LIGHT ? elemHtmlClasses.remove(classDark) : elemHtmlClasses.add(classDark);
|
|
56
56
|
currentMode.value = value;
|
|
57
57
|
};
|
|
@@ -62,7 +62,7 @@ const useDarkMode = () => {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
const autoModeWatcher = (): void => {
|
|
65
|
-
const mql = window.matchMedia(
|
|
65
|
+
const mql = window.matchMedia('(prefers-color-scheme: light)');
|
|
66
66
|
const setMode = (value: boolean) => {
|
|
67
67
|
const elemHtmlClasses = document.documentElement.classList;
|
|
68
68
|
const classDark = `dark`;
|