1- <script setup>
2- import { ref } from ' vue'
1+ <script setup lang="ts" >
2+ import { ref , reactive , onMounted , watchEffect } from ' vue'
33import DsfrModal from ' @/components/DsfrModal/DsfrModal.vue'
4+ import type { Preferences , UseSchemeResult } from ' @/composables/index'
5+ import { useScheme } from ' @/composables/index'
6+ import lightThemeSvg from ' @gouvfr/dsfr/dist/artwork/pictograms/environment/sun.svg'
7+ import darkThemeSvg from ' @gouvfr/dsfr/dist/artwork/pictograms/environment/moon.svg'
8+ import systemThemeSvg from ' @gouvfr/dsfr/dist/artwork/pictograms/system/system.svg'
49
510const isModalOpen = ref (false )
11+ const isThemeModalOpen = ref (false )
612const displayAlert = ref (false )
713const close = () => {
814 displayAlert .value = false
@@ -29,6 +35,41 @@ const actions = [
2935 onClick : () => { isModalOpen .value = false },
3036 },
3137]
38+
39+ const preferences: Preferences = reactive ({
40+ theme: ' light' ,
41+ scheme: ' light' ,
42+ })
43+
44+ onMounted (() => {
45+ const { theme, scheme, setScheme } = useScheme () as UseSchemeResult
46+ preferences .scheme = scheme .value
47+
48+ watchEffect (() => {
49+ preferences .theme = theme .value
50+ })
51+
52+ watchEffect (() => setScheme (preferences .scheme ))
53+ })
54+
55+ const options = [
56+ {
57+ label: ' Thème clair' ,
58+ value: ' light' ,
59+ svgPath: lightThemeSvg ,
60+ },
61+ {
62+ label: ' Thème sombre' ,
63+ value: ' dark' ,
64+ svgPath: darkThemeSvg ,
65+ },
66+ {
67+ label: ' Thème système' ,
68+ value: ' system' ,
69+ hint: ' Utilise les paramètres système' ,
70+ svgPath: systemThemeSvg ,
71+ },
72+ ]
3273 </script >
3374
3475<template >
@@ -37,10 +78,45 @@ const actions = [
3778 class =" my-1"
3879 @click =" isModalOpen = true"
3980 >
40- Open modal
81+ Ouvrir modal
4182 </DsfrButton >
4283 </div >
4384
85+ <DsfrButton
86+ ref =" modalOrigin"
87+ label =" Changer le thème"
88+ @click =" isThemeModalOpen = true"
89+ />
90+ <DsfrModal
91+ :opened =" isThemeModalOpen"
92+ title =" Changer le thème"
93+ :origin =" $refs.modalOrigin"
94+ @close =" isThemeModalOpen = false"
95+ >
96+ <DsfrRadioButtonSet
97+ v-model =" preferences.scheme"
98+ :options =" options"
99+ name =" theme-selector"
100+ legend =" Choisissez un thème pour personnaliser l’apparence du site."
101+ />
102+ </DsfrModal >
103+
104+ <DsfrModal
105+ v-if =" isThemeModalOpen"
106+ title =" Exemple de modale"
107+ :opened =" isModalOpen"
108+ :actions =" actions"
109+ @close =" isModalOpen = false"
110+ >
111+ <DsfrAlert
112+ :closed =" !displayAlert"
113+ type =" success"
114+ small
115+ description =" Opération terminée avec succès"
116+ />
117+ Ceci est une modale. Elle peut se fermer sans aucun changement au clic sur le bouton "Fermer" ou bien simplement avec la touche <kbd >Échap</kbd >
118+ </DsfrModal >
119+
44120 <DsfrModal
45121 title =" Exemple de modale"
46122 :opened =" isModalOpen"
0 commit comments