codevdesign 1.0.41 → 1.0.42

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,120 +1,102 @@
1
1
  <template>
2
- <div>
3
- <v-row dense>
4
- <v-col
5
- cols="9"
6
- md="8"
7
- lg="6"
8
- class="d-flex align-end"
2
+ <v-row
3
+ dense
4
+ class="align-center"
5
+ >
6
+ <!-- Texte + détails -->
7
+ <v-col
8
+ cols="10"
9
+ xl="11"
10
+ class="py-0"
11
+ >
12
+ <component
13
+ :is="labelCliquable ? 'label' : 'div'"
14
+ :for="labelCliquable ? switchId : undefined"
15
+ class="labelSwitchSiSwitchApres"
16
+ :class="{ 'label-cliquable': labelCliquable && !desactiver }"
9
17
  >
10
- <div class="labelSwitchSiSwitchApres">{{ texte }}</div>
11
- </v-col>
12
- <v-col
13
- cols="2"
14
- class="d-flex align-end justify-end"
15
- >
16
- <v-switch
17
- v-model="maValeur"
18
- :disabled="desactiver"
19
- density="compact"
20
- inset
21
- v-bind="$attrs"
22
- hide-details
23
- @update:model-value="sauvegarder"
24
- />
25
- </v-col>
26
- </v-row>
27
- <v-row dense>
28
- <v-col
29
- cols="9"
30
- md="8"
18
+ <slot name="label">
19
+ {{ texte }}
20
+ </slot>
21
+ </component>
22
+
23
+ <div
24
+ v-if="afficherDetails"
25
+ class="details"
31
26
  >
32
- <span v-html="texteDetaille"></span>
33
- </v-col>
34
- </v-row>
35
- </div>
27
+ <slot name="details">
28
+ <span v-html="texteDetaille"></span>
29
+ </slot>
30
+ </div>
31
+ </v-col>
32
+
33
+ <!-- Switch -->
34
+ <v-col
35
+ cols="2"
36
+ xl="1"
37
+ class="d-flex align-center justify-end py-0"
38
+ >
39
+ <v-switch
40
+ :id="switchId"
41
+ v-model="maValeur"
42
+ class="switch-compact"
43
+ :disabled="desactiver"
44
+ :density="($attrs.density as any) ?? 'compact'"
45
+ :inset="($attrs.inset as any) ?? true"
46
+ v-bind="$attrs"
47
+ hide-details
48
+ />
49
+ </v-col>
50
+ </v-row>
36
51
  </template>
52
+
37
53
  <script setup lang="ts">
38
- import { ref, watch, onMounted, type PropType } from 'vue'
54
+ import { computed, useSlots } from 'vue'
39
55
 
40
- // Définition des props
41
56
  const props = defineProps({
42
- valeurInverse: {
43
- type: Boolean,
44
- default: false,
45
- },
46
- desactiver: {
47
- type: Boolean,
48
- default: false,
49
- },
50
- modelValue: {
51
- type: Boolean,
52
- required: true,
53
- },
54
- texte: {
55
- type: String,
56
- required: true,
57
- },
58
- texteDetaille: {
59
- type: String,
60
- required: true,
61
- },
57
+ valeurInverse: { type: Boolean, default: false },
58
+ desactiver: { type: Boolean, default: false },
59
+ modelValue: { type: Boolean, required: true },
60
+ texte: { type: String, required: true },
61
+ texteDetaille: { type: String, default: '' },
62
+ labelCliquable: { type: Boolean, default: true },
62
63
  })
63
64
 
64
- // Définition de l'événement
65
65
  const emit = defineEmits(['update:modelValue'])
66
+ const slots = useSlots()
66
67
 
67
- // Référence pour la valeur interne
68
- const maValeur = ref<boolean>(false)
69
-
70
- // Montée du composant
71
- onMounted(() => {
72
- if (props.valeurInverse) {
73
- maValeur.value = !props.modelValue
74
- } else {
75
- maValeur.value = props.modelValue
76
- }
68
+ const maValeur = computed<boolean>({
69
+ get: () => (props.valeurInverse ? !props.modelValue : props.modelValue),
70
+ set: v => emit('update:modelValue', props.valeurInverse ? !v : v),
77
71
  })
78
72
 
79
- // Watcher pour suivre les changements de la prop 'value'
80
- watch(
81
- () => props.modelValue,
82
- newValue => {
83
- if (props.valeurInverse) {
84
- maValeur.value = !newValue
85
- } else {
86
- maValeur.value = newValue
87
- }
88
- },
89
- )
90
-
91
- watch(
92
- () => props.valeurInverse,
93
- newValue => {
94
- if (props.valeurInverse) {
95
- maValeur.value = newValue
96
- } else {
97
- maValeur.value = !newValue
98
- }
99
- },
100
- )
73
+ const afficherDetails = computed(() => {
74
+ const slotExiste = !!slots.details?.().length
75
+ return slotExiste || props.texteDetaille.trim().length > 0
76
+ })
101
77
 
102
- // Méthode pour sauvegarder la valeur
103
- const sauvegarder = () => {
104
- if (props.valeurInverse) {
105
- emit('update:modelValue', !maValeur.value)
106
- } else {
107
- emit('update:modelValue', maValeur.value)
108
- }
109
- }
78
+ const switchId = `sw_${Math.random().toString(36).slice(2)}`
110
79
  </script>
111
80
 
112
- <style lang="css" scoped>
81
+ <style scoped>
113
82
  .labelSwitchSiSwitchApres {
114
83
  font-weight: bold;
115
- margin-top: 25px;
84
+ line-height: 1.2;
85
+ }
86
+
87
+ .label-cliquable {
88
+ cursor: pointer;
89
+ }
90
+
91
+ .details {
92
+ margin-top: 4px;
93
+ }
94
+
95
+ /* compact switch */
96
+ :deep(.switch-compact.v-input) {
97
+ margin: 0;
116
98
  }
117
- .v-switch {
118
- margin-bottom: -10px; /* aligner le switch avec son texte*/
99
+ :deep(.switch-compact .v-selection-control) {
100
+ margin: 0;
119
101
  }
120
102
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codevdesign",
3
- "version": "1.0.41",
3
+ "version": "1.0.42",
4
4
  "description": "Composants Vuetify 3 pour les projets Codev",
5
5
  "files": [
6
6
  "./**/*.vue",