agnosticui-core 2.0.0-alpha.22 → 2.0.0-alpha.23

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.
@@ -1,13 +1,26 @@
1
- import { EventName } from '@lit/react';
2
- import { AgnosticDrawer, DrawerProps, DrawerOpenEvent, DrawerCloseEvent, DrawerCancelEvent } from '../core/Drawer';
1
+ import { AgnosticDrawer, DrawerProps } from '../core/Drawer';
3
2
  import * as React from 'react';
4
3
  /**
5
- * React-specific props for Drawer
4
+ * React-specific props for Drawer.
5
+ *
6
+ * Includes onOpenChange for controlled-component support. This is necessary
7
+ * because the underlying Lit web component manages its own open state internally
8
+ * (e.g. it sets this.open = false on Escape or backdrop click). @lit/react's
9
+ * createComponent only bridges DOM events -> React props, so without explicitly
10
+ * calling onOpenChange(false) on close/cancel, React's state never learns the
11
+ * drawer closed. The stale open={true} is then re-applied on the next render,
12
+ * causing previously dismissed drawers to reappear when other drawers are opened.
6
13
  */
7
14
  export interface ReactDrawerProps extends DrawerProps {
8
15
  children?: React.ReactNode;
9
16
  className?: string;
10
17
  id?: string;
18
+ /**
19
+ * Called with the new open state whenever the drawer opens or closes.
20
+ * Wire this to your React state setter (e.g. onOpenChange={setIsOpen}) so
21
+ * React stays in sync when the drawer closes itself internally.
22
+ */
23
+ onOpenChange?: (open: boolean) => void;
11
24
  }
12
25
  /**
13
26
  * Helper component for drawer header slot
@@ -21,11 +34,17 @@ export interface DrawerHeaderProps {
21
34
  export interface DrawerFooterProps {
22
35
  children?: React.ReactNode;
23
36
  }
24
- export declare const ReactDrawer: import('@lit/react').ReactWebComponent<AgnosticDrawer, {
25
- onDrawerOpen: EventName<DrawerOpenEvent>;
26
- onDrawerClose: EventName<DrawerCloseEvent>;
27
- onDrawerCancel: EventName<DrawerCancelEvent>;
28
- }>;
37
+ /**
38
+ * ReactDrawer wraps _ReactDrawerBase to add onOpenChange support.
39
+ *
40
+ * The Lit element fires "drawer-close" when the close button is clicked and
41
+ * "drawer-cancel" when the user presses Escape or clicks the backdrop. Both
42
+ * mean the drawer is now closed. We intercept those two events and call
43
+ * onOpenChange(false) so React state reflects the new closed state immediately,
44
+ * preventing the stale open={true} from being pushed back into the element on
45
+ * the next render.
46
+ */
47
+ export declare const ReactDrawer: React.ForwardRefExoticComponent<ReactDrawerProps & React.RefAttributes<AgnosticDrawer>>;
29
48
  export declare const DrawerHeader: React.FC<DrawerHeaderProps>;
30
49
  export declare const DrawerFooter: React.FC<DrawerFooterProps>;
31
50
  export type { DrawerOpenEvent, DrawerCloseEvent, DrawerCancelEvent } from '../core/Drawer';
@@ -1 +1 @@
1
- {"version":3,"file":"ReactDrawer.d.ts","sourceRoot":"","sources":["../../../../src/components/Drawer/react/ReactDrawer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EACL,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACvB,MAAM,gBAAgB,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAGD,eAAO,MAAM,WAAW;kBAKW,SAAS,CAAC,eAAe,CAAC;mBACxB,SAAS,CAAC,gBAAgB,CAAC;oBACzB,SAAS,CAAC,iBAAiB,CAAC;EAEjE,CAAC;AAGH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAEpD,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAEpD,CAAC;AAGF,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"ReactDrawer.d.ts","sourceRoot":"","sources":["../../../../src/components/Drawer/react/ReactDrawer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EACL,cAAc,EACd,KAAK,WAAW,EAIjB,MAAM,gBAAgB,CAAC;AAExB;;;;;;;;;;GAUG;AACH,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAeD;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,yFA4BvB,CAAC;AAKF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAEpD,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAEpD,CAAC;AAGF,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,20 +1,42 @@
1
- import { j as e } from "../../../jsx-runtime-BzflLqGi.js";
1
+ import { j as a } from "../../../jsx-runtime-BzflLqGi.js";
2
2
  import * as o from "react";
3
- import { o as a } from "../../../create-component-BPMDMe-q.js";
3
+ import { o as m } from "../../../create-component-BPMDMe-q.js";
4
4
  import "../core/Drawer.js";
5
- import { AgnosticDrawer as t } from "../core/_drawer.js";
6
- const w = a({
5
+ import { AgnosticDrawer as i } from "../core/_drawer.js";
6
+ const p = m({
7
7
  tagName: "ag-drawer",
8
- elementClass: t,
8
+ elementClass: i,
9
9
  react: o,
10
10
  events: {
11
11
  onDrawerOpen: "drawer-open",
12
12
  onDrawerClose: "drawer-close",
13
13
  onDrawerCancel: "drawer-cancel"
14
14
  }
15
- }), i = ({ children: r }) => /* @__PURE__ */ e.jsx("div", { slot: "header", children: r }), p = ({ children: r }) => /* @__PURE__ */ e.jsx("div", { slot: "footer", children: r });
15
+ }), f = o.forwardRef(
16
+ ({ onOpenChange: r, onDrawerOpen: t, onDrawerClose: s, onDrawerCancel: n, ...w }, c) => {
17
+ const l = (e) => {
18
+ t?.(e), r?.(!0);
19
+ }, D = (e) => {
20
+ s?.(e), r?.(!1);
21
+ }, d = (e) => {
22
+ n?.(e), r?.(!1);
23
+ };
24
+ return /* @__PURE__ */ a.jsx(
25
+ p,
26
+ {
27
+ ref: c,
28
+ onDrawerOpen: l,
29
+ onDrawerClose: D,
30
+ onDrawerCancel: d,
31
+ ...w
32
+ }
33
+ );
34
+ }
35
+ );
36
+ f.displayName = "ReactDrawer";
37
+ const C = ({ children: r }) => /* @__PURE__ */ a.jsx("div", { slot: "header", children: r }), v = ({ children: r }) => /* @__PURE__ */ a.jsx("div", { slot: "footer", children: r });
16
38
  export {
17
- p as DrawerFooter,
18
- i as DrawerHeader,
19
- w as ReactDrawer
39
+ v as DrawerFooter,
40
+ C as DrawerHeader,
41
+ f as ReactDrawer
20
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agnosticui-core",
3
- "version": "2.0.0-alpha.22",
3
+ "version": "2.0.0-alpha.23",
4
4
  "author": "AgnosticUI",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -9,12 +9,26 @@ import {
9
9
  } from '../core/Drawer';
10
10
 
11
11
  /**
12
- * React-specific props for Drawer
12
+ * React-specific props for Drawer.
13
+ *
14
+ * Includes onOpenChange for controlled-component support. This is necessary
15
+ * because the underlying Lit web component manages its own open state internally
16
+ * (e.g. it sets this.open = false on Escape or backdrop click). @lit/react's
17
+ * createComponent only bridges DOM events -> React props, so without explicitly
18
+ * calling onOpenChange(false) on close/cancel, React's state never learns the
19
+ * drawer closed. The stale open={true} is then re-applied on the next render,
20
+ * causing previously dismissed drawers to reappear when other drawers are opened.
13
21
  */
14
22
  export interface ReactDrawerProps extends DrawerProps {
15
23
  children?: React.ReactNode;
16
24
  className?: string;
17
25
  id?: string;
26
+ /**
27
+ * Called with the new open state whenever the drawer opens or closes.
28
+ * Wire this to your React state setter (e.g. onOpenChange={setIsOpen}) so
29
+ * React stays in sync when the drawer closes itself internally.
30
+ */
31
+ onOpenChange?: (open: boolean) => void;
18
32
  }
19
33
 
20
34
  /**
@@ -31,8 +45,9 @@ export interface DrawerFooterProps {
31
45
  children?: React.ReactNode;
32
46
  }
33
47
 
34
- // Create Drawer component with @lit/react
35
- export const ReactDrawer = createComponent({
48
+ // Raw @lit/react bridge — maps Lit custom events to React prop callbacks.
49
+ // Does NOT handle onOpenChange; that requires the wrapper below.
50
+ const _ReactDrawerBase = createComponent({
36
51
  tagName: 'ag-drawer',
37
52
  elementClass: AgnosticDrawer,
38
53
  react: React,
@@ -43,6 +58,48 @@ export const ReactDrawer = createComponent({
43
58
  },
44
59
  });
45
60
 
61
+ /**
62
+ * ReactDrawer wraps _ReactDrawerBase to add onOpenChange support.
63
+ *
64
+ * The Lit element fires "drawer-close" when the close button is clicked and
65
+ * "drawer-cancel" when the user presses Escape or clicks the backdrop. Both
66
+ * mean the drawer is now closed. We intercept those two events and call
67
+ * onOpenChange(false) so React state reflects the new closed state immediately,
68
+ * preventing the stale open={true} from being pushed back into the element on
69
+ * the next render.
70
+ */
71
+ export const ReactDrawer = React.forwardRef<AgnosticDrawer, ReactDrawerProps>(
72
+ ({ onOpenChange, onDrawerOpen, onDrawerClose, onDrawerCancel, ...props }, ref) => {
73
+ const handleDrawerOpen = (event: DrawerOpenEvent) => {
74
+ onDrawerOpen?.(event);
75
+ onOpenChange?.(true);
76
+ };
77
+
78
+ // Both close and cancel mean the drawer is no longer open — notify React.
79
+ const handleDrawerClose = (event: DrawerCloseEvent) => {
80
+ onDrawerClose?.(event);
81
+ onOpenChange?.(false);
82
+ };
83
+
84
+ const handleDrawerCancel = (event: DrawerCancelEvent) => {
85
+ onDrawerCancel?.(event);
86
+ onOpenChange?.(false);
87
+ };
88
+
89
+ return (
90
+ <_ReactDrawerBase
91
+ ref={ref}
92
+ onDrawerOpen={handleDrawerOpen}
93
+ onDrawerClose={handleDrawerClose}
94
+ onDrawerCancel={handleDrawerCancel}
95
+ {...props}
96
+ />
97
+ );
98
+ }
99
+ );
100
+
101
+ ReactDrawer.displayName = 'ReactDrawer';
102
+
46
103
  // Helper components for slots (simple React components)
47
104
  export const DrawerHeader: React.FC<DrawerHeaderProps> = ({ children }) => {
48
105
  return <div slot="header">{children}</div>;