kempo-ui 0.3.5 → 0.3.7
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/AGENTS.md +2 -1
- package/dist/components/Aside.js +1 -1
- package/dist/components/Main.js +1 -1
- package/docs/components/accordion.html +240 -8
- package/docs/components/aside-items.html +13 -9
- package/docs/components/aside-menu.html +13 -9
- package/docs/components/aside-push.html +11 -6
- package/docs/components/aside.html +289 -115
- package/docs/components/card.html +238 -7
- package/docs/components/color-picker.html +245 -14
- package/docs/components/content-slider.html +240 -8
- package/docs/components/context.html +241 -7
- package/docs/components/dialog.html +238 -7
- package/docs/components/dropdown.html +238 -7
- package/docs/components/filter-list.html +239 -10
- package/docs/components/focus-capture.html +241 -10
- package/docs/components/html-editor.html +266 -35
- package/docs/components/hybrid-component.html +238 -6
- package/docs/components/icon.html +239 -9
- package/docs/components/import.html +239 -8
- package/docs/components/light-component.html +239 -7
- package/docs/components/nav.html +240 -8
- package/docs/components/photo-viewer.html +239 -9
- package/docs/components/resize.html +240 -9
- package/docs/components/shadow-component.html +239 -7
- package/docs/components/show-more.html +237 -8
- package/docs/components/sortable.html +239 -8
- package/docs/components/spinner.html +237 -6
- package/docs/components/split.html +241 -10
- package/docs/components/table.html +241 -11
- package/docs/components/tableControls.html +240 -7
- package/docs/components/tableCustomFields.html +241 -8
- package/docs/components/tableFetchRecords.html +239 -7
- package/docs/components/tableFieldSortHide.html +239 -7
- package/docs/components/tablePagination.html +246 -13
- package/docs/components/tablePlaceholder.html +241 -8
- package/docs/components/tableRecordEditing.html +241 -8
- package/docs/components/tableRecordFiltering.html +239 -7
- package/docs/components/tableRecordHiding.html +241 -9
- package/docs/components/tableRecordSearching.html +239 -7
- package/docs/components/tableRecordSelection.html +240 -7
- package/docs/components/tableRowControls.html +241 -8
- package/docs/components/tableServerSync.html +245 -11
- package/docs/components/tableSorting.html +239 -7
- package/docs/components/tabs.html +240 -7
- package/docs/components/tags.html +239 -7
- package/docs/components/theme-select.html +239 -7
- package/docs/components/theme-switcher.html +240 -8
- package/docs/components/timestamp.html +239 -8
- package/docs/components/toast.html +240 -8
- package/docs/components/toggle.html +240 -9
- package/docs/components/tree.html +239 -8
- package/docs/index.html +244 -6
- package/docs/prod.config.json +0 -4
- package/docs/src/components/Aside.js +1 -1
- package/docs/src/components/Main.js +1 -1
- package/docs/utils/context.html +237 -6
- package/docs/utils/cookie.html +251 -21
- package/docs/utils/debounce.html +236 -5
- package/docs/utils/drag.html +236 -5
- package/docs/utils/elevation.html +238 -6
- package/docs/utils/formatTimestamp.html +239 -9
- package/docs/utils/object.html +236 -5
- package/docs/utils/propConverters.html +233 -3
- package/docs/utils/string.html +236 -5
- package/docs/utils/theme.html +237 -6
- package/docs/utils/toTitleCase.html +239 -9
- package/docs/utils/type.html +236 -5
- package/docs/utils/wait.html +236 -5
- package/docs-src/.config.js +16 -0
- package/docs-src/bare.template.html +16 -0
- package/docs-src/components/accordion.page.html +201 -0
- package/docs-src/components/aside-items.page.html +36 -0
- package/docs-src/components/aside-menu.page.html +36 -0
- package/docs-src/components/aside-push.page.html +20 -0
- package/docs-src/components/aside.page.html +494 -0
- package/docs-src/components/card.page.html +78 -0
- package/docs-src/components/color-picker.page.html +559 -0
- package/docs-src/components/content-slider.page.html +266 -0
- package/docs-src/components/context.page.html +214 -0
- package/docs-src/components/dialog.page.html +365 -0
- package/docs-src/components/dropdown.page.html +300 -0
- package/docs-src/components/filter-list.page.html +117 -0
- package/docs-src/components/focus-capture.page.html +97 -0
- package/docs-src/components/html-editor.page.html +423 -0
- package/docs-src/components/hybrid-component.page.html +96 -0
- package/docs-src/components/icon.page.html +208 -0
- package/docs-src/components/import.page.html +76 -0
- package/docs-src/components/light-component.page.html +99 -0
- package/docs-src/components/nav.page.html +106 -0
- package/docs-src/components/photo-viewer.page.html +253 -0
- package/docs-src/components/resize.page.html +161 -0
- package/docs-src/components/shadow-component.page.html +84 -0
- package/docs-src/components/show-more.page.html +113 -0
- package/docs-src/components/sortable.page.html +117 -0
- package/docs-src/components/spinner.page.html +197 -0
- package/docs-src/components/split.page.html +195 -0
- package/docs-src/components/table.page.html +283 -0
- package/docs-src/components/tableControls.page.html +64 -0
- package/docs-src/components/tableCustomFields.page.html +124 -0
- package/docs-src/components/tableFetchRecords.page.html +95 -0
- package/docs-src/components/tableFieldSortHide.page.html +56 -0
- package/docs-src/components/tablePagination.page.html +85 -0
- package/docs-src/components/tablePlaceholder.page.html +73 -0
- package/docs-src/components/tableRecordEditing.page.html +161 -0
- package/docs-src/components/tableRecordFiltering.page.html +69 -0
- package/docs-src/components/tableRecordHiding.page.html +65 -0
- package/docs-src/components/tableRecordSearching.page.html +56 -0
- package/docs-src/components/tableRecordSelection.page.html +60 -0
- package/docs-src/components/tableRowControls.page.html +62 -0
- package/docs-src/components/tableServerSync.page.html +129 -0
- package/docs-src/components/tableSorting.page.html +54 -0
- package/docs-src/components/tabs.page.html +201 -0
- package/docs-src/components/tags.page.html +157 -0
- package/docs-src/components/theme-select.page.html +106 -0
- package/docs-src/components/theme-switcher.page.html +122 -0
- package/docs-src/components/timestamp.page.html +109 -0
- package/docs-src/components/toast.page.html +338 -0
- package/docs-src/components/toggle.page.html +177 -0
- package/docs-src/components/tree.page.html +356 -0
- package/docs-src/default.template.html +28 -0
- package/docs-src/index.page.html +312 -0
- package/docs-src/nav.fragment.html +228 -0
- package/docs-src/utils/context.page.html +143 -0
- package/docs-src/utils/cookie.page.html +128 -0
- package/docs-src/utils/debounce.page.html +42 -0
- package/docs-src/utils/drag.page.html +64 -0
- package/docs-src/utils/elevation.page.html +144 -0
- package/docs-src/utils/formatTimestamp.page.html +76 -0
- package/docs-src/utils/object.page.html +76 -0
- package/docs-src/utils/propConverters.page.html +73 -0
- package/docs-src/utils/string.page.html +66 -0
- package/docs-src/utils/theme.page.html +136 -0
- package/docs-src/utils/toTitleCase.page.html +52 -0
- package/docs-src/utils/type.page.html +31 -0
- package/docs-src/utils/wait.page.html +31 -0
- package/package.json +4 -4
- package/scripts/build.js +5 -0
- package/scripts/docs.js +5 -52
- package/src/components/Aside.js +12 -1
- package/src/components/Main.js +1 -1
- package/tests/components/Aside.browser-test.js +75 -0
- package/docs/dev.config.json +0 -20
- package/docs/nav-1.inc.html +0 -168
- package/docs/nav.inc.html +0 -168
- package/docs/nav.inc.js +0 -70
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
<page pageName="Toast" title="Toast - Components - Kempo Docs - A Web Components Solution">
|
|
2
|
+
<content>
|
|
3
|
+
<k-accordion persistent-id="toc" class="b r mb">
|
|
4
|
+
<k-accordion-header for-panel="toc-panel">Table of Contents</k-accordion-header>
|
|
5
|
+
<k-accordion-panel name="toc-panel">
|
|
6
|
+
<div class="m ">
|
|
7
|
+
<h6>Examples</h6>
|
|
8
|
+
<a href="#basicUsage">Basic Usage</a><br />
|
|
9
|
+
<a href="#positions">Different Positions</a><br />
|
|
10
|
+
<a href="#timeouts">Timeouts</a><br />
|
|
11
|
+
<a href="#actionAndClose">Action and Close Buttons</a><br />
|
|
12
|
+
|
|
13
|
+
<h6 class="mt">JavaScript Reference</h6>
|
|
14
|
+
<a href="#constructor">Constructor</a><br />
|
|
15
|
+
<a href="#staticMethods">Static Methods</a><br />
|
|
16
|
+
<a href="#requirements">Requirements</a><br />
|
|
17
|
+
<a href="#properties">Properties</a><br />
|
|
18
|
+
<a href="#methods">Methods</a><br />
|
|
19
|
+
<a href="#events">Events</a><br />
|
|
20
|
+
<a href="#toastContainer">ToastContainer</a><br />
|
|
21
|
+
</div>
|
|
22
|
+
</k-accordion-panel>
|
|
23
|
+
</k-accordion>
|
|
24
|
+
|
|
25
|
+
<h3>Description</h3>
|
|
26
|
+
<p>The Toast component provides a way to display short-lived notifications to users. Toasts appear in a corner of
|
|
27
|
+
the screen, can be configured with different positions, and can optionally include action and close buttons.
|
|
28
|
+
Toasts can be set to automatically close after a specified timeout or remain until manually dismissed.</p>
|
|
29
|
+
|
|
30
|
+
<h3 id="basicUsage"><a href="#basicUsage" class="no-link">Basic Usage</a></h3>
|
|
31
|
+
<div class="row -mx">
|
|
32
|
+
<div class="col d-span-6 t-span-6 m-span-12 px">
|
|
33
|
+
<k-card label="HTML">
|
|
34
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example1"</span>></span>Open Toast<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></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>, () => {<br /> Toast.create(<span class="hljs-string">"Hello World"</span>);<br /> });<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
35
|
+
</k-card>
|
|
36
|
+
</div>
|
|
37
|
+
<div class="col d-span-6 t-span-6 m-span-12 px">
|
|
38
|
+
<k-card label="Results">
|
|
39
|
+
<button id="example1" class="mb">Open Toast</button>
|
|
40
|
+
<script type="module">
|
|
41
|
+
import Toast from '{{pathToRoot}}src/components/Toast.js';
|
|
42
|
+
document.getElementById('example1').addEventListener('click', () => {
|
|
43
|
+
Toast.create("Hello World");
|
|
44
|
+
});
|
|
45
|
+
</script>
|
|
46
|
+
</k-card>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
<h3 id="positions"><a href="#positions" class="no-link">Different Positions</a></h3>
|
|
52
|
+
<p>Toasts can be positioned in different corners of the screen using the <code>position</code> property.</p>
|
|
53
|
+
<div class="row -mx">
|
|
54
|
+
<div class="col d-span-6 t-span-6 m-span-12 px">
|
|
55
|
+
<k-card label="HTML">
|
|
56
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example2-topleft"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"mb"</span>></span>Top Left<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example2-topcenter"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"mb"</span>></span>Top Center<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example2-topright"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"mb"</span>></span>Top Right<span class="hljs-tag"></<span class="hljs-name">button</span>></span><span class="hljs-tag"><<span class="hljs-name">br</span> /></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example2-bottomleft"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"mb"</span>></span>Bottom Left<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example2-bottomcenter"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"mb"</span>></span>Bottom Center<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example2-bottomright"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"mb"</span>></span>Bottom Right<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></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>, () => {<br /> Toast.create(<span class="hljs-string">"Hello 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>, () => {<br /> Toast.create(<span class="hljs-string">"Hello 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>, () => {<br /> Toast.create(<span class="hljs-string">"Hello 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>, () => {<br /> Toast.create(<span class="hljs-string">"Hello 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>, () => {<br /> Toast.create(<span class="hljs-string">"Hello 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>, () => {<br /> Toast.create(<span class="hljs-string">"Hello 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"></<span class="hljs-name">script</span>></span></code></pre>
|
|
57
|
+
</k-card>
|
|
58
|
+
</div>
|
|
59
|
+
<div class="col d-span-6 t-span-6 m-span-12 px">
|
|
60
|
+
<k-card label="Results">
|
|
61
|
+
<button id="example2-topleft" class="mb">Top Left</button>
|
|
62
|
+
<button id="example2-topcenter" class="mb">Top Center</button>
|
|
63
|
+
<button id="example2-topright" class="mb">Top Right</button><br />
|
|
64
|
+
<button id="example2-bottomleft" class="mb">Bottom Left</button>
|
|
65
|
+
<button id="example2-bottomcenter" class="mb">Bottom Center</button>
|
|
66
|
+
<button id="example2-bottomright" class="mb">Bottom Right</button>
|
|
67
|
+
<script type="module">
|
|
68
|
+
import Toast from '{{pathToRoot}}src/components/Toast.js';
|
|
69
|
+
document.getElementById('example2-topleft').addEventListener('click', () => {
|
|
70
|
+
Toast.create("Hello Top Left", {
|
|
71
|
+
position: "top left"
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
document.getElementById('example2-topcenter').addEventListener('click', () => {
|
|
75
|
+
Toast.create("Hello Top Center", {
|
|
76
|
+
position: "top center"
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
document.getElementById('example2-topright').addEventListener('click', () => {
|
|
80
|
+
Toast.create("Hello Top Right", {
|
|
81
|
+
position: "top right"
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
document.getElementById('example2-bottomleft').addEventListener('click', () => {
|
|
85
|
+
Toast.create("Hello Bottom Left", {
|
|
86
|
+
position: "bottom left"
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
document.getElementById('example2-bottomcenter').addEventListener('click', () => {
|
|
90
|
+
Toast.create("Hello Bottom Center", {
|
|
91
|
+
position: "bottom center"
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
document.getElementById('example2-bottomright').addEventListener('click', () => {
|
|
95
|
+
Toast.create("Hello Bottom Right", {
|
|
96
|
+
position: "bottom right"
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
</script>
|
|
100
|
+
</k-card>
|
|
101
|
+
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<h3 id="timeouts"><a href="#timeouts" class="no-link">Timeouts</a></h3>
|
|
106
|
+
<p>Toasts can automatically close after a specified timeout (in milliseconds). The default timeout when using
|
|
107
|
+
<code>Toast.create</code> is <code>5000</code> (ms), or 5 seconds.
|
|
108
|
+
</p>
|
|
109
|
+
<div class="row -mx">
|
|
110
|
+
<div class="col d-span-6 t-span-6 m-span-12 px">
|
|
111
|
+
<k-card label="HTML">
|
|
112
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example3-1"</span>></span>Open 1 Second Timeout Toast<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example3-3"</span>></span>Open 3 Second Timeout Toast<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example3-10"</span>></span>Open 10 Second Timeout Toast<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></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>, () => {<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>, () => {<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>, () => {<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"></<span class="hljs-name">script</span>></span></code></pre>
|
|
113
|
+
</k-card>
|
|
114
|
+
</div>
|
|
115
|
+
<div class="col d-span-6 t-span-6 m-span-12 px">
|
|
116
|
+
<k-card label="Results">
|
|
117
|
+
<button id="example3-1" class="mb">Open 1 Second Timeout Toast</button>
|
|
118
|
+
<button id="example3-3" class="mb">Open 3 Second Timeout Toast</button>
|
|
119
|
+
<button id="example3-10" class="mb">Open 10 Second Timeout Toast</button>
|
|
120
|
+
<script type="module">
|
|
121
|
+
import Toast from '{{pathToRoot}}src/components/Toast.js';
|
|
122
|
+
document.getElementById('example3-1').addEventListener('click', () => {
|
|
123
|
+
Toast.create("I will timeout in 1 second", {
|
|
124
|
+
timeout: 1000
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
document.getElementById('example3-3').addEventListener('click', () => {
|
|
128
|
+
Toast.create("I will timeout in 3 second", {
|
|
129
|
+
timeout: 3000
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
document.getElementById('example3-10').addEventListener('click', () => {
|
|
133
|
+
Toast.create("I will timeout in 10 second", {
|
|
134
|
+
timeout: 10000
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
</script>
|
|
138
|
+
</k-card>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
|
|
142
|
+
<h3 id="actionAndClose"><a href="#actionAndClose" class="no-link">Action and Close Buttons</a></h3>
|
|
143
|
+
<p>Toasts can have action and close buttons that trigger callbacks when clicked.</p>
|
|
144
|
+
<div class="row -mx">
|
|
145
|
+
<div class="col d-span-6 t-span-6 m-span-12 px">
|
|
146
|
+
<k-card label="HTML">
|
|
147
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example4-action"</span>></span>Open Toast with Action<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example4-close"</span>></span>Open Toast with Close Button<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example4-action-close"</span>></span>Open Toast with Action and Close Button<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></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>, () => {<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> =></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>, () => {<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">'<k-icon name="close"></div>'</span>,<br /> <span class="hljs-attr">closeCallback</span>: <span class="hljs-function"><span class="hljs-params">()</span> =></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>, () => {<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> =></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">'<k-icon name="close"></div>'</span>,<br /> <span class="hljs-attr">closeCallback</span>: <span class="hljs-function"><span class="hljs-params">()</span> =></span> {<br /> Toast.create(<span class="hljs-string">"You closed the toast"</span>);<br /> }<br /> });<br /> });<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
148
|
+
</k-card>
|
|
149
|
+
</div>
|
|
150
|
+
<div class="col d-span-6 t-span-6 m-span-12 px">
|
|
151
|
+
<k-card label="Results">
|
|
152
|
+
<button id="example4-action" class="mb">Open Toast with Action</button>
|
|
153
|
+
<button id="example4-close" class="mb">Open Toast with Close Button</button>
|
|
154
|
+
<button id="example4-action-close" class="mb">Open Toast with Action and Close Button</button>
|
|
155
|
+
<script type="module">
|
|
156
|
+
import Toast from '{{pathToRoot}}src/components/Toast.js';
|
|
157
|
+
document.getElementById('example4-action').addEventListener('click', () => {
|
|
158
|
+
Toast.create("Hello World", {
|
|
159
|
+
timeout: 0,
|
|
160
|
+
action: 'Click Me',
|
|
161
|
+
actionCallback: () => {
|
|
162
|
+
Toast.create("You clicked the action");
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
document.getElementById('example4-close').addEventListener('click', () => {
|
|
167
|
+
Toast.create("Hello World", {
|
|
168
|
+
timeout: 0,
|
|
169
|
+
close: '<k-icon name="close"></div>',
|
|
170
|
+
closeCallback: () => {
|
|
171
|
+
Toast.create("You closed the toast");
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
document.getElementById('example4-action-close').addEventListener('click', () => {
|
|
176
|
+
Toast.create("Hello World", {
|
|
177
|
+
timeout: 0,
|
|
178
|
+
action: 'Click Me',
|
|
179
|
+
actionCallback: () => {
|
|
180
|
+
Toast.create("You clicked the action");
|
|
181
|
+
return false; // return false to prevent closing
|
|
182
|
+
},
|
|
183
|
+
close: '<k-icon name="close"></div>',
|
|
184
|
+
closeCallback: () => {
|
|
185
|
+
Toast.create("You closed the toast");
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
</script>
|
|
190
|
+
</k-card>
|
|
191
|
+
</div>
|
|
192
|
+
</div>
|
|
193
|
+
|
|
194
|
+
<h3 id="successWarningError"><a href="#successWarningError" class="no-link">Success, Warning and Error</a></h3>
|
|
195
|
+
<p>Toasts can be created as a success, warning or error message.</p>
|
|
196
|
+
<div class="row -mx">
|
|
197
|
+
<div class="col d-span-6 t-span-6 m-span-12 px">
|
|
198
|
+
<k-card label="HTML">
|
|
199
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example5-success"</span>></span>Success Toast<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example5-warning"</span>></span>Warning Toast<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"example5-error"</span>></span>Error Toast<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"module"</span>></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>, () => {<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>, () => {<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>, () => {<br /> Toast.error(<span class="hljs-string">"That's a very bad idea"</span>);<br /> });<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
200
|
+
</k-card>
|
|
201
|
+
</div>
|
|
202
|
+
<div class="col d-span-6 t-span-6 m-span-12 px">
|
|
203
|
+
<k-card label="Results">
|
|
204
|
+
<button id="example5-success" class="mb">Success Toast</button>
|
|
205
|
+
<button id="example5-warning" class="mb">Warning Toast</button>
|
|
206
|
+
<button id="example5-error" class="mb">Error Toast</button>
|
|
207
|
+
<script type="module">
|
|
208
|
+
import Toast from '{{pathToRoot}}src/components/Toast.js';
|
|
209
|
+
document.getElementById('example5-success').addEventListener('click', () => {
|
|
210
|
+
Toast.success("It Worked!");
|
|
211
|
+
});
|
|
212
|
+
document.getElementById('example5-warning').addEventListener('click', () => {
|
|
213
|
+
Toast.warning("Be Careful");
|
|
214
|
+
});
|
|
215
|
+
document.getElementById('example5-error').addEventListener('click', () => {
|
|
216
|
+
Toast.error("That's a very bad idea");
|
|
217
|
+
});
|
|
218
|
+
</script>
|
|
219
|
+
</k-card>
|
|
220
|
+
</div>
|
|
221
|
+
</div>
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
<h2 id="jsRef"><a href="#jsRef" class="no-link">JavaScript Reference</a></h2>
|
|
225
|
+
|
|
226
|
+
<h3 id="constructor"><a href="#constructor" class="no-link">Constructor</a></h3>
|
|
227
|
+
<h6>Extends <a href="./component.html">Component</a></h6>
|
|
228
|
+
<h5>
|
|
229
|
+
<code>new Toast()</code><br />
|
|
230
|
+
<code>new Toast(<i>object</i> options)</code>
|
|
231
|
+
</h5>
|
|
232
|
+
|
|
233
|
+
<h4>Parameters</h4>
|
|
234
|
+
<h5><code>options<i>: object</i></code></h5>
|
|
235
|
+
<p>An object with the following optional properties:</p>
|
|
236
|
+
<ul>
|
|
237
|
+
<li><code>actionCallback<i>: function</i></code> - Function to call when the action button is clicked. If this
|
|
238
|
+
function returns <code>false</code>, the toast will not close.</li>
|
|
239
|
+
<li><code>actionHtml<i>: string</i></code> - HTML content for the action button.</li>
|
|
240
|
+
<li><code>closeCallback<i>: function</i></code> - Function to call when the toast is closed.</li>
|
|
241
|
+
<li><code>closeHtml<i>: string</i></code> - HTML content for the close button.</li>
|
|
242
|
+
<li><code>timeout<i>: number</i></code> - Time in milliseconds before the toast automatically closes. Default is 0
|
|
243
|
+
(no auto-close).</li>
|
|
244
|
+
</ul>
|
|
245
|
+
|
|
246
|
+
<h3 id="staticMethods"><a href="#staticMethods" class="no-link">Static Methods</a></h3>
|
|
247
|
+
<h5><code>Toast.create(message, options)<i>: Toast</i></code></h5>
|
|
248
|
+
<p>Creates and displays a new toast with the specified message and options. Returns the created Toast instance.</p>
|
|
249
|
+
<p>Options include:</p>
|
|
250
|
+
<ul>
|
|
251
|
+
<li><code>position<i>: string</i></code> - Position of the toast on the screen. Default is 'auto', which uses
|
|
252
|
+
'bottom center' on mobile and 'top right' on desktop. Valid positions are: 'top left', 'top center', 'top
|
|
253
|
+
right', 'bottom left', 'bottom center', 'bottom right'.</li>
|
|
254
|
+
<li><code>removeOnClose<i>: boolean</i></code> - If true, the toast element will be removed from the DOM when
|
|
255
|
+
closed. Default is true.</li>
|
|
256
|
+
<li><code>timeout<i>: number</i></code> - Time in milliseconds before the toast automatically closes. Default is
|
|
257
|
+
5000ms (5 seconds).</li>
|
|
258
|
+
<li><code>action<i>: string | HTMLElement</i></code> - Text or HTML element to use for the action button.</li>
|
|
259
|
+
<li><code>actionCallback<i>: function</i></code> - Function to call when the action button is clicked. If this
|
|
260
|
+
function returns <code>false</code>, the toast will not close.</li>
|
|
261
|
+
<li><code>close<i>: string | HTMLElement</i></code> - Text or HTML element to use for the close button.</li>
|
|
262
|
+
<li><code>closeCallback<i>: function</i></code> - Function to call when the toast is closed.</li>
|
|
263
|
+
<li><code>icon<i>: string | HTMLElement</i></code> - Text or HTML element to use as an icon in the toast.</li>
|
|
264
|
+
</ul>
|
|
265
|
+
|
|
266
|
+
<h5><code>Toast.success(message, options)<i>: Toast</i></code></h5>
|
|
267
|
+
<p>Creates and displays a success toast with a check icon and applies a success background style. Accepts the same
|
|
268
|
+
options as <code>Toast.create()</code>.</p>
|
|
269
|
+
|
|
270
|
+
<h5><code>Toast.warning(message, options)<i>: Toast</i></code></h5>
|
|
271
|
+
<p>Creates and displays a warning toast with a warning icon and applies a warning background style. Accepts the same
|
|
272
|
+
options as <code>Toast.create()</code>.</p>
|
|
273
|
+
|
|
274
|
+
<h5><code>Toast.error(message, options)<i>: Toast</i></code></h5>
|
|
275
|
+
<p>Creates and displays an error toast with an error icon and applies a danger background style. Accepts the same
|
|
276
|
+
options as <code>Toast.create()</code>.</p>
|
|
277
|
+
|
|
278
|
+
<h3 id="requirements"><a href="#requirements" class="no-link">Requirements</a></h3>
|
|
279
|
+
<ul>
|
|
280
|
+
<li>ShadowComponent (configure <code>ShadowComponent.pathToStylesheet</code> as needed for your server)</li>
|
|
281
|
+
<li><a href="./icon.html">Icon</a></li>
|
|
282
|
+
</ul>
|
|
283
|
+
|
|
284
|
+
<h3 id="properties"><a href="#properties" class="no-link">Properties</a></h3>
|
|
285
|
+
<h5><code>actionHtml<i>: string</i></code></h5>
|
|
286
|
+
<p>HTML content for the action button. Syncs to <code>action-html</code> attribute.</p>
|
|
287
|
+
|
|
288
|
+
<h5><code>closeHtml<i>: string</i></code></h5>
|
|
289
|
+
<p>HTML content for the close button. Syncs to <code>close-html</code> attribute.</p>
|
|
290
|
+
|
|
291
|
+
<h5><code>timeout<i>: number</i></code></h5>
|
|
292
|
+
<p>Time in milliseconds before the toast automatically closes. Default is 0 (no auto-close). Syncs to
|
|
293
|
+
<code>timeout</code> attribute.
|
|
294
|
+
</p>
|
|
295
|
+
|
|
296
|
+
<h5><code>opened<i>: boolean</i></code></h5>
|
|
297
|
+
<p>Whether the toast is currently open. Default is false. Syncs to <code>opened</code> attribute.</p>
|
|
298
|
+
|
|
299
|
+
<h5><code>actionCallback<i>: function</i></code></h5>
|
|
300
|
+
<p>Function to call when the action button is clicked.</p>
|
|
301
|
+
|
|
302
|
+
<h5><code>closeCallback<i>: function</i></code></h5>
|
|
303
|
+
<p>Function to call when the toast is closed.</p>
|
|
304
|
+
|
|
305
|
+
<h3 id="methods"><a href="#methods" class="no-link">Methods</a></h3>
|
|
306
|
+
<h5><code>open()<i>: void</i></code></h5>
|
|
307
|
+
<p>Opens the toast. If a timeout is specified, this starts the timer for automatic closing.</p>
|
|
308
|
+
|
|
309
|
+
<h5><code>close()<i>: void</i></code></h5>
|
|
310
|
+
<p>Closes the toast and calls the <code>closeCallback</code> if provided.</p>
|
|
311
|
+
|
|
312
|
+
<h3 id="events"><a href="#events" class="no-link">Events</a></h3>
|
|
313
|
+
<h5><code>open</code></h5>
|
|
314
|
+
<p>Fired when the toast is opened.</p>
|
|
315
|
+
|
|
316
|
+
<h5><code>close</code></h5>
|
|
317
|
+
<p>Fired when the toast is closed.</p>
|
|
318
|
+
|
|
319
|
+
<h5><code>openchange</code></h5>
|
|
320
|
+
<p>Fired when the toast open state changes (both when opening and closing).</p>
|
|
321
|
+
|
|
322
|
+
<h3 id="toastContainer"><a href="#toastContainer" class="no-link">ToastContainer</a></h3>
|
|
323
|
+
<p>The <code>ToastContainer</code> is an internal component used to position and display toasts. It is automatically
|
|
324
|
+
created when <code>Toast.create()</code> is called, but can also be used directly.</p>
|
|
325
|
+
|
|
326
|
+
<h5><code>new ToastContainer(position)</code></h5>
|
|
327
|
+
<p>Creates a new toast container at the specified position.</p>
|
|
328
|
+
|
|
329
|
+
<h5><code>position<i>: string</i></code></h5>
|
|
330
|
+
<p>The position of the container on the screen. Valid values are: 'top left', 'top center', 'top right', 'bottom
|
|
331
|
+
left', 'bottom center', 'bottom right'.</p>
|
|
332
|
+
</content>
|
|
333
|
+
<content location="scripts">
|
|
334
|
+
<script type="module" src="{{pathToRoot}}src/components/Toast.js"></script>
|
|
335
|
+
<script type="module" src="{{pathToRoot}}src/components/Accordion.js"></script>
|
|
336
|
+
<script type="module" src="{{pathToRoot}}src/components/Card.js"></script>
|
|
337
|
+
</content>
|
|
338
|
+
</page>
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
<page pageName="Toggle" title="Toggle - Components - Kempo Docs - A Web Components Solution">
|
|
2
|
+
<content>
|
|
3
|
+
<k-accordion persistent-id="toc" class="b r mb">
|
|
4
|
+
<k-accordion-header for-panel="toc-panel">Table of Contents</k-accordion-header>
|
|
5
|
+
<k-accordion-panel name="toc-panel">
|
|
6
|
+
<div class="m pl">
|
|
7
|
+
<h6>Examples</h6>
|
|
8
|
+
<a href="#basicUsage">Basic Usage</a><br />
|
|
9
|
+
<a href="#onByDefault">On By Default</a><br />
|
|
10
|
+
<a href="#responsiveBehavior">Responsive Behavior</a><br />
|
|
11
|
+
<a href="#customStyles">Custom Styles</a><br />
|
|
12
|
+
<a href="#javascriptUsage">JavaScript Usage</a><br />
|
|
13
|
+
<a href="#disabled">Disabled</a><br />
|
|
14
|
+
|
|
15
|
+
<h6 class="mt"><a href="jsRef" class="no-link">JavaScript Reference</a></h6>
|
|
16
|
+
<a href="#constructor">Constructor</a><br />
|
|
17
|
+
<a href="#requirements">Requirements</a><br />
|
|
18
|
+
<a href="#properties">Properties</a><br />
|
|
19
|
+
<a href="#methods">Methods</a><br />
|
|
20
|
+
</div>
|
|
21
|
+
</k-accordion-panel>
|
|
22
|
+
</k-accordion>
|
|
23
|
+
|
|
24
|
+
<h3 id="basicUsage"><a href="#basicUsage" class="no-link">Basic Usage</a></h3>
|
|
25
|
+
<div class="row -mx">
|
|
26
|
+
<div class="col m-span-12 px">
|
|
27
|
+
<k-card label="HTML">
|
|
28
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-toggle</span>></span>Toggle Me<span class="hljs-tag"></<span class="hljs-name">k-toggle</span>></span></code></pre>
|
|
29
|
+
</k-card>
|
|
30
|
+
</div>
|
|
31
|
+
<div class="col m-span-12 px">
|
|
32
|
+
<k-card label="Output">
|
|
33
|
+
<k-toggle>Toggle Me</k-toggle>
|
|
34
|
+
</k-card>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<h3 id="onByDefault"><a href="#onByDefault" class="no-link">On By Default</a></h3>
|
|
39
|
+
<div class="row -mx">
|
|
40
|
+
<div class="col m-span-12 px">
|
|
41
|
+
<k-card label="HTML">
|
|
42
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-toggle</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"true"</span>></span>Toggle Me<span class="hljs-tag"></<span class="hljs-name">k-toggle</span>></span></code></pre>
|
|
43
|
+
</k-card>
|
|
44
|
+
</div>
|
|
45
|
+
<div class="col m-span-12 px">
|
|
46
|
+
<k-card label="Output">
|
|
47
|
+
<k-toggle value="true">Toggle Me</k-toggle>
|
|
48
|
+
</k-card>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<h3 id="responsiveBehavior"><a href="#responsiveBehavior" class="no-link">Responsive Behavior</a></h3>
|
|
53
|
+
<p>The visual toggle maintains its size even in narrow containers. Only the label shrinks to fit the available space.</p>
|
|
54
|
+
<div class="row -mx">
|
|
55
|
+
<div class="col m-span-12 px">
|
|
56
|
+
<k-card label="HTML">
|
|
57
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"width: 150px;"</span>></span><br /> <span class="hljs-tag"><<span class="hljs-name">k-toggle</span>></span>A very long label that should shrink<span class="hljs-tag"></<span class="hljs-name">k-toggle</span>></span><br /><span class="hljs-tag"></<span class="hljs-name">div</span>></span></code></pre>
|
|
58
|
+
</k-card>
|
|
59
|
+
</div>
|
|
60
|
+
<div class="col m-span-12 px">
|
|
61
|
+
<k-card label="Output">
|
|
62
|
+
<div style="width: 150px;">
|
|
63
|
+
<k-toggle>A very long label that should shrink</k-toggle>
|
|
64
|
+
</div>
|
|
65
|
+
</k-card>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
<h3 id="customStyles"><a href="#customStyles" class="no-link">Custom Styles</a></h3>
|
|
70
|
+
<div class="row -mx">
|
|
71
|
+
<div class="col m-span-12 px">
|
|
72
|
+
<k-card label="HTML">
|
|
73
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-toggle</span> <br /> <span class="hljs-attr">style</span>=<span class="hljs-string">"<br /> --switch_height: 3rem;<br /> --switch_width: 5rem;<br /> --switch_border: none;<br /> --switch_background__off: var(--c_danger);<br /> --switch_background__on: var(--c_success);<br /> --handle_size__off: 2rem;<br /> --handle_size__on: calc(3rem - 2px);<br /> --handle_border: none;<br /> --handle_background__off: #ddd;<br /> --handle_background__on: white;<br /> "</span><br />></span>Toggle Me<span class="hljs-tag"></<span class="hljs-name">k-toggle</span>></span></code></pre>
|
|
74
|
+
</k-card>
|
|
75
|
+
</div>
|
|
76
|
+
<div class="col m-span-12 px">
|
|
77
|
+
<k-card label="Output">
|
|
78
|
+
<k-toggle
|
|
79
|
+
style="
|
|
80
|
+
--switch_height: 3rem;
|
|
81
|
+
--switch_width: 5rem;
|
|
82
|
+
--switch_border: none;
|
|
83
|
+
--switch_background__off: var(--c_danger);
|
|
84
|
+
--switch_background__on: var(--c_success);
|
|
85
|
+
--handle_size__off: 2rem;
|
|
86
|
+
--handle_size__on: calc(3rem - 2px);
|
|
87
|
+
--handle_border: none;
|
|
88
|
+
--handle_background__off: #ddd;
|
|
89
|
+
--handle_background__on: white;
|
|
90
|
+
"
|
|
91
|
+
>Toggle Me</k-toggle>
|
|
92
|
+
</k-card>
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
<h3 id="javascriptUsage"><a href="#javascriptUsage" class="no-link">JavaScript Usage</a></h3>
|
|
97
|
+
<div class="row -mx">
|
|
98
|
+
<div class="col m-span-12 px">
|
|
99
|
+
<k-card label="HTML">
|
|
100
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-toggle</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"tog1"</span>></span>Toggle Me<span class="hljs-tag"></<span class="hljs-name">k-toggle</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"turnOn"</span>></span>Turn On<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"turnOff"</span>></span>Turn Off<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"toggle"</span>></span>Toggle<span class="hljs-tag"></<span class="hljs-name">button</span>></span><br /><span class="hljs-tag"><<span class="hljs-name">script</span>></span><span class="javascript"><br /> <span class="hljs-keyword">const</span> $tog1 = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'tog1'</span>);<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'turnOn'</span>).addEventListener(<span class="hljs-string">'click'</span>, ()=>{<br /> $tog1.on();<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'turnOff'</span>).addEventListener(<span class="hljs-string">'click'</span>, ()=>{<br /> $tog1.off();<br /> });<br /> <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'toggle'</span>).addEventListener(<span class="hljs-string">'click'</span>, ()=>{<br /> $tog1.toggle();<br /> });<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
101
|
+
</k-card>
|
|
102
|
+
</div>
|
|
103
|
+
<div class="col m-span-12 px">
|
|
104
|
+
<k-card label="Output">
|
|
105
|
+
<k-toggle id="tog1">Toggle Me</k-toggle>
|
|
106
|
+
<button id="turnOn">Turn On</button>
|
|
107
|
+
<button id="turnOff">Turn Off</button>
|
|
108
|
+
<button id="toggle">Toggle</button>
|
|
109
|
+
<script>
|
|
110
|
+
const $tog1 = document.getElementById('tog1');
|
|
111
|
+
document.getElementById('turnOn').addEventListener('click', ()=>{
|
|
112
|
+
$tog1.on();
|
|
113
|
+
});
|
|
114
|
+
document.getElementById('turnOff').addEventListener('click', ()=>{
|
|
115
|
+
$tog1.off();
|
|
116
|
+
});
|
|
117
|
+
document.getElementById('toggle').addEventListener('click', ()=>{
|
|
118
|
+
$tog1.toggle();
|
|
119
|
+
});
|
|
120
|
+
</script>
|
|
121
|
+
</k-card>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<h3 id="disabled"><a href="#disabled" class="no-link">Disabled</a></h3>
|
|
126
|
+
<p>The <code>disabled</code> attribute prevents the user from changing the toggle's state while still displaying its current value.</p>
|
|
127
|
+
<div class="row -mx">
|
|
128
|
+
<div class="col m-span-12 px">
|
|
129
|
+
<k-card label="HTML">
|
|
130
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-toggle</span> <span class="hljs-attr">disabled</span>></span>Disabled Off<span class="hljs-tag"></<span class="hljs-name">k-toggle</span>></span><br><span class="hljs-tag"><<span class="hljs-name">k-toggle</span> <span class="hljs-attr">disabled</span> <span class="hljs-attr">value</span>></span>Disabled On<span class="hljs-tag"></<span class="hljs-name">k-toggle</span>></span></code></pre>
|
|
131
|
+
</k-card>
|
|
132
|
+
</div>
|
|
133
|
+
<div class="col m-span-12 px">
|
|
134
|
+
<k-card label="Output">
|
|
135
|
+
<k-toggle disabled>Disabled Off</k-toggle>
|
|
136
|
+
<k-toggle disabled value>Disabled On</k-toggle>
|
|
137
|
+
</k-card>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
|
|
141
|
+
<h2 id="jsRef"><a href="jsRef" class="no-link">JavaScript Reference</a></h2>
|
|
142
|
+
|
|
143
|
+
<h3 id="constructor"><a href="#constructor" class="no-link">Constructor</a></h3>
|
|
144
|
+
<h6>Extends <a href="./component.html">Component</a></h6>
|
|
145
|
+
<h5>
|
|
146
|
+
<code>new Toggle()</code>
|
|
147
|
+
</h5>
|
|
148
|
+
|
|
149
|
+
<h3 id="requirements"><a href="#requirements" class="no-link">Requirements</a></h3>
|
|
150
|
+
<ul>
|
|
151
|
+
<li><a href="./component.html">Component</a></li>
|
|
152
|
+
</ul>
|
|
153
|
+
|
|
154
|
+
<h3 id="properties"><a href="#properties" class="no-link">Properties</a></h3>
|
|
155
|
+
<h5><code>value<i>: boolean</i></code></h5>
|
|
156
|
+
<p>A boolean that indicates if the switch is on or off, the default value is <code>false</code>. Syncs to <code>value</code> attribute.</p>
|
|
157
|
+
<p>This can be set directly, but it is not recommended as it only triggers the a <code>change</code> event and not a <code>on</code>, <code>off</code> or <code>toggle</code> event as the methods do, so the methods are preferrable.</p>
|
|
158
|
+
|
|
159
|
+
<h5><code>disabled<i>: boolean</i></code></h5>
|
|
160
|
+
<p>When <code>true</code>, the toggle cannot be changed by user interaction. The current state is still displayed. The element will appear at 50% opacity. Syncs to <code>disabled</code> attribute.</p>
|
|
161
|
+
|
|
162
|
+
<h3 id="methods"><a href="#methods" class="no-link">Methods</a></h3>
|
|
163
|
+
<h5><code>on()<i>: this</i></code></h5>
|
|
164
|
+
<p>Set's the <code>value</code> to <code>true</code>, dispatches a <code><i>change</i></code> and an <code><i>on</i></code> event. The switch visual changes to the <b>on</b> state.</p>
|
|
165
|
+
|
|
166
|
+
<h5><code>off()<i>: this</i></code></h5>
|
|
167
|
+
<p>Set's the <code>value</code> to <code>false</code>, dispatches a <code><i>change</i></code> and an <code><i>off</i></code> event. The switch visual changes to the <b>off</b> state.</p>
|
|
168
|
+
|
|
169
|
+
<h5><code>toggle()<i>: this</i></code></h5>
|
|
170
|
+
<p>Negates the <code>value</code>, if it is <code>true</code> it is now set to <code>false</code>, but if it is <code>false</code> it is now set to <code>true</code>. It also dispatches dispatches a <code><i>change</i></code> and an <code><i>on</i></code> or <code><i>off</i></code> event. The switch visual changes to the oposite state.</p>
|
|
171
|
+
</content>
|
|
172
|
+
<content location="scripts">
|
|
173
|
+
<script type="module" src="{{pathToRoot}}src/components/Toggle.js"></script>
|
|
174
|
+
<script type="module" src="{{pathToRoot}}src/components/Accordion.js"></script>
|
|
175
|
+
<script type="module" src="{{pathToRoot}}src/components/Card.js"></script>
|
|
176
|
+
</content>
|
|
177
|
+
</page>
|