diff --git a/src/components/ContactForm.vue b/src/components/ContactForm.vue index 18fb9b6..e019e38 100644 --- a/src/components/ContactForm.vue +++ b/src/components/ContactForm.vue @@ -8,6 +8,8 @@ const formVisible = ref(true); const turnstileKey = import.meta.env.PUBLIC_TURNSTILE_SITE_KEY || '{TURNSTILE_SITE_KEY}'; +const isDarkMode = ref(false); + const formData = ref({ name: '', email: '', @@ -18,7 +20,32 @@ const formData = ref({ turnstileToken: '' }); + +function renderTurnstile() { + const container = document.getElementById('turnstile-container'); + if (!container) return; + + // Clear any existing widget if present + container.innerHTML = ''; + + // Render Turnstile widget based on active site theme since auto mode doesn't seem to read the current theme handling properly. + if (window.turnstile) { + window.turnstile.render("#turnstile-container", { + sitekey: turnstileKey, + callback: (token: string) => { + formData.value.turnstileToken = token; + }, + "error-callback": () => { + responseMessage.value = "Turnstile validation failed. Please try again."; + }, + theme: isDarkMode.value ? "dark" : "light" + }); + } +} + onMounted(() => { + isDarkMode.value = document.body.classList.contains('darkmode'); + const script = document.createElement("script"); script.src = "https://challenges.cloudflare.com/turnstile/v0/api.js"; script.async = true; @@ -26,20 +53,14 @@ onMounted(() => { document.head.appendChild(script); script.onload = () => { - if (window.turnstile) { - window.turnstile.render("#turnstile-container", { - sitekey: turnstileKey, - callback: (token: string) => { - formData.value.turnstileToken = token; - }, - "error-callback": () => { - responseMessage.value = "Turnstile validation failed. Please try again."; - }, - }); - }; + renderTurnstile(); }; }); +watch(isDarkMode, () => { + renderTurnstile(); +}); + function formatPhoneNumber(value: string): string { const cleaned = value.replace(/\D/g, ''); const match = cleaned.match(/(\d{0,3})(\d{0,3})(\d{0,4})/); @@ -216,12 +237,13 @@ watch(formVisible, (newVal) => { aria-label="Message Input (Required)" class="py-3 px-4 block w-full text-md rounded-lg border border-[var(--highlight-blue-200)] dark:border-[var(--highlight-blue-400)] bg-[var(--neutral-100)] dark:bg-[var(--highlight-blue-700)]" /> +

{{ formData.message.length }} / {{ messageMaxLength }}

-
+

- By submitting this contact form, you acknowledge and agree to the collection of your personal information per our privacy policy. + By submitting this contact form, you acknowledge and agree to the collection of your information per our privacy policy.

diff --git a/src/components/Navigation.astro b/src/components/Navigation.astro index 50934f9..63d70ad 100644 --- a/src/components/Navigation.astro +++ b/src/components/Navigation.astro @@ -1,8 +1,8 @@ --- -import ResponsiveToggle from './ResponsiveToggle.astro' -import { DarkMode } from 'accessible-astro-components' -import { Image } from 'astro:assets' -import logo from '../assets/img/logo.svg' +import ResponsiveToggle from './ResponsiveToggle.astro'; +import { DarkMode } from 'accessible-astro-components'; +import { Image } from 'astro:assets'; +import logo from '../assets/img/logo.svg'; ---