@overlastic/react 0.8.1 → 0.8.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/dist/index.cjs CHANGED
@@ -18,31 +18,29 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  OverlaysProvider: () => OverlaysProvider,
24
24
  defineOverlay: () => defineOverlay,
25
25
  renderOverlay: () => renderOverlay,
26
- useExtendOverlay: () => useExtendOverlay,
27
- useOverlayHolder: () => useOverlayHolder,
28
- useOverlayInject: () => useOverlayInject
26
+ useDisclosure: () => useDisclosure,
27
+ useOverlay: () => useOverlay
29
28
  });
30
- module.exports = __toCommonJS(src_exports);
29
+ module.exports = __toCommonJS(index_exports);
31
30
 
32
- // src/composable/define.ts
33
- var import_core2 = require("@overlastic/core");
31
+ // src/components/Provider.tsx
34
32
  var import_react2 = require("react");
35
33
 
36
34
  // src/internal/contexts.tsx
37
35
  var import_core = require("@overlastic/core");
38
36
  var import_react = require("react");
39
37
  var ScriptsContext = (0, import_react.createContext)({
40
- reject: import_core.noop,
41
- resolve: import_core.noop,
42
- setVisible: import_core.noop,
38
+ cancel: import_core.noop,
39
+ confirm: import_core.noop,
40
+ change: import_core.noop,
43
41
  vanish: import_core.noop,
44
42
  visible: false,
45
- in_dec: true
43
+ __is_declarative: true
46
44
  });
47
45
  var InstancesContext = (0, import_react.createContext)({});
48
46
  InstancesContext.displayName = "OverlayInstancesContext";
@@ -53,117 +51,114 @@ function defineAnonymousComponent(component) {
53
51
  return { "--": component }["--"];
54
52
  }
55
53
 
54
+ // src/components/Provider.tsx
55
+ var import_jsx_runtime = require("react/jsx-runtime");
56
+ function OverlaysProvider(props) {
57
+ const [instances, setInstances] = (0, import_react2.useState)([]);
58
+ function render(Instance, props2) {
59
+ setInstances((instances2) => [...instances2, { Instance, props: props2 }]);
60
+ }
61
+ function vanish(instance) {
62
+ setInstances((instances2) => [...instances2.filter(({ Instance }) => instance !== Instance)]);
63
+ }
64
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(InstancesContext.Provider, { value: { render, vanish }, children: [
65
+ instances.map(({ Instance, props: props2 }, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Instance, { ...props2 }, index)),
66
+ props.children
67
+ ] });
68
+ }
69
+
56
70
  // src/composable/define.ts
57
- function useExtendOverlay(options = {}) {
58
- const { immediate = true, duration = 0, automatic = true } = options;
59
- const context = (0, import_react2.useContext)(ScriptsContext);
60
- const dec = Reflect.get(context, "in_dec");
61
- const overlay = dec ? useDeclarative(options) : context;
62
- const { setVisible, vanish, deferred } = overlay;
71
+ var import_core2 = require("@overlastic/core");
72
+ var import_react3 = require("react");
73
+ function useDisclosure(options = {}) {
74
+ const { immediate = true, duration = 300, automatic = true } = options;
75
+ const context = (0, import_react3.useContext)(ScriptsContext);
76
+ const isDeclarative = Reflect.get(context, "__is_declarative");
77
+ const overlay = isDeclarative ? useDeclarative(options) : context;
63
78
  async function destroy() {
64
- setVisible(false);
79
+ var _a;
80
+ overlay.change(false);
65
81
  await (0, import_core2.delay)(duration);
66
- vanish == null ? void 0 : vanish();
82
+ (_a = overlay.vanish) == null ? void 0 : _a.call(overlay);
67
83
  return Promise.resolve();
68
84
  }
69
- useMount(() => immediate && setVisible(true));
85
+ useMount(() => immediate && overlay.change(true));
70
86
  useMount(() => {
71
- if (!dec && automatic)
72
- deferred == null ? void 0 : deferred.then(destroy).catch(destroy);
87
+ var _a;
88
+ if (!isDeclarative && automatic)
89
+ (_a = overlay.deferred) == null ? void 0 : _a.then(destroy).catch(destroy);
73
90
  });
74
91
  return overlay;
75
92
  }
76
93
  function useDeclarative(options = {}) {
77
94
  const { props = {}, model = "visible", events = {} } = options;
78
- const { reject = "onReject", resolve = "onResolve" } = events;
79
- const _reject = (value) => {
95
+ const { cancel = "onCancel", confirm = "onConfirm", close = "onClose" } = events;
96
+ const _cancel = (value) => {
80
97
  var _a;
81
- (_a = props[reject]) == null ? void 0 : _a.call(props, value);
98
+ return (_a = props[cancel]) == null ? void 0 : _a.call(props, value);
82
99
  };
83
- const _resolve = (value) => {
100
+ const _confirm = (value) => {
84
101
  var _a;
85
- (_a = props[resolve]) == null ? void 0 : _a.call(props, value);
102
+ return (_a = props[confirm]) == null ? void 0 : _a.call(props, value);
103
+ };
104
+ const _close = (value) => {
105
+ var _a;
106
+ return (_a = props[close]) == null ? void 0 : _a.call(props, value);
86
107
  };
87
108
  return {
88
- reject: _reject,
89
- resolve: _resolve,
109
+ cancel: _cancel,
110
+ confirm: _confirm,
111
+ close: _close,
90
112
  visible: props[model],
91
113
  vanish: import_core2.noop,
92
- setVisible: import_core2.noop,
114
+ change: import_core2.noop,
93
115
  deferred: void 0
94
116
  };
95
117
  }
96
118
  function useMount(callback = import_core2.noop) {
97
- (0, import_react2.useEffect)(() => callback(), []);
119
+ (0, import_react3.useEffect)(() => callback(), []);
98
120
  }
99
121
 
100
- // src/composable/scripts.ts
101
- var import_react3 = require("react");
102
- function useScripts(options) {
103
- const { reject: _reject } = options.deferred || {};
122
+ // src/composable/utils/index.ts
123
+ var import_core3 = require("@overlastic/core");
124
+ var import_react4 = require("react");
125
+ function createScripts(options) {
126
+ const { cancel: _cancel } = options.deferred || {};
104
127
  const { vanish: _vanish } = options;
105
- const [visible, setVisible] = (0, import_react3.useState)(false);
128
+ const [visible, change] = (0, import_react4.useState)(false);
106
129
  function vanish() {
107
130
  _vanish == null ? void 0 : _vanish();
108
- _reject == null ? void 0 : _reject();
131
+ _cancel == null ? void 0 : _cancel();
109
132
  }
110
133
  return {
111
- resolve: options.deferred.resolve,
112
- reject: options.deferred.reject,
134
+ confirm: options.deferred.confirm,
135
+ cancel: options.deferred.cancel,
136
+ close: () => options.deferred.confirm(),
113
137
  deferred: options.deferred,
114
- setVisible,
138
+ change,
115
139
  visible,
116
140
  vanish
117
141
  };
118
142
  }
119
-
120
- // src/composable/holder.tsx
121
- var import_core3 = require("@overlastic/core");
122
- var import_pascal_case = require("pascal-case");
123
- var import_react4 = require("react");
124
- var import_react_dom = require("react-dom");
125
- var import_jsx_runtime = require("react/jsx-runtime");
126
- function useOverlayHolder(component, options = {}) {
127
- const { callback, scripts, props, refresh } = useRefreshMetadata();
128
- const name = (0, import_core3.defineName)(options.id, options.autoIncrement);
129
- function render() {
130
- const root = options.root || (typeof document !== "undefined" ? document.body : void 0);
131
- const Comp = component;
132
- const content = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { id: name, children: [
133
- " ",
134
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Comp, { ...props }),
135
- " "
136
- ] });
137
- return options.root !== false && root ? (0, import_react_dom.createPortal)(content, root) : content;
138
- }
139
- const holder = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
140
- ScriptsContext.Provider,
141
- {
142
- value: scripts,
143
- ...{ id: (0, import_pascal_case.pascalCase)(name) },
144
- children: refresh ? render() : null
145
- }
146
- );
147
- return [holder, callback];
148
- }
149
- function useRefreshMetadata() {
143
+ function createRefreshMetadata() {
150
144
  const [props, setProps] = (0, import_react4.useState)();
151
145
  const [refresh, setRefresh] = (0, import_react4.useState)(false);
152
- const [visible, setVisible] = (0, import_react4.useState)(false);
146
+ const [visible, change] = (0, import_react4.useState)(false);
153
147
  const deferred = (0, import_react4.useRef)({});
154
148
  const scripts = {
155
149
  deferred: deferred.current,
156
- resolve: deferred.current.resolve,
157
- reject: deferred.current.reject,
150
+ confirm: deferred.current.confirm,
151
+ cancel: deferred.current.cancel,
152
+ close: () => deferred.current.confirm(),
158
153
  vanish,
159
154
  visible,
160
- setVisible
155
+ change
161
156
  };
162
157
  function vanish() {
163
158
  var _a;
164
159
  setRefresh(false);
165
160
  setProps({});
166
- (_a = scripts.reject) == null ? void 0 : _a.call(scripts);
161
+ (_a = scripts.cancel) == null ? void 0 : _a.call(scripts);
167
162
  }
168
163
  async function callback(props2) {
169
164
  deferred.current = (0, import_core3.createDeferred)();
@@ -174,38 +169,64 @@ function useRefreshMetadata() {
174
169
  return { callback, scripts, props, refresh };
175
170
  }
176
171
 
177
- // src/composable/inject.tsx
172
+ // src/composable/overlay.tsx
178
173
  var import_core4 = require("@overlastic/core");
174
+ var import_pascal_case = require("pascal-case");
179
175
  var import_react5 = require("react");
180
- var import_pascal_case2 = require("pascal-case");
176
+ var import_react_dom = require("react-dom");
181
177
  var import_jsx_runtime2 = require("react/jsx-runtime");
182
- var { define } = (0, import_core4.createConstructor)((Instance, props, options) => {
183
- const { id, deferred, render, vanish: _vanish } = options;
184
- const InstanceWithProvider = defineAnonymousComponent(() => {
185
- const content = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
186
- ScriptsContext.Provider,
187
- {
188
- value: useScripts({ deferred, vanish }),
189
- ...{ id: (0, import_pascal_case2.pascalCase)(id) },
190
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Instance, { ...props })
191
- }
192
- );
193
- return content;
194
- });
195
- function vanish() {
196
- _vanish(InstanceWithProvider);
178
+ var { define: defineInject } = (0, import_core4.createConstructor)(
179
+ (Instance, props, options) => {
180
+ const { id, deferred, render, vanish: _vanish } = options;
181
+ const InstanceWithProvider = defineAnonymousComponent(() => {
182
+ const content = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
183
+ ScriptsContext.Provider,
184
+ {
185
+ value: createScripts({ deferred, vanish }),
186
+ ...{ id: (0, import_pascal_case.pascalCase)(id) },
187
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Instance, { ...props })
188
+ }
189
+ );
190
+ return content;
191
+ });
192
+ function vanish() {
193
+ _vanish(InstanceWithProvider);
194
+ }
195
+ render(InstanceWithProvider, props);
196
+ },
197
+ { container: false }
198
+ );
199
+ function defineHolder(component, options = {}) {
200
+ const { callback, scripts, props, refresh } = createRefreshMetadata();
201
+ const name = (0, import_core4.defineName)(options.id, options.autoIncrement);
202
+ function render() {
203
+ const root = options.root || (typeof document !== "undefined" ? document.body : void 0);
204
+ const Comp = component;
205
+ const content = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { id: name, children: [
206
+ " ",
207
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Comp, { ...props }),
208
+ " "
209
+ ] });
210
+ return options.root !== false && root ? (0, import_react_dom.createPortal)(content, root) : content;
211
+ }
212
+ const holder = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ScriptsContext.Provider, { value: scripts, ...{ id: (0, import_pascal_case.pascalCase)(name) }, children: refresh ? render() : null });
213
+ return [holder, callback];
214
+ }
215
+ function useOverlay(Instance, options = {}) {
216
+ const { type = "inject" } = options != null ? options : {};
217
+ if (type === "inject") {
218
+ const { render, vanish } = (0, import_react5.useContext)(InstancesContext);
219
+ return defineInject(Instance, { render, vanish });
220
+ }
221
+ if (type === "holder") {
222
+ return defineHolder(Instance, options);
197
223
  }
198
- render(InstanceWithProvider, props);
199
- }, { container: false });
200
- function useOverlayInject(Instance) {
201
- const { render, vanish } = (0, import_react5.useContext)(InstancesContext);
202
- return define(Instance, { render, vanish });
203
224
  }
204
225
 
205
226
  // src/define/constructor.tsx
206
227
  var import_core5 = require("@overlastic/core");
228
+ var import_pascal_case2 = require("pascal-case");
207
229
  var import_client = require("react-dom/client");
208
- var import_pascal_case3 = require("pascal-case");
209
230
  var import_jsx_runtime3 = require("react/jsx-runtime");
210
231
  var constructor = (0, import_core5.createConstructor)((Instance, props, options) => {
211
232
  const { container, id, deferred } = options;
@@ -214,8 +235,8 @@ var constructor = (0, import_core5.createConstructor)((Instance, props, options)
214
235
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
215
236
  ScriptsContext.Provider,
216
237
  {
217
- value: useScripts({ deferred, vanish }),
218
- ...{ id: (0, import_pascal_case3.pascalCase)(id) },
238
+ value: createScripts({ deferred, vanish }),
239
+ ...{ id: (0, import_pascal_case2.pascalCase)(id) },
219
240
  children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Instance, { ...props })
220
241
  }
221
242
  );
@@ -233,29 +254,11 @@ var constructor = (0, import_core5.createConstructor)((Instance, props, options)
233
254
  // src/define/index.ts
234
255
  var defineOverlay = constructor.define;
235
256
  var renderOverlay = constructor.render;
236
-
237
- // src/components/Provider.tsx
238
- var import_react6 = require("react");
239
- var import_jsx_runtime4 = require("react/jsx-runtime");
240
- function OverlaysProvider(props) {
241
- const [instances, setInstances] = (0, import_react6.useState)([]);
242
- function render(Instance, props2) {
243
- setInstances((instances2) => [...instances2, { Instance, props: props2 }]);
244
- }
245
- function vanish(instance) {
246
- setInstances((instances2) => [...instances2.filter(({ Instance }) => instance !== Instance)]);
247
- }
248
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(InstancesContext.Provider, { value: { render, vanish }, children: [
249
- instances.map(({ Instance, props: props2 }, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Instance, { ...props2 }, index)),
250
- props.children
251
- ] });
252
- }
253
257
  // Annotate the CommonJS export names for ESM import in node:
254
258
  0 && (module.exports = {
255
259
  OverlaysProvider,
256
260
  defineOverlay,
257
261
  renderOverlay,
258
- useExtendOverlay,
259
- useOverlayHolder,
260
- useOverlayInject
262
+ useDisclosure,
263
+ useOverlay
261
264
  });
package/dist/index.d.cts CHANGED
@@ -1,30 +1,34 @@
1
- import { Dispatch, SetStateAction, FC, PropsWithChildren } from 'react';
2
- import * as _overlastic_core from '@overlastic/core';
3
- import { ImperativeOverlay, MountOptions } from '@overlastic/core';
4
- import { GlobalMountOptions } from '@vue/test-utils/dist/types';
5
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { PropsWithChildren, Dispatch, SetStateAction, FC } from 'react';
3
+ import { MountOptions, ImperativeOverlay, GlobalMountOptions } from '@overlastic/core';
6
4
 
7
- type PropsWidthOverlays<P = unknown> = P & {
5
+ declare function OverlaysProvider(props: PropsWithChildren): react_jsx_runtime.JSX.Element;
6
+
7
+ type PropsWithOverlays<P = unknown, V = void> = P & {
8
8
  visible?: boolean;
9
- onReject?: (value: any) => void;
10
- onResolve?: (value: any) => void;
9
+ onCancel?: (value: any) => void;
10
+ onConfirm?: (value: V) => void;
11
11
  };
12
12
 
13
13
  interface PromptifyEvents {
14
14
  /**
15
- * reject event name used by the template
15
+ * confirm event name used by the template
16
+ */
17
+ close?: string;
18
+ /**
19
+ * cancel event name used by the template
16
20
  *
17
- * @default 'onReject'
21
+ * @default 'onCancel'
18
22
  */
19
- reject?: string;
23
+ cancel?: string;
20
24
  /**
21
- * resolve event name used by the template
25
+ * confirm event name used by the template
22
26
  *
23
- * @default 'onResolve'
27
+ * @default 'onConfirm'
24
28
  */
25
- resolve?: string;
29
+ confirm?: string;
26
30
  }
27
- interface ExtendOverlayOptions {
31
+ interface UseDisclosureOptions {
28
32
  /** animation duration to avoid premature destruction of components */
29
33
  duration?: number;
30
34
  /** whether to set visible to true immediately */
@@ -32,7 +36,7 @@ interface ExtendOverlayOptions {
32
36
  /**
33
37
  * pass in the required props on jsx
34
38
  */
35
- props?: PropsWidthOverlays;
39
+ props?: PropsWithOverlays;
36
40
  /**
37
41
  * fields used by jsx show
38
42
  *
@@ -50,34 +54,34 @@ interface ExtendOverlayOptions {
50
54
  */
51
55
  automatic?: boolean;
52
56
  }
53
- interface ExtendOverlayReturn {
54
- /** the notification reject, modify visible, and destroy it after the duration ends */
55
- reject: (reason?: any) => void;
56
- /** the notification resolve, modify visible, and destroy it after the duration ends */
57
- resolve: (value?: any) => void;
57
+ interface UseDisclosureReturn {
58
+ /** the notification cancel(reason), modify visible, and destroy it after the duration ends */
59
+ cancel: (reason?: any) => void;
60
+ /** the notification confirm(value), modify visible, and destroy it after the duration ends */
61
+ confirm: (value?: any) => void;
62
+ /** the notification confirm(void), modify visible, and destroy it after the duration ends */
63
+ close: () => void;
58
64
  /** destroy the current instance (immediately) */
59
65
  vanish: () => void;
60
66
  /** visible control popup display and hide */
61
67
  visible: boolean;
62
68
  /** visible dispatch change */
63
- setVisible: Dispatch<SetStateAction<boolean>>;
69
+ change: Dispatch<SetStateAction<boolean>>;
64
70
  /** current deferred */
65
71
  deferred?: Promise<any>;
66
72
  }
67
- declare function useExtendOverlay(options?: ExtendOverlayOptions): ExtendOverlayReturn;
73
+ declare function useDisclosure(options?: UseDisclosureOptions): UseDisclosureReturn;
68
74
 
69
- type InjectionHolder<Props, Resolved> = [JSX.Element, ImperativeOverlay<Props, Resolved>];
70
- declare function useOverlayHolder<Props, Resolved = void>(component: FC<Props>, options?: MountOptions): InjectionHolder<Props, Resolved>;
71
-
72
- interface Options {
73
- render: (instance: FC, props: any) => void;
74
- vanish: (instance: FC) => void;
75
- }
76
- declare function useOverlayInject<Props, Resolved>(Instance: FC<Props>): _overlastic_core.ImperativeOverlay<Props, Resolved, Options>;
75
+ type ExtractProps<P> = Omit<P, `on${string}` | 'visible'>;
76
+ type ExtractEvent<P extends Record<string, any>> = Parameters<Required<P>['onConfirm']>[0];
77
+ declare function useOverlay<Props extends Record<string, any>, Resolved = ExtractEvent<Props>>(Instance: FC<Props>, options?: MountOptions<{
78
+ type?: 'inject';
79
+ }>): ImperativeOverlay<ExtractProps<Props>, Resolved>;
80
+ declare function useOverlay<Props extends Record<string, any>, Resolved = ExtractEvent<Props>>(Instance: FC<Props>, options?: MountOptions<{
81
+ type?: 'holder';
82
+ }>): [JSX.Element, ImperativeOverlay<ExtractProps<Props>, Resolved>];
77
83
 
78
84
  declare const defineOverlay: <Props, Resolved = void>(instance: React.FC<Props>, options?: GlobalMountOptions | undefined) => ImperativeOverlay<Props, Resolved, unknown>;
79
85
  declare const renderOverlay: <Props, Resolved = void>(instance: React.FC<Props>, props?: Props | undefined, options?: GlobalMountOptions | undefined) => Promise<Resolved>;
80
86
 
81
- declare function OverlaysProvider(props: PropsWithChildren): react_jsx_runtime.JSX.Element;
82
-
83
- export { type ExtendOverlayOptions, type ExtendOverlayReturn, type InjectionHolder, OverlaysProvider, type PropsWidthOverlays, defineOverlay, renderOverlay, useExtendOverlay, useOverlayHolder, useOverlayInject };
87
+ export { OverlaysProvider, type PropsWithOverlays, type UseDisclosureOptions, type UseDisclosureReturn, defineOverlay, renderOverlay, useDisclosure, useOverlay };
package/dist/index.d.ts CHANGED
@@ -1,30 +1,34 @@
1
- import { Dispatch, SetStateAction, FC, PropsWithChildren } from 'react';
2
- import * as _overlastic_core from '@overlastic/core';
3
- import { ImperativeOverlay, MountOptions } from '@overlastic/core';
4
- import { GlobalMountOptions } from '@vue/test-utils/dist/types';
5
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { PropsWithChildren, Dispatch, SetStateAction, FC } from 'react';
3
+ import { MountOptions, ImperativeOverlay, GlobalMountOptions } from '@overlastic/core';
6
4
 
7
- type PropsWidthOverlays<P = unknown> = P & {
5
+ declare function OverlaysProvider(props: PropsWithChildren): react_jsx_runtime.JSX.Element;
6
+
7
+ type PropsWithOverlays<P = unknown, V = void> = P & {
8
8
  visible?: boolean;
9
- onReject?: (value: any) => void;
10
- onResolve?: (value: any) => void;
9
+ onCancel?: (value: any) => void;
10
+ onConfirm?: (value: V) => void;
11
11
  };
12
12
 
13
13
  interface PromptifyEvents {
14
14
  /**
15
- * reject event name used by the template
15
+ * confirm event name used by the template
16
+ */
17
+ close?: string;
18
+ /**
19
+ * cancel event name used by the template
16
20
  *
17
- * @default 'onReject'
21
+ * @default 'onCancel'
18
22
  */
19
- reject?: string;
23
+ cancel?: string;
20
24
  /**
21
- * resolve event name used by the template
25
+ * confirm event name used by the template
22
26
  *
23
- * @default 'onResolve'
27
+ * @default 'onConfirm'
24
28
  */
25
- resolve?: string;
29
+ confirm?: string;
26
30
  }
27
- interface ExtendOverlayOptions {
31
+ interface UseDisclosureOptions {
28
32
  /** animation duration to avoid premature destruction of components */
29
33
  duration?: number;
30
34
  /** whether to set visible to true immediately */
@@ -32,7 +36,7 @@ interface ExtendOverlayOptions {
32
36
  /**
33
37
  * pass in the required props on jsx
34
38
  */
35
- props?: PropsWidthOverlays;
39
+ props?: PropsWithOverlays;
36
40
  /**
37
41
  * fields used by jsx show
38
42
  *
@@ -50,34 +54,34 @@ interface ExtendOverlayOptions {
50
54
  */
51
55
  automatic?: boolean;
52
56
  }
53
- interface ExtendOverlayReturn {
54
- /** the notification reject, modify visible, and destroy it after the duration ends */
55
- reject: (reason?: any) => void;
56
- /** the notification resolve, modify visible, and destroy it after the duration ends */
57
- resolve: (value?: any) => void;
57
+ interface UseDisclosureReturn {
58
+ /** the notification cancel(reason), modify visible, and destroy it after the duration ends */
59
+ cancel: (reason?: any) => void;
60
+ /** the notification confirm(value), modify visible, and destroy it after the duration ends */
61
+ confirm: (value?: any) => void;
62
+ /** the notification confirm(void), modify visible, and destroy it after the duration ends */
63
+ close: () => void;
58
64
  /** destroy the current instance (immediately) */
59
65
  vanish: () => void;
60
66
  /** visible control popup display and hide */
61
67
  visible: boolean;
62
68
  /** visible dispatch change */
63
- setVisible: Dispatch<SetStateAction<boolean>>;
69
+ change: Dispatch<SetStateAction<boolean>>;
64
70
  /** current deferred */
65
71
  deferred?: Promise<any>;
66
72
  }
67
- declare function useExtendOverlay(options?: ExtendOverlayOptions): ExtendOverlayReturn;
73
+ declare function useDisclosure(options?: UseDisclosureOptions): UseDisclosureReturn;
68
74
 
69
- type InjectionHolder<Props, Resolved> = [JSX.Element, ImperativeOverlay<Props, Resolved>];
70
- declare function useOverlayHolder<Props, Resolved = void>(component: FC<Props>, options?: MountOptions): InjectionHolder<Props, Resolved>;
71
-
72
- interface Options {
73
- render: (instance: FC, props: any) => void;
74
- vanish: (instance: FC) => void;
75
- }
76
- declare function useOverlayInject<Props, Resolved>(Instance: FC<Props>): _overlastic_core.ImperativeOverlay<Props, Resolved, Options>;
75
+ type ExtractProps<P> = Omit<P, `on${string}` | 'visible'>;
76
+ type ExtractEvent<P extends Record<string, any>> = Parameters<Required<P>['onConfirm']>[0];
77
+ declare function useOverlay<Props extends Record<string, any>, Resolved = ExtractEvent<Props>>(Instance: FC<Props>, options?: MountOptions<{
78
+ type?: 'inject';
79
+ }>): ImperativeOverlay<ExtractProps<Props>, Resolved>;
80
+ declare function useOverlay<Props extends Record<string, any>, Resolved = ExtractEvent<Props>>(Instance: FC<Props>, options?: MountOptions<{
81
+ type?: 'holder';
82
+ }>): [JSX.Element, ImperativeOverlay<ExtractProps<Props>, Resolved>];
77
83
 
78
84
  declare const defineOverlay: <Props, Resolved = void>(instance: React.FC<Props>, options?: GlobalMountOptions | undefined) => ImperativeOverlay<Props, Resolved, unknown>;
79
85
  declare const renderOverlay: <Props, Resolved = void>(instance: React.FC<Props>, props?: Props | undefined, options?: GlobalMountOptions | undefined) => Promise<Resolved>;
80
86
 
81
- declare function OverlaysProvider(props: PropsWithChildren): react_jsx_runtime.JSX.Element;
82
-
83
- export { type ExtendOverlayOptions, type ExtendOverlayReturn, type InjectionHolder, OverlaysProvider, type PropsWidthOverlays, defineOverlay, renderOverlay, useExtendOverlay, useOverlayHolder, useOverlayInject };
87
+ export { OverlaysProvider, type PropsWithOverlays, type UseDisclosureOptions, type UseDisclosureReturn, defineOverlay, renderOverlay, useDisclosure, useOverlay };