@pro6pp/infer-react 0.0.2-beta.0 → 0.0.2-beta.10
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 +50 -8
- package/dist/index.cjs +777 -0
- package/dist/index.d.cts +68 -0
- package/dist/index.d.ts +54 -10
- package/dist/index.js +732 -32
- package/package.json +35 -10
- package/dist/index.d.mts +0 -24
- package/dist/index.mjs +0 -25
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Pro6PP Infer React SDK
|
|
2
2
|
|
|
3
3
|
React Hook for the [Pro6PP Infer API](https://www.pro6pp.com/developer/infer/nl/parameters).
|
|
4
4
|
A headless library to build custom address autocomplete components in React.
|
|
@@ -11,13 +11,52 @@ npm install @pro6pp/infer-react
|
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
The `Pro6PPInfer` component provides a styled address autocomplete input.
|
|
15
15
|
|
|
16
16
|
```tsx
|
|
17
17
|
import React from 'react';
|
|
18
|
-
import {
|
|
18
|
+
import { Pro6PPInfer } from '@pro6pp/infer-react';
|
|
19
19
|
|
|
20
20
|
const AddressForm = () => {
|
|
21
|
+
return (
|
|
22
|
+
<div className="form-group">
|
|
23
|
+
<label>Search Address</label>
|
|
24
|
+
<Pro6PPInfer
|
|
25
|
+
authKey="YOUR_AUTH_KEY"
|
|
26
|
+
country="NL"
|
|
27
|
+
onSelect={(selection) => console.log('Selected:', selection)}
|
|
28
|
+
placeholder="Type a Dutch address..."
|
|
29
|
+
/>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
You can customize the appearance of the component via the following props:
|
|
36
|
+
|
|
37
|
+
| Prop | Description |
|
|
38
|
+
| :--------------------- | :---------------------------------------------------------------------------------------- |
|
|
39
|
+
| `className` | Optional CSS class name for the wrapper `div`. |
|
|
40
|
+
| `disableDefaultStyles` | If `true`, prevents the automatic injection of the default CSS theme. |
|
|
41
|
+
| `placeholder` | Custom placeholder text for the input field. |
|
|
42
|
+
| `noResultsText` | The text to display when no suggestions are found. |
|
|
43
|
+
| `renderItem` | A custom render function for suggestion items, receiving the `item` and `isActive` state. |
|
|
44
|
+
| `renderNoResults` | A custom render function for the empty state, receiving the current `state`. |
|
|
45
|
+
| `debounceMs` | Delay in ms before API search. Defaults to `150` (min `50`). |
|
|
46
|
+
| `maxRetries` | Maximum retry attempts for transient network errors. Valid range: `0` to `10`. |
|
|
47
|
+
| `showClearButton` | If `true`, displays a button to empty the input field. Defaults to `true`. |
|
|
48
|
+
| `loadMoreText` | The text to display on the pagination button. |
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
Alternatively, you can use the headless `useInfer` hook.
|
|
53
|
+
This hook handles all the logic (state, API calls, debouncing, keyboard navigation), but allows you to build your own custom UI.
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
import React from 'react';
|
|
57
|
+
import { useInfer } from '@pro6pp/infer-react';
|
|
58
|
+
|
|
59
|
+
const CustomAddressForm = () => {
|
|
21
60
|
const { state, inputProps, selectItem } = useInfer({
|
|
22
61
|
authKey: 'YOUR_AUTH_KEY',
|
|
23
62
|
country: 'NL',
|
|
@@ -28,19 +67,22 @@ const AddressForm = () => {
|
|
|
28
67
|
<div className="address-autocomplete">
|
|
29
68
|
<label>Address</label>
|
|
30
69
|
|
|
31
|
-
|
|
70
|
+
{/* inputProps contains value, onChange, and onKeyDown */}
|
|
71
|
+
<input {...inputProps} placeholder="Type an address..." className="my-input-class" />
|
|
72
|
+
|
|
73
|
+
{state.isLoading && <div className="spinner">Loading...</div>}
|
|
32
74
|
|
|
33
75
|
{/* render the dropdown */}
|
|
34
76
|
{(state.suggestions.length > 0 || state.cities.length > 0) && (
|
|
35
77
|
<ul className="my-dropdown-class">
|
|
36
|
-
{/* render cities
|
|
78
|
+
{/* render cities */}
|
|
37
79
|
{state.cities.map((city, i) => (
|
|
38
80
|
<li key={`city-${i}`} onClick={() => selectItem(city)}>
|
|
39
81
|
<strong>{city.label}</strong> (City)
|
|
40
82
|
</li>
|
|
41
83
|
))}
|
|
42
84
|
|
|
43
|
-
{/* render streets
|
|
85
|
+
{/* render streets */}
|
|
44
86
|
{state.streets.map((street, i) => (
|
|
45
87
|
<li key={`street-${i}`} onClick={() => selectItem(street)}>
|
|
46
88
|
<strong>{street.label}</strong> (Street)
|
|
@@ -49,14 +91,14 @@ const AddressForm = () => {
|
|
|
49
91
|
|
|
50
92
|
{/* render general suggestions */}
|
|
51
93
|
{state.suggestions.map((item, i) => (
|
|
52
|
-
<li key={`
|
|
94
|
+
<li key={`suggestion-${i}`} onClick={() => selectItem(item)}>
|
|
53
95
|
{item.label}
|
|
54
96
|
</li>
|
|
55
97
|
))}
|
|
56
98
|
</ul>
|
|
57
99
|
)}
|
|
58
100
|
|
|
59
|
-
{state.isValid && <p>Valid address selected
|
|
101
|
+
{state.isValid && <p>Valid address selected.</p>}
|
|
60
102
|
</div>
|
|
61
103
|
);
|
|
62
104
|
};
|