-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathct-dialog-builder.ts
More file actions
182 lines (158 loc) · 5.08 KB
/
ct-dialog-builder.ts
File metadata and controls
182 lines (158 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import { TemplateResult } from "lit";
import { CtDialog } from "./ct-dialog.js";
/**
* ## CtDialogBuilder
* A builder class for creating and configuring dialogs with various components.
*
* This class provides a fluent API for building dialogs with headers, buttons,
* content, and lists, similar to Material Design dialog patterns.
*
* ### Usage
* ```javascript
* import { CtDialogBuilder } from "./ct-dialog.js";
*
* // Create a dialog builder
* const builder = new CtDialogBuilder();
*
* // Configure the dialog
* builder
* .title('Dialog Title')
* .content('This is the dialog content')
* .positiveButton('OK')
* .negativeButton('Cancel')
* .show();
* ```
*/
export default class CtDialogBuilder {
/**
* The dialog instance being configured
*/
dialog: CtDialog;
/**
* Container element where dialog will be attached
*/
cnx!: HTMLElement;
/**
* Reference to the dialog element
*/
dialogType!: HTMLElement;
/**
* Border radius value for the dialog
*/
cornerRadiusValue = 16;
/**
* Creates a new dialog builder
* @param {HTMLElement} cnx - Container element where dialog will be attached (default: document.body)
* @param {CtDialog} dialog - Optional existing dialog instance to configure
*/
constructor(cnx: HTMLElement = document.body, dialog = new CtDialog()) {
this.cnx = cnx;
this.dialog = dialog;
}
// ================================== Header ==================================
/**
* Sets an icon for the dialog header
* @param {string} svg - SVG content for the icon
* @returns {CtDialogBuilder} The builder instance for chaining
*/
icon(svg: string) {}
/**
* Sets the title for the dialog
* @param {string} title - Dialog title text
* @returns {CtDialogBuilder} The builder instance for chaining
*/
title(title: string) {}
// ================================== Button ==================================
/**
* Adds a positive action button (like "OK", "Accept", etc.)
* @param {string} positiveButton - Text for the positive button
* @returns {CtDialogBuilder} The builder instance for chaining
*/
positiveButton(positiveButton: string) {}
/**
* Adds a negative action button (like "Cancel", "No", etc.)
* @param {string} negativeButton - Text for the negative button
* @returns {CtDialogBuilder} The builder instance for chaining
*/
negativeButton(negativeButton: string) {}
/**
* Adds a neutral action button (like "Later", "Remind me", etc.)
* @param {string} neutralButton - Text for the neutral button
* @returns {CtDialogBuilder} The builder instance for chaining
*/
neutralButton(neutralButton: string) {}
// ================================== BODY ==================================
/**
* Sets the content text for the dialog
* @param {string} content - Content text
* @returns {CtDialogBuilder} The builder instance for chaining
*/
content(content: string) {}
// ================= LISTAS =================
/**
* Adds a simple list of items to the dialog
* @param {string[]} items - Array of text items
* @returns {CtDialogBuilder} The builder instance for chaining
*/
listItems(items: string[]) {}
/**
* Adds a single-choice list to the dialog (like radio buttons)
* @param {string[]} items - Array of text items
* @returns {CtDialogBuilder} The builder instance for chaining
*/
listItemsSingleChoice(items: string[]) {}
/**
* Adds a multi-choice list to the dialog (like checkboxes)
* @param {string[]} items - Array of text items
* @returns {CtDialogBuilder} The builder instance for chaining
*/
listItemsMultiChoice(items: string[]) {}
/**
* Adds a custom list with a render function for each item
* @template T The type of items in the list
* @param {T[]} items - Array of items
* @param {function(T, number): TemplateResult} renderItem - Function to render each item
* @returns {CtDialogBuilder} The builder instance for chaining
*/
customListAdapter<T = any>(items: T[], renderItem: (item: T, index: number) => TemplateResult) {}
// ================= View =================
/**
* Shows the dialog
* @returns {CtDialog} The dialog instance
*/
show() {
this.cnx.appendChild(this.dialogType);
}
/**
* Dismisses the dialog
* @returns {CtDialogBuilder} The builder instance for chaining
*/
dismiss() {}
// ================= EVENTS =================
/**
* Registers a callback to be called before the dialog is shown
* @returns {CtDialogBuilder} The builder instance for chaining
*/
onPreShow() {}
/**
* Registers a callback to be called after the dialog is shown
* @returns {CtDialogBuilder} The builder instance for chaining
*/
onPostShow() {}
/**
* Registers a callback to be called when the dialog is dismissed
* @returns {CtDialogBuilder} The builder instance for chaining
*/
onDismiss() {}
// =============== CUSTOM ==========
/**
* Sets the corner radius for the dialog
* @param {number} radius - Corner radius in pixels
* @returns {CtDialogBuilder} The builder instance for chaining
*/
cornerRadius(radius: number) {
this.cornerRadiusValue = radius;
}
}
// @ts-ignore
window.CtDialogBuilder = CtDialogBuilder;