@c2n/details 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 +27 -0
- package/dist/details-context.js +5 -0
- package/dist/details.js +216 -0
- package/package.json +64 -0
- package/types/src/details-context.d.ts +8 -0
- package/types/src/details-context.d.ts.map +1 -0
- package/types/src/details.d.ts +121 -0
- package/types/src/details.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,27 @@
|
|
|
1
|
+
# @c2n/details
|
|
2
|
+
|
|
3
|
+
Collapsible disclosure built on native `<details>` / `<summary>` with Lit.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @c2n/details
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<script type="module">
|
|
11
|
+
import '@c2n/details'
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<c2-details label="Shipping">Delivered in 3–5 business days.</c2-details>
|
|
15
|
+
|
|
16
|
+
<!-- exclusive accordion: opening one closes the others -->
|
|
17
|
+
<c2-details name="faq" label="Can I cancel anytime?">Yes.</c2-details>
|
|
18
|
+
<c2-details name="faq" label="Do you offer refunds?">Within 14 days.</c2-details>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- **Native first**: keyboard access, screen-reader semantics and find-in-page auto-expand come from the browser. `expanded` mirrors the native `open` state and the `toggle` event is re-dispatched on the element.
|
|
22
|
+
- **Accordion**: panels that share a `name` (within the same document or shadow root) are exclusive: opening one closes the others.
|
|
23
|
+
- **Slots**: `title` (or the `label` attribute), `header-content` for a second header row that stays visible when collapsed and whose buttons and links do not toggle the panel, `icon` and `expanded-icon` for the chevron, and the default slot for the content.
|
|
24
|
+
- **Options**: `title-not-clickable` makes only the icon toggle; `disabled` dims the header and blocks toggling.
|
|
25
|
+
- **Animation**: open and close slide the content (height plus a fade) with the Web Animations API, so the motion is the same in every browser; `--c2-details--transition-duration: 0ms` turns it off, and `prefers-reduced-motion` is respected.
|
|
26
|
+
|
|
27
|
+
Theming is done through CSS custom properties: `--c2-details--*` for the frame, `--c2-details__header--*` (plus `__icon`, `__content`, `__hover`, `__open`, `__focus`, `__disabled`) for the summary, and `--c2-details__content--*` for the body. The full list is in `custom-elements.json` and on the docs site.
|
package/dist/details.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { accordionContext } from "./details-context.js";
|
|
2
|
+
import { LitElement, html, nothing, unsafeCSS } from "lit";
|
|
3
|
+
import { consume } from "@lit/context";
|
|
4
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
|
5
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
6
|
+
import { redispatchEvent } from "@c2n/core/dom-helper.js";
|
|
7
|
+
//#region src/details.scss?inline
|
|
8
|
+
var details_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n:host {\n display: flex;\n}\n\n.c2-details {\n flex: 1;\n align-self: stretch;\n display: flex;\n flex-direction: column;\n min-width: 0;\n overflow: clip;\n background: var(--c2-details--background,rgb(255, 255, 255));\n box-shadow: var(--c2-details--box-shadow);\n border-top: var(--c2-details--border-top,1px solid rgb(213, 213, 213));\n border-right: var(--c2-details--border-right,1px solid rgb(213, 213, 213));\n border-bottom: var(--c2-details--border-bottom,1px solid rgb(213, 213, 213));\n border-left: var(--c2-details--border-left,1px solid rgb(213, 213, 213));\n border-top-left-radius: var(--c2-details--border-top-left-radius,8px);\n border-top-right-radius: var(--c2-details--border-top-right-radius,8px);\n border-bottom-left-radius: var(--c2-details--border-bottom-left-radius,8px);\n border-bottom-right-radius: var(--c2-details--border-bottom-right-radius,8px);\n}\n\nsummary {\n list-style: none;\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n cursor: pointer;\n user-select: none;\n padding-top: var(--c2-details__header--padding-top,12px);\n padding-right: var(--c2-details__header--padding-right,16px);\n padding-bottom: var(--c2-details__header--padding-bottom,12px);\n padding-left: var(--c2-details__header--padding-left,16px);\n background: var(--c2-details__header--background);\n color: var(--c2-details__header--color);\n font-weight: var(--c2-details__header--font-weight,500);\n font-size: var(--c2-details__header--font-size);\n transition: background var(--c2-details--transition-duration,250ms) cubic-bezier(0.2, 0, 0, 1), color var(--c2-details--transition-duration,250ms) cubic-bezier(0.2, 0, 0, 1);\n}\nsummary::-webkit-details-marker, summary::marker {\n display: none;\n content: \"\";\n}\nsummary:hover {\n background: var(--c2-details__header__hover--background,var(--c2-details__header--background,rgb(248, 248, 248)));\n color: var(--c2-details__header__hover--color,var(--c2-details__header--color));\n}\nsummary:focus-visible {\n outline: var(--c2-details__header__focus--outline,2px solid rgba(2, 101, 220, 0.4));\n outline-offset: var(--c2-details__header__focus--outline-offset,-2px);\n}\n\n.c2-details-summary-row {\n display: flex;\n align-items: center;\n gap: var(--c2-details__header--gap,12px);\n flex-direction: var(--c2-details__header--flex-direction,row);\n}\n\n.c2-details-summary-content {\n flex: 1;\n min-width: 0;\n display: flex;\n align-items: center;\n}\n\n.c2-details-icons {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex: none;\n color: var(--c2-details__header__icon--color,rgb(109, 109, 109));\n}\n.c2-details-icons .default-icon,\n.c2-details-icons ::slotted(*) {\n display: block;\n width: var(--c2-details__header__icon--width,20px);\n height: var(--c2-details__header__icon--height,20px);\n transition: transform var(--c2-details--transition-duration,250ms) cubic-bezier(0.2, 0, 0, 1);\n}\n.c2-details-icons slot[name=expanded-icon] {\n display: none;\n}\n\n.c2-details-header-content {\n margin-top: var(--c2-details__header__content--margin-top,4px);\n color: var(--c2-details__header__content--color,rgb(109, 109, 109));\n font-size: var(--c2-details__header__content--font-size,13px);\n font-weight: var(--c2-details__header__content--font-weight,400);\n cursor: auto;\n}\n.c2-details-header-content[hidden] {\n display: none;\n}\n\n.c2-details-content {\n flex: none;\n min-height: 0;\n transition-property: none;\n transition-duration: var(--c2-details--transition-duration,250ms);\n transition-timing-function: cubic-bezier(0.2, 0, 0, 1);\n}\n\n.c2-details-body {\n padding-top: var(--c2-details__content--padding-top,4px);\n padding-right: var(--c2-details__content--padding-right,var(--c2-details__header--padding-right,16px));\n padding-bottom: var(--c2-details__content--padding-bottom,var(--c2-details__header--padding-bottom,12px));\n padding-left: var(--c2-details__content--padding-left,var(--c2-details__header--padding-left,16px));\n color: var(--c2-details__content--color);\n border-top: var(--c2-details__content--border-top);\n}\n\n.c2-details[open] summary {\n background: var(--c2-details__header__open--background,var(--c2-details__header--background));\n color: var(--c2-details__header__open--color,var(--c2-details__header--color));\n}\n.c2-details[open] summary:hover {\n background: var(--c2-details__header__hover--background,var(--c2-details__header__open--background,var(--c2-details__header--background,rgb(248, 248, 248))));\n}\n.c2-details[open] .c2-details-icons .default-icon,\n.c2-details[open] .c2-details-icons slot[name=icon]::slotted(*) {\n transform: rotate(var(--c2-details__header__icon--rotate,180deg));\n}\n.c2-details[open] .c2-details-icons.has-expanded-icon slot[name=icon] {\n display: none;\n}\n.c2-details[open] .c2-details-icons.has-expanded-icon slot[name=expanded-icon] {\n display: contents;\n}\n\n:host([disabled]) summary {\n cursor: default;\n opacity: var(--c2-details__header__disabled--opacity,0.38);\n}\n\n@media (prefers-reduced-motion: reduce) {\n summary,\n .c2-details-icons .default-icon,\n .c2-details-icons ::slotted(*) {\n transition: none;\n }\n .c2-details-content {\n transition-duration: 0s;\n }\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/details.ts
|
|
19
|
+
var Details = class Details extends LitElement {
|
|
20
|
+
constructor(..._args) {
|
|
21
|
+
super(..._args);
|
|
22
|
+
this.expanded = false;
|
|
23
|
+
this.label = "";
|
|
24
|
+
this.name = void 0;
|
|
25
|
+
this.titleNotClickable = false;
|
|
26
|
+
this.disabled = false;
|
|
27
|
+
this.hasHeaderContent = false;
|
|
28
|
+
this.hasExpandedIcon = false;
|
|
29
|
+
this.closing = false;
|
|
30
|
+
this.contentAnimations = [];
|
|
31
|
+
}
|
|
32
|
+
static {
|
|
33
|
+
this.styles = unsafeCSS(details_default);
|
|
34
|
+
}
|
|
35
|
+
disconnectedCallback() {
|
|
36
|
+
super.disconnectedCallback();
|
|
37
|
+
this.accordion = void 0;
|
|
38
|
+
this.cancelContentAnimations();
|
|
39
|
+
this.closing = false;
|
|
40
|
+
}
|
|
41
|
+
willUpdate(changed) {
|
|
42
|
+
if (changed.has("expanded") && this.hasUpdated) {
|
|
43
|
+
if (this.expanded) this.closing = false;
|
|
44
|
+
else if (changed.get("expanded")) this.closing = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
updated(changed) {
|
|
48
|
+
if (this.isConnected && changed.has("expanded") && changed.get("expanded") !== void 0) {
|
|
49
|
+
this.animateContent(this.expanded);
|
|
50
|
+
this.accordion?.expandedChanged(this);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
cancelContentAnimations() {
|
|
54
|
+
for (const animation of this.contentAnimations) animation.cancel();
|
|
55
|
+
this.contentAnimations = [];
|
|
56
|
+
if (this.contentElement) this.contentElement.style.overflow = "";
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Slides the content between collapsed and its natural height, fading the body along the way. Duration and easing
|
|
60
|
+
* come from the `transition-*` values the stylesheet puts on the content element, so `--c2-details--transition-duration`
|
|
61
|
+
* and `prefers-reduced-motion` both apply. Reversing mid-flight starts from the current rendered height.
|
|
62
|
+
*/
|
|
63
|
+
animateContent(open) {
|
|
64
|
+
const content = this.contentElement;
|
|
65
|
+
const body = this.bodyElement;
|
|
66
|
+
if (!content || !body) return;
|
|
67
|
+
const from = this.contentAnimations.length ? content.getBoundingClientRect().height : open ? 0 : content.scrollHeight;
|
|
68
|
+
const fromOpacity = this.contentAnimations.length ? parseFloat(getComputedStyle(body).opacity) : open ? 0 : 1;
|
|
69
|
+
this.cancelContentAnimations();
|
|
70
|
+
const style = getComputedStyle(content);
|
|
71
|
+
const duration = parseDuration(firstListEntry(style.transitionDuration));
|
|
72
|
+
const easing = firstListEntry(style.transitionTimingFunction) || "ease";
|
|
73
|
+
if (duration <= 0 || typeof content.animate !== "function") {
|
|
74
|
+
this.closing = false;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const to = open ? content.scrollHeight : 0;
|
|
78
|
+
content.style.overflow = "hidden";
|
|
79
|
+
const height = content.animate([{ height: `${from}px` }, { height: `${to}px` }], {
|
|
80
|
+
duration,
|
|
81
|
+
easing
|
|
82
|
+
});
|
|
83
|
+
const fade = body.animate([{ opacity: fromOpacity }, { opacity: open ? 1 : 0 }], {
|
|
84
|
+
duration,
|
|
85
|
+
easing
|
|
86
|
+
});
|
|
87
|
+
this.contentAnimations = [height, fade];
|
|
88
|
+
height.finished.then(() => {
|
|
89
|
+
this.contentAnimations = [];
|
|
90
|
+
content.style.overflow = "";
|
|
91
|
+
if (!open) this.closing = false;
|
|
92
|
+
}).catch(() => {});
|
|
93
|
+
}
|
|
94
|
+
/** `slotchange` does not fire for server-rendered slots, so read them once after the first render. */
|
|
95
|
+
firstUpdated() {
|
|
96
|
+
for (const slot of this.renderRoot.querySelectorAll("slot")) this.updateSlot(slot);
|
|
97
|
+
}
|
|
98
|
+
handleSlotChange(event) {
|
|
99
|
+
this.updateSlot(event.target);
|
|
100
|
+
}
|
|
101
|
+
updateSlot(slot) {
|
|
102
|
+
const filled = slot.assignedNodes({ flatten: true }).some((node) => node.nodeType === Node.ELEMENT_NODE || (node.textContent ?? "").trim() !== "");
|
|
103
|
+
if (slot.name === "header-content") this.hasHeaderContent = filled;
|
|
104
|
+
else if (slot.name === "expanded-icon") this.hasExpandedIcon = filled;
|
|
105
|
+
}
|
|
106
|
+
handleSummaryClick(event) {
|
|
107
|
+
if (this.disabled) {
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const path = event.composedPath();
|
|
112
|
+
const inHeaderContent = path.some((el) => el instanceof HTMLElement && el.classList.contains("c2-details-header-content"));
|
|
113
|
+
const onIcon = path.some((el) => el instanceof HTMLElement && el.classList.contains("c2-details-icons"));
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
if (inHeaderContent || this.titleNotClickable && !onIcon) return;
|
|
116
|
+
this.toggle();
|
|
117
|
+
}
|
|
118
|
+
handleSummaryKeydown(event) {
|
|
119
|
+
if (this.disabled && (event.key === "Enter" || event.key === " ")) event.preventDefault();
|
|
120
|
+
}
|
|
121
|
+
handleDetailsToggle(event) {
|
|
122
|
+
this.expanded = this.detailsElement.open;
|
|
123
|
+
redispatchEvent(this, event);
|
|
124
|
+
}
|
|
125
|
+
/** Opens or closes the panel. */
|
|
126
|
+
toggle(force) {
|
|
127
|
+
if (this.disabled) return;
|
|
128
|
+
this.expanded = force ?? !this.expanded;
|
|
129
|
+
}
|
|
130
|
+
renderIcon() {
|
|
131
|
+
return html`
|
|
132
|
+
<span class=${classMap({
|
|
133
|
+
"c2-details-icons": true,
|
|
134
|
+
"has-expanded-icon": this.hasExpandedIcon
|
|
135
|
+
})}>
|
|
136
|
+
<slot name="expanded-icon" @slotchange=${this.handleSlotChange}></slot>
|
|
137
|
+
<slot name="icon">
|
|
138
|
+
<svg class="default-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
139
|
+
<polyline points="6 9 12 15 18 9"></polyline>
|
|
140
|
+
</svg>
|
|
141
|
+
</slot>
|
|
142
|
+
</span>
|
|
143
|
+
`;
|
|
144
|
+
}
|
|
145
|
+
render() {
|
|
146
|
+
return html`
|
|
147
|
+
<details class="c2-details" ?open=${this.expanded || this.closing} @toggle=${this.handleDetailsToggle}>
|
|
148
|
+
<summary
|
|
149
|
+
class=${classMap({ "has-header-content": this.hasHeaderContent })}
|
|
150
|
+
tabindex=${this.disabled ? "-1" : nothing}
|
|
151
|
+
aria-disabled=${this.disabled ? "true" : nothing}
|
|
152
|
+
@click=${this.handleSummaryClick}
|
|
153
|
+
@keydown=${this.handleSummaryKeydown}
|
|
154
|
+
>
|
|
155
|
+
<div class="c2-details-summary-row">
|
|
156
|
+
<div class="c2-details-summary-content"><slot name="title">${this.label}</slot></div>
|
|
157
|
+
${this.renderIcon()}
|
|
158
|
+
</div>
|
|
159
|
+
<div class="c2-details-header-content" ?hidden=${!this.hasHeaderContent}>
|
|
160
|
+
<slot name="header-content" @slotchange=${this.handleSlotChange}></slot>
|
|
161
|
+
</div>
|
|
162
|
+
</summary>
|
|
163
|
+
<div class="c2-details-content">
|
|
164
|
+
<div class="c2-details-body">
|
|
165
|
+
<slot></slot>
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
</details>
|
|
169
|
+
`;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
__decorate([query("details")], Details.prototype, "detailsElement", void 0);
|
|
173
|
+
__decorate([query(".c2-details-content")], Details.prototype, "contentElement", void 0);
|
|
174
|
+
__decorate([query(".c2-details-body")], Details.prototype, "bodyElement", void 0);
|
|
175
|
+
__decorate([property({
|
|
176
|
+
type: Boolean,
|
|
177
|
+
reflect: true
|
|
178
|
+
})], Details.prototype, "expanded", void 0);
|
|
179
|
+
__decorate([property()], Details.prototype, "label", void 0);
|
|
180
|
+
__decorate([property()], Details.prototype, "name", void 0);
|
|
181
|
+
__decorate([property({
|
|
182
|
+
type: Boolean,
|
|
183
|
+
reflect: true,
|
|
184
|
+
attribute: "title-not-clickable"
|
|
185
|
+
})], Details.prototype, "titleNotClickable", void 0);
|
|
186
|
+
__decorate([property({
|
|
187
|
+
type: Boolean,
|
|
188
|
+
reflect: true
|
|
189
|
+
})], Details.prototype, "disabled", void 0);
|
|
190
|
+
__decorate([state()], Details.prototype, "hasHeaderContent", void 0);
|
|
191
|
+
__decorate([state()], Details.prototype, "hasExpandedIcon", void 0);
|
|
192
|
+
__decorate([state()], Details.prototype, "closing", void 0);
|
|
193
|
+
__decorate([consume({
|
|
194
|
+
context: accordionContext,
|
|
195
|
+
subscribe: true
|
|
196
|
+
})], Details.prototype, "accordion", void 0);
|
|
197
|
+
Details = __decorate([customElement("c2-details")], Details);
|
|
198
|
+
/** First top-level entry of a comma-separated CSS list; commas inside `cubic-bezier(...)` are kept. */
|
|
199
|
+
function firstListEntry(value) {
|
|
200
|
+
let depth = 0;
|
|
201
|
+
for (let i = 0; i < value.length; i++) {
|
|
202
|
+
const char = value[i];
|
|
203
|
+
if (char === "(") depth++;
|
|
204
|
+
else if (char === ")") depth--;
|
|
205
|
+
else if (char === "," && depth === 0) return value.slice(0, i).trim();
|
|
206
|
+
}
|
|
207
|
+
return value.trim();
|
|
208
|
+
}
|
|
209
|
+
/** Parses a computed `transition-duration` value (`0.25s`, `250ms`) into milliseconds. */
|
|
210
|
+
function parseDuration(value) {
|
|
211
|
+
const amount = parseFloat(value);
|
|
212
|
+
if (Number.isNaN(amount)) return 0;
|
|
213
|
+
return value.endsWith("ms") ? amount : amount * 1e3;
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
export { Details };
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@c2n/details",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/details.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"default": "./dist/details.js",
|
|
9
|
+
"types": "./types/src/details.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./details-context.js": {
|
|
12
|
+
"default": "./dist/details-context.js",
|
|
13
|
+
"types": "./types/src/details-context.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./custom-elements.json": "./custom-elements.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"types"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"details",
|
|
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":"details-context.d.ts","sourceRoot":"","sources":["../../src/details-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC,MAAM,WAAW,gBAAgB;IAC/B,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAA;CACtC;AAED,eAAO,MAAM,gBAAgB;;CAA+D,CAAA"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { LitElement, type PropertyValues } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Collapsible disclosure built on native `<details>` / `<summary>`, so keyboard access, screen-reader semantics and
|
|
4
|
+
* find-in-page auto-expand come from the browser. Panels that share a `name` form an exclusive accordion. Open and
|
|
5
|
+
* close animate the content height (plus a fade) with the Web Animations API, so the motion is identical in every
|
|
6
|
+
* browser; the native `open` attribute is only removed once the close animation has finished.
|
|
7
|
+
*
|
|
8
|
+
* @tag c2-details
|
|
9
|
+
*
|
|
10
|
+
* @slot title - Header label. Falls back to the `label` attribute.
|
|
11
|
+
* @slot header-content - Second header row under the title (description, badges, actions). Stays visible when
|
|
12
|
+
* collapsed; clicks inside it do not toggle the panel, so buttons and links work there.
|
|
13
|
+
* @slot icon - Chevron shown in the header; rotates when open. Defaults to an inline SVG.
|
|
14
|
+
* @slot expanded-icon - Alternative icon shown only while open (replaces the rotation).
|
|
15
|
+
* @slot - Collapsible content.
|
|
16
|
+
*
|
|
17
|
+
* @event {ToggleEvent} toggle - Re-dispatched from the native details after it opens or closes (`newState` is `open` or `closed`).
|
|
18
|
+
*
|
|
19
|
+
* @cssproperty {border} [--c2-details--border-top=1px solid rgb(213, 213, 213)]
|
|
20
|
+
* @cssproperty {border} [--c2-details--border-right=1px solid rgb(213, 213, 213)]
|
|
21
|
+
* @cssproperty {border} [--c2-details--border-bottom=1px solid rgb(213, 213, 213)]
|
|
22
|
+
* @cssproperty {border} [--c2-details--border-left=1px solid rgb(213, 213, 213)]
|
|
23
|
+
*
|
|
24
|
+
* @cssproperty {border-radius} [--c2-details--border-top-left-radius=8px]
|
|
25
|
+
* @cssproperty {border-radius} [--c2-details--border-top-right-radius=8px]
|
|
26
|
+
* @cssproperty {border-radius} [--c2-details--border-bottom-left-radius=8px]
|
|
27
|
+
* @cssproperty {border-radius} [--c2-details--border-bottom-right-radius=8px]
|
|
28
|
+
*
|
|
29
|
+
* @cssproperty {background} [--c2-details--background=rgb(255, 255, 255)]
|
|
30
|
+
* @cssproperty {box-shadow} --c2-details--box-shadow
|
|
31
|
+
* @cssproperty {time} [--c2-details--transition-duration=250ms] - Open and close animation length; `0ms` disables it. Respects `prefers-reduced-motion`.
|
|
32
|
+
*
|
|
33
|
+
* @cssproperty {padding} [--c2-details__header--padding-top=12px]
|
|
34
|
+
* @cssproperty {padding} [--c2-details__header--padding-right=16px]
|
|
35
|
+
* @cssproperty {padding} [--c2-details__header--padding-bottom=12px]
|
|
36
|
+
* @cssproperty {padding} [--c2-details__header--padding-left=16px]
|
|
37
|
+
*
|
|
38
|
+
* @cssproperty {background} --c2-details__header--background
|
|
39
|
+
* @cssproperty {color} --c2-details__header--color
|
|
40
|
+
* @cssproperty {font-weight} [--c2-details__header--font-weight=500]
|
|
41
|
+
* @cssproperty {font-size} --c2-details__header--font-size
|
|
42
|
+
* @cssproperty {pixel} [--c2-details__header--gap=12px]
|
|
43
|
+
* @cssproperty {flex-direction-row} [--c2-details__header--flex-direction=row] - `row-reverse` puts the icon first.
|
|
44
|
+
*
|
|
45
|
+
* @cssproperty {pixel} [--c2-details__header__icon--width=20px]
|
|
46
|
+
* @cssproperty {pixel} [--c2-details__header__icon--height=20px]
|
|
47
|
+
* @cssproperty {pixel} [--c2-details__header__icon--rotate=180deg]
|
|
48
|
+
* @cssproperty {color} [--c2-details__header__icon--color=rgb(109, 109, 109)]
|
|
49
|
+
*
|
|
50
|
+
* @cssproperty {pixel} [--c2-details__header__content--margin-top=4px]
|
|
51
|
+
* @cssproperty {color} [--c2-details__header__content--color=rgb(109, 109, 109)]
|
|
52
|
+
* @cssproperty {font-size} [--c2-details__header__content--font-size=13px]
|
|
53
|
+
* @cssproperty {font-weight} [--c2-details__header__content--font-weight=400]
|
|
54
|
+
*
|
|
55
|
+
* @cssproperty {background} [--c2-details__header__hover--background=rgb(248, 248, 248)]
|
|
56
|
+
* @cssproperty {color} --c2-details__header__hover--color
|
|
57
|
+
* @cssproperty {background} --c2-details__header__open--background
|
|
58
|
+
* @cssproperty {color} --c2-details__header__open--color
|
|
59
|
+
* @cssproperty {outline} [--c2-details__header__focus--outline=2px solid rgba(2, 101, 220, 0.4)]
|
|
60
|
+
* @cssproperty {pixel} [--c2-details__header__focus--outline-offset=-2px]
|
|
61
|
+
* @cssproperty {opacity} [--c2-details__header__disabled--opacity=0.38]
|
|
62
|
+
*
|
|
63
|
+
* @cssproperty {padding} [--c2-details__content--padding-top=4px]
|
|
64
|
+
* @cssproperty {padding} --c2-details__content--padding-right - Falls back to the header padding.
|
|
65
|
+
* @cssproperty {padding} --c2-details__content--padding-bottom - Falls back to the header padding.
|
|
66
|
+
* @cssproperty {padding} --c2-details__content--padding-left - Falls back to the header padding.
|
|
67
|
+
* @cssproperty {color} --c2-details__content--color
|
|
68
|
+
* @cssproperty {border} --c2-details__content--border-top - Divider between header and content.
|
|
69
|
+
*/
|
|
70
|
+
export declare class Details extends LitElement {
|
|
71
|
+
static styles: import("lit").CSSResult;
|
|
72
|
+
protected detailsElement: HTMLDetailsElement;
|
|
73
|
+
private contentElement;
|
|
74
|
+
private bodyElement;
|
|
75
|
+
/** Open state, kept in sync with the native `open` attribute. */
|
|
76
|
+
expanded: boolean;
|
|
77
|
+
/** Header text when the `title` slot is empty. */
|
|
78
|
+
label: string;
|
|
79
|
+
/**
|
|
80
|
+
* Accordion group: opening a panel closes every other `c2-details` with the same name in the same document or shadow
|
|
81
|
+
* root. (The native `name` attribute cannot be used: each panel's `<details>` sits in its own shadow tree.)
|
|
82
|
+
*/
|
|
83
|
+
name: string | undefined;
|
|
84
|
+
/** Only the icon toggles the panel; clicking the title does nothing. */
|
|
85
|
+
titleNotClickable: boolean;
|
|
86
|
+
/** Dims the header and blocks toggling (pointer and keyboard). */
|
|
87
|
+
disabled: boolean;
|
|
88
|
+
private hasHeaderContent;
|
|
89
|
+
private hasExpandedIcon;
|
|
90
|
+
/** Keeps the native `open` attribute while the close animation plays; the content is hidden by the browser otherwise. */
|
|
91
|
+
private closing;
|
|
92
|
+
private contentAnimations;
|
|
93
|
+
private accordion;
|
|
94
|
+
disconnectedCallback(): void;
|
|
95
|
+
willUpdate(changed: PropertyValues<this>): void;
|
|
96
|
+
updated(changed: PropertyValues<this>): void;
|
|
97
|
+
private cancelContentAnimations;
|
|
98
|
+
/**
|
|
99
|
+
* Slides the content between collapsed and its natural height, fading the body along the way. Duration and easing
|
|
100
|
+
* come from the `transition-*` values the stylesheet puts on the content element, so `--c2-details--transition-duration`
|
|
101
|
+
* and `prefers-reduced-motion` both apply. Reversing mid-flight starts from the current rendered height.
|
|
102
|
+
*/
|
|
103
|
+
private animateContent;
|
|
104
|
+
/** `slotchange` does not fire for server-rendered slots, so read them once after the first render. */
|
|
105
|
+
firstUpdated(): void;
|
|
106
|
+
private handleSlotChange;
|
|
107
|
+
private updateSlot;
|
|
108
|
+
private handleSummaryClick;
|
|
109
|
+
private handleSummaryKeydown;
|
|
110
|
+
private handleDetailsToggle;
|
|
111
|
+
/** Opens or closes the panel. */
|
|
112
|
+
toggle(force?: boolean): void;
|
|
113
|
+
protected renderIcon(): import("lit-html").TemplateResult<1>;
|
|
114
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
115
|
+
}
|
|
116
|
+
declare global {
|
|
117
|
+
interface HTMLElementTagNameMap {
|
|
118
|
+
'c2-details': Details;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=details.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"details.d.ts","sourceRoot":"","sources":["../../src/details.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAQ/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,qBACa,OAAQ,SAAQ,UAAU;IACrC,OAAgB,MAAM,0BAAoB;IAExB,SAAS,CAAC,cAAc,EAAG,kBAAkB,CAAA;IACjC,OAAO,CAAC,cAAc,CAAc;IACvC,OAAO,CAAC,WAAW,CAAc;IAE5D,iEAAiE;IACrB,QAAQ,UAAQ;IAE5D,kDAAkD;IACtC,KAAK,SAAK;IAEtB;;;OAGG;IACS,IAAI,EAAE,MAAM,GAAG,SAAS,CAAY;IAEhD,wEAAwE;IACM,iBAAiB,UAAQ;IAEvG,kEAAkE;IACtB,QAAQ,UAAQ;IAEnD,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,CAAC,eAAe,CAAQ;IACxC,yHAAyH;IAChH,OAAO,CAAC,OAAO,CAAQ;IAEhC,OAAO,CAAC,iBAAiB,CAAkB;IAG3C,OAAO,CAAC,SAAS,CAA8B;IAEtC,oBAAoB;IAOpB,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAOxC,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAO9C,OAAO,CAAC,uBAAuB;IAM/B;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAmCtB,sGAAsG;IAC7F,YAAY;IAIrB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,mBAAmB;IAK3B,iCAAiC;IACjC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO;IAKtB,SAAS,CAAC,UAAU;IAaX,MAAM;CA0BhB;AAqBD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,YAAY,EAAE,OAAO,CAAA;KACtB;CACF"}
|