215 lines
12 KiB
Plaintext
215 lines
12 KiB
Plaintext
component NewsletterForm {
|
|
props {
|
|
class: string = ""
|
|
eyebrow = ""
|
|
title = "Stay up to date"
|
|
description = ""
|
|
|
|
placeholder = "Enter your email"
|
|
buttonLabel = "Subscribe"
|
|
|
|
action = "/newsletter/subscribe"
|
|
method = "post"
|
|
emailName = "email"
|
|
|
|
privacyLabel = ""
|
|
privacyHref = "/privacy"
|
|
|
|
successMessage = "You are subscribed."
|
|
errorMessage = "Something went wrong. Please try again."
|
|
|
|
iconClass = "icon-[lucide--mail]"
|
|
|
|
centered = false
|
|
compact = false
|
|
showIcon = true
|
|
showPrivacy = true
|
|
fullWidth = false
|
|
}
|
|
|
|
state email = ""
|
|
state status = "idle"
|
|
state message = ""
|
|
|
|
view {
|
|
<section
|
|
aria-labelledby="newsletter-form-title"
|
|
class="w-full px-5 sm:px-8 lg:px-10 xl:px-12 {class}"
|
|
>
|
|
<div
|
|
class=" relative mx-auto w-full overflow-hidden rounded-3xl border border-indigo-200/80 bg-linear-to-br from-indigo-50 via-white to-violet-50 shadow-xl shadow-indigo-950/5 dark:border-indigo-500/20 dark:from-indigo-500/10 dark:via-slate-900 dark:to-violet-500/10 dark:shadow-black/20 "
|
|
class:max-w-7xl="fullWidth"
|
|
class:max-w-3xl="!fullWidth"
|
|
>
|
|
<!-- Background decoration -->
|
|
<div
|
|
aria-hidden="true"
|
|
class="pointer-events-none absolute inset-0 overflow-hidden"
|
|
>
|
|
<div class="absolute -right-20 -top-24 h-64 w-64 rounded-full bg-indigo-300/25 blur-3xl dark:bg-indigo-500/10"></div>
|
|
|
|
<div class="absolute -bottom-28 -left-20 h-64 w-64 rounded-full bg-violet-300/20 blur-3xl dark:bg-violet-500/10"></div>
|
|
|
|
<div class="absolute left-1/2 top-0 h-px w-2/3 -translate-x-1/2 bg-linear-to-r from-transparent via-indigo-400/60 to-transparent dark:via-indigo-400/20"></div>
|
|
</div>
|
|
|
|
<div
|
|
class="relative"
|
|
class:p-5="compact"
|
|
class:sm:p-6="compact"
|
|
class:p-7="!compact"
|
|
class:sm:p-9="!compact"
|
|
class:lg:p-10="!compact"
|
|
>
|
|
<div
|
|
class=" {compact ? 'flex flex-col gap-5 lg:flex-row lg:items-center lg:justify-between lg:gap-10' : centered ? 'mx-auto flex max-w-2xl flex-col items-center gap-7 text-center' : 'grid gap-8 lg:grid-cols-[minmax(0,1fr)_minmax(360px,480px)] lg:items-center lg:gap-12' } "
|
|
>
|
|
<!-- Content -->
|
|
<div
|
|
class=" min-w-0 {compact ? 'max-w-2xl' : ''} {centered && !compact ? 'w-full max-w-2xl' : ''} "
|
|
>
|
|
<div class=" flex gap-4 {centered && !compact ? 'flex-col items-center' : 'items-start' } " >
|
|
<!-- Icon -->
|
|
<div
|
|
class="relative shrink-0"
|
|
class:hidden="!showIcon"
|
|
>
|
|
<div aria-hidden="true" class="absolute inset-1 rounded-2xl bg-indigo-500/25 blur-xl" ></div>
|
|
|
|
<span
|
|
class=" relative grid place-items-center rounded-2xl border border-indigo-200 bg-white/90 text-indigo-600 shadow-lg shadow-indigo-950/10 backdrop-blur-sm dark:border-indigo-500/20 dark:bg-indigo-500/10 dark:text-indigo-300 dark:shadow-black/20 {compact ? 'h-11 w-11' : 'h-13 w-13'} "
|
|
>
|
|
<span class=" {iconClass} {compact ? 'h-5 w-5' : 'h-6 w-6'} " aria-hidden="true" ></span>
|
|
</span>
|
|
</div>
|
|
|
|
<div class="min-w-0">
|
|
<!-- Eyebrow -->
|
|
<p
|
|
class="text-xs font-bold uppercase tracking-[0.18em] text-indigo-600 dark:text-indigo-400"
|
|
class:hidden="eyebrow === ''"
|
|
>
|
|
{eyebrow}
|
|
</p>
|
|
|
|
<!-- Title -->
|
|
<h2
|
|
id="newsletter-form-title"
|
|
class=" font-bold leading-tight tracking-tight text-slate-950 dark:text-white {eyebrow !== '' ? 'mt-2' : ''} {compact ? 'text-xl sm:text-2xl' : 'text-2xl sm:text-3xl' } "
|
|
>
|
|
{title}
|
|
</h2>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Description -->
|
|
<p
|
|
class=" mt-4 text-sm leading-6 text-slate-600 dark:text-slate-400 {!compact ? 'sm:text-base sm:leading-7' : ''} {centered && !compact ? 'mx-auto max-w-xl' : 'max-w-2xl' } "
|
|
class:hidden="description === ''"
|
|
>
|
|
{description}
|
|
</p>
|
|
</div>
|
|
|
|
<!-- Form -->
|
|
<div class=" w-full {compact ? 'lg:max-w-xl' : ''} {centered && !compact ? 'max-w-2xl' : ''} " >
|
|
<form
|
|
action="{action}"
|
|
method="{method}"
|
|
class="w-full"
|
|
@submit=" status = 'loading'; message = ''; "
|
|
>
|
|
<label
|
|
for="newsletter-email"
|
|
class="sr-only"
|
|
>
|
|
Email address
|
|
</label>
|
|
|
|
<div
|
|
class=" flex w-full flex-col gap-2 rounded-2xl border border-slate-200 bg-white/85 p-2 shadow-sm backdrop-blur-sm dark:border-white/10 dark:bg-white/5 sm:flex-row "
|
|
>
|
|
<div class="relative min-w-0 flex-1">
|
|
<span class="pointer-events-none absolute left-3.5 top-1/2 h-4.5 w-4.5 -translate-y-1/2 text-slate-400 icon-[lucide--mail] dark:text-slate-500" aria-hidden="true" ></span>
|
|
|
|
<input
|
|
id="newsletter-email"
|
|
type="email"
|
|
name="{emailName}"
|
|
value="{email}"
|
|
placeholder="{placeholder}"
|
|
autocomplete="email"
|
|
required
|
|
@input="email = event.target.value"
|
|
class=" w-full rounded-xl bg-transparent pl-10 pr-3 text-sm text-slate-950 outline-none placeholder:text-slate-400 focus:bg-white dark:text-white dark:placeholder:text-slate-500 dark:focus:bg-white/5 {compact ? 'h-10' : 'h-11'} "
|
|
/>
|
|
</div>
|
|
|
|
<button
|
|
type="submit"
|
|
class=" group inline-flex shrink-0 items-center justify-center gap-2 rounded-xl bg-indigo-600 px-5 text-sm font-bold text-white shadow-lg shadow-indigo-600/20 transition hover:-translate-y-0.5 hover:bg-indigo-500 hover:shadow-xl focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 focus-visible:ring-offset-2 disabled:cursor-wait disabled:opacity-70 dark:focus-visible:ring-offset-slate-900 {compact ? 'h-10' : 'h-11'} "
|
|
disabled="{status === 'loading'}"
|
|
>
|
|
<span class="icon-[lucide--loader-circle] h-4 w-4 animate-spin" aria-hidden="true" class:hidden="status !== 'loading'" ></span>
|
|
|
|
<span class:hidden="status === 'loading'">
|
|
{buttonLabel}
|
|
</span>
|
|
|
|
<span class:hidden="status !== 'loading'">
|
|
Subscribing
|
|
</span>
|
|
|
|
<span class="icon-[lucide--arrow-right] h-4 w-4 transition-transform group-hover:translate-x-1" aria-hidden="true" class:hidden="status === 'loading'" ></span>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
<p
|
|
class="mt-3 text-xs leading-5 text-slate-500 dark:text-slate-400"
|
|
class:hidden="!showPrivacy"
|
|
class:text-center="centered && !compact"
|
|
>
|
|
No spam. Unsubscribe at any time.
|
|
|
|
<a
|
|
href="{privacyHref}"
|
|
class="font-semibold text-indigo-600 transition hover:text-indigo-500 dark:text-indigo-400 dark:hover:text-indigo-300"
|
|
class:hidden="privacyLabel === ''"
|
|
>
|
|
{privacyLabel}
|
|
</a>
|
|
</p>
|
|
|
|
<div
|
|
role="status"
|
|
aria-live="polite"
|
|
class="mt-3 rounded-xl px-3 py-2.5 text-sm font-medium"
|
|
class:hidden="message === ''"
|
|
class:bg-emerald-50="status === 'success'"
|
|
class:text-emerald-700="status === 'success'"
|
|
class:ring-1="status === 'success'"
|
|
class:ring-inset="status === 'success'"
|
|
class:ring-emerald-200="status === 'success'"
|
|
class:dark:bg-emerald-500/10="status === 'success'"
|
|
class:dark:text-emerald-300="status === 'success'"
|
|
class:dark:ring-emerald-500/20="status === 'success'"
|
|
class:bg-rose-50="status === 'error'"
|
|
class:text-rose-700="status === 'error'"
|
|
class:ring-1="status === 'error'"
|
|
class:ring-inset="status === 'error'"
|
|
class:ring-rose-200="status === 'error'"
|
|
class:dark:bg-rose-500/10="status === 'error'"
|
|
class:dark:text-rose-300="status === 'error'"
|
|
class:dark:ring-rose-500/20="status === 'error'"
|
|
>
|
|
{message}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
}
|
|
}
|