kempo-ui 0.4.0 → 0.4.2

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 (82) hide show
  1. package/bin/get_icon.js +0 -0
  2. package/bin/highlight_code.js +0 -0
  3. package/bin/icon.js +0 -0
  4. package/bin/list_icons.js +0 -0
  5. package/dist/components/Slider.js +188 -0
  6. package/dist/components/Split.js +31 -13
  7. package/docs/components/accordion.html +4 -0
  8. package/docs/components/aside.html +4 -0
  9. package/docs/components/card.html +4 -0
  10. package/docs/components/code-editor.html +4 -0
  11. package/docs/components/color-picker.html +4 -0
  12. package/docs/components/combobox.html +4 -0
  13. package/docs/components/content-slider.html +4 -0
  14. package/docs/components/context.html +4 -0
  15. package/docs/components/dialog.html +4 -0
  16. package/docs/components/dropdown.html +4 -0
  17. package/docs/components/filter-list.html +4 -0
  18. package/docs/components/focus-capture.html +4 -0
  19. package/docs/components/html-editor.html +4 -0
  20. package/docs/components/hybrid-component.html +4 -0
  21. package/docs/components/icon.html +4 -0
  22. package/docs/components/import.html +4 -0
  23. package/docs/components/light-component.html +4 -0
  24. package/docs/components/nav-spacer.html +4 -0
  25. package/docs/components/nav.html +4 -0
  26. package/docs/components/photo-viewer.html +4 -0
  27. package/docs/components/progress.html +4 -0
  28. package/docs/components/resize.html +4 -0
  29. package/docs/components/shadow-component.html +4 -0
  30. package/docs/components/show-more.html +4 -0
  31. package/docs/components/slider.html +781 -0
  32. package/docs/components/sortable.html +4 -0
  33. package/docs/components/spinner.html +4 -0
  34. package/docs/components/split.html +32 -3
  35. package/docs/components/table.html +4 -0
  36. package/docs/components/tableControls.html +4 -0
  37. package/docs/components/tableCustomFields.html +4 -0
  38. package/docs/components/tableFetchRecords.html +4 -0
  39. package/docs/components/tableFieldSortHide.html +4 -0
  40. package/docs/components/tablePagination.html +4 -0
  41. package/docs/components/tablePlaceholder.html +4 -0
  42. package/docs/components/tableRecordEditing.html +4 -0
  43. package/docs/components/tableRecordFiltering.html +4 -0
  44. package/docs/components/tableRecordHiding.html +4 -0
  45. package/docs/components/tableRecordSearching.html +4 -0
  46. package/docs/components/tableRecordSelection.html +4 -0
  47. package/docs/components/tableRowControls.html +4 -0
  48. package/docs/components/tableServerSync.html +4 -0
  49. package/docs/components/tableSorting.html +4 -0
  50. package/docs/components/tabs.html +4 -0
  51. package/docs/components/tags.html +4 -0
  52. package/docs/components/theme-select.html +4 -0
  53. package/docs/components/theme-switcher.html +4 -0
  54. package/docs/components/timestamp.html +4 -0
  55. package/docs/components/toast.html +4 -0
  56. package/docs/components/toggle.html +4 -0
  57. package/docs/components/tree.html +4 -0
  58. package/docs/index.html +10 -0
  59. package/docs/src/components/Slider.js +188 -0
  60. package/docs/src/components/Split.js +31 -13
  61. package/docs/utils/context.html +4 -0
  62. package/docs/utils/cookie.html +4 -0
  63. package/docs/utils/debounce.html +4 -0
  64. package/docs/utils/drag.html +4 -0
  65. package/docs/utils/elevation.html +4 -0
  66. package/docs/utils/formatTimestamp.html +4 -0
  67. package/docs/utils/object.html +4 -0
  68. package/docs/utils/propConverters.html +4 -0
  69. package/docs/utils/string.html +4 -0
  70. package/docs/utils/theme.html +4 -0
  71. package/docs/utils/toTitleCase.html +4 -0
  72. package/docs/utils/type.html +4 -0
  73. package/docs/utils/wait.html +4 -0
  74. package/docs-src/components/slider.page.html +331 -0
  75. package/docs-src/components/split.page.html +28 -3
  76. package/docs-src/index.page.html +6 -0
  77. package/docs-src/nav.fragment.html +4 -0
  78. package/llms.txt +1 -0
  79. package/package.json +1 -1
  80. package/src/components/Slider.js +480 -0
  81. package/src/components/Split.js +163 -132
  82. package/tests/components/Slider.browser-test.js +823 -0
@@ -1,125 +1,157 @@
1
1
  import { html, css } from '../lit-all.min.js';
2
2
  import ShadowComponent from './ShadowComponent.js';
3
3
  import drag from '../utils/drag.js';
4
+ import { boolExists } from '../utils/propConverters.js';
4
5
 
5
6
  export default class Split extends ShadowComponent {
6
- static properties = {
7
- resizing: { type: Boolean, reflect: true },
8
- stacked: { type: Boolean, reflect: true },
9
- stackWidth: { type: Number, attribute: 'stack-width' },
10
- direction: { type: String, reflect: true },
11
- persistentId: { type: String, reflect: true, attribute: 'persistent-id' }
12
- };
13
-
14
- constructor() {
15
- super();
16
-
17
- this.resizing = false;
18
- this.stacked = false;
19
- this.stackWidth = 0;
20
- this.direction = 'horizontal';
21
- this.persistentId = null;
22
-
23
- // Private state
24
- this.dragStartSize = 0;
25
- this.dragCleanup = () => {};
26
- this.resizeObserver = null;
27
- }
28
-
29
- /*
30
- Lifecycle Callbacks
31
- */
32
- firstUpdated() {
33
- super.firstUpdated();
34
- this.setupDragHandler();
35
- this.setupResizeObserver();
36
- if(this.persistentId && window?.localStorage) {
37
- const size = window.localStorage.getItem(`split-persistent-id-${this.persistentId}`);
38
- if(size) this.setSize(size);
39
- }
40
- }
41
-
42
- disconnectedCallback() {
43
- super.disconnectedCallback();
44
- this.dragCleanup();
45
- if(this.resizeObserver) {
46
- this.resizeObserver.disconnect();
47
- this.resizeObserver = null;
48
- }
49
- }
50
-
51
- /*
52
- Event Handlers
53
- */
54
- handleDragStart = () => {
55
- this.resizing = true;
56
- this.dragStartSize = Math.round(this.shadowRoot.getElementById('pane-1').getBoundingClientRect()[this.direction === 'vertical' ? 'height' : 'width']);
57
- this.dispatchEvent(new CustomEvent('resizestart', {
58
- detail: { startSize: this.dragStartSize },
59
- bubbles: true
60
- }));
61
- };
62
-
63
- handleDrag = ({ x, y }) => {
64
- const delta = this.direction === 'vertical' ? y : x;
65
- const size = `${this.dragStartSize + delta}px`;
66
- this.setSize(size);
67
- this.dispatchEvent(new CustomEvent('resize', {
68
- detail: { size },
69
- bubbles: true
70
- }));
71
- };
72
-
73
- handleDragEnd = ({ x, y }) => {
74
- this.resizing = false;
75
- const delta = this.direction === 'vertical' ? y : x;
76
- const size = `${this.dragStartSize + delta}px`;
77
- this.setSize(size);
78
- if(this.persistentId && window?.localStorage) {
79
- window.localStorage.setItem(`split-persistent-id-${this.persistentId}`, size);
80
- }
81
- this.dispatchEvent(new CustomEvent('resizeend', {
82
- detail: { size },
83
- bubbles: true
84
- }));
85
- };
86
-
87
- /*
88
- Public Methods
89
- */
90
- setSize(size) {
91
- this.style.setProperty('--pane_1_size', size);
92
- }
93
-
94
- setupDragHandler() {
95
- const handle = this.shadowRoot.getElementById('divider-handle');
96
- if(handle) {
97
- this.dragCleanup = drag({
98
- element: handle,
99
- callback: this.handleDrag,
100
- startCallback: this.handleDragStart,
101
- endCallback: this.handleDragEnd
102
- });
103
- }
104
- }
105
-
106
- setupResizeObserver() {
107
- this.resizeObserver = new ResizeObserver(entries => {
108
- for(const entry of entries) {
109
- const width = entry.contentRect.width;
110
- this.stacked = width <= this.stackWidth;
111
- }
112
- });
113
- this.resizeObserver.observe(this);
114
- }
115
-
116
- /*
117
- Styles
118
- */
119
- static styles = css`
7
+ static properties = {
8
+ resizing: { type: Boolean, reflect: true },
9
+ stacked: { type: Boolean, reflect: true },
10
+ stackWidth: { type: Number, attribute: 'stack-width' },
11
+ direction: { type: String, reflect: true },
12
+ persistentId: { type: String, reflect: true, attribute: 'persistent-id' },
13
+ grip: { type: Boolean, reflect: true, converter: boolExists }
14
+ };
15
+
16
+ constructor() {
17
+ super();
18
+
19
+ this.resizing = false;
20
+ this.stacked = false;
21
+ this.stackWidth = 0;
22
+ this.direction = 'horizontal';
23
+ this.persistentId = null;
24
+ this.grip = false;
25
+
26
+ // Private state
27
+ this.dragStartSize = 0;
28
+ this.dragCleanup = () => { };
29
+ this.resizeObserver = null;
30
+ }
31
+
32
+ /*
33
+ Lifecycle Callbacks
34
+ */
35
+ firstUpdated() {
36
+ super.firstUpdated();
37
+ if(this.grip){
38
+ const el = document.createElement('div');
39
+ el.style.cssText = 'position:absolute;visibility:hidden;width:var(--handle_width)';
40
+ this.shadowRoot.appendChild(el);
41
+ const handleWidth = el.offsetWidth;
42
+ this.shadowRoot.removeChild(el);
43
+ const gripWidth = handleWidth % 2 === 0 ? handleWidth - 1 : handleWidth;
44
+ this.style.setProperty('--handle_grip_width', `${gripWidth}px`);
45
+ }
46
+ this.setupDragHandler();
47
+ this.setupResizeObserver();
48
+ if (this.persistentId && window?.localStorage) {
49
+ const size = window.localStorage.getItem(`split-persistent-id-${this.persistentId}`);
50
+ if (size) this.setSize(size);
51
+ }
52
+ }
53
+
54
+ disconnectedCallback() {
55
+ super.disconnectedCallback();
56
+ this.dragCleanup();
57
+ if (this.resizeObserver) {
58
+ this.resizeObserver.disconnect();
59
+ this.resizeObserver = null;
60
+ }
61
+ }
62
+
63
+ /*
64
+ Event Handlers
65
+ */
66
+ handleDragStart = () => {
67
+ this.resizing = true;
68
+ this.dragStartSize = Math.round(this.shadowRoot.getElementById('pane-1').getBoundingClientRect()[this.direction === 'vertical' ? 'height' : 'width']);
69
+ this.dispatchEvent(new CustomEvent('resizestart', {
70
+ detail: { startSize: this.dragStartSize },
71
+ bubbles: true
72
+ }));
73
+ };
74
+
75
+ handleDrag = ({ x, y }) => {
76
+ const delta = this.direction === 'vertical' ? y : x;
77
+ const size = `${this.dragStartSize + delta}px`;
78
+ this.setSize(size);
79
+ this.dispatchEvent(new CustomEvent('resize', {
80
+ detail: { size },
81
+ bubbles: true
82
+ }));
83
+ };
84
+
85
+ handleDragEnd = ({ x, y }) => {
86
+ this.resizing = false;
87
+ const delta = this.direction === 'vertical' ? y : x;
88
+ const size = `${this.dragStartSize + delta}px`;
89
+ this.setSize(size);
90
+ if (this.persistentId && window?.localStorage) {
91
+ window.localStorage.setItem(`split-persistent-id-${this.persistentId}`, size);
92
+ }
93
+ this.dispatchEvent(new CustomEvent('resizeend', {
94
+ detail: { size },
95
+ bubbles: true
96
+ }));
97
+ };
98
+
99
+ /*
100
+ Public Methods
101
+ */
102
+ setSize(size) {
103
+ this.style.setProperty('--pane_1_size', size);
104
+ }
105
+
106
+ setupDragHandler() {
107
+ const handle = this.shadowRoot.getElementById('divider-handle');
108
+ if (handle) {
109
+ this.dragCleanup = drag({
110
+ element: handle,
111
+ callback: this.handleDrag,
112
+ startCallback: this.handleDragStart,
113
+ endCallback: this.handleDragEnd
114
+ });
115
+ }
116
+ }
117
+
118
+ setupResizeObserver() {
119
+ this.resizeObserver = new ResizeObserver(entries => {
120
+ for (const entry of entries) {
121
+ const width = entry.contentRect.width;
122
+ this.stacked = width <= this.stackWidth;
123
+ }
124
+ });
125
+ this.resizeObserver.observe(this);
126
+ }
127
+
128
+ /*
129
+ Styles
130
+ */
131
+
132
+
133
+ /*
134
+ Rendering
135
+ */
136
+ render() {
137
+ return html`
138
+ <div id="pane-1" class="pane">
139
+ <slot></slot>
140
+ </div>
141
+ <div id="divider-handle">
142
+ <div id="divider-border">
143
+ ${this.grip ? html`<div id="divider-grip"></div>` : ''}
144
+ </div>
145
+ </div>
146
+ <div id="pane-2" class="pane">
147
+ <slot name="right"></slot>
148
+ </div>
149
+ `;
150
+ }
151
+ static styles = css`
120
152
  :host {
121
153
  --pane_1_size: calc((100% - var(--handle_width)) / 2);
122
- --handle_width: 0.5rem;
154
+ --handle_width: 7px;
123
155
  --min_pane_size: 6rem;
124
156
 
125
157
  height: 100%;
@@ -145,6 +177,7 @@ export default class Split extends ShadowComponent {
145
177
  }
146
178
 
147
179
  #divider-handle {
180
+ position: relative;
148
181
  display: flex;
149
182
  flex-shrink: 0;
150
183
  justify-content: center;
@@ -165,10 +198,21 @@ export default class Split extends ShadowComponent {
165
198
  }
166
199
 
167
200
  #divider-border {
201
+ position: relative;
168
202
  width: 1px;
169
203
  height: 100%;
170
204
  border-left: 1px solid var(--c_border);
171
205
  }
206
+ #divider-grip {
207
+ position: absolute;
208
+ top: 50%;
209
+ left: 50%;
210
+ transform: translate(-50%, -50%);
211
+ width: var(--handle_grip_width, var(--handle_width));
212
+ height: 2rem;
213
+ border-radius: 0.25rem;
214
+ background-color: var(--c_border);
215
+ }
172
216
 
173
217
  #pane-2 {
174
218
  flex: 1 1;
@@ -223,24 +267,11 @@ export default class Split extends ShadowComponent {
223
267
  border-left: none;
224
268
  border-top: 1px solid var(--c_border);
225
269
  }
270
+ :host([direction="vertical"]) #divider-grip {
271
+ width: 2rem;
272
+ height: 0.5rem;
273
+ }
226
274
  `;
227
-
228
- /*
229
- Rendering
230
- */
231
- render() {
232
- return html`
233
- <div id="pane-1" class="pane">
234
- <slot></slot>
235
- </div>
236
- <div id="divider-handle">
237
- <div id="divider-border"></div>
238
- </div>
239
- <div id="pane-2" class="pane">
240
- <slot name="right"></slot>
241
- </div>
242
- `;
243
- }
244
275
  }
245
276
 
246
277
  customElements.define('k-split', Split);