@cartbot/plate-search 3.1.1 → 3.1.3
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 +144 -0
- package/build/dist/js/plate-search.js +13 -13
- package/dist/js/plate-search.es.js +844 -771
- package/dist/js/plate-search.js +13 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,112 @@ const MyComponent = () => {
|
|
|
35
35
|
};
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
### Customizing Action Button
|
|
39
|
+
|
|
40
|
+
You can customize the "Show Products" button label:
|
|
41
|
+
|
|
42
|
+
```jsx
|
|
43
|
+
<PlateSearch
|
|
44
|
+
apiKey="YOUR_API_KEY"
|
|
45
|
+
productsUrl="/products"
|
|
46
|
+
actionButtonLabel="View Parts"
|
|
47
|
+
/>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Controlled Modal State
|
|
51
|
+
|
|
52
|
+
Control the modal open/close state from your own UI using either **controlled props** or **imperative methods**:
|
|
53
|
+
|
|
54
|
+
**Option 1: Controlled Props (Recommended)**
|
|
55
|
+
|
|
56
|
+
```jsx
|
|
57
|
+
import { useState } from "react";
|
|
58
|
+
import PlateSearch from "@cartbot/plate-search";
|
|
59
|
+
|
|
60
|
+
function App() {
|
|
61
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<>
|
|
65
|
+
<button onClick={() => setIsOpen(true)}>Search by Registration</button>
|
|
66
|
+
|
|
67
|
+
<PlateSearch
|
|
68
|
+
apiKey="YOUR_API_KEY"
|
|
69
|
+
isOpen={isOpen}
|
|
70
|
+
onOpenChange={setIsOpen}
|
|
71
|
+
hideDefaultButton
|
|
72
|
+
onModalClose={() => console.log("Modal closed")}
|
|
73
|
+
/>
|
|
74
|
+
</>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Option 2: Imperative Methods (via ref)**
|
|
80
|
+
|
|
81
|
+
```jsx
|
|
82
|
+
import { useRef } from "react";
|
|
83
|
+
import PlateSearch from "@cartbot/plate-search";
|
|
84
|
+
|
|
85
|
+
function App() {
|
|
86
|
+
const plateSearchRef = useRef();
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<>
|
|
90
|
+
<button onClick={() => plateSearchRef.current?.open()}>
|
|
91
|
+
Search by Registration
|
|
92
|
+
</button>
|
|
93
|
+
|
|
94
|
+
<PlateSearch
|
|
95
|
+
ref={plateSearchRef}
|
|
96
|
+
apiKey="YOUR_API_KEY"
|
|
97
|
+
hideDefaultButton
|
|
98
|
+
onModalClose={() => console.log("Modal closed")}
|
|
99
|
+
/>
|
|
100
|
+
</>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Available methods:
|
|
105
|
+
// plateSearchRef.current.open() - Open the modal
|
|
106
|
+
// plateSearchRef.current.close() - Close the modal
|
|
107
|
+
// plateSearchRef.current.toggle() - Toggle modal state
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Auto-Close on Vehicle Selection
|
|
111
|
+
|
|
112
|
+
By default, the component shows a confirmation/summary page after vehicle selection. To auto-close the modal immediately after selection:
|
|
113
|
+
|
|
114
|
+
```jsx
|
|
115
|
+
<PlateSearch
|
|
116
|
+
apiKey="YOUR_API_KEY"
|
|
117
|
+
autoCloseOnSelect={true}
|
|
118
|
+
onModalClose={() => {
|
|
119
|
+
// Modal closed after vehicle selection
|
|
120
|
+
const vehicle = JSON.parse(
|
|
121
|
+
localStorage.getItem("partbot_selected_vehicle")
|
|
122
|
+
);
|
|
123
|
+
console.log("Selected:", vehicle);
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Listening to Events
|
|
129
|
+
|
|
130
|
+
The component dispatches DOM events you can listen to:
|
|
131
|
+
|
|
132
|
+
```jsx
|
|
133
|
+
// Listen to modal close events
|
|
134
|
+
document.addEventListener("plate-search-modal-close", (e) => {
|
|
135
|
+
console.log("Modal closed at", e.detail.timestamp);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Listen to vehicle selection events
|
|
139
|
+
document.addEventListener("plate-search-change", (e) => {
|
|
140
|
+
console.log("Vehicle selected:", e.detail.vehicle_ids);
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
38
144
|
### Advanced Usage
|
|
39
145
|
|
|
40
146
|
If you need direct access to the component without Shadow DOM isolation (for example, to apply your own styling), you can import the raw component:
|
|
@@ -56,6 +162,44 @@ import { PlateSearchRaw } from "@cartbot/plate-search";
|
|
|
56
162
|
/>
|
|
57
163
|
```
|
|
58
164
|
|
|
165
|
+
### Web Component - Customization
|
|
166
|
+
|
|
167
|
+
```html
|
|
168
|
+
<!-- Custom action button label -->
|
|
169
|
+
<plate-search
|
|
170
|
+
data-api-key="YOUR_API_KEY"
|
|
171
|
+
data-products-url="/products"
|
|
172
|
+
data-action-button-label="View Parts"
|
|
173
|
+
/>
|
|
174
|
+
|
|
175
|
+
<!-- Hide default button (trigger modal from your own button) -->
|
|
176
|
+
<button onclick="document.querySelector('plate-search').open()">
|
|
177
|
+
Search by Rego
|
|
178
|
+
</button>
|
|
179
|
+
<plate-search data-api-key="YOUR_API_KEY" data-hide-default-button="true" />
|
|
180
|
+
|
|
181
|
+
<!-- Auto-close after vehicle selection -->
|
|
182
|
+
<plate-search data-api-key="YOUR_API_KEY" data-auto-close-on-select="true" />
|
|
183
|
+
|
|
184
|
+
<script>
|
|
185
|
+
// Control modal programmatically
|
|
186
|
+
const plateSearch = document.querySelector("plate-search");
|
|
187
|
+
|
|
188
|
+
plateSearch.open(); // Open the modal
|
|
189
|
+
plateSearch.close(); // Close the modal
|
|
190
|
+
plateSearch.toggle(); // Toggle modal open/close
|
|
191
|
+
|
|
192
|
+
// Listen to events
|
|
193
|
+
document.addEventListener("plate-search-modal-close", (e) => {
|
|
194
|
+
console.log("Modal closed at", e.detail.timestamp);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
document.addEventListener("plate-search-change", (e) => {
|
|
198
|
+
console.log("Vehicle selected:", e.detail.vehicle_ids);
|
|
199
|
+
});
|
|
200
|
+
</script>
|
|
201
|
+
```
|
|
202
|
+
|
|
59
203
|
Copyright (c) Partbot Software Pty Ltd
|
|
60
204
|
|
|
61
205
|
[use.partbot.io](https://use.partbot.io)
|