@cartbot/plate-search 3.1.1 → 3.1.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 CHANGED
@@ -35,6 +35,79 @@ 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:
53
+
54
+ ```jsx
55
+ import { useState } from "react";
56
+ import PlateSearch from "@cartbot/plate-search";
57
+
58
+ function App() {
59
+ const [isOpen, setIsOpen] = useState(false);
60
+
61
+ return (
62
+ <>
63
+ <button onClick={() => setIsOpen(true)}>Search by Registration</button>
64
+
65
+ <PlateSearch
66
+ apiKey="YOUR_API_KEY"
67
+ isOpen={isOpen}
68
+ onOpenChange={setIsOpen}
69
+ hideDefaultButton
70
+ onModalClose={() => console.log("Modal closed")}
71
+ />
72
+ </>
73
+ );
74
+ }
75
+ ```
76
+
77
+ ### Auto-Close on Vehicle Selection
78
+
79
+ By default, the component shows a confirmation/summary page after vehicle selection. To auto-close the modal immediately after selection:
80
+
81
+ ```jsx
82
+ <PlateSearch
83
+ apiKey="YOUR_API_KEY"
84
+ autoCloseOnSelect={true}
85
+ onModalClose={() => {
86
+ // Modal closed after vehicle selection
87
+ const vehicle = JSON.parse(
88
+ localStorage.getItem("partbot_selected_vehicle")
89
+ );
90
+ console.log("Selected:", vehicle);
91
+ }}
92
+ />
93
+ ```
94
+
95
+ ### Listening to Events
96
+
97
+ The component dispatches DOM events you can listen to:
98
+
99
+ ```jsx
100
+ // Listen to modal close events
101
+ document.addEventListener("plate-search-modal-close", (e) => {
102
+ console.log("Modal closed at", e.detail.timestamp);
103
+ });
104
+
105
+ // Listen to vehicle selection events
106
+ document.addEventListener("plate-search-change", (e) => {
107
+ console.log("Vehicle selected:", e.detail.vehicle_ids);
108
+ });
109
+ ```
110
+
38
111
  ### Advanced Usage
39
112
 
40
113
  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 +129,44 @@ import { PlateSearchRaw } from "@cartbot/plate-search";
56
129
  />
57
130
  ```
58
131
 
132
+ ### Web Component - Customization
133
+
134
+ ```html
135
+ <!-- Custom action button label -->
136
+ <plate-search
137
+ data-api-key="YOUR_API_KEY"
138
+ data-products-url="/products"
139
+ data-action-button-label="View Parts"
140
+ />
141
+
142
+ <!-- Hide default button (trigger modal from your own button) -->
143
+ <button onclick="document.querySelector('plate-search').open()">
144
+ Search by Rego
145
+ </button>
146
+ <plate-search data-api-key="YOUR_API_KEY" data-hide-default-button="true" />
147
+
148
+ <!-- Auto-close after vehicle selection -->
149
+ <plate-search data-api-key="YOUR_API_KEY" data-auto-close-on-select="true" />
150
+
151
+ <script>
152
+ // Control modal programmatically
153
+ const plateSearch = document.querySelector("plate-search");
154
+
155
+ plateSearch.open(); // Open the modal
156
+ plateSearch.close(); // Close the modal
157
+ plateSearch.toggle(); // Toggle modal open/close
158
+
159
+ // Listen to events
160
+ document.addEventListener("plate-search-modal-close", (e) => {
161
+ console.log("Modal closed at", e.detail.timestamp);
162
+ });
163
+
164
+ document.addEventListener("plate-search-change", (e) => {
165
+ console.log("Vehicle selected:", e.detail.vehicle_ids);
166
+ });
167
+ </script>
168
+ ```
169
+
59
170
  Copyright (c) Partbot Software Pty Ltd
60
171
 
61
172
  [use.partbot.io](https://use.partbot.io)