@tsproxy/react 0.0.1 → 0.0.2
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/README.md +68 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -18
- package/package.json +11 -13
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @tsproxy/react
|
|
2
|
+
|
|
3
|
+
Headless React components for [tsproxy](https://github.com/akshitkrnagpal/tsproxy) with a BaseUI-style overrides pattern.
|
|
4
|
+
|
|
5
|
+
> **This project is under heavy development.**
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @tsproxy/react @tsproxy/js react-instantsearch
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { SearchProvider, SearchBox, Hits, RefinementList, Pagination, Stats } from "@tsproxy/react";
|
|
17
|
+
import { Configure } from "react-instantsearch";
|
|
18
|
+
|
|
19
|
+
export default function SearchPage() {
|
|
20
|
+
return (
|
|
21
|
+
<SearchProvider serverUrl="http://localhost:3000" indexName="products">
|
|
22
|
+
<Configure hitsPerPage={12} />
|
|
23
|
+
<SearchBox placeholder="Search..." />
|
|
24
|
+
<Stats />
|
|
25
|
+
<RefinementList attribute="category" />
|
|
26
|
+
<Hits hitComponent={({ hit }) => <div>{hit.name}</div>} />
|
|
27
|
+
<Pagination />
|
|
28
|
+
</SearchProvider>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Overrides
|
|
34
|
+
|
|
35
|
+
Every component accepts an `overrides` prop to customize any sub-element:
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
<SearchBox
|
|
39
|
+
overrides={{
|
|
40
|
+
Input: { props: { className: "rounded-full border px-4 py-2" } },
|
|
41
|
+
SubmitButton: { props: { hidden: true } },
|
|
42
|
+
ResetButton: { component: MyResetButton },
|
|
43
|
+
}}
|
|
44
|
+
/>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Components
|
|
48
|
+
|
|
49
|
+
| Component | Sub-elements |
|
|
50
|
+
|-----------|-------------|
|
|
51
|
+
| `SearchBox` | Root, Form, Input, SubmitButton, ResetButton |
|
|
52
|
+
| `Hits` | Root, List, Item |
|
|
53
|
+
| `RefinementList` | Root, List, Item, Label, Checkbox, LabelText, Count |
|
|
54
|
+
| `Pagination` | Root, List, Item, Link |
|
|
55
|
+
| `Stats` | Root, Text |
|
|
56
|
+
| `SortBy` | Root, Select, Option |
|
|
57
|
+
| `NoResults` | Root, Title, Message |
|
|
58
|
+
| `HitsSkeleton` | Root, List, Item |
|
|
59
|
+
| `LocaleSelector` | Root, Select, Option |
|
|
60
|
+
| `SearchProvider` | — (wraps InstantSearch) |
|
|
61
|
+
|
|
62
|
+
## Documentation
|
|
63
|
+
|
|
64
|
+
[tsproxy.akshit.io](https://tsproxy.akshit.io)
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ interface LocaleContextValue {
|
|
|
40
40
|
locale: string | undefined;
|
|
41
41
|
setLocale: (locale: string) => void;
|
|
42
42
|
}
|
|
43
|
-
declare const LocaleContext: react.Context<LocaleContextValue
|
|
43
|
+
declare const LocaleContext: react.Context<LocaleContextValue>;
|
|
44
44
|
declare function useLocale(): LocaleContextValue;
|
|
45
45
|
interface LocaleProviderProps {
|
|
46
46
|
initialLocale?: string;
|
|
@@ -108,7 +108,7 @@ interface PaginationProps {
|
|
|
108
108
|
padding?: number;
|
|
109
109
|
overrides?: Overrides<PaginationElements>;
|
|
110
110
|
}
|
|
111
|
-
declare function Pagination({ padding, overrides }: PaginationProps): react_jsx_runtime.JSX.Element
|
|
111
|
+
declare function Pagination({ padding, overrides }: PaginationProps): react_jsx_runtime.JSX.Element;
|
|
112
112
|
|
|
113
113
|
type StatsElements = {
|
|
114
114
|
Root: "div";
|
|
@@ -161,7 +161,7 @@ interface NoResultsProps {
|
|
|
161
161
|
children?: ReactNode;
|
|
162
162
|
overrides?: Overrides<NoResultsElements>;
|
|
163
163
|
}
|
|
164
|
-
declare function NoResults({ title, message, children, overrides, }: NoResultsProps): react_jsx_runtime.JSX.Element
|
|
164
|
+
declare function NoResults({ title, message, children, overrides, }: NoResultsProps): react_jsx_runtime.JSX.Element;
|
|
165
165
|
|
|
166
166
|
type HitsSkeletonElements = {
|
|
167
167
|
Root: "div";
|
package/dist/index.js
CHANGED
|
@@ -40,12 +40,12 @@ import { useMemo as useMemo2 } from "react";
|
|
|
40
40
|
import { InstantSearch } from "react-instantsearch";
|
|
41
41
|
import { createSearchClient } from "@tsproxy/js";
|
|
42
42
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
43
|
-
function
|
|
43
|
+
function SearchProvider({
|
|
44
44
|
serverUrl,
|
|
45
45
|
indexName,
|
|
46
|
+
locale,
|
|
46
47
|
children
|
|
47
48
|
}) {
|
|
48
|
-
const { locale } = useLocale();
|
|
49
49
|
const searchClient = useMemo2(
|
|
50
50
|
() => createSearchClient({
|
|
51
51
|
url: serverUrl,
|
|
@@ -54,22 +54,7 @@ function SearchProviderInner({
|
|
|
54
54
|
}),
|
|
55
55
|
[serverUrl, locale]
|
|
56
56
|
);
|
|
57
|
-
return /* @__PURE__ */ jsx2(
|
|
58
|
-
InstantSearch,
|
|
59
|
-
{
|
|
60
|
-
searchClient,
|
|
61
|
-
indexName,
|
|
62
|
-
children
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
function SearchProvider({
|
|
67
|
-
serverUrl,
|
|
68
|
-
indexName,
|
|
69
|
-
locale,
|
|
70
|
-
children
|
|
71
|
-
}) {
|
|
72
|
-
return /* @__PURE__ */ jsx2(LocaleProvider, { initialLocale: locale, children: /* @__PURE__ */ jsx2(SearchProviderInner, { serverUrl, indexName, children }) });
|
|
57
|
+
return /* @__PURE__ */ jsx2(InstantSearch, { searchClient, indexName, children });
|
|
73
58
|
}
|
|
74
59
|
|
|
75
60
|
// src/components/SearchBox.tsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsproxy/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Headless React components for tsproxy with BaseUI-style overrides",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
16
17
|
],
|
|
17
18
|
"publishConfig": {
|
|
18
19
|
"access": "public"
|
|
@@ -30,8 +31,12 @@
|
|
|
30
31
|
"headless",
|
|
31
32
|
"search"
|
|
32
33
|
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"typecheck": "tsc --noEmit"
|
|
37
|
+
},
|
|
33
38
|
"dependencies": {
|
|
34
|
-
"@tsproxy/js": "0.0.
|
|
39
|
+
"@tsproxy/js": "^0.0.2"
|
|
35
40
|
},
|
|
36
41
|
"peerDependencies": {
|
|
37
42
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -39,16 +44,9 @@
|
|
|
39
44
|
"react-instantsearch": "^7.0.0"
|
|
40
45
|
},
|
|
41
46
|
"devDependencies": {
|
|
42
|
-
"@types/react": "^
|
|
43
|
-
"@types/react-dom": "^
|
|
44
|
-
"react": "^18.3.0",
|
|
45
|
-
"react-dom": "^18.3.0",
|
|
46
|
-
"react-instantsearch": "^7.29.0",
|
|
47
|
+
"@types/react": "^19",
|
|
48
|
+
"@types/react-dom": "^19",
|
|
47
49
|
"tsup": "^8.4.0",
|
|
48
50
|
"typescript": "^5.5.3"
|
|
49
|
-
},
|
|
50
|
-
"scripts": {
|
|
51
|
-
"build": "tsup src/index.ts --format esm --dts --external react --external react-dom --external react-instantsearch --external @tsproxy/js --tsconfig tsconfig.build.json",
|
|
52
|
-
"typecheck": "tsc --noEmit"
|
|
53
51
|
}
|
|
54
|
-
}
|
|
52
|
+
}
|