@garagem-ai/site-sdk 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ "use client";
2
+
3
+ import type { FormEvent, ReactElement, ReactNode } from "react";
4
+
5
+ import { SearchClearIcon, SearchLensIcon } from "./icons";
6
+
7
+ export type SearchQueryFormProps = {
8
+ value: string;
9
+ onChange: (value: string) => void;
10
+ onSubmit: () => void;
11
+ onClear: () => void;
12
+ className?: string;
13
+ iconClassName?: string;
14
+ searchIcon?: ReactNode;
15
+ clearIcon?: ReactNode;
16
+ };
17
+
18
+ export function SearchQueryForm({
19
+ value,
20
+ onChange,
21
+ onSubmit,
22
+ onClear,
23
+ className,
24
+ iconClassName,
25
+ searchIcon,
26
+ clearIcon,
27
+ }: SearchQueryFormProps): ReactElement {
28
+ function handleSubmit(event: FormEvent) {
29
+ event.preventDefault();
30
+ onSubmit();
31
+ }
32
+
33
+ return (
34
+ <form
35
+ role="search"
36
+ data-slot="search-query"
37
+ onSubmit={handleSubmit}
38
+ className={className}
39
+ >
40
+ <label htmlFor="garagem-search-q" data-slot="search-label">
41
+ Busca
42
+ </label>
43
+ <div data-slot="search-query-field">
44
+ <input
45
+ id="garagem-search-q"
46
+ name="q"
47
+ type="text"
48
+ inputMode="search"
49
+ autoComplete="off"
50
+ enterKeyHint="search"
51
+ value={value}
52
+ onChange={(event) => onChange(event.target.value)}
53
+ placeholder="Busque por bairro, rua ou código"
54
+ data-slot="search-query-input"
55
+ />
56
+ <div data-slot="search-query-actions">
57
+ {value ? (
58
+ <button
59
+ type="button"
60
+ title="Limpar busca"
61
+ aria-label="Limpar busca"
62
+ onClick={onClear}
63
+ data-slot="search-icon-button"
64
+ data-kind="clear"
65
+ >
66
+ {clearIcon ?? <SearchClearIcon className={iconClassName} />}
67
+ </button>
68
+ ) : null}
69
+ <button
70
+ type="submit"
71
+ title="Buscar"
72
+ aria-label="Buscar"
73
+ data-slot="search-icon-button"
74
+ >
75
+ {searchIcon ?? <SearchLensIcon className={iconClassName} />}
76
+ </button>
77
+ </div>
78
+ </div>
79
+ </form>
80
+ );
81
+ }