@etoile-dev/react 0.1.2 → 0.2.0

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.
package/dist/Search.d.ts CHANGED
@@ -13,6 +13,7 @@ export type SearchProps = {
13
13
  className?: string;
14
14
  /** Custom render function for each result (optional) */
15
15
  renderResult?: (result: SearchResultData) => React.ReactNode;
16
+ baseUrl?: string;
16
17
  };
17
18
  /**
18
19
  * All-in-one search component with sensible defaults.
@@ -33,4 +34,4 @@ export type SearchProps = {
33
34
  * <Search apiKey="your-api-key" collections={["paintings"]} className="dark" />
34
35
  * ```
35
36
  */
36
- export declare const Search: ({ apiKey, collections, limit, placeholder, className, renderResult, }: SearchProps) => import("react/jsx-runtime").JSX.Element;
37
+ export declare const Search: ({ apiKey, collections, limit, placeholder, className, renderResult, baseUrl, }: SearchProps) => import("react/jsx-runtime").JSX.Element;
package/dist/Search.js CHANGED
@@ -26,6 +26,6 @@ const DefaultResult = (result) => (_jsxs(SearchResult, { children: [_jsx(SearchR
26
26
  * <Search apiKey="your-api-key" collections={["paintings"]} className="dark" />
27
27
  * ```
28
28
  */
29
- export const Search = ({ apiKey, collections, limit, placeholder = "Search...", className, renderResult, }) => {
30
- return (_jsxs(SearchRoot, { apiKey: apiKey, collections: collections, limit: limit, className: className, children: [_jsxs("div", { className: "etoile-input-wrapper", children: [_jsx(SearchIcon, {}), _jsx(SearchInput, { placeholder: placeholder }), _jsx(SearchKbd, {})] }), _jsx(SearchResults, { children: renderResult ?? DefaultResult })] }));
29
+ export const Search = ({ apiKey, collections, limit, placeholder = "Search...", className, renderResult, baseUrl, }) => {
30
+ return (_jsxs(SearchRoot, { apiKey: apiKey, collections: collections, limit: limit, className: className, baseUrl: baseUrl, children: [_jsxs("div", { className: "etoile-input-wrapper", children: [_jsx(SearchIcon, {}), _jsx(SearchInput, { placeholder: placeholder }), _jsx(SearchKbd, {})] }), _jsx(SearchResults, { children: renderResult ?? DefaultResult })] }));
31
31
  };
@@ -14,6 +14,7 @@ export type SearchRootProps = {
14
14
  className?: string;
15
15
  /** Child components (SearchInput, SearchResults, etc.) */
16
16
  children: React.ReactNode;
17
+ baseUrl?: string;
17
18
  };
18
19
  /**
19
20
  * Root component for Étoile search that provides context to all child components.
@@ -40,4 +41,4 @@ export type SearchRootProps = {
40
41
  * </SearchRoot>
41
42
  * ```
42
43
  */
43
- export declare const SearchRoot: ({ apiKey, collections, limit, debounceMs, autoFocus, className, children, }: SearchRootProps) => import("react/jsx-runtime").JSX.Element;
44
+ export declare const SearchRoot: ({ apiKey, collections, limit, debounceMs, autoFocus, className, children, baseUrl, }: SearchRootProps) => import("react/jsx-runtime").JSX.Element;
@@ -27,8 +27,8 @@ import { useSearch } from "../hooks/useSearch.js";
27
27
  * </SearchRoot>
28
28
  * ```
29
29
  */
30
- export const SearchRoot = ({ apiKey, collections, limit, debounceMs, autoFocus = false, className, children, }) => {
31
- const search = useSearch({ apiKey, collections, limit, debounceMs });
30
+ export const SearchRoot = ({ apiKey, collections, limit, debounceMs, autoFocus = false, className, children, baseUrl, }) => {
31
+ const search = useSearch({ apiKey, collections, limit, debounceMs, baseUrl });
32
32
  const listboxId = React.useId();
33
33
  const resultRefs = React.useRef(new Map());
34
34
  const registerResult = (index, node) => {
@@ -8,6 +8,7 @@ export type UseSearchOptions = {
8
8
  limit?: number;
9
9
  /** Debounce delay in milliseconds before triggering search (default: 100) */
10
10
  debounceMs?: number;
11
+ baseUrl?: string;
11
12
  };
12
13
  export type UseSearchReturn = {
13
14
  /** Current search query string */
@@ -52,4 +53,4 @@ export type UseSearchReturn = {
52
53
  * });
53
54
  * ```
54
55
  */
55
- export declare const useSearch: ({ apiKey, collections, limit, debounceMs, }: UseSearchOptions) => UseSearchReturn;
56
+ export declare const useSearch: ({ apiKey, collections, limit, debounceMs, baseUrl, }: UseSearchOptions) => UseSearchReturn;
@@ -39,12 +39,13 @@ const clampIndex = (index, length) => {
39
39
  * });
40
40
  * ```
41
41
  */
42
- export const useSearch = ({ apiKey, collections, limit = 10, debounceMs = 100, }) => {
42
+ export const useSearch = ({ apiKey, collections, limit = 10, debounceMs = 100, baseUrl, }) => {
43
43
  const [query, setQuery] = React.useState("");
44
44
  const [debouncedQuery, setDebouncedQuery] = React.useState("");
45
45
  const [results, setResults] = React.useState([]);
46
46
  const [isLoading, setIsLoading] = React.useState(false);
47
47
  const [selectedIndex, setSelectedIndexState] = React.useState(-1);
48
+ const client = React.useMemo(() => new Etoile({ apiKey, baseUrl }), [apiKey, baseUrl]);
48
49
  React.useEffect(() => {
49
50
  const handle = setTimeout(() => {
50
51
  setDebouncedQuery(query);
@@ -63,7 +64,6 @@ export const useSearch = ({ apiKey, collections, limit = 10, debounceMs = 100, }
63
64
  const runSearch = async () => {
64
65
  setIsLoading(true);
65
66
  try {
66
- const client = new Etoile({ apiKey });
67
67
  const response = await client.search({
68
68
  collections,
69
69
  query: debouncedQuery,
@@ -90,7 +90,7 @@ export const useSearch = ({ apiKey, collections, limit = 10, debounceMs = 100, }
90
90
  return () => {
91
91
  isActive = false;
92
92
  };
93
- }, [apiKey, collections, debouncedQuery, limit]);
93
+ }, [client, collections, debouncedQuery, limit]);
94
94
  React.useEffect(() => {
95
95
  setSelectedIndexState((current) => clampIndex(current, results.length));
96
96
  }, [results.length]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etoile-dev/react",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Official React primitives for Étoile - Headless, composable search components",
5
5
  "keywords": [
6
6
  "etoile",
@@ -49,10 +49,10 @@
49
49
  "react": ">=18"
50
50
  },
51
51
  "dependencies": {
52
- "@etoile-dev/client": "^0.1.0"
52
+ "@etoile-dev/client": "^0.2.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/react": "^18.0.0",
56
56
  "typescript": "^5.0.0"
57
57
  }
58
- }
58
+ }