srcdev-nuxt-forms 2.4.5 → 2.4.6
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.
|
@@ -2,24 +2,24 @@
|
|
|
2
2
|
<div class="colour-scheme-select" :data-size="size" :data-form-theme="theme">
|
|
3
3
|
<p>Color Scheme select</p>
|
|
4
4
|
|
|
5
|
-
<form class="colour-scheme-select-form mbe-20">
|
|
5
|
+
<form class="colour-scheme-select-form mbe-20" ref="colourSchemeWrapper">
|
|
6
6
|
<div class="select-scheme-marker-wrapper">
|
|
7
7
|
<div class="select-scheme-marker"></div>
|
|
8
8
|
</div>
|
|
9
9
|
<div class="select-scheme-group-wrapper">
|
|
10
10
|
<div class="select-scheme-group">
|
|
11
11
|
<LazyIcon name="material-symbols:night-sight-auto-sharp" class="scheme-icon" />
|
|
12
|
-
<input type="radio" id="auto" name="colour-scheme" class="scheme-input" v-model="
|
|
12
|
+
<input type="radio" id="auto" name="colour-scheme" class="scheme-input" v-model="currentColourScheme" value="auto" />
|
|
13
13
|
<label for="auto" class="sr-only">Auto</label>
|
|
14
14
|
</div>
|
|
15
15
|
<div class="select-scheme-group">
|
|
16
16
|
<LazyIcon name="radix-icons:sun" class="scheme-icon" />
|
|
17
|
-
<input type="radio" id="light" name="colour-scheme" class="scheme-input" v-model="
|
|
17
|
+
<input type="radio" id="light" name="colour-scheme" class="scheme-input" v-model="currentColourScheme" value="light" />
|
|
18
18
|
<label for="light" class="sr-only">Light</label>
|
|
19
19
|
</div>
|
|
20
20
|
<div class="select-scheme-group">
|
|
21
21
|
<LazyIcon name="radix-icons:moon" class="scheme-icon" />
|
|
22
|
-
<input type="radio" id="dark" name="colour-scheme" class="scheme-input" v-model="
|
|
22
|
+
<input type="radio" id="dark" name="colour-scheme" class="scheme-input" v-model="currentColourScheme" value="dark" />
|
|
23
23
|
<label for="dark" class="sr-only">Dark</label>
|
|
24
24
|
</div>
|
|
25
25
|
</div>
|
|
@@ -55,9 +55,49 @@ defineProps({
|
|
|
55
55
|
},
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
const
|
|
58
|
+
const { currentColourScheme } = useColourScheme();
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
const colourSchemeWrapper = ref<HTMLFormElement | null>(null);
|
|
61
|
+
const colourSchemeInputElements = ref<HTMLDivElement[]>([]);
|
|
62
|
+
|
|
63
|
+
// console.log('colourSchemeInputElements');
|
|
64
|
+
// console.log(colourSchemeInputElements);
|
|
65
|
+
|
|
66
|
+
const findIndexOfInputValueFromCurrentColourScheme = () => {
|
|
67
|
+
if (currentColourScheme.value === 'auto') return 1;
|
|
68
|
+
if (currentColourScheme.value === 'light') return 2;
|
|
69
|
+
if (currentColourScheme.value === 'dark') return 3;
|
|
70
|
+
return undefined;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// const findLeftOffsetOfInputValueFromCurrentColourScheme = (index: number) => {
|
|
74
|
+
// const normalisedIndex = index - 1;
|
|
75
|
+
|
|
76
|
+
// console.log(`findLeftOffsetOfInputValueFromCurrentColourScheme: ${normalisedIndex}`);
|
|
77
|
+
// console.log(colourSchemeInputElements.value[normalisedIndex].offsetLeft);
|
|
78
|
+
|
|
79
|
+
// return colourSchemeInputElements.value?.[normalisedIndex]?.getBoundingClientRect().left;
|
|
80
|
+
// };
|
|
81
|
+
|
|
82
|
+
const setColourSchemeAttr = () => {
|
|
83
|
+
const index = findIndexOfInputValueFromCurrentColourScheme() ?? 0;
|
|
84
|
+
const wrapperLeftPosition = colourSchemeWrapper.value?.getBoundingClientRect().left ?? 0;
|
|
85
|
+
colourSchemeWrapper.value?.style.setProperty('--_select-scheme-marker-position', index !== undefined ? index.toString() : '0');
|
|
86
|
+
colourSchemeWrapper.value?.style.setProperty('--_select-scheme-marker-left-offset', colourSchemeInputElements.value?.[index - 1]?.offsetLeft - wrapperLeftPosition + 'px');
|
|
87
|
+
colourSchemeWrapper.value?.style.setProperty('--_select-scheme-marker-width', colourSchemeInputElements.value?.[index - 1]?.getBoundingClientRect().width + 'px');
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
onMounted(() => {
|
|
91
|
+
colourSchemeInputElements.value = Array.from(colourSchemeWrapper.value?.querySelectorAll('.select-scheme-group') || []) as HTMLInputElement[];
|
|
92
|
+
|
|
93
|
+
if (colourSchemeWrapper.value !== null) {
|
|
94
|
+
setColourSchemeAttr();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
watch(currentColourScheme, () => {
|
|
99
|
+
setColourSchemeAttr();
|
|
100
|
+
});
|
|
61
101
|
</script>
|
|
62
102
|
|
|
63
103
|
<style lang="css">
|
|
@@ -77,14 +117,14 @@ useColourScheme(colourScheme);
|
|
|
77
117
|
--_form-items-gap: 1rem;
|
|
78
118
|
--_form-padding: 0.6rem;
|
|
79
119
|
|
|
80
|
-
--_select-scheme-marker-position: 1;
|
|
120
|
+
/* --_select-scheme-marker-position: 1; */
|
|
81
121
|
|
|
82
122
|
--_select-scheme-group-background-color: red;
|
|
83
123
|
--_select-scheme-group-padding: 0.5rem;
|
|
84
|
-
--_select-scheme-group-border-width: 0.
|
|
85
|
-
--_select-scheme-group-border-colour:
|
|
86
|
-
--_select-scheme-group-outline-width: 0.
|
|
87
|
-
--_select-scheme-group-outline-colour:
|
|
124
|
+
--_select-scheme-group-border-width: 0.2rem;
|
|
125
|
+
--_select-scheme-group-border-colour: transparent;
|
|
126
|
+
--_select-scheme-group-outline-width: 0.2rem;
|
|
127
|
+
--_select-scheme-group-outline-colour: transparent;
|
|
88
128
|
--_select-scheme-group-width: calc(
|
|
89
129
|
var(--_scheme-icon-font-size) + (var(--_select-scheme-group-padding) * 2) + (var(--_select-scheme-group-border-width) * 2) + (var(--_select-scheme-group-outline-width) * 2)
|
|
90
130
|
);
|
|
@@ -101,30 +141,37 @@ useColourScheme(colourScheme);
|
|
|
101
141
|
border: var(--_form-border-width) solid var(--_form-border-colour);
|
|
102
142
|
outline: var(--_form-outline-width) solid var(--_form-outline-colour);
|
|
103
143
|
border-radius: var(--_form-border-radius);
|
|
104
|
-
padding: var(--_form-padding);
|
|
105
144
|
|
|
106
145
|
.select-scheme-marker-wrapper {
|
|
107
146
|
grid-area: select-stack;
|
|
108
|
-
display: grid;
|
|
147
|
+
/* display: grid; */
|
|
109
148
|
/* grid-template-columns: repeat(3, 1fr); */
|
|
110
|
-
grid-template-columns: repeat(3, 1fr);
|
|
111
149
|
z-index: 1;
|
|
112
|
-
grid-area: select-stack;
|
|
113
|
-
gap: var(--_form-items-gap);
|
|
114
|
-
transition: all 200ms;
|
|
115
|
-
transition-behavior: allow-discrete;
|
|
150
|
+
/* grid-area: select-stack; */
|
|
151
|
+
/* gap: var(--_form-items-gap); */
|
|
152
|
+
/* transition: all 200ms; */
|
|
153
|
+
/* transition-behavior: allow-discrete; */
|
|
116
154
|
|
|
117
|
-
display: none;
|
|
155
|
+
/* display: none; */
|
|
156
|
+
|
|
157
|
+
display: flex;
|
|
158
|
+
align-items: center;
|
|
159
|
+
position: relative;
|
|
118
160
|
|
|
119
161
|
.select-scheme-marker {
|
|
120
|
-
grid-column: var(--_select-scheme-marker-position);
|
|
162
|
+
/* grid-column: var(--_select-scheme-marker-position); */
|
|
121
163
|
aspect-ratio: 1;
|
|
122
164
|
/* width: calc(var(--_select-scheme-group-width) + (var(--_form-outline-width) * 2)); */
|
|
123
165
|
/* translate: -1px 0; */
|
|
124
166
|
width: var(--_select-scheme-group-width);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
167
|
+
/* translate: calc(var(--_select-scheme-marker-left-offset) - var(--_form-items-gap) - (var(--_select-scheme-group-outline-width) * 1) - (var(--_select-scheme-group-border-width) * 1)) 0; */
|
|
168
|
+
/* translate: calc(var(--_select-scheme-marker-left-offset) - (var(--_select-scheme-group-outline-width) * 1) - (var(--_select-scheme-group-border-width) * 1)) 0; */
|
|
169
|
+
transition: all 300ms ease-in-out;
|
|
170
|
+
background-color: var(--theme-form-radio-border);
|
|
171
|
+
border-radius: 50%;
|
|
172
|
+
|
|
173
|
+
position: absolute;
|
|
174
|
+
left: calc(var(--_select-scheme-marker-left-offset) - var(--_form-border-width) - var(--_form-outline-width) - 1px);
|
|
128
175
|
}
|
|
129
176
|
}
|
|
130
177
|
|
|
@@ -134,6 +181,7 @@ useColourScheme(colourScheme);
|
|
|
134
181
|
grid-template-columns: repeat(3, 1fr);
|
|
135
182
|
align-items: center;
|
|
136
183
|
width: fit-content;
|
|
184
|
+
padding: var(--_form-padding);
|
|
137
185
|
z-index: 2;
|
|
138
186
|
gap: var(--_form-items-gap);
|
|
139
187
|
|
|
@@ -141,7 +189,7 @@ useColourScheme(colourScheme);
|
|
|
141
189
|
aspect-ratio: 1;
|
|
142
190
|
display: grid;
|
|
143
191
|
grid-template-areas: 'icon-stack';
|
|
144
|
-
width: var(--_select-scheme-
|
|
192
|
+
/* width: var(--_select-scheme-marker-width); */
|
|
145
193
|
place-content: center;
|
|
146
194
|
background-color: var(--_select-scheme-group-background-color);
|
|
147
195
|
border: var(--_select-scheme-group-border-width) solid var(--_select-scheme-group-border-colour);
|
|
@@ -169,9 +217,9 @@ useColourScheme(colourScheme);
|
|
|
169
217
|
--_select-scheme-group-background-color: green;
|
|
170
218
|
|
|
171
219
|
&:has(input[value='auto']:checked) {
|
|
172
|
-
--_select-scheme-marker-position: 1;
|
|
173
|
-
--_select-scheme-group-border-colour: var(--theme-form-radio-border);
|
|
174
|
-
--_select-scheme-group-outline-colour: var(--theme-form-radio-outline);
|
|
220
|
+
/* --_select-scheme-marker-position: 1; */
|
|
221
|
+
/* --_select-scheme-group-border-colour: var(--theme-form-radio-border); */
|
|
222
|
+
/* --_select-scheme-group-outline-colour: var(--theme-form-radio-outline); */
|
|
175
223
|
}
|
|
176
224
|
}
|
|
177
225
|
|
|
@@ -179,9 +227,9 @@ useColourScheme(colourScheme);
|
|
|
179
227
|
--_select-scheme-group-background-color: orange;
|
|
180
228
|
|
|
181
229
|
&:has(input[value='light']:checked) {
|
|
182
|
-
--_select-scheme-marker-position: 2;
|
|
183
|
-
--_select-scheme-group-border-colour: var(--theme-form-radio-border);
|
|
184
|
-
--_select-scheme-group-outline-colour: var(--theme-form-radio-outline);
|
|
230
|
+
/* --_select-scheme-marker-position: 2; */
|
|
231
|
+
/* --_select-scheme-group-border-colour: var(--theme-form-radio-border); */
|
|
232
|
+
/* --_select-scheme-group-outline-colour: var(--theme-form-radio-outline); */
|
|
185
233
|
}
|
|
186
234
|
}
|
|
187
235
|
|
|
@@ -189,9 +237,9 @@ useColourScheme(colourScheme);
|
|
|
189
237
|
--_select-scheme-group-background-color: black;
|
|
190
238
|
|
|
191
239
|
&:has(input[value='dark']:checked) {
|
|
192
|
-
--_select-scheme-marker-position: 3;
|
|
193
|
-
--_select-scheme-group-border-colour: var(--theme-form-radio-border);
|
|
194
|
-
--_select-scheme-group-outline-colour: var(--theme-form-radio-outline);
|
|
240
|
+
/* --_select-scheme-marker-position: 3; */
|
|
241
|
+
/* --_select-scheme-group-border-colour: var(--theme-form-radio-border); */
|
|
242
|
+
/* --_select-scheme-group-outline-colour: var(--theme-form-radio-outline); */
|
|
195
243
|
}
|
|
196
244
|
}
|
|
197
245
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<ToggleSwitchWithLabelInline v-model="
|
|
2
|
+
<ToggleSwitchWithLabelInline v-model="currentColourScheme" :name :label labelWeight="normal" :size trueValue="dark" falseValue="light" :style-class-passthrough>
|
|
3
3
|
<template #iconOn>
|
|
4
4
|
<LazyIcon name="radix-icons:moon" class="icon" />
|
|
5
5
|
</template>
|
|
@@ -41,7 +41,7 @@ defineProps({
|
|
|
41
41
|
},
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
const displayMode = ref<'auto' | 'dark' | 'light'>('auto');
|
|
44
|
+
// const displayMode = ref<'auto' | 'dark' | 'light'>('auto');
|
|
45
45
|
|
|
46
|
-
useColourScheme(
|
|
46
|
+
const { currentColourScheme } = useColourScheme();
|
|
47
47
|
</script>
|
|
@@ -1,41 +1,58 @@
|
|
|
1
|
-
export const useColourScheme = (
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
export const useColourScheme = () => {
|
|
2
|
+
// const currentColourScheme = computed(() => {
|
|
3
|
+
// return colourScheme.value;
|
|
4
|
+
// });
|
|
5
|
+
|
|
6
|
+
const currentColourScheme = ref<'auto' | 'dark' | 'light' | null>(null);
|
|
7
|
+
|
|
8
|
+
// const updateColourScheme = (newColourScheme: 'auto' | 'dark' | 'light') => {
|
|
9
|
+
// colourScheme.value = newColourScheme;
|
|
10
|
+
// };
|
|
11
|
+
|
|
12
|
+
// const getSetPrefereredColourScheme = () => {
|
|
13
|
+
// if (import.meta.client) {
|
|
14
|
+
// if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches && !document.documentElement.dataset.colorScheme) {
|
|
15
|
+
// colourScheme.value = 'dark';
|
|
16
|
+
// } else {
|
|
17
|
+
// colourScheme.value = 'light';
|
|
18
|
+
// }
|
|
19
|
+
// }
|
|
20
|
+
// };
|
|
5
21
|
|
|
6
|
-
const
|
|
22
|
+
const returnSavedColourPreferenceFromLocalStorage = () => {
|
|
7
23
|
if (import.meta.client) {
|
|
8
|
-
|
|
9
|
-
colourScheme.value = 'dark';
|
|
10
|
-
} else {
|
|
11
|
-
colourScheme.value = 'light';
|
|
12
|
-
}
|
|
24
|
+
return localStorage.getItem('colourScheme') as 'auto' | 'dark' | 'light' | null;
|
|
13
25
|
}
|
|
14
26
|
};
|
|
15
27
|
|
|
16
28
|
onMounted(() => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
29
|
+
currentColourScheme.value = returnSavedColourPreferenceFromLocalStorage() || 'auto';
|
|
30
|
+
// colourScheme.value = currentColourScheme.value;
|
|
31
|
+
//
|
|
32
|
+
// if (import.meta.client) {
|
|
33
|
+
// const savedColourScheme = localStorage.getItem('colourScheme');
|
|
34
|
+
// if (savedColourScheme) {
|
|
35
|
+
// colourScheme.value = savedColourScheme as 'dark' | 'light';
|
|
36
|
+
// } else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
37
|
+
// colourScheme.value = 'dark';
|
|
38
|
+
// } else {
|
|
39
|
+
// colourScheme.value = 'light';
|
|
40
|
+
// }
|
|
41
|
+
// }
|
|
27
42
|
});
|
|
28
43
|
|
|
29
|
-
watch(
|
|
30
|
-
if (import.meta.client) {
|
|
44
|
+
watch(currentColourScheme, (newVal) => {
|
|
45
|
+
if (import.meta.client && newVal !== null) {
|
|
31
46
|
localStorage.setItem('colourScheme', newVal);
|
|
32
47
|
document.documentElement.dataset.colorScheme = newVal;
|
|
48
|
+
currentColourScheme.value = newVal;
|
|
33
49
|
}
|
|
34
50
|
});
|
|
35
51
|
|
|
36
52
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
53
|
+
currentColourScheme,
|
|
54
|
+
// colourScheme,
|
|
55
|
+
// updateColourScheme,
|
|
56
|
+
// getSetPrefereredColourScheme,
|
|
40
57
|
};
|
|
41
58
|
};
|
package/package.json
CHANGED