@@ -9,113 +9,31 @@ import { showLoaderBar, hideLoaderBar } from "../states/loader-bar";
99import {
1010 showNoticeNotification ,
1111 addNotificationWithLevel ,
12- AddNotificationOptions ,
1312} from "../states/notifications" ;
1413import {
1514 ValidatedHtmlInputElement ,
1615 ValidationOptions ,
1716} from "./input-validation" ;
1817import { ElementWithUtils , qsr } from "../utils/dom" ;
18+ import { ValidationResult } from "../types/validation" ;
1919import {
20- IsValidResponse ,
21- Validation ,
22- ValidationResult ,
23- } from "../types/validation " ;
20+ SimpleModalConfig ,
21+ SimpleModalInput ,
22+ ExecReturn as BaseExecReturn ,
23+ } from "../states/simple-modal " ;
2424
2525const simpleModalEl = qsr < HTMLDialogElement > ( "#simpleModal" ) ;
2626
27- type CommonInput < TType , TValue > = {
28- type : TType ;
29- initVal ?: TValue ;
30- placeholder ?: string ;
31- hidden ?: boolean ;
32- disabled ?: boolean ;
33- optional ?: boolean ;
34- label ?: string ;
35- oninput ?: ( event : Event ) => void ;
36- /**
37- * Validate the input value and indicate the validation result next to the input.
38- * If the schema is defined it is always checked first.
39- * Only if the schema validaton is passed or missing the `isValid` method is called.
40- */
41- validation ?: Omit < Validation < string > , "isValid" > & {
42- /**
43- * Custom async validation method.
44- * This is intended to be used for validations that cannot be handled with a Zod schema like server-side validations.
45- * @param value current input value
46- * @param thisPopup the current modal
47- * @returns true if the `value` is valid, an errorMessage as string if it is invalid.
48- */
49- isValid ?: (
50- value : string ,
51- thisPopup : SimpleModal ,
52- ) => Promise < IsValidResponse > ;
53- } ;
54- } ;
55-
56- export type TextInput = CommonInput < "text" , string > ;
57- export type TextArea = CommonInput < "textarea" , string > ;
58- export type PasswordInput = CommonInput < "password" , string > ;
59- type EmailInput = CommonInput < "email" , string > ;
60-
61- type RangeInput = {
62- min : number ;
63- max : number ;
64- step ?: number ;
65- } & CommonInput < "range" , number > ;
66-
67- type DateTimeInput = {
68- min ?: Date ;
69- max ?: Date ;
70- } & CommonInput < "datetime-local" , Date > ;
71- type DateInput = {
72- min ?: Date ;
73- max ?: Date ;
74- } & CommonInput < "date" , Date > ;
75-
76- type CheckboxInput = {
77- label : string ;
78- placeholder ?: never ;
79- description ?: string ;
80- } & CommonInput < "checkbox" , boolean > ;
81-
82- type NumberInput = {
83- min ?: number ;
84- max ?: number ;
85- } & CommonInput < "number" , number > ;
86-
87- type CommonInputType =
88- | TextInput
89- | TextArea
90- | PasswordInput
91- | EmailInput
92- | RangeInput
93- | DateTimeInput
94- | DateInput
95- | CheckboxInput
96- | NumberInput ;
97-
98- export type ExecReturn = {
99- status : "success" | "notice" | "error" ;
100- message : string ;
101- showNotification ?: false ;
102- notificationOptions ?: AddNotificationOptions ;
27+ export type ExecReturn = BaseExecReturn & {
10328 hideOptions ?: HideOptions ;
104- afterHide ?: ( ) => void ;
105- alwaysHide ?: boolean ;
10629} ;
10730
108- type FormInput = CommonInputType & {
31+ type FormInput = SimpleModalInput & {
10932 hasError ?: boolean ;
11033 currentValue : ( ) => string ;
11134} ;
112- type SimpleModalOptions = {
35+ type SimpleModalOptions = Omit < SimpleModalConfig , "execFn" > & {
11336 id : string ;
114- title : string ;
115- inputs ?: CommonInputType [ ] ;
116- text ?: string ;
117- textAllowHtml ?: boolean ;
118- buttonText : string ;
11937 execFn : ( thisPopup : SimpleModal , ...params : string [ ] ) => Promise < ExecReturn > ;
12038 beforeInitFn ?: ( thisPopup : SimpleModal ) => void ;
12139 beforeShowFn ?: ( thisPopup : SimpleModal ) => void ;
@@ -135,7 +53,7 @@ export class SimpleModal {
13553 inputs : FormInput [ ] ;
13654 text ?: string ;
13755 textAllowHtml : boolean ;
138- buttonText : string ;
56+ buttonText ? : string ;
13957 execFn : ( thisPopup : SimpleModal , ...params : string [ ] ) => Promise < ExecReturn > ;
14058 beforeInitFn : ( ( thisPopup : SimpleModal ) => void ) | undefined ;
14159 beforeShowFn : ( ( thisPopup : SimpleModal ) => void ) | undefined ;
@@ -183,7 +101,7 @@ export class SimpleModal {
183101
184102 this . initInputs ( ) ;
185103
186- if ( this . buttonText === "" ) {
104+ if ( this . buttonText === "" || this . buttonText === undefined ) {
187105 this . element . qs ( ".submitButton" ) ?. remove ( ) ;
188106 } else {
189107 this . element . qs ( ".submitButton" ) ?. setText ( this . buttonText ) ;
0 commit comments