srcdev-nuxt-forms 2.1.29 → 2.1.31

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.
@@ -27,6 +27,16 @@
27
27
 
28
28
  --theme-form-range-accent-color: light-dark(var(--red-12), var(--red-3));
29
29
 
30
+ /*
31
+ * ToggleSwitch
32
+ **/
33
+ --theme-form-toggle-bg-off: light-dark(var(--gray-1), var(--gray-4));
34
+ --theme-form-toggle-bg-on: light-dark(var(--gray-1), var(--gray-6));
35
+ --theme-form-toggle-border: 1px solid light-dark(var(--red-12), var(--red-1));
36
+ --theme-form-toggle-outline: 1px solid light-dark(var(--red-12), var(--red-12));
37
+ --theme-form-toggle-symbol-off: var(--orange-12);
38
+ --theme-form-toggle-symbol-on: var(--gray-12);
39
+
30
40
  /*
31
41
  * Checkbox as button
32
42
  **/
@@ -27,6 +27,16 @@
27
27
 
28
28
  --theme-form-range-accent-color: light-dark(var(--gray-12), var(--gray-3));
29
29
 
30
+ /*
31
+ * ToggleSwitch
32
+ **/
33
+ --theme-form-toggle-bg-off: light-dark(var(--gray-1), var(--gray-4));
34
+ --theme-form-toggle-bg-on: light-dark(var(--gray-1), var(--gray-6));
35
+ --theme-form-toggle-border: 1px solid light-dark(var(--gray-12), var(--gray-1));
36
+ --theme-form-toggle-outline: 1px solid light-dark(var(--gray-12), var(--gray-12));
37
+ --theme-form-toggle-symbol-off: var(--gray-4);
38
+ --theme-form-toggle-symbol-on: var(--gray-12);
39
+
30
40
  /*
31
41
  * Checkbox as button
32
42
  **/
@@ -27,6 +27,16 @@
27
27
 
28
28
  --theme-form-range-accent-color: light-dark(var(--blue-12), var(--blue-));
29
29
 
30
+ /*
31
+ * ToggleSwitch
32
+ **/
33
+ --theme-form-toggle-bg-off: light-dark(var(--gray-1), var(--gray-4));
34
+ --theme-form-toggle-bg-on: light-dark(var(--gray-1), var(--gray-6));
35
+ --theme-form-toggle-border: 1px solid light-dark(var(--blue-12), var(--blue-1));
36
+ --theme-form-toggle-outline: 1px solid light-dark(var(--blue-12), var(--blue-12));
37
+ --theme-form-toggle-symbol-off: var(--blue-7);
38
+ --theme-form-toggle-symbol-on: var(--gray-12);
39
+
30
40
  /*
31
41
  * Checkbox as button
32
42
  **/
@@ -27,6 +27,16 @@
27
27
 
28
28
  --theme-form-range-accent-color: light-dark(var(--gray-12), var(--gray-3));
29
29
 
30
+ /*
31
+ * ToggleSwitch
32
+ **/
33
+ --theme-form-toggle-bg-off: light-dark(var(--gray-1), var(--gray-4));
34
+ --theme-form-toggle-bg-on: light-dark(var(--gray-1), var(--gray-6));
35
+ --theme-form-toggle-border: 1px solid light-dark(var(--gray-12), var(--gray-1));
36
+ --theme-form-toggle-outline: 1px solid light-dark(var(--gray-12), var(--gray-12));
37
+ --theme-form-toggle-symbol-off: var(--gray-4);
38
+ --theme-form-toggle-symbol-on: var(--gray-12);
39
+
30
40
  /*
31
41
  * Checkbox as button
32
42
  **/
@@ -27,6 +27,16 @@
27
27
 
28
28
  --theme-form-range-accent-color: light-dark(var(--green-12), var(--green-3));
29
29
 
30
+ /*
31
+ * ToggleSwitch
32
+ **/
33
+ --theme-form-toggle-bg-off: light-dark(var(--gray-1), var(--gray-4));
34
+ --theme-form-toggle-bg-on: light-dark(var(--gray-1), var(--gray-6));
35
+ --theme-form-toggle-border: 1px solid light-dark(var(--green-12), var(--green-1));
36
+ --theme-form-toggle-outline: 1px solid light-dark(var(--green-12), var(--green-12));
37
+ --theme-form-toggle-symbol-off: var(--green-4);
38
+ --theme-form-toggle-symbol-on: var(--green-12);
39
+
30
40
  /*
31
41
  * Checkbox as button
32
42
  **/
@@ -27,6 +27,16 @@
27
27
 
28
28
  --theme-form-range-accent-color: light-dark(var(--gray-12), var(--gray-3));
29
29
 
30
+ /*
31
+ * ToggleSwitch
32
+ **/
33
+ --theme-form-toggle-bg-off: light-dark(var(--gray-1), var(--gray-4));
34
+ --theme-form-toggle-bg-on: light-dark(var(--gray-1), var(--gray-6));
35
+ --theme-form-toggle-border: 1px solid light-dark(var(--gray-12), var(--gray-1));
36
+ --theme-form-toggle-outline: 1px solid light-dark(var(--gray-12), var(--gray-12));
37
+ --theme-form-toggle-symbol-off: var(--gray-4);
38
+ --theme-form-toggle-symbol-on: var(--gray-12);
39
+
30
40
  /*
31
41
  * Checkbox as button
32
42
  **/
@@ -27,6 +27,16 @@
27
27
 
28
28
  --theme-form-range-accent-color: light-dark(var(--orange-12), var(--orange-3));
29
29
 
30
+ /*
31
+ * ToggleSwitch
32
+ **/
33
+ --theme-form-toggle-bg-off: light-dark(var(--gray-1), var(--gray-4));
34
+ --theme-form-toggle-bg-on: light-dark(var(--gray-1), var(--gray-6));
35
+ --theme-form-toggle-border: 1px solid light-dark(var(--orange-12), var(--orange-1));
36
+ --theme-form-toggle-outline: 1px solid light-dark(var(--orange-12), var(--orange-12));
37
+ --theme-form-toggle-symbol-off: var(--orange-12);
38
+ --theme-form-toggle-symbol-on: var(--gray-12);
39
+
30
40
  /*
31
41
  * Checkbox as button
32
42
  **/
@@ -0,0 +1,228 @@
1
+ <template>
2
+ <div class="toggle-switch-core" :class="(elementClasses, size)" :data-form-theme="formTheme">
3
+ <label class="toggle-switch-input" :class="[{ round }]" :for="inputId">
4
+ <input type="checkbox" v-model="modelValue" :true-value :false-value :id="inputId" :aria-describedby="`${id}-description`" :name :required />
5
+ <div class="symbol-wrapper" :class="[{ round }]">
6
+ <div class="symbol" :class="[{ round }]">
7
+ <div v-if="hasIconOnSlot" class="symbol-icon icon-on">
8
+ <slot name="iconOn"></slot>
9
+ </div>
10
+
11
+ <div v-if="hasIconOffSlot" class="symbol-icon icon-off">
12
+ <slot name="iconOff"></slot>
13
+ </div>
14
+ </div>
15
+ </div>
16
+ </label>
17
+ </div>
18
+ </template>
19
+
20
+ <script setup lang="ts">
21
+ import propValidators from '../c12/prop-validators';
22
+
23
+ const { id, name, required, fieldHasError, trueValue, falseValue, styleClassPassthrough, theme, round, size, ariaDescribedby } = defineProps({
24
+ id: {
25
+ type: String,
26
+ required: true,
27
+ },
28
+ name: {
29
+ type: String,
30
+ required: true,
31
+ },
32
+ required: {
33
+ type: Boolean,
34
+ default: false,
35
+ },
36
+ fieldHasError: {
37
+ type: Boolean,
38
+ default: false,
39
+ },
40
+ trueValue: {
41
+ type: [String, Number, Boolean],
42
+ default: true,
43
+ },
44
+ falseValue: {
45
+ type: [String, Number, Boolean],
46
+ default: false,
47
+ },
48
+ styleClassPassthrough: {
49
+ type: Array as PropType<string[]>,
50
+ default: () => [],
51
+ },
52
+ theme: {
53
+ type: String as PropType<string>,
54
+ default: 'primary',
55
+ validator(value: string) {
56
+ return propValidators.theme.includes(value);
57
+ },
58
+ },
59
+ round: {
60
+ type: Boolean,
61
+ default: true,
62
+ },
63
+ size: {
64
+ type: String as PropType<string>,
65
+ default: 'normal',
66
+ validator(value: string) {
67
+ return propValidators.size.includes(value);
68
+ },
69
+ },
70
+ ariaDescribedby: {
71
+ type: String,
72
+ default: null,
73
+ },
74
+ });
75
+
76
+ const slots = useSlots();
77
+ const hasIconOnSlot = computed(() => slots.iconOn !== undefined);
78
+ const hasIconOffSlot = computed(() => slots.iconOff !== undefined);
79
+
80
+ const formTheme = computed(() => {
81
+ return fieldHasError ? 'error' : theme;
82
+ });
83
+
84
+ const modelValue = defineModel();
85
+ const { elementClasses, updateElementClasses } = useStyleClassPassthrough(styleClassPassthrough);
86
+
87
+ const inputId = computed(() => `toggle-sitch-${id}`);
88
+ </script>
89
+
90
+ <style lang="css">
91
+ .toggle-switch-core {
92
+ --_transition-duration: 0.4s;
93
+
94
+ .toggle-switch-label {
95
+ display: block;
96
+ }
97
+
98
+ .toggle-switch-input {
99
+ position: relative;
100
+ display: inline-block;
101
+
102
+ input {
103
+ opacity: 0;
104
+ width: 0;
105
+ height: 0;
106
+ }
107
+ input:checked {
108
+ --_icon-on-opacity: 1;
109
+ --_icon-off-opacity: 0;
110
+ }
111
+
112
+ /* The symbol */
113
+ .symbol-wrapper {
114
+ position: absolute;
115
+ cursor: pointer;
116
+ top: 0;
117
+ left: 0;
118
+ right: 0;
119
+ bottom: 0;
120
+ overflow: clip;
121
+
122
+ .symbol {
123
+ display: grid;
124
+ grid-template-areas: 'icon-stack';
125
+ overflow: clip;
126
+ position: absolute;
127
+
128
+ .symbol-icon {
129
+ grid-area: icon-stack;
130
+ display: flex;
131
+ align-items: center;
132
+ justify-content: center;
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+
139
+ /*
140
+ * ToggleSwitch configurable
141
+ **/
142
+ .toggle-switch-core {
143
+ /* Sizes */
144
+ &.x-small {
145
+ --_symbol-size: 20px;
146
+ }
147
+ &.small {
148
+ --_symbol-size: 24px;
149
+ }
150
+ &.normal {
151
+ --_symbol-size: 34px;
152
+ }
153
+ &.medium {
154
+ --_symbol-size: 40px;
155
+ }
156
+ &.large {
157
+ --_symbol-size: 44px;
158
+ }
159
+
160
+ /* .toggle-switch-label {
161
+ } */
162
+
163
+ .toggle-switch-input {
164
+ border: var(--theme-form-toggle-border);
165
+ outline: var(--theme-form-toggle-outline);
166
+ width: calc(var(--_symbol-size) * 2 - 4px);
167
+ height: calc(var(--_symbol-size) + 4px);
168
+
169
+ &.round {
170
+ border-radius: calc(var(--_symbol-size) + 2px);
171
+ }
172
+
173
+ .symbol-wrapper {
174
+ background-color: var(--theme-form-toggle-bg-off);
175
+ transition: 0.4s;
176
+
177
+ &.round {
178
+ border-radius: var(--_symbol-size);
179
+ }
180
+ .symbol {
181
+ height: calc(var(--_symbol-size) - 6px);
182
+ width: calc(var(--_symbol-size) - 6px);
183
+ left: 4px;
184
+ bottom: 4px;
185
+ background-color: var(--theme-form-toggle-symbol-off);
186
+ transition: var(--_transition-duration);
187
+
188
+ &.round {
189
+ border-radius: 50%;
190
+ }
191
+
192
+ .symbol-icon {
193
+ transition: opacity var(--_transition-duration);
194
+
195
+ &.icon-on {
196
+ opacity: 0;
197
+ }
198
+ &.icon-off {
199
+ opacity: 1;
200
+ }
201
+ }
202
+ }
203
+ }
204
+
205
+ /* input:checked + .symbol-wrapper .symbol {
206
+ background-color: var(--theme-form-toggle-bg-on);
207
+ } */
208
+
209
+ input:focus-visible + .symbol-wrapper {
210
+ box-shadow: var(--theme-form-focus-box-shadow);
211
+ }
212
+
213
+ input:checked + .symbol-wrapper .symbol {
214
+ background-color: var(--theme-form-toggle-symbol-on);
215
+ transform: translateX(26px);
216
+
217
+ .symbol-icon {
218
+ &.icon-on {
219
+ opacity: 1;
220
+ }
221
+ &.icon-off {
222
+ opacity: 0;
223
+ }
224
+ }
225
+ }
226
+ }
227
+ }
228
+ </style>
@@ -0,0 +1,107 @@
1
+ <template>
2
+ <div class="toggle-switch-with-label" :class="(elementClasses, size)" :data-form-theme="formTheme">
3
+ <p class="toggle-switch-label input-text-label body-normal-bold" :for="`toggle-sitch-${id}`">{{ label }}</p>
4
+ <div v-if="hasDescriptionSlot" :id="`${id}-description`">
5
+ <slot name="description"></slot>
6
+ </div>
7
+ <ToggleSwitchCore v-model="modelValue" :id :name :required :field-has-error :true-value :false-value :theme :round :size :ariaDescribedby>
8
+ <template v-if="hasIconOnSlot" #iconOn>
9
+ <slot name="iconOn"></slot>
10
+ </template>
11
+
12
+ <template v-if="hasIconOffSlot" #iconOff>
13
+ <slot name="iconOff"></slot>
14
+ </template>
15
+ </ToggleSwitchCore>
16
+ <InputError :errorMessage="errorMessage" :showError="fieldHasError" :id="errorId" :isDetached="true" />
17
+ </div>
18
+ </template>
19
+
20
+ <script setup lang="ts">
21
+ import propValidators from '../../c12/prop-validators';
22
+
23
+ const { id, name, label, required, errorMessage, fieldHasError, trueValue, falseValue, styleClassPassthrough, theme, round, size } = defineProps({
24
+ id: {
25
+ type: String,
26
+ required: true,
27
+ },
28
+ name: {
29
+ type: String,
30
+ required: true,
31
+ },
32
+ label: {
33
+ type: String,
34
+ required: true,
35
+ },
36
+ required: {
37
+ type: Boolean,
38
+ default: false,
39
+ },
40
+ errorMessage: {
41
+ type: [Object, String],
42
+ required: true,
43
+ },
44
+ fieldHasError: {
45
+ type: Boolean,
46
+ default: false,
47
+ },
48
+ trueValue: {
49
+ type: [String, Number, Boolean],
50
+ default: true,
51
+ },
52
+ falseValue: {
53
+ type: [String, Number, Boolean],
54
+ default: false,
55
+ },
56
+ styleClassPassthrough: {
57
+ type: Array as PropType<string[]>,
58
+ default: () => [],
59
+ },
60
+ theme: {
61
+ type: String as PropType<string>,
62
+ default: 'primary',
63
+ validator(value: string) {
64
+ return propValidators.theme.includes(value);
65
+ },
66
+ },
67
+ round: {
68
+ type: Boolean,
69
+ default: true,
70
+ },
71
+ size: {
72
+ type: String as PropType<string>,
73
+ default: 'normal',
74
+ validator(value: string) {
75
+ return propValidators.size.includes(value);
76
+ },
77
+ },
78
+ });
79
+
80
+ const slots = useSlots();
81
+ const hasDescriptionSlot = computed(() => slots.description !== undefined);
82
+ const hasIconOnSlot = computed(() => slots.iconOn !== undefined);
83
+ const hasIconOffSlot = computed(() => slots.iconOff !== undefined);
84
+
85
+ const formTheme = computed(() => {
86
+ return fieldHasError ? 'error' : theme;
87
+ });
88
+
89
+ const errorId = `${id}-error-message`;
90
+ const ariaDescribedby = computed(() => {
91
+ const ariaDescribedbyId = hasDescriptionSlot.value ? `${id}-description` : null;
92
+ return fieldHasError ? errorId : ariaDescribedbyId;
93
+ });
94
+
95
+ const modelValue = defineModel();
96
+ const { elementClasses, updateElementClasses } = useStyleClassPassthrough(styleClassPassthrough);
97
+ </script>
98
+
99
+ <style lang="css">
100
+ .toggle-switch-with-label {
101
+ --_transition-duration: 0.4s;
102
+
103
+ .toggle-switch-label {
104
+ display: block;
105
+ }
106
+ }
107
+ </style>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "srcdev-nuxt-forms",
3
3
  "type": "module",
4
- "version": "2.1.29",
4
+ "version": "2.1.31",
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",