kempo-ui 0.0.3 → 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.
Files changed (137) hide show
  1. package/.github/workflows/publish-major.yml +39 -0
  2. package/.github/workflows/publish-minor.yml +39 -0
  3. package/.github/workflows/{publish-npm.yml → publish-patch.yml} +1 -1
  4. package/.vscode/settings.json +2 -0
  5. package/dist/kempo-hljs.css +1 -0
  6. package/dist/src/components/Accordion.js +36 -0
  7. package/dist/src/components/Card.js +37 -0
  8. package/dist/src/components/Collapsible.js +41 -0
  9. package/dist/src/components/ContentSlider.js +44 -0
  10. package/dist/src/components/Dialog.js +113 -0
  11. package/dist/src/components/Icon.js +2 -2
  12. package/dist/src/components/PersistantCollapsible.js +1 -0
  13. package/dist/src/components/PhotoViewer.js +135 -0
  14. package/dist/src/components/Resize.js +96 -0
  15. package/dist/src/components/ShowMore.js +42 -0
  16. package/dist/src/components/SideMenu.js +1 -1
  17. package/dist/src/components/Split.js +84 -0
  18. package/dist/src/components/Tabs.js +155 -0
  19. package/dist/src/components/Tags.js +69 -0
  20. package/dist/src/components/ThemeSwitcher.js +23 -0
  21. package/dist/src/components/Timestamp.js +1 -0
  22. package/dist/src/utils/debounce.js +1 -0
  23. package/dist/src/utils/drag.js +1 -0
  24. package/dist/src/utils/formatTimestamp.js +1 -0
  25. package/dist/src/utils/propConverters.js +1 -0
  26. package/dist/src/utils/watchWindowSize.js +1 -0
  27. package/docs/components/accordion.html +69 -25
  28. package/docs/components/card.html +6 -5
  29. package/docs/components/collapsible.html +198 -0
  30. package/docs/components/content-slider.html +56 -26
  31. package/docs/components/dialog.html +54 -48
  32. package/docs/components/focus-capture.html +2 -3
  33. package/docs/components/icon.html +5 -8
  34. package/docs/components/import.html +1 -6
  35. package/docs/components/persistant-collapsible.html +123 -0
  36. package/docs/components/photo-viewer.html +226 -0
  37. package/docs/components/resize.html +44 -18
  38. package/docs/components/show-more.html +12 -6
  39. package/docs/components/side-menu.html +3 -12
  40. package/docs/components/split.html +26 -5
  41. package/docs/components/tablePagination.html +4 -4
  42. package/docs/components/tableRecordFiltering.html +16 -3
  43. package/docs/components/tableRecordSelection.html +2 -2
  44. package/docs/components/tabs.html +24 -7
  45. package/docs/components/tags.html +24 -8
  46. package/docs/components/theme-switcher.html +3 -6
  47. package/docs/components/timestamp.html +20 -24
  48. package/docs/components/toast.html +23 -32
  49. package/docs/components/toggle.html +4 -3
  50. package/docs/kempo-hljs.css +1 -0
  51. package/docs/media/civic.jpg +0 -0
  52. package/docs/media/corvette.jpg +0 -0
  53. package/docs/media/evo.jpg +0 -0
  54. package/docs/media/gtr.jpg +0 -0
  55. package/docs/media/nsx.jpg +0 -0
  56. package/docs/nav.inc.html +11 -17
  57. package/docs/src/components/Accordion.js +36 -0
  58. package/docs/src/components/Card.js +37 -0
  59. package/docs/src/components/Collapsible.js +41 -0
  60. package/docs/src/components/ContentSlider.js +44 -0
  61. package/docs/src/components/Dialog.js +113 -0
  62. package/docs/src/components/Icon.js +2 -2
  63. package/docs/src/components/PersistantCollapsible.js +1 -0
  64. package/docs/src/components/PhotoViewer.js +135 -0
  65. package/docs/src/components/Resize.js +96 -0
  66. package/docs/src/components/ShowMore.js +42 -0
  67. package/docs/src/components/SideMenu.js +1 -1
  68. package/docs/src/components/Split.js +84 -0
  69. package/docs/src/components/Tabs.js +155 -0
  70. package/docs/src/components/Tags.js +69 -0
  71. package/docs/src/components/ThemeSwitcher.js +23 -0
  72. package/docs/src/components/Timestamp.js +1 -0
  73. package/docs/src/utils/debounce.js +1 -0
  74. package/docs/src/utils/drag.js +1 -0
  75. package/docs/src/utils/formatTimestamp.js +1 -0
  76. package/docs/src/utils/propConverters.js +1 -0
  77. package/docs/src/utils/watchWindowSize.js +1 -0
  78. package/docs/utils/debounce.html +78 -0
  79. package/docs/utils/drag.html +104 -0
  80. package/docs/utils/formatTimestamp.html +114 -0
  81. package/docs/utils/propConverters.html +132 -0
  82. package/docs/utils/watchWindowSize.html +166 -0
  83. package/icons/error.svg +1 -1
  84. package/icons/warning.svg +1 -1
  85. package/package.json +1 -1
  86. package/scripts/build.js +1 -1
  87. package/scripts/docs.js +4 -2
  88. package/src/components/Accordion.js +229 -0
  89. package/src/components/Collapsible.js +109 -0
  90. package/src/components/ContentSlider.js +205 -0
  91. package/src/components/Dialog.js +368 -0
  92. package/src/components/PersistantCollapsible.js +69 -0
  93. package/src/components/PhotoViewer.js +368 -0
  94. package/src/components/Resize.js +210 -0
  95. package/src/components/ShadowComponent.js +3 -1
  96. package/src/components/ShowMore.js +109 -0
  97. package/src/components/Sortable.js +193 -0
  98. package/src/components/Split.js +192 -0
  99. package/src/components/Table.js +1202 -0
  100. package/src/components/Tabs.js +428 -0
  101. package/src/components/Tags.js +253 -0
  102. package/src/components/Timestamp.js +31 -0
  103. package/src/components/Toast.js +454 -0
  104. package/src/components/Toggle.js +173 -0
  105. package/src/components/tableControls/DeleteRecord.js +29 -0
  106. package/src/components/tableControls/Edit.js +88 -0
  107. package/src/components/tableControls/ExportCSV.js +71 -0
  108. package/src/components/tableControls/ExportJson.js +55 -0
  109. package/src/components/tableControls/FieldSortHide.js +76 -0
  110. package/src/components/tableControls/Filters.js +114 -0
  111. package/src/components/tableControls/FirstPage.js +65 -0
  112. package/src/components/tableControls/HiddenCount.js +45 -0
  113. package/src/components/tableControls/Hide.js +34 -0
  114. package/src/components/tableControls/LastPage.js +65 -0
  115. package/src/components/tableControls/NextPage.js +65 -0
  116. package/src/components/tableControls/PageSelect.js +109 -0
  117. package/src/components/tableControls/PageSize.js +68 -0
  118. package/src/components/tableControls/PrevPage.js +65 -0
  119. package/src/components/tableControls/Search.js +58 -0
  120. package/src/components/tableControls/ShowAll.js +34 -0
  121. package/src/components/tableControls/TableControl.js +105 -0
  122. package/src/utils/debounce.js +9 -0
  123. package/src/utils/drag.js +80 -0
  124. package/src/utils/formatTimestamp.js +27 -0
  125. package/src/utils/toTitleCase.js +9 -0
  126. package/src/utils/watchWindowSize.js +16 -0
  127. package/dist/src/utils/cli.js +0 -1
  128. package/dist/src/utils/fs-utils.js +0 -1
  129. package/docs/components/component.html +0 -90
  130. package/docs/components/directory-viewer.html +0 -90
  131. package/docs/components/lazy-component.html +0 -84
  132. package/docs/components/reactive-component.html +0 -69
  133. package/docs/components/reactive-lazy-component.html +0 -69
  134. package/docs/components/search.html +0 -102
  135. package/docs/components/sortable.html +0 -96
  136. package/src/utils/cli.js +0 -43
  137. package/src/utils/fs-utils.js +0 -41
@@ -0,0 +1,193 @@
1
+ import { LitElement, html, css } from '../lit-all.min.js';
2
+ import drag from '../utils/drag.js';
3
+
4
+ /*
5
+ Sortable Container Component
6
+ */
7
+ export class Sortable extends LitElement {
8
+ getCursorElement(){
9
+ const items = Array.from(this.children).filter(child =>
10
+ child.tagName === 'K-SORTABLE-ITEM' && !child.hasAttribute('sorting')
11
+ );
12
+ if(items.length === 0) return null;
13
+
14
+ const cursorY = event.clientY;
15
+ if(cursorY < items[0].getBoundingClientRect().top){
16
+ return [items[0], 'before'];
17
+ }
18
+ if(cursorY > items[items.length - 1].getBoundingClientRect().bottom){
19
+ return [items[items.length - 1], 'after'];
20
+ }
21
+
22
+ for(const item of items){
23
+ const rect = item.getBoundingClientRect();
24
+ const middleY = rect.top + rect.height / 2;
25
+ if(cursorY < middleY){
26
+ return [item, 'before'];
27
+ } else if(cursorY < rect.bottom){
28
+ return [item, 'after'];
29
+ }
30
+ }
31
+ return null;
32
+ }
33
+
34
+ render(){
35
+ return html`<slot></slot>`;
36
+ }
37
+
38
+ static styles = css`
39
+ :host {
40
+ display: block;
41
+ }
42
+ `;
43
+ }
44
+ customElements.define('k-sortable', Sortable);
45
+
46
+ /*
47
+ Sortable Item Component
48
+ */
49
+ export class SortableItem extends LitElement {
50
+ static properties = {
51
+ sorting: { type: Boolean, reflect: true }
52
+ };
53
+
54
+ constructor(){
55
+ super();
56
+ this.cleanupDrag = null;
57
+ }
58
+
59
+ /*
60
+ Lifecycle Callbacks
61
+ */
62
+ firstUpdated(){
63
+ this.setupDrag();
64
+ }
65
+
66
+ updated(changedProperties){
67
+ super.updated(changedProperties);
68
+ if(changedProperties.has('sorting') && !this.sorting){
69
+ // Re-setup drag after sorting completes
70
+ this.setupDrag();
71
+ }
72
+ }
73
+
74
+ disconnectedCallback(){
75
+ super.disconnectedCallback();
76
+ if(this.cleanupDrag){
77
+ this.cleanupDrag();
78
+ this.cleanupDrag = null;
79
+ }
80
+ }
81
+
82
+ /*
83
+ Methods
84
+ */
85
+ setupDrag(){
86
+ if(this.cleanupDrag){
87
+ this.cleanupDrag();
88
+ }
89
+ const handle = this.shadowRoot.getElementById('handle');
90
+ if(handle){
91
+ this.cleanupDrag = drag({
92
+ element: handle,
93
+ startCallback: this.handleDragStart,
94
+ moveCallback: this.handleDragMove,
95
+ endCallback: this.handleDragEnd
96
+ });
97
+ }
98
+ }
99
+
100
+ /*
101
+ Event Handlers
102
+ */
103
+ handleDragStart = () => {
104
+ this.sorting = true;
105
+ };
106
+
107
+ handleDragMove = ({y}) => {
108
+ this.style.transform = `translateY(${y}px)`;
109
+ this.style.zIndex = '9999';
110
+ const [target, position] = this.sortable.getCursorElement();
111
+ Array.from(this.sortable.children).forEach(child => {
112
+ child.classList.remove('target-before', 'target-after');
113
+ });
114
+ if(target){
115
+ target.classList.add(`target-${position}`);
116
+ }
117
+ };
118
+
119
+ handleDragEnd = () => {
120
+ this.sorting = false;
121
+ this.style.transform = '';
122
+ this.style.zIndex = '';
123
+ const [target, position] = this.sortable.getCursorElement();
124
+ Array.from(this.sortable.children).forEach(child => {
125
+ child.classList.remove('target-before', 'target-after');
126
+ });
127
+ if(target){
128
+ if(position === 'before'){
129
+ this.sortable.insertBefore(this, target);
130
+ } else if(position === 'after'){
131
+ this.sortable.insertBefore(this, target.nextSibling);
132
+ }
133
+ this.sortable.dispatchEvent(new CustomEvent('sort', { bubbles: true }));
134
+ }
135
+ };
136
+
137
+ /*
138
+ Getters
139
+ */
140
+ get sortable(){
141
+ return this.closest('k-sortable');
142
+ }
143
+
144
+ /*
145
+ Rendering
146
+ */
147
+ render(){
148
+ return html`
149
+ <div id="handle">
150
+ <k-icon name="drag-handle"></k-icon>
151
+ </div>
152
+ <div id="content" class="p pl0">
153
+ <slot></slot>
154
+ </div>
155
+ `;
156
+ }
157
+
158
+ static styles = css`
159
+ :host {
160
+ display: block;
161
+ border: 1px solid var(--c_border);
162
+ user-select: none;
163
+ position: relative;
164
+ }
165
+ :host([sorting]){
166
+ opacity: 0.8;
167
+ }
168
+ #handle {
169
+ display: inline-block;
170
+ cursor: pointer;
171
+ padding: var(--spacer);
172
+ }
173
+ #content {
174
+ display: inline-block;
175
+ }
176
+ :host(.target-before)::before,
177
+ :host(.target-after)::after {
178
+ content: '';
179
+ position: absolute;
180
+ left: 0;
181
+ right: 0;
182
+ height: 4px;
183
+ background-color: var(--c_primary);
184
+ }
185
+ :host(.target-before)::before {
186
+ top: -2px;
187
+ }
188
+ :host(.target-after)::after {
189
+ bottom: -2px;
190
+ }
191
+ `;
192
+ }
193
+ customElements.define('k-sortable-item', SortableItem);
@@ -0,0 +1,192 @@
1
+ import { html, css } from '../lit-all.min.js';
2
+ import ShadowComponent from './ShadowComponent.js';
3
+ import drag from '../utils/drag.js';
4
+ import { watchWindowSize, unwatchWindowSize } from '../utils/watchWindowSize.js';
5
+
6
+ export default class Split extends ShadowComponent {
7
+ static properties = {
8
+ resizing: { type: Boolean, reflect: true },
9
+ stacked: { type: Boolean, reflect: true },
10
+ stackWidth: { type: Number, attribute: 'stack-width' }
11
+ };
12
+
13
+ constructor() {
14
+ super();
15
+
16
+ this.resizing = false;
17
+ this.stacked = false;
18
+ this.stackWidth = 0;
19
+
20
+ // Private state
21
+ this.dragStartWidth = 0;
22
+ this.dragCleanup = () => {};
23
+ this.windowResizeHandler = this.handleWindowResize.bind(this);
24
+ }
25
+
26
+ /*
27
+ Lifecycle Callbacks
28
+ */
29
+ firstUpdated() {
30
+ super.firstUpdated();
31
+ this.setupDragHandler();
32
+ this.stacked = watchWindowSize(this.windowResizeHandler) <= this.stackWidth;
33
+ }
34
+
35
+ disconnectedCallback() {
36
+ super.disconnectedCallback();
37
+ this.dragCleanup();
38
+ unwatchWindowSize(this.windowResizeHandler);
39
+ }
40
+
41
+ /*
42
+ Event Handlers
43
+ */
44
+ handleWindowResize = (width) => {
45
+ this.stacked = width <= this.stackWidth;
46
+ };
47
+
48
+ handleDragStart = () => {
49
+ this.resizing = true;
50
+ this.dragStartWidth = Math.round(this.shadowRoot.getElementById('left').getBoundingClientRect().width);
51
+ this.dispatchEvent(new CustomEvent('resizestart', {
52
+ detail: { startSize: this.dragStartWidth },
53
+ bubbles: true
54
+ }));
55
+ };
56
+
57
+ handleDrag = ({ x }) => {
58
+ const size = `${this.dragStartWidth + x}px`;
59
+ this.setSize(size);
60
+ this.dispatchEvent(new CustomEvent('resize', {
61
+ detail: { size },
62
+ bubbles: true
63
+ }));
64
+ };
65
+
66
+ handleDragEnd = ({ x }) => {
67
+ this.resizing = false;
68
+ const width = this.dragStartWidth + x;
69
+ const size = `${width}px`;
70
+ this.setSize(size);
71
+ this.dispatchEvent(new CustomEvent('resizeend', {
72
+ detail: { size },
73
+ bubbles: true
74
+ }));
75
+ };
76
+
77
+ /*
78
+ Public Methods
79
+ */
80
+ setSize(size) {
81
+ this.style.setProperty('--left_width', size);
82
+ }
83
+
84
+ setupDragHandler() {
85
+ const handle = this.shadowRoot.getElementById('divider-handle');
86
+ if(handle) {
87
+ this.dragCleanup = drag({
88
+ element: handle,
89
+ callback: this.handleDrag,
90
+ startCallback: this.handleDragStart,
91
+ endCallback: this.handleDragEnd
92
+ });
93
+ }
94
+ }
95
+
96
+ /*
97
+ Styles
98
+ */
99
+ static styles = css`
100
+ :host {
101
+ --left_width: calc((100% - var(--handle_width)) / 2);
102
+ --handle_width: 0.5rem;
103
+ --min_pane_width: 6rem;
104
+
105
+ height: 100%;
106
+ display: flex;
107
+ align-items: stretch;
108
+ flex: 1 1 auto;
109
+ overflow: hidden;
110
+ }
111
+
112
+ .pane, #divider-handle {
113
+ display: inline-block;
114
+ }
115
+
116
+ .pane {
117
+ min-width: var(--min_pane_width);
118
+ max-width: calc(100% - var(--min_pane_width));
119
+ max-height: 100%;
120
+ overflow: hidden;
121
+ }
122
+
123
+ #left {
124
+ flex: 0 0 var(--left_width);
125
+ }
126
+
127
+ #divider-handle {
128
+ display: flex;
129
+ justify-content: center;
130
+ width: var(--handle_width);
131
+ cursor: ew-resize;
132
+ }
133
+
134
+ :host([resizing]) #divider-handle {
135
+ background-color: var(--tc_primary);
136
+ }
137
+
138
+ :host([resizing]) .pane {
139
+ pointer-events: none;
140
+ user-select: none;
141
+ }
142
+
143
+ #divider-border {
144
+ width: 1px;
145
+ height: 100%;
146
+ border-left: 1px solid var(--c_border);
147
+ }
148
+
149
+ #right {
150
+ flex: 1 1;
151
+ }
152
+
153
+ :host([stacked]) #left,
154
+ :host([stacked]) #right {
155
+ display: block;
156
+ }
157
+
158
+ :host([stacked]) #divider-handle {
159
+ display: none;
160
+ }
161
+
162
+ :host([stacked]) .pane {
163
+ min-width: 0;
164
+ max-width: 100%;
165
+ max-height: none;
166
+ overflow: auto;
167
+ }
168
+
169
+ :host([stacked]) {
170
+ display: block;
171
+ }
172
+ `;
173
+
174
+ /*
175
+ Rendering
176
+ */
177
+ render() {
178
+ return html`
179
+ <div id="left" class="pane">
180
+ <slot></slot>
181
+ </div>
182
+ <div id="divider-handle">
183
+ <div id="divider-border"></div>
184
+ </div>
185
+ <div id="right" class="pane">
186
+ <slot name="right"></slot>
187
+ </div>
188
+ `;
189
+ }
190
+ }
191
+
192
+ customElements.define('k-split', Split);