hisd3-ui-kit 4.4.1 → 4.7.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/README.md CHANGED
@@ -201,6 +201,47 @@ logo is used. `HISD3_LOGO_SRC` is exported if you need the mark elsewhere.
201
201
  `primary` accepts the brand presets `"brand"` (the logo's gear, `#E5533B`) and
202
202
  `"brandBlue"` (its cloud, `#1B6FE0`), any other preset, or a hex value.
203
203
 
204
+ ## Drawers and modals — `useDialog`
205
+
206
+ Open a drawer or modal from anywhere, without the page holding its state. Put
207
+ `DialogProvider` once near the root, inside whatever providers a dialog may
208
+ need (the account and Apollo providers, and `HISD3Provider` for the theme):
209
+
210
+ ```tsx
211
+ <HISD3Provider primary="teal">
212
+ <DialogProvider>{children}</DialogProvider>
213
+ </HISD3Provider>
214
+ ```
215
+
216
+ Then a page calls a function instead of owning `open` state per drawer:
217
+
218
+ ```tsx
219
+ const showRecord = useDialog(RecordEventDrawer);
220
+
221
+ showRecord({ fundYear, balances }, (batchId) => {
222
+ if (batchId) refetch();
223
+ });
224
+ ```
225
+
226
+ The component receives two extra props on top of its own — `open` (pass it to
227
+ antd's `open` so the close animates) and `hide(result)`, whose argument reaches
228
+ the second argument of `showRecord`:
229
+
230
+ ```tsx
231
+ function RecordEventDrawer({ open, hide, fundYear }: DialogProps<string> & Props) {
232
+ return (
233
+ <Drawer open={open} onClose={() => hide()} title={`Record — ${fundYear}`}>
234
+ <Button onClick={() => hide(batchId)}>Save</Button>
235
+ </Drawer>
236
+ );
237
+ }
238
+ ```
239
+
240
+ Props are captured when `show` is called, so a drawer that used to be fed live
241
+ state by its parent (`saving`) owns that state itself now. `hide` is safe to
242
+ call twice — Escape during the close animation will not fire the callback
243
+ again — and the instance unmounts once the animation finishes.
244
+
204
245
  ## Migrating
205
246
 
206
247
  ### from 3.x