1 GitHub star = 1 new component.

App & Dashboard appdashboardsaasreal-estatevaluationwizardmulti-stepformlead

Estate Valuation Wizard

Three-step home valuation: address and type, size, rooms, condition and extras, then a price range from the zone’s €/m² and a lead form for an agent to confirm it.

Live Preview

Valora tu vivienda en 2 minutos

  1. La vivienda
  2. Detalles
  3. Tu valoración
1. La vivienda

Usage

Copy and paste this code into your Astro page:

astro
---
import { EstateValuationWizard } from 'astro-component-kit/app';
---

<EstateValuationWizard zones={estateZones} action="/api/valuation" />
--- import { EstateValuationWizard } from 'astro-component-kit/app'; --- <EstateValuationWizard zones={estateZones} action="/api/valuation" />

Examples in context

Real code from the kit: how this piece is used inside templates, sections and other components.

Template Nido · Real Estate Agency & CRM EstateValuationPage.astro
astro
<EstateValuationWizard zones={data.zones} action={action} />
<EstateValuationWizard zones={data.zones} action={action} />

Works well with

Manual Installation

If you are not using the npm package, create a new file and paste the following code: src/components/lib/EstateValuationWizard.astro:

astro
---
/**
 * EstateValuationWizard — Three-step home valuation for owners who want to sell.
 * 1) Address, zone and type · 2) Size, rooms, condition and extras · 3) Estimated price range
 * from the zone's average €/m², plus a contact form so an agent can confirm it.
 * Runs entirely in the browser; wire `action` to your backend to receive the lead.
 *
 * @param {EstateZone[]} zones - Zones with average €/m² used for the estimate.
 * @param {string} action - Form action for the final step. Default '' (handled on the page).
 * @param {string} method - Form method. Default 'post'.
 * @param {string} title - Heading.
 * @param {string} variant - 'card' | 'plain'. Default 'card'.
 * @param {string} class - Extra class for the root.
 *
 * Accessibility: real <form> with one <fieldset> per step; the step list marks
 * aria-current="step"; "Next" validates only the visible step (native messages);
 * focus moves to each step's heading; the result and confirmation are announced.
 */
import type { HTMLAttributes } from 'astro/types';
import '../templates/real-estate/real-estate-theme.css';
import { estateZones, estateTypeLabels, type EstateZone } from '../templates/real-estate/data';

interface OwnProps {
  zones?: EstateZone[];
  action?: string;
  method?: 'post' | 'get';
  title?: string;
  variant?: 'card' | 'plain';
}

type Props = OwnProps & Omit<HTMLAttributes<'section'>, keyof OwnProps | 'class'> & { class?: string };

const {
  zones = estateZones,
  action = '',
  method = 'post',
  title = 'Valora tu vivienda en 2 minutos',
  variant = 'card',
  class: classAttr,
  ...rest
} = Astro.props;

const uid = `evw-${Math.random().toString(36).slice(2, 8)}`;
const steps = ['La vivienda', 'Detalles', 'Tu valoración'];
const zonePrices = Object.fromEntries(zones.map((z) => [z.name, z.avgPriceM2]));
const extras = [
  { value: 'elevator', label: 'Ascensor' },
  { value: 'terrace', label: 'Terraza o balcón' },
  { value: 'parking', label: 'Garaje' },
  { value: 'pool', label: 'Piscina' },
];
---

<section
  class:list={['estate-ui', 'estate-wizard', `estate-wizard--${variant}`, classAttr]}
  aria-labelledby={`${uid}-title`}
  data-estate-wizard
  data-zone-prices={JSON.stringify(zonePrices)}
  {...rest}
>
  <h2 id={`${uid}-title`} class="estate-wizard__title">{title}</h2>

  <ol class="estate-wizard__steps" data-steps>
    {steps.map((s, i) => (
      <li class="estate-wizard__step" aria-current={i === 0 ? 'step' : undefined}>
        <span class="estate-wizard__step-num" aria-hidden="true">{i + 1}</span>
        <span>{s}</span>
      </li>
    ))}
  </ol>

  <form class="estate-wizard__form" action={action || undefined} method={method} novalidate data-form>
    <fieldset class="estate-wizard__panel" data-panel="0">
      <legend class="estate-wizard__legend" tabindex="-1">1. La vivienda</legend>
      <div class="estate-wizard__field estate-wizard__field--full">
        <label for={`${uid}-address`}>Dirección</label>
        <input id={`${uid}-address`} name="address" type="text" autocomplete="street-address" required placeholder="Calle y número" />
      </div>
      <div class="estate-wizard__field">
        <label for={`${uid}-zone`}>Barrio</label>
        <select id={`${uid}-zone`} name="zone" required>
          <option value="">Elige un barrio</option>
          {zones.map((z) => <option value={z.name}>{z.name}</option>)}
        </select>
      </div>
      <div class="estate-wizard__field">
        <label for={`${uid}-type`}>Tipo de vivienda</label>
        <select id={`${uid}-type`} name="type" required>
          {Object.entries(estateTypeLabels).map(([value, label]) => <option value={value}>{label}</option>)}
        </select>
      </div>
    </fieldset>

    <fieldset class="estate-wizard__panel" data-panel="1" hidden>
      <legend class="estate-wizard__legend" tabindex="-1">2. Detalles</legend>
      <div class="estate-wizard__field">
        <label for={`${uid}-m2`}>Superficie construida (m²)</label>
        <input id={`${uid}-m2`} name="m2" type="number" inputmode="numeric" min="15" max="2000" required placeholder="Ej. 95" />
      </div>
      <div class="estate-wizard__field">
        <label for={`${uid}-beds`}>Habitaciones</label>
        <select id={`${uid}-beds`} name="beds">
          {[1, 2, 3, 4, 5].map((n) => <option value={n} selected={n === 3}>{n === 5 ? '5 o más' : n}</option>)}
        </select>
      </div>
      <fieldset class="estate-wizard__group estate-wizard__field--full">
        <legend>Estado</legend>
        <div class="estate-wizard__choices">
          {[
            { value: '0.88', label: 'A reformar' },
            { value: '1', label: 'Buen estado', checked: true },
            { value: '1.12', label: 'Reformado' },
          ].map((c) => (
            <label class="estate-wizard__choice">
              <input type="radio" name="condition" value={c.value} checked={c.checked} />
              <span>{c.label}</span>
            </label>
          ))}
        </div>
      </fieldset>
      <fieldset class="estate-wizard__group estate-wizard__field--full">
        <legend>Extras</legend>
        <div class="estate-wizard__choices">
          {extras.map((x) => (
            <label class="estate-wizard__choice">
              <input type="checkbox" name="extras" value={x.value} />
              <span>{x.label}</span>
            </label>
          ))}
        </div>
      </fieldset>
    </fieldset>

    <fieldset class="estate-wizard__panel" data-panel="2" hidden>
      <legend class="estate-wizard__legend" tabindex="-1">3. Tu valoración</legend>
      <div class="estate-wizard__estimate estate-wizard__field--full" aria-live="polite">
        <span class="estate-wizard__estimate-label">Precio de venta estimado</span>
        <output class="estate-wizard__estimate-range" data-range>—</output>
        <span class="estate-wizard__estimate-hint" data-hint></span>
      </div>
      <p class="estate-wizard__field--full estate-wizard__lead">Déjanos tus datos y un agente del barrio revisará la valoración con datos de ventas reales.</p>
      <div class="estate-wizard__field">
        <label for={`${uid}-name`}>Nombre</label>
        <input id={`${uid}-name`} name="name" type="text" autocomplete="name" required />
      </div>
      <div class="estate-wizard__field">
        <label for={`${uid}-phone`}>Teléfono</label>
        <input id={`${uid}-phone`} name="phone" type="tel" autocomplete="tel" required />
      </div>
      <div class="estate-wizard__field estate-wizard__field--full">
        <label for={`${uid}-email`}>Email</label>
        <input id={`${uid}-email`} name="email" type="email" autocomplete="email" required />
      </div>
      <label class="estate-wizard__consent estate-wizard__field--full">
        <input type="checkbox" name="consent" required />
        <span>Acepto que Nido me contacte sobre esta valoración.</span>
      </label>
    </fieldset>

    <div class="estate-wizard__done" data-done hidden tabindex="-1" role="status">
      <svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="12" cy="12" r="10" /><path d="m8 12 3 3 5-6" /></svg>
      <p><strong>¡Recibido!</strong> Te llamaremos en menos de 24 horas laborables.</p>
    </div>

    <div class="estate-wizard__actions" data-actions>
      <button type="button" class="estate-wizard__btn estate-wizard__btn--ghost" data-back hidden>Atrás</button>
      <button type="button" class="estate-wizard__btn" data-next>Siguiente</button>
      <button type="submit" class="estate-wizard__btn" data-submit hidden>Solicitar valoración</button>
    </div>
  </form>
</section>

<script>
  function initWizard(root: HTMLElement) {
    if (root.dataset.bound) return;
    root.dataset.bound = 'true';
    const form = root.querySelector<HTMLFormElement>('[data-form]')!;
    const panels = Array.from(root.querySelectorAll<HTMLFieldSetElement>('[data-panel]'));
    const stepItems = Array.from(root.querySelectorAll<HTMLElement>('[data-steps] li'));
    const back = root.querySelector<HTMLButtonElement>('[data-back]')!;
    const next = root.querySelector<HTMLButtonElement>('[data-next]')!;
    const submit = root.querySelector<HTMLButtonElement>('[data-submit]')!;
    const zonePrices: Record<string, number> = JSON.parse(root.dataset.zonePrices || '{}');
    const eur = (n: number) =>
      new Intl.NumberFormat('es-ES', { style: 'currency', currency: 'EUR', maximumFractionDigits: 0 }).format(Math.round(n / 1000) * 1000);
    let step = 0;

    const estimate = () => {
      const data = new FormData(form);
      const m2 = Number(data.get('m2')) || 0;
      const base = zonePrices[String(data.get('zone'))] || 3000;
      const condition = Number(data.get('condition')) || 1;
      const extrasCount = data.getAll('extras').length;
      const type = String(data.get('type'));
      const typeFactor = type === 'penthouse' ? 1.12 : type === 'villa' ? 1.08 : type === 'studio' ? 1.05 : 1;
      const mid = m2 * base * condition * typeFactor * (1 + extrasCount * 0.03);
      const rangeEl = root.querySelector<HTMLElement>('[data-range]')!;
      const hintEl = root.querySelector<HTMLElement>('[data-hint]')!;
      rangeEl.textContent = `${eur(mid * 0.94)} – ${eur(mid * 1.06)}`;
      hintEl.textContent = `Basado en ${new Intl.NumberFormat('es-ES').format(base)} €/m² de media en ${data.get('zone')}.`;
    };

    const show = (i: number) => {
      step = i;
      panels.forEach((p, idx) => (p.hidden = idx !== i));
      stepItems.forEach((li, idx) => {
        if (idx === i) li.setAttribute('aria-current', 'step');
        else li.removeAttribute('aria-current');
        li.classList.toggle('is-done', idx < i);
      });
      back.hidden = i === 0;
      next.hidden = i === panels.length - 1;
      submit.hidden = i !== panels.length - 1;
      if (i === panels.length - 1) estimate();
      panels[i].querySelector<HTMLElement>('legend')?.focus();
    };

    const valid = (panel: HTMLElement) => {
      const fields = Array.from(panel.querySelectorAll<HTMLInputElement | HTMLSelectElement>('input, select'));
      const firstInvalid = fields.find((f) => !f.checkValidity());
      if (firstInvalid) {
        firstInvalid.reportValidity();
        return false;
      }
      return true;
    };

    next.addEventListener('click', () => {
      if (valid(panels[step])) show(step + 1);
    });
    back.addEventListener('click', () => show(step - 1));

    form.addEventListener('submit', (e) => {
      if (!valid(panels[step])) {
        e.preventDefault();
        return;
      }
      if (form.getAttribute('action')) return; // let the browser post to the backend
      e.preventDefault();
      panels.forEach((p) => (p.hidden = true));
      root.querySelector<HTMLElement>('[data-actions]')!.hidden = true;
      stepItems.forEach((li) => {
        li.removeAttribute('aria-current');
        li.classList.add('is-done');
      });
      const done = root.querySelector<HTMLElement>('[data-done]')!;
      done.hidden = false;
      done.focus();
    });
  }

  function initAll() {
    document.querySelectorAll<HTMLElement>('[data-estate-wizard]').forEach(initWizard);
  }

  initAll();
  document.addEventListener('astro:page-load', initAll);
</script>

<style>
  .estate-wizard {
    display: flex;
    flex-direction: column;
    gap: var(--sp-5, 1.25rem);
    color: var(--estate-text);
    font-family: var(--estate-font-body);
  }

  .estate-wizard--card {
    padding: var(--sp-6, 1.5rem);
    border-radius: var(--r-xl, 28px);
    border: 1px solid var(--estate-border);
    background: var(--estate-bg-raised);
  }

  .estate-wizard__title {
    margin: 0;
    font-family: var(--estate-font-display);
    font-weight: 500;
    font-size: clamp(1.6rem, 3vw, 2.1rem);
  }

  .estate-wizard__steps {
    display: flex;
    gap: var(--sp-2, 0.5rem);
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: none;
  }

  .estate-wizard__step {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--sp-2, 0.5rem);
    padding-top: var(--sp-2, 0.5rem);
    border-top: 3px solid var(--estate-border-strong);
    color: var(--estate-text-3);
    font-size: 0.85rem;
    font-weight: 600;
  }

  .estate-wizard__step[aria-current='step'] {
    border-color: var(--estate-brand);
    color: var(--estate-text);
  }

  .estate-wizard__step.is-done {
    border-color: var(--estate-sage);
    color: var(--estate-text-2);
  }

  .estate-wizard__step-num {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--estate-surface-2);
    font-size: 0.75rem;
  }

  .estate-wizard__step[aria-current='step'] .estate-wizard__step-num {
    background: var(--estate-brand);
    color: var(--estate-on-brand);
  }

  .estate-wizard__panel {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--sp-4, 1rem);
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
  }

  .estate-wizard__panel[hidden] {
    display: none;
  }

  .estate-wizard__legend {
    grid-column: 1 / -1;
    padding: 0;
    margin-bottom: var(--sp-1, 0.25rem);
    font-size: 1.1rem;
    font-weight: 600;
  }

  .estate-wizard__legend:focus {
    outline: none;
  }

  .estate-wizard__field {
    display: flex;
    flex-direction: column;
    gap: var(--sp-1, 0.25rem);
    min-width: 0;
  }

  .estate-wizard__field label,
  .estate-wizard__group legend {
    color: var(--estate-text-2);
    font-size: 0.9rem;
    font-weight: 500;
  }

  .estate-wizard__field :is(input, select) {
    min-height: 48px;
    width: 100%;
    box-sizing: border-box;
    padding: 0 var(--sp-3, 0.75rem);
    border-radius: var(--r-md, 12px);
    border: 1px solid var(--estate-border-strong);
    background: var(--estate-surface);
    color: var(--estate-text);
    font: inherit;
    font-size: 1rem;
  }

  .estate-wizard__field :is(input, select):focus-visible,
  .estate-wizard__choice input:focus-visible + span,
  .estate-wizard__consent input:focus-visible,
  .estate-wizard__btn:focus-visible {
    outline: 2px solid var(--estate-brand);
    outline-offset: 2px;
  }

  .estate-wizard__field :is(input, select):user-invalid {
    border-color: var(--estate-down);
  }

  .estate-wizard__group {
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
  }

  .estate-wizard__group legend {
    padding: 0;
    margin-bottom: var(--sp-2, 0.5rem);
  }

  .estate-wizard__choices {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2, 0.5rem);
  }

  .estate-wizard__choice {
    position: relative;
  }

  .estate-wizard__choice input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
  }

  .estate-wizard__choice span {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 var(--sp-4, 1rem);
    border-radius: var(--r-full, 999px);
    border: 1px solid var(--estate-border-strong);
    color: var(--estate-text-2);
    font-weight: 500;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  }

  .estate-wizard__choice input:checked + span {
    border-color: var(--estate-brand);
    background: rgba(var(--estate-brand-rgb), 0.14);
    color: var(--estate-text);
  }

  .estate-wizard__estimate {
    display: flex;
    flex-direction: column;
    gap: var(--sp-1, 0.25rem);
    padding: var(--sp-5, 1.25rem);
    border-radius: var(--r-lg, 20px);
    background: var(--estate-surface);
  }

  .estate-wizard__estimate-label {
    color: var(--estate-text-3);
    font-size: 0.85rem;
  }

  .estate-wizard__estimate-range {
    font-family: var(--estate-font-display);
    font-size: clamp(1.6rem, 4vw, 2.3rem);
    font-weight: 600;
    color: var(--estate-brand);
  }

  .estate-wizard__estimate-hint {
    color: var(--estate-text-3);
    font-size: 0.85rem;
  }

  .estate-wizard__lead {
    margin: 0;
    color: var(--estate-text-2);
  }

  .estate-wizard__consent {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-2, 0.5rem);
    color: var(--estate-text-2);
    font-size: 0.9rem;
  }

  .estate-wizard__consent input {
    width: 20px;
    height: 20px;
    margin: 0.1rem 0 0;
    accent-color: var(--estate-brand);
  }

  .estate-wizard__actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-2, 0.5rem);
  }

  .estate-wizard__actions[hidden],
  .estate-wizard__btn[hidden] {
    display: none;
  }

  .estate-wizard__btn {
    min-height: 48px;
    padding: 0 var(--sp-6, 1.5rem);
    border: 0;
    border-radius: var(--r-full, 999px);
    background: var(--estate-brand);
    color: var(--estate-on-brand);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease;
  }

  .estate-wizard__btn:hover {
    background: var(--estate-brand-hover);
  }

  .estate-wizard__btn--ghost {
    background: transparent;
    color: var(--estate-text);
    border: 1px solid var(--estate-border-strong);
  }

  .estate-wizard__btn--ghost:hover {
    background: var(--estate-surface);
  }

  .estate-wizard__done {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-3, 0.75rem);
    padding: var(--sp-8, 2rem) var(--sp-4, 1rem);
    text-align: center;
    color: var(--estate-sage);
  }

  .estate-wizard__done[hidden] {
    display: none;
  }

  .estate-wizard__done:focus {
    outline: none;
  }

  .estate-wizard__done p {
    margin: 0;
    color: var(--estate-text);
  }

  @media (min-width: 640px) {
    .estate-wizard__panel {
      grid-template-columns: 1fr 1fr;
    }

    .estate-wizard__field--full {
      grid-column: 1 / -1;
    }
  }

  @media (max-width: 480px) {
    .estate-wizard__step span:not(.estate-wizard__step-num) {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
    }
  }
</style>
--- /** * EstateValuationWizard — Three-step home valuation for owners who want to sell. * 1) Address, zone and type · 2) Size, rooms, condition and extras · 3) Estimated price range * from the zone's average €/m², plus a contact form so an agent can confirm it. * Runs entirely in the browser; wire `action` to your backend to receive the lead. * * @param {EstateZone[]} zones - Zones with average €/m² used for the estimate. * @param {string} action - Form action for the final step. Default '' (handled on the page). * @param {string} method - Form method. Default 'post'. * @param {string} title - Heading. * @param {string} variant - 'card' | 'plain'. Default 'card'. * @param {string} class - Extra class for the root. * * Accessibility: real <form> with one <fieldset> per step; the step list marks * aria-current="step"; "Next" validates only the visible step (native messages); * focus moves to each step's heading; the result and confirmation are announced. */ import type { HTMLAttributes } from 'astro/types'; import '../templates/real-estate/real-estate-theme.css'; import { estateZones, estateTypeLabels, type EstateZone } from '../templates/real-estate/data'; interface OwnProps { zones?: EstateZone[]; action?: string; method?: 'post' | 'get'; title?: string; variant?: 'card' | 'plain'; } type Props = OwnProps & Omit<HTMLAttributes<'section'>, keyof OwnProps | 'class'> & { class?: string }; const { zones = estateZones, action = '', method = 'post', title = 'Valora tu vivienda en 2 minutos', variant = 'card', class: classAttr, ...rest } = Astro.props; const uid = `evw-${Math.random().toString(36).slice(2, 8)}`; const steps = ['La vivienda', 'Detalles', 'Tu valoración']; const zonePrices = Object.fromEntries(zones.map((z) => [z.name, z.avgPriceM2])); const extras = [ { value: 'elevator', label: 'Ascensor' }, { value: 'terrace', label: 'Terraza o balcón' }, { value: 'parking', label: 'Garaje' }, { value: 'pool', label: 'Piscina' }, ]; --- <section class:list={['estate-ui', 'estate-wizard', `estate-wizard--${variant}`, classAttr]} aria-labelledby={`${uid}-title`} data-estate-wizard data-zone-prices={JSON.stringify(zonePrices)} {...rest} > <h2 id={`${uid}-title`} class="estate-wizard__title">{title}</h2> <ol class="estate-wizard__steps" data-steps> {steps.map((s, i) => ( <li class="estate-wizard__step" aria-current={i === 0 ? 'step' : undefined}> <span class="estate-wizard__step-num" aria-hidden="true">{i + 1}</span> <span>{s}</span> </li> ))} </ol> <form class="estate-wizard__form" action={action || undefined} method={method} novalidate data-form> <fieldset class="estate-wizard__panel" data-panel="0"> <legend class="estate-wizard__legend" tabindex="-1">1. La vivienda</legend> <div class="estate-wizard__field estate-wizard__field--full"> <label for={`${uid}-address`}>Dirección</label> <input id={`${uid}-address`} name="address" type="text" autocomplete="street-address" required placeholder="Calle y número" /> </div> <div class="estate-wizard__field"> <label for={`${uid}-zone`}>Barrio</label> <select id={`${uid}-zone`} name="zone" required> <option value="">Elige un barrio</option> {zones.map((z) => <option value={z.name}>{z.name}</option>)} </select> </div> <div class="estate-wizard__field"> <label for={`${uid}-type`}>Tipo de vivienda</label> <select id={`${uid}-type`} name="type" required> {Object.entries(estateTypeLabels).map(([value, label]) => <option value={value}>{label}</option>)} </select> </div> </fieldset> <fieldset class="estate-wizard__panel" data-panel="1" hidden> <legend class="estate-wizard__legend" tabindex="-1">2. Detalles</legend> <div class="estate-wizard__field"> <label for={`${uid}-m2`}>Superficie construida (m²)</label> <input id={`${uid}-m2`} name="m2" type="number" inputmode="numeric" min="15" max="2000" required placeholder="Ej. 95" /> </div> <div class="estate-wizard__field"> <label for={`${uid}-beds`}>Habitaciones</label> <select id={`${uid}-beds`} name="beds"> {[1, 2, 3, 4, 5].map((n) => <option value={n} selected={n === 3}>{n === 5 ? '5 o más' : n}</option>)} </select> </div> <fieldset class="estate-wizard__group estate-wizard__field--full"> <legend>Estado</legend> <div class="estate-wizard__choices"> {[ { value: '0.88', label: 'A reformar' }, { value: '1', label: 'Buen estado', checked: true }, { value: '1.12', label: 'Reformado' }, ].map((c) => ( <label class="estate-wizard__choice"> <input type="radio" name="condition" value={c.value} checked={c.checked} /> <span>{c.label}</span> </label> ))} </div> </fieldset> <fieldset class="estate-wizard__group estate-wizard__field--full"> <legend>Extras</legend> <div class="estate-wizard__choices"> {extras.map((x) => ( <label class="estate-wizard__choice"> <input type="checkbox" name="extras" value={x.value} /> <span>{x.label}</span> </label> ))} </div> </fieldset> </fieldset> <fieldset class="estate-wizard__panel" data-panel="2" hidden> <legend class="estate-wizard__legend" tabindex="-1">3. Tu valoración</legend> <div class="estate-wizard__estimate estate-wizard__field--full" aria-live="polite"> <span class="estate-wizard__estimate-label">Precio de venta estimado</span> <output class="estate-wizard__estimate-range" data-range>—</output> <span class="estate-wizard__estimate-hint" data-hint></span> </div> <p class="estate-wizard__field--full estate-wizard__lead">Déjanos tus datos y un agente del barrio revisará la valoración con datos de ventas reales.</p> <div class="estate-wizard__field"> <label for={`${uid}-name`}>Nombre</label> <input id={`${uid}-name`} name="name" type="text" autocomplete="name" required /> </div> <div class="estate-wizard__field"> <label for={`${uid}-phone`}>Teléfono</label> <input id={`${uid}-phone`} name="phone" type="tel" autocomplete="tel" required /> </div> <div class="estate-wizard__field estate-wizard__field--full"> <label for={`${uid}-email`}>Email</label> <input id={`${uid}-email`} name="email" type="email" autocomplete="email" required /> </div> <label class="estate-wizard__consent estate-wizard__field--full"> <input type="checkbox" name="consent" required /> <span>Acepto que Nido me contacte sobre esta valoración.</span> </label> </fieldset> <div class="estate-wizard__done" data-done hidden tabindex="-1" role="status"> <svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="12" cy="12" r="10" /><path d="m8 12 3 3 5-6" /></svg> <p><strong>¡Recibido!</strong> Te llamaremos en menos de 24 horas laborables.</p> </div> <div class="estate-wizard__actions" data-actions> <button type="button" class="estate-wizard__btn estate-wizard__btn--ghost" data-back hidden>Atrás</button> <button type="button" class="estate-wizard__btn" data-next>Siguiente</button> <button type="submit" class="estate-wizard__btn" data-submit hidden>Solicitar valoración</button> </div> </form> </section> <script> function initWizard(root: HTMLElement) { if (root.dataset.bound) return; root.dataset.bound = 'true'; const form = root.querySelector<HTMLFormElement>('[data-form]')!; const panels = Array.from(root.querySelectorAll<HTMLFieldSetElement>('[data-panel]')); const stepItems = Array.from(root.querySelectorAll<HTMLElement>('[data-steps] li')); const back = root.querySelector<HTMLButtonElement>('[data-back]')!; const next = root.querySelector<HTMLButtonElement>('[data-next]')!; const submit = root.querySelector<HTMLButtonElement>('[data-submit]')!; const zonePrices: Record<string, number> = JSON.parse(root.dataset.zonePrices || '{}'); const eur = (n: number) => new Intl.NumberFormat('es-ES', { style: 'currency', currency: 'EUR', maximumFractionDigits: 0 }).format(Math.round(n / 1000) * 1000); let step = 0; const estimate = () => { const data = new FormData(form); const m2 = Number(data.get('m2')) || 0; const base = zonePrices[String(data.get('zone'))] || 3000; const condition = Number(data.get('condition')) || 1; const extrasCount = data.getAll('extras').length; const type = String(data.get('type')); const typeFactor = type === 'penthouse' ? 1.12 : type === 'villa' ? 1.08 : type === 'studio' ? 1.05 : 1; const mid = m2 * base * condition * typeFactor * (1 + extrasCount * 0.03); const rangeEl = root.querySelector<HTMLElement>('[data-range]')!; const hintEl = root.querySelector<HTMLElement>('[data-hint]')!; rangeEl.textContent = `${eur(mid * 0.94)} – ${eur(mid * 1.06)}`; hintEl.textContent = `Basado en ${new Intl.NumberFormat('es-ES').format(base)} €/m² de media en ${data.get('zone')}.`; }; const show = (i: number) => { step = i; panels.forEach((p, idx) => (p.hidden = idx !== i)); stepItems.forEach((li, idx) => { if (idx === i) li.setAttribute('aria-current', 'step'); else li.removeAttribute('aria-current'); li.classList.toggle('is-done', idx < i); }); back.hidden = i === 0; next.hidden = i === panels.length - 1; submit.hidden = i !== panels.length - 1; if (i === panels.length - 1) estimate(); panels[i].querySelector<HTMLElement>('legend')?.focus(); }; const valid = (panel: HTMLElement) => { const fields = Array.from(panel.querySelectorAll<HTMLInputElement | HTMLSelectElement>('input, select')); const firstInvalid = fields.find((f) => !f.checkValidity()); if (firstInvalid) { firstInvalid.reportValidity(); return false; } return true; }; next.addEventListener('click', () => { if (valid(panels[step])) show(step + 1); }); back.addEventListener('click', () => show(step - 1)); form.addEventListener('submit', (e) => { if (!valid(panels[step])) { e.preventDefault(); return; } if (form.getAttribute('action')) return; // let the browser post to the backend e.preventDefault(); panels.forEach((p) => (p.hidden = true)); root.querySelector<HTMLElement>('[data-actions]')!.hidden = true; stepItems.forEach((li) => { li.removeAttribute('aria-current'); li.classList.add('is-done'); }); const done = root.querySelector<HTMLElement>('[data-done]')!; done.hidden = false; done.focus(); }); } function initAll() { document.querySelectorAll<HTMLElement>('[data-estate-wizard]').forEach(initWizard); } initAll(); document.addEventListener('astro:page-load', initAll); </script> <style> .estate-wizard { display: flex; flex-direction: column; gap: var(--sp-5, 1.25rem); color: var(--estate-text); font-family: var(--estate-font-body); } .estate-wizard--card { padding: var(--sp-6, 1.5rem); border-radius: var(--r-xl, 28px); border: 1px solid var(--estate-border); background: var(--estate-bg-raised); } .estate-wizard__title { margin: 0; font-family: var(--estate-font-display); font-weight: 500; font-size: clamp(1.6rem, 3vw, 2.1rem); } .estate-wizard__steps { display: flex; gap: var(--sp-2, 0.5rem); margin: 0; padding: 0; list-style: none; counter-reset: none; } .estate-wizard__step { flex: 1; display: flex; align-items: center; gap: var(--sp-2, 0.5rem); padding-top: var(--sp-2, 0.5rem); border-top: 3px solid var(--estate-border-strong); color: var(--estate-text-3); font-size: 0.85rem; font-weight: 600; } .estate-wizard__step[aria-current='step'] { border-color: var(--estate-brand); color: var(--estate-text); } .estate-wizard__step.is-done { border-color: var(--estate-sage); color: var(--estate-text-2); } .estate-wizard__step-num { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--estate-surface-2); font-size: 0.75rem; } .estate-wizard__step[aria-current='step'] .estate-wizard__step-num { background: var(--estate-brand); color: var(--estate-on-brand); } .estate-wizard__panel { display: grid; grid-template-columns: 1fr; gap: var(--sp-4, 1rem); margin: 0; padding: 0; border: 0; min-width: 0; } .estate-wizard__panel[hidden] { display: none; } .estate-wizard__legend { grid-column: 1 / -1; padding: 0; margin-bottom: var(--sp-1, 0.25rem); font-size: 1.1rem; font-weight: 600; } .estate-wizard__legend:focus { outline: none; } .estate-wizard__field { display: flex; flex-direction: column; gap: var(--sp-1, 0.25rem); min-width: 0; } .estate-wizard__field label, .estate-wizard__group legend { color: var(--estate-text-2); font-size: 0.9rem; font-weight: 500; } .estate-wizard__field :is(input, select) { min-height: 48px; width: 100%; box-sizing: border-box; padding: 0 var(--sp-3, 0.75rem); border-radius: var(--r-md, 12px); border: 1px solid var(--estate-border-strong); background: var(--estate-surface); color: var(--estate-text); font: inherit; font-size: 1rem; } .estate-wizard__field :is(input, select):focus-visible, .estate-wizard__choice input:focus-visible + span, .estate-wizard__consent input:focus-visible, .estate-wizard__btn:focus-visible { outline: 2px solid var(--estate-brand); outline-offset: 2px; } .estate-wizard__field :is(input, select):user-invalid { border-color: var(--estate-down); } .estate-wizard__group { margin: 0; padding: 0; border: 0; min-width: 0; } .estate-wizard__group legend { padding: 0; margin-bottom: var(--sp-2, 0.5rem); } .estate-wizard__choices { display: flex; flex-wrap: wrap; gap: var(--sp-2, 0.5rem); } .estate-wizard__choice { position: relative; } .estate-wizard__choice input { position: absolute; inset: 0; opacity: 0; cursor: pointer; } .estate-wizard__choice span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--sp-4, 1rem); border-radius: var(--r-full, 999px); border: 1px solid var(--estate-border-strong); color: var(--estate-text-2); font-weight: 500; transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease; } .estate-wizard__choice input:checked + span { border-color: var(--estate-brand); background: rgba(var(--estate-brand-rgb), 0.14); color: var(--estate-text); } .estate-wizard__estimate { display: flex; flex-direction: column; gap: var(--sp-1, 0.25rem); padding: var(--sp-5, 1.25rem); border-radius: var(--r-lg, 20px); background: var(--estate-surface); } .estate-wizard__estimate-label { color: var(--estate-text-3); font-size: 0.85rem; } .estate-wizard__estimate-range { font-family: var(--estate-font-display); font-size: clamp(1.6rem, 4vw, 2.3rem); font-weight: 600; color: var(--estate-brand); } .estate-wizard__estimate-hint { color: var(--estate-text-3); font-size: 0.85rem; } .estate-wizard__lead { margin: 0; color: var(--estate-text-2); } .estate-wizard__consent { display: flex; align-items: flex-start; gap: var(--sp-2, 0.5rem); color: var(--estate-text-2); font-size: 0.9rem; } .estate-wizard__consent input { width: 20px; height: 20px; margin: 0.1rem 0 0; accent-color: var(--estate-brand); } .estate-wizard__actions { display: flex; justify-content: flex-end; gap: var(--sp-2, 0.5rem); } .estate-wizard__actions[hidden], .estate-wizard__btn[hidden] { display: none; } .estate-wizard__btn { min-height: 48px; padding: 0 var(--sp-6, 1.5rem); border: 0; border-radius: var(--r-full, 999px); background: var(--estate-brand); color: var(--estate-on-brand); font: inherit; font-weight: 700; cursor: pointer; transition: background 0.2s ease; } .estate-wizard__btn:hover { background: var(--estate-brand-hover); } .estate-wizard__btn--ghost { background: transparent; color: var(--estate-text); border: 1px solid var(--estate-border-strong); } .estate-wizard__btn--ghost:hover { background: var(--estate-surface); } .estate-wizard__done { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3, 0.75rem); padding: var(--sp-8, 2rem) var(--sp-4, 1rem); text-align: center; color: var(--estate-sage); } .estate-wizard__done[hidden] { display: none; } .estate-wizard__done:focus { outline: none; } .estate-wizard__done p { margin: 0; color: var(--estate-text); } @media (min-width: 640px) { .estate-wizard__panel { grid-template-columns: 1fr 1fr; } .estate-wizard__field--full { grid-column: 1 / -1; } } @media (max-width: 480px) { .estate-wizard__step span:not(.estate-wizard__step-num) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } } </style>

Quick Info

Category
App & Dashboard
Filename
EstateValuationWizard.astro
Dependencies
None — pure Astro + CSS
Tags
appdashboardsaasreal-estatevaluationwizardmulti-stepformlead