@code-coaching/vuetiful 0.23.2 → 0.24.1

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 (36) hide show
  1. package/dist/types/components/atoms/VLightSwitch.vue.d.ts +5 -1
  2. package/dist/types/services/dark-mode.service.d.ts +13 -13
  3. package/dist/types/services/index.d.ts +2 -2
  4. package/dist/types/utils/colors/colors.service.d.ts +69 -0
  5. package/dist/types/utils/index.d.ts +5 -1
  6. package/dist/types/utils/theme/theme.service.d.ts +12 -23
  7. package/dist/types/utils/theme/themes.d.ts +39 -0
  8. package/dist/vuetiful.es.mjs +452 -146
  9. package/dist/vuetiful.umd.js +71 -16
  10. package/package.json +1 -1
  11. package/src/components/atoms/VLightSwitch.test.ts +61 -12
  12. package/src/components/atoms/VLightSwitch.vue +13 -19
  13. package/src/components/molecules/VTabs/VTab.test.ts +21 -0
  14. package/src/directives/clipboard.test.ts +2 -2
  15. package/src/services/dark-mode.service.test.ts +58 -210
  16. package/src/services/dark-mode.service.ts +32 -51
  17. package/src/services/drawer.service.test.ts +4 -4
  18. package/src/services/highlight.service.test.ts +3 -3
  19. package/src/services/index.ts +2 -2
  20. package/src/services/rail.service.test.ts +2 -2
  21. package/src/utils/colors/colors.service.ts +293 -0
  22. package/src/utils/index.ts +5 -1
  23. package/src/utils/platform/platform.service.test.ts +3 -3
  24. package/src/utils/theme/callback.test.ts +9 -5
  25. package/src/utils/theme/remove.test.ts +7 -5
  26. package/src/utils/theme/theme-switcher.vue +34 -37
  27. package/src/utils/theme/theme.service.test.ts +160 -58
  28. package/src/utils/theme/theme.service.ts +140 -78
  29. package/src/utils/theme/themes.ts +127 -0
  30. package/dist/types/components/index.test.d.ts +0 -1
  31. package/dist/types/index.test.d.ts +0 -1
  32. package/dist/types/utils/index.test.d.ts +0 -1
  33. package/src/components/index.test.ts +0 -10
  34. package/src/index.test.ts +0 -26
  35. package/src/utils/index.test.ts +0 -11
  36. /package/src/themes/{theme-vuetiful-0.0.1.css → theme-vuetiful.css} +0 -0
@@ -1,11 +1,11 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, test } from 'vitest';
2
2
  import { useDrawer } from './drawer.service';
3
3
 
4
4
  const { drawer, open, close } = useDrawer();
5
5
 
6
6
  describe('useDrawer', () => {
7
7
  describe('defaults', () => {
8
- it('should have the default values', () => {
8
+ test('should have the default values', () => {
9
9
  expect(drawer.id).toBe('default');
10
10
  expect(drawer.open).toBe(false);
11
11
  expect(drawer.position).toBe('left');
@@ -16,7 +16,7 @@ describe('useDrawer', () => {
16
16
  });
17
17
 
18
18
  describe('open', () => {
19
- it('should use the settings', () => {
19
+ test('should use the settings', () => {
20
20
  open({
21
21
  id: 'test',
22
22
  open: true,
@@ -35,7 +35,7 @@ describe('useDrawer', () => {
35
35
  });
36
36
 
37
37
  describe('close', () => {
38
- it('should set the drawer to close', () => {
38
+ test('should set the drawer to close', () => {
39
39
  open();
40
40
  expect(drawer.open).toBe(true);
41
41
  close();
@@ -1,4 +1,4 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, test } from 'vitest';
2
2
  import { useHighlight } from './highlight.service';
3
3
 
4
4
  const { highlight } = useHighlight();
@@ -6,7 +6,7 @@ const { highlight } = useHighlight();
6
6
  describe('useHighlight', () => {
7
7
  describe('highlight', () => {
8
8
  describe('given a known language is passed', () => {
9
- it('should trim and highlight the code', () => {
9
+ test('should trim and highlight the code', () => {
10
10
  expect(highlight(" const name = 'John Duck' ", 'javascript')).toEqual(
11
11
  '<span class="hljs-keyword">const</span> name = <span class="hljs-string">&#x27;John Duck&#x27;</span>',
12
12
  );
@@ -14,7 +14,7 @@ describe('useHighlight', () => {
14
14
  });
15
15
 
16
16
  describe('given an unknown language is passed', () => {
17
- it('should trim and auto highlight the code', () => {
17
+ test('should trim and auto highlight the code', () => {
18
18
  expect(highlight(" const name = 'John Duck' ", 'unknown')).toEqual(
19
19
  '<span class="hljs-keyword">const</span> <span class="hljs-keyword">name</span> = <span class="hljs-string">&#x27;John Duck&#x27;</span>',
20
20
  );
@@ -1,8 +1,8 @@
1
- import { useDarkMode } from './dark-mode.service';
1
+ import { useDarkMode, Mode } from './dark-mode.service';
2
2
  import { useDrawer } from './drawer.service';
3
3
  import { useHighlight } from './highlight.service';
4
4
  import { useRail } from './rail.service';
5
5
  import { useSettings, VuetifulSettings } from './settings.service';
6
6
 
7
7
  export { useDarkMode, useDrawer, useHighlight, useRail, useSettings };
8
- export type { VuetifulSettings };
8
+ export type { VuetifulSettings, Mode };
@@ -1,11 +1,11 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, test } from 'vitest';
2
2
  import { useRail } from './rail.service';
3
3
 
4
4
  const { selectedRailTile } = useRail();
5
5
 
6
6
  describe('useRail', () => {
7
7
  describe('selectedRailTile', () => {
8
- it('should expose selectedRailTile', () => {
8
+ test('should expose selectedRailTile', () => {
9
9
  selectedRailTile.value = 'John Duck';
10
10
  expect(selectedRailTile.value).toBe('John Duck');
11
11
  });
@@ -0,0 +1,293 @@
1
+ // This file is taken from Skeleton - wrapped in a useColors composable function
2
+ type ContrastLevel = 'AA' | 'AAA';
3
+ type ContrastSize = 'small' | 'large';
4
+
5
+ export interface Report {
6
+ emoji: string;
7
+ note: string;
8
+ }
9
+
10
+ export interface PassReport {
11
+ textColor: string;
12
+ backgroundColor: string;
13
+ contrast: number;
14
+ report: Report;
15
+ smallAA: boolean;
16
+ smallAAA: boolean;
17
+ largeAA: boolean;
18
+ largeAAA: boolean;
19
+ fails: boolean;
20
+ }
21
+
22
+ export type Palette = {
23
+ [key: number]: {
24
+ hex: string;
25
+ rgb: string;
26
+ on: string;
27
+ };
28
+ };
29
+
30
+ export const semanticNames = ['primary', 'secondary', 'tertiary', 'success', 'warning', 'error', 'surface'] as const;
31
+ export type SemanticNames = (typeof semanticNames)[number];
32
+ export interface ColorSettings {
33
+ key: SemanticNames;
34
+ label: string;
35
+ hex: string;
36
+ rgb: string;
37
+ on: string;
38
+ }
39
+
40
+ type Rgb = {
41
+ r: number;
42
+ g: number;
43
+ b: number;
44
+ };
45
+
46
+ const useColors = () => {
47
+ function hexToRgb(hex: string): Rgb | null {
48
+ const sanitizedHex = hex.replaceAll('##', '#');
49
+ const colorParts = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(sanitizedHex);
50
+
51
+ if (!colorParts) return null;
52
+
53
+ const [, r, g, b] = colorParts;
54
+
55
+ return {
56
+ r: parseInt(r, 16),
57
+ g: parseInt(g, 16),
58
+ b: parseInt(b, 16),
59
+ } as Rgb;
60
+ }
61
+
62
+ function hexToTailwindRgbString(hex: string): string {
63
+ const sanitizedHex = hex.replaceAll('##', '#');
64
+ const colorParts = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(sanitizedHex);
65
+
66
+ if (!colorParts) return '(invalid)';
67
+
68
+ const [, r, g, b] = colorParts;
69
+
70
+ return `${parseInt(r, 16)} ${parseInt(g, 16)} ${parseInt(b, 16)}`;
71
+ }
72
+
73
+ function rgbToHex(r: number, g: number, b: number): string {
74
+ const toHex = (c: number) => `0${c.toString(16)}`.slice(-2);
75
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
76
+ }
77
+
78
+ function generateA11yOnColor(hex: string): '255 255 255' | '0 0 0' {
79
+ const black = calculateRatio(hex, '#000000');
80
+ const white = calculateRatio(hex, '#FFFFFF');
81
+ return black < white ? '0 0 0' : '255 255 255';
82
+ }
83
+
84
+ function lighten(hex: string, intensity: number): string {
85
+ const color = hexToRgb(`#${hex}`);
86
+
87
+ if (!color) return '';
88
+
89
+ const r = Math.round(color.r + (255 - color.r) * intensity);
90
+ const g = Math.round(color.g + (255 - color.g) * intensity);
91
+ const b = Math.round(color.b + (255 - color.b) * intensity);
92
+
93
+ return rgbToHex(r, g, b);
94
+ }
95
+
96
+ function darken(hex: string, intensity: number): string {
97
+ const color = hexToRgb(hex);
98
+
99
+ if (!color) return '';
100
+
101
+ const r = Math.round(color.r * intensity);
102
+ const g = Math.round(color.g * intensity);
103
+ const b = Math.round(color.b * intensity);
104
+
105
+ return rgbToHex(r, g, b);
106
+ }
107
+
108
+ function generatePalette(baseColor: string): Palette {
109
+ const hexValidation = new RegExp(/^#[0-9a-f]{6}$/i);
110
+ if (!hexValidation.test(baseColor)) baseColor = '#CCCCCC';
111
+
112
+ const hex500 = `#${baseColor}`.replace('##', '#');
113
+
114
+ const response: Palette = {
115
+ 500: { hex: hex500, rgb: hexToTailwindRgbString(hex500), on: generateA11yOnColor(hex500) },
116
+ };
117
+
118
+ const intensityMap: { [key: number]: number } = {
119
+ 50: 0.85,
120
+ 100: 0.8,
121
+ 200: 0.75,
122
+ 300: 0.6,
123
+ 400: 0.3,
124
+ 600: 0.9,
125
+ 700: 0.75,
126
+ 800: 0.6,
127
+ 900: 0.49,
128
+ };
129
+
130
+ [50, 100, 200, 300, 400].forEach((level) => {
131
+ const hex = lighten(baseColor, intensityMap[level]);
132
+ response[level] = { hex, rgb: hexToTailwindRgbString(hex), on: generateA11yOnColor(hex) };
133
+ });
134
+
135
+ [600, 700, 800, 900].forEach((level) => {
136
+ const hex = darken(baseColor, intensityMap[level]);
137
+ response[level] = { hex, rgb: hexToTailwindRgbString(hex), on: generateA11yOnColor(hex) };
138
+ });
139
+
140
+ return response as Palette;
141
+ }
142
+
143
+ const contrastLevels: Record<
144
+ ContrastSize,
145
+ {
146
+ [key in ContrastLevel]: number;
147
+ }
148
+ > = {
149
+ /** For text that is less than 18pt */
150
+ small: {
151
+ AA: 1 / 4.5,
152
+ AAA: 1 / 7,
153
+ },
154
+ /** For text that is at or is larger than 18pt */
155
+ large: {
156
+ AA: 1 / 3,
157
+ AAA: 1 / 4.5,
158
+ },
159
+ };
160
+
161
+ /** Takes the RGB and returns the luminance of it */
162
+ function getLuminance(r: Rgb): number;
163
+ function getLuminance(r: number, g: number, b: number): number;
164
+ function getLuminance(r: number | Rgb, g?: number, b?: number) {
165
+ const { _r, _g, _b } = typeof r === 'object' ? { _r: r.r, _g: r.g, _b: r.b } : { _r: r, _g: g, _b: b }; // I'm not really happy with this ternary, but it works
166
+ // we can't use !_r shorthand here because 0 is a valid value
167
+ if (_r === undefined || _g === undefined || _b === undefined) throw new Error('Invalid RGB value!');
168
+ const a = [_r, _g, _b].map(function (v) {
169
+ v /= 255;
170
+ return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
171
+ });
172
+ return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
173
+ }
174
+
175
+ function destringRgb(rgbString: string): Rgb {
176
+ const rgb = rgbString.match(/(\d+),?\s*(\d+),?\s*(\d+)/); // matches "255, 255, 255" and "255 255 255"
177
+ if (!rgb) throw new Error('Invalid RGB string!');
178
+ return { r: parseInt(rgb[1], 10), g: parseInt(rgb[2], 10), b: parseInt(rgb[3], 10) };
179
+ }
180
+
181
+ // overload to specify that when there is no returnType, it will always return Rgb
182
+ function handleStringColor(colorString: string): Rgb;
183
+ function handleStringColor(colorString: string, returnType: 'rgb'): Rgb;
184
+ function handleStringColor(colorString: string, returnType: 'hex'): string;
185
+ function handleStringColor(colorString: string, returnType?: 'hex' | 'rgb'): string | Rgb;
186
+ function handleStringColor(colorString: string, returnType: 'hex' | 'rgb' = 'rgb'): string | Rgb {
187
+ // if it's a css variable
188
+ if (colorString.includes('--')) {
189
+ colorString = colorString.replace(/var\(|\)/g, ''); // grab just the variable name
190
+ const cssVarHydrated = getComputedStyle(document.documentElement).getPropertyValue(colorString).trim();
191
+ return handleStringColor(cssVarHydrated, returnType);
192
+ }
193
+ // if it has spaces, it's an rgb string
194
+ if (colorString.includes(' ')) {
195
+ const rgb = destringRgb(colorString);
196
+ return returnType === 'hex' ? rgbToHex(rgb.r, rgb.g, rgb.b) : rgb;
197
+ }
198
+
199
+ // if it's a hex string
200
+ if (colorString.includes('#')) {
201
+ const rgb = hexToRgb(colorString);
202
+ if (!rgb) return '(invalid)';
203
+ return returnType === 'hex' ? colorString : rgb;
204
+ }
205
+ return colorString;
206
+ }
207
+
208
+ function calculateRatio(luminance1: string | number, luminance2: string | number) {
209
+ const lum1 = typeof luminance1 === 'string' ? getLuminance(handleStringColor(luminance1)) : luminance1;
210
+ const lum2 = typeof luminance2 === 'string' ? getLuminance(handleStringColor(luminance2)) : luminance2;
211
+ if (lum1 === undefined || lum2 === undefined) throw new Error('Luminance is undefined!');
212
+ return lum1 > lum2 ? (lum2 + 0.05) / (lum1 + 0.05) : (lum1 + 0.05) / (lum2 + 0.05);
213
+ }
214
+
215
+ function textPasses(textColor: string, backgroundColor: string, size: ContrastSize, level: ContrastLevel) {
216
+ const ratio = calculateRatio(textColor, backgroundColor);
217
+ return ratio <= contrastLevels[size][level];
218
+ }
219
+
220
+ function hexValueIsValid(textColor: string) {
221
+ return /^#[0-9A-F]{6}$/i.test(textColor);
222
+ }
223
+
224
+ /** A catch-all function to give a report on what size and level a given combination achieves. */
225
+ function getPassReport(textColor: string, backgroundColor: string): PassReport {
226
+ const _textColor = handleStringColor(textColor, 'hex');
227
+ const _backgroundColor = handleStringColor(backgroundColor, 'hex');
228
+ const contrast = calculateRatio(_textColor, _backgroundColor);
229
+ const smallAA = textPasses(_textColor, _backgroundColor, 'small', 'AA');
230
+ const smallAAA = textPasses(_textColor, _backgroundColor, 'small', 'AAA');
231
+ const largeAA = textPasses(_textColor, _backgroundColor, 'large', 'AA');
232
+ const largeAAA = textPasses(_textColor, _backgroundColor, 'large', 'AAA');
233
+ const fails = !smallAA && !smallAAA && !largeAA && !largeAAA;
234
+ const AAAEmoji = '<i class="fa-solid fa-heart"></i>';
235
+ const AAEmoji = '<i class="fa-solid fa-star"></i>';
236
+ const largeAAEmoji = '<i class="fa-solid fa-star-half-stroke"></i>';
237
+ const failEmoji = '<i class="fa-solid fa-triangle-exclamation"></i>';
238
+ const report = {
239
+ emoji: smallAAA ? AAAEmoji : smallAA ? AAEmoji : largeAA ? largeAAEmoji : failEmoji,
240
+ note:
241
+ `${_textColor} and ${_backgroundColor} ` +
242
+ (smallAAA
243
+ ? 'has great contrast!'
244
+ : smallAA
245
+ ? 'is satisfactory for larger text'
246
+ : largeAA
247
+ ? 'has poor contrast'
248
+ : 'fail contrast guidelines'),
249
+ };
250
+ return {
251
+ textColor: _textColor,
252
+ backgroundColor: _backgroundColor,
253
+ contrast,
254
+ report,
255
+ smallAA,
256
+ smallAAA,
257
+ largeAA,
258
+ largeAAA,
259
+ fails,
260
+ };
261
+ }
262
+
263
+ const hexValuesAreValid = (colors: Array<ColorSettings>) => {
264
+ let valid = true;
265
+ colors?.forEach((color: ColorSettings) => {
266
+ valid = valid && hexValueIsValid(color.hex);
267
+ });
268
+
269
+ return valid;
270
+ };
271
+
272
+ return {
273
+ hexToRgb,
274
+ hexToTailwindRgbString,
275
+ rgbToHex,
276
+ generateA11yOnColor,
277
+ lighten,
278
+ darken,
279
+ generatePalette,
280
+ contrastLevels,
281
+ getLuminance,
282
+ destringRgb,
283
+ handleStringColor,
284
+ calculateRatio,
285
+ textPasses,
286
+ hexValueIsValid,
287
+ getPassReport,
288
+ hexValuesAreValid,
289
+ semanticNames
290
+ };
291
+ };
292
+
293
+ export { useColors };
@@ -1,4 +1,8 @@
1
+ import type { ColorSettings, Palette, PassReport, Report, SemanticNames } from './colors/colors.service';
2
+ import { useColors } from './colors/colors.service';
3
+ import { usePlatform } from './platform/platform.service';
1
4
  import ThemeSwitcher from './theme/theme-switcher.vue';
2
5
  import { useTheme } from './theme/theme.service';
3
6
 
4
- export { ThemeSwitcher, useTheme };
7
+ export { ThemeSwitcher, useColors, usePlatform, useTheme };
8
+ export type { ColorSettings, Palette, PassReport, Report, SemanticNames };
@@ -1,16 +1,16 @@
1
- import { describe, expect, it, vi } from 'vitest';
1
+ import { describe, expect, vi, test } from 'vitest';
2
2
  import { usePlatform } from './platform.service';
3
3
 
4
4
  const matchMediaMock = (matches: boolean) => vi.fn(() => ({ matches, onchange: vi.fn() }));
5
5
 
6
6
  describe('usePlatform', () => {
7
7
  describe('isBrowser', () => {
8
- it('should return true when window is defined', () => {
8
+ test('should return true when window is defined', () => {
9
9
  const { isBrowser } = usePlatform();
10
10
  expect(isBrowser).toBe(true);
11
11
  });
12
12
 
13
- it('should return false when window is not defined', () => {
13
+ test('should return false when window is not defined', () => {
14
14
  window = undefined as any;
15
15
  const { isBrowser } = usePlatform();
16
16
  expect(isBrowser).toBe(false);
@@ -1,4 +1,4 @@
1
- import { describe, expect, it, vi } from 'vitest';
1
+ import { describe, expect, vi, test } from 'vitest';
2
2
 
3
3
  /**
4
4
  * No clue why, but when this test is added to theme.service.test.ts, it fails.
@@ -6,16 +6,20 @@ import { describe, expect, it, vi } from 'vitest';
6
6
  */
7
7
 
8
8
  describe('given there is a callback', () => {
9
- it('should call the callback', async () => {
9
+ test('should call the callback', async () => {
10
10
  const { useTheme } = await import('./theme.service');
11
- const { loadTheme } = useTheme();
11
+ const { applyTheme, themes } = useTheme();
12
12
 
13
13
  const callbackSpy = vi.fn();
14
14
  const callbackFunction = () => {
15
15
  callbackSpy();
16
16
  };
17
- loadTheme('vuetiful', callbackFunction);
18
- const link = document.querySelector('#theme') as HTMLLinkElement;
17
+
18
+ const newTheme = JSON.parse(JSON.stringify(themes[0]));
19
+ newTheme.name = 'new-theme';
20
+ applyTheme(newTheme, callbackFunction);
21
+
22
+ const link = document.querySelector('#vuetiful-theme') as HTMLLinkElement;
19
23
  // @ts-ignore
20
24
  link.onload();
21
25
 
@@ -1,4 +1,4 @@
1
- import { describe, expect, it, vi } from 'vitest';
1
+ import { describe, expect, vi, test } from 'vitest';
2
2
 
3
3
  /**
4
4
  * No clue why, but when this test is added to theme.service.test.ts, it fails.
@@ -6,17 +6,19 @@ import { describe, expect, it, vi } from 'vitest';
6
6
  */
7
7
 
8
8
  describe('given there is no existing theme style tag', () => {
9
- it('should create a new theme style tag', async () => {
9
+ test('should create a new theme style tag', async () => {
10
10
  const { useTheme } = await import('./theme.service');
11
- const { loadTheme } = useTheme();
11
+ const { applyTheme, themes } = useTheme();
12
12
 
13
13
  const removeObject = { remove: () => {} };
14
14
  const removeSpy = vi.spyOn(removeObject, 'remove');
15
15
  vi.spyOn(window.document, 'getElementById').mockReturnValueOnce(removeObject as any);
16
16
 
17
- loadTheme('vuetiful');
17
+ const newTheme = JSON.parse(JSON.stringify(themes[0]));
18
+ newTheme.name = 'new-theme';
19
+ applyTheme(newTheme);
18
20
 
19
- const link = document.querySelector('#theme') as HTMLLinkElement;
21
+ const link = document.querySelector('#vuetiful-theme') as HTMLLinkElement;
20
22
  // @ts-ignore
21
23
  link.onload();
22
24
 
@@ -1,36 +1,3 @@
1
- <template>
2
- <div class="vuetiful-theme-switcher">
3
- <v-button :class="`vuetiful-theme-switcher__button ${classButton}`" @click="showPopup = !showPopup">
4
- Theme
5
- </v-button>
6
-
7
- <div
8
- v-if="showPopup"
9
- class="vuetiful-theme-switcher__popup absolute z-10 mt-1 space-y-4 p-4 shadow-xl rounded-container-token"
10
- :class="`${background} ${text} ${widthPopup} ${classList}`"
11
- >
12
- <section class="flex items-center justify-between">
13
- <div class="text-lg">Mode</div>
14
- <v-light-switch />
15
- </section>
16
- <nav
17
- class="vuetiful-theme-switcher__popup-list -m-4 flex flex-col gap-4 overflow-y-auto p-4"
18
- :class="`${heightList} ${classList}`"
19
- >
20
- <v-button
21
- class="vuetiful-theme-switcher__popup-list-item h-full w-full p-2 text-center capitalize hover:cursor-pointer"
22
- v-for="(theme, index) in themes"
23
- :class="`${classListItem} ${chosenTheme === theme.name ? 'variant-filled-surface' : ''}`"
24
- :key="index"
25
- @click="loadTheme(theme.name)"
26
- >
27
- {{ theme.name }}
28
- </v-button>
29
- </nav>
30
- </div>
31
- </div>
32
- </template>
33
-
34
1
  <script setup lang="ts">
35
2
  import { CssClasses, useTheme, VButton, VLightSwitch } from '@/index';
36
3
  import { onMounted, ref } from 'vue';
@@ -68,10 +35,40 @@ defineProps({
68
35
  },
69
36
  });
70
37
 
71
- const { initializeTheme, loadTheme, themes, chosenTheme } = useTheme();
38
+ const { applyTheme, themes, chosenTheme } = useTheme();
72
39
 
73
40
  const showPopup = ref(false);
74
- onMounted(() => {
75
- initializeTheme();
76
- });
77
41
  </script>
42
+
43
+ <template>
44
+ <div class="vuetiful-theme-switcher">
45
+ <v-button :class="`vuetiful-theme-switcher__button ${classButton}`" @click="showPopup = !showPopup">
46
+ Theme
47
+ </v-button>
48
+
49
+ <div
50
+ v-if="showPopup"
51
+ class="vuetiful-theme-switcher__popup absolute z-10 mt-1 space-y-4 p-4 shadow-xl rounded-container-token"
52
+ :class="`${background} ${text} ${widthPopup} ${classList}`"
53
+ >
54
+ <section class="flex items-center justify-between">
55
+ <div class="text-lg">Mode</div>
56
+ <v-light-switch />
57
+ </section>
58
+ <nav
59
+ class="vuetiful-theme-switcher__popup-list -m-4 flex flex-col gap-4 overflow-y-auto p-4"
60
+ :class="`${heightList} ${classList}`"
61
+ >
62
+ <v-button
63
+ class="vuetiful-theme-switcher__popup-list-item h-full w-full p-2 text-center capitalize hover:cursor-pointer"
64
+ v-for="(theme, index) in themes"
65
+ :class="`${classListItem} ${chosenTheme.name === theme.name ? 'variant-filled-surface' : ''}`"
66
+ :key="index"
67
+ @click="applyTheme(theme)"
68
+ >
69
+ {{ theme.name }}
70
+ </v-button>
71
+ </nav>
72
+ </div>
73
+ </div>
74
+ </template>