kempo-ui 0.0.2 → 0.0.4
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/.github/copilot-instructions.md +149 -149
- package/.github/workflows/publish-major.yml +39 -0
- package/.github/workflows/publish-minor.yml +39 -0
- package/.github/workflows/{publish-npm.yml → publish-patch.yml} +44 -44
- package/.vscode/settings.json +2 -0
- package/CONTRIBUTING.md +149 -149
- package/README.md +0 -0
- package/dist/kempo-hljs.css +1 -0
- package/dist/kempo-vars.css +0 -0
- package/dist/src/components/Accordion.js +36 -0
- package/dist/src/components/Card.js +37 -0
- package/dist/src/components/Collapsible.js +41 -0
- package/dist/src/components/ContentSlider.js +44 -0
- package/dist/src/components/Dialog.js +113 -0
- package/dist/src/components/FocusCapture.js +7 -0
- package/dist/src/components/Icon.js +10 -0
- package/dist/src/components/Import.js +1 -0
- package/dist/src/components/PersistantCollapsible.js +1 -0
- package/dist/src/components/PhotoViewer.js +135 -0
- package/dist/src/components/Resize.js +96 -0
- package/dist/src/components/ShadowComponent.js +1 -0
- package/dist/src/components/ShowMore.js +42 -0
- package/dist/src/components/SideMenu.js +97 -0
- package/dist/src/components/Split.js +84 -0
- package/dist/src/components/Tabs.js +155 -0
- package/dist/src/components/Tags.js +69 -0
- package/dist/src/components/ThemeSwitcher.js +23 -0
- package/dist/src/components/Timestamp.js +1 -0
- package/dist/src/lit-all.min.js +120 -0
- package/dist/src/utils/debounce.js +1 -0
- package/dist/src/utils/drag.js +1 -0
- package/dist/src/utils/formatTimestamp.js +1 -0
- package/dist/src/utils/propConverters.js +1 -0
- package/dist/src/utils/watchWindowSize.js +1 -0
- package/docs/components/accordion.html +166 -0
- package/docs/components/card.html +92 -0
- package/docs/components/collapsible.html +198 -0
- package/docs/components/content-slider.html +223 -0
- package/docs/components/dialog.html +251 -0
- package/docs/components/focus-capture.html +67 -0
- package/docs/components/icon.html +158 -0
- package/docs/components/import.html +73 -0
- package/docs/components/persistant-collapsible.html +123 -0
- package/docs/components/photo-viewer.html +226 -0
- package/docs/components/resize.html +178 -0
- package/docs/components/show-more.html +129 -0
- package/docs/components/side-menu.html +159 -0
- package/docs/components/split.html +147 -0
- package/docs/components/table.html +312 -0
- package/docs/components/tableControls.html +77 -0
- package/docs/components/tableCustomFields.html +113 -0
- package/docs/components/tableFetchRecords.html +114 -0
- package/docs/components/tableFieldSortHide.html +75 -0
- package/docs/components/tablePagination.html +100 -0
- package/docs/components/tableRecordEditing.html +144 -0
- package/docs/components/tableRecordFiltering.html +88 -0
- package/docs/components/tableRecordHiding.html +80 -0
- package/docs/components/tableRecordSearching.html +75 -0
- package/docs/components/tableRecordSelection.html +75 -0
- package/docs/components/tableRowControls.html +78 -0
- package/docs/components/tableSorting.html +73 -0
- package/docs/components/tabs.html +180 -0
- package/docs/components/tags.html +110 -0
- package/docs/components/theme-switcher.html +126 -0
- package/docs/components/timestamp.html +82 -0
- package/docs/components/toast.html +319 -0
- package/docs/components/toggle.html +156 -0
- package/docs/dev.config.json +20 -0
- package/docs/icons/add.svg +1 -0
- package/docs/icons/arrow-back.svg +1 -0
- package/docs/icons/arrow-down-double.svg +1 -0
- package/docs/icons/arrow-down.svg +1 -0
- package/docs/icons/arrow-forward.svg +1 -0
- package/docs/icons/arrow-up-double.svg +1 -0
- package/docs/icons/arrow-up.svg +1 -0
- package/docs/icons/cards.svg +1 -0
- package/docs/icons/check.svg +1 -0
- package/docs/icons/chevron-left.svg +1 -0
- package/docs/icons/chevron-right.svg +1 -0
- package/docs/icons/close.svg +2 -0
- package/docs/icons/compare.svg +1 -0
- package/docs/icons/delete.svg +1 -0
- package/docs/icons/drag-handle.svg +1 -0
- package/docs/icons/drawing2.svg +124 -0
- package/docs/icons/edit.svg +1 -0
- package/docs/icons/error.svg +1 -0
- package/docs/icons/export-file.svg +1 -0
- package/docs/icons/file-text.svg +1 -0
- package/docs/icons/file.svg +1 -0
- package/docs/icons/filter-off.svg +1 -0
- package/docs/icons/filter.svg +1 -0
- package/docs/icons/first.svg +1 -0
- package/docs/icons/folder-clear.svg +1 -0
- package/docs/icons/folder-create.svg +1 -0
- package/docs/icons/folder-open.svg +1 -0
- package/docs/icons/folder.svg +1 -0
- package/docs/icons/hide.svg +1 -0
- package/docs/icons/image.svg +1 -0
- package/docs/icons/label-add.svg +1 -0
- package/docs/icons/label.svg +1 -0
- package/docs/icons/last.svg +1 -0
- package/docs/icons/menu.svg +1 -0
- package/docs/icons/mode-auto.svg +1 -0
- package/docs/icons/mode-dark.svg +1 -0
- package/docs/icons/mode-light.svg +1 -0
- package/docs/icons/open-in-browser.svg +1 -0
- package/docs/icons/pause.svg +1 -0
- package/docs/icons/play.svg +1 -0
- package/docs/icons/refresh.svg +1 -0
- package/docs/icons/remove.svg +1 -0
- package/docs/icons/save.svg +1 -0
- package/docs/icons/search.svg +1 -0
- package/docs/icons/settings.svg +1 -0
- package/docs/icons/show.svg +1 -0
- package/docs/icons/storage.svg +1 -0
- package/docs/icons/table-visibility.svg +1 -0
- package/docs/icons/tag.svg +1 -0
- package/docs/icons/tools.svg +1 -0
- package/docs/icons/trash-x.svg +1 -0
- package/docs/icons/warning.svg +1 -0
- package/docs/index.html +28 -21
- package/docs/kempo-hljs.css +1 -0
- package/docs/media/civic.jpg +0 -0
- package/docs/media/corvette.jpg +0 -0
- package/docs/media/evo.jpg +0 -0
- package/docs/media/gtr.jpg +0 -0
- package/docs/media/nsx.jpg +0 -0
- package/docs/nav.inc.html +67 -0
- package/docs/nav.inc.js +4 -0
- package/{config/production.json → docs/prod.config.json} +20 -16
- package/docs/src/components/Accordion.js +36 -0
- package/docs/src/components/Card.js +37 -0
- package/docs/src/components/Collapsible.js +41 -0
- package/docs/src/components/ContentSlider.js +44 -0
- package/docs/src/components/Dialog.js +113 -0
- package/docs/src/components/FocusCapture.js +7 -0
- package/docs/src/components/HybridComponent.js +1 -0
- package/docs/src/components/Icon.js +10 -0
- package/docs/src/components/Import.js +1 -0
- package/docs/src/components/LightComponent.js +1 -0
- package/docs/src/components/PersistantCollapsible.js +1 -0
- package/docs/src/components/PhotoViewer.js +135 -0
- package/docs/src/components/Resize.js +96 -0
- package/docs/src/components/ShadowComponent.js +1 -0
- package/docs/src/components/ShowMore.js +42 -0
- package/docs/src/components/SideMenu.js +97 -0
- package/docs/src/components/Split.js +84 -0
- package/docs/src/components/Tabs.js +155 -0
- package/docs/src/components/Tags.js +69 -0
- package/docs/src/components/ThemeSwitcher.js +23 -0
- package/docs/src/components/Timestamp.js +1 -0
- package/docs/src/lit-all.min.js +120 -0
- package/docs/src/utils/debounce.js +1 -0
- package/docs/src/utils/drag.js +1 -0
- package/docs/src/utils/formatTimestamp.js +1 -0
- package/docs/src/utils/propConverters.js +1 -0
- package/docs/src/utils/watchWindowSize.js +1 -0
- package/docs/styles.css +6 -0
- package/docs/utils/debounce.html +78 -0
- package/docs/utils/drag.html +104 -0
- package/docs/utils/formatTimestamp.html +114 -0
- package/docs/utils/propConverters.html +132 -0
- package/docs/utils/watchWindowSize.html +166 -0
- package/icons/add.svg +1 -0
- package/icons/arrow-back.svg +1 -0
- package/icons/arrow-down-double.svg +1 -0
- package/icons/arrow-down.svg +1 -0
- package/icons/arrow-forward.svg +1 -0
- package/icons/arrow-up-double.svg +1 -0
- package/icons/arrow-up.svg +1 -0
- package/icons/cards.svg +1 -0
- package/icons/check.svg +1 -0
- package/icons/chevron-left.svg +1 -0
- package/icons/chevron-right.svg +1 -0
- package/icons/close.svg +2 -0
- package/icons/compare.svg +1 -0
- package/icons/delete.svg +1 -0
- package/icons/drag-handle.svg +1 -0
- package/icons/drawing2.svg +124 -0
- package/icons/edit.svg +1 -0
- package/icons/error.svg +1 -0
- package/icons/export-file.svg +1 -0
- package/icons/file-text.svg +1 -0
- package/icons/file.svg +1 -0
- package/icons/filter-off.svg +1 -0
- package/icons/filter.svg +1 -0
- package/icons/first.svg +1 -0
- package/icons/folder-clear.svg +1 -0
- package/icons/folder-create.svg +1 -0
- package/icons/folder-open.svg +1 -0
- package/icons/folder.svg +1 -0
- package/icons/hide.svg +1 -0
- package/icons/image.svg +1 -0
- package/icons/label-add.svg +1 -0
- package/icons/label.svg +1 -0
- package/icons/last.svg +1 -0
- package/icons/menu.svg +1 -0
- package/icons/mode-auto.svg +1 -0
- package/icons/mode-dark.svg +1 -0
- package/icons/mode-light.svg +1 -0
- package/icons/open-in-browser.svg +1 -0
- package/icons/pause.svg +1 -0
- package/icons/play.svg +1 -0
- package/icons/refresh.svg +1 -0
- package/icons/remove.svg +1 -0
- package/icons/save.svg +1 -0
- package/icons/search.svg +1 -0
- package/icons/settings.svg +1 -0
- package/icons/show.svg +1 -0
- package/icons/storage.svg +1 -0
- package/icons/table-visibility.svg +1 -0
- package/icons/tag.svg +1 -0
- package/icons/tools.svg +1 -0
- package/icons/trash-x.svg +1 -0
- package/icons/warning.svg +1 -0
- package/package.json +2 -2
- package/scripts/build.js +109 -138
- package/scripts/docs.js +62 -60
- package/src/components/Accordion.js +229 -0
- package/src/components/Card.js +66 -0
- package/src/components/Collapsible.js +109 -0
- package/src/components/ContentSlider.js +205 -0
- package/src/components/Dialog.js +368 -0
- package/src/components/FocusCapture.js +23 -0
- package/src/components/HybridComponent.js +40 -40
- package/src/components/Icon.js +155 -0
- package/src/components/Import.js +104 -0
- package/src/components/LightComponent.js +32 -32
- package/src/components/PersistantCollapsible.js +69 -0
- package/src/components/PhotoViewer.js +368 -0
- package/src/components/Resize.js +210 -0
- package/src/components/ShadowComponent.js +32 -17
- package/src/components/ShowMore.js +109 -0
- package/src/components/SideMenu.js +167 -0
- package/src/components/Sortable.js +193 -0
- package/src/components/Split.js +192 -0
- package/src/components/Table.js +1202 -0
- package/src/components/Tabs.js +428 -0
- package/src/components/Tags.js +253 -0
- package/src/components/ThemeSwitcher.js +108 -0
- package/src/components/Timestamp.js +31 -0
- package/src/components/Toast.js +454 -0
- package/src/components/Toggle.js +173 -0
- package/src/components/tableControls/DeleteRecord.js +29 -0
- package/src/components/tableControls/Edit.js +88 -0
- package/src/components/tableControls/ExportCSV.js +71 -0
- package/src/components/tableControls/ExportJson.js +55 -0
- package/src/components/tableControls/FieldSortHide.js +76 -0
- package/src/components/tableControls/Filters.js +114 -0
- package/src/components/tableControls/FirstPage.js +65 -0
- package/src/components/tableControls/HiddenCount.js +45 -0
- package/src/components/tableControls/Hide.js +34 -0
- package/src/components/tableControls/LastPage.js +65 -0
- package/src/components/tableControls/NextPage.js +65 -0
- package/src/components/tableControls/PageSelect.js +109 -0
- package/src/components/tableControls/PageSize.js +68 -0
- package/src/components/tableControls/PrevPage.js +65 -0
- package/src/components/tableControls/Search.js +58 -0
- package/src/components/tableControls/ShowAll.js +34 -0
- package/src/components/tableControls/TableControl.js +105 -0
- package/src/kempo-hljs.css +146 -0
- package/src/utils/debounce.js +9 -0
- package/src/utils/drag.js +80 -0
- package/src/utils/formatTimestamp.js +27 -0
- package/src/utils/propConverters.js +11 -0
- package/src/utils/toTitleCase.js +9 -0
- package/src/utils/watchWindowSize.js +16 -0
- package/tests/HybridComponent.browser-test.js +214 -214
- package/tests/LightComponent.browser-test.js +169 -169
- package/tests/ShadowComponent.browser-test.js +130 -130
- package/config/development.json +0 -14
- package/docs/components/ShadowComponent.js +0 -1
- package/src/utils/cli.js +0 -43
- package/src/utils/fs-utils.js +0 -41
- /package/{docs → dist/src}/components/HybridComponent.js +0 -0
- /package/{docs → dist/src}/components/LightComponent.js +0 -0
- /package/docs/{utils → src/utils}/cli.js +0 -0
- /package/docs/{utils → src/utils}/fs-utils.js +0 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import ShadowComponent from './ShadowComponent.js';
|
|
2
|
+
import { html, css } from '../lit-all.min.js';
|
|
3
|
+
import { boolExists } from '../utils/propConverters.js';
|
|
4
|
+
import './Icon.js';
|
|
5
|
+
|
|
6
|
+
const firstFocusable = element => {
|
|
7
|
+
const focusableElements = element.querySelectorAll(
|
|
8
|
+
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
9
|
+
);
|
|
10
|
+
return focusableElements[0];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default class Dialog extends ShadowComponent {
|
|
14
|
+
/*
|
|
15
|
+
Properties
|
|
16
|
+
*/
|
|
17
|
+
static properties = {
|
|
18
|
+
opened: { type: Boolean, reflect: true, converter: boolExists },
|
|
19
|
+
closeBtn: { type: Boolean, reflect: true, attribute: 'close-btn', converter: boolExists },
|
|
20
|
+
overlayClose: { type: Boolean, reflect: true, attribute: 'overlay-close', converter: boolExists },
|
|
21
|
+
confirmText: { type: String, reflect: true, attribute: 'confirm-text' },
|
|
22
|
+
confirmClasses: { type: String, reflect: true, attribute: 'confirm-classes' },
|
|
23
|
+
cancelText: { type: String, reflect: true, attribute: 'cancel-text' },
|
|
24
|
+
cancelClasses: { type: String, reflect: true, attribute: 'cancel-classes' }
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
constructor() {
|
|
28
|
+
super();
|
|
29
|
+
this.opened = false;
|
|
30
|
+
this.closeBtn = true;
|
|
31
|
+
this.overlayClose = true;
|
|
32
|
+
this.confirmText = '';
|
|
33
|
+
this.confirmClasses = 'success ml';
|
|
34
|
+
this.cancelText = '';
|
|
35
|
+
this.cancelClasses = '';
|
|
36
|
+
this.confirmAction = () => {};
|
|
37
|
+
this.cancelAction = () => {};
|
|
38
|
+
this.closeCallback = () => {};
|
|
39
|
+
this.previousFocus = null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
Event Handlers
|
|
44
|
+
*/
|
|
45
|
+
handleClick = event => {
|
|
46
|
+
const { target } = event;
|
|
47
|
+
const id = target.id || target.closest('[id]')?.id;
|
|
48
|
+
|
|
49
|
+
if((id === 'overlay' && this.overlayClose) || id === 'close') {
|
|
50
|
+
this.close();
|
|
51
|
+
} else if(id === 'cancel') {
|
|
52
|
+
this.cancelAction(event);
|
|
53
|
+
if(!event.defaultPrevented) this.close();
|
|
54
|
+
} else if(id === 'confirm') {
|
|
55
|
+
this.confirmAction(event);
|
|
56
|
+
if(!event.defaultPrevented) this.close();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
handleKeydown = event => {
|
|
61
|
+
if(event.keyCode === 27) {
|
|
62
|
+
this.close();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
Lifecycle Callbacks
|
|
68
|
+
*/
|
|
69
|
+
connectedCallback() {
|
|
70
|
+
super.connectedCallback();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
disconnectedCallback() {
|
|
74
|
+
super.disconnectedCallback();
|
|
75
|
+
window.removeEventListener('keydown', this.handleKeydown);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
updated(changedProperties) {
|
|
79
|
+
super.updated(changedProperties);
|
|
80
|
+
|
|
81
|
+
if(changedProperties.has('opened')) {
|
|
82
|
+
this.dispatchEvent(new CustomEvent(this.opened ? 'opened' : 'close'));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/*
|
|
87
|
+
Public Methods
|
|
88
|
+
*/
|
|
89
|
+
open() {
|
|
90
|
+
this.opened = true;
|
|
91
|
+
window.addEventListener('keydown', this.handleKeydown);
|
|
92
|
+
|
|
93
|
+
// Use updateComplete or setTimeout as fallback
|
|
94
|
+
const updatePromise = this.updateComplete || this.requestUpdate();
|
|
95
|
+
if(updatePromise && updatePromise.then) {
|
|
96
|
+
updatePromise.then(() => {
|
|
97
|
+
const toFocus = this.shadowRoot.querySelector('[autofocus]') || firstFocusable(this.shadowRoot);
|
|
98
|
+
if(toFocus) toFocus.focus();
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
// Fallback for when updateComplete/requestUpdate don't return a promise
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
const toFocus = this.shadowRoot.querySelector('[autofocus]') || firstFocusable(this.shadowRoot);
|
|
104
|
+
if(toFocus) toFocus.focus();
|
|
105
|
+
}, 0);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
close() {
|
|
110
|
+
this.opened = false;
|
|
111
|
+
this.blur();
|
|
112
|
+
this.closeCallback();
|
|
113
|
+
window.removeEventListener('keydown', this.handleKeydown);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
toggle() {
|
|
117
|
+
this.opened ? this.close() : this.open();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
focus() {
|
|
121
|
+
const firstFocus = firstFocusable(this.shadowRoot);
|
|
122
|
+
if(firstFocus) {
|
|
123
|
+
this.previousFocus = document.activeElement;
|
|
124
|
+
firstFocus.focus();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
blur() {
|
|
129
|
+
if(this.previousFocus) {
|
|
130
|
+
this.previousFocus.focus();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/*
|
|
135
|
+
Private Methods
|
|
136
|
+
*/
|
|
137
|
+
hasTitle() {
|
|
138
|
+
return !!this.querySelector('[slot="title"]');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/*
|
|
142
|
+
Styles
|
|
143
|
+
*/
|
|
144
|
+
static styles = css`
|
|
145
|
+
:host {
|
|
146
|
+
position: fixed;
|
|
147
|
+
top: 0;
|
|
148
|
+
left: 0;
|
|
149
|
+
width: 100vw;
|
|
150
|
+
height: 100vh;
|
|
151
|
+
z-index: 100;
|
|
152
|
+
display: none;
|
|
153
|
+
justify-content: center;
|
|
154
|
+
align-items: center;
|
|
155
|
+
}
|
|
156
|
+
:host([opened]) {
|
|
157
|
+
display: flex;
|
|
158
|
+
}
|
|
159
|
+
#overlay {
|
|
160
|
+
position: absolute;
|
|
161
|
+
width: 100%;
|
|
162
|
+
height: 100%;
|
|
163
|
+
top: 0;
|
|
164
|
+
left: 0;
|
|
165
|
+
background-color: var(--c_overlay);
|
|
166
|
+
border: 0px solid transparent;
|
|
167
|
+
box-shadow: 0 0 0 transparent;
|
|
168
|
+
}
|
|
169
|
+
#wrapper {
|
|
170
|
+
position: relative;
|
|
171
|
+
z-index: 1;
|
|
172
|
+
pointer-events: none;
|
|
173
|
+
}
|
|
174
|
+
#dialog {
|
|
175
|
+
display: flex;
|
|
176
|
+
flex-direction: column;
|
|
177
|
+
min-width: var(--min_width, 20rem);
|
|
178
|
+
width: var(--width, fit-content);
|
|
179
|
+
max-width: var(--max_width, calc(100vw - 4rem));
|
|
180
|
+
min-height: var(--min_height, 12rem);
|
|
181
|
+
height: var(--height, fit-content);
|
|
182
|
+
max-height: var(--max_height, calc(100vh - 4rem));
|
|
183
|
+
background-color: var(--c_bg);
|
|
184
|
+
box-shadow: var(--drop_shadow);
|
|
185
|
+
border-radius: var(--radius);
|
|
186
|
+
pointer-events: all;
|
|
187
|
+
}
|
|
188
|
+
#header {
|
|
189
|
+
display: flex;
|
|
190
|
+
align-items: center;
|
|
191
|
+
}
|
|
192
|
+
#header.has-title {
|
|
193
|
+
border-bottom: 1px solid var(--c_border);
|
|
194
|
+
}
|
|
195
|
+
#title {
|
|
196
|
+
flex: 1 1 auto;
|
|
197
|
+
}
|
|
198
|
+
#close {
|
|
199
|
+
border: 0px;
|
|
200
|
+
background: transparent;
|
|
201
|
+
box-shadow: 0 0 0 transparent;
|
|
202
|
+
color: var(--tc);
|
|
203
|
+
}
|
|
204
|
+
#close k-icon {
|
|
205
|
+
pointer-events: none;
|
|
206
|
+
}
|
|
207
|
+
#body {
|
|
208
|
+
flex: 1 1 auto;
|
|
209
|
+
}
|
|
210
|
+
#footer {
|
|
211
|
+
display: flex;
|
|
212
|
+
justify-content: flex-end;
|
|
213
|
+
padding: var(--spacer_h);
|
|
214
|
+
}
|
|
215
|
+
`;
|
|
216
|
+
|
|
217
|
+
/*
|
|
218
|
+
Rendering
|
|
219
|
+
*/
|
|
220
|
+
render() {
|
|
221
|
+
return html`
|
|
222
|
+
<button id="overlay" aria-label="Close the Dialog" @click=${this.handleClick}></button>
|
|
223
|
+
<div id="wrapper">
|
|
224
|
+
<div
|
|
225
|
+
id="dialog"
|
|
226
|
+
role="dialog"
|
|
227
|
+
aria-modal="true"
|
|
228
|
+
aria-labelledby="title"
|
|
229
|
+
>
|
|
230
|
+
<div
|
|
231
|
+
id="header"
|
|
232
|
+
class="${this.hasTitle() ? 'has-title' : ''}"
|
|
233
|
+
>
|
|
234
|
+
<div id="title">
|
|
235
|
+
<slot name="title"></slot>
|
|
236
|
+
</div>
|
|
237
|
+
${this.closeBtn ? html`
|
|
238
|
+
<button id="close" @click=${this.handleClick}>
|
|
239
|
+
<k-icon name="close"></k-icon>
|
|
240
|
+
</button>
|
|
241
|
+
` : ''}
|
|
242
|
+
</div>
|
|
243
|
+
<div id="body">
|
|
244
|
+
<slot></slot>
|
|
245
|
+
</div>
|
|
246
|
+
${this.cancelText || this.confirmText ? html`
|
|
247
|
+
<div id="footer">
|
|
248
|
+
${this.cancelText ? html`
|
|
249
|
+
<button id="cancel" class="${this.cancelClasses}" @click=${this.handleClick}>
|
|
250
|
+
${this.cancelText}
|
|
251
|
+
</button>
|
|
252
|
+
` : ''}
|
|
253
|
+
${this.confirmText ? html`
|
|
254
|
+
<button id="confirm" class="${this.confirmClasses}" @click=${this.handleClick}>
|
|
255
|
+
${this.confirmText}
|
|
256
|
+
</button>
|
|
257
|
+
` : ''}
|
|
258
|
+
</div>
|
|
259
|
+
` : ''}
|
|
260
|
+
</div>
|
|
261
|
+
</div>
|
|
262
|
+
`;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/*
|
|
266
|
+
Static Methods
|
|
267
|
+
*/
|
|
268
|
+
static create(contents = '', options = {}) {
|
|
269
|
+
if(options.closeExisting !== false) {
|
|
270
|
+
document.querySelectorAll('k-dialog').forEach(d => d.close());
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const {
|
|
274
|
+
removeOnClose = true,
|
|
275
|
+
closeCallback = () => {}
|
|
276
|
+
} = options;
|
|
277
|
+
|
|
278
|
+
const dialog = new Dialog();
|
|
279
|
+
|
|
280
|
+
// Set properties
|
|
281
|
+
Object.assign(dialog, {
|
|
282
|
+
opened: true,
|
|
283
|
+
...options,
|
|
284
|
+
closeCallback: (...args) => {
|
|
285
|
+
if(removeOnClose) {
|
|
286
|
+
dialog.remove();
|
|
287
|
+
}
|
|
288
|
+
closeCallback(...args);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// Set content
|
|
293
|
+
if(contents instanceof HTMLElement || contents instanceof DocumentFragment) {
|
|
294
|
+
dialog.appendChild(contents);
|
|
295
|
+
} else if(contents) {
|
|
296
|
+
dialog.innerHTML = contents;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Set CSS custom properties for dimensions
|
|
300
|
+
if(options.width) dialog.style.setProperty('--width', options.width);
|
|
301
|
+
if(options.minWidth) dialog.style.setProperty('--min_width', options.minWidth);
|
|
302
|
+
if(options.maxWidth) dialog.style.setProperty('--max_width', options.maxWidth);
|
|
303
|
+
if(options.height) dialog.style.setProperty('--height', options.height);
|
|
304
|
+
if(options.minHeight) dialog.style.setProperty('--min_height', options.minHeight);
|
|
305
|
+
if(options.maxHeight) dialog.style.setProperty('--max_height', options.maxHeight);
|
|
306
|
+
|
|
307
|
+
document.body.appendChild(dialog);
|
|
308
|
+
dialog.open();
|
|
309
|
+
|
|
310
|
+
return dialog;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
static confirm(text, responseCallback, options = {}) {
|
|
314
|
+
const title = options.title || 'Confirm';
|
|
315
|
+
return Dialog.create(`
|
|
316
|
+
<h5 slot="title" class="pyh px m0">${title}</h5>
|
|
317
|
+
<p class="p">${text}</p>
|
|
318
|
+
`, {
|
|
319
|
+
closeBtn: false,
|
|
320
|
+
overlayClose: false,
|
|
321
|
+
confirmText: 'Yes',
|
|
322
|
+
confirmClasses: 'success ml',
|
|
323
|
+
confirmAction: () => responseCallback(true),
|
|
324
|
+
cancelText: 'No',
|
|
325
|
+
cancelClasses: 'danger',
|
|
326
|
+
cancelAction: () => responseCallback(false),
|
|
327
|
+
...options
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
static alert(text, responseCallback, options = {}) {
|
|
332
|
+
const title = options.title || 'Alert';
|
|
333
|
+
return Dialog.create(`
|
|
334
|
+
<h5 slot="title" class="pyh px m0">${title}</h5>
|
|
335
|
+
<p class="p">${text}</p>
|
|
336
|
+
`, {
|
|
337
|
+
closeCallback: responseCallback,
|
|
338
|
+
cancelText: 'Ok',
|
|
339
|
+
...options
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
static error(text, responseCallback, options = {}) {
|
|
344
|
+
const title = options.title || 'Error';
|
|
345
|
+
return Dialog.create(`
|
|
346
|
+
<h5 slot="title" class="pyh px m0 tc-danger">${title}</h5>
|
|
347
|
+
<p class="p">${text}</p>
|
|
348
|
+
`, {
|
|
349
|
+
closeCallback: responseCallback,
|
|
350
|
+
cancelText: 'Ok',
|
|
351
|
+
...options
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
static success(text, responseCallback, options = {}) {
|
|
356
|
+
const title = options.title || 'Success';
|
|
357
|
+
return Dialog.create(`
|
|
358
|
+
<h5 slot="title" class="pyh px m0 tc-success">${title}</h5>
|
|
359
|
+
<p class="p">${text}</p>
|
|
360
|
+
`, {
|
|
361
|
+
closeCallback: responseCallback,
|
|
362
|
+
cancelText: 'Ok',
|
|
363
|
+
...options
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
customElements.define('k-dialog', Dialog);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LitElement, html } from '../lit-all.min.js';
|
|
2
|
+
|
|
3
|
+
export default class FocusCapture extends LitElement {
|
|
4
|
+
static shadowRootOptions = {
|
|
5
|
+
mode: 'open',
|
|
6
|
+
delegatesFocus: true
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
afterFocus = () => {
|
|
10
|
+
this.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])').focus();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
render(){
|
|
14
|
+
return html`
|
|
15
|
+
<slot></slot>
|
|
16
|
+
<div
|
|
17
|
+
tabindex="0"
|
|
18
|
+
@focus=${this.afterFocus}
|
|
19
|
+
></div>
|
|
20
|
+
`
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
window.customElements.define('k-focus-capture', FocusCapture);
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { html, render } from '../lit-all.min.js';
|
|
2
|
-
import ShadowComponent from './ShadowComponent.js';
|
|
3
|
-
|
|
4
|
-
export default class HybridComponent extends ShadowComponent {
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
Shadow DOM Setup
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
createRenderRoot() {
|
|
11
|
-
const renderContainer = super.createRenderRoot();
|
|
12
|
-
|
|
13
|
-
this.lightRoot = document.createElement('div');
|
|
14
|
-
this.lightRoot.style.display = 'contents';
|
|
15
|
-
this.lightRoot.slot = 'lightRoot';
|
|
16
|
-
this.appendChild(this.lightRoot);
|
|
17
|
-
|
|
18
|
-
return renderContainer;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/*
|
|
22
|
-
Lifecycle Callbacks
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
updated() {
|
|
26
|
-
render(this.renderLightDom(), this.lightRoot);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/*
|
|
30
|
-
Rendering
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
renderLightDom() {
|
|
34
|
-
return html``;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
render() {
|
|
38
|
-
return html`<slot name="lightRoot"></slot>`;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
import { html, render } from '../lit-all.min.js';
|
|
2
|
+
import ShadowComponent from './ShadowComponent.js';
|
|
3
|
+
|
|
4
|
+
export default class HybridComponent extends ShadowComponent {
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
Shadow DOM Setup
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
createRenderRoot() {
|
|
11
|
+
const renderContainer = super.createRenderRoot();
|
|
12
|
+
|
|
13
|
+
this.lightRoot = document.createElement('div');
|
|
14
|
+
this.lightRoot.style.display = 'contents';
|
|
15
|
+
this.lightRoot.slot = 'lightRoot';
|
|
16
|
+
this.appendChild(this.lightRoot);
|
|
17
|
+
|
|
18
|
+
return renderContainer;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
Lifecycle Callbacks
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
updated() {
|
|
26
|
+
render(this.renderLightDom(), this.lightRoot);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
Rendering
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
renderLightDom() {
|
|
34
|
+
return html``;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
render() {
|
|
38
|
+
return html`<slot name="lightRoot"></slot>`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import ShadowComponent from './ShadowComponent.js';
|
|
2
|
+
import { html, css, unsafeHTML } from '../lit-all.min.js';
|
|
3
|
+
|
|
4
|
+
const cache = {};
|
|
5
|
+
|
|
6
|
+
const getIconByPath = async (path) => {
|
|
7
|
+
if (!cache[path]) {
|
|
8
|
+
cache[path] = new Promise(async (resolve, reject) => {
|
|
9
|
+
const controller = new AbortController();
|
|
10
|
+
const signal = controller.signal;
|
|
11
|
+
try {
|
|
12
|
+
const response = await fetch(path, { signal });
|
|
13
|
+
if (response.status === 200) {
|
|
14
|
+
resolve(await response.text());
|
|
15
|
+
} else if (response.status === 404) {
|
|
16
|
+
resolve(null);
|
|
17
|
+
}
|
|
18
|
+
} catch (e) {
|
|
19
|
+
if (e.name !== 'AbortError') {
|
|
20
|
+
reject(e);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}).catch(() => null);
|
|
24
|
+
}
|
|
25
|
+
return await cache[path];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const getIconByName = (name) => {
|
|
29
|
+
const tryDir = async (dir) => getIconByPath(`${dir}/${name}.svg`);
|
|
30
|
+
|
|
31
|
+
return new Promise(async (resolve, reject) => {
|
|
32
|
+
let svg;
|
|
33
|
+
for(let i = 0; i < Icon.pathToIcons.length && !svg; i++){
|
|
34
|
+
try {
|
|
35
|
+
svg = await tryDir(Icon.pathToIcons[i]);
|
|
36
|
+
} catch(e){}
|
|
37
|
+
}
|
|
38
|
+
if(svg){
|
|
39
|
+
resolve(svg);
|
|
40
|
+
} else {
|
|
41
|
+
resolve(null);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default class Icon extends ShadowComponent {
|
|
47
|
+
/*
|
|
48
|
+
Properties
|
|
49
|
+
*/
|
|
50
|
+
static properties = {
|
|
51
|
+
src: { type: String, reflect: true },
|
|
52
|
+
name: { type: String, reflect: true },
|
|
53
|
+
iconContent: { type: String }
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
constructor(name = '') {
|
|
57
|
+
super();
|
|
58
|
+
this.src = '';
|
|
59
|
+
this.name = name;
|
|
60
|
+
this.iconContent = '';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
Lifecycle Callbacks
|
|
65
|
+
*/
|
|
66
|
+
updated(changedProperties) {
|
|
67
|
+
super.updated();
|
|
68
|
+
|
|
69
|
+
if (changedProperties.has('src') || changedProperties.has('name')) {
|
|
70
|
+
this.loadIcon();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (changedProperties.has('iconContent')) {
|
|
74
|
+
this.fixSVG();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
Methods
|
|
80
|
+
*/
|
|
81
|
+
async loadIcon() {
|
|
82
|
+
let svg;
|
|
83
|
+
|
|
84
|
+
if (this.src) {
|
|
85
|
+
svg = await getIconByPath(this.src);
|
|
86
|
+
} else if (this.name) {
|
|
87
|
+
svg = await getIconByName(this.name);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (svg) {
|
|
91
|
+
this.iconContent = svg;
|
|
92
|
+
} else {
|
|
93
|
+
// Check for slotted fallback content first
|
|
94
|
+
const slottedContent = this.innerHTML.trim();
|
|
95
|
+
if (slottedContent) {
|
|
96
|
+
this.iconContent = slottedContent;
|
|
97
|
+
} else {
|
|
98
|
+
this.iconContent = Icon.fallback;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fixSVG() {
|
|
104
|
+
// Use setTimeout to ensure DOM is updated
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
const $svg = this.querySelector('svg');
|
|
107
|
+
if ($svg) {
|
|
108
|
+
$svg.removeAttribute('width');
|
|
109
|
+
$svg.removeAttribute('height');
|
|
110
|
+
$svg.querySelectorAll('path, rect, circle').forEach($path => {
|
|
111
|
+
$path.setAttribute('fill', 'currentColor');
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}, 0);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/*
|
|
118
|
+
Styles
|
|
119
|
+
*/
|
|
120
|
+
static styles = css`
|
|
121
|
+
:host {
|
|
122
|
+
display: inline-block;
|
|
123
|
+
vertical-align: bottom;
|
|
124
|
+
}
|
|
125
|
+
::slotted(svg), svg {
|
|
126
|
+
height: 1.35em;
|
|
127
|
+
vertical-align: middle;
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
Rendering
|
|
133
|
+
*/
|
|
134
|
+
render() {
|
|
135
|
+
if (!this.iconContent) {
|
|
136
|
+
// Show slotted content while loading
|
|
137
|
+
return html`<slot></slot>`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return html`${unsafeHTML(this.iconContent)}`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/*
|
|
144
|
+
Static Properties
|
|
145
|
+
*/
|
|
146
|
+
static pathToIcons = [
|
|
147
|
+
'/icons'
|
|
148
|
+
];
|
|
149
|
+
|
|
150
|
+
static fallback = `
|
|
151
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path fill="currentColor" d="M480-79q-16 0-30.5-6T423-102L102-423q-11-12-17-26.5T79-480q0-16 6-31t17-26l321-321q12-12 26.5-17.5T480-881q16 0 31 5.5t26 17.5l321 321q12 11 17.5 26t5.5 31q0 16-5.5 30.5T858-423L537-102q-11 11-26 17t-31 6Zm0-80 321-321-321-321-321 321 321 321Zm-40-281h80v-240h-80v240Zm40 120q17 0 28.5-11.5T520-360q0-17-11.5-28.5T480-400q-17 0-28.5 11.5T440-360q0 17 11.5 28.5T480-320Zm0-160Z"/></svg>
|
|
152
|
+
`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
window.customElements.define('k-icon', Icon);
|