@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,122 @@
|
|
|
1
|
+
# List
|
|
2
|
+
|
|
3
|
+
`list` is a list of rows: messages, articles, files, the entries of a settings page. The list is the surface and the list for assistive technology; every [`el-list-item`](../list-item/list-item.readme.md) in it is one row. It gives its rows one density, one line between two of them, and one place where their texts begin.
|
|
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/list/define';
|
|
17
|
+
import '@webtides/element-library/list-item/define';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```html
|
|
21
|
+
<el-list label="Messages">
|
|
22
|
+
<el-list-item href="/messages/1" mark="Unread">
|
|
23
|
+
<el-avatar slot="start" initials="AL" label="Ada Lovelace"></el-avatar>
|
|
24
|
+
Ada Lovelace
|
|
25
|
+
<span slot="description">The notes on the engine are ready for you.</span>
|
|
26
|
+
<time slot="end" datetime="09:12">09:12</time>
|
|
27
|
+
</el-list-item>
|
|
28
|
+
<el-list-item href="/messages/2" current="true">
|
|
29
|
+
<el-avatar slot="start" initials="GH" label="Grace Hopper"></el-avatar>
|
|
30
|
+
Grace Hopper
|
|
31
|
+
<span slot="description">Found it. A moth, in relay 70.</span>
|
|
32
|
+
<time slot="end" datetime="08:40">08:40</time>
|
|
33
|
+
</el-list-item>
|
|
34
|
+
</el-list>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
> Boolean attributes are passed as strings (`current="true"`), matching the rest of the library.
|
|
38
|
+
|
|
39
|
+
## API
|
|
40
|
+
|
|
41
|
+
#### Properties/Attributes
|
|
42
|
+
|
|
43
|
+
| Name | Type | Default | Description |
|
|
44
|
+
| --- | --- | --- | --- |
|
|
45
|
+
| `label` | `string` | `''` | The name of the list for assistive technology. Unset, the list has none. |
|
|
46
|
+
| `density` | `'default' \| 'compact'` | `'default'` | How much room a row has above and below its texts. Reflected to the `density` attribute. |
|
|
47
|
+
| `appearance` | `'plain' \| 'outlined' \| 'filled'` | `'plain'` | How the surface is painted: not at all, or as a card with the background of the page or a muted fill. Reflected to the `appearance` attribute. |
|
|
48
|
+
|
|
49
|
+
#### Methods
|
|
50
|
+
|
|
51
|
+
_None._
|
|
52
|
+
|
|
53
|
+
#### Events
|
|
54
|
+
|
|
55
|
+
_None._
|
|
56
|
+
|
|
57
|
+
#### Slots
|
|
58
|
+
|
|
59
|
+
| Name | Description |
|
|
60
|
+
| --------- | ---------------------------------- |
|
|
61
|
+
| (default) | The rows: `el-list-item` elements. |
|
|
62
|
+
|
|
63
|
+
#### CSS Parts
|
|
64
|
+
|
|
65
|
+
| Name | Description |
|
|
66
|
+
| ------ | ----------------------------------------- |
|
|
67
|
+
| `base` | The list (`role="list"`) and its surface. |
|
|
68
|
+
|
|
69
|
+
#### CSS Custom Properties
|
|
70
|
+
|
|
71
|
+
| Name | Default | Description |
|
|
72
|
+
| --- | --- | --- |
|
|
73
|
+
| `--el-list-padding-inline` | `--el-space-4` | The padding of a row at its start and its end. Read by the rows, so it can be set on the list or for the page. Without a theme it is `1rem`. |
|
|
74
|
+
|
|
75
|
+
## Where the texts begin
|
|
76
|
+
|
|
77
|
+
What stands at the start of a row differs: an avatar in one row, a small icon in the next, nothing in a third. The texts of all rows of a list begin on one line all the same, after the widest start of the list. The list has two columns, the start and the rest, and every row takes them over (`subgrid`). A list in which no row has a start has no first column: its texts begin at the padding of the row.
|
|
78
|
+
|
|
79
|
+
A `mark` of a row (an unread message) is a dot in that padding. It moves nothing.
|
|
80
|
+
|
|
81
|
+
## Density
|
|
82
|
+
|
|
83
|
+
`density="compact"` gives a row less room above and below its texts: `--el-space-2` in the place of `--el-space-3`, `0.5rem` in the place of `0.75rem` without a theme. Nothing else changes: the texts, the gap and the padding at the sides are the same.
|
|
84
|
+
|
|
85
|
+
On a touch screen (`@media (any-pointer: coarse)`) a row that is a link is at least `--el-touch-target` high in either density. A row that is no target stays as compact as it is.
|
|
86
|
+
|
|
87
|
+
## From edge to edge, and as a card
|
|
88
|
+
|
|
89
|
+
- `appearance="plain"`, the default: no surface. The list is as wide as its place, and a line reaches from one edge of it to the other. That is the list of a phone screen, or of a column that is one.
|
|
90
|
+
- `appearance="outlined"`: the surface of an `el-card`, with the background of the page, a border, round corners and the shadow of the theme.
|
|
91
|
+
- `appearance="filled"`: the same with the muted fill.
|
|
92
|
+
|
|
93
|
+
Between two rows is a line in `--el-color-border`, `--el-border-width` wide. Without a theme the list is headless: no line, no border, no fill.
|
|
94
|
+
|
|
95
|
+
A list in the body of an `el-card` has the padding of the card around it. `--el-list-padding-inline: 0` puts its rows on the line of the other content of the card:
|
|
96
|
+
|
|
97
|
+
```html
|
|
98
|
+
<el-card>
|
|
99
|
+
<strong slot="header">Folders</strong>
|
|
100
|
+
<el-list label="Folders" style="--el-list-padding-inline: 0">
|
|
101
|
+
<el-list-item href="/inbox">Inbox <span slot="end">12</span></el-list-item>
|
|
102
|
+
<el-list-item href="/drafts">Drafts <span slot="end">2</span></el-list-item>
|
|
103
|
+
</el-list>
|
|
104
|
+
</el-card>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The `hidden` attribute hides the list, and a row.
|
|
108
|
+
|
|
109
|
+
## Accessibility
|
|
110
|
+
|
|
111
|
+
- The list has `role="list"`, and every row is an item of it: a screen reader says how many rows the list has and where its user is in it.
|
|
112
|
+
- `label` names the list. A screen reader reads the name when its user enters the list; without it the list has none. A list of links that is the navigation of a page belongs into a `<nav>` of the page.
|
|
113
|
+
- The list has no keyboard model of its own. The Tab key goes from one link or control to the next, in the order of the rows.
|
|
114
|
+
|
|
115
|
+
## Server-side rendering
|
|
116
|
+
|
|
117
|
+
The list, its name and the rows are part of the server-rendered markup (Declarative Shadow DOM), with their links. The list runs no script: it looks the same before and after its JavaScript has loaded, its links work before that, and without JavaScript.
|
|
118
|
+
|
|
119
|
+
## What it is not
|
|
120
|
+
|
|
121
|
+
- No choice of several rows, no reordering by dragging, no swipe actions and no virtual scrolling.
|
|
122
|
+
- No groups with headings. Write a heading and a list after it for each group.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import hostStyle from '../../styles/host.style.js';
|
|
2
|
+
|
|
3
|
+
const css = String.raw;
|
|
4
|
+
|
|
5
|
+
const style = css`
|
|
6
|
+
:host {
|
|
7
|
+
display: block;
|
|
8
|
+
|
|
9
|
+
/* What the rows read. The density is the room above and below the texts of a row. */
|
|
10
|
+
--_el-list-padding-block: var(--el-space-3, 0.75rem);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
:host([density='compact']) {
|
|
14
|
+
--_el-list-padding-block: var(--el-space-2, 0.5rem);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Two columns for every row: what stands at the start, and the rest. A row takes them over
|
|
19
|
+
* (subgrid), so the first column is as wide as the widest start of the list, and the texts of
|
|
20
|
+
* all rows begin on one line. Without a start in any row the column has no width.
|
|
21
|
+
*
|
|
22
|
+
* The rows are told on themselves, not through the host: a property of the host would reach
|
|
23
|
+
* everything inside of the list, a row of another list in the content of a row as well.
|
|
24
|
+
*/
|
|
25
|
+
.list {
|
|
26
|
+
display: grid;
|
|
27
|
+
grid-template-columns: auto minmax(0, 1fr);
|
|
28
|
+
font-family: var(--el-font-family, inherit);
|
|
29
|
+
line-height: var(--el-line-height, inherit);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
::slotted(*) {
|
|
33
|
+
--_el-list-columns: subgrid;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/* ── Surface ──────────────────────────────────────────────────────────── */
|
|
37
|
+
|
|
38
|
+
/* A card: the surface of el-card. It is headless without a theme, every token falls back to a
|
|
39
|
+
value that paints nothing. The corners clip the fill of a row under the pointer; the focus
|
|
40
|
+
ring of a row is inside of the row, so it is not cut. */
|
|
41
|
+
:host([appearance='outlined']) .list,
|
|
42
|
+
:host([appearance='filled']) .list {
|
|
43
|
+
overflow: hidden;
|
|
44
|
+
background: var(--el-color-bg, transparent);
|
|
45
|
+
color: var(--el-color-fg, inherit);
|
|
46
|
+
border: var(--el-border-width, 0) solid var(--el-color-border, transparent);
|
|
47
|
+
border-radius: var(--el-radius-lg, 0);
|
|
48
|
+
box-shadow: var(--el-shadow-md, none);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
:host([appearance='filled']) .list {
|
|
52
|
+
background: var(--el-color-bg-muted, transparent);
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
export default [hostStyle(), style].join('\n');
|
|
@@ -0,0 +1,24 @@
|
|
|
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-list-item`: one row of an `el-list`, an item of its list (`role="listitem"`). It has a start (`start` slot), a title (default slot), a line under it (`description`), an end (`end`) and a control of its own (`action`). ([#192](https://github.com/webtides/element-library/issues/192))
|
|
20
|
+
- With `href` the row is a link as a whole: the title is a native link (`target` is passed on, `rel` is written with it), and its target is the whole row. A control in `action` lies on top of the link and stays a target of its own. On a touch screen a row that is a link is at least `--el-touch-target` high.
|
|
21
|
+
- `current` marks the current or the chosen row: `aria-current` (`"page"` on the link, `"true"` on a row without one), a tint, a bar at the start in the accent colour and a heavier title. The bar is a border, so it stays where the user forces colours.
|
|
22
|
+
- `mark` draws a dot in the padding at the start of the row, which does not move the texts. Its text is read in front of the title and is part of the name of the link (`mark="Unread"`).
|
|
23
|
+
- A long title breaks into more lines, inside of a word where it has to, so a text a user typed cannot widen the page. `truncate` cuts the title and the line under it after one line.
|
|
24
|
+
- The row runs no script: its link works before the element takes over, and without JavaScript in server-rendered markup.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { TemplateElement, defineElement, html, classMap, spreadAttributes } from '@webtides/element-js';
|
|
2
|
+
import style from './list-item.style.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* One row of an `el-list`. It has the parts a row has everywhere: something at the start (an icon,
|
|
6
|
+
* an avatar), a title, a line under it, something at the end (a value, a count, a chevron), and a
|
|
7
|
+
* control of its own after that.
|
|
8
|
+
*
|
|
9
|
+
* With `href` the row is a link as a whole: the title is the link, and its target is the whole
|
|
10
|
+
* row. What is slotted into `action` stays a target of its own.
|
|
11
|
+
*
|
|
12
|
+
* Pure presentation: the row runs no script of its own.
|
|
13
|
+
*
|
|
14
|
+
* @element el-list-item
|
|
15
|
+
*
|
|
16
|
+
* @slot - The title of the row.
|
|
17
|
+
* @slot description - The line under the title.
|
|
18
|
+
* @slot start - What stands in front of the texts: an icon, an avatar. The texts of all rows of a
|
|
19
|
+
* list begin after the widest start.
|
|
20
|
+
* @slot end - What stands at the end of the row and belongs to it: a value, a count, a chevron. In
|
|
21
|
+
* a row that is a link it is part of the target of the link.
|
|
22
|
+
* @slot action - A control at the very end: a button, a switch, a menu. In a row that is a link it
|
|
23
|
+
* lies on top of the link and is a target of its own.
|
|
24
|
+
*
|
|
25
|
+
* @csspart base - The row: an item of the list.
|
|
26
|
+
* @csspart mark - The dot of `mark`, in the padding at the start of the row.
|
|
27
|
+
* @csspart start - The region of the `start` slot.
|
|
28
|
+
* @csspart text - The title and the line under it.
|
|
29
|
+
* @csspart title - The title: an `<a>` with `href`, a `<span>` without.
|
|
30
|
+
* @csspart description - The region of the `description` slot.
|
|
31
|
+
* @csspart end - The region of the `end` slot.
|
|
32
|
+
* @csspart action - The region of the `action` slot.
|
|
33
|
+
*
|
|
34
|
+
* @cssproperty --el-list-padding-inline - The padding of the row at its start and its end. Unset,
|
|
35
|
+
* it is `--el-space-4`, and `1rem` without a theme.
|
|
36
|
+
*
|
|
37
|
+
* @property {string} href - The address the row leads to. Unset, the row is no link.
|
|
38
|
+
* @property {string} target - Where to open the address (only with `href`).
|
|
39
|
+
* @property {string} rel - `rel` attribute for the link, written when `target` is set. Default
|
|
40
|
+
* `'noreferrer noopener'`.
|
|
41
|
+
* @property {boolean} current - The row is the current or the chosen one: it gets `aria-current`
|
|
42
|
+
* (`"page"` on the link of a row with `href`, `"true"` on a row without), a bar at its start
|
|
43
|
+
* and a heavier title. Default `false`.
|
|
44
|
+
* @property {string} mark - Marks the row with a dot in the padding at its start, which does not
|
|
45
|
+
* move the texts: an unread message, for example. The text is what assistive technology reads
|
|
46
|
+
* in front of the title ("Unread"). Unset, the row has no mark.
|
|
47
|
+
* @property {boolean} truncate - Cuts the title and the line under it after one line, with an
|
|
48
|
+
* ellipsis. Unset, a long text breaks into more lines. Default `false`.
|
|
49
|
+
*/
|
|
50
|
+
export default class ListItem extends TemplateElement {
|
|
51
|
+
constructor() {
|
|
52
|
+
super({
|
|
53
|
+
styles: [style],
|
|
54
|
+
shadowRender: true,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
properties() {
|
|
59
|
+
return {
|
|
60
|
+
href: '',
|
|
61
|
+
target: '',
|
|
62
|
+
rel: 'noreferrer noopener',
|
|
63
|
+
current: false,
|
|
64
|
+
mark: '',
|
|
65
|
+
truncate: false,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @private */
|
|
70
|
+
titleTemplate() {
|
|
71
|
+
// Read in front of the title, and part of the name of the link: a list of links says
|
|
72
|
+
// which of them are marked. The space keeps the two words apart in that name.
|
|
73
|
+
const mark = this.mark ? html`<span class="mark-text">${this.mark} </span>` : '';
|
|
74
|
+
|
|
75
|
+
if (!this.href) {
|
|
76
|
+
return html`<span part="title" class="title">${mark}<slot></slot></span>`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return html`
|
|
80
|
+
<a
|
|
81
|
+
part="title"
|
|
82
|
+
class="title"
|
|
83
|
+
href="${this.href}"
|
|
84
|
+
${spreadAttributes({
|
|
85
|
+
target: this.target || undefined,
|
|
86
|
+
rel: this.target ? this.rel : undefined,
|
|
87
|
+
'aria-current': this.current ? 'page' : undefined,
|
|
88
|
+
})}
|
|
89
|
+
>${mark}<slot></slot
|
|
90
|
+
></a>
|
|
91
|
+
`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
template() {
|
|
95
|
+
const classes = {
|
|
96
|
+
item: true,
|
|
97
|
+
'item--link': !!this.href,
|
|
98
|
+
'item--current': !!this.current,
|
|
99
|
+
'item--truncate': !!this.truncate,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// The role of a row is inside of the shadow root, not on the element: it is part of the
|
|
103
|
+
// server-rendered markup that way, and needs no script.
|
|
104
|
+
return html`
|
|
105
|
+
<div
|
|
106
|
+
part="base"
|
|
107
|
+
class="${classMap(classes)}"
|
|
108
|
+
role="listitem"
|
|
109
|
+
${spreadAttributes({ 'aria-current': this.current && !this.href ? 'true' : undefined })}
|
|
110
|
+
>
|
|
111
|
+
${this.mark ? html`<span part="mark" class="mark" aria-hidden="true"></span>` : ''}
|
|
112
|
+
<span part="start" class="start"><slot name="start"></slot></span>
|
|
113
|
+
<span class="body">
|
|
114
|
+
<span part="text" class="text">
|
|
115
|
+
${this.titleTemplate()}
|
|
116
|
+
<span part="description" class="description"><slot name="description"></slot></span>
|
|
117
|
+
</span>
|
|
118
|
+
<span part="end" class="end"><slot name="end"></slot></span>
|
|
119
|
+
<span part="action" class="action"><slot name="action"></slot></span>
|
|
120
|
+
</span>
|
|
121
|
+
</div>
|
|
122
|
+
`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function define() {
|
|
127
|
+
defineElement('el-list-item', ListItem);
|
|
128
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# ListItem
|
|
2
|
+
|
|
3
|
+
`list-item` is one row of an [`el-list`](../list/list.readme.md). It has the parts a row has everywhere: something at the start, a title, a line under it, something at the end, and a control of its own after that. With `href` the row is a link as a whole.
|
|
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/list/define';
|
|
17
|
+
import '@webtides/element-library/list-item/define';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```html
|
|
21
|
+
<el-list label="Files">
|
|
22
|
+
<el-list-item href="/files/notes.pdf">
|
|
23
|
+
<el-svg-use slot="start" name="file"></el-svg-use>
|
|
24
|
+
notes.pdf
|
|
25
|
+
<span slot="description">240 KB</span>
|
|
26
|
+
<el-badge slot="end" pill="true">3</el-badge>
|
|
27
|
+
<el-button slot="action" size="small" appearance="plain" aria-label="Remove notes.pdf">✕</el-button>
|
|
28
|
+
</el-list-item>
|
|
29
|
+
</el-list>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
> Boolean attributes are passed as strings (`current="true"`), matching the rest of the library.
|
|
33
|
+
|
|
34
|
+
## API
|
|
35
|
+
|
|
36
|
+
#### Properties/Attributes
|
|
37
|
+
|
|
38
|
+
| Name | Type | Default | Description |
|
|
39
|
+
| --- | --- | --- | --- |
|
|
40
|
+
| `href` | `string` | `''` | The address the row leads to. Unset, the row is no link. |
|
|
41
|
+
| `target` | `string` | `''` | Where to open the address (only with `href`). |
|
|
42
|
+
| `rel` | `string` | `'noreferrer noopener'` | `rel` attribute for the link, written when `target` is set. |
|
|
43
|
+
| `current` | `boolean` | `false` | The row is the current or the chosen one: it gets `aria-current`, a bar at its start and a heavier title. |
|
|
44
|
+
| `mark` | `string` | `''` | Marks the row with a dot in the padding at its start. The text is read in front of the title. Unset, the row has no mark. |
|
|
45
|
+
| `truncate` | `boolean` | `false` | Cuts the title and the line under it after one line, with an ellipsis. |
|
|
46
|
+
|
|
47
|
+
#### Methods
|
|
48
|
+
|
|
49
|
+
_None._
|
|
50
|
+
|
|
51
|
+
#### Events
|
|
52
|
+
|
|
53
|
+
_None._
|
|
54
|
+
|
|
55
|
+
#### Slots
|
|
56
|
+
|
|
57
|
+
| Name | Description |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| (default) | The title of the row. |
|
|
60
|
+
| `description` | The line under the title. |
|
|
61
|
+
| `start` | What stands in front of the texts: an icon, an avatar. |
|
|
62
|
+
| `end` | What stands at the end of the row and belongs to it: a value, a count, a chevron. In a row that is a link it is part of the target of the link. |
|
|
63
|
+
| `action` | A control at the very end: a button, a switch, a menu. In a row that is a link it lies on top of the link and is a target of its own. |
|
|
64
|
+
|
|
65
|
+
#### CSS Parts
|
|
66
|
+
|
|
67
|
+
| Name | Description |
|
|
68
|
+
| ------------- | ---------------------------------------------------- |
|
|
69
|
+
| `base` | The row: an item of the list. |
|
|
70
|
+
| `mark` | The dot of `mark`, in the padding at the start. |
|
|
71
|
+
| `start` | The region of the `start` slot. |
|
|
72
|
+
| `text` | The title and the line under it. |
|
|
73
|
+
| `title` | The title: an `<a>` with `href`, a `<span>` without. |
|
|
74
|
+
| `description` | The region of the `description` slot. |
|
|
75
|
+
| `end` | The region of the `end` slot. |
|
|
76
|
+
| `action` | The region of the `action` slot. |
|
|
77
|
+
|
|
78
|
+
#### CSS Custom Properties
|
|
79
|
+
|
|
80
|
+
| Name | Default | Description |
|
|
81
|
+
| --- | --- | --- |
|
|
82
|
+
| `--el-list-padding-inline` | `--el-space-4` | The padding of the row at its start and its end. Set on the list, or for the page. Without a theme it is `1rem`. |
|
|
83
|
+
|
|
84
|
+
## A row that is a link
|
|
85
|
+
|
|
86
|
+
With `href` the title is a native link, and the target of that link is the whole row: the padding, the start, the texts and the end. A click anywhere on the row follows the link, and it is a real link there: the context menu, a middle click and "open in a new tab" work as on any link. The name of the link is the title alone; the line under it and the end are text beside it.
|
|
87
|
+
|
|
88
|
+
The link takes the keyboard focus once, and its focus ring is drawn around the row, inside of it.
|
|
89
|
+
|
|
90
|
+
On a touch screen (`@media (any-pointer: coarse)`) a row that is a link is at least `--el-touch-target` high.
|
|
91
|
+
|
|
92
|
+
## `end` and `action`
|
|
93
|
+
|
|
94
|
+
Both stand at the end of the row, `end` first.
|
|
95
|
+
|
|
96
|
+
- **`end`** is for what belongs to the row: a value, a count, a time, a chevron. In a row that is a link, a click on it follows the link.
|
|
97
|
+
- **`action`** is for a control: a button, a switch, a menu. It lies on top of the link and is a target of its own, with a place of its own in the tab order after the link.
|
|
98
|
+
|
|
99
|
+
A control belongs into `action`. In `end` it would lie under the link of the row, and a click on it would follow the link. In a row without `href` the two only differ in their order and their colour.
|
|
100
|
+
|
|
101
|
+
## The current row
|
|
102
|
+
|
|
103
|
+
`current` marks the row of the page the user is on, or the row that is chosen: the message that is open beside the list. A row with `href` gets `aria-current="page"` on its link, a row without gets `aria-current="true"`.
|
|
104
|
+
|
|
105
|
+
It is told apart by a tint of the text colour, by a bar at its start in the accent colour and by a heavier title. The bar and the weight do not depend on a colour: where the user forces colours, the bar is drawn in a colour of the system.
|
|
106
|
+
|
|
107
|
+
## A mark
|
|
108
|
+
|
|
109
|
+
`mark="Unread"` draws a dot in the padding at the start of the row, in the accent colour. It is out of the flow: a row with a mark has its start and its texts where a row without one has them. The text of the attribute is for assistive technology: it is read in front of the title, and it is part of the name of the link ("Unread Ada Lovelace"). Write it in the language of the page.
|
|
110
|
+
|
|
111
|
+
## Long texts
|
|
112
|
+
|
|
113
|
+
A title that is longer than the row breaks into more lines, and so does the line under it. A text without a space (an address, a word a user typed) breaks inside of the word: a row is never wider than its list. What is in `end` takes half of the row at most and breaks after that.
|
|
114
|
+
|
|
115
|
+
`truncate="true"` cuts the title and the line under it after one line, with an ellipsis. What is cut is not shown anywhere else; use it where the row leads to the whole text.
|
|
116
|
+
|
|
117
|
+
## Accessibility
|
|
118
|
+
|
|
119
|
+
- The row has `role="listitem"`. Use it in an `el-list`, which is the list.
|
|
120
|
+
- A row with `href` holds one link, named by the title. The texts beside it are read with the row.
|
|
121
|
+
- An icon or an avatar in `start` that only repeats the title should be hidden from assistive technology (`aria-hidden="true"`), or have a name that adds something.
|
|
122
|
+
- A control in `action` needs a name that says which row it acts on ("Remove notes.pdf"), because a screen reader user may reach it without the row.
|
|
123
|
+
|
|
124
|
+
## Server-side rendering
|
|
125
|
+
|
|
126
|
+
The row, its link and its parts are part of the server-rendered markup (Declarative Shadow DOM). The row runs no script: it looks the same before and after its JavaScript has loaded, and its link works before that.
|