@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.
Files changed (151) hide show
  1. package/dist/style.css +1 -1
  2. package/dist/types/components/VBootstrap.vue.d.ts +1 -1
  3. package/dist/types/components/atoms/VAvatar.vue.d.ts +1 -1
  4. package/dist/types/components/atoms/VLightSwitch.vue.d.ts +7 -3
  5. package/dist/types/components/atoms/index.d.ts +13 -13
  6. package/dist/types/components/index.d.ts +2 -2
  7. package/dist/types/components/molecules/VAlert.vue.d.ts +1 -1
  8. package/dist/types/components/molecules/VCodeBlock.vue.d.ts +2 -2
  9. package/dist/types/components/molecules/VDrawer.vue.d.ts +1 -1
  10. package/dist/types/components/molecules/VListbox/VListbox.vue.d.ts +1 -1
  11. package/dist/types/components/molecules/VRail/VRail.vue.d.ts +1 -1
  12. package/dist/types/components/molecules/VRail/VRailTile.vue.d.ts +1 -1
  13. package/dist/types/components/molecules/index.d.ts +21 -21
  14. package/dist/types/directives/clipboard.d.ts +1 -1
  15. package/dist/types/directives/index.d.ts +1 -1
  16. package/dist/types/index.d.ts +6 -6
  17. package/dist/types/props/props.d.ts +1 -1
  18. package/dist/types/services/dark-mode.service.d.ts +13 -13
  19. package/dist/types/services/drawer.service.d.ts +1 -1
  20. package/dist/types/services/index.d.ts +6 -6
  21. package/dist/types/types/index.d.ts +1 -1
  22. package/dist/types/utils/colors/colors.service.d.ts +69 -0
  23. package/dist/types/utils/index.d.ts +7 -3
  24. package/dist/types/utils/theme/theme-switcher.vue.d.ts +1 -1
  25. package/dist/types/utils/theme/theme.service.d.ts +9 -24
  26. package/dist/types/utils/theme/themes.d.ts +35 -0
  27. package/dist/vuetiful.es.mjs +456 -161
  28. package/dist/vuetiful.umd.js +71 -16
  29. package/package.json +1 -1
  30. package/src/assets/main.css +6 -6
  31. package/src/components/VBootstrap.vue +43 -43
  32. package/src/components/atoms/VAvatar.test.ts +71 -71
  33. package/src/components/atoms/VAvatar.vue +22 -23
  34. package/src/components/atoms/VBadge.test.ts +11 -11
  35. package/src/components/atoms/VBadge.vue +2 -2
  36. package/src/components/atoms/VButton.test.ts +82 -82
  37. package/src/components/atoms/VButton.vue +20 -21
  38. package/src/components/atoms/VChip.test.ts +11 -11
  39. package/src/components/atoms/VChip.vue +3 -3
  40. package/src/components/atoms/VLightSwitch.test.ts +63 -14
  41. package/src/components/atoms/VLightSwitch.vue +35 -46
  42. package/src/components/atoms/VRadio/VRadioDescription.test.ts +13 -13
  43. package/src/components/atoms/VRadio/VRadioDescription.vue +2 -2
  44. package/src/components/atoms/VRadio/VRadioGroup.test.ts +40 -40
  45. package/src/components/atoms/VRadio/VRadioGroup.vue +19 -22
  46. package/src/components/atoms/VRadio/VRadioItem.test.ts +67 -67
  47. package/src/components/atoms/VRadio/VRadioItem.vue +10 -13
  48. package/src/components/atoms/VRadio/VRadioLabel.test.ts +13 -13
  49. package/src/components/atoms/VRadio/VRadioLabel.vue +5 -3
  50. package/src/components/atoms/VSwitch/VSwitch.test.ts +33 -33
  51. package/src/components/atoms/VSwitch/VSwitch.vue +24 -27
  52. package/src/components/atoms/VSwitch/VSwitchDescription.test.ts +13 -13
  53. package/src/components/atoms/VSwitch/VSwitchDescription.vue +2 -2
  54. package/src/components/atoms/VSwitch/VSwitchGroup.test.ts +9 -9
  55. package/src/components/atoms/VSwitch/VSwitchGroup.vue +2 -2
  56. package/src/components/atoms/VSwitch/VSwitchLabel.test.ts +19 -19
  57. package/src/components/atoms/VSwitch/VSwitchLabel.vue +2 -2
  58. package/src/components/atoms/index.ts +13 -13
  59. package/src/components/index.ts +2 -2
  60. package/src/components/molecules/VAccordion/VAccordion.test.ts +11 -17
  61. package/src/components/molecules/VAccordion/VAccordion.vue +3 -3
  62. package/src/components/molecules/VAccordion/VAccordionItem.test.ts +55 -55
  63. package/src/components/molecules/VAccordion/VAccordionItem.vue +9 -22
  64. package/src/components/molecules/VAlert.test.ts +38 -38
  65. package/src/components/molecules/VAlert.vue +25 -47
  66. package/src/components/molecules/VCard/VCard.test.ts +25 -25
  67. package/src/components/molecules/VCard/VCard.vue +13 -15
  68. package/src/components/molecules/VCard/VCardBody.test.ts +14 -14
  69. package/src/components/molecules/VCard/VCardBody.vue +4 -8
  70. package/src/components/molecules/VCard/VCardFooter.test.ts +22 -22
  71. package/src/components/molecules/VCard/VCardFooter.vue +10 -8
  72. package/src/components/molecules/VCard/VCardHeader.test.ts +25 -25
  73. package/src/components/molecules/VCard/VCardHeader.vue +7 -8
  74. package/src/components/molecules/VCodeBlock.test.ts +63 -63
  75. package/src/components/molecules/VCodeBlock.vue +27 -34
  76. package/src/components/molecules/VDrawer.test.ts +5 -5
  77. package/src/components/molecules/VDrawer.vue +10 -10
  78. package/src/components/molecules/VListbox/VListbox.test.ts +53 -53
  79. package/src/components/molecules/VListbox/VListbox.vue +31 -32
  80. package/src/components/molecules/VListbox/VListboxButton.test.ts +13 -13
  81. package/src/components/molecules/VListbox/VListboxButton.vue +5 -5
  82. package/src/components/molecules/VListbox/VListboxItem.test.ts +25 -25
  83. package/src/components/molecules/VListbox/VListboxItem.vue +7 -8
  84. package/src/components/molecules/VListbox/VListboxItems.test.ts +14 -14
  85. package/src/components/molecules/VListbox/VListboxItems.vue +9 -11
  86. package/src/components/molecules/VListbox/VListboxLabel.test.ts +10 -10
  87. package/src/components/molecules/VListbox/VListboxLabel.vue +2 -2
  88. package/src/components/molecules/VPreview.test.ts +26 -26
  89. package/src/components/molecules/VPreview.vue +22 -27
  90. package/src/components/molecules/VRail/VRail.test.ts +5 -5
  91. package/src/components/molecules/VRail/VRail.vue +7 -7
  92. package/src/components/molecules/VRail/VRailTile.test.ts +26 -28
  93. package/src/components/molecules/VRail/VRailTile.vue +13 -11
  94. package/src/components/molecules/VShell.test.ts +5 -5
  95. package/src/components/molecules/VShell.vue +11 -20
  96. package/src/components/molecules/VTabs/VTab.test.ts +69 -52
  97. package/src/components/molecules/VTabs/VTab.vue +13 -17
  98. package/src/components/molecules/VTabs/VTabPanel.test.ts +8 -8
  99. package/src/components/molecules/VTabs/VTabPanel.vue +1 -1
  100. package/src/components/molecules/VTabs/VTabs.test.ts +36 -36
  101. package/src/components/molecules/VTabs/VTabs.vue +18 -22
  102. package/src/components/molecules/index.ts +21 -21
  103. package/src/directives/clipboard.test.ts +9 -9
  104. package/src/directives/clipboard.ts +2 -2
  105. package/src/directives/index.ts +1 -1
  106. package/src/env.d.ts +2 -2
  107. package/src/index.ts +7 -7
  108. package/src/props/index.ts +1 -1
  109. package/src/props/props.ts +44 -44
  110. package/src/services/dark-mode.service.test.ts +64 -194
  111. package/src/services/dark-mode.service.ts +35 -54
  112. package/src/services/drawer.service.test.ts +21 -21
  113. package/src/services/drawer.service.ts +10 -10
  114. package/src/services/highlight.service.test.ts +12 -12
  115. package/src/services/highlight.service.ts +1 -1
  116. package/src/services/index.ts +6 -6
  117. package/src/services/rail.service.test.ts +7 -7
  118. package/src/services/rail.service.ts +2 -2
  119. package/src/services/settings.service.test.ts +5 -5
  120. package/src/services/settings.service.ts +1 -1
  121. package/src/styles/all.css +7 -7
  122. package/src/styles/elements/buttons.css +1 -1
  123. package/src/styles/elements/forms.css +7 -7
  124. package/src/styles/elements.css +13 -13
  125. package/src/styles/transitions.css +2 -2
  126. package/src/styles/typography.css +5 -5
  127. package/src/themes/theme-rocket.css +10 -10
  128. package/src/themes/theme-sahara.css +13 -13
  129. package/src/themes/theme-seafoam.css +13 -13
  130. package/src/themes/theme-seasonal.css +4 -4
  131. package/src/themes/theme-skeleton.css +7 -7
  132. package/src/themes/theme-vintage.css +12 -12
  133. package/src/themes/theme-vuetiful-0.0.1.css +13 -13
  134. package/src/types/index.ts +46 -46
  135. package/src/types/tailwind.ts +2 -21
  136. package/src/utils/colors/colors.service.ts +293 -0
  137. package/src/utils/index.ts +7 -3
  138. package/src/utils/platform/platform.service.test.ts +6 -6
  139. package/src/utils/platform/platform.service.ts +1 -1
  140. package/src/utils/theme/callback.test.ts +11 -7
  141. package/src/utils/theme/remove.test.ts +11 -9
  142. package/src/utils/theme/theme-switcher.vue +43 -49
  143. package/src/utils/theme/theme.service.test.ts +194 -84
  144. package/src/utils/theme/theme.service.ts +141 -81
  145. package/src/utils/theme/themes.ts +122 -0
  146. package/dist/types/components/index.test.d.ts +0 -1
  147. package/dist/types/index.test.d.ts +0 -1
  148. package/dist/types/utils/index.test.d.ts +0 -1
  149. package/src/components/index.test.ts +0 -10
  150. package/src/index.test.ts +0 -26
  151. package/src/utils/index.test.ts +0 -11
@@ -1,30 +1,30 @@
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";
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 "./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";
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 "./VTabs/VTab.vue";
14
- import VTabPanel from "./VTabs/VTabPanel.vue";
15
- import VTabs from "./VTabs/VTabs.vue";
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 "./VAccordion/VAccordion.vue";
18
- import VAccordionItem from "./VAccordion/VAccordionItem.vue";
17
+ import VAccordion from './VAccordion/VAccordion.vue';
18
+ import VAccordionItem from './VAccordion/VAccordionItem.vue';
19
19
 
20
- import VAlert from "./VAlert.vue";
20
+ import VAlert from './VAlert.vue';
21
21
 
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";
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 "./VCodeBlock.vue";
27
+ import VCodeBlock from './VCodeBlock.vue';
28
28
 
29
29
  export {
30
30
  VAccordion,
@@ -1,6 +1,6 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
2
- import { DirectiveBinding } from "vue";
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("clipboard", () => {
11
+ describe('clipboard', () => {
12
12
  afterEach(() => {
13
13
  vi.resetAllMocks();
14
14
  });
15
- describe("given the v-clipboard directive is used", () => {
16
- it("should copy text to the clipboard on click", () => {
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("div");
20
- vClipboard(el, { value: "John Duck" } as DirectiveBinding);
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("John Duck");
23
+ expect(navigator.clipboard.writeText).toHaveBeenCalledWith('John Duck');
24
24
  });
25
25
  });
26
26
  });
@@ -1,7 +1,7 @@
1
- import { DirectiveBinding } from "vue";
1
+ import { DirectiveBinding } from 'vue';
2
2
 
3
3
  const clipboard = (el: HTMLElement, binding: DirectiveBinding) => {
4
- el.addEventListener("click", () => {
4
+ el.addEventListener('click', () => {
5
5
  navigator.clipboard.writeText(binding.value);
6
6
  });
7
7
  };
@@ -1,3 +1,3 @@
1
- import vClipboard from "./clipboard";
1
+ import vClipboard from './clipboard';
2
2
 
3
3
  export { vClipboard };
package/src/env.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="vite/client" />
2
2
 
3
- declare module "*.vue" {
4
- import { DefineComponent } from "vue";
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 "./components";
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 "./assets/main.css";
11
- import "./styles/tailwind.css";
10
+ import './assets/main.css';
11
+ import './styles/tailwind.css';
12
12
 
13
13
  export default { install };
14
14
 
15
- export * from "./components";
16
- export * from "./utils";
17
- export * from "./directives";
18
- export * from "./services";
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;
@@ -1 +1 @@
1
- export * from './props';
1
+ export * from './props';
@@ -1,8 +1,8 @@
1
- import { Size, Variant } from "@/types";
2
- import { PropType } from "vue";
1
+ import { Size, Variant } from '@/types';
2
+ import { PropType } from 'vue';
3
3
 
4
4
  const sizeProp = {
5
- type: String as PropType<"xs" | "sm" | "md" | "lg" | "xl">,
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
- | "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"
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 "vitest";
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("useDarkMode", () => {
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
- window.localStorage = localStorageMock as any;
49
- vi.spyOn(window.localStorage, "getItem").mockReturnValueOnce("true");
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
- expect(getModeUserPrefers()).toBe(true);
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
- describe("getModeOsPrefers", () => {
58
- describe("given not in browser", () => {
59
- it("should return default modeOsPrefers", async () => {
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("getModeAutoPrefers", () => {
102
- describe("given not in browser", () => {
103
- it("should return default modeAutoPrefers", async () => {
104
- const platform = await import("../utils/platform/platform.service");
105
- vi.spyOn(platform, "usePlatform").mockReturnValueOnce({ isBrowser: false });
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
- expect(getModeAutoPrefers()).toBe(false);
126
- });
127
- });
128
- describe("given modeUserPrefers in localStorage", () => {
129
- it("should return the value", async () => {
130
- const platform = await import("../utils/platform/platform.service");
131
- vi.spyOn(platform, "usePlatform").mockReturnValueOnce({ isBrowser: true });
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
- const { useDarkMode } = await import("./dark-mode.service");
134
- const { getModeAutoPrefers } = useDarkMode();
48
+ darkMode.autoModeWatcher();
135
49
 
136
- window.localStorage = localStorageMock as any;
137
- vi.spyOn(window.localStorage, "getItem").mockReturnValueOnce("true");
50
+ mql.matches = false;
51
+ mql.onchange?.();
52
+ expect(darkMode.chosenMode.value).toBe('dark');
138
53
 
139
- expect(getModeAutoPrefers()).toBe(true);
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("setModeUserPrefers", () => {
146
- describe("given not in browser", () => {
147
- it("should set modeUserPrefers", async () => {
148
- const platform = await import("../utils/platform/platform.service");
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
- setModeUserPrefers(true);
172
- expect(modeUserPrefers.value).toBe(true);
173
- expect(localStorageSpy).toHaveBeenCalledWith("modeUserPrefers", "true");
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("setModeCurrent", () => {
179
- it("light mode set", async () => {
180
- const { useDarkMode } = await import("./dark-mode.service");
181
- const { setModeCurrent, currentMode, MODE } = useDarkMode();
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
- setModeCurrent(MODE.LIGHT);
184
- expect(currentMode.value).toBe(MODE.LIGHT);
185
- expect(document.documentElement.classList.contains("dark")).toBe(false);
78
+ const cookies = '';
79
+ const result = darkMode.getModeFromCookie(cookies);
80
+ expect(result).toBe('dark');
186
81
  });
187
- it("dark mode set", async () => {
188
- const { useDarkMode } = await import("./dark-mode.service");
189
- const { setModeCurrent, currentMode, MODE } = useDarkMode();
82
+ test('should return mode from cookie', async () => {
83
+ const { useDarkMode } = await import('./dark-mode.service');
84
+ const darkMode = useDarkMode();
190
85
 
191
- setModeCurrent(MODE.DARK);
192
- expect(currentMode.value).toBe(MODE.DARK);
193
- expect(document.documentElement.classList.contains("dark")).toBe(true);
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("initializeMode", () => {
198
- it("should set currentMode", async () => {
199
- const { useDarkMode } = await import("./dark-mode.service");
200
- const { initializeMode, currentMode, getModeAutoPrefers } = useDarkMode();
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 mode = getModeAutoPrefers();
203
- initializeMode();
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
- describe("autoModeWatcher", () => {
209
- describe("given mode changes", () => {
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
  });