@webtides/element-library 0.3.1 → 0.4.0
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/CHANGELOG.md +193 -0
- package/README.md +72 -56
- package/all.js +16 -0
- package/catalog.js +17 -1
- package/custom-elements.json +14723 -10220
- package/package.json +1 -1
- package/src/components/accordion/accordion.changelog.md +11 -0
- package/src/components/accordion/accordion.js +15 -3
- package/src/components/accordion/accordion.readme.md +27 -1
- package/src/components/accordion/accordion.style.js +19 -0
- package/src/components/app-bar/app-bar.changelog.md +24 -0
- package/src/components/app-bar/app-bar.define.js +3 -0
- package/src/components/app-bar/app-bar.js +91 -0
- package/src/components/app-bar/app-bar.readme.md +130 -0
- package/src/components/app-bar/app-bar.style.js +103 -0
- package/src/components/app-frame/app-frame.changelog.md +45 -0
- package/src/components/app-frame/app-frame.define.js +3 -0
- package/src/components/app-frame/app-frame.events.js +6 -0
- package/src/components/app-frame/app-frame.js +1073 -0
- package/src/components/app-frame/app-frame.readme.md +416 -0
- package/src/components/app-frame/app-frame.style.js +527 -0
- package/src/components/button/button.changelog.md +15 -0
- package/src/components/button/button.events.js +3 -0
- package/src/components/button/button.js +145 -3
- package/src/components/button/button.readme.md +72 -4
- package/src/components/button/button.style.js +161 -7
- package/src/components/description-list/description-list.changelog.md +25 -0
- package/src/components/description-list/description-list.define.js +3 -0
- package/src/components/description-list/description-list.js +44 -0
- package/src/components/description-list/description-list.readme.md +135 -0
- package/src/components/description-list/description-list.style.js +140 -0
- package/src/components/dialog/dialog.changelog.md +7 -0
- package/src/components/dialog/dialog.readme.md +5 -0
- package/src/components/dialog/dialog.style.js +17 -2
- package/src/components/drawer/drawer.changelog.md +7 -0
- package/src/components/drawer/drawer.readme.md +7 -6
- package/src/components/drawer/drawer.style.js +35 -2
- package/src/components/dropdown/dropdown.readme.md +6 -1
- package/src/components/list/list.changelog.md +24 -0
- package/src/components/list/list.define.js +3 -0
- package/src/components/list/list.js +66 -0
- package/src/components/list/list.readme.md +122 -0
- package/src/components/list/list.style.js +56 -0
- package/src/components/list-item/list-item.changelog.md +24 -0
- package/src/components/list-item/list-item.define.js +3 -0
- package/src/components/list-item/list-item.js +128 -0
- package/src/components/list-item/list-item.readme.md +126 -0
- package/src/components/list-item/list-item.style.js +234 -0
- package/src/components/menu/menu.changelog.md +27 -0
- package/src/components/menu/menu.define.js +3 -0
- package/src/components/menu/menu.events.js +5 -0
- package/src/components/menu/menu.js +570 -0
- package/src/components/menu/menu.readme.md +272 -0
- package/src/components/menu/menu.style.js +55 -0
- package/src/components/menu-group/menu-group.changelog.md +20 -0
- package/src/components/menu-group/menu-group.define.js +3 -0
- package/src/components/menu-group/menu-group.js +44 -0
- package/src/components/menu-group/menu-group.readme.md +74 -0
- package/src/components/menu-group/menu-group.style.js +38 -0
- package/src/components/menu-item/menu-item.changelog.md +24 -0
- package/src/components/menu-item/menu-item.define.js +3 -0
- package/src/components/menu-item/menu-item.js +130 -0
- package/src/components/menu-item/menu-item.readme.md +94 -0
- package/src/components/menu-item/menu-item.style.js +87 -0
- package/src/components/nav/nav.changelog.md +35 -0
- package/src/components/nav/nav.define.js +3 -0
- package/src/components/nav/nav.js +212 -0
- package/src/components/nav/nav.readme.md +248 -0
- package/src/components/nav/nav.style.js +269 -0
- package/src/components/nav-item/nav-item.changelog.md +25 -0
- package/src/components/nav-item/nav-item.define.js +3 -0
- package/src/components/nav-item/nav-item.js +75 -0
- package/src/components/nav-item/nav-item.readme.md +111 -0
- package/src/components/nav-item/nav-item.style.js +159 -0
- package/src/components/pagination/pagination.changelog.md +8 -0
- package/src/components/pagination/pagination.js +123 -49
- package/src/components/pagination/pagination.readme.md +24 -6
- package/src/components/pagination/pagination.style.js +11 -1
- package/src/components/scroll-to-top/scroll-to-top.changelog.md +7 -5
- package/src/components/scroll-to-top/scroll-to-top.js +16 -12
- package/src/components/scroll-to-top/scroll-to-top.readme.md +2 -0
- package/src/components/segmented-field/segmented-field.changelog.md +27 -0
- package/src/components/segmented-field/segmented-field.define.js +3 -0
- package/src/components/segmented-field/segmented-field.js +175 -0
- package/src/components/segmented-field/segmented-field.readme.md +140 -0
- package/src/components/segmented-field/segmented-field.style.js +193 -0
- package/src/components/splitter/splitter.changelog.md +24 -0
- package/src/components/splitter/splitter.define.js +3 -0
- package/src/components/splitter/splitter.events.js +4 -0
- package/src/components/splitter/splitter.js +237 -0
- package/src/components/splitter/splitter.readme.md +164 -0
- package/src/components/splitter/splitter.style.js +100 -0
- package/src/components/status-bar/status-bar.changelog.md +25 -0
- package/src/components/status-bar/status-bar.define.js +3 -0
- package/src/components/status-bar/status-bar.js +74 -0
- package/src/components/status-bar/status-bar.readme.md +139 -0
- package/src/components/status-bar/status-bar.style.js +122 -0
- package/src/components/tab-group/tab-group.changelog.md +7 -0
- package/src/components/tab-group/tab-group.js +30 -9
- package/src/components/tab-group/tab-group.readme.md +14 -0
- package/src/components/toast/toast.changelog.md +6 -0
- package/src/components/toast/toast.readme.md +5 -3
- package/src/components/toast/toast.style.js +22 -6
- package/src/components/toolbar/toolbar.changelog.md +24 -0
- package/src/components/toolbar/toolbar.define.js +3 -0
- package/src/components/toolbar/toolbar.js +233 -0
- package/src/components/toolbar/toolbar.readme.md +156 -0
- package/src/components/toolbar/toolbar.style.js +49 -0
- package/src/components/tooltip/tooltip.changelog.md +11 -0
- package/src/components/tooltip/tooltip.js +51 -4
- package/src/components/tooltip/tooltip.readme.md +26 -1
- package/src/components/tree/tree.changelog.md +23 -0
- package/src/components/tree/tree.define.js +3 -0
- package/src/components/tree/tree.js +138 -0
- package/src/components/tree/tree.readme.md +119 -0
- package/src/components/tree/tree.style.js +16 -0
- package/src/components/tree-item/tree-item.changelog.md +23 -0
- package/src/components/tree-item/tree-item.define.js +3 -0
- package/src/components/tree-item/tree-item.events.js +3 -0
- package/src/components/tree-item/tree-item.js +246 -0
- package/src/components/tree-item/tree-item.readme.md +128 -0
- package/src/components/tree-item/tree-item.style.js +226 -0
- package/src/styles/appearance.style.js +47 -0
- package/src/styles/choice-group.style.js +1 -1
- package/src/styles/modal.style.js +14 -1
- package/src/styles/size.style.js +41 -0
- package/src/utils/focus.js +69 -0
- package/src/utils/scroll.js +24 -0
- package/types/all.d.ts +16 -0
- package/types/src/components/accordion/accordion.d.ts +3 -1
- package/types/src/components/app-bar/app-bar.d.ts +43 -0
- package/types/src/components/app-bar/app-bar.define.d.ts +1 -0
- package/types/src/components/app-bar/app-bar.style.d.ts +2 -0
- package/types/src/components/app-frame/app-frame.d.ts +491 -0
- package/types/src/components/app-frame/app-frame.define.d.ts +1 -0
- package/types/src/components/app-frame/app-frame.events.d.ts +7 -0
- package/types/src/components/app-frame/app-frame.style.d.ts +8 -0
- package/types/src/components/button/button.d.ts +61 -0
- package/types/src/components/button/button.events.d.ts +4 -0
- package/types/src/components/description-list/description-list.d.ts +29 -0
- package/types/src/components/description-list/description-list.define.d.ts +1 -0
- package/types/src/components/description-list/description-list.style.d.ts +2 -0
- package/types/src/components/list/list.d.ts +39 -0
- package/types/src/components/list/list.define.d.ts +1 -0
- package/types/src/components/list/list.style.d.ts +2 -0
- package/types/src/components/list-item/list-item.d.ts +62 -0
- package/types/src/components/list-item/list-item.define.d.ts +1 -0
- package/types/src/components/list-item/list-item.style.d.ts +2 -0
- package/types/src/components/menu/menu.d.ts +266 -0
- package/types/src/components/menu/menu.define.d.ts +1 -0
- package/types/src/components/menu/menu.events.d.ts +6 -0
- package/types/src/components/menu/menu.style.d.ts +2 -0
- package/types/src/components/menu-group/menu-group.d.ts +24 -0
- package/types/src/components/menu-group/menu-group.define.d.ts +1 -0
- package/types/src/components/menu-group/menu-group.style.d.ts +2 -0
- package/types/src/components/menu-item/menu-item.d.ts +59 -0
- package/types/src/components/menu-item/menu-item.define.d.ts +1 -0
- package/types/src/components/menu-item/menu-item.style.d.ts +2 -0
- package/types/src/components/nav/nav.d.ts +103 -0
- package/types/src/components/nav/nav.define.d.ts +1 -0
- package/types/src/components/nav/nav.style.d.ts +2 -0
- package/types/src/components/nav-item/nav-item.d.ts +39 -0
- package/types/src/components/nav-item/nav-item.define.d.ts +1 -0
- package/types/src/components/nav-item/nav-item.style.d.ts +2 -0
- package/types/src/components/pagination/pagination.d.ts +31 -2
- package/types/src/components/scroll-to-top/scroll-to-top.d.ts +6 -5
- package/types/src/components/segmented-field/segmented-field.d.ts +85 -0
- package/types/src/components/segmented-field/segmented-field.define.d.ts +1 -0
- package/types/src/components/segmented-field/segmented-field.style.d.ts +2 -0
- package/types/src/components/splitter/splitter.d.ts +127 -0
- package/types/src/components/splitter/splitter.define.d.ts +1 -0
- package/types/src/components/splitter/splitter.events.d.ts +5 -0
- package/types/src/components/splitter/splitter.style.d.ts +2 -0
- package/types/src/components/status-bar/status-bar.d.ts +44 -0
- package/types/src/components/status-bar/status-bar.define.d.ts +1 -0
- package/types/src/components/status-bar/status-bar.style.d.ts +2 -0
- package/types/src/components/tab-group/tab-group.d.ts +17 -0
- package/types/src/components/toolbar/toolbar.d.ts +96 -0
- package/types/src/components/toolbar/toolbar.define.d.ts +1 -0
- package/types/src/components/toolbar/toolbar.style.d.ts +2 -0
- package/types/src/components/tooltip/tooltip.d.ts +26 -0
- package/types/src/components/tree/tree.d.ts +62 -0
- package/types/src/components/tree/tree.define.d.ts +1 -0
- package/types/src/components/tree/tree.style.d.ts +2 -0
- package/types/src/components/tree-item/tree-item.d.ts +106 -0
- package/types/src/components/tree-item/tree-item.define.d.ts +1 -0
- package/types/src/components/tree-item/tree-item.events.d.ts +4 -0
- package/types/src/components/tree-item/tree-item.style.d.ts +2 -0
- package/types/src/styles/appearance.style.d.ts +31 -0
- package/types/src/styles/choice-group.style.d.ts +1 -1
- package/types/src/styles/modal.style.d.ts +5 -0
- package/types/src/styles/size.style.d.ts +24 -0
- package/types/src/utils/focus.d.ts +25 -0
- package/types/src/utils/scroll.d.ts +11 -0
- package/web-types.json +2530 -393
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { TemplateElement, defineElement, html } from '@webtides/element-js';
|
|
2
|
+
import style from './splitter.style.js';
|
|
3
|
+
import Events from './splitter.events.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The edge between two panes that are beside each other, which the user drags to set the width of
|
|
7
|
+
* one of them: with a mouse, a finger or a pen, and with the arrow keys. To assistive technology
|
|
8
|
+
* it is a separator with a value, the width in pixels, and with the name of what it sizes.
|
|
9
|
+
*
|
|
10
|
+
* The splitter is the control and sizes nothing itself, as a range does: it has a `value` between
|
|
11
|
+
* `min` and `max`, and tells of every change. The layout around it takes the value. An
|
|
12
|
+
* `el-app-frame` renders one at the edge of its navigation and of its aside (`resizable`); a page
|
|
13
|
+
* with two panes of its own writes one between them and sets the width of the pane from the
|
|
14
|
+
* event.
|
|
15
|
+
*
|
|
16
|
+
* @element el-splitter
|
|
17
|
+
*
|
|
18
|
+
* @fires {CustomEvent<{ value: number }>} splitter-resize - Fired with every change the user
|
|
19
|
+
* makes: while the edge is dragged, and with every key. The new width is in `detail.value`.
|
|
20
|
+
* @fires {CustomEvent<{ value: number }>} splitter-resize-end - Fired once the user has set a
|
|
21
|
+
* width: when the pointer lets go of the edge, and with every key. The width to keep is in
|
|
22
|
+
* `detail.value`.
|
|
23
|
+
*
|
|
24
|
+
* @csspart base - The separator: what takes the pointer and the focus. It is wider than the line.
|
|
25
|
+
* @csspart line - The line that shows, and the mark it becomes under the pointer and with the
|
|
26
|
+
* focus.
|
|
27
|
+
*
|
|
28
|
+
* @cssproperty --el-splitter-line-width - The width of the line. Default `--el-border-width`.
|
|
29
|
+
*
|
|
30
|
+
* @cssstate dragging - Set while a pointer drags the edge.
|
|
31
|
+
*
|
|
32
|
+
* @property {number} value - The width of the pane the splitter sizes, in pixels. Default `0`.
|
|
33
|
+
* @property {number} min - The least width. Default `0`.
|
|
34
|
+
* @property {number} max - The greatest width. Default `100`.
|
|
35
|
+
* @property {number} step - How far an arrow key moves the edge, in pixels. Default `16`.
|
|
36
|
+
* @property {string} label - The name of what the splitter sizes, for assistive technology.
|
|
37
|
+
* Default `''`.
|
|
38
|
+
* @property {'start'|'end'} placement - The edge of its pane the splitter is. `end`: the pane is
|
|
39
|
+
* in front of it, and grows when the edge moves away from the start. `start`: the pane is after
|
|
40
|
+
* it. Default `'end'`.
|
|
41
|
+
*/
|
|
42
|
+
export default class Splitter extends TemplateElement {
|
|
43
|
+
/**
|
|
44
|
+
* The drag that is going on: the pointer, where it took the edge, the width then, and the
|
|
45
|
+
* direction in which the width grows.
|
|
46
|
+
* @private
|
|
47
|
+
* @type {{ pointerId: number, x: number, value: number, sign: number } | undefined}
|
|
48
|
+
*/
|
|
49
|
+
_drag = undefined;
|
|
50
|
+
|
|
51
|
+
constructor() {
|
|
52
|
+
super({ styles: [style], shadowRender: true });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
properties() {
|
|
56
|
+
return {
|
|
57
|
+
value: 0,
|
|
58
|
+
min: 0,
|
|
59
|
+
max: 100,
|
|
60
|
+
step: 16,
|
|
61
|
+
label: '',
|
|
62
|
+
placement: 'end',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
events() {
|
|
67
|
+
return {
|
|
68
|
+
"[part~='base']": {
|
|
69
|
+
pointerdown: (event) => this._onPointerDown(event),
|
|
70
|
+
pointermove: (event) => this._onPointerMove(event),
|
|
71
|
+
pointerup: (event) => this._onPointerEnd(event),
|
|
72
|
+
pointercancel: (event) => this._onPointerEnd(event),
|
|
73
|
+
// The capture of a finger starts on what it touched, the line, and moves to the
|
|
74
|
+
// separator: only the separator losing it is the end of a drag.
|
|
75
|
+
lostpointercapture: (event) => {
|
|
76
|
+
if (event.target === event.currentTarget) this._onPointerEnd(event);
|
|
77
|
+
},
|
|
78
|
+
keydown: (event) => this._onKeyDown(event),
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
disconnected() {
|
|
84
|
+
this._drag = undefined;
|
|
85
|
+
this._internals.states.delete('dragging');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A width between the least and the greatest one, in whole pixels.
|
|
90
|
+
* @private
|
|
91
|
+
* @param {number} value
|
|
92
|
+
* @returns {number}
|
|
93
|
+
*/
|
|
94
|
+
_clamp(value) {
|
|
95
|
+
const min = Number(this.min) || 0;
|
|
96
|
+
const max = Math.max(min, Number(this.max) || 0);
|
|
97
|
+
return Math.round(Math.min(max, Math.max(min, Number(value) || 0)));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The direction in which the width grows: 1 where it grows as the edge moves to the right.
|
|
102
|
+
* The pane is in front of the edge or after it, and the page runs from the left or from the
|
|
103
|
+
* right.
|
|
104
|
+
* @private
|
|
105
|
+
* @returns {number}
|
|
106
|
+
*/
|
|
107
|
+
_sign() {
|
|
108
|
+
const rtl = getComputedStyle(this).direction === 'rtl';
|
|
109
|
+
return (rtl ? -1 : 1) * (this.placement === 'start' ? -1 : 1);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Takes a width from the user and tells of it. A width that is the same as before is none.
|
|
114
|
+
* @private
|
|
115
|
+
* @param {number} value
|
|
116
|
+
* @returns {boolean} Whether the width has changed.
|
|
117
|
+
*/
|
|
118
|
+
_resize(value) {
|
|
119
|
+
const next = this._clamp(value);
|
|
120
|
+
if (next === this._clamp(this.value)) return false;
|
|
121
|
+
this.value = next;
|
|
122
|
+
this.dispatch(Events.RESIZE, { value: next });
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The edge follows the pointer that took it, wherever that goes. The separator captures the
|
|
128
|
+
* pointer, so a move outside of the window still arrives here. A page in the page takes a pen
|
|
129
|
+
* that is over it all the same: while the edge is dragged, the separator covers the viewport
|
|
130
|
+
* (see the stylesheet), and the pointer is over nothing else.
|
|
131
|
+
* @private
|
|
132
|
+
* @param {PointerEvent} event
|
|
133
|
+
*/
|
|
134
|
+
_onPointerDown(event) {
|
|
135
|
+
if (event.button !== 0) return;
|
|
136
|
+
// A drag whose end never arrived is over when the next one starts.
|
|
137
|
+
this._endDrag();
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
141
|
+
} catch {
|
|
142
|
+
// A pointer that is gone again cannot be captured. The drag ends with the next one.
|
|
143
|
+
}
|
|
144
|
+
this._drag = {
|
|
145
|
+
pointerId: event.pointerId,
|
|
146
|
+
x: event.clientX,
|
|
147
|
+
value: this._clamp(this.value),
|
|
148
|
+
sign: this._sign(),
|
|
149
|
+
};
|
|
150
|
+
this._internals.states.add('dragging');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @private
|
|
155
|
+
* @param {PointerEvent} event
|
|
156
|
+
*/
|
|
157
|
+
_onPointerMove(event) {
|
|
158
|
+
const drag = this._drag;
|
|
159
|
+
if (!drag || event.pointerId !== drag.pointerId) return;
|
|
160
|
+
|
|
161
|
+
this._resize(drag.value + drag.sign * (event.clientX - drag.x));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The pointer has let go, or the system has taken it away: the width stays as it is now.
|
|
166
|
+
* @private
|
|
167
|
+
* @param {PointerEvent} event
|
|
168
|
+
*/
|
|
169
|
+
_onPointerEnd(event) {
|
|
170
|
+
if (event.pointerId === this._drag?.pointerId) this._endDrag();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Ends the drag that is going on, and tells of the width that stays if it is another one than
|
|
175
|
+
* before the drag.
|
|
176
|
+
* @private
|
|
177
|
+
*/
|
|
178
|
+
_endDrag() {
|
|
179
|
+
const drag = this._drag;
|
|
180
|
+
if (!drag) return;
|
|
181
|
+
|
|
182
|
+
this._drag = undefined;
|
|
183
|
+
this._internals.states.delete('dragging');
|
|
184
|
+
const value = this._clamp(this.value);
|
|
185
|
+
if (value !== drag.value) this.dispatch(Events.RESIZE_END, { value });
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The arrow keys move the edge a step, in the direction of the arrow. `Home` and `End` take
|
|
190
|
+
* it to the least and to the greatest width.
|
|
191
|
+
* @private
|
|
192
|
+
* @param {KeyboardEvent} event
|
|
193
|
+
*/
|
|
194
|
+
_onKeyDown(event) {
|
|
195
|
+
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
196
|
+
|
|
197
|
+
const value = this._clamp(this.value);
|
|
198
|
+
const step = Math.abs(Number(this.step)) || 1;
|
|
199
|
+
const to = {
|
|
200
|
+
ArrowRight: value + this._sign() * step,
|
|
201
|
+
ArrowLeft: value - this._sign() * step,
|
|
202
|
+
Home: Number(this.min) || 0,
|
|
203
|
+
End: Number(this.max) || 0,
|
|
204
|
+
}[event.key];
|
|
205
|
+
if (to === undefined) return;
|
|
206
|
+
|
|
207
|
+
// The key is the one of the splitter: the page does not scroll with it.
|
|
208
|
+
event.preventDefault();
|
|
209
|
+
if (this._resize(to)) this.dispatch(Events.RESIZE_END, { value: this._clamp(this.value) });
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
template() {
|
|
213
|
+
const min = Number(this.min) || 0;
|
|
214
|
+
|
|
215
|
+
return html`
|
|
216
|
+
<div
|
|
217
|
+
part="base"
|
|
218
|
+
class="splitter"
|
|
219
|
+
role="separator"
|
|
220
|
+
tabindex="0"
|
|
221
|
+
aria-orientation="vertical"
|
|
222
|
+
aria-label="${this.label || null}"
|
|
223
|
+
aria-valuenow="${this._clamp(this.value)}"
|
|
224
|
+
aria-valuemin="${min}"
|
|
225
|
+
aria-valuemax="${Math.max(min, Number(this.max) || 0)}"
|
|
226
|
+
>
|
|
227
|
+
<span part="line" class="line"></span>
|
|
228
|
+
</div>
|
|
229
|
+
`;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function define() {
|
|
234
|
+
defineElement('el-splitter', Splitter);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export { Events };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Splitter
|
|
2
|
+
|
|
3
|
+
`splitter` is the edge between two panes that are beside each other, which the user drags to set the width of one of them: more room for long names in a list, or less of it for more of what is chosen from the list. It is dragged with a mouse, a finger or a pen, and moved with the arrow keys.
|
|
4
|
+
|
|
5
|
+
The splitter is the control and sizes nothing itself, as a range does: it has a `value` between `min` and `max`, the width in pixels, and tells of every change. The layout around it takes the value. An [`el-app-frame`](../app-frame/app-frame.readme.md) has one at the edge of its navigation and of its aside (`resizable`); a page with two panes of its own writes one between them.
|
|
6
|
+
|
|
7
|
+
## How to use
|
|
8
|
+
|
|
9
|
+
#### Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm i --save @webtides/element-library
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
#### Use
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import '@webtides/element-library/splitter/define';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```html
|
|
22
|
+
<div class="panes" style="--list: 320px">
|
|
23
|
+
<el-list label="Messages">…</el-list>
|
|
24
|
+
<el-splitter label="Messages" value="320" min="200" max="480"></el-splitter>
|
|
25
|
+
<article>…</article>
|
|
26
|
+
</div>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```css
|
|
30
|
+
.panes {
|
|
31
|
+
display: grid;
|
|
32
|
+
grid-template-columns: var(--list) auto minmax(0, 1fr);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
const panes = document.querySelector('.panes');
|
|
38
|
+
|
|
39
|
+
panes.addEventListener('splitter-resize', (event) => {
|
|
40
|
+
panes.style.setProperty('--list', `${event.detail.value}px`);
|
|
41
|
+
});
|
|
42
|
+
panes.addEventListener('splitter-resize-end', (event) => {
|
|
43
|
+
localStorage.setItem('list', event.detail.value);
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API
|
|
48
|
+
|
|
49
|
+
#### Properties/Attributes
|
|
50
|
+
|
|
51
|
+
| Name | Type | Default | Description |
|
|
52
|
+
| --- | --- | --- | --- |
|
|
53
|
+
| `value` | `number` | `0` | The width of the pane the splitter sizes, in pixels. |
|
|
54
|
+
| `min` | `number` | `0` | The least width. |
|
|
55
|
+
| `max` | `number` | `100` | The greatest width. |
|
|
56
|
+
| `step` | `number` | `16` | How far an arrow key moves the edge, in pixels. |
|
|
57
|
+
| `label` | `string` | `''` | The name of what the splitter sizes, for assistive technology. |
|
|
58
|
+
| `placement` | `'start' \| 'end'` | `'end'` | The edge of its pane the splitter is. `end`: the pane is in front of it. `start`: the pane is after it. |
|
|
59
|
+
|
|
60
|
+
#### Methods
|
|
61
|
+
|
|
62
|
+
_None._
|
|
63
|
+
|
|
64
|
+
#### Events
|
|
65
|
+
|
|
66
|
+
| Name | Detail | Description |
|
|
67
|
+
| --- | --- | --- |
|
|
68
|
+
| `splitter-resize` | `{ value: number }` | Fired with every change the user makes: while the edge is dragged, and with every key. |
|
|
69
|
+
| `splitter-resize-end` | `{ value: number }` | Fired once the user has set a width: when the pointer lets go of the edge, and with every key. The width to keep. |
|
|
70
|
+
|
|
71
|
+
#### Slots
|
|
72
|
+
|
|
73
|
+
_None._
|
|
74
|
+
|
|
75
|
+
#### CSS Parts
|
|
76
|
+
|
|
77
|
+
| Name | Description |
|
|
78
|
+
| ------ | ---------------------------------------------------------------------------------- |
|
|
79
|
+
| `base` | The separator: what takes the pointer and the focus. It is wider than the line. |
|
|
80
|
+
| `line` | The line that shows, and the mark it becomes under the pointer and with the focus. |
|
|
81
|
+
|
|
82
|
+
#### CSS Custom Properties
|
|
83
|
+
|
|
84
|
+
| Name | Default | Description |
|
|
85
|
+
| --- | --- | --- |
|
|
86
|
+
| `--el-splitter-line-width` | `--el-border-width` | The width of the line. `0px` for an edge that lies on a line the layout draws itself. |
|
|
87
|
+
|
|
88
|
+
Reads `--el-color-border` and `--el-border-width` for its line, `--el-color-accent` for the mark, `--el-focus-ring-width` and `--el-color-focus-ring` for the focus ring, `--el-space-2` for the width of what takes the pointer, `--el-duration-md` and `--el-ease` for the way from the line to the mark, and `--el-touch-target` on a touch screen.
|
|
89
|
+
|
|
90
|
+
#### States
|
|
91
|
+
|
|
92
|
+
| Name | Description |
|
|
93
|
+
| ---------- | ----------------------------------- |
|
|
94
|
+
| `dragging` | Set while a pointer drags the edge. |
|
|
95
|
+
|
|
96
|
+
## The value, and who takes it
|
|
97
|
+
|
|
98
|
+
The splitter has the width of one pane as its `value`, in pixels. It does not know the pane and writes nothing onto it.
|
|
99
|
+
|
|
100
|
+
- The page gives the width it starts with, and the least and the greatest one: `value`, `min`, `max`. A value outside of the two is said as the nearer of them.
|
|
101
|
+
- While the user changes the width, `splitter-resize` tells of every one. The page sets it on its layout, a custom property of a grid for example. A page that is slow to do so loses nothing: the edge follows the pointer, not the layout.
|
|
102
|
+
- `splitter-resize-end` tells of the width that stays. That is the moment to keep it, in the storage of the browser or on the server.
|
|
103
|
+
- A width the page sets on the splitter (`value`) tells of nothing.
|
|
104
|
+
|
|
105
|
+
The splitter is as wide as its line and as high as the row it is in: a flex row or a grid row stretches it. It sizes a width. Two panes above each other are not what it is for.
|
|
106
|
+
|
|
107
|
+
## Which pane it sizes
|
|
108
|
+
|
|
109
|
+
`placement` says at which edge of its pane the splitter is. That decides in which direction the width grows.
|
|
110
|
+
|
|
111
|
+
```html
|
|
112
|
+
<!-- The pane is in front of the splitter: a list at the start. -->
|
|
113
|
+
<el-list>…</el-list>
|
|
114
|
+
<el-splitter label="Messages" …></el-splitter>
|
|
115
|
+
<article>…</article>
|
|
116
|
+
|
|
117
|
+
<!-- The pane is after it: details at the end. -->
|
|
118
|
+
<article>…</article>
|
|
119
|
+
<el-splitter placement="start" label="Details" …></el-splitter>
|
|
120
|
+
<aside>…</aside>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
In a right-to-left page start and end are the other way around, and so are the drag and the arrow keys.
|
|
124
|
+
|
|
125
|
+
## Keeping a width
|
|
126
|
+
|
|
127
|
+
A server-rendered page that has kept a width writes it in two places: on its layout, and as the `value` of the splitter. Nothing jumps then: the layout has the width before the script has run, and the splitter says the same one when it starts.
|
|
128
|
+
|
|
129
|
+
```html
|
|
130
|
+
<div class="panes" style="--list: 280px">
|
|
131
|
+
…
|
|
132
|
+
<el-splitter label="Messages" value="280" min="200" max="480"></el-splitter>
|
|
133
|
+
…
|
|
134
|
+
</div>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Pointer
|
|
138
|
+
|
|
139
|
+
- The edge is a thin line. It takes the pointer in a wider area around it, which lies over the panes at both sides: `--el-space-2` wide, and at least `--el-touch-target` on a touch screen.
|
|
140
|
+
- While the edge is dragged, no text is selected and a finger does not scroll the page.
|
|
141
|
+
- The edge keeps following the pointer wherever it goes. It captures the pointer, and it covers the viewport while it is dragged: a page in the page (an `iframe`) under the pointer would take a pen away from it.
|
|
142
|
+
- Only the main button of a mouse takes the edge.
|
|
143
|
+
|
|
144
|
+
## Keyboard
|
|
145
|
+
|
|
146
|
+
| Key | What it does |
|
|
147
|
+
| -------------------------- | -------------------------------------------------------------- |
|
|
148
|
+
| `Tab` | The edge is a stop of the Tab key. |
|
|
149
|
+
| `ArrowLeft` / `ArrowRight` | Move the edge by `step` pixels, in the direction of the arrow. |
|
|
150
|
+
| `Home` | The least width. |
|
|
151
|
+
| `End` | The greatest width. |
|
|
152
|
+
|
|
153
|
+
Every key is a width that stays: it fires `splitter-resize` and `splitter-resize-end`.
|
|
154
|
+
|
|
155
|
+
## Server-side rendering
|
|
156
|
+
|
|
157
|
+
The splitter renders on a server with `@webtides/element-js-ssr-renderer`: the separator with its name and its value is in the markup, and the line looks the same before and after the element takes over. It moves once the script has run.
|
|
158
|
+
|
|
159
|
+
## Accessibility
|
|
160
|
+
|
|
161
|
+
- A separator that takes the focus (`role="separator"` with `tabindex="0"`), with `aria-orientation="vertical"`, the width as `aria-valuenow` and the limits as `aria-valuemin` and `aria-valuemax`.
|
|
162
|
+
- `label` is its name: what it sizes ("Messages"), not what it is.
|
|
163
|
+
- The keyboard focus shows as a ring around what takes the pointer, and the line is the mark it is under the pointer.
|
|
164
|
+
- The line is a border: it stays where the user forces colours, and it is there without a theme then. Without a theme and without forced colours the line has no width, and shows as a mark under the pointer and with the focus.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import hostStyle from '../../styles/host.style.js';
|
|
2
|
+
|
|
3
|
+
const css = String.raw;
|
|
4
|
+
|
|
5
|
+
const style = css`
|
|
6
|
+
/*
|
|
7
|
+
* The element is as wide as its line and as high as the row it is in. What takes the pointer
|
|
8
|
+
* is wider and lies over the panes at both sides.
|
|
9
|
+
*/
|
|
10
|
+
:host {
|
|
11
|
+
display: block;
|
|
12
|
+
position: relative;
|
|
13
|
+
z-index: 1;
|
|
14
|
+
flex: none;
|
|
15
|
+
align-self: stretch;
|
|
16
|
+
/* Where the user forces colours, the line is there without a theme as well. */
|
|
17
|
+
--_el-splitter-line-width: var(--el-splitter-line-width, var(--el-border-width, 0px));
|
|
18
|
+
/* The width of what takes the pointer. */
|
|
19
|
+
--_el-splitter-target: var(--el-space-2, 0.5rem);
|
|
20
|
+
|
|
21
|
+
inline-size: var(--_el-splitter-line-width);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@media (forced-colors: active) {
|
|
25
|
+
:host {
|
|
26
|
+
--_el-splitter-line-width: max(var(--el-splitter-line-width, var(--el-border-width, 0px)), 1px);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* On a touch screen the edge takes a finger: at least the touch target. Without the token it
|
|
31
|
+
stays as it is. */
|
|
32
|
+
@media (any-pointer: coarse) {
|
|
33
|
+
:host {
|
|
34
|
+
--_el-splitter-target: max(var(--el-space-2, 0.5rem), var(--el-touch-target, 0px));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* The separator, with the line in its middle. A drag that starts here selects no text, and a
|
|
40
|
+
* finger that moves it does not scroll the page.
|
|
41
|
+
*/
|
|
42
|
+
.splitter {
|
|
43
|
+
position: absolute;
|
|
44
|
+
inset-block: 0;
|
|
45
|
+
inset-inline-start: calc((var(--_el-splitter-line-width) - var(--_el-splitter-target)) / 2);
|
|
46
|
+
display: flex;
|
|
47
|
+
justify-content: center;
|
|
48
|
+
inline-size: var(--_el-splitter-target);
|
|
49
|
+
cursor: col-resize;
|
|
50
|
+
touch-action: none;
|
|
51
|
+
user-select: none;
|
|
52
|
+
-webkit-user-select: none;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* While the edge is dragged, the separator covers the viewport. The pointer is over nothing
|
|
57
|
+
* else then: not over a page in the page (an iframe), which would take a pen away from the
|
|
58
|
+
* edge, and not over a control with a cursor of its own.
|
|
59
|
+
*/
|
|
60
|
+
:host(:state(dragging)) .splitter::after {
|
|
61
|
+
content: '';
|
|
62
|
+
position: fixed;
|
|
63
|
+
inset: 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* The line is a border: it stays where the user forces colours. */
|
|
67
|
+
.line {
|
|
68
|
+
border-inline-start: var(--_el-splitter-line-width) solid var(--el-color-border, transparent);
|
|
69
|
+
transition:
|
|
70
|
+
border-color var(--el-duration-md, 0s) var(--el-ease, linear),
|
|
71
|
+
border-width var(--el-duration-md, 0s) var(--el-ease, linear);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* Under the pointer, while it is dragged and with the focus of the keyboard the line is a mark:
|
|
75
|
+
wider, and in the accent colour. Without a theme it has the colour of the text. */
|
|
76
|
+
@media (hover: hover) {
|
|
77
|
+
.splitter:hover .line {
|
|
78
|
+
border-inline-start-width: max(var(--_el-splitter-line-width), 0.1875rem);
|
|
79
|
+
border-inline-start-color: var(--el-color-accent, currentColor);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
:host(:state(dragging)) .line,
|
|
84
|
+
.splitter:focus-visible .line {
|
|
85
|
+
border-inline-start-width: max(var(--_el-splitter-line-width), 0.1875rem);
|
|
86
|
+
border-inline-start-color: var(--el-color-accent, currentColor);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* The ring is around what takes the pointer: a narrow bar as high as the edge. */
|
|
90
|
+
.splitter:focus-visible {
|
|
91
|
+
outline: var(--el-focus-ring-width, 2px) solid var(--el-color-focus-ring, currentColor);
|
|
92
|
+
outline-offset: calc(-1 * var(--el-focus-ring-width, 2px));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.splitter:focus:not(:focus-visible) {
|
|
96
|
+
outline: none;
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
export default [hostStyle(), style].join('\n');
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this component live here. Versions refer to the parent `@webtides/element-library` release (see root [`CHANGELOG.md`](../../../CHANGELOG.md)); components no longer version independently.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|
6
|
+
|
|
7
|
+
<!--
|
|
8
|
+
When your PR touches this component, add an entry under Unreleased and
|
|
9
|
+
mirror it (prefixed with the component name) in root CHANGELOG.md.
|
|
10
|
+
Uncomment headings as needed.
|
|
11
|
+
-->
|
|
12
|
+
|
|
13
|
+
## Unreleased
|
|
14
|
+
|
|
15
|
+
## [0.4.0] - 2026-11-27
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- Initial `el-status-bar`: a narrow line of state at the lower edge of a tool for a desktop, with entries at its start and at its end (slot `end`), which follow the reading direction. An entry is what the page writes: a text, an icon with a name, an `el-button`, an `el-spinner` or an `el-progress-bar`. ([#180](https://github.com/webtides/element-library/issues/180))
|
|
20
|
+
- The bar is lower than a control, seven tenths of `--el-control-height`, with the small text of the tokens (`--el-font-size-sm`), and keeps that height whatever is in it. On a touch screen it is at least `--el-touch-target` high.
|
|
21
|
+
- An `el-button` in the bar is as high as the bar, plain, has its small text, and shows its focus ring inside of itself. The bar does not write to its buttons: it says all of it in CSS properties that are inherited.
|
|
22
|
+
- Entries that do not fit do not wrap and do not lie on each other. The entries at the start give way: their group is cut at its end, and the entries at the end stay. A button in the part that is cut shows while it has the keyboard focus.
|
|
23
|
+
- The bar is no live region and has no role. The page marks an entry whose change is announced (`role="status"`).
|
|
24
|
+
- In the footer of an `el-app-frame` the surface of the bar reaches as far as the surface of the region: to the lower edge of the screen and to its sides, while its entries stay clear of them. The line to the content is the one of the region there.
|
|
25
|
+
- A surface from `--el-color-bg`, text in `--el-color-fg-muted`, and a line to the content from `--el-color-border` and `--el-border-width`. The line is a border, which stays where the user forces colours and is there without a theme then.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { TemplateElement, defineElement, html } from '@webtides/element-js';
|
|
2
|
+
import { hasSlotted } from '../../utils/slots.js';
|
|
3
|
+
import style from './status-bar.style.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A narrow line of state at the lower edge of a tool for a desktop: whether the connection is
|
|
7
|
+
* there, what is selected, how many entries there are, a task that runs in the background, the
|
|
8
|
+
* version. Entries at its start and at its end, in one row that keeps its height.
|
|
9
|
+
*
|
|
10
|
+
* An entry is what the page writes: a text, an icon with a name, an `el-button`, or a small
|
|
11
|
+
* component (`el-spinner`, `el-progress-bar`). The bar is no live region. An entry whose change
|
|
12
|
+
* is to be announced is one the page marks itself (`role="status"`).
|
|
13
|
+
*
|
|
14
|
+
* In the footer of an `el-app-frame` the surface of the bar reaches as far as the surface of the
|
|
15
|
+
* region. The look is the stylesheet alone, so a server-rendered bar does not change when the
|
|
16
|
+
* element takes over.
|
|
17
|
+
*
|
|
18
|
+
* @element el-status-bar
|
|
19
|
+
*
|
|
20
|
+
* @slot - The entries at the start of the bar. They give way first where the bar is too narrow.
|
|
21
|
+
* @slot end - The entries at the end of the bar.
|
|
22
|
+
*
|
|
23
|
+
* @csspart base - The bar: its surface and the line to the content.
|
|
24
|
+
* @csspart row - The row of the entries, which keeps its height.
|
|
25
|
+
* @csspart start - The entries at the start.
|
|
26
|
+
* @csspart end - The entries at the end.
|
|
27
|
+
*/
|
|
28
|
+
export default class StatusBar extends TemplateElement {
|
|
29
|
+
constructor() {
|
|
30
|
+
super({ styles: [style], shadowRender: true });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
events() {
|
|
34
|
+
return {
|
|
35
|
+
// A template element does not render again when a child comes, goes or changes its
|
|
36
|
+
// `slot` attribute. The slot tells of all three, and the event bubbles to the base.
|
|
37
|
+
"[part~='base']": {
|
|
38
|
+
slotchange: () => this.requestUpdate(),
|
|
39
|
+
},
|
|
40
|
+
this: {
|
|
41
|
+
focusout: () => this._showStart(),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Entries that do not fit are cut off, and the browser moves a group to show a button in the
|
|
48
|
+
* part that is cut when the keyboard gets to it. With the focus gone, the group shows its
|
|
49
|
+
* first entries again.
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
_showStart() {
|
|
53
|
+
for (const group of this.shadowRoot?.querySelectorAll('.start, .end') ?? []) {
|
|
54
|
+
group.scrollLeft = 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
template() {
|
|
59
|
+
return html`
|
|
60
|
+
<div part="base" class="bar">
|
|
61
|
+
<div part="row" class="row">
|
|
62
|
+
<div part="start" class="start"><slot></slot></div>
|
|
63
|
+
<div part="end" class="end" ?hidden="${!hasSlotted(this, 'end')}">
|
|
64
|
+
<slot name="end"></slot>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function define() {
|
|
73
|
+
defineElement('el-status-bar', StatusBar);
|
|
74
|
+
}
|