summaryrefslogtreecommitdiff
path: root/src/components/ui/Form.astro
blob: 276b39fd68f5ee6b6fb6e2732069ed2ebde767f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
import type { Form as Props } from '~/types';
import Button from '~/components/ui/Button.astro';

const { inputs, textarea, disclaimer, button = 'Contact us', description = '' } = Astro.props;
---

<form>
  {
    inputs &&
      inputs.map(
        ({ type = 'text', name, label = '', autocomplete = 'on', placeholder = '' }) =>
          name && (
            <div class="mb-6">
              {label && (
                <label for={name} class="block text-sm font-medium">
                  {label}
                </label>
              )}
              <input
                type={type}
                name={name}
                id={name}
                autocomplete={autocomplete}
                placeholder={placeholder}
                class="py-3 px-4 block w-full text-md rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-slate-900"
              />
            </div>
          )
      )
  }

  {
    textarea && (
      <div>
        <label for="textarea" class="block text-sm font-medium">
          {textarea.label}
        </label>
        <textarea
          id="textarea"
          name={textarea.name ? textarea.name : 'message'}
          rows={textarea.rows ? textarea.rows : 4}
          placeholder={textarea.placeholder}
          class="py-3 px-4 block w-full text-md rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-slate-900"
        />
      </div>
    )
  }

  {
    disclaimer && (
      <div class="mt-3 flex items-start">
        <div class="flex mt-0.5">
          <input
            id="disclaimer"
            name="disclaimer"
            type="checkbox"
            class="cursor-pointer mt-1 py-3 px-4 block w-full text-md rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-slate-900"
          />
        </div>
        <div class="ml-3">
          <label for="disclaimer" class="cursor-pointer select-none text-sm text-gray-600 dark:text-gray-400">
            {disclaimer.label}
          </label>
        </div>
      </div>
    )
  }

  {
    button && (
      <div class="mt-10 grid">
        <Button variant="primary" type="submit">
          {button}
        </Button>
      </div>
    )
  }

  {
    description && (
      <div class="mt-3 text-center">
        <p class="text-sm text-gray-600 dark:text-gray-400">{description}</p>
      </div>
    )
  }
</form>