kempo-ui 0.0.8 → 0.0.9

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.
@@ -211,6 +211,7 @@
211
211
  <p>Custom content for the next button. Defaults to a right chevron icon if not provided.</p>
212
212
 
213
213
  </main>
214
+ <div style="height:33vh"></div>
214
215
  <script type="module" src="../src/components/Import.js"></script>
215
216
  <script type="module" src="../src/components/ContentSlider.js"></script>
216
217
  </body>
@@ -22,10 +22,12 @@
22
22
  <a href="#titles">Titles</a><br />
23
23
  <a href="#actionButtons">Action Buttons</a><br />
24
24
  <a href="#jsUsage">JavaScript Usage</a><br />
25
+ <a href="#confirmDialog">Confirm Dialog</a><br />
25
26
 
26
27
  <h6 class="mt">JavaScript Reference</h6>
27
28
  <a href="#constructor">Constructor</a><br />
28
29
  <a href="#requirements">Requirements</a><br />
30
+ <a href="#attributes">Attributes</a><br />
29
31
  <a href="#properties">Properties</a><br />
30
32
  <a href="#methods">Methods</a><br />
31
33
  <a href="#staticMethods">Static Methods</a><br />
@@ -34,7 +36,7 @@
34
36
 
35
37
  <h3 id="basicUsage"><a href="#basicUsage" class="no-link">Basic Usage</a></h3>
36
38
  <p>Create dialogs using the <code>k-dialog</code> component. Open the dialog by calling the <code>open()</code> method, and close it by calling the <code>close()</code> method. Or it can be closed using the dialog's GUI (clicking the overlay, clicking the close button, or the cancel or confirm action buttons).</p>
37
- <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">k-dialog</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"d1"</span>&gt;</span><br /> <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"p"</span>&gt;</span>Hello World<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span><br /><span class="hljs-tag">&lt;/<span class="hljs-name">k-dialog</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"doument.getElementById('d1').open()"</span>&gt;</span>Open Dialog<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></code></pre>
39
+ <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">k-dialog</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"d1"</span>&gt;</span><br /> <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"p"</span>&gt;</span>Hello World<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span><br /><span class="hljs-tag">&lt;/<span class="hljs-name">k-dialog</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"document.getElementById('d1').open()"</span>&gt;</span>Open Dialog<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></code></pre>
38
40
  <button class="openDialog mb" data-dialog="d1" slot="right">Open Dialog</button>
39
41
  <k-dialog id="d1">
40
42
  <p class="p">Hello World</p>
@@ -88,9 +90,239 @@
88
90
 
89
91
  <h3 id="jsUsage"><a href="#jsUsage" class="no-link">JavaScript Usage</a></h3>
90
92
  <h5>Create Dialog</h5>
91
- <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"d7"</span>&gt;</span>Open Dialog<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Dialog <span class="hljs-keyword">from</span> <span class="hljs-string">'/src/components/Dialog.js'</span>;<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'d7'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Dialog.create(<span class="hljs-string">'&lt;p&gt;Hello World&lt;/p&gt;'</span>);<br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
93
+ <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"d7"</span>&gt;</span>Open Dialog<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Dialog <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/components/Dialog.js'</span>;<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'d7'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Dialog.create(<span class="hljs-string">'Hello World'</span>);<br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
92
94
  <button id="d7" class="mb">Open Dialog</button>
93
- <script type="module" src="./init.js"></script>
95
+ <script type="module">
96
+ import Dialog from '../src/components/Dialog.js';
97
+ document.getElementById('d7').addEventListener('click', () => {
98
+ Dialog.create('Hello World');
99
+ });
100
+ </script>
101
+
102
+ <h5>Dialog with Title</h5>
103
+ <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"d7b"</span>&gt;</span>Open Dialog with Title<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Dialog <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/components/Dialog.js'</span>;<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'d7b'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Dialog.create(<span class="hljs-string">'This is the dialog content'</span>, {<br /> <span class="hljs-attr">title</span>: <span class="hljs-string">'My Dialog Title'</span><br /> });<br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
104
+ <button id="d7b" class="mb">Open Dialog with Title</button>
105
+ <script type="module">
106
+ import Dialog from '../src/components/Dialog.js';
107
+ document.getElementById('d7b').addEventListener('click', () => {
108
+ Dialog.create('This is the dialog content', {
109
+ title: 'My Dialog Title'
110
+ });
111
+ });
112
+ </script>
113
+
114
+ <h5>Error Dialog</h5>
115
+ <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"d8"</span>&gt;</span>Open Dialog<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Dialog <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/components/Dialog.js'</span>;<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'d8'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Dialog.error(<span class="hljs-string">"Oh no, don't do that!"</span>);<br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
116
+ <button id="d8" class="mb">Open Dialog</button>
117
+ <script type="module">
118
+ import Dialog from '../src/components/Dialog.js';
119
+ document.getElementById('d8').addEventListener('click', () => {
120
+ Dialog.error("Oh no, don't do that!");
121
+ });
122
+ </script>
123
+
124
+ <h3 id="confirmDialog"><a href="#confirmDialog" class="no-link">Confirm Dialog</a></h3>
125
+ <p>Use the <code>Dialog.confirm</code> static method to create a confirmation dialog. This method takes a text message, a response callback, and an options object.</p>
126
+ <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"d9"</span>&gt;</span>Open Confirm Dialog<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Dialog <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/components/Dialog.js'</span>;<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'d9'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Dialog.confirm(<span class="hljs-string">"Are you sure you want to proceed?"</span>, <span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> {<br /> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"User response:"</span>, response);<br /> });<br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
127
+ <button id="d9" class="mb">Open Confirm Dialog</button>
128
+ <script type="module">
129
+ import Dialog from '../src/components/Dialog.js';
130
+ document.getElementById('d9').addEventListener('click', () => {
131
+ Dialog.confirm("Are you sure you want to proceed?", response => {
132
+ console.log("User response:", response);
133
+ });
134
+ });
135
+ </script>
136
+
137
+ <h2 id="jsRef">JavaScript Reference</h2>
138
+
139
+ <h3 id="constructor"><a href="#constructor" class="no-link">Constructor</a></h3>
140
+ <h6>Extends <a href="./shadow-component.html">ShadowComponent</a></h6>
141
+ <h5>
142
+ <code>new Dialog()</code><br />
143
+ <code>new Dialog(<i>object</i> options)</code>
144
+ </h5>
145
+
146
+ <h4>Parameters</h4>
147
+ <h5><code>options<i>: object</i></code></h5>
148
+ <p>An object containing the initial configuration for the dialog. The options object can contain the following properties:</p>
149
+ <ul>
150
+ <li><code>opened</code>: <i>boolean</i> - Whether the dialog is initially opened.</li>
151
+ <li><code>closeBtn</code>: <i>boolean</i> - Whether to show the close button.</li>
152
+ <li><code>overlayClose</code>: <i>boolean</i> - Whether clicking the overlay closes the dialog.</li>
153
+ <li><code>confirmText</code>: <i>string</i> - Text for the confirm button.</li>
154
+ <li><code>confirmClasses</code>: <i>string</i> - Classes for the confirm button.</li>
155
+ <li><code>confirmAction</code>: <i>function</i> - Action to perform on confirm.</li>
156
+ <li><code>cancelText</code>: <i>string</i> - Text for the cancel button.</li>
157
+ <li><code>cancelClasses</code>: <i>string</i> - Classes for the cancel button.</li>
158
+ <li><code>cancelAction</code>: <i>function</i> - Action to perform on cancel.</li>
159
+ <li><code>closeCallback</code>: <i>function</i> - Callback to execute when the dialog is closed.</li>
160
+ </ul>
161
+
162
+ <h3 id="requirements"><a href="#requirements" class="no-link">Requirements</a></h3>
163
+ <ul>
164
+ <li><a href="./shadow-component.html">ShadowComponent</a></li>
165
+ <li><a href="./icon.html">Icon</a></li>
166
+ <li><a href="./focus-capture.html">FocusCapture</a></li>
167
+ </ul>
168
+
169
+ <h3 id="attributes"><a href="#attributes" class="no-link">Attributes</a></h3>
170
+ <h5><code>opened<i>: boolean</i></code></h5>
171
+ <p>Whether the dialog is opened.</p>
172
+
173
+ <h5><code>close-btn<i>: boolean</i></code></h5>
174
+ <p>Whether to show the close button. Default is <code>true</code>.</p>
175
+
176
+ <h5><code>overlay-close<i>: boolean</i></code></h5>
177
+ <p>Whether clicking the overlay closes the dialog. Default is <code>true</code>.</p>
178
+
179
+ <h5><code>confirm-text<i>: string</i></code></h5>
180
+ <p>Text for the confirm button.</p>
181
+
182
+ <h5><code>confirm-classes<i>: string</i></code></h5>
183
+ <p>Classes for the confirm button. Default is <code>'success ml'</code>.</p>
184
+
185
+ <h5><code>cancel-text<i>: string</i></code></h5>
186
+ <p>Text for the cancel button.</p>
187
+
188
+ <h5><code>cancel-classes<i>: string</i></code></h5>
189
+ <p>Classes for the cancel button.</p>
190
+
191
+ <h3 id="properties"><a href="#properties" class="no-link">Properties</a></h3>
192
+ <h5><code>confirmAction<i>: function</i></code></h5>
193
+ <p>Action to perform on confirm. If the function calls <code>event.preventDefault()</code>, the dialog will not close automatically.</p>
194
+
195
+ <h5><code>cancelAction<i>: function</i></code></h5>
196
+ <p>Action to perform on cancel. If the function calls <code>event.preventDefault()</code>, the dialog will not close automatically.</p>
197
+
198
+ <h5><code>closeCallback<i>: function</i></code></h5>
199
+ <p>Callback to execute when the dialog is closed.</p>
200
+
201
+ <h5><code>previousFocus<i>: HTMLElement</i></code></h5>
202
+ <p>Reference to the element that had focus before the dialog was opened.</p>
203
+
204
+ <h3 id="methods"><a href="#methods" class="no-link">Methods</a></h3>
205
+ <h5><code>open()<i>: void</i></code></h5>
206
+ <p>Opens the dialog and sets focus to the first focusable element or an element with the <code>autofocus</code> attribute.</p>
207
+
208
+ <h5><code>close()<i>: void</i></code></h5>
209
+ <p>Closes the dialog and calls the <code>closeCallback</code>.</p>
210
+
211
+ <h5><code>toggle()<i>: void</i></code></h5>
212
+ <p>Toggles the dialog open or closed.</p>
213
+
214
+ <h5><code>focus()<i>: void</i></code></h5>
215
+ <p>Focuses the first focusable element in the dialog and saves the previously focused element.</p>
216
+
217
+ <h5><code>blur()<i>: void</i></code></h5>
218
+ <p>Returns focus to the element that had focus before the dialog was opened.</p>
219
+
220
+ <h3 id="staticMethods"><a href="#staticMethods" class="no-link">Static Methods</a></h3>
221
+ <h5><code>Dialog.create(contents, options)<i>: Dialog</i></code></h5>
222
+ <p>Creates and opens a new dialog with the specified contents and options. Returns the created Dialog instance.</p>
223
+ <p>If <code>contents</code> is plain text (no HTML tags), it will automatically be wrapped in a <code>&lt;p class="p"&gt;</code> tag. If it contains HTML, it will be inserted as-is. If it's an HTMLElement or DocumentFragment, it will be appended directly.</p>
224
+
225
+ <h6>Parameters</h6>
226
+ <ul>
227
+ <li><code>contents<i>: string | HTMLElement | DocumentFragment</i></code> - The content to display in the dialog. Plain text will be wrapped in a paragraph tag automatically.</li>
228
+ <li><code>options<i>: object</i></code> - Configuration options for the dialog.</li>
229
+ </ul>
230
+
231
+ <h6>Options</h6>
232
+ <ul>
233
+ <li><code>title</code>: <i>string | HTMLElement</i> - The title to display in the dialog header. Will be wrapped in an <code>&lt;h5&gt;</code> tag with the <code>title</code> slot.</li>
234
+ <li><code>titleClasses</code>: <i>string</i> - CSS classes for the title element. Default is <code>'pyh px m0'</code>.</li>
235
+ <li><code>opened</code>: <i>boolean</i> - Whether the dialog is initially opened. Default is <code>true</code>.</li>
236
+ <li><code>closeBtn</code>: <i>boolean</i> - Whether to show the close button.</li>
237
+ <li><code>overlayClose</code>: <i>boolean</i> - Whether clicking the overlay closes the dialog.</li>
238
+ <li><code>confirmText</code>: <i>string</i> - Text for the confirm button.</li>
239
+ <li><code>confirmClasses</code>: <i>string</i> - Classes for the confirm button.</li>
240
+ <li><code>confirmAction</code>: <i>function</i> - Action to perform on confirm.</li>
241
+ <li><code>cancelText</code>: <i>string</i> - Text for the cancel button.</li>
242
+ <li><code>cancelClasses</code>: <i>string</i> - Classes for the cancel button.</li>
243
+ <li><code>cancelAction</code>: <i>function</i> - Action to perform on cancel.</li>
244
+ <li><code>closeCallback</code>: <i>function</i> - Callback to execute when the dialog is closed.</li>
245
+ <li><code>removeOnClose</code>: <i>boolean</i> - Whether to remove the dialog from the DOM when closed. Default is <code>true</code>.</li>
246
+ <li><code>closeExisting</code>: <i>boolean</i> - Whether to close existing dialogs before opening this one. Default is <code>true</code>.</li>
247
+ <li><code>width</code>: <i>string</i> - CSS width value for the dialog.</li>
248
+ <li><code>minWidth</code>: <i>string</i> - CSS min-width value for the dialog.</li>
249
+ <li><code>maxWidth</code>: <i>string</i> - CSS max-width value for the dialog.</li>
250
+ <li><code>height</code>: <i>string</i> - CSS height value for the dialog.</li>
251
+ <li><code>minHeight</code>: <i>string</i> - CSS min-height value for the dialog.</li>
252
+ <li><code>maxHeight</code>: <i>string</i> - CSS max-height value for the dialog.</li>
253
+ </ul>
254
+
255
+ <h5><code>Dialog.confirm(text, responseCallback, options)<i>: Dialog</i></code></h5>
256
+ <p>Creates and opens a confirmation dialog with the specified text and options. The response callback receives a boolean value indicating whether the user confirmed (<code>true</code>) or canceled (<code>false</code>).</p>
257
+
258
+ <h6>Parameters</h6>
259
+ <ul>
260
+ <li><code>text<i>: string</i></code> - The message to display in the dialog.</li>
261
+ <li><code>responseCallback<i>: function</i></code> - Function called with the user's response (<code>true</code> for confirm, <code>false</code> for cancel).</li>
262
+ <li><code>options<i>: object</i></code> - Configuration options.</li>
263
+ </ul>
264
+
265
+ <h6>Options</h6>
266
+ <ul>
267
+ <li><code>title</code>: <i>string</i> - The title of the dialog. Default is <code>'Confirm'</code>.</li>
268
+ <li><code>confirmText</code>: <i>string</i> - Text for the confirm button. Default is <code>'Yes'</code>.</li>
269
+ <li><code>confirmClasses</code>: <i>string</i> - Classes for the confirm button. Default is <code>'success ml'</code>.</li>
270
+ <li><code>cancelText</code>: <i>string</i> - Text for the cancel button. Default is <code>'No'</code>.</li>
271
+ <li><code>cancelClasses</code>: <i>string</i> - Classes for the cancel button. Default is <code>'danger'</code>.</li>
272
+ <li><code>closeBtn</code>: <i>boolean</i> - Whether to show the close button. Default is <code>false</code>.</li>
273
+ <li><code>overlayClose</code>: <i>boolean</i> - Whether clicking the overlay closes the dialog. Default is <code>false</code>.</li>
274
+ </ul>
275
+
276
+ <h5><code>Dialog.alert(text, responseCallback, options)<i>: Dialog</i></code></h5>
277
+ <p>Creates and opens an alert dialog with the specified text and options.</p>
278
+
279
+ <h6>Parameters</h6>
280
+ <ul>
281
+ <li><code>text<i>: string</i></code> - The message to display in the dialog.</li>
282
+ <li><code>responseCallback<i>: function</i></code> - Function called when the dialog is closed.</li>
283
+ <li><code>options<i>: object</i></code> - Configuration options.</li>
284
+ </ul>
285
+
286
+ <h6>Options</h6>
287
+ <ul>
288
+ <li><code>title</code>: <i>string</i> - The title of the dialog. Default is <code>'Alert'</code>.</li>
289
+ <li><code>cancelText</code>: <i>string</i> - Text for the OK button. Default is <code>'Ok'</code>.</li>
290
+ </ul>
291
+
292
+ <h5><code>Dialog.error(text, responseCallback, options)<i>: Dialog</i></code></h5>
293
+ <p>Creates and opens an error dialog with the specified text and options. The title is displayed in red.</p>
294
+
295
+ <h6>Parameters</h6>
296
+ <ul>
297
+ <li><code>text<i>: string</i></code> - The error message to display in the dialog.</li>
298
+ <li><code>responseCallback<i>: function</i></code> - Function called when the dialog is closed.</li>
299
+ <li><code>options<i>: object</i></code> - Configuration options.</li>
300
+ </ul>
301
+
302
+ <h6>Options</h6>
303
+ <ul>
304
+ <li><code>title</code>: <i>string</i> - The title of the dialog. Default is <code>'Error'</code>.</li>
305
+ <li><code>cancelText</code>: <i>string</i> - Text for the OK button. Default is <code>'Ok'</code>.</li>
306
+ </ul>
307
+
308
+ <h5><code>Dialog.success(text, responseCallback, options)<i>: Dialog</i></code></h5>
309
+ <p>Creates and opens a success dialog with the specified text and options. The title is displayed in green.</p>
310
+
311
+ <h6>Parameters</h6>
312
+ <ul>
313
+ <li><code>text<i>: string</i></code> - The success message to display in the dialog.</li>
314
+ <li><code>responseCallback<i>: function</i></code> - Function called when the dialog is closed.</li>
315
+ <li><code>options<i>: object</i></code> - Configuration options.</li>
316
+ </ul>
317
+
318
+ <h6>Options</h6>
319
+ <ul>
320
+ <li><code>title</code>: <i>string</i> - The title of the dialog. Default is <code>'Success'</code>.</li>
321
+ <li><code>cancelText</code>: <i>string</i> - Text for the OK button. Default is <code>'Ok'</code>.</li>
322
+ </ul>
323
+
324
+ </main>
325
+ <div style="height:33vh"></div>
94
326
  <script type="module" src="../src/components/Dialog.js"></script>
95
327
  <script>
96
328
  document.querySelectorAll('.openDialog').forEach( $btn => {
@@ -61,7 +61,7 @@
61
61
  </div>
62
62
 
63
63
  <h3 id="explicitSource"><a href="#explicitSource" class="no-link">Explicitly Set the Source</a></h3>
64
- <p>You can use any svg file that is publically available (on your site or any other public domain) buy using the <code>src</code> attribute instead of <code>name</code>. The code will attempt to ensure compatability.</p>
64
+ <p>You can use any SVG file that is publicly available (on your site or any other public domain) by using the <code>src</code> attribute instead of <code>name</code>. The Icon component will automatically fix the SVG to ensure compatibility by removing width/height attributes and setting fill colors to <code>currentColor</code> so the icon adapts to the current text color.</p>
65
65
  <div class="row -mx mb">
66
66
  <div class="col d-span-6 m-span-12 px">
67
67
  <k-card label="HTML">
@@ -98,7 +98,7 @@
98
98
  <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Icon <span class="hljs-keyword">from</span> <span class="hljs-string">'/src/components/Icon.js'</span>;<br /> Icon.pathToIcons = <span class="hljs-string">'./pathTo/icons'</span>;<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
99
99
 
100
100
  <h3 id="addingIcons"><a href="#addingIcons" class="no-link">Adding Icons</a></h3>
101
- <p>Add your SVGs to the directory, remove the <code>height</code> and <code>width</code> attributes from the <code>svg</code> tag (if you do not, the Icon component will attempt to do it for you). The height and width will be managed by CSS to match the font-size. Give all objects (path, rect, circle) a fill of <code>currentColor</code>, this will allow the icon to adapt to the font color where it is rendered.</p>
101
+ <p>Add your SVGs to the directory. The Icon component will automatically remove the <code>height</code> and <code>width</code> attributes from the <code>svg</code> tag and set the fill of all objects (path, rect, circle) to <code>currentColor</code>. This allows the icon to adapt to the font color where it is rendered and ensures consistent sizing. However, you can manually prepare your icons this way for better performance.</p>
102
102
  <div class="row -mx mb">
103
103
  <div class="col d-span-6 m-span-12 px">
104
104
  <k-card label="Before">
@@ -23,11 +23,13 @@
23
23
  <a href="#positions">Different Positions</a><br />
24
24
  <a href="#timeouts">Timeouts</a><br />
25
25
  <a href="#actionAndClose">Action and Close Buttons</a><br />
26
+ <a href="#successWarningError">Success, Warning and Error</a><br />
26
27
 
27
28
  <h6 class="mt">JavaScript Reference</h6>
28
29
  <a href="#constructor">Constructor</a><br />
29
30
  <a href="#staticMethods">Static Methods</a><br />
30
31
  <a href="#requirements">Requirements</a><br />
32
+ <a href="#attributes">Attributes</a><br />
31
33
  <a href="#properties">Properties</a><br />
32
34
  <a href="#methods">Methods</a><br />
33
35
  <a href="#events">Events</a><br />
@@ -41,11 +43,315 @@
41
43
  <h3 id="basicUsage"><a href="#basicUsage" class="no-link">Basic Usage</a></h3>
42
44
  <div class="row -mx">
43
45
  <div class="col d-span-6 t-span-6 m-span-12 px">
44
- <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example1"</span>&gt;</span>Open Toast<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Toast <span class="hljs-keyword">from</span> <span class="hljs-string">'/src/components/Toast.js'</span>;<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example1'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"Hello World"</span>);<br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
46
+ <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example1"</span>&gt;</span>Open Toast<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Toast <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/components/Toast.js'</span>;<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example1'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"Hello World"</span>);<br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
45
47
  </div>
46
48
  <div class="col d-span-6 t-span-6 m-span-12 px">
47
49
  <button id="example1" class="mb">Open Toast</button>
48
- <script type="module" src="./init.js"></script>
50
+ <script type="module">
51
+ import Toast from '../src/components/Toast.js';
52
+ document.getElementById('example1').addEventListener('click', () => {
53
+ Toast.create("Hello World");
54
+ });
55
+ </script>
56
+ </div>
57
+ </div>
58
+
59
+
60
+ <h3 id="positions"><a href="#positions" class="no-link">Different Positions</a></h3>
61
+ <p>Toasts can be positioned in different corners of the screen using the <code>position</code> property.</p>
62
+ <div class="row -mx">
63
+ <div class="col d-span-6 t-span-6 m-span-12 px">
64
+ <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example2-topleft"</span>&gt;</span>Top Left<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example2-topcenter"</span>&gt;</span>Top Center<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example2-topright"</span>&gt;</span>Top Right<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example2-bottomleft"</span>&gt;</span>Bottom Left<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example2-bottomcenter"</span>&gt;</span>Bottom Center<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example2-bottomright"</span>&gt;</span>Bottom Right<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Toast <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/components/Toast.js'</span>;<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example2-topleft'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"Hello from top left!"</span>, {<br /> <span class="hljs-attr">position</span>: <span class="hljs-string">'top left'</span><br /> });<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example2-topcenter'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"Hello from top center!"</span>, {<br /> <span class="hljs-attr">position</span>: <span class="hljs-string">'top center'</span><br /> });<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example2-topright'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"Hello from top right!"</span>, {<br /> <span class="hljs-attr">position</span>: <span class="hljs-string">'top right'</span><br /> });<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example2-bottomleft'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"Hello from bottom left!"</span>, {<br /> <span class="hljs-attr">position</span>: <span class="hljs-string">'bottom left'</span><br /> });<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example2-bottomcenter'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"Hello from bottom center!"</span>, {<br /> <span class="hljs-attr">position</span>: <span class="hljs-string">'bottom center'</span><br /> });<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example2-bottomright'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"Hello from bottom right!"</span>, {<br /> <span class="hljs-attr">position</span>: <span class="hljs-string">'bottom right'</span><br /> });<br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
65
+ </div>
66
+ <div class="col d-span-6 t-span-6 m-span-12 px">
67
+ <button id="example2-topleft" class="mb">Top Left</button>
68
+ <button id="example2-topcenter" class="mb">Top Center</button>
69
+ <button id="example2-topright" class="mb">Top Right</button><br />
70
+ <button id="example2-bottomleft" class="mb">Bottom Left</button>
71
+ <button id="example2-bottomcenter" class="mb">Bottom Center</button>
72
+ <button id="example2-bottomright" class="mb">Bottom Right</button>
73
+ <script type="module">
74
+ import Toast from '../src/components/Toast.js';
75
+ document.getElementById('example2-topleft').addEventListener('click', () => {
76
+ Toast.create("Hello from top left!", {
77
+ position: 'top left'
78
+ });
79
+ });
80
+ document.getElementById('example2-topcenter').addEventListener('click', () => {
81
+ Toast.create("Hello from top center!", {
82
+ position: 'top center'
83
+ });
84
+ });
85
+ document.getElementById('example2-topright').addEventListener('click', () => {
86
+ Toast.create("Hello from top right!", {
87
+ position: 'top right'
88
+ });
89
+ });
90
+ document.getElementById('example2-bottomleft').addEventListener('click', () => {
91
+ Toast.create("Hello from bottom left!", {
92
+ position: 'bottom left'
93
+ });
94
+ });
95
+ document.getElementById('example2-bottomcenter').addEventListener('click', () => {
96
+ Toast.create("Hello from bottom center!", {
97
+ position: 'bottom center'
98
+ });
99
+ });
100
+ document.getElementById('example2-bottomright').addEventListener('click', () => {
101
+ Toast.create("Hello from bottom right!", {
102
+ position: 'bottom right'
103
+ });
104
+ });
105
+ </script>
106
+ </div>
107
+ </div>
108
+
109
+ <h3 id="timeouts"><a href="#timeouts" class="no-link">Timeouts</a></h3>
110
+ <p>Toasts can automatically close after a specified timeout (in milliseconds). The default timeout when using <code>Toast.create</code> is <code>5000</code> (ms), or 5 seconds.</p>
111
+ <div class="row -mx">
112
+ <div class="col d-span-6 t-span-6 m-span-12 px">
113
+ <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example3-1"</span>&gt;</span>Open 1 Second Timeout Toast<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example3-3"</span>&gt;</span>Open 3 Second Timeout Toast<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example3-10"</span>&gt;</span>Open 10 Second Timeout Toast<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Toast <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/components/Toast.js'</span>;<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example3-1'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"I will timeout in 1 second"</span>, {<br /> <span class="hljs-attr">timeout</span>: <span class="hljs-number">1000</span><br /> });<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example3-3'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"I will timeout in 3 second"</span>, {<br /> <span class="hljs-attr">timeout</span>: <span class="hljs-number">3000</span><br /> });<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example3-10'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"I will timeout in 10 second"</span>, {<br /> <span class="hljs-attr">timeout</span>: <span class="hljs-number">10000</span><br /> });<br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
114
+ </div>
115
+ <div class="col d-span-6 t-span-6 m-span-12 px">
116
+ <button id="example3-1" class="mb">Open 1 Second Timeout Toast</button>
117
+ <button id="example3-3" class="mb">Open 3 Second Timeout Toast</button>
118
+ <button id="example3-10" class="mb">Open 10 Second Timeout Toast</button>
119
+ <script type="module">
120
+ import Toast from '../src/components/Toast.js';
121
+ document.getElementById('example3-1').addEventListener('click', () => {
122
+ Toast.create("I will timeout in 1 second", {
123
+ timeout: 1000
124
+ });
125
+ });
126
+ document.getElementById('example3-3').addEventListener('click', () => {
127
+ Toast.create("I will timeout in 3 second", {
128
+ timeout: 3000
129
+ });
130
+ });
131
+ document.getElementById('example3-10').addEventListener('click', () => {
132
+ Toast.create("I will timeout in 10 second", {
133
+ timeout: 10000
134
+ });
135
+ });
136
+ </script>
137
+ </div>
138
+ </div>
139
+
140
+
141
+ <h3 id="actionAndClose"><a href="#actionAndClose" class="no-link">Action and Close Buttons</a></h3>
142
+ <p>Toasts can have action and close buttons that trigger callbacks when clicked.</p>
143
+ <div class="row -mx">
144
+ <div class="col d-span-6 t-span-6 m-span-12 px">
145
+ <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example4-action"</span>&gt;</span>Open Toast with Action<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example4-close"</span>&gt;</span>Open Toast with Close Button<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example4-action-close"</span>&gt;</span>Open Toast with Action and Close Button<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Toast <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/components/Toast.js'</span>;<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example4-action'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"Hello World"</span>, {<br /> <span class="hljs-attr">timeout</span>: <span class="hljs-number">0</span>,<br /> <span class="hljs-attr">action</span>: <span class="hljs-string">'Click Me'</span>,<br /> <span class="hljs-attr">actionCallback</span>: <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {<br /> Toast.create(<span class="hljs-string">"You clicked the action"</span>);<br /> }<br /> });<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example4-close'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"Hello World"</span>, {<br /> <span class="hljs-attr">timeout</span>: <span class="hljs-number">0</span>,<br /> <span class="hljs-attr">close</span>: <span class="hljs-string">'&lt;k-icon name="close"&gt;&lt;/div&gt;'</span>,<br /> <span class="hljs-attr">closeCallback</span>: <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {<br /> Toast.create(<span class="hljs-string">"You closed the toast"</span>);<br /> }<br /> });<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example4-action-close'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.create(<span class="hljs-string">"Hello World"</span>, {<br /> <span class="hljs-attr">timeout</span>: <span class="hljs-number">0</span>,<br /> <span class="hljs-attr">action</span>: <span class="hljs-string">'Click Me'</span>,<br /> <span class="hljs-attr">actionCallback</span>: <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {<br /> Toast.create(<span class="hljs-string">"You clicked the action"</span>);<br /> <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>; <span class="hljs-comment">// return false to prevent closing</span><br /> },<br /> <span class="hljs-attr">close</span>: <span class="hljs-string">'&lt;k-icon name="close"&gt;&lt;/div&gt;'</span>,<br /> <span class="hljs-attr">closeCallback</span>: <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {<br /> Toast.create(<span class="hljs-string">"You closed the toast"</span>);<br /> }<br /> });<br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
146
+ </div>
147
+ <div class="col d-span-6 t-span-6 m-span-12 px">
148
+ <button id="example4-action" class="mb">Open Toast with Action</button>
149
+ <button id="example4-close" class="mb">Open Toast with Close Button</button>
150
+ <button id="example4-action-close" class="mb">Open Toast with Action and Close Button</button>
151
+ <script type="module">
152
+ import Toast from '../src/components/Toast.js';
153
+ document.getElementById('example4-action').addEventListener('click', () => {
154
+ Toast.create("Hello World", {
155
+ timeout: 0,
156
+ action: 'Click Me',
157
+ actionCallback: () => {
158
+ Toast.create("You clicked the action");
159
+ }
160
+ });
161
+ });
162
+ document.getElementById('example4-close').addEventListener('click', () => {
163
+ Toast.create("Hello World", {
164
+ timeout: 0,
165
+ close: '<k-icon name="close"></div>',
166
+ closeCallback: () => {
167
+ Toast.create("You closed the toast");
168
+ }
169
+ });
170
+ });
171
+ document.getElementById('example4-action-close').addEventListener('click', () => {
172
+ Toast.create("Hello World", {
173
+ timeout: 0,
174
+ action: 'Click Me',
175
+ actionCallback: () => {
176
+ Toast.create("You clicked the action");
177
+ return false; // return false to prevent closing
178
+ },
179
+ close: '<k-icon name="close"></div>',
180
+ closeCallback: () => {
181
+ Toast.create("You closed the toast");
182
+ }
183
+ });
184
+ });
185
+ </script>
186
+ </div>
187
+ </div>
188
+
189
+ <h3 id="successWarningError"><a href="#successWarningError" class="no-link">Success, Warning and Error</a></h3>
190
+ <p>Toasts can be created as a success, warning or error message.</p>
191
+ <div class="row -mx">
192
+ <div class="col d-span-6 t-span-6 m-span-12 px">
193
+ <pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example5-success"</span>&gt;</span>Success Toast<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example5-warning"</span>&gt;</span>Warning Toast<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example5-error"</span>&gt;</span>Error Toast<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br /><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>&gt;</span><span class="javascript"><br /> <span class="hljs-keyword">import</span> Toast <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/components/Toast.js'</span>;<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example5-success'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.success(<span class="hljs-string">"It Worked!"</span>);<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example5-warning'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.warning(<span class="hljs-string">"Be Careful"</span>);<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'example5-error'</span>).addEventListener(<span class="hljs-string">'click'</span>, () =&gt; {<br /> Toast.error(<span class="hljs-string">"That's a very bad idea"</span>);<br /> });<br /></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></code></pre>
194
+ </div>
195
+ <div class="col d-span-6 t-span-6 m-span-12 px">
196
+ <button id="example5-success" class="mb">Success Toast</button>
197
+ <button id="example5-warning" class="mb">Warning Toast</button>
198
+ <button id="example5-error" class="mb">Error Toast</button>
199
+ <script type="module">
200
+ import Toast from '../src/components/Toast.js';
201
+ document.getElementById('example5-success').addEventListener('click', () => {
202
+ Toast.success("It Worked!");
203
+ });
204
+ document.getElementById('example5-warning').addEventListener('click', () => {
205
+ Toast.warning("Be Careful");
206
+ });
207
+ document.getElementById('example5-error').addEventListener('click', () => {
208
+ Toast.error("That's a very bad idea");
209
+ });
210
+ </script>
211
+ </div>
212
+ </div>
213
+
214
+
215
+ <h2 id="jsRef">JavaScript Reference</h2>
216
+
217
+ <h3 id="constructor"><a href="#constructor" class="no-link">Constructor</a></h3>
218
+ <h6>Extends <a href="./shadow-component.html">ShadowComponent</a></h6>
219
+ <h5>
220
+ <code>new Toast()</code><br />
221
+ <code>new Toast(<i>object</i> options)</code>
222
+ </h5>
223
+
224
+ <h4>Parameters</h4>
225
+ <h5><code>options<i>: object</i></code></h5>
226
+ <p>An object with the following optional properties:</p>
227
+ <ul>
228
+ <li><code>actionCallback<i>: function</i></code> - Function to call when the action button is clicked. If this function returns <code>false</code>, the toast will not close.</li>
229
+ <li><code>actionHtml<i>: string</i></code> - HTML content for the action button.</li>
230
+ <li><code>closeCallback<i>: function</i></code> - Function to call when the toast is closed.</li>
231
+ <li><code>closeHtml<i>: string</i></code> - HTML content for the close button.</li>
232
+ <li><code>timeout<i>: number</i></code> - Time in milliseconds before the toast automatically closes. Default is 0 (no auto-close).</li>
233
+ </ul>
234
+
235
+ <h3 id="staticMethods"><a href="#staticMethods" class="no-link">Static Methods</a></h3>
236
+ <h5><code>Toast.create(message, options)<i>: Toast</i></code></h5>
237
+ <p>Creates and displays a new toast with the specified message and options. Returns the created Toast instance.</p>
238
+ <p>Options include:</p>
239
+ <ul>
240
+ <li><code>position<i>: string</i></code> - Position of the toast on the screen. Default is 'auto', which uses 'bottom center' on mobile and 'top right' on desktop. Valid positions are: 'top left', 'top center', 'top right', 'bottom left', 'bottom center', 'bottom right'.</li>
241
+ <li><code>removeOnClose<i>: boolean</i></code> - If true, the toast element will be removed from the DOM when closed. Default is true.</li>
242
+ <li><code>timeout<i>: number</i></code> - Time in milliseconds before the toast automatically closes. Default is 5000ms (5 seconds).</li>
243
+ <li><code>action<i>: string | HTMLElement</i></code> - Text or HTML element to use for the action button.</li>
244
+ <li><code>actionCallback<i>: function</i></code> - Function to call when the action button is clicked. If this function returns <code>false</code>, the toast will not close.</li>
245
+ <li><code>close<i>: string | HTMLElement</i></code> - Text or HTML element to use for the close button.</li>
246
+ <li><code>closeCallback<i>: function</i></code> - Function to call when the toast is closed.</li>
247
+ <li><code>icon<i>: string | HTMLElement</i></code> - Text or HTML element to use as an icon in the toast.</li>
248
+ </ul>
249
+
250
+ <h5><code>Toast.success(message, options)<i>: Toast</i></code></h5>
251
+ <p>Creates and displays a success toast with a check icon and applies a success background style. Accepts the same options as <code>Toast.create()</code>.</p>
252
+
253
+ <h5><code>Toast.warning(message, options)<i>: Toast</i></code></h5>
254
+ <p>Creates and displays a warning toast with a warning icon and applies a warning background style. Accepts the same options as <code>Toast.create()</code>.</p>
255
+
256
+ <h5><code>Toast.error(message, options)<i>: Toast</i></code></h5>
257
+ <p>Creates and displays an error toast with an error icon and applies a danger background style. Accepts the same options as <code>Toast.create()</code>.</p>
258
+
259
+ <h3 id="requirements"><a href="#requirements" class="no-link">Requirements</a></h3>
260
+ <ul>
261
+ <li><a href="./shadow-component.html">ShadowComponent</a></li>
262
+ <li><a href="./icon.html">Icon</a> (for success, warning, and error toasts)</li>
263
+ </ul>
264
+
265
+ <h3 id="attributes"><a href="#attributes" class="no-link">Attributes</a></h3>
266
+ <h5><code>action-html<i>: string</i></code></h5>
267
+ <p>HTML content for the action button.</p>
268
+
269
+ <h5><code>close-html<i>: string</i></code></h5>
270
+ <p>HTML content for the close button.</p>
271
+
272
+ <h5><code>timeout<i>: number</i></code></h5>
273
+ <p>Time in milliseconds before the toast automatically closes. Default is 0 (no auto-close).</p>
274
+
275
+ <h5><code>opened<i>: boolean</i></code></h5>
276
+ <p>Whether the toast is currently open. Default is false.</p>
277
+
278
+ <h5><code>has-action<i>: boolean</i></code></h5>
279
+ <p>Whether the toast has an action button. Automatically set based on slotted content.</p>
280
+
281
+ <h5><code>has-close<i>: boolean</i></code></h5>
282
+ <p>Whether the toast has a close button. Automatically set based on slotted content.</p>
283
+
284
+ <h5><code>has-icon<i>: boolean</i></code></h5>
285
+ <p>Whether the toast has an icon. Automatically set based on slotted content.</p>
286
+
287
+ <h5><code>position<i>: string</i></code></h5>
288
+ <p>Position of the toast on the screen.</p>
289
+
290
+ <h5><code>animating<i>: string</i></code></h5>
291
+ <p>Current animation state ('in', 'out', or empty string).</p>
292
+
293
+ <h3 id="properties"><a href="#properties" class="no-link">Properties</a></h3>
294
+ <h5><code>actionCallback<i>: function</i></code></h5>
295
+ <p>Function to call when the action button is clicked.</p>
296
+
297
+ <h5><code>closeCallback<i>: function</i></code></h5>
298
+ <p>Function to call when the toast is closed.</p>
299
+
300
+ <h5><code>actionHtml<i>: string</i></code></h5>
301
+ <p>HTML content for the action button.</p>
302
+
303
+ <h5><code>closeHtml<i>: string</i></code></h5>
304
+ <p>HTML content for the close button.</p>
305
+
306
+ <h5><code>timeout<i>: number</i></code></h5>
307
+ <p>Time in milliseconds before the toast automatically closes.</p>
308
+
309
+ <h5><code>opened<i>: boolean</i></code></h5>
310
+ <p>Whether the toast is currently open.</p>
311
+
312
+ <h5><code>hasAction<i>: boolean</i></code></h5>
313
+ <p>Whether the toast has an action button.</p>
314
+
315
+ <h5><code>hasClose<i>: boolean</i></code></h5>
316
+ <p>Whether the toast has a close button.</p>
317
+
318
+ <h5><code>hasIcon<i>: boolean</i></code></h5>
319
+ <p>Whether the toast has an icon.</p>
320
+
321
+ <h5><code>position<i>: string</i></code></h5>
322
+ <p>Position of the toast on the screen.</p>
323
+
324
+ <h5><code>animating<i>: string</i></code></h5>
325
+ <p>Current animation state.</p>
326
+
327
+ <h3 id="methods"><a href="#methods" class="no-link">Methods</a></h3>
328
+ <h5><code>open()<i>: void</i></code></h5>
329
+ <p>Opens the toast. If a timeout is specified, this starts the timer for automatic closing.</p>
330
+
331
+ <h5><code>close()<i>: void</i></code></h5>
332
+ <p>Closes the toast and calls the <code>closeCallback</code> if provided.</p>
333
+
334
+ <h3 id="events"><a href="#events" class="no-link">Events</a></h3>
335
+ <h5><code>open</code></h5>
336
+ <p>Fired when the toast is opened.</p>
337
+
338
+ <h5><code>close</code></h5>
339
+ <p>Fired when the toast is closed.</p>
340
+
341
+ <h5><code>openchange</code></h5>
342
+ <p>Fired when the toast open state changes (both when opening and closing).</p>
343
+
344
+ <h3 id="toastContainer"><a href="#toastContainer" class="no-link">ToastContainer</a></h3>
345
+ <p>The <code>ToastContainer</code> is an internal component used to position and display toasts. It is automatically created when <code>Toast.create()</code> is called, but can also be used directly.</p>
346
+
347
+ <h5><code>new ToastContainer(position)</code></h5>
348
+ <p>Creates a new toast container at the specified position.</p>
349
+
350
+ <h5><code>position<i>: string</i></code></h5>
351
+ <p>The position of the container on the screen. Valid values are: 'top left', 'top center', 'top right', 'bottom left', 'bottom center', 'bottom right'.</p>
352
+
353
+ </main>
354
+ <div style="height:33vh"></div>
49
355
  <script type="module" src="../src/components/Toast.js"></script>
50
356
  </body>
51
357
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kempo-ui",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "description": "A Lit based web-component library",
6
6
  "main": "index.js",
@@ -11,7 +11,7 @@ export default class Card extends ShadowComponent {
11
11
 
12
12
  constructor() {
13
13
  super();
14
- this.label = '';
14
+ this.label = null;
15
15
  }
16
16
 
17
17
  /*
@@ -38,12 +38,9 @@ export default class Card extends ShadowComponent {
38
38
  border-radius: var(--radius);
39
39
  padding: var(--spacer_h);
40
40
  }
41
- :host([label]) {
42
- padding-top: calc(1.5 * var(--spacer));
43
- margin-top: var(--spacer);
44
- }
45
41
  :host([label]) #card {
46
42
  padding-top: calc(1.5 * var(--spacer));
43
+ margin-top: var(--spacer);
47
44
  }
48
45
  :host(:not([label])) #label {
49
46
  display: none;
@@ -227,13 +227,13 @@ export default class Dialog extends ShadowComponent {
227
227
  return html`
228
228
  <button id="overlay" aria-label="Close the Dialog" @click=${this.handleClick}></button>
229
229
  <div id="wrapper">
230
- <div
231
- id="dialog"
232
- role="dialog"
233
- aria-modal="true"
234
- aria-labelledby="title"
235
- >
236
- <k-focus-capture>
230
+ <k-focus-capture>
231
+ <div
232
+ id="dialog"
233
+ role="dialog"
234
+ aria-modal="true"
235
+ aria-labelledby="title"
236
+ >
237
237
  <div
238
238
  id="header"
239
239
  class="${this.hasTitle() ? 'has-title' : ''}"
@@ -264,8 +264,8 @@ export default class Dialog extends ShadowComponent {
264
264
  ` : ''}
265
265
  </div>
266
266
  ` : ''}
267
- </k-focus-capture>
268
- </div>
267
+ </div>
268
+ </k-focus-capture>
269
269
  </div>
270
270
  `;
271
271
  }
@@ -280,7 +280,9 @@ export default class Dialog extends ShadowComponent {
280
280
 
281
281
  const {
282
282
  removeOnClose = true,
283
- closeCallback = () => {}
283
+ closeCallback = () => {},
284
+ title = '',
285
+ titleClasses = 'pyh px m0'
284
286
  } = options;
285
287
 
286
288
  const dialog = new Dialog();
@@ -297,11 +299,33 @@ export default class Dialog extends ShadowComponent {
297
299
  }
298
300
  });
299
301
 
302
+ // Set title if provided
303
+ if(title) {
304
+ const titleElement = document.createElement('h5');
305
+ titleElement.slot = 'title';
306
+ titleElement.className = titleClasses;
307
+ if(title instanceof HTMLElement) {
308
+ titleElement.appendChild(title);
309
+ } else {
310
+ titleElement.innerHTML = title;
311
+ }
312
+ dialog.appendChild(titleElement);
313
+ }
314
+
300
315
  // Set content
301
316
  if(contents instanceof HTMLElement || contents instanceof DocumentFragment) {
302
317
  dialog.appendChild(contents);
303
318
  } else if(contents) {
304
- dialog.innerHTML = contents;
319
+ // Check if content is plain text (no HTML tags)
320
+ const hasHtmlTags = /<[^>]+>/.test(contents);
321
+ if(hasHtmlTags) {
322
+ dialog.innerHTML += contents;
323
+ } else {
324
+ const p = document.createElement('p');
325
+ p.className = 'p';
326
+ p.textContent = contents;
327
+ dialog.appendChild(p);
328
+ }
305
329
  }
306
330
 
307
331
  // Set CSS custom properties for dimensions
@@ -319,11 +343,8 @@ export default class Dialog extends ShadowComponent {
319
343
  }
320
344
 
321
345
  static confirm(text, responseCallback, options = {}) {
322
- const title = options.title || 'Confirm';
323
- return Dialog.create(`
324
- <h5 slot="title" class="pyh px m0">${title}</h5>
325
- <p class="p">${text}</p>
326
- `, {
346
+ return Dialog.create(text, {
347
+ title: options.title || 'Confirm',
327
348
  closeBtn: false,
328
349
  overlayClose: false,
329
350
  confirmText: 'Yes',
@@ -336,36 +357,29 @@ export default class Dialog extends ShadowComponent {
336
357
  });
337
358
  }
338
359
 
339
- static alert(text, responseCallback, options = {}) {
340
- const title = options.title || 'Alert';
341
- return Dialog.create(`
342
- <h5 slot="title" class="pyh px m0">${title}</h5>
343
- <p class="p">${text}</p>
344
- `, {
360
+ static alert(text, responseCallback = () => {}, options = {}) {
361
+ return Dialog.create(text, {
362
+ title: options.title || 'Alert',
345
363
  closeCallback: responseCallback,
346
364
  cancelText: 'Ok',
347
365
  ...options
348
366
  });
349
367
  }
350
368
 
351
- static error(text, responseCallback, options = {}) {
352
- const title = options.title || 'Error';
353
- return Dialog.create(`
354
- <h5 slot="title" class="pyh px m0 tc-danger">${title}</h5>
355
- <p class="p">${text}</p>
356
- `, {
369
+ static error(text, responseCallback = () => {}, options = {}) {
370
+ return Dialog.create(text, {
371
+ title: options.title || 'Error',
372
+ titleClasses: 'pyh px m0 tc-danger',
357
373
  closeCallback: responseCallback,
358
374
  cancelText: 'Ok',
359
375
  ...options
360
376
  });
361
377
  }
362
378
 
363
- static success(text, responseCallback, options = {}) {
364
- const title = options.title || 'Success';
365
- return Dialog.create(`
366
- <h5 slot="title" class="pyh px m0 tc-success">${title}</h5>
367
- <p class="p">${text}</p>
368
- `, {
379
+ static success(text, responseCallback = () => {}, options = {}) {
380
+ return Dialog.create(text, {
381
+ title: options.title || 'Success',
382
+ titleClasses: 'pyh px m0 tc-success',
369
383
  closeCallback: responseCallback,
370
384
  cancelText: 'Ok',
371
385
  ...options
@@ -69,10 +69,6 @@ export default class Icon extends ShadowComponent {
69
69
  if (changedProperties.has('src') || changedProperties.has('name')) {
70
70
  this.loadIcon();
71
71
  }
72
-
73
- if (changedProperties.has('iconContent')) {
74
- this.fixSVG();
75
- }
76
72
  }
77
73
 
78
74
  /*
@@ -88,30 +84,41 @@ export default class Icon extends ShadowComponent {
88
84
  }
89
85
 
90
86
  if (svg) {
91
- this.iconContent = svg;
87
+ this.iconContent = this.fixSVG(svg);
92
88
  } else {
93
89
  // Check for slotted fallback content first
94
90
  const slottedContent = this.innerHTML.trim();
95
91
  if (slottedContent) {
96
- this.iconContent = slottedContent;
92
+ this.iconContent = this.fixSVG(slottedContent);
97
93
  } else {
98
94
  this.iconContent = Icon.fallback;
99
95
  }
100
96
  }
101
97
  }
102
98
 
103
- fixSVG() {
104
- // Use setTimeout to ensure DOM is updated
105
- setTimeout(() => {
106
- const $svg = this.querySelector('svg');
107
- if ($svg) {
108
- $svg.removeAttribute('width');
109
- $svg.removeAttribute('height');
110
- $svg.querySelectorAll('path, rect, circle').forEach($path => {
111
- $path.setAttribute('fill', 'currentColor');
112
- });
113
- }
114
- }, 0);
99
+ fixSVG(svgString) {
100
+ if(!svgString) return svgString;
101
+
102
+ // Parse the SVG string and fix attributes
103
+ const parser = new DOMParser();
104
+ const doc = parser.parseFromString(svgString, 'image/svg+xml');
105
+ const $svg = doc.querySelector('svg');
106
+
107
+ if($svg) {
108
+ // Remove width and height attributes
109
+ $svg.removeAttribute('width');
110
+ $svg.removeAttribute('height');
111
+
112
+ // Set fill to currentColor on all paths, rects, and circles
113
+ $svg.querySelectorAll('path, rect, circle').forEach($el => {
114
+ $el.setAttribute('fill', 'currentColor');
115
+ });
116
+
117
+ // Return the fixed SVG as a string
118
+ return new XMLSerializer().serializeToString($svg);
119
+ }
120
+
121
+ return svgString;
115
122
  }
116
123
 
117
124
  /*
@@ -1,62 +0,0 @@
1
- import fs from 'fs/promises';
2
- import path from 'path';
3
- import { fileURLToPath } from 'url';
4
-
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = path.dirname(__filename);
7
-
8
- const docsComponentsDir = path.join(__dirname, '..', 'docs', 'components');
9
- const docsUtilsDir = path.join(__dirname, '..', 'docs', 'utils');
10
-
11
- async function fixComponentHtmlFile(filePath) {
12
- let content = await fs.readFile(filePath, 'utf-8');
13
- let modified = false;
14
-
15
- // Replace the inline script block with script src to init.js
16
- const scriptPattern = /<script type="module">\s*import.*?(ShadowComponent|Import|Icon).*?<\/script>/s;
17
- if (scriptPattern.test(content)) {
18
- content = content.replace(
19
- scriptPattern,
20
- '<script type="module" src="./init.js"></script>'
21
- );
22
- modified = true;
23
- }
24
-
25
- // Fix the backtick-n issue in stylesheets
26
- if (content.includes('`n')) {
27
- content = content.replace(/`n/g, '\n');
28
- modified = true;
29
- }
30
-
31
- if (modified) {
32
- await fs.writeFile(filePath, content, 'utf-8');
33
- console.log(`Fixed: ${path.basename(filePath)}`);
34
- return true;
35
- }
36
- return false;
37
- }
38
-
39
- async function fixAllFilesInDirectory(dir, dirName) {
40
- const files = await fs.readdir(dir);
41
- let fixedCount = 0;
42
-
43
- for (const file of files) {
44
- if (file.endsWith('.html')) {
45
- const filePath = path.join(dir, file);
46
- const fixed = await fixComponentHtmlFile(filePath);
47
- if (fixed) fixedCount++;
48
- }
49
- }
50
-
51
- console.log(`\nFixed ${fixedCount} HTML files in ${dirName}/`);
52
- }
53
-
54
- async function fixAllComponentFiles() {
55
- console.log('Fixing components...');
56
- await fixAllFilesInDirectory(docsComponentsDir, 'docs/components');
57
-
58
- console.log('\nFixing utils...');
59
- await fixAllFilesInDirectory(docsUtilsDir, 'docs/utils');
60
- }
61
-
62
- fixAllComponentFiles().catch(console.error);