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