kempo-ui 0.0.9 → 0.0.10
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/dist/src/components/Card.js +3 -3
- package/dist/src/components/Dialog.js +11 -11
- package/dist/src/components/Icon.js +1 -1
- package/dist/src/components/Toggle.js +15 -14
- package/dist/src/components/Tree.js +11 -3
- package/docs/components/accordion.html +2 -3
- package/docs/components/card.html +2 -3
- package/docs/components/collapsible.html +2 -3
- package/docs/components/content-slider.html +2 -3
- package/docs/components/dialog.html +2 -2
- package/docs/components/focus-capture.html +2 -3
- package/docs/components/hybrid-component.html +2 -3
- package/docs/components/icon.html +4 -5
- package/docs/components/import.html +2 -3
- package/docs/components/light-component.html +2 -3
- package/docs/components/persistant-collapsible.html +19 -37
- package/docs/components/photo-viewer.html +129 -84
- package/docs/components/resize.html +2 -3
- package/docs/components/shadow-component.html +2 -3
- package/docs/components/show-more.html +2 -4
- package/docs/components/side-menu.html +2 -3
- package/docs/components/sortable.html +3 -3
- package/docs/components/split.html +2 -3
- package/docs/components/table.html +2 -3
- package/docs/components/tableControls.html +2 -3
- package/docs/components/tableCustomFields.html +2 -3
- package/docs/components/tableFetchRecords.html +2 -3
- package/docs/components/tableFieldSortHide.html +2 -3
- package/docs/components/tablePagination.html +2 -3
- package/docs/components/tableRecordEditing.html +2 -3
- package/docs/components/tableRecordFiltering.html +2 -3
- package/docs/components/tableRecordHiding.html +2 -3
- package/docs/components/tableRecordSearching.html +2 -3
- package/docs/components/tableRecordSelection.html +2 -3
- package/docs/components/tableRowControls.html +2 -3
- package/docs/components/tableSorting.html +2 -3
- package/docs/components/tabs.html +89 -70
- package/docs/components/tags.html +45 -16
- package/docs/components/theme-switcher.html +3 -4
- package/docs/components/timestamp.html +40 -10
- package/docs/components/toast.html +3 -2
- package/docs/components/toggle.html +3 -5
- package/docs/components/tree.html +76 -64
- package/docs/src/components/Card.js +3 -3
- package/docs/src/components/Dialog.js +11 -11
- package/docs/src/components/Icon.js +1 -1
- package/docs/src/components/Toggle.js +15 -14
- package/docs/src/components/Tree.js +11 -3
- package/docs/utils/debounce.html +5 -24
- package/docs/utils/drag.html +3 -13
- package/docs/utils/formatTimestamp.html +7 -25
- package/docs/utils/propConverters.html +7 -46
- package/docs/utils/toTitleCase.html +2 -2
- package/docs/utils/watchWindowSize.html +7 -98
- package/package.json +1 -1
- package/src/components/Card.js +3 -0
- package/src/components/Toggle.js +69 -69
- package/src/components/Tree.js +10 -2
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Toggle - Components - Kempo Docs - A Web Components Solution</title>
|
|
7
|
-
<link rel="stylesheet" href="../
|
|
8
|
-
<link rel="stylesheet" href="../
|
|
7
|
+
<link rel="stylesheet" href="../kempo-vars.css" /><link rel="stylesheet" href="../kempo.min.css" />
|
|
8
|
+
<link rel="stylesheet" href="../kempo-hljs.css" />
|
|
9
9
|
<link rel="stylesheet" href="../styles.css" />
|
|
10
10
|
<script type="module" src="./init.js"></script>
|
|
11
11
|
</head>
|
|
@@ -143,8 +143,6 @@
|
|
|
143
143
|
<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>
|
|
144
144
|
|
|
145
145
|
</main>
|
|
146
|
-
<div style="height:33vh"></div>
|
|
147
|
-
<script type="module" src="../src/components/Import.js"></script>
|
|
148
|
-
<script type="module" src="../src/components/Toggle.js"></script>
|
|
146
|
+
<div style="height:33vh"></div><script type="module" src="../src/components/Toggle.js"></script>
|
|
149
147
|
</body>
|
|
150
148
|
</html>
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Tree - Components - Kempo Docs - A Web Components Solution</title>
|
|
7
|
-
<link rel="stylesheet" href="../
|
|
8
|
-
<link rel="stylesheet" href="../
|
|
7
|
+
<link rel="stylesheet" href="../kempo-vars.css" /><link rel="stylesheet" href="../kempo.css" />
|
|
8
|
+
<link rel="stylesheet" href="../kempo-hljs.css" />
|
|
9
9
|
<link rel="stylesheet" href="../styles.css" />
|
|
10
10
|
<script type="module" src="./init.js"></script>
|
|
11
11
|
</head>
|
|
@@ -33,24 +33,28 @@
|
|
|
33
33
|
<p>Create a tree using the <code>k-tree</code> component. Set your data by setting the <code>data</code> property.</p>
|
|
34
34
|
<div class="row -mx mb">
|
|
35
35
|
<div class="col d-span-6 m-span-12 px">
|
|
36
|
-
<
|
|
36
|
+
<k-card label="HTML">
|
|
37
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-tree</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"myTree"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-tree</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> Tree <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/components/Tree.js'</span>;<br /> <span class="hljs-keyword">const</span> tree = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myTree'</span>);<br /> tree.data = {<br /> <span class="hljs-attr">name</span>: <span class="hljs-string">'John Doe'</span>,<br /> <span class="hljs-attr">age</span>: <span class="hljs-number">30</span>,<br /> <span class="hljs-attr">active</span>: <span class="hljs-literal">true</span>,<br /> <span class="hljs-attr">hobbies</span>: [<span class="hljs-string">'reading'</span>, <span class="hljs-string">'coding'</span>],<br /> <span class="hljs-attr">address</span>: {<br /> <span class="hljs-attr">street</span>: <span class="hljs-string">'123 Main St'</span>,<br /> <span class="hljs-attr">city</span>: <span class="hljs-string">'New York'</span><br /> }<br /> };<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
38
|
+
</k-card>
|
|
37
39
|
</div>
|
|
38
40
|
<div class="col d-span-6 m-span-12 px">
|
|
39
|
-
<k-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
<k-card label="Output">
|
|
42
|
+
<k-tree id="myTree"></k-tree>
|
|
43
|
+
<script type="module">
|
|
44
|
+
import Tree from '../src/components/Tree.js';
|
|
45
|
+
const tree = document.getElementById('myTree');
|
|
46
|
+
tree.data = {
|
|
47
|
+
name: 'John Doe',
|
|
48
|
+
age: 30,
|
|
49
|
+
active: true,
|
|
50
|
+
hobbies: ['reading', 'coding'],
|
|
51
|
+
address: {
|
|
52
|
+
street: '123 Main St',
|
|
53
|
+
city: 'New York'
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
</script>
|
|
57
|
+
</k-card>
|
|
54
58
|
</div>
|
|
55
59
|
</div>
|
|
56
60
|
|
|
@@ -58,26 +62,30 @@
|
|
|
58
62
|
<p>Use the <code>depth</code> attribute to control how many levels of branches are open by default. This example shows depth set to <code>2</code>:</p>
|
|
59
63
|
<div class="row -mx mb">
|
|
60
64
|
<div class="col d-span-6 m-span-12 px">
|
|
61
|
-
<
|
|
65
|
+
<k-card label="HTML">
|
|
66
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-tree</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"depthTree"</span> <span class="hljs-attr">depth</span>=<span class="hljs-string">"2"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-tree</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> Tree <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/components/Tree.js'</span>;<br /> <span class="hljs-keyword">const</span> tree = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'depthTree'</span>);<br /> tree.data = {<br /> <span class="hljs-attr">company</span>: <span class="hljs-string">'Tech Corp'</span>,<br /> <span class="hljs-attr">departments</span>: {<br /> <span class="hljs-attr">engineering</span>: {<br /> <span class="hljs-attr">frontend</span>: [<span class="hljs-string">'Alice'</span>, <span class="hljs-string">'Bob'</span>],<br /> <span class="hljs-attr">backend</span>: [<span class="hljs-string">'Charlie'</span>, <span class="hljs-string">'Diana'</span>]<br /> },<br /> <span class="hljs-attr">sales</span>: {<br /> <span class="hljs-attr">team</span>: [<span class="hljs-string">'Eve'</span>, <span class="hljs-string">'Frank'</span>]<br /> }<br /> }<br /> };<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
67
|
+
</k-card>
|
|
62
68
|
</div>
|
|
63
69
|
<div class="col d-span-6 m-span-12 px">
|
|
64
|
-
<k-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
<k-card label="Output">
|
|
71
|
+
<k-tree id="depthTree" depth="2"></k-tree>
|
|
72
|
+
<script type="module">
|
|
73
|
+
import Tree from '../src/components/Tree.js';
|
|
74
|
+
const tree = document.getElementById('depthTree');
|
|
75
|
+
tree.data = {
|
|
76
|
+
company: 'Tech Corp',
|
|
77
|
+
departments: {
|
|
78
|
+
engineering: {
|
|
79
|
+
frontend: ['Alice', 'Bob'],
|
|
80
|
+
backend: ['Charlie', 'Diana']
|
|
81
|
+
},
|
|
82
|
+
sales: {
|
|
83
|
+
team: ['Eve', 'Frank']
|
|
84
|
+
}
|
|
77
85
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
</
|
|
86
|
+
};
|
|
87
|
+
</script>
|
|
88
|
+
</k-card>
|
|
81
89
|
</div>
|
|
82
90
|
</div>
|
|
83
91
|
|
|
@@ -85,40 +93,44 @@
|
|
|
85
93
|
<p>You can define custom leaf types to handle specific data types. Create a class that extends <code>TreeLeaf</code>, implement a <code>detect</code> static method that checks for specific properties, and a <code>render</code> method, then register it with <code>Tree.addLeaf()</code>.</p>
|
|
86
94
|
<div class="row -mx mb">
|
|
87
95
|
<div class="col d-span-6 m-span-12 px">
|
|
88
|
-
<
|
|
96
|
+
<k-card label="HTML">
|
|
97
|
+
<pre><code class="hljs xml"><span class="hljs-tag"><<span class="hljs-name">k-tree</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"customTree"</span>></span><span class="hljs-tag"></<span class="hljs-name">k-tree</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> Tree, { TreeLeaf } <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/components/Tree.js'</span>;<br /> <span class="hljs-keyword">import</span> { html } <span class="hljs-keyword">from</span> <span class="hljs-string">'../src/lit-all.min.js'</span>;<br /><br /> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">DateLeaf</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">TreeLeaf</span> </span>{<br /> render(){<br /> <span class="hljs-keyword">const</span> { month, day, year } = <span class="hljs-keyword">this</span>.value;<br /> <span class="hljs-keyword">return</span> html`<span class="xml"><span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"tc-warning"</span>></span>📅 </span><span class="hljs-subst">${month}</span><span class="xml">/</span><span class="hljs-subst">${day}</span><span class="xml">/</span><span class="hljs-subst">${year}</span><span class="xml"><span class="hljs-tag"></<span class="hljs-name">span</span>></span>`</span>;<br /> }<br /><br /> <span class="hljs-keyword">static</span> detect = <span class="hljs-function"><span class="hljs-params">value</span> =></span> {<br /> <span class="hljs-keyword">return</span> <span class="hljs-keyword">typeof</span> value === <span class="hljs-string">'object'</span> <br /> && value !== <span class="hljs-literal">null</span><br /> && <span class="hljs-string">'month'</span> <span class="hljs-keyword">in</span> value <br /> && <span class="hljs-string">'day'</span> <span class="hljs-keyword">in</span> value <br /> && <span class="hljs-string">'year'</span> <span class="hljs-keyword">in</span> value;<br /> };<br /> }<br /><br /> Tree.addLeaf(DateLeaf);<br /><br /> <span class="hljs-keyword">const</span> tree = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'customTree'</span>);<br /> tree.data = {<br /> <span class="hljs-attr">event</span>: <span class="hljs-string">'Tech Conference 2025'</span>,<br /> <span class="hljs-attr">startDate</span>: { <span class="hljs-attr">month</span>: <span class="hljs-number">10</span>, <span class="hljs-attr">day</span>: <span class="hljs-number">15</span>, <span class="hljs-attr">year</span>: <span class="hljs-number">2025</span> },<br /> <span class="hljs-attr">endDate</span>: { <span class="hljs-attr">month</span>: <span class="hljs-number">10</span>, <span class="hljs-attr">day</span>: <span class="hljs-number">17</span>, <span class="hljs-attr">year</span>: <span class="hljs-number">2025</span> },<br /> <span class="hljs-attr">location</span>: <span class="hljs-string">'San Francisco'</span>,<br /> <span class="hljs-attr">attendees</span>: <span class="hljs-number">250</span><br /> };<br /></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></code></pre>
|
|
98
|
+
</k-card>
|
|
89
99
|
</div>
|
|
90
100
|
<div class="col d-span-6 m-span-12 px">
|
|
91
|
-
<k-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
<k-card label="Output">
|
|
102
|
+
<k-tree id="customTree"></k-tree>
|
|
103
|
+
<script type="module">
|
|
104
|
+
import Tree, { TreeLeaf } from '../src/components/Tree.js';
|
|
105
|
+
import { html } from '../src/lit-all.min.js';
|
|
106
|
+
|
|
107
|
+
class DateLeaf extends TreeLeaf {
|
|
108
|
+
render(){
|
|
109
|
+
const { month, day, year } = this.value;
|
|
110
|
+
return html`<span class="tc-warning">📅 ${month}/${day}/${year}</span>`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static detect = value => {
|
|
114
|
+
return typeof value === 'object'
|
|
115
|
+
&& value !== null
|
|
116
|
+
&& 'month' in value
|
|
117
|
+
&& 'day' in value
|
|
118
|
+
&& 'year' in value;
|
|
119
|
+
};
|
|
100
120
|
}
|
|
101
121
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
122
|
+
Tree.addLeaf(DateLeaf);
|
|
123
|
+
|
|
124
|
+
const tree = document.getElementById('customTree');
|
|
125
|
+
tree.data = {
|
|
126
|
+
event: 'Tech Conference 2025',
|
|
127
|
+
startDate: { month: 10, day: 15, year: 2025 },
|
|
128
|
+
endDate: { month: 10, day: 17, year: 2025 },
|
|
129
|
+
location: 'San Francisco',
|
|
130
|
+
attendees: 250
|
|
108
131
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
Tree.addLeaf(DateLeaf);
|
|
112
|
-
|
|
113
|
-
const tree = document.getElementById('customTree');
|
|
114
|
-
tree.data = {
|
|
115
|
-
event: 'Tech Conference 2025',
|
|
116
|
-
startDate: { month: 10, day: 15, year: 2025 },
|
|
117
|
-
endDate: { month: 10, day: 17, year: 2025 },
|
|
118
|
-
location: 'San Francisco',
|
|
119
|
-
attendees: 250
|
|
120
|
-
};
|
|
121
|
-
</script>
|
|
132
|
+
</script>
|
|
133
|
+
</k-card>
|
|
122
134
|
</div>
|
|
123
135
|
</div>
|
|
124
136
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ShadowComponent from"./ShadowComponent.js";import{html,css}from"../lit-all.min.js";export default class Card extends ShadowComponent{static properties={label:{type:String,reflect:!0}};constructor(){super(),this.label=
|
|
1
|
+
import ShadowComponent from"./ShadowComponent.js";import{html,css}from"../lit-all.min.js";export default class Card extends ShadowComponent{static properties={label:{type:String,reflect:!0}};constructor(){super(),this.label=null}static styles=css`
|
|
2
2
|
:host {
|
|
3
3
|
display: block;
|
|
4
4
|
}
|
|
@@ -20,11 +20,11 @@ import ShadowComponent from"./ShadowComponent.js";import{html,css}from"../lit-al
|
|
|
20
20
|
padding: var(--spacer_h);
|
|
21
21
|
}
|
|
22
22
|
:host([label]) {
|
|
23
|
-
padding-top:
|
|
24
|
-
margin-top: var(--spacer);
|
|
23
|
+
padding-top: 0.1px; /* Prevent Collapsing Margins */
|
|
25
24
|
}
|
|
26
25
|
:host([label]) #card {
|
|
27
26
|
padding-top: calc(1.5 * var(--spacer));
|
|
27
|
+
margin-top: var(--spacer);
|
|
28
28
|
}
|
|
29
29
|
:host(:not([label])) #label {
|
|
30
30
|
display: none;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ShadowComponent from"./ShadowComponent.js";import{html,css}from"../lit-all.min.js";import{boolExists}from"../utils/propConverters.js";import"./Icon.js";import"./FocusCapture.js";const firstFocusable=
|
|
1
|
+
import ShadowComponent from"./ShadowComponent.js";import{html,css}from"../lit-all.min.js";import{boolExists}from"../utils/propConverters.js";import"./Icon.js";import"./FocusCapture.js";const firstFocusable=e=>e.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')[0];export default class Dialog extends ShadowComponent{static properties={opened:{type:Boolean,reflect:!0,converter:boolExists},closeBtn:{type:Boolean,reflect:!0,attribute:"close-btn",converter:boolExists},overlayClose:{type:Boolean,reflect:!0,attribute:"overlay-close",converter:boolExists},confirmText:{type:String,reflect:!0,attribute:"confirm-text"},confirmClasses:{type:String,reflect:!0,attribute:"confirm-classes"},cancelText:{type:String,reflect:!0,attribute:"cancel-text"},cancelClasses:{type:String,reflect:!0,attribute:"cancel-classes"}};constructor(){super(),this.opened=!1,this.closeBtn=!0,this.overlayClose=!0,this.confirmText="",this.confirmClasses="success ml",this.cancelText="",this.cancelClasses="",this.confirmAction=()=>{},this.cancelAction=()=>{},this.closeCallback=()=>{},this.previousFocus=null}handleClick=e=>{const{target:t}=e,o=t.id||t.closest("[id]")?.id;"overlay"===o&&this.overlayClose||"close"===o?this.close():"cancel"===o?(this.cancelAction(e),e.defaultPrevented||this.close()):"confirm"===o&&(this.confirmAction(e),e.defaultPrevented||this.close())};handleKeydown=e=>{27===e.keyCode&&this.close()};connectedCallback(){super.connectedCallback()}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("keydown",this.handleKeydown)}updated(e){super.updated(e),e.has("opened")&&this.dispatchEvent(new CustomEvent(this.opened?"opened":"close"))}open(){this.opened=!0,window.addEventListener("keydown",this.handleKeydown);const e=this.updateComplete||this.requestUpdate();e&&e.then?e.then(()=>{const e=this.shadowRoot.querySelector("[autofocus]")||firstFocusable(this.shadowRoot);e&&e.focus()}):setTimeout(()=>{const e=this.shadowRoot.querySelector("[autofocus]")||firstFocusable(this.shadowRoot);e&&e.focus()},0)}close(){this.opened=!1,this.blur(),this.closeCallback(),window.removeEventListener("keydown",this.handleKeydown)}toggle(){this.opened?this.close():this.open()}focus(){const e=firstFocusable(this.shadowRoot);e&&(this.previousFocus=document.activeElement,e.focus())}blur(){this.previousFocus&&this.previousFocus.focus()}hasTitle(){return!!this.querySelector('[slot="title"]')}static styles=css`
|
|
2
2
|
:host {
|
|
3
3
|
position: fixed;
|
|
4
4
|
top: 0;
|
|
@@ -77,13 +77,13 @@ import ShadowComponent from"./ShadowComponent.js";import{html,css}from"../lit-al
|
|
|
77
77
|
`;render(){return html`
|
|
78
78
|
<button id="overlay" aria-label="Close the Dialog" @click=${this.handleClick}></button>
|
|
79
79
|
<div id="wrapper">
|
|
80
|
-
<
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
<k-focus-capture>
|
|
81
|
+
<div
|
|
82
|
+
id="dialog"
|
|
83
|
+
role="dialog"
|
|
84
|
+
aria-modal="true"
|
|
85
|
+
aria-labelledby="title"
|
|
86
|
+
>
|
|
87
87
|
<div
|
|
88
88
|
id="header"
|
|
89
89
|
class="${this.hasTitle()?"has-title":""}"
|
|
@@ -114,7 +114,7 @@ import ShadowComponent from"./ShadowComponent.js";import{html,css}from"../lit-al
|
|
|
114
114
|
`:""}
|
|
115
115
|
</div>
|
|
116
116
|
`:""}
|
|
117
|
-
</
|
|
118
|
-
</
|
|
117
|
+
</div>
|
|
118
|
+
</k-focus-capture>
|
|
119
119
|
</div>
|
|
120
|
-
`}static create(
|
|
120
|
+
`}static create(e="",t={}){!1!==t.closeExisting&&document.querySelectorAll("k-dialog").forEach(e=>e.close());const{removeOnClose:o=!0,closeCallback:s=()=>{},title:i="",titleClasses:l="pyh px m0"}=t,n=new Dialog;if(Object.assign(n,{opened:!0,...t,closeCallback:(...e)=>{o&&n.remove(),s(...e)}}),i){const e=document.createElement("h5");e.slot="title",e.className=l,i instanceof HTMLElement?e.appendChild(i):e.innerHTML=i,n.appendChild(e)}if(e instanceof HTMLElement||e instanceof DocumentFragment)n.appendChild(e);else if(e){if(/<[^>]+>/.test(e))n.innerHTML+=e;else{const t=document.createElement("p");t.className="p",t.textContent=e,n.appendChild(t)}}return t.width&&n.style.setProperty("--width",t.width),t.minWidth&&n.style.setProperty("--min_width",t.minWidth),t.maxWidth&&n.style.setProperty("--max_width",t.maxWidth),t.height&&n.style.setProperty("--height",t.height),t.minHeight&&n.style.setProperty("--min_height",t.minHeight),t.maxHeight&&n.style.setProperty("--max_height",t.maxHeight),document.body.appendChild(n),n.open(),n}static confirm(e,t,o={}){return Dialog.create(e,{title:o.title||"Confirm",closeBtn:!1,overlayClose:!1,confirmText:"Yes",confirmClasses:"success ml",confirmAction:()=>t(!0),cancelText:"No",cancelClasses:"danger",cancelAction:()=>t(!1),...o})}static alert(e,t=()=>{},o={}){return Dialog.create(e,{title:o.title||"Alert",closeCallback:t,cancelText:"Ok",...o})}static error(e,t=()=>{},o={}){return Dialog.create(e,{title:o.title||"Error",titleClasses:"pyh px m0 tc-danger",closeCallback:t,cancelText:"Ok",...o})}static success(e,t=()=>{},o={}){return Dialog.create(e,{title:o.title||"Success",titleClasses:"pyh px m0 tc-success",closeCallback:t,cancelText:"Ok",...o})}}customElements.define("k-dialog",Dialog);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ShadowComponent from"./ShadowComponent.js";import{html,css,unsafeHTML}from"../lit-all.min.js";const cache={},getIconByPath=async t=>(cache[t]||(cache[t]=new Promise(async(e,n)=>{const o=(new AbortController).signal;try{const n=await fetch(t,{signal:o});200===n.status?e(await n.text()):404===n.status&&e(null)}catch(t){"AbortError"!==t.name&&n(t)}}).catch(()=>null)),await cache[t]),getIconByName=t=>{const e=async e=>getIconByPath(`${e}/${t}.svg`);return new Promise(async(t,n)=>{let o;for(let t=0;t<Icon.pathToIcons.length&&!o;t++)try{o=await e(Icon.pathToIcons[t])}catch(t){}t(o||null)})};export default class Icon extends ShadowComponent{static properties={src:{type:String,reflect:!0},name:{type:String,reflect:!0},iconContent:{type:String}};constructor(t=""){super(),this.src="",this.name=t,this.iconContent=""}updated(t){super.updated(),(t.has("src")||t.has("name"))&&this.loadIcon()
|
|
1
|
+
import ShadowComponent from"./ShadowComponent.js";import{html,css,unsafeHTML}from"../lit-all.min.js";const cache={},getIconByPath=async t=>(cache[t]||(cache[t]=new Promise(async(e,n)=>{const o=(new AbortController).signal;try{const n=await fetch(t,{signal:o});200===n.status?e(await n.text()):404===n.status&&e(null)}catch(t){"AbortError"!==t.name&&n(t)}}).catch(()=>null)),await cache[t]),getIconByName=t=>{const e=async e=>getIconByPath(`${e}/${t}.svg`);return new Promise(async(t,n)=>{let o;for(let t=0;t<Icon.pathToIcons.length&&!o;t++)try{o=await e(Icon.pathToIcons[t])}catch(t){}t(o||null)})};export default class Icon extends ShadowComponent{static properties={src:{type:String,reflect:!0},name:{type:String,reflect:!0},iconContent:{type:String}};constructor(t=""){super(),this.src="",this.name=t,this.iconContent=""}updated(t){super.updated(),(t.has("src")||t.has("name"))&&this.loadIcon()}async loadIcon(){let t;if(this.src?t=await getIconByPath(this.src):this.name&&(t=await getIconByName(this.name)),t)this.iconContent=this.fixSVG(t);else{const t=this.innerHTML.trim();this.iconContent=t?this.fixSVG(t):Icon.fallback}}fixSVG(t){if(!t)return t;const e=(new DOMParser).parseFromString(t,"image/svg+xml").querySelector("svg");return e?(e.removeAttribute("width"),e.removeAttribute("height"),e.querySelectorAll("path, rect, circle").forEach(t=>{t.setAttribute("fill","currentColor")}),(new XMLSerializer).serializeToString(e)):t}static styles=css`
|
|
2
2
|
:host {
|
|
3
3
|
display: inline-block;
|
|
4
4
|
vertical-align: bottom;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";export default class Toggle extends ShadowComponent{static properties={value:{type:Boolean,reflect:!0}};
|
|
1
|
+
import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComponent.js";export default class Toggle extends ShadowComponent{static properties={value:{type:Boolean,reflect:!0}};constructor(){super(),this.value=!1,this.tabIndex=0}updated(e){super.updated(e),e.has("value")&&this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0}))}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this.handleClick),this.addEventListener("keydown",this.handleKeyDown)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this.handleClick),this.removeEventListener("keydown",this.handleKeyDown)}handleClick=()=>{this.toggle()};handleKeyDown=e=>{["Space","Enter"].includes(e.code)&&(e.preventDefault(),this.toggle())};on(){return this.value=!0,this.dispatchEvent(new CustomEvent("on",{detail:{value:!0},bubbles:!0})),this}off(){return this.value=!1,this.dispatchEvent(new CustomEvent("off",{detail:{value:!1},bubbles:!0})),this}toggle(){return this.value?this.off():this.on(),this.dispatchEvent(new CustomEvent("toggle",{detail:{value:this.value},bubbles:!0})),this}render(){return html`
|
|
2
|
+
<div id="switch">
|
|
3
|
+
<div id="handle"></div>
|
|
4
|
+
</div>
|
|
5
|
+
<label id="label">
|
|
6
|
+
<slot></slot>
|
|
7
|
+
</label>
|
|
8
|
+
`}static styles=css`
|
|
2
9
|
:host {
|
|
3
10
|
--switch_height: 2rem;
|
|
4
11
|
--switch_width: 3rem;
|
|
@@ -19,11 +26,6 @@ import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComp
|
|
|
19
26
|
outline: none;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
:host(:focus) {
|
|
23
|
-
outline: 2px solid var(--c_primary, blue);
|
|
24
|
-
outline-offset: 2px;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
29
|
#switch {
|
|
28
30
|
display: flex;
|
|
29
31
|
align-items: center;
|
|
@@ -33,6 +35,12 @@ import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComp
|
|
|
33
35
|
background: var(--switch_background__off);
|
|
34
36
|
border-radius: 999rem;
|
|
35
37
|
margin-right: var(--spacer);
|
|
38
|
+
box-shadow: 0 0 0 transparent;
|
|
39
|
+
will-change: box-shadow;
|
|
40
|
+
transition: box-shadow var(--animation_ms, 256ms);
|
|
41
|
+
}
|
|
42
|
+
:host(:focus) #switch {
|
|
43
|
+
box-shadow: var(--focus_shadow);
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
#handle {
|
|
@@ -64,11 +72,4 @@ import{html,css}from"../lit-all.min.js";import ShadowComponent from"./ShadowComp
|
|
|
64
72
|
flex: 1 1 auto;
|
|
65
73
|
padding: 0;
|
|
66
74
|
}
|
|
67
|
-
|
|
68
|
-
<div id="switch">
|
|
69
|
-
<div id="handle"></div>
|
|
70
|
-
</div>
|
|
71
|
-
<label id="label">
|
|
72
|
-
<slot></slot>
|
|
73
|
-
</label>
|
|
74
|
-
`}}window.customElements.define("k-toggle",Toggle);
|
|
75
|
+
`}window.customElements.define("k-toggle",Toggle);
|
|
@@ -6,12 +6,12 @@ import ShadowComponent from"./ShadowComponent.js";import{html,css,render}from"..
|
|
|
6
6
|
<div class="tree-root">
|
|
7
7
|
${Tree.renderValue(this.data,null,0,this.depth)}
|
|
8
8
|
</div>
|
|
9
|
-
`:html`<slot></slot>`}static leafs=[];static addLeaf=(...e)=>{e.forEach(e=>Tree.leafs.unshift(e))};static renderValue(e,t=null,s=0,
|
|
9
|
+
`:html`<slot></slot>`}static leafs=[];static addLeaf=(...e)=>{e.forEach(e=>Tree.leafs.unshift(e))};static renderValue(e,t=null,s=0,a=0){const r=Tree.leafs.find(t=>t.detect(e));if(r){const s=document.createElement("span");if(s.className="d-b",null!==t){const e=document.createElement("span");e.className="number"==typeof t?"tc-muted":"",e.textContent=`${t}: `,s.appendChild(e)}const a=new r(e).render();if(a instanceof Node)s.appendChild(a);else{const e=document.createElement("span");render(a,e),s.appendChild(e)}return s}if("object"==typeof e&&null!==e){const r=new TreeBranch;return r.value=e,r.key=t,r.currentDepth=s,r.maxDepth=a,r}return html`<span class="d-b primitive">${null!==t?html`<span class="${"number"==typeof t?"tc-muted":""}">${t}: </span>`:""}${e}</span>`}}window.customElements.define("k-tree",Tree);export class TreeBranch extends ShadowComponent{static properties={value:{type:Object},key:{type:String},currentDepth:{type:Number},maxDepth:{type:Number},opened:{type:Boolean,converter:boolExists,reflect:!0}};constructor(){super(),this.value=null,this.key=null,this.currentDepth=0,this.maxDepth=0,this.opened=!1}connectedCallback(){super.connectedCallback(),this.currentDepth<=this.maxDepth&&(this.opened=!0)}get tree(){return this.closest("k-tree")}toggle=()=>{this.opened=!this.opened};render(){const e=null!==this.key?`${this.key}: `:"",t=Array.isArray(this.value)?"Array":"Object";return html`
|
|
10
10
|
<div>
|
|
11
|
-
<
|
|
11
|
+
<button class="branch-label no-btn" @click=${this.toggle} aria-expanded="${this.opened}">
|
|
12
12
|
<k-icon name="chevron-right" class="toggle-icon ${this.opened?"opened":""}"></k-icon>
|
|
13
13
|
${e}${t}
|
|
14
|
-
</
|
|
14
|
+
</button>
|
|
15
15
|
${this.opened?html`
|
|
16
16
|
<div class="pl">
|
|
17
17
|
${this.value?(Array.isArray(this.value)?this.value.map((e,t)=>[t,e]):Object.entries(this.value)).map(([e,t])=>Tree.renderValue(t,e,this.currentDepth+1,this.maxDepth)):""}
|
|
@@ -23,11 +23,19 @@ import ShadowComponent from"./ShadowComponent.js";import{html,css,render}from"..
|
|
|
23
23
|
display: block;
|
|
24
24
|
}
|
|
25
25
|
.branch-label{
|
|
26
|
+
display: block;
|
|
27
|
+
width: 100%;
|
|
26
28
|
cursor: pointer;
|
|
27
29
|
}
|
|
28
30
|
.branch-label:hover{
|
|
29
31
|
background-color: var(--c_bg__alt, #f5f5f5);
|
|
30
32
|
}
|
|
33
|
+
.branch-label:focus{
|
|
34
|
+
box-shadow: none;
|
|
35
|
+
}
|
|
36
|
+
.branch-label:focus-visible{
|
|
37
|
+
box-shadow: var(--focus_shadow);
|
|
38
|
+
}
|
|
31
39
|
.toggle-icon{
|
|
32
40
|
transition: transform var(--animation_ms, 200ms);
|
|
33
41
|
}
|
package/docs/utils/debounce.html
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>debounce - Kempo UI</title>
|
|
7
|
-
<link rel="stylesheet" href="../
|
|
7
|
+
<link rel="stylesheet" href="../kempo-vars.css" />
|
|
8
8
|
<link rel="stylesheet" href="../kempo.min.css" />
|
|
9
|
-
<link rel="stylesheet" href="../
|
|
9
|
+
<link rel="stylesheet" href="../kempo-hljs.css" />
|
|
10
10
|
<link rel="stylesheet" href="../styles.css" />
|
|
11
11
|
<script type="module" src="./init.js"></script>
|
|
12
12
|
</head>
|
|
@@ -32,14 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
<h3 id="basicUsage"><a href="#basicUsage" class="no-link">Basic Usage</a></h3>
|
|
34
34
|
<p>Import and use the debounce function to limit function execution frequency:</p>
|
|
35
|
-
<pre><code class="hljs javascript">import debounce from './utils/debounce.js'
|
|
36
|
-
|
|
37
|
-
const handleSearch = debounce((query) => {
|
|
38
|
-
console.log('Searching for:', query);
|
|
39
|
-
}, 300);
|
|
40
|
-
|
|
41
|
-
// Will only execute after 300ms of no calls
|
|
42
|
-
handleSearch('test');</code></pre>
|
|
35
|
+
<pre><code class="hljs javascript"><span class="hljs-keyword">import</span> debounce <span class="hljs-keyword">from</span> <span class="hljs-string">'./utils/debounce.js'</span>;<br /><br /><span class="hljs-keyword">const</span> handleSearch = debounce(<span class="hljs-function">(<span class="hljs-params">query</span>) =></span> {<br /> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Searching for:'</span>, query);<br />}, <span class="hljs-number">300</span>);<br /><br /><span class="hljs-comment">// Will only execute after 300ms of no calls</span><br />handleSearch(<span class="hljs-string">'test'</span>);</code></pre>
|
|
43
36
|
|
|
44
37
|
<h3 id="parameters"><a href="#parameters" class="no-link">Parameters</a></h3>
|
|
45
38
|
<h5><code>func<i>: Function</i></code></h5>
|
|
@@ -50,22 +43,10 @@ handleSearch('test');</code></pre>
|
|
|
50
43
|
<h3 id="examples"><a href="#examples" class="no-link">Examples</a></h3>
|
|
51
44
|
|
|
52
45
|
<h4>Search Input Debouncing</h4>
|
|
53
|
-
<pre><code class="hljs javascript">const debouncedSearch = debounce((searchTerm)
|
|
54
|
-
// API call or expensive search operation
|
|
55
|
-
performSearch(searchTerm);
|
|
56
|
-
}, 500);
|
|
57
|
-
|
|
58
|
-
searchInput.addEventListener('input', (e) => {
|
|
59
|
-
debouncedSearch(e.target.value);
|
|
60
|
-
});</code></pre>
|
|
46
|
+
<pre><code class="hljs javascript"><span class="hljs-keyword">const</span> debouncedSearch = debounce(<span class="hljs-function">(<span class="hljs-params">searchTerm</span>) =></span> {<br /> <span class="hljs-comment">// API call or expensive search operation</span><br /> performSearch(searchTerm);<br />}, <span class="hljs-number">500</span>);<br /><br />searchInput.addEventListener(<span class="hljs-string">'input'</span>, (e) => {<br /> debouncedSearch(e.target.value);<br />});</code></pre>
|
|
61
47
|
|
|
62
48
|
<h4>Window Resize Handler</h4>
|
|
63
|
-
<pre><code class="hljs javascript">const debouncedResize = debounce(()
|
|
64
|
-
// Expensive layout calculations
|
|
65
|
-
recalculateLayout();
|
|
66
|
-
}, 250);
|
|
67
|
-
|
|
68
|
-
window.addEventListener('resize', debouncedResize);</code></pre>
|
|
49
|
+
<pre><code class="hljs javascript"><span class="hljs-keyword">const</span> debouncedResize = debounce(<span class="hljs-function"><span class="hljs-params">()</span> =></span> {<br /> <span class="hljs-comment">// Expensive layout calculations</span><br /> recalculateLayout();<br />}, <span class="hljs-number">250</span>);<br /><br /><span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">'resize'</span>, debouncedResize);</code></pre>
|
|
69
50
|
|
|
70
51
|
</main>
|
|
71
52
|
<div style="height:33vh"></div>
|
package/docs/utils/drag.html
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>drag - Kempo UI</title>
|
|
7
|
-
<link rel="stylesheet" href="../
|
|
7
|
+
<link rel="stylesheet" href="../kempo-vars.css" />
|
|
8
8
|
<link rel="stylesheet" href="../kempo.min.css" />
|
|
9
|
-
<link rel="stylesheet" href="../
|
|
9
|
+
<link rel="stylesheet" href="../kempo-hljs.css" />
|
|
10
10
|
<link rel="stylesheet" href="../styles.css" />
|
|
11
11
|
<script type="module" src="./init.js"></script>
|
|
12
12
|
</head>
|
|
@@ -60,17 +60,7 @@
|
|
|
60
60
|
<h3 id="examples"><a href="#examples" class="no-link">Examples</a></h3>
|
|
61
61
|
|
|
62
62
|
<h4>Draggable Element</h4>
|
|
63
|
-
<pre><code class="hljs javascript">const box = document
|
|
64
|
-
let position = { x: 0, y: 0 };
|
|
65
|
-
|
|
66
|
-
drag({
|
|
67
|
-
element: box,
|
|
68
|
-
callback: (diff) => {
|
|
69
|
-
position.x += diff.x;
|
|
70
|
-
position.y += diff.y;
|
|
71
|
-
box.style.transform = `translate(${position.x}px, ${position.y}px)`;
|
|
72
|
-
}
|
|
73
|
-
});</code></pre>
|
|
63
|
+
<pre><code class="hljs javascript"><span class="hljs-keyword">const</span> box = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">'.box'</span>);<br /><span class="hljs-keyword">let</span> position = { <span class="hljs-attr">x</span>: <span class="hljs-number">0</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">0</span> };<br /><br />drag({<br /> <span class="hljs-attr">element</span>: box,<br /> <span class="hljs-attr">callback</span>: <span class="hljs-function">(<span class="hljs-params">diff</span>) =></span> {<br /> position.x += diff.x;<br /> position.y += diff.y;<br /> box.style.transform = <span class="hljs-string">`translate(<span class="hljs-subst">${position.x}</span>px, <span class="hljs-subst">${position.y}</span>px)`</span>;<br /> }<br />});</code></pre>
|
|
74
64
|
|
|
75
65
|
<h4>Resize Handle</h4>
|
|
76
66
|
<pre><code class="hljs javascript"><span class="hljs-keyword">const</span> resizeHandle = <span class="hljs-built_in">document</span>.<span class="hljs-title function_">querySelector</span>(<span class="hljs-string">'.resize-handle'</span>);<br /><span class="hljs-keyword">const</span> panel = <span class="hljs-built_in">document</span>.<span class="hljs-title function_">querySelector</span>(<span class="hljs-string">'.panel'</span>);<br /><br /><span class="hljs-title function_">drag</span>({<br /> <span class="hljs-attr">element</span>: resizeHandle,<br /> <span class="hljs-attr">preventScroll</span>: <span class="hljs-literal">true</span>,<br /> <span class="hljs-attr">callback</span>: <span class="hljs-function">(<span class="hljs-params">diff</span>) =></span> {<br /> <span class="hljs-keyword">const</span> newWidth = panel.offsetWidth + diff.x;<br /> panel.style.width = <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">max</span>(<span class="hljs-number">100</span>, newWidth) + <span class="hljs-string">'px'</span>;<br /> },<br /> <span class="hljs-attr">startCallback</span>: <span class="hljs-function">() =></span> {<br /> panel.classList.<span class="hljs-title function_">add</span>(<span class="hljs-string">'resizing'</span>);<br /> },<br /> <span class="hljs-attr">endCallback</span>: <span class="hljs-function">() =></span> {<br /> panel.classList.<span class="hljs-title function_">remove</span>(<span class="hljs-string">'resizing'</span>);<br /> }<br />});</code></pre>
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>formatTimestamp - Kempo UI</title>
|
|
7
|
-
<link rel="stylesheet" href="../
|
|
7
|
+
<link rel="stylesheet" href="../kempo-vars.css" />
|
|
8
8
|
<link rel="stylesheet" href="../kempo.min.css" />
|
|
9
|
-
<link rel="stylesheet" href="../
|
|
9
|
+
<link rel="stylesheet" href="../kempo-hljs.css" />
|
|
10
10
|
<link rel="stylesheet" href="../styles.css" />
|
|
11
11
|
<script type="module" src="./init.js"></script>
|
|
12
12
|
</head>
|
|
@@ -33,11 +33,7 @@
|
|
|
33
33
|
|
|
34
34
|
<h3 id="basicUsage"><a href="#basicUsage" class="no-link">Basic Usage</a></h3>
|
|
35
35
|
<p>Import and use the formatTimestamp function to format dates:</p>
|
|
36
|
-
<pre><code class="hljs javascript">import formatTimestamp from './utils/formatTimestamp.js';
|
|
37
|
-
|
|
38
|
-
const timestamp = Date.now();
|
|
39
|
-
const formatted = formatTimestamp(timestamp, 'YYYY-MM-DD');
|
|
40
|
-
console.log(formatted); // "2025-09-19"</code></pre>
|
|
36
|
+
<pre><code class="hljs javascript"><span class="hljs-keyword">import</span> formatTimestamp <span class="hljs-keyword">from</span> <span class="hljs-string">'./utils/formatTimestamp.js'</span>;<br /><br /><span class="hljs-keyword">const</span> timestamp = <span class="hljs-built_in">Date</span>.now();<br /><span class="hljs-keyword">const</span> formatted = formatTimestamp(timestamp, <span class="hljs-string">'YYYY-MM-DD'</span>);<br /><span class="hljs-built_in">console</span>.log(formatted); <span class="hljs-comment">// "2025-09-19"</span></code></pre>
|
|
41
37
|
|
|
42
38
|
<h3 id="parameters"><a href="#parameters" class="no-link">Parameters</a></h3>
|
|
43
39
|
<h5><code>timestamp<i>: number|string</i></code></h5>
|
|
@@ -78,30 +74,16 @@ console.log(formatted); // "2025-09-19"</code></pre>
|
|
|
78
74
|
<h3 id="examples"><a href="#examples" class="no-link">Examples</a></h3>
|
|
79
75
|
|
|
80
76
|
<h4>Date Formats</h4>
|
|
81
|
-
<pre><code class="hljs javascript">const timestamp = 1633024800000;
|
|
82
|
-
|
|
83
|
-
formatTimestamp(timestamp, 'YYYY-MM-DD'); // "2021-10-01"
|
|
84
|
-
formatTimestamp(timestamp, 'MM/DD/YYYY'); // "10/01/2021"
|
|
85
|
-
formatTimestamp(timestamp, 'DD-MM-YY'); // "01-10-21"</code></pre>
|
|
77
|
+
<pre><code class="hljs javascript"><span class="hljs-keyword">const</span> timestamp = <span class="hljs-number">1633024800000</span>;<br /><br />formatTimestamp(timestamp, <span class="hljs-string">'YYYY-MM-DD'</span>); <span class="hljs-comment">// "2021-10-01"</span><br />formatTimestamp(timestamp, <span class="hljs-string">'MM/DD/YYYY'</span>); <span class="hljs-comment">// "10/01/2021"</span><br />formatTimestamp(timestamp, <span class="hljs-string">'DD-MM-YY'</span>); <span class="hljs-comment">// "01-10-21"</span></code></pre>
|
|
86
78
|
|
|
87
79
|
<h4>Time Formats</h4>
|
|
88
|
-
<pre><code class="hljs javascript">formatTimestamp(timestamp, 'hh:mm:ss');
|
|
89
|
-
formatTimestamp(timestamp, 'h:mm'); // "0:00"
|
|
90
|
-
formatTimestamp(timestamp, 'hh:mm:ss.iii'); // "00:00:00.000"</code></pre>
|
|
80
|
+
<pre><code class="hljs javascript">formatTimestamp(timestamp, <span class="hljs-string">'hh:mm:ss'</span>); <span class="hljs-comment">// "00:00:00"</span><br />formatTimestamp(timestamp, <span class="hljs-string">'h:mm'</span>); <span class="hljs-comment">// "0:00"</span><br />formatTimestamp(timestamp, <span class="hljs-string">'hh:mm:ss.iii'</span>); <span class="hljs-comment">// "00:00:00.000"</span></code></pre>
|
|
91
81
|
|
|
92
82
|
<h4>Combined Formats</h4>
|
|
93
|
-
<pre><code class="hljs javascript">formatTimestamp(timestamp, 'YYYY-MM-DD hh:mm:ss');
|
|
94
|
-
// "2021-10-01 00:00:00"
|
|
95
|
-
|
|
96
|
-
formatTimestamp(timestamp, 'MM/DD/YY at h:mm');
|
|
97
|
-
// "10/01/21 at 0:00"</code></pre>
|
|
83
|
+
<pre><code class="hljs javascript">formatTimestamp(timestamp, <span class="hljs-string">'YYYY-MM-DD hh:mm:ss'</span>); <br /><span class="hljs-comment">// "2021-10-01 00:00:00"</span><br /><br />formatTimestamp(timestamp, <span class="hljs-string">'MM/DD/YY at h:mm'</span>);<br /><span class="hljs-comment">// "10/01/21 at 0:00"</span></code></pre>
|
|
98
84
|
|
|
99
85
|
<h4>Locale Formatting</h4>
|
|
100
|
-
<pre><code class="hljs javascript">// Uses browser locale when no format specified
|
|
101
|
-
formatTimestamp(timestamp); // "10/1/2021, 12:00:00 AM"
|
|
102
|
-
|
|
103
|
-
// Force specific locale
|
|
104
|
-
formatTimestamp(timestamp, null, 'de-DE'); // German formatting</code></pre>
|
|
86
|
+
<pre><code class="hljs javascript"><span class="hljs-comment">// Uses browser locale when no format specified</span><br />formatTimestamp(timestamp); <span class="hljs-comment">// "10/1/2021, 12:00:00 AM"</span><br /><br /><span class="hljs-comment">// Force specific locale</span><br />formatTimestamp(timestamp, <span class="hljs-literal">null</span>, <span class="hljs-string">'de-DE'</span>); <span class="hljs-comment">// German formatting</span></code></pre>
|
|
105
87
|
|
|
106
88
|
</main>
|
|
107
89
|
<div style="height:33vh"></div>
|