srcdev-nuxt-forms 2.1.38 → 2.1.40

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.
@@ -28,6 +28,7 @@ export const propValidators = {
28
28
  checkboxStyle: ['check', 'cross'],
29
29
  radioAppearance: [null, 'with-decorator'],
30
30
  optionsLayout: ['block', 'inline', 'equal-widths'],
31
+ labelWeight: ['normal', 'semi-bold', 'bold'],
31
32
  inputTypesButton: ['button', 'cancel', 'reset', 'submit'],
32
33
  inputTypesText: ['text', 'email', 'password', 'number', 'tel', 'url'],
33
34
  inputMode: ['text', 'email', 'tel', 'url', 'search', 'numeric', 'none', 'decimal'],
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div class="toggle-switch-core" :class="elementClasses" :data-size="size" :data-form-theme="formTheme">
3
- <label class="toggle-switch-input" :class="[{ round }]" :for="inputId">
3
+ <div @click="toggleSwitchValue" class="toggle-switch-input" :class="[{ round }]" :for="inputId">
4
4
  <input type="checkbox" v-model="modelValue" :true-value :false-value :id="inputId" :aria-describedby="`${id}-description`" :name :required />
5
5
  <div class="symbol-wrapper" :class="[{ round }]">
6
6
  <div class="symbol" :class="[{ round }]">
@@ -13,7 +13,7 @@
13
13
  </div>
14
14
  </div>
15
15
  </div>
16
- </label>
16
+ </div>
17
17
  </div>
18
18
  </template>
19
19
 
@@ -85,6 +85,10 @@ const modelValue = defineModel();
85
85
  const { elementClasses, updateElementClasses } = useStyleClassPassthrough(styleClassPassthrough);
86
86
 
87
87
  const inputId = computed(() => `toggle-sitch-${id}`);
88
+
89
+ const toggleSwitchValue = () => {
90
+ modelValue.value = modelValue.value === trueValue ? falseValue : trueValue;
91
+ };
88
92
  </script>
89
93
 
90
94
  <style lang="css">
@@ -1,6 +1,6 @@
1
1
  <template>
2
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>
3
+ <label class="toggle-switch-label input-text-label body-normal-bold" :for="`toggle-sitch-${id}`">{{ label }}</label>
4
4
  <div v-if="hasDescriptionSlot" :id="`${id}-description`">
5
5
  <slot name="description"></slot>
6
6
  </div>
@@ -0,0 +1,103 @@
1
+ <template>
2
+ <div class="toggle-switch-with-label-inline" :class="(elementClasses, size)" :data-form-theme="theme">
3
+ <label class="toggle-switch-label input-text-label" :class="labelWeightClass" :for="`toggle-sitch-${id}`">{{ label }}</label>
4
+ <ToggleSwitchCore v-model="modelValue" :id :name :true-value :false-value :theme :round :size>
5
+ <template v-if="hasIconOnSlot" #iconOn>
6
+ <slot name="iconOn"></slot>
7
+ </template>
8
+
9
+ <template v-if="hasIconOffSlot" #iconOff>
10
+ <slot name="iconOff"></slot>
11
+ </template>
12
+ </ToggleSwitchCore>
13
+ </div>
14
+ </template>
15
+
16
+ <script setup lang="ts">
17
+ import propValidators from '../../c12/prop-validators';
18
+
19
+ const { id, name, label, labelWeight, trueValue, falseValue, styleClassPassthrough, theme, round, size } = defineProps({
20
+ id: {
21
+ type: String,
22
+ required: true,
23
+ },
24
+ name: {
25
+ type: String,
26
+ required: true,
27
+ },
28
+ label: {
29
+ type: String,
30
+ required: true,
31
+ },
32
+ labelWeight: {
33
+ type: String as PropType<string>,
34
+ default: 'semi-bold',
35
+ validator(value: string) {
36
+ return propValidators.labelWeight.includes(value);
37
+ },
38
+ },
39
+ trueValue: {
40
+ type: [String, Number, Boolean],
41
+ default: true,
42
+ },
43
+ falseValue: {
44
+ type: [String, Number, Boolean],
45
+ default: false,
46
+ },
47
+ styleClassPassthrough: {
48
+ type: Array as PropType<string[]>,
49
+ default: () => [],
50
+ },
51
+ theme: {
52
+ type: String as PropType<string>,
53
+ default: 'primary',
54
+ validator(value: string) {
55
+ return propValidators.theme.includes(value);
56
+ },
57
+ },
58
+ round: {
59
+ type: Boolean,
60
+ default: true,
61
+ },
62
+ size: {
63
+ type: String as PropType<string>,
64
+ default: 'normal',
65
+ validator(value: string) {
66
+ return propValidators.size.includes(value);
67
+ },
68
+ },
69
+ });
70
+
71
+ const slots = useSlots();
72
+ const hasIconOnSlot = computed(() => slots.iconOn !== undefined);
73
+ const hasIconOffSlot = computed(() => slots.iconOff !== undefined);
74
+
75
+ const labelWeightClass = computed(() => {
76
+ switch (labelWeight) {
77
+ case 'bold':
78
+ return 'body-normal-bold';
79
+ case 'semi-bold':
80
+ return 'body-normal-semibold';
81
+ case 'normal':
82
+ return 'body-normal';
83
+ default:
84
+ return 'body-normal-semibold';
85
+ }
86
+ });
87
+
88
+ const modelValue = defineModel();
89
+ const { elementClasses, updateElementClasses } = useStyleClassPassthrough(styleClassPassthrough);
90
+ </script>
91
+
92
+ <style lang="css">
93
+ .toggle-switch-with-label-inline {
94
+ --_transition-duration: 0.4s;
95
+ display: flex;
96
+ align-items: center;
97
+ gap: 12px;
98
+
99
+ .toggle-switch-label {
100
+ display: block;
101
+ }
102
+ }
103
+ </style>
@@ -1,12 +1,12 @@
1
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">
2
+ <ToggleSwitchWithLabelInline v-model="displayMode" id="dark-mode-switcher" name="dark-mode-switcher" label="Toggle Dark mode (inline)" size="small">
3
3
  <template #iconOn>
4
4
  <Icon name="radix-icons:moon" class="icon" />
5
5
  </template>
6
6
  <template #iconOff>
7
7
  <Icon name="radix-icons:sun" class="icon" />
8
8
  </template>
9
- </ToggleSwitchCore>
9
+ </ToggleSwitchWithLabelInline>
10
10
  </template>
11
11
 
12
12
  <script setup lang="ts">
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "srcdev-nuxt-forms",
3
3
  "type": "module",
4
- "version": "2.1.38",
4
+ "version": "2.1.40",
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",