diff --git a/src/components/Toggle/toggle.astro b/src/components/Toggle/toggle.astro index 391d8f3..a9a07ab 100644 --- a/src/components/Toggle/toggle.astro +++ b/src/components/Toggle/toggle.astro @@ -1,14 +1,16 @@ --- +import { boolean } from 'astro:schema'; + export interface Props { - checked?: boolean; + 'data-checked': boolean; name?: string; id: string; } -const { checked = false, name = 'toggle', id} = Astro.props; +const { 'data-checked': dataChecked = 'false', name = 'toggle', id } = Astro.props; --- - +
diff --git a/src/pages/index.astro b/src/pages/index.astro index 4960fc9..8d07e5c 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -10,7 +10,7 @@ import { } from '../components/Icons/index.ts'; import Notification from '../components/Notifications/notification.astro'; -const initialChecked = false; +const initialChecked = true; --- @@ -196,12 +196,22 @@ const initialChecked = false; const toggle = document.getElementById('my-toggle') as any; const stateLabel = document.getElementById('toggle-state'); - toggle?.addEventListener('change', (e: CustomEvent) => { - const { checked, name } = e.detail; + // Défaut: thème sombre + if (!document.documentElement.hasAttribute('data-theme')) { + document.documentElement.setAttribute('data-theme', 'dark'); + } + if (stateLabel) stateLabel.textContent = 'Thème : Sombre'; - if (stateLabel) { - stateLabel.textContent = `State: ${checked ? 'Checked' : 'Unchecked'}`; - } + toggle?.addEventListener('change', (e: CustomEvent) => { + const { checked } = e.detail; + + if (checked) { + document.documentElement.setAttribute('data-theme', 'dark'); + if (stateLabel) stateLabel.textContent = 'Thème : Sombre'; + } else { + document.documentElement.setAttribute('data-theme', 'light'); + if (stateLabel) stateLabel.textContent = 'Thème : Clair'; + } }); @@ -211,6 +221,7 @@ const initialChecked = false; background-color: var(--nds-background); color: var(--nds-text); } + main { max-width: 900px; margin: 0 auto;