@webtides/element-library 0.3.0 → 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 +208 -0
- package/README.md +72 -56
- package/all.js +16 -0
- package/catalog.js +17 -1
- package/custom-elements.json +14731 -10193
- 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 +25 -0
- package/src/components/button/button.events.js +3 -0
- package/src/components/button/button.js +209 -14
- package/src/components/button/button.readme.md +82 -6
- package/src/components/button/button.style.js +161 -7
- package/src/components/checkbox-field/checkbox-field.changelog.md +6 -0
- package/src/components/checkbox-field/checkbox-field.js +7 -1
- 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/switch-field/switch-field.changelog.md +6 -0
- package/src/components/switch-field/switch-field.js +7 -1
- 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 +97 -7
- 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,94 @@
|
|
|
1
|
+
# Menu Item
|
|
2
|
+
|
|
3
|
+
`menu-item` is one entry of an [`el-menu`](../menu/menu.readme.md): an action, or a link with an address.
|
|
4
|
+
|
|
5
|
+
## How to use
|
|
6
|
+
|
|
7
|
+
#### Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i --save @webtides/element-library
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
#### Use
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import '@webtides/element-library/menu/define';
|
|
17
|
+
import '@webtides/element-library/menu-item/define';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```html
|
|
21
|
+
<el-menu>
|
|
22
|
+
<el-button slot="trigger">More</el-button>
|
|
23
|
+
<el-menu-item value="edit"><svg slot="icon" aria-hidden="true">…</svg>Edit</el-menu-item>
|
|
24
|
+
<el-menu-item href="/invoices/12/print">Print</el-menu-item>
|
|
25
|
+
<el-menu-item value="move" disabled="true">Move</el-menu-item>
|
|
26
|
+
<el-menu-item value="delete" variant="danger">Delete</el-menu-item>
|
|
27
|
+
</el-menu>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
> Boolean attributes are passed as strings (`disabled="true"`), matching the rest of the library.
|
|
31
|
+
|
|
32
|
+
## API
|
|
33
|
+
|
|
34
|
+
#### Properties/Attributes
|
|
35
|
+
|
|
36
|
+
| Name | Type | Default | Description |
|
|
37
|
+
| --- | --- | --- | --- |
|
|
38
|
+
| `href` | `string` | `''` | The address the entry leads to. With one it is a link. |
|
|
39
|
+
| `target` | `string` | `''` | Where to open the address. |
|
|
40
|
+
| `rel` | `string` | `'noreferrer noopener'` | `rel` attribute for the link, written when `target` is set. |
|
|
41
|
+
| `value` | `string` | `''` | What the entry stands for, for the listener of `menu-select`. |
|
|
42
|
+
| `disabled` | `boolean` | `false` | Whether the entry cannot be chosen. The keyboard still gets to it. |
|
|
43
|
+
| `variant` | `string` | `'neutral'` | `neutral`, `brand`, `success`, `warning` or `danger`: `danger` for something that cannot be undone. Reflected. |
|
|
44
|
+
|
|
45
|
+
#### Methods
|
|
46
|
+
|
|
47
|
+
| Name | Description |
|
|
48
|
+
| --------- | --------------------------------------------------------- |
|
|
49
|
+
| `focus()` | Puts the focus on the entry: on the control inside of it. |
|
|
50
|
+
|
|
51
|
+
#### Events
|
|
52
|
+
|
|
53
|
+
_None of its own._ A choice is a `click` on the entry, and `menu-select` on its menu.
|
|
54
|
+
|
|
55
|
+
#### Slots
|
|
56
|
+
|
|
57
|
+
| Name | Description |
|
|
58
|
+
| --------- | ----------------------------------------------------------------- |
|
|
59
|
+
| (default) | The text of the entry. |
|
|
60
|
+
| `icon` | An icon in front of the text: a decoration, the text is the name. |
|
|
61
|
+
|
|
62
|
+
#### CSS Parts
|
|
63
|
+
|
|
64
|
+
| Name | Description |
|
|
65
|
+
| ------- | ------------------------------------------------- |
|
|
66
|
+
| `base` | The entry: a `<button>`, or an `<a>` with `href`. |
|
|
67
|
+
| `icon` | The place of the icon. |
|
|
68
|
+
| `label` | The text of the entry. |
|
|
69
|
+
|
|
70
|
+
#### CSS Custom Properties
|
|
71
|
+
|
|
72
|
+
Reads `--el-control-height` for its height (an entry is a little lower than a control), `--el-space-1`, `--el-space-2` and `--el-space-3` for its padding and the gap to its icon, `--el-radius-md`, `--el-focus-ring-width` and `--el-color-focus-ring` for the focus, `--el-touch-target` on a touch screen, and the colour of its variant: `--el-color-fg`, or `--el-color-danger` for `variant="danger"`.
|
|
73
|
+
|
|
74
|
+
## An action or a link
|
|
75
|
+
|
|
76
|
+
Without `href` the entry is a button, and choosing it is a click the page acts on. With `href` it is a link, which the browser follows. Both have the role of a menu item, and both close the menu.
|
|
77
|
+
|
|
78
|
+
## Disabled
|
|
79
|
+
|
|
80
|
+
`disabled="true"` takes the entry out of what can be chosen. It says so to assistive technology (`aria-disabled="true"`), fires no click, and a link has no address while it is disabled. The arrow keys still stop at it: a screen reader user learns that the action is there and not available now.
|
|
81
|
+
|
|
82
|
+
## A danger
|
|
83
|
+
|
|
84
|
+
`variant="danger"` shows the entry in the colour of a danger, for an action that cannot be undone. The colour alone does not say so to everyone: name the action for what it does ("Delete"), and ask before it is done where it matters.
|
|
85
|
+
|
|
86
|
+
## The icon
|
|
87
|
+
|
|
88
|
+
What is in the `icon` slot stands in front of the text. It is a decoration: give it `aria-hidden="true"`, the text is the name of the entry. Without an icon the text starts where the entry starts.
|
|
89
|
+
|
|
90
|
+
## Accessibility
|
|
91
|
+
|
|
92
|
+
- A menu item (`role="menuitem"`), which is no stop of the Tab key: its menu moves the focus to it.
|
|
93
|
+
- The focus of the keyboard shows as a ring inside of the entry and a tint, the pointer as a tint.
|
|
94
|
+
- On a touch screen the entry is at least `--el-touch-target` high. Without the token nothing changes.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import hostStyle from '../../styles/host.style.js';
|
|
2
|
+
import variantsStyle from '../../styles/variants.style.js';
|
|
3
|
+
|
|
4
|
+
const css = String.raw;
|
|
5
|
+
|
|
6
|
+
const style = css`
|
|
7
|
+
:host {
|
|
8
|
+
display: block;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* The whole entry is the control: an icon, and the text beside it. A little lower than a
|
|
12
|
+
control of a form, so a menu of a few entries is no tower. */
|
|
13
|
+
.item {
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
gap: var(--el-space-2, 0.5rem);
|
|
17
|
+
box-sizing: border-box;
|
|
18
|
+
inline-size: 100%;
|
|
19
|
+
min-block-size: calc(var(--el-control-height, 2.5rem) * 0.85);
|
|
20
|
+
margin: 0;
|
|
21
|
+
padding: var(--el-space-1, 0.25rem) var(--el-space-3, 0.75rem);
|
|
22
|
+
border: 0;
|
|
23
|
+
border-radius: var(--el-radius-md, 0);
|
|
24
|
+
background: transparent;
|
|
25
|
+
/* The colour of the variant: the text colour of the menu, or the colour of a danger. */
|
|
26
|
+
color: var(--_el-variant-text);
|
|
27
|
+
font: inherit;
|
|
28
|
+
text-align: start;
|
|
29
|
+
text-decoration: none;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
user-select: none;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.icon {
|
|
35
|
+
display: inline-flex;
|
|
36
|
+
flex: none;
|
|
37
|
+
align-items: center;
|
|
38
|
+
justify-content: center;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* One line as a rule. A text that is longer than the menu is wide wraps: an action that is
|
|
42
|
+
cut off cannot be read. */
|
|
43
|
+
.label {
|
|
44
|
+
flex: 1 1 auto;
|
|
45
|
+
min-inline-size: 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* Under the pointer, and with the focus of the keyboard: a tint of the text colour, which
|
|
49
|
+
shows on every background. Hover only where a pointer can hover: a touch screen leaves the
|
|
50
|
+
state on what was tapped last. */
|
|
51
|
+
@media (hover: hover) {
|
|
52
|
+
.item:hover {
|
|
53
|
+
background: color-mix(in srgb, currentColor 10%, transparent);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.item:focus-visible {
|
|
58
|
+
background: color-mix(in srgb, currentColor 10%, transparent);
|
|
59
|
+
/* The ring is inside of the entry: the edge of the menu is around it. It is what shows
|
|
60
|
+
where the user forces colours. */
|
|
61
|
+
outline: var(--el-focus-ring-width, 2px) solid var(--el-color-focus-ring, currentColor);
|
|
62
|
+
outline-offset: calc(-1 * var(--el-focus-ring-width, 2px));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.item:active {
|
|
66
|
+
background: color-mix(in srgb, currentColor 18%, transparent);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* An entry that cannot be chosen. The keyboard still gets to it, so it has its ring. */
|
|
70
|
+
.item--disabled,
|
|
71
|
+
.item--disabled:hover,
|
|
72
|
+
.item--disabled:active {
|
|
73
|
+
background: transparent;
|
|
74
|
+
opacity: 0.55;
|
|
75
|
+
cursor: not-allowed;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* On a touch screen an entry is at least as high as a finger needs. Without the token the
|
|
79
|
+
sizes stay as they are. */
|
|
80
|
+
@media (any-pointer: coarse) {
|
|
81
|
+
.item {
|
|
82
|
+
min-block-size: max(calc(var(--el-control-height, 2.5rem) * 0.85), var(--el-touch-target, 0px));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
export default [hostStyle(), variantsStyle(), style].join('\n');
|
|
@@ -0,0 +1,35 @@
|
|
|
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-nav`: the destinations of an application as a bar for the lower edge of a phone. A navigation landmark (`<nav>`, named by `label`) with a list of `el-nav-item` links. ([#179](https://github.com/webtides/element-library/issues/179))
|
|
20
|
+
- Three to five destinations share the width in equal parts, however long their texts are. The bar is as high as an `el-app-bar`, and keeps that height: a text that does not fit is cut.
|
|
21
|
+
- In the footer of an `el-app-frame` the surface of the bar reaches the lower edge of the screen and its sides, and the destinations stay above the home indicator of a phone. The line to the content is the one of the region there. Alone, the bar keeps its destinations clear of the home indicator and of the sides itself (`env(safe-area-inset-*)`).
|
|
22
|
+
- A surface from `--el-color-bg` 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.
|
|
23
|
+
- `layout="rail"`: the destinations below each other in a narrow column for the side of a wider screen, `--el-nav-rail-size` wide (`5rem`), with a line to the content at the side that faces it. The rail is as high as its place, and scrolls where it has more destinations than height. ([#181](https://github.com/webtides/element-library/issues/181))
|
|
24
|
+
- The `end` slot: a second group at the lower end of a rail, for the settings and the account. It is a list of its own, stays in view while the group at the top scrolls, and is not shown in a bar.
|
|
25
|
+
- `labels="false"`: the destinations show an icon alone. Their texts are off the screen and stay the names of their links, and show as tooltips for the pointer and for the focus of the keyboard, beside a rail and above a bar. The tooltips are `el-tooltip` elements in the shadow root (`::part(tooltip)`); the element imports the tooltip, and with it `@floating-ui/dom`.
|
|
26
|
+
- `layout="auto"`, the new default: a bar, and a rail where an `el-app-frame` has the element in the column at its side. The frame says so in a CSS property that is inherited, so the page writes the destinations once and the stylesheets decide, before any script has run. Alone, and in the footer of a frame, `auto` is the bar that was the default.
|
|
27
|
+
- Alone, a rail keeps its destinations clear of the top, its side and the lower edge of the screen (`env(safe-area-inset-*)`).
|
|
28
|
+
- `layout="list"`: the destinations below each other, each a row with its icon and its text beside it, for a sidebar. A list is as wide as its place and as high as it, scrolls where it has more destinations than height, and keeps the `end` slot at its lower end in view. Where its place is as wide as what is in it, it is `--el-nav-list-size` wide (`16rem`). ([#199](https://github.com/webtides/element-library/issues/199))
|
|
29
|
+
- `column`: what `layout="auto"` is in the column at the side of an `el-app-frame`, `rail` (the default) or `list`. The class of the landmark says it and the stylesheet decides, so a server-rendered page has a list on one view and a rail on another before any script has run.
|
|
30
|
+
- The `secondary` slot: a second group of destinations below the first, for the pages that have no room in a bar, with `secondary-label` as its heading. A list shows the heading, a rail shows the group below a line, and a bar leaves the group out. The group is a list of its own with the heading as its name (`::part(secondary)`, `::part(secondary-label)`, `::part(secondary-list)`).
|
|
31
|
+
- In an element of the page that is in the `navigation` slot of a frame, the element takes its layout from the frame as one that is in the slot itself. In a flex column of that element it takes the height that is left: its destinations scroll, and what the page puts above and below it stays in view.
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- The groups at the top of a rail scroll together in a new part, `groups`. `::part(list)` is the first group as before and no longer the element that scrolls. ([#199](https://github.com/webtides/element-library/issues/199))
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { TemplateElement, defineElement, html } from '@webtides/element-js';
|
|
2
|
+
import { define as defineTooltip } from '../tooltip/tooltip.js';
|
|
3
|
+
import { hasSlotted } from '../../utils/slots.js';
|
|
4
|
+
import style from './nav.style.js';
|
|
5
|
+
|
|
6
|
+
const LAYOUTS = ['auto', 'bar', 'rail', 'list'];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The destinations of an application: the places the user goes to all the time. Each destination
|
|
10
|
+
* is an `el-nav-item`: a link with an icon and a short text, and the one of the current view is
|
|
11
|
+
* marked. The element is a navigation landmark, named by `label`.
|
|
12
|
+
*
|
|
13
|
+
* Three layouts. A **bar** for the lower edge of a phone, in which three to five destinations share
|
|
14
|
+
* the width in equal parts. A **rail** for the side of a wider screen: a narrow column of icons
|
|
15
|
+
* with a word under each. A **list** for a sidebar: an icon and its text in one row, as wide as
|
|
16
|
+
* its place. A rail and a list have a group at their top and one at their lower end, and scroll
|
|
17
|
+
* where they have more destinations than height.
|
|
18
|
+
*
|
|
19
|
+
* `layout="auto"`, the default, is a bar, and where an `el-app-frame` has the element in the
|
|
20
|
+
* column at its side it is what `column` names, a rail or a list: the page writes the
|
|
21
|
+
* destinations once.
|
|
22
|
+
*
|
|
23
|
+
* A second group takes the destinations that have no room among the five of a bar (the
|
|
24
|
+
* `secondary` slot, with `secondary-label` as its heading). A bar leaves it out.
|
|
25
|
+
*
|
|
26
|
+
* In a region of an `el-app-frame` the surface reaches the edge of the screen, and the
|
|
27
|
+
* destinations stay clear of the home indicator and the notch. Alone it keeps them clear itself.
|
|
28
|
+
*
|
|
29
|
+
* The look is the stylesheet alone, so server-rendered destinations do not change when the
|
|
30
|
+
* element takes over. The script adds the tooltips of destinations that show an icon alone.
|
|
31
|
+
*
|
|
32
|
+
* @element el-nav
|
|
33
|
+
*
|
|
34
|
+
* @slot - The destinations: `el-nav-item` elements.
|
|
35
|
+
* @slot secondary - A second group of destinations, below the first: the pages that have no room
|
|
36
|
+
* in a bar, which leaves them out.
|
|
37
|
+
* @slot end - The destinations at the lower end of a rail or a list: the settings, the account. A
|
|
38
|
+
* bar has no room for them, and leaves them out.
|
|
39
|
+
*
|
|
40
|
+
* @csspart base - The navigation landmark (`<nav>`): the surface and its line to the content.
|
|
41
|
+
* @csspart groups - The two groups at the top, which scroll where a rail or a list has more
|
|
42
|
+
* destinations than height.
|
|
43
|
+
* @csspart list - The list of the destinations.
|
|
44
|
+
* @csspart secondary - The second group: its heading and its list.
|
|
45
|
+
* @csspart secondary-label - The heading of the second group, which a list shows.
|
|
46
|
+
* @csspart secondary-list - The list of the destinations of the second group.
|
|
47
|
+
* @csspart end - The list of the destinations at the lower end of a rail or a list.
|
|
48
|
+
* @csspart tooltip - The tooltip of a destination that shows an icon alone: an `el-tooltip`.
|
|
49
|
+
*
|
|
50
|
+
* @cssproperty --el-nav-rail-size - The width of a rail. Default `5rem`.
|
|
51
|
+
* @cssproperty --el-nav-list-size - The width of a list where its place is as wide as what is in
|
|
52
|
+
* it. Default `16rem`.
|
|
53
|
+
*
|
|
54
|
+
* @property {string} label - The name of the navigation for assistive technology, "Main". A page
|
|
55
|
+
* with more than one navigation needs it to tell them apart.
|
|
56
|
+
* @property {'auto'|'bar'|'rail'|'list'} layout - How the destinations lie: `bar`, a row in which
|
|
57
|
+
* they share the width in equal parts; `rail`, a narrow column; `list`, rows of an icon and its
|
|
58
|
+
* text; `auto`, a bar, and in the column at the side of an `el-app-frame` what `column` names.
|
|
59
|
+
* Default `'auto'`.
|
|
60
|
+
* @property {'rail'|'list'} column - What the destinations are in the column at the side of an
|
|
61
|
+
* `el-app-frame`, with `layout="auto"`. Default `'rail'`.
|
|
62
|
+
* @property {string} secondaryLabel - The heading of the second group, and its name for assistive
|
|
63
|
+
* technology: "More". Default `''`.
|
|
64
|
+
* @property {boolean} labels - Whether the destinations show their texts. With `false` they show
|
|
65
|
+
* an icon alone: the text stays the name of the link, and shows as a tooltip. Default `true`.
|
|
66
|
+
*/
|
|
67
|
+
export default class Nav extends TemplateElement {
|
|
68
|
+
/**
|
|
69
|
+
* Whether the element has started in a browser, see `connected()`.
|
|
70
|
+
* @private
|
|
71
|
+
*/
|
|
72
|
+
_started = false;
|
|
73
|
+
|
|
74
|
+
constructor() {
|
|
75
|
+
super({
|
|
76
|
+
styles: [style],
|
|
77
|
+
shadowRender: true,
|
|
78
|
+
// The tooltips have the texts of the destinations: a destination that comes or goes,
|
|
79
|
+
// and a text that changes, ask for a new render. The filter names the attributes of
|
|
80
|
+
// the element itself as well: element-js hears of them through the same observer.
|
|
81
|
+
mutationObserverOptions: {
|
|
82
|
+
childList: true,
|
|
83
|
+
subtree: true,
|
|
84
|
+
characterData: true,
|
|
85
|
+
attributeFilter: ['label', 'layout', 'column', 'secondary-label', 'labels'],
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
properties() {
|
|
91
|
+
return {
|
|
92
|
+
label: '',
|
|
93
|
+
layout: 'auto',
|
|
94
|
+
column: 'rail',
|
|
95
|
+
secondaryLabel: '',
|
|
96
|
+
labels: true,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
connected() {
|
|
101
|
+
// The tooltips come with the script: a server renders none, and the first render in the
|
|
102
|
+
// browser is the markup of the server.
|
|
103
|
+
this._started = true;
|
|
104
|
+
if (!this._showsLabels()) this.requestUpdate();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
events() {
|
|
108
|
+
return {
|
|
109
|
+
// A template element does not render again when a child comes, goes or changes its
|
|
110
|
+
// `slot` attribute. The slot tells of all three, and the event bubbles to the base.
|
|
111
|
+
"[part~='base']": {
|
|
112
|
+
slotchange: () => this.requestUpdate(),
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @private
|
|
119
|
+
* @returns {boolean}
|
|
120
|
+
*/
|
|
121
|
+
_showsLabels() {
|
|
122
|
+
return this.labels !== false && this.labels !== 'false';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The destinations with their texts: what is in a destination and in none of its named slots.
|
|
127
|
+
* None before the element has started, and none while the texts show: a tooltip is for an
|
|
128
|
+
* icon alone, and on a server there is no pointer to show one to.
|
|
129
|
+
* @private
|
|
130
|
+
* @returns {Array<[Element, string]>}
|
|
131
|
+
*/
|
|
132
|
+
_named() {
|
|
133
|
+
if (!this._started || this._showsLabels()) return [];
|
|
134
|
+
return [...this.querySelectorAll('el-nav-item')]
|
|
135
|
+
.map((item) => [
|
|
136
|
+
item,
|
|
137
|
+
[...item.childNodes]
|
|
138
|
+
.filter((node) => node.nodeType === Node.TEXT_NODE || !node.getAttribute?.('slot'))
|
|
139
|
+
.map((node) => node.textContent)
|
|
140
|
+
.join(' ')
|
|
141
|
+
.replace(/\s+/g, ' ')
|
|
142
|
+
.trim(),
|
|
143
|
+
])
|
|
144
|
+
.filter(([, text]) => text);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Where the tooltip of a destination goes: beside a rail, on the side of the content, and
|
|
149
|
+
* above a bar. The stylesheet decides what the destinations are; this reads what it decided.
|
|
150
|
+
* @private
|
|
151
|
+
* @returns {string}
|
|
152
|
+
*/
|
|
153
|
+
_tooltipPlacement() {
|
|
154
|
+
const base = this.shadowRoot.querySelector("[part~='base']");
|
|
155
|
+
if (!base) return 'top';
|
|
156
|
+
const style = getComputedStyle(base);
|
|
157
|
+
if (style.getPropertyValue('--_el-nav-direction').trim() !== 'column') return 'top';
|
|
158
|
+
return style.direction === 'rtl' ? 'left' : 'right';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
template() {
|
|
162
|
+
const layout = LAYOUTS.includes(this.layout) ? this.layout : 'auto';
|
|
163
|
+
const named = this._named();
|
|
164
|
+
const placement = named.length ? this._tooltipPlacement() : 'top';
|
|
165
|
+
|
|
166
|
+
// The layout is a class of the landmark, not an attribute of the element: a server writes
|
|
167
|
+
// it, and the default has to be on no element for the stylesheet. So is what the column
|
|
168
|
+
// of a frame makes of the destinations.
|
|
169
|
+
// A plain binding leaves a name out while there is none.
|
|
170
|
+
return html`
|
|
171
|
+
<nav
|
|
172
|
+
part="base"
|
|
173
|
+
class="nav nav--${layout} ${this.column === 'list' ? 'nav--column-list' : ''} ${
|
|
174
|
+
this._showsLabels() ? '' : 'nav--icons'
|
|
175
|
+
}"
|
|
176
|
+
aria-label="${this.label || null}"
|
|
177
|
+
>
|
|
178
|
+
<div part="groups" class="groups">
|
|
179
|
+
<div part="list" class="list" role="list"><slot></slot></div>
|
|
180
|
+
<div part="secondary" class="secondary" ?hidden="${!hasSlotted(this, 'secondary')}">
|
|
181
|
+
<div
|
|
182
|
+
part="secondary-label"
|
|
183
|
+
class="heading"
|
|
184
|
+
aria-hidden="true"
|
|
185
|
+
?hidden="${!this.secondaryLabel}"
|
|
186
|
+
>
|
|
187
|
+
${this.secondaryLabel}
|
|
188
|
+
</div>
|
|
189
|
+
<div part="secondary-list" class="list" role="list" aria-label="${this.secondaryLabel || null}">
|
|
190
|
+
<slot name="secondary"></slot>
|
|
191
|
+
</div>
|
|
192
|
+
</div>
|
|
193
|
+
</div>
|
|
194
|
+
<div part="end" class="end" role="list" ?hidden="${!hasSlotted(this, 'end')}">
|
|
195
|
+
<slot name="end"></slot>
|
|
196
|
+
</div>
|
|
197
|
+
</nav>
|
|
198
|
+
${named.map(
|
|
199
|
+
([item, text]) =>
|
|
200
|
+
html`<el-tooltip part="tooltip" type="label" placement="${placement}" .anchor="${item}"
|
|
201
|
+
>${text}</el-tooltip
|
|
202
|
+
>`,
|
|
203
|
+
)}
|
|
204
|
+
`;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function define() {
|
|
209
|
+
// The tooltips of the destinations that show an icon alone.
|
|
210
|
+
defineTooltip();
|
|
211
|
+
defineElement('el-nav', Nav);
|
|
212
|
+
}
|