@garagem-ai/site-sdk 0.4.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.
@@ -1,15 +1,15 @@
1
1
  "use client";
2
2
 
3
- import type { ReactElement } from "react";
3
+ import type { MouseEvent, ReactElement } from "react";
4
4
  import Link from "next/link";
5
5
 
6
- import { paginationPages } from "../search-engine";
7
- import { cn } from "./cn";
6
+ import { hrefWithExplicitPage, paginationPages } from "../search-engine";
8
7
 
9
8
  export type SearchPaginationProps = {
10
9
  page: number;
11
10
  totalPages: number;
12
11
  hrefForPage: (page: number) => string;
12
+ onNavigate?: (href: string) => void;
13
13
  className?: string;
14
14
  };
15
15
 
@@ -18,36 +18,44 @@ function NavItem({
18
18
  label,
19
19
  disabled,
20
20
  current,
21
- className,
21
+ onNavigate,
22
22
  }: {
23
23
  href?: string;
24
24
  label: string;
25
25
  disabled?: boolean;
26
26
  current?: boolean;
27
- className?: string;
27
+ onNavigate?: (href: string) => void;
28
28
  }): ReactElement {
29
- const itemClass = cn(
30
- "inline-flex size-8 cursor-pointer items-center justify-center rounded-md border text-xs font-medium md:size-9",
31
- current && "bg-primary text-primary-foreground",
32
- disabled && "cursor-not-allowed text-muted-foreground",
33
- className
34
- );
35
29
  if (disabled || !href || current) {
36
30
  return (
37
- <li className={itemClass}>
38
- <span className="flex size-full items-center justify-center">
39
- {label}
40
- </span>
31
+ <li
32
+ data-slot="search-pagination-item"
33
+ data-current={current ? "true" : undefined}
34
+ data-disabled={disabled ? "true" : undefined}
35
+ >
36
+ <span>{label}</span>
41
37
  </li>
42
38
  );
43
39
  }
40
+
41
+ function handleClick(event: MouseEvent<HTMLAnchorElement>) {
42
+ if (!onNavigate || !href) return;
43
+ if (
44
+ event.metaKey ||
45
+ event.ctrlKey ||
46
+ event.shiftKey ||
47
+ event.altKey ||
48
+ event.button !== 0
49
+ ) {
50
+ return;
51
+ }
52
+ event.preventDefault();
53
+ onNavigate(href);
54
+ }
55
+
44
56
  return (
45
- <li className={itemClass}>
46
- <Link
47
- href={href}
48
- className="flex size-full items-center justify-center"
49
- aria-label={label}
50
- >
57
+ <li data-slot="search-pagination-item">
58
+ <Link href={href} onClick={handleClick} aria-label={label}>
51
59
  {label}
52
60
  </Link>
53
61
  </li>
@@ -58,51 +66,53 @@ export function SearchPagination({
58
66
  page,
59
67
  totalPages,
60
68
  hrefForPage,
69
+ onNavigate,
61
70
  className,
62
71
  }: SearchPaginationProps): ReactElement | null {
63
72
  if (totalPages <= 1) return null;
64
- const mobile = paginationPages(page, totalPages, 1);
65
- const desktop = paginationPages(page, totalPages, 2);
73
+ const pages = paginationPages(page, totalPages, 2);
66
74
  return (
67
75
  <nav
68
76
  data-slot="search-pagination"
69
- className={cn("mt-10 flex justify-center", className)}
77
+ className={className}
70
78
  aria-label="Paginação"
71
79
  >
72
- <ul className="flex gap-0.5 md:gap-1">
73
- <NavItem href={hrefForPage(1)} label="‹‹" disabled={page <= 1} />
80
+ <ul>
74
81
  <NavItem
75
- href={hrefForPage(Math.max(1, page - 1))}
82
+ href={hrefWithExplicitPage(hrefForPage(1), 1)}
83
+ label="‹‹"
84
+ disabled={page <= 1}
85
+ onNavigate={onNavigate}
86
+ />
87
+ <NavItem
88
+ href={hrefWithExplicitPage(
89
+ hrefForPage(Math.max(1, page - 1)),
90
+ Math.max(1, page - 1)
91
+ )}
76
92
  label="‹"
77
93
  disabled={page <= 1}
94
+ onNavigate={onNavigate}
78
95
  />
79
- {mobile.map((n) => (
80
- <NavItem
81
- key={`m-${n}`}
82
- href={hrefForPage(n)}
83
- label={String(n)}
84
- current={n === page}
85
- className="md:hidden"
86
- />
87
- ))}
88
- {desktop.map((n) => (
96
+ {pages.map((n) => (
89
97
  <NavItem
90
- key={`d-${n}`}
91
- href={hrefForPage(n)}
98
+ key={n}
99
+ href={hrefWithExplicitPage(hrefForPage(n), n)}
92
100
  label={String(n)}
93
101
  current={n === page}
94
- className="hidden md:inline-flex"
102
+ onNavigate={onNavigate}
95
103
  />
96
104
  ))}
97
105
  <NavItem
98
106
  href={hrefForPage(Math.min(totalPages, page + 1))}
99
107
  label="›"
100
108
  disabled={page >= totalPages}
109
+ onNavigate={onNavigate}
101
110
  />
102
111
  <NavItem
103
112
  href={hrefForPage(totalPages)}
104
113
  label="››"
105
114
  disabled={page >= totalPages}
115
+ onNavigate={onNavigate}
106
116
  />
107
117
  </ul>
108
118
  </nav>
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
 
3
- import type { FormEvent, ReactElement } from "react";
3
+ import type { FormEvent, ReactElement, ReactNode } from "react";
4
4
 
5
- import { cn } from "./cn";
5
+ import { SearchClearIcon, SearchLensIcon } from "./icons";
6
6
 
7
7
  export type SearchQueryFormProps = {
8
8
  value: string;
@@ -10,6 +10,9 @@ export type SearchQueryFormProps = {
10
10
  onSubmit: () => void;
11
11
  onClear: () => void;
12
12
  className?: string;
13
+ iconClassName?: string;
14
+ searchIcon?: ReactNode;
15
+ clearIcon?: ReactNode;
13
16
  };
14
17
 
15
18
  export function SearchQueryForm({
@@ -18,6 +21,9 @@ export function SearchQueryForm({
18
21
  onSubmit,
19
22
  onClear,
20
23
  className,
24
+ iconClassName,
25
+ searchIcon,
26
+ clearIcon,
21
27
  }: SearchQueryFormProps): ReactElement {
22
28
  function handleSubmit(event: FormEvent) {
23
29
  event.preventDefault();
@@ -29,45 +35,44 @@ export function SearchQueryForm({
29
35
  role="search"
30
36
  data-slot="search-query"
31
37
  onSubmit={handleSubmit}
32
- className={cn("flex items-end gap-2", className)}
38
+ className={className}
33
39
  >
34
- <div className="min-w-0 flex-1">
35
- <label
36
- htmlFor="garagem-search-q"
37
- className="mb-1 block text-sm text-muted-foreground"
38
- >
39
- Busca
40
- </label>
41
- <div className="relative">
42
- <input
43
- id="garagem-search-q"
44
- name="q"
45
- type="search"
46
- autoComplete="off"
47
- enterKeyHint="search"
48
- value={value}
49
- onChange={(event) => onChange(event.target.value)}
50
- placeholder="Busque por bairro, rua ou código"
51
- className="min-h-12 w-full rounded-xl border border-border bg-background px-4 pr-20 outline-none focus:border-primary"
52
- />
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">
53
57
  {value ? (
54
58
  <button
55
59
  type="button"
56
60
  title="Limpar busca"
57
61
  aria-label="Limpar busca"
58
62
  onClick={onClear}
59
- className="absolute right-10 top-1/2 -translate-y-1/2 cursor-pointer rounded-md px-2 py-1 text-sm text-muted-foreground hover:text-foreground"
63
+ data-slot="search-icon-button"
64
+ data-kind="clear"
60
65
  >
61
- ×
66
+ {clearIcon ?? <SearchClearIcon className={iconClassName} />}
62
67
  </button>
63
68
  ) : null}
64
69
  <button
65
70
  type="submit"
66
71
  title="Buscar"
67
72
  aria-label="Buscar"
68
- className="absolute right-2 top-1/2 -translate-y-1/2 cursor-pointer rounded-md px-2 py-1 text-sm font-medium hover:bg-muted"
73
+ data-slot="search-icon-button"
69
74
  >
70
- ⌕
75
+ {searchIcon ?? <SearchLensIcon className={iconClassName} />}
71
76
  </button>
72
77
  </div>
73
78
  </div>