srcdev-nuxt-forms 2.1.33 → 2.1.35

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.
@@ -1,12 +1,19 @@
1
- :root {
1
+ html {
2
2
  color-scheme: light dark;
3
- }
4
3
 
5
- html {
6
- /* background-color: var(--body-background-color); */
4
+ &[data-color-scheme='light'] {
5
+ color-scheme: light;
6
+ }
7
+
8
+ &[data-color-scheme='dark'] {
9
+ color-scheme: dark;
10
+ }
11
+
7
12
  background-color: var(--page-bg);
8
13
 
9
14
  font-size: 62.5%;
15
+
16
+ transition: background-color 0.4s ease, color 0.4s ease;
10
17
  }
11
18
  body,
12
19
  p,
@@ -39,7 +39,8 @@ const { id, name, label, required, errorMessage, fieldHasError, trueValue, false
39
39
  },
40
40
  errorMessage: {
41
41
  type: [Object, String],
42
- required: true,
42
+ default: '',
43
+ required: false,
43
44
  },
44
45
  fieldHasError: {
45
46
  type: Boolean,
@@ -0,0 +1,23 @@
1
+ <template>
2
+ <ToggleSwitchCore v-model="displayMode" class="dark-mode-switcher" :class="elementClasses" true-value="dark" false-value="light" name="header-dark-mode-switcher" id="header-dark-mode-switcher">
3
+ <template #iconOn>
4
+ <Icon name="radix-icons:moon" class="icon" />
5
+ </template>
6
+ <template #iconOff>
7
+ <Icon name="radix-icons:sun" class="icon" />
8
+ </template>
9
+ </ToggleSwitchCore>
10
+ </template>
11
+
12
+ <script setup lang="ts">
13
+ const { styleClassPassthrough } = defineProps({
14
+ styleClassPassthrough: {
15
+ type: Array as PropType<string[]>,
16
+ default: () => [],
17
+ },
18
+ });
19
+
20
+ const displayMode = ref<'auto' | 'dark' | 'light'>('auto');
21
+ const { elementClasses } = useStyleClassPassthrough(styleClassPassthrough);
22
+ useColourScheme(displayMode);
23
+ </script>
@@ -0,0 +1,41 @@
1
+ export const useColourScheme = (colourScheme: Ref<'auto' | 'dark' | 'light'> = ref('light')) => {
2
+ const updateColourScheme = (newColourScheme: 'auto' | 'dark' | 'light') => {
3
+ colourScheme.value = newColourScheme;
4
+ };
5
+
6
+ const getSetPrefereredColourScheme = () => {
7
+ if (import.meta.client) {
8
+ if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches && !document.documentElement.dataset.colorScheme) {
9
+ colourScheme.value = 'dark';
10
+ } else {
11
+ colourScheme.value = 'light';
12
+ }
13
+ }
14
+ };
15
+
16
+ onMounted(() => {
17
+ if (import.meta.client) {
18
+ const storedMode = localStorage.getItem('colourScheme');
19
+ if (storedMode) {
20
+ colourScheme.value = storedMode as 'dark' | 'light';
21
+ } else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
22
+ colourScheme.value = 'dark';
23
+ } else {
24
+ colourScheme.value = 'light';
25
+ }
26
+ }
27
+ });
28
+
29
+ watch(colourScheme, (newVal) => {
30
+ if (import.meta.client) {
31
+ localStorage.setItem('colourScheme', newVal);
32
+ document.documentElement.dataset.colorScheme = newVal;
33
+ }
34
+ });
35
+
36
+ return {
37
+ colourScheme,
38
+ updateColourScheme,
39
+ getSetPrefereredColourScheme,
40
+ };
41
+ };
package/nuxt.config.ts CHANGED
@@ -11,6 +11,16 @@ export default defineNuxtConfig({
11
11
  },
12
12
  },
13
13
  },
14
+ app: {
15
+ head: {
16
+ htmlAttrs: {
17
+ lang: 'en',
18
+ 'data-color-scheme': 'auto',
19
+ },
20
+ titleTemplate: '%s - Website name',
21
+ meta: [{ charset: 'utf-8' }, { name: 'viewport', content: 'width=device-width, initial-scale=1' }],
22
+ },
23
+ },
14
24
  components: [
15
25
  {
16
26
  path: './components',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "srcdev-nuxt-forms",
3
3
  "type": "module",
4
- "version": "2.1.33",
4
+ "version": "2.1.35",
5
5
  "main": "nuxt.config.ts",
6
6
  "scripts": {
7
7
  "clean": "rm -rf .nuxt && rm -rf .output && rm -rf .playground/.nuxt && rm -rf .playground/.output",