@code-coaching/vuetiful 0.23.1 → 0.24.0
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 +7 -3
- 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 +13 -13
- package/dist/types/services/drawer.service.d.ts +1 -1
- package/dist/types/services/index.d.ts +6 -6
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/utils/colors/colors.service.d.ts +69 -0
- package/dist/types/utils/index.d.ts +7 -3
- package/dist/types/utils/theme/theme-switcher.vue.d.ts +1 -1
- package/dist/types/utils/theme/theme.service.d.ts +9 -24
- package/dist/types/utils/theme/themes.d.ts +35 -0
- package/dist/vuetiful.es.mjs +456 -161
- package/dist/vuetiful.umd.js +71 -16
- 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 +63 -14
- package/src/components/atoms/VLightSwitch.vue +35 -46
- 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.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 +69 -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.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 +64 -194
- package/src/services/dark-mode.service.ts +35 -54
- 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 +6 -6
- 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/colors/colors.service.ts +293 -0
- package/src/utils/index.ts +7 -3
- 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 +11 -7
- package/src/utils/theme/remove.test.ts +11 -9
- package/src/utils/theme/theme-switcher.vue +43 -49
- package/src/utils/theme/theme.service.test.ts +194 -84
- package/src/utils/theme/theme.service.ts +141 -81
- package/src/utils/theme/themes.ts +122 -0
- package/dist/types/components/index.test.d.ts +0 -1
- package/dist/types/index.test.d.ts +0 -1
- package/dist/types/utils/index.test.d.ts +0 -1
- package/src/components/index.test.ts +0 -10
- package/src/index.test.ts +0 -26
- package/src/utils/index.test.ts +0 -11
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import VDrawer from
|
|
2
|
-
import VPreview from
|
|
3
|
-
import VRail from
|
|
4
|
-
import VRailTile from
|
|
5
|
-
import VShell from
|
|
1
|
+
import VDrawer from './VDrawer.vue';
|
|
2
|
+
import VPreview from './VPreview.vue';
|
|
3
|
+
import VRail from './VRail/VRail.vue';
|
|
4
|
+
import VRailTile from './VRail/VRailTile.vue';
|
|
5
|
+
import VShell from './VShell.vue';
|
|
6
6
|
|
|
7
|
-
import VListbox from
|
|
8
|
-
import VListboxButton from
|
|
9
|
-
import VListboxItem from
|
|
10
|
-
import VListboxItems from
|
|
11
|
-
import VListboxLabel from
|
|
7
|
+
import VListbox from './VListbox/VListbox.vue';
|
|
8
|
+
import VListboxButton from './VListbox/VListboxButton.vue';
|
|
9
|
+
import VListboxItem from './VListbox/VListboxItem.vue';
|
|
10
|
+
import VListboxItems from './VListbox/VListboxItems.vue';
|
|
11
|
+
import VListboxLabel from './VListbox/VListboxLabel.vue';
|
|
12
12
|
|
|
13
|
-
import VTab from
|
|
14
|
-
import VTabPanel from
|
|
15
|
-
import VTabs from
|
|
13
|
+
import VTab from './VTabs/VTab.vue';
|
|
14
|
+
import VTabPanel from './VTabs/VTabPanel.vue';
|
|
15
|
+
import VTabs from './VTabs/VTabs.vue';
|
|
16
16
|
|
|
17
|
-
import VAccordion from
|
|
18
|
-
import VAccordionItem from
|
|
17
|
+
import VAccordion from './VAccordion/VAccordion.vue';
|
|
18
|
+
import VAccordionItem from './VAccordion/VAccordionItem.vue';
|
|
19
19
|
|
|
20
|
-
import VAlert from
|
|
20
|
+
import VAlert from './VAlert.vue';
|
|
21
21
|
|
|
22
|
-
import VCard from
|
|
23
|
-
import VCardBody from
|
|
24
|
-
import VCardFooter from
|
|
25
|
-
import VCardHeader from
|
|
22
|
+
import VCard from './VCard/VCard.vue';
|
|
23
|
+
import VCardBody from './VCard/VCardBody.vue';
|
|
24
|
+
import VCardFooter from './VCard/VCardFooter.vue';
|
|
25
|
+
import VCardHeader from './VCard/VCardHeader.vue';
|
|
26
26
|
|
|
27
|
-
import VCodeBlock from
|
|
27
|
+
import VCodeBlock from './VCodeBlock.vue';
|
|
28
28
|
|
|
29
29
|
export {
|
|
30
30
|
VAccordion,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { afterEach, describe, expect,
|
|
2
|
-
import { DirectiveBinding } from
|
|
3
|
-
import { vClipboard } from
|
|
1
|
+
import { afterEach, describe, expect, vi, test } 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
|
-
|
|
15
|
+
describe('given the v-clipboard directive is used', () => {
|
|
16
|
+
test('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.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,
|
|
1
|
+
import { afterEach, describe, expect, vi, test } from 'vitest';
|
|
2
2
|
|
|
3
3
|
const localStorageMock = {
|
|
4
4
|
getItem: vi.fn(),
|
|
@@ -6,229 +6,99 @@ 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("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({ isBrowser: false });
|
|
18
|
-
|
|
19
|
-
const { useDarkMode } = await import("./dark-mode.service");
|
|
20
|
-
const { getModeUserPrefers } = useDarkMode();
|
|
21
|
-
expect(getModeUserPrefers()).toBe(undefined);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe("given in browser", () => {
|
|
26
|
-
describe("given no modeUserPrefers in localStorage", () => {
|
|
27
|
-
it("should return default modeUserPrefers", async () => {
|
|
28
|
-
const platform = await import("../utils/platform/platform.service");
|
|
29
|
-
vi.spyOn(platform, "usePlatform").mockReturnValueOnce({ isBrowser: true });
|
|
30
|
-
|
|
31
|
-
const { useDarkMode } = await import("./dark-mode.service");
|
|
32
|
-
const { getModeUserPrefers } = useDarkMode();
|
|
33
|
-
|
|
34
|
-
window.localStorage = localStorageMock as any;
|
|
35
|
-
vi.spyOn(window.localStorage, "getItem").mockReturnValueOnce(null);
|
|
36
|
-
|
|
37
|
-
expect(getModeUserPrefers()).toBe(undefined);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe("given modeUserPrefers in localStorage", () => {
|
|
41
|
-
it("should return the value", async () => {
|
|
42
|
-
const platform = await import("../utils/platform/platform.service");
|
|
43
|
-
vi.spyOn(platform, "usePlatform").mockReturnValueOnce({ isBrowser: true });
|
|
44
|
-
|
|
45
|
-
const { useDarkMode } = await import("./dark-mode.service");
|
|
46
|
-
const { getModeUserPrefers } = useDarkMode();
|
|
47
13
|
|
|
48
|
-
|
|
49
|
-
|
|
14
|
+
describe('applyMode', () => {
|
|
15
|
+
test('light mode set', async () => {
|
|
16
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
17
|
+
const { applyMode, chosenMode, MODE } = useDarkMode();
|
|
50
18
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
19
|
+
applyMode(MODE.LIGHT);
|
|
20
|
+
expect(chosenMode.value).toBe(MODE.LIGHT);
|
|
21
|
+
expect(document.documentElement.classList.contains('dark')).toBe(false);
|
|
54
22
|
});
|
|
55
|
-
|
|
23
|
+
test('dark mode set', async () => {
|
|
24
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
25
|
+
const { applyMode, chosenMode, MODE } = useDarkMode();
|
|
56
26
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const platform = await import("../utils/platform/platform.service");
|
|
61
|
-
vi.spyOn(platform, "usePlatform").mockReturnValueOnce({ isBrowser: false });
|
|
62
|
-
|
|
63
|
-
const { useDarkMode } = await import("./dark-mode.service");
|
|
64
|
-
const { getModeOsPrefers } = useDarkMode();
|
|
65
|
-
expect(getModeOsPrefers()).toBe(false);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe("given in browser", () => {
|
|
70
|
-
describe("given prefers-color-scheme: light", () => {
|
|
71
|
-
it("should return true", async () => {
|
|
72
|
-
const platform = await import("../utils/platform/platform.service");
|
|
73
|
-
vi.spyOn(platform, "usePlatform").mockReturnValueOnce({ isBrowser: true });
|
|
74
|
-
const localStorageSpy = vi.spyOn(window.localStorage, "setItem");
|
|
75
|
-
|
|
76
|
-
const { useDarkMode } = await import("./dark-mode.service");
|
|
77
|
-
const { getModeOsPrefers, MODE } = useDarkMode();
|
|
78
|
-
|
|
79
|
-
window.matchMedia = matchMediaMock(MODE.LIGHT) as any;
|
|
80
|
-
expect(getModeOsPrefers()).toBe(MODE.LIGHT);
|
|
81
|
-
expect(localStorageSpy).toHaveBeenCalledWith("modeOsPrefers", "true");
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
describe("given prefers-color-scheme: dark", () => {
|
|
85
|
-
it("should return false", async () => {
|
|
86
|
-
const platform = await import("../utils/platform/platform.service");
|
|
87
|
-
vi.spyOn(platform, "usePlatform").mockReturnValueOnce({ isBrowser: true });
|
|
88
|
-
const localStorageSpy = vi.spyOn(window.localStorage, "setItem");
|
|
89
|
-
|
|
90
|
-
const { useDarkMode } = await import("./dark-mode.service");
|
|
91
|
-
const { getModeOsPrefers, MODE } = useDarkMode();
|
|
92
|
-
|
|
93
|
-
window.matchMedia = matchMediaMock(MODE.DARK) as any;
|
|
94
|
-
expect(getModeOsPrefers()).toBe(MODE.DARK);
|
|
95
|
-
expect(localStorageSpy).toHaveBeenCalledWith("modeOsPrefers", "false");
|
|
96
|
-
});
|
|
97
|
-
});
|
|
27
|
+
applyMode(MODE.DARK);
|
|
28
|
+
expect(chosenMode.value).toBe(MODE.DARK);
|
|
29
|
+
expect(document.documentElement.classList.contains('dark')).toBe(true);
|
|
98
30
|
});
|
|
99
31
|
});
|
|
100
32
|
|
|
101
|
-
describe(
|
|
102
|
-
describe(
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const { useDarkMode } = await import("./dark-mode.service");
|
|
108
|
-
const { getModeAutoPrefers } = useDarkMode();
|
|
109
|
-
expect(getModeAutoPrefers()).toBe(false);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe("given in browser", () => {
|
|
114
|
-
describe("given no modeUserPrefers in localStorage", () => {
|
|
115
|
-
it("should return default modeAutoPrefers", async () => {
|
|
116
|
-
const platform = await import("../utils/platform/platform.service");
|
|
117
|
-
vi.spyOn(platform, "usePlatform").mockReturnValueOnce({ isBrowser: true });
|
|
118
|
-
|
|
119
|
-
const { useDarkMode } = await import("./dark-mode.service");
|
|
120
|
-
const { getModeAutoPrefers } = useDarkMode();
|
|
121
|
-
|
|
122
|
-
window.localStorage = localStorageMock as any;
|
|
123
|
-
vi.spyOn(window.localStorage, "getItem").mockReturnValueOnce(null);
|
|
33
|
+
describe('autoModeWatcher', () => {
|
|
34
|
+
describe('given mode changes', () => {
|
|
35
|
+
test('should set modeCurrent', async () => {
|
|
36
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
37
|
+
const darkMode = useDarkMode();
|
|
124
38
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
39
|
+
const mql = {
|
|
40
|
+
matches: true,
|
|
41
|
+
onchange: () => {
|
|
42
|
+
const mode = mql.matches ? darkMode.MODE.LIGHT : darkMode.MODE.DARK;
|
|
43
|
+
darkMode.applyMode(mode);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
vi.spyOn(window, 'matchMedia').mockReturnValueOnce(mql as any);
|
|
132
47
|
|
|
133
|
-
|
|
134
|
-
const { getModeAutoPrefers } = useDarkMode();
|
|
48
|
+
darkMode.autoModeWatcher();
|
|
135
49
|
|
|
136
|
-
|
|
137
|
-
|
|
50
|
+
mql.matches = false;
|
|
51
|
+
mql.onchange?.();
|
|
52
|
+
expect(darkMode.chosenMode.value).toBe('dark');
|
|
138
53
|
|
|
139
|
-
|
|
140
|
-
|
|
54
|
+
mql.matches = true;
|
|
55
|
+
mql.onchange?.();
|
|
56
|
+
expect(darkMode.chosenMode.value).toBe('light');
|
|
141
57
|
});
|
|
142
58
|
});
|
|
143
59
|
});
|
|
144
60
|
|
|
145
|
-
describe(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
vi.spyOn(platform, "usePlatform").mockReturnValueOnce({ isBrowser: false });
|
|
150
|
-
vi.spyOn(window.localStorage, "setItem");
|
|
151
|
-
|
|
152
|
-
const { useDarkMode } = await import("./dark-mode.service");
|
|
153
|
-
const { setModeUserPrefers, modeUserPrefers } = useDarkMode();
|
|
154
|
-
|
|
155
|
-
setModeUserPrefers(true);
|
|
156
|
-
expect(modeUserPrefers.value).toBe(true);
|
|
157
|
-
expect(window.localStorage.setItem).not.toHaveBeenCalled();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe("given in browser", () => {
|
|
162
|
-
it("should set modeUserPrefers and localStorage", async () => {
|
|
163
|
-
const platform = await import("../utils/platform/platform.service");
|
|
164
|
-
vi.spyOn(platform, "usePlatform").mockReturnValueOnce({ isBrowser: true });
|
|
165
|
-
|
|
166
|
-
const { useDarkMode } = await import("./dark-mode.service");
|
|
167
|
-
const { setModeUserPrefers, modeUserPrefers } = useDarkMode();
|
|
168
|
-
|
|
169
|
-
const localStorageSpy = vi.spyOn(window.localStorage, "setItem");
|
|
61
|
+
describe('applyModeSSR', () => {
|
|
62
|
+
test('should add dark class to html tag', async () => {
|
|
63
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
64
|
+
const darkMode = useDarkMode();
|
|
170
65
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
66
|
+
const html = '<html>';
|
|
67
|
+
const mode = darkMode.MODE.DARK;
|
|
68
|
+
const result = darkMode.applyModeSSR(html, mode);
|
|
69
|
+
expect(result).toBe('<html class="dark">');
|
|
175
70
|
});
|
|
176
71
|
});
|
|
177
72
|
|
|
178
|
-
describe(
|
|
179
|
-
|
|
180
|
-
const { useDarkMode } = await import(
|
|
181
|
-
const
|
|
73
|
+
describe('getModeFromCookie', () => {
|
|
74
|
+
test('should return default mode if cookie is not set', async () => {
|
|
75
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
76
|
+
const darkMode = useDarkMode();
|
|
182
77
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
expect(
|
|
78
|
+
const cookies = '';
|
|
79
|
+
const result = darkMode.getModeFromCookie(cookies);
|
|
80
|
+
expect(result).toBe('dark');
|
|
186
81
|
});
|
|
187
|
-
|
|
188
|
-
const { useDarkMode } = await import(
|
|
189
|
-
const
|
|
82
|
+
test('should return mode from cookie', async () => {
|
|
83
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
84
|
+
const darkMode = useDarkMode();
|
|
190
85
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
expect(
|
|
86
|
+
const cookies = 'vuetiful-mode=light';
|
|
87
|
+
const result = darkMode.getModeFromCookie(cookies);
|
|
88
|
+
expect(result).toBe('light');
|
|
194
89
|
});
|
|
195
90
|
});
|
|
196
91
|
|
|
197
|
-
describe(
|
|
198
|
-
|
|
199
|
-
const { useDarkMode } = await import(
|
|
200
|
-
const
|
|
92
|
+
describe('initializeMode', () => {
|
|
93
|
+
test('should set mode from cookie', async () => {
|
|
94
|
+
const { useDarkMode } = await import('./dark-mode.service');
|
|
95
|
+
const darkMode = useDarkMode();
|
|
201
96
|
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
expect(currentMode.value).toBe(mode);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
97
|
+
const cookies = 'vuetiful-mode=dark';
|
|
98
|
+
vi.spyOn(document, 'cookie', 'get').mockReturnValueOnce(cookies);
|
|
207
99
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
it("should set modeCurrent", async () => {
|
|
211
|
-
const { useDarkMode } = await import("./dark-mode.service");
|
|
212
|
-
const darkMode = useDarkMode();
|
|
213
|
-
|
|
214
|
-
const mql = {
|
|
215
|
-
matches: true,
|
|
216
|
-
onchange: () => {
|
|
217
|
-
darkMode.setModeCurrent(mql.matches);
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
vi.spyOn(window, "matchMedia").mockReturnValueOnce(mql as any);
|
|
221
|
-
|
|
222
|
-
darkMode.autoModeWatcher();
|
|
223
|
-
|
|
224
|
-
mql.matches = false;
|
|
225
|
-
mql.onchange?.();
|
|
226
|
-
expect(darkMode.currentMode.value).toBe(false);
|
|
227
|
-
|
|
228
|
-
mql.matches = true;
|
|
229
|
-
mql.onchange?.();
|
|
230
|
-
expect(darkMode.currentMode.value).toBe(true);
|
|
231
|
-
});
|
|
100
|
+
darkMode.initializeMode();
|
|
101
|
+
expect(darkMode.chosenMode.value).toBe('dark');
|
|
232
102
|
});
|
|
233
103
|
});
|
|
234
104
|
});
|