@c2n/list-item 0.0.6
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/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/list-item-context-CXKVRXXI.js +14 -0
- package/dist/list-item-context.js +2 -0
- package/dist/list-item.js +169 -0
- package/package.json +64 -0
- package/types/src/list-item-context.d.ts +4 -0
- package/types/src/list-item-context.d.ts.map +1 -0
- package/types/src/list-item.d.ts +128 -0
- package/types/src/list-item.d.ts.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Nguyen Thai Vinh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @c2n/list-item
|
|
2
|
+
|
|
3
|
+
`c2-list-item` is a selectable row: on its own a click, Enter or Space toggles `selected`; inside a `c2-list` (or a `c2-select`) the list drives the selected state and the keyboard.
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
<c2-list-item value="inbox" selected>
|
|
7
|
+
<svg slot="prefix-icon" viewBox="0 0 24 24">…</svg>
|
|
8
|
+
Inbox
|
|
9
|
+
<span slot="description">12 unread</span>
|
|
10
|
+
</c2-list-item>
|
|
11
|
+
|
|
12
|
+
<c2-list-item href="/settings">Settings</c2-list-item>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
- Attributes: `value`, `label`, `selected`, `disabled`, `href` / `target`; property `data`.
|
|
16
|
+
- Slots: default content, `description` (second muted line), `prefix-icon`, `suffix-icon`.
|
|
17
|
+
- Accessibility: `role="button"` + `aria-pressed` standalone, `role="option"` + `aria-selected` inside a list, `role="link"` with `href`; a visible focus ring via the `__focus` tokens.
|
|
18
|
+
- `selected-change` fires after `selected` changes.
|
|
19
|
+
- Theming: `--c2-list-item--*` with `__description`, `__hover`, `__selected`, `__focus`, `__disabled` states and `__icon--size` / `__icon--color`.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region ../../../node_modules/@lit/context/lib/create-context.js
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2021 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
function n(n) {
|
|
8
|
+
return n;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/list-item-context.ts
|
|
12
|
+
var selectedItemValueContext = n(Symbol("list-item-selectedItemValue"));
|
|
13
|
+
//#endregion
|
|
14
|
+
export { selectedItemValueContext as t };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { t as selectedItemValueContext } from "./list-item-context-CXKVRXXI.js";
|
|
2
|
+
import { LitElement, html, nothing, unsafeCSS } from "lit";
|
|
3
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
|
4
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
5
|
+
import { ContextConsumer } from "@c2n/core/controllers/context-consumer.js";
|
|
6
|
+
import { redispatchEvent } from "@c2n/core/dom-helper.js";
|
|
7
|
+
//#region src/list-item.scss?inline
|
|
8
|
+
var list_item_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n:host {\n display: block;\n flex: none;\n user-select: none;\n}\n\n:host([hidden]) {\n display: none;\n}\n\n.c2-list-item {\n display: flex;\n align-items: center;\n box-sizing: border-box;\n cursor: pointer;\n text-decoration: none;\n min-height: var(--c2-list-item--min-height,36px);\n gap: var(--c2-list-item--gap,8px);\n font-size: var(--c2-list-item--font-size,14px);\n font-weight: var(--c2-list-item--font-weight);\n font-style: var(--c2-list-item--font-style);\n font-family: var(--c2-list-item--font-family);\n line-height: var(--c2-list-item--line-height,20px);\n border-top-left-radius: var(--c2-list-item--border-top-left-radius,6px);\n border-top-right-radius: var(--c2-list-item--border-top-right-radius,6px);\n border-bottom-left-radius: var(--c2-list-item--border-bottom-left-radius,6px);\n border-bottom-right-radius: var(--c2-list-item--border-bottom-right-radius,6px);\n padding-top: var(--c2-list-item--padding-top,6px);\n padding-right: var(--c2-list-item--padding-right,10px);\n padding-bottom: var(--c2-list-item--padding-bottom,6px);\n padding-left: var(--c2-list-item--padding-left,10px);\n border-top: var(--c2-list-item--border-top);\n border-bottom: var(--c2-list-item--border-bottom);\n border-right: var(--c2-list-item--border-right);\n border-left: var(--c2-list-item--border-left);\n background: var(--c2-list-item--background,transparent);\n color: var(--c2-list-item--color,#18181b);\n will-change: background, color, border;\n transition: background 250ms cubic-bezier(0.2, 0, 0, 1), color 250ms cubic-bezier(0.2, 0, 0, 1), border 250ms cubic-bezier(0.2, 0, 0, 1);\n}\n.c2-list-item:hover {\n border-top: var(--c2-list-item__hover--border-top,var(--c2-list-item--border-top));\n border-bottom: var(--c2-list-item__hover--border-bottom,var(--c2-list-item--border-bottom));\n border-right: var(--c2-list-item__hover--border-right,var(--c2-list-item--border-right));\n border-left: var(--c2-list-item__hover--border-left,var(--c2-list-item--border-left));\n background: var(--c2-list-item__hover--background,var(--c2-list-item--background,#f4f4f5));\n color: var(--c2-list-item__hover--color,var(--c2-list-item--color,#18181b));\n}\n\n.c2-list-item__content {\n flex: 1;\n min-width: 0;\n}\n\n.c2-list-item__description {\n margin-top: var(--c2-list-item__description--margin-top,1px);\n color: var(--c2-list-item__description--color,#71717a);\n font-size: var(--c2-list-item__description--font-size,12px);\n line-height: var(--c2-list-item__description--line-height,16px);\n font-weight: normal;\n}\n.c2-list-item__description[hidden] {\n display: none;\n}\n\n:host(:focus) {\n outline: none;\n}\n\n:host(:focus-visible) .c2-list-item {\n outline: var(--c2-list-item__focus--outline,2px solid rgba(2, 101, 220, 0.4));\n outline-offset: var(--c2-list-item__focus--outline-offset,-2px);\n}\n\n::slotted([slot=prefix-icon]),\n::slotted([slot=suffix-icon]) {\n flex: none;\n width: var(--c2-list-item__icon--size,16px);\n height: var(--c2-list-item__icon--size,16px);\n color: var(--c2-list-item__icon--color);\n --c2-feather-icon--size: var(--c2-list-item__icon--size,16px);\n --c2-mat-icon--font-size: var(--c2-list-item__icon--size,16px);\n}\n\n:host([selected]) .c2-list-item {\n border-top: var(--c2-list-item__selected--border-top,var(--c2-list-item--border-top));\n border-bottom: var(--c2-list-item__selected--border-bottom,var(--c2-list-item--border-bottom));\n border-right: var(--c2-list-item__selected--border-right,var(--c2-list-item--border-right));\n border-left: var(--c2-list-item__selected--border-left,var(--c2-list-item--border-left));\n background: var(--c2-list-item__selected--background,var(--c2-list-item--background,#edf1fe));\n color: var(--c2-list-item__selected--color,var(--c2-list-item--color,#2f56e6));\n}\n:host([selected]) .c2-list-item:hover {\n background: var(--c2-list-item__selected__hover--background,var(--c2-list-item__selected--background,#e2e9fd));\n}\n:host([selected]) .c2-list-item__description {\n color: var(--c2-list-item__selected__description--color,var(--c2-list-item__description--color,#71717a));\n}\n\n:host([selected][joined-before]) .c2-list-item {\n border-top-left-radius: 0;\n border-top-right-radius: 0;\n}\n\n:host([selected][joined-after]) .c2-list-item {\n border-bottom-left-radius: 0;\n border-bottom-right-radius: 0;\n}\n\n:host([disabled]) .c2-list-item {\n pointer-events: none;\n cursor: default;\n opacity: var(--c2-list-item__disabled--opacity,0.38);\n}";
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
|
|
11
|
+
function __decorate(decorators, target, key, desc) {
|
|
12
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
14
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
15
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/list-item.ts
|
|
19
|
+
var ListItem = class ListItem extends LitElement {
|
|
20
|
+
constructor(..._args) {
|
|
21
|
+
super(..._args);
|
|
22
|
+
this.contextConsumer = new ContextConsumer(this, {
|
|
23
|
+
context: selectedItemValueContext,
|
|
24
|
+
subscribe: true,
|
|
25
|
+
callback: (value) => {
|
|
26
|
+
this.selected = value ? value.includes(this.value) : false;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
this.selected = false;
|
|
30
|
+
this.disabled = false;
|
|
31
|
+
this.value = "";
|
|
32
|
+
this.href = void 0;
|
|
33
|
+
this.target = void 0;
|
|
34
|
+
this.applyContext = false;
|
|
35
|
+
this.hasDescription = false;
|
|
36
|
+
this.authorRole = null;
|
|
37
|
+
this.handleClick = (event) => {
|
|
38
|
+
if (this.disabled) {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
event.stopPropagation();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (redispatchEvent(this, event) && this.applyContext == false) this.selected = !this.selected;
|
|
44
|
+
};
|
|
45
|
+
this.handleKeydown = (event) => {
|
|
46
|
+
if (this.applyContext || this.disabled) return;
|
|
47
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
if (this.href) this.renderRoot.querySelector("a")?.click();
|
|
50
|
+
else this.activate();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
static {
|
|
55
|
+
this.styles = unsafeCSS(list_item_default);
|
|
56
|
+
}
|
|
57
|
+
/** The text a `c2-select` shows for this row: `label` when set, otherwise the text content of the default slot. */
|
|
58
|
+
get displayText() {
|
|
59
|
+
if (this.label !== void 0) return this.label;
|
|
60
|
+
return (this.contentSlot.assignedNodes({ flatten: true }).flatMap((item) => item.innerText ?? item.textContent).join(" ").trim() || this.contentSlot.innerText) ?? this.contentSlot.textContent;
|
|
61
|
+
}
|
|
62
|
+
connectedCallback() {
|
|
63
|
+
super.connectedCallback();
|
|
64
|
+
if (this.authorRole === null) this.authorRole = this.getAttribute("role");
|
|
65
|
+
this.addEventListener("keydown", this.handleKeydown);
|
|
66
|
+
}
|
|
67
|
+
disconnectedCallback() {
|
|
68
|
+
super.disconnectedCallback();
|
|
69
|
+
this.removeEventListener("keydown", this.handleKeydown);
|
|
70
|
+
}
|
|
71
|
+
/** Behaves like a click: dispatches `click` on the row and, for a standalone row, toggles `selected`. */
|
|
72
|
+
activate() {
|
|
73
|
+
if (this.disabled) return;
|
|
74
|
+
if (this.dispatchEvent(new MouseEvent("click", {
|
|
75
|
+
bubbles: true,
|
|
76
|
+
composed: true,
|
|
77
|
+
cancelable: true
|
|
78
|
+
})) && !this.applyContext) this.selected = !this.selected;
|
|
79
|
+
}
|
|
80
|
+
handleDescriptionSlotChange(event) {
|
|
81
|
+
this.updateDescription(event.target);
|
|
82
|
+
}
|
|
83
|
+
updateDescription(slot) {
|
|
84
|
+
this.hasDescription = slot.assignedNodes({ flatten: true }).some((n) => n.nodeType === Node.ELEMENT_NODE || (n.textContent ?? "").trim() !== "");
|
|
85
|
+
}
|
|
86
|
+
willUpdate(changedProperties) {
|
|
87
|
+
if (changedProperties.has("applyContext")) {
|
|
88
|
+
if (this.applyContext) this.contextConsumer.applyContext();
|
|
89
|
+
else if (this.applyContext == false) this.contextConsumer.unApplyContext();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
firstUpdated() {
|
|
93
|
+
const slot = this.renderRoot.querySelector("slot[name=\"description\"]");
|
|
94
|
+
if (slot) this.updateDescription(slot);
|
|
95
|
+
}
|
|
96
|
+
updated(changedProperties) {
|
|
97
|
+
if (changedProperties.has("selected") && changedProperties.get("selected") !== void 0) this.dispatchEvent(new CustomEvent("selected-change", {
|
|
98
|
+
bubbles: true,
|
|
99
|
+
composed: true,
|
|
100
|
+
detail: {
|
|
101
|
+
selected: this.selected,
|
|
102
|
+
value: this.value
|
|
103
|
+
}
|
|
104
|
+
}));
|
|
105
|
+
this.syncAria();
|
|
106
|
+
}
|
|
107
|
+
syncAria() {
|
|
108
|
+
const inList = this.applyContext;
|
|
109
|
+
const role = this.authorRole ?? (this.href ? "link" : inList ? "option" : "button");
|
|
110
|
+
this.setAttribute("role", role);
|
|
111
|
+
if (role === "option") {
|
|
112
|
+
this.setAttribute("aria-selected", String(this.selected));
|
|
113
|
+
this.removeAttribute("aria-pressed");
|
|
114
|
+
} else if (role === "button") {
|
|
115
|
+
this.setAttribute("aria-pressed", String(this.selected));
|
|
116
|
+
this.removeAttribute("aria-selected");
|
|
117
|
+
} else {
|
|
118
|
+
this.removeAttribute("aria-selected");
|
|
119
|
+
this.removeAttribute("aria-pressed");
|
|
120
|
+
}
|
|
121
|
+
if (this.disabled) this.setAttribute("aria-disabled", "true");
|
|
122
|
+
else this.removeAttribute("aria-disabled");
|
|
123
|
+
if (!inList) this.tabIndex = this.disabled ? -1 : 0;
|
|
124
|
+
else if (this.disabled) this.tabIndex = -1;
|
|
125
|
+
}
|
|
126
|
+
renderInner() {
|
|
127
|
+
return html`
|
|
128
|
+
<slot name="prefix-icon"></slot>
|
|
129
|
+
<div class="c2-list-item__content">
|
|
130
|
+
<div class="c2-list-item__text"><slot>${this.label ?? this.value}</slot></div>
|
|
131
|
+
<div class="c2-list-item__description" ?hidden=${!this.hasDescription}>
|
|
132
|
+
<slot name="description" @slotchange=${this.handleDescriptionSlotChange}></slot>
|
|
133
|
+
</div>
|
|
134
|
+
</div>
|
|
135
|
+
<slot name="suffix-icon"></slot>
|
|
136
|
+
`;
|
|
137
|
+
}
|
|
138
|
+
render() {
|
|
139
|
+
if (this.href && !this.disabled) return html`<a
|
|
140
|
+
class="c2-list-item"
|
|
141
|
+
href=${this.href}
|
|
142
|
+
target=${ifDefined(this.target)}
|
|
143
|
+
rel=${this.target === "_blank" ? "noopener noreferrer" : nothing}
|
|
144
|
+
tabindex="-1"
|
|
145
|
+
@click=${this.handleClick}
|
|
146
|
+
>${this.renderInner()}</a
|
|
147
|
+
>`;
|
|
148
|
+
return html`<div class="c2-list-item" @click=${this.handleClick}>${this.renderInner()}</div>`;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
__decorate([property({
|
|
152
|
+
type: Boolean,
|
|
153
|
+
reflect: true
|
|
154
|
+
})], ListItem.prototype, "selected", void 0);
|
|
155
|
+
__decorate([property({
|
|
156
|
+
type: Boolean,
|
|
157
|
+
reflect: true
|
|
158
|
+
})], ListItem.prototype, "disabled", void 0);
|
|
159
|
+
__decorate([property({ reflect: true })], ListItem.prototype, "value", void 0);
|
|
160
|
+
__decorate([property({ reflect: true })], ListItem.prototype, "label", void 0);
|
|
161
|
+
__decorate([property()], ListItem.prototype, "href", void 0);
|
|
162
|
+
__decorate([property()], ListItem.prototype, "target", void 0);
|
|
163
|
+
__decorate([property({ attribute: false })], ListItem.prototype, "data", void 0);
|
|
164
|
+
__decorate([property({ attribute: false })], ListItem.prototype, "applyContext", void 0);
|
|
165
|
+
__decorate([state()], ListItem.prototype, "hasDescription", void 0);
|
|
166
|
+
__decorate([query("slot:not([name])")], ListItem.prototype, "contentSlot", void 0);
|
|
167
|
+
ListItem = __decorate([customElement("c2-list-item")], ListItem);
|
|
168
|
+
//#endregion
|
|
169
|
+
export { ListItem };
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@c2n/list-item",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/list-item.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"default": "./dist/list-item.js",
|
|
9
|
+
"types": "./types/src/list-item.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./list-item-context.js": {
|
|
12
|
+
"default": "./dist/list-item-context.js",
|
|
13
|
+
"types": "./types/src/list-item-context.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./custom-elements.json": "./custom-elements.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"types"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"list-item",
|
|
23
|
+
"web component",
|
|
24
|
+
"lit"
|
|
25
|
+
],
|
|
26
|
+
"author": "code2nguyen@gmail.com",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"registry": "https://registry.npmjs.org",
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/code2nguyen/web-components.git"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"dev": "vite",
|
|
37
|
+
"build": "wireit",
|
|
38
|
+
"type-check": "wireit"
|
|
39
|
+
},
|
|
40
|
+
"wireit": {
|
|
41
|
+
"type-check": {
|
|
42
|
+
"dependencies": [
|
|
43
|
+
"../../core:build"
|
|
44
|
+
],
|
|
45
|
+
"command": "tsc -p tsconfig.lib.json --composite false"
|
|
46
|
+
},
|
|
47
|
+
"build": {
|
|
48
|
+
"dependencies": [
|
|
49
|
+
"type-check"
|
|
50
|
+
],
|
|
51
|
+
"command": "vite build"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@c2n/core": "0.0.6",
|
|
56
|
+
"@lit/context": "1.1.6",
|
|
57
|
+
"lit": "3.3.3"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@c2n/config": "*"
|
|
61
|
+
},
|
|
62
|
+
"customElements": "custom-elements.json",
|
|
63
|
+
"gitHead": "2921054bc75299da66dad11c1e374246ff88a51e"
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-item-context.d.ts","sourceRoot":"","sources":["../../src/list-item-context.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,wBAAwB;;CAAiE,CAAA"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { LitElement, type PropertyValueMap } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* A selectable row. On its own it is a toggle: click, Enter or Space flips `selected`. Inside a `c2-list` (and
|
|
4
|
+
* therefore inside a `c2-select`) the list drives the selected state through context, handles the keyboard and the row
|
|
5
|
+
* only reports clicks. The default slot is the primary text, `description` a second, muted line, `prefix-icon` and
|
|
6
|
+
* `suffix-icon` take an inline SVG, a `c2-feather-*` icon or a `c2-mat-icon` and are sized by `--c2-list-item__icon--size`.
|
|
7
|
+
* With `href` the row is a link. In a multiple-selection list, adjacent selected rows lose the corner radius between
|
|
8
|
+
* them (the list marks them `joined-before` / `joined-after`) so a run of selected rows reads as one block.
|
|
9
|
+
*
|
|
10
|
+
* Accessibility: standalone rows are `role="button"` with `aria-pressed`; rows in a list are `role="option"` with
|
|
11
|
+
* `aria-selected` and a roving `tabindex` managed by the list. Set your own `role` to override.
|
|
12
|
+
*
|
|
13
|
+
* @tag c2-list-item
|
|
14
|
+
*
|
|
15
|
+
* @slot default - The row content. Falls back to `label`, then `value`, when empty.
|
|
16
|
+
* @slot description - Secondary line under the content (muted, smaller).
|
|
17
|
+
* @slot prefix-icon - Icon (or avatar, badge, …) shown before the content.
|
|
18
|
+
* @slot suffix-icon - Icon shown after the content, e.g. a check mark or shortcut hint.
|
|
19
|
+
*
|
|
20
|
+
* @event {CustomEvent<{ selected: boolean; value: string }>} selected-change - Fired after `selected` changes, whether from a click or from the parent list.
|
|
21
|
+
*
|
|
22
|
+
* @cssproperty {pixel} [--c2-list-item--min-height=36px]
|
|
23
|
+
* @cssproperty {pixel} [--c2-list-item--gap=8px] - Space between the icons and the content.
|
|
24
|
+
*
|
|
25
|
+
* @cssproperty {border-radius} [--c2-list-item--border-top-left-radius=6px]
|
|
26
|
+
* @cssproperty {border-radius} [--c2-list-item--border-top-right-radius=6px]
|
|
27
|
+
* @cssproperty {border-radius} [--c2-list-item--border-bottom-left-radius=6px]
|
|
28
|
+
* @cssproperty {border-radius} [--c2-list-item--border-bottom-right-radius=6px]
|
|
29
|
+
*
|
|
30
|
+
* @cssproperty {padding} [--c2-list-item--padding-top=6px]
|
|
31
|
+
* @cssproperty {padding} [--c2-list-item--padding-right=10px]
|
|
32
|
+
* @cssproperty {padding} [--c2-list-item--padding-bottom=6px]
|
|
33
|
+
* @cssproperty {padding} [--c2-list-item--padding-left=10px]
|
|
34
|
+
*
|
|
35
|
+
* @cssproperty {font-size} [--c2-list-item--font-size=14px]
|
|
36
|
+
* @cssproperty {font-weight} --c2-list-item--font-weight
|
|
37
|
+
* @cssproperty {font-style} --c2-list-item--font-style
|
|
38
|
+
* @cssproperty {font-family} --c2-list-item--font-family
|
|
39
|
+
* @cssproperty {pixel} [--c2-list-item--line-height=20px]
|
|
40
|
+
*
|
|
41
|
+
* @cssproperty {border} --c2-list-item--border-top
|
|
42
|
+
* @cssproperty {border} --c2-list-item--border-bottom
|
|
43
|
+
* @cssproperty {border} --c2-list-item--border-right
|
|
44
|
+
* @cssproperty {border} --c2-list-item--border-left
|
|
45
|
+
*
|
|
46
|
+
* @cssproperty {color} [--c2-list-item--color=#18181b]
|
|
47
|
+
* @cssproperty {color} [--c2-list-item--background=transparent]
|
|
48
|
+
*
|
|
49
|
+
* @cssproperty {color} [--c2-list-item__description--color=#71717a]
|
|
50
|
+
* @cssproperty {font-size} [--c2-list-item__description--font-size=12px]
|
|
51
|
+
* @cssproperty {pixel} [--c2-list-item__description--line-height=16px]
|
|
52
|
+
* @cssproperty {pixel} [--c2-list-item__description--margin-top=1px]
|
|
53
|
+
*
|
|
54
|
+
* @cssproperty {border} --c2-list-item__hover--border-top
|
|
55
|
+
* @cssproperty {border} --c2-list-item__hover--border-bottom
|
|
56
|
+
* @cssproperty {border} --c2-list-item__hover--border-right
|
|
57
|
+
* @cssproperty {border} --c2-list-item__hover--border-left
|
|
58
|
+
* @cssproperty {color} --c2-list-item__hover--color
|
|
59
|
+
* @cssproperty {color} [--c2-list-item__hover--background=#f4f4f5]
|
|
60
|
+
*
|
|
61
|
+
* @cssproperty {border} --c2-list-item__selected--border-top
|
|
62
|
+
* @cssproperty {border} --c2-list-item__selected--border-bottom
|
|
63
|
+
* @cssproperty {border} --c2-list-item__selected--border-right
|
|
64
|
+
* @cssproperty {border} --c2-list-item__selected--border-left
|
|
65
|
+
* @cssproperty {color} [--c2-list-item__selected--color=#2f56e6]
|
|
66
|
+
* @cssproperty {color} [--c2-list-item__selected--background=#edf1fe]
|
|
67
|
+
* @cssproperty {color} [--c2-list-item__selected__hover--background=#e2e9fd]
|
|
68
|
+
* @cssproperty {color} --c2-list-item__selected__description--color - Defaults to the description colour.
|
|
69
|
+
*
|
|
70
|
+
* @cssproperty {outline} [--c2-list-item__focus--outline=2px solid rgba(2, 101, 220, 0.4)]
|
|
71
|
+
* @cssproperty {pixel} [--c2-list-item__focus--outline-offset=-2px]
|
|
72
|
+
*
|
|
73
|
+
* @cssproperty {opacity} [--c2-list-item__disabled--opacity=0.38]
|
|
74
|
+
*
|
|
75
|
+
* @cssproperty {pixel} [--c2-list-item__icon--size=16px]
|
|
76
|
+
* @cssproperty {color} --c2-list-item__icon--color - Defaults to the row text colour.
|
|
77
|
+
*/
|
|
78
|
+
export declare class ListItem extends LitElement {
|
|
79
|
+
static styles: import("lit").CSSResult;
|
|
80
|
+
private contextConsumer;
|
|
81
|
+
/** Whether the row is selected. Toggled by a click on a standalone row; controlled by the list otherwise. */
|
|
82
|
+
selected: boolean;
|
|
83
|
+
/** Dims the row and ignores clicks and keyboard. */
|
|
84
|
+
disabled: boolean;
|
|
85
|
+
/** The value reported to the parent list / select. */
|
|
86
|
+
value: string;
|
|
87
|
+
/**
|
|
88
|
+
* Text shown by the parent select for this row instead of the slotted content. Also the fallback content of the
|
|
89
|
+
* default slot when it is empty. Use it when the row content is rich (icons, two lines) but the trigger should show a
|
|
90
|
+
* short label.
|
|
91
|
+
*/
|
|
92
|
+
label?: string;
|
|
93
|
+
/** Makes the row a link. Selection still works when the row sits in a list. */
|
|
94
|
+
href: string | undefined;
|
|
95
|
+
target: string | undefined;
|
|
96
|
+
/** Arbitrary payload returned alongside `value` in the list's `selection-change` event. Not an attribute. */
|
|
97
|
+
data?: unknown;
|
|
98
|
+
/**
|
|
99
|
+
* Private property, it will use context value to setup selected state of component.
|
|
100
|
+
*/
|
|
101
|
+
applyContext: boolean;
|
|
102
|
+
private hasDescription;
|
|
103
|
+
private contentSlot;
|
|
104
|
+
/** `role` written by the author, kept over the automatic one. */
|
|
105
|
+
private authorRole;
|
|
106
|
+
/** The text a `c2-select` shows for this row: `label` when set, otherwise the text content of the default slot. */
|
|
107
|
+
get displayText(): string;
|
|
108
|
+
connectedCallback(): void;
|
|
109
|
+
disconnectedCallback(): void;
|
|
110
|
+
/** Behaves like a click: dispatches `click` on the row and, for a standalone row, toggles `selected`. */
|
|
111
|
+
activate(): void;
|
|
112
|
+
private handleClick;
|
|
113
|
+
private handleKeydown;
|
|
114
|
+
private handleDescriptionSlotChange;
|
|
115
|
+
private updateDescription;
|
|
116
|
+
protected willUpdate(changedProperties: PropertyValueMap<this>): void;
|
|
117
|
+
protected firstUpdated(): void;
|
|
118
|
+
protected updated(changedProperties: PropertyValueMap<this>): void;
|
|
119
|
+
private syncAria;
|
|
120
|
+
private renderInner;
|
|
121
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
122
|
+
}
|
|
123
|
+
declare global {
|
|
124
|
+
interface HTMLElementTagNameMap {
|
|
125
|
+
'c2-list-item': ListItem;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=list-item.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["../../src/list-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAQjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,qBACa,QAAS,SAAQ,UAAU;IACtC,OAAgB,MAAM,0BAAoB;IAE1C,OAAO,CAAC,eAAe,CAMrB;IAEF,6GAA6G;IACjE,QAAQ,UAAQ;IAE5D,oDAAoD;IACR,QAAQ,UAAQ;IAE5D,sDAAsD;IACzB,KAAK,SAAK;IAEvC;;;;OAIG;IAC0B,KAAK,CAAC,EAAE,MAAM,CAAA;IAE3C,+EAA+E;IACnE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAY;IAEpC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAY;IAElD,6GAA6G;IAC7E,IAAI,CAAC,EAAE,OAAO,CAAA;IAE9C;;OAEG;IAC6B,YAAY,UAAQ;IAE3C,OAAO,CAAC,cAAc,CAAQ;IAGvC,OAAO,CAAC,WAAW,CAAkB;IAErC,iEAAiE;IACjE,OAAO,CAAC,UAAU,CAAsB;IAExC,mHAAmH;IACnH,IAAI,WAAW,IAAI,MAAM,CAYxB;IAEQ,iBAAiB;IAMjB,oBAAoB;IAK7B,yGAAyG;IACzG,QAAQ;IAMR,OAAO,CAAC,WAAW,CAWlB;IAED,OAAO,CAAC,aAAa,CAQpB;IAED,OAAO,CAAC,2BAA2B;IAInC,OAAO,CAAC,iBAAiB;cAIN,UAAU,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,IAAI;cAU3D,YAAY,IAAI,IAAI;cAKpB,OAAO,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,IAAI;IAc3E,OAAO,CAAC,QAAQ;IAqBhB,OAAO,CAAC,WAAW;IAaV,MAAM;CAchB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,cAAc,EAAE,QAAQ,CAAA;KACzB;CACF"}
|