ados-rcm 1.0.85 → 1.0.86

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,12 +1,19 @@
1
1
  import React from 'react';
2
+ import { TUseValues } from '../../AHooks/useValues';
2
3
  import { Resources } from '../AResource/AResource';
3
- import { IAEvent, TActionRef } from '../ATypes/ATypes';
4
+ import { IAEvent } from '../ATypes/ATypes';
4
5
  /**
5
6
  * onOk와 ok의 네이밍 차이 : 해당 function이 Action임을 정의하는 기준을 고찰.
6
7
  * onAction은 callback으로 action이 수행될 때 호출된다. 따라서 기본적으로 onAction을 호출하는 곳은 action 한 곳 뿐이다.
7
8
  * 이와 다르게 action은 여러 곳에서 해당 action을 수행하고 싶을 때 호출할 수 있다. 만약 한 곳에서만 action을 호출하는 상황이라면 onAction을 사용하도록 한다.
8
9
  */
9
- export interface IADialogActions {
10
+ export interface IADialogAction {
11
+ /**
12
+ * open : () => void
13
+ *
14
+ * Description : open dialog
15
+ */
16
+ open: () => void;
10
17
  /**
11
18
  * close : () => void
12
19
  *
@@ -30,13 +37,17 @@ export interface IADialogChildren {
30
37
  children?: React.ReactNode;
31
38
  }
32
39
  export type TADialogTypes = 'okCancel' | 'cancelOk' | 'ok' | 'cancel' | 'none';
40
+ export type TADialogContext<P> = (props: P) => {
41
+ children: JSX.Element;
42
+ isOkDisabled: boolean;
43
+ };
33
44
  export interface IADialogProps {
34
45
  /**
35
- * dlgState : IADialogState
46
+ * dlgCore : IADialogCore
36
47
  *
37
- * Description : setOpen of the dialog. it is used when the dialog is closed.
48
+ * Description : core of the dialog
38
49
  */
39
- dlgState: IADialogState;
50
+ dlgCore: IADialogCore;
40
51
  /**
41
52
  * type? : TADialogTypes = 'okCancel'
42
53
  *
@@ -49,12 +60,6 @@ export interface IADialogProps {
49
60
  * Description : title of the dialog
50
61
  */
51
62
  title?: React.ReactNode;
52
- /**
53
- * actionRef? : TActionRef<IADialogActions>
54
- *
55
- * Description : actionRef of the dialog
56
- */
57
- actionRef?: TActionRef<IADialogActions>;
58
63
  /**
59
64
  * children? : React.ReactNode
60
65
  *
@@ -164,71 +169,85 @@ export interface IADialogProps {
164
169
  * Description : ADialog is a dialog component.
165
170
  *
166
171
  *
167
- * Basic Usage :
172
+ * Basic Usage : You should use 'createADialog' and 'ADialog' to make dialog component,
173
+ * and manage it with 'useADialogCore(s)'.
168
174
  *
169
- * const dlgState = useDialogState();
170
- * const onOk = () => { console.log('ok') }
171
- * const onCancel = (e : IAEvent) => {
172
- * e.event.preventDefault(); // this prevents the dialog from closing.
173
- * console.log('cancel')
174
- * }
175
+ * const DTest = createADialog((props: { dlgCore: IADialogCore }) => {
176
+ * const { dlgCore } = props;
177
+ * const onOk = () => console.log('ok')
178
+ * const onCancel = () => console.log('cancel')
175
179
  *
176
- * if (case 1)
177
- * <>
178
- * <ADialogFrame dlgState={dlgState}>
179
- * <ADialog dlgState={dlgState}
180
+ * return (
181
+ * <ADialog dlgCore={dlgCore}
180
182
  * title='Dialog Title'
181
183
  * onOk={onOk}
182
184
  * onCancel={onCancel}>
183
185
  * <div>Content</div>
186
+ * <AButton onClick={dlgCore.action.close}>close</AButton>
184
187
  * </ADialog>
185
- * </ADialogFrame>
186
- * <AButton onClick={dlgState.open}>Open Dialog</AButton>
187
- * </>
188
+ * );
189
+ * });
188
190
  *
189
- * if (case 2)
190
- * <ADialogFrame dlgState={dlgState}>
191
- * <DTest dlgState={dlgState}
192
- * onOk={onOk}
193
- * onCancel={onCancel}>
194
- * </DTest>
195
- * </ADialogFrame>
191
+ * if (case 1)
192
+ * const CallerComponent = () => {
193
+ * const dlgCore = useADialogCore();
194
+ * return (
195
+ * <div>
196
+ * <AButton onClick={dlgCore.action.open}>Open Dialog</AButton>
197
+ * <DTest dlgCore={dlgCore}/>
198
+ * </div>
199
+ * )
196
200
  *
197
- * const DTest = (props: IADialogProps) => {
198
- * let { dlgState, onOk, onCancel } = props;
199
- * const [num, setNum] = useState(0);
200
- * return (
201
- * <ADialog dlgState={dlgState}
202
- * title='Dialog Title'
203
- * onOk={onOk}
204
- * onCancel={onCancel}>
205
- * {num}
206
- * <AButton onClick={() => setNum(num + 1)}>Add</AButton>
207
- * <AButton onClick={() => setNum(num - 1)}>Sub</AButton>
208
- * </ADialog>
209
- * )
210
- * }
201
+ * if (case 2)
202
+ * const CallerComponent = () => {
203
+ * const dlgCores = useADialogCores('dlg1');
204
+ * return (
205
+ * <div>
206
+ * some contents
207
+ * <AButton onClick={dlgCores.dlg1.action.open}>Open Dialog</AButton>
208
+ * <DTest dlgState={dlgCores.dlg1}/>
209
+ * </div>
210
+ * );
211
+ * }
211
212
  *
212
213
  */
213
214
  export declare const ADialog: (props: IADialogProps) => React.ReactPortal;
214
215
  export interface IADialogState {
215
- isOpen: boolean;
216
- setIsOpen: (isOpen: boolean) => void;
217
- open: () => void;
218
- onClose: () => void;
216
+ /**
217
+ * useIsOpen : [boolean, (isOpen: boolean) => void]
218
+ *
219
+ * Description : [ASystem] use should not modify this property.
220
+ */
221
+ useIsOpen: TUseValues<boolean>;
222
+ /**
223
+ * setAction : (action: Partial<IADialogAction>) => void
224
+ *
225
+ * Description : set action of the dialog
226
+ */
227
+ setAction: (action: Partial<IADialogAction>) => void;
219
228
  }
220
- export declare const useADialogState: () => IADialogState;
221
- export interface IADialogFrameProps {
229
+ export type TADialogCores<T extends string> = {
230
+ [key in T]: IADialogCore;
231
+ };
232
+ export interface IADialogCore {
222
233
  /**
223
- * dlgState : IADialogState
234
+ * state : IADialogState
224
235
  *
225
- * Description : isOpen of the dialog. you can 'open' using this.
226
- * you can 'close' using actionRef. not this.
236
+ * Description : [ASystem] use should not modify this property.
227
237
  */
228
- dlgState: IADialogState;
238
+ state: IADialogState;
229
239
  /**
230
- * children : React.ReactElement
240
+ * action : IADialogAction
241
+ *
242
+ * Description : action of the dialog
231
243
  */
232
- children: React.ReactElement;
244
+ action: IADialogAction;
233
245
  }
234
- export declare const ADialogFrame: (props: IADialogFrameProps) => import("react/jsx-runtime").JSX.Element;
246
+ export type TADialogActions<T extends string> = {
247
+ [key in T]: IADialogAction;
248
+ };
249
+ export declare const useADialogCores: <T extends string>(...dlgNames: T[]) => TADialogCores<T>;
250
+ export declare const useADialogCore: () => IADialogCore;
251
+ export declare const createADialog: <P extends {
252
+ dlgCore: IADialogCore;
253
+ }>(Builder: (props: P) => JSX.Element) => (props: P) => import("react/jsx-runtime").JSX.Element;