Skip to content

Commit 45fc2ee

Browse files
committed
rewrite DocsCollapsible
now with disabled js support and less broken animations
1 parent 22b8e15 commit 45fc2ee

File tree

9 files changed

+136
-46
lines changed

9 files changed

+136
-46
lines changed

src/components/Accordion.astro

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
import "@styles/components/accordion.css"
3+
---
4+
<details class=`accordion ${Astro.props.class ?? ""}` {...Astro.props}>
5+
<summary>
6+
<slot name="header"/>
7+
</summary>
8+
<div class="accordion-container">
9+
<div>
10+
<slot/>
11+
</div>
12+
</div>
13+
</details>
14+
<script>
15+
document.addEventListener("DOMContentLoaded", () => {
16+
document.querySelectorAll(".accordion").forEach(element => {
17+
const accordion = element as HTMLDetailsElement;
18+
const summary = accordion.querySelector("summary")!;
19+
const body = accordion.querySelector(".accordion-container") as HTMLDivElement;
20+
21+
summary.addEventListener("click", event => {
22+
event.preventDefault();
23+
body.classList.toggle("animate", true);
24+
25+
if (!accordion.open || accordion.classList.contains("closing")) {
26+
accordion.classList.toggle("closing", false);
27+
body.style.setProperty("--height", "0px");
28+
29+
requestAnimationFrame(() => {
30+
accordion.open = true;
31+
body.style.setProperty("--height", body.scrollHeight + "px");
32+
});
33+
} else {
34+
body.style.setProperty("--height", body.scrollHeight + "px");
35+
36+
requestAnimationFrame(() => {
37+
accordion.classList.toggle("closing", true);
38+
body.style.setProperty("--height", "0px");
39+
});
40+
}
41+
});
42+
43+
body.addEventListener("transitionend", event => {
44+
if ((event as TransitionEvent).propertyName == "max-height") {
45+
body.classList.toggle("animate", false);
46+
47+
if (accordion.classList.contains("closing")) {
48+
accordion.classList.toggle("closing", false);
49+
accordion.open = false;
50+
}
51+
}
52+
});
53+
});
54+
});
55+
</script>

src/components/Collapsible.astro

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
import Accordion from "./Accordion.astro"
3+
import collapsibleMarker from "@icons/collapsible-marker.svg?raw"
4+
5+
interface Props {
6+
title: string
7+
}
8+
const { title } = Astro.props;
9+
---
10+
<Accordion class="docs-collapsible">
11+
<div slot="header">
12+
<Fragment set:html={collapsibleMarker}/>
13+
{title}
14+
</div>
15+
<slot>
16+
</Accordion>

src/components/Collapsible.tsx

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/icons/collapsible-marker.svg

Lines changed: 2 additions & 0 deletions
Loading

src/pages/docs/configuration/intro.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: "@layouts/ConfigLayout.astro"
33
title: "Introduction"
44
---
55

6-
import { DocsCollapsible } from "@components/Collapsible.tsx";
6+
import Collapsible from "@components/Collapsible.astro";
77
import MD_Title from "@components/MD_Title.tsx"
88

99
# {frontmatter.title}
@@ -35,7 +35,7 @@ The shell root is not a visual element but instead contains all of the visual
3535
and non visual objects in your shell. You can have multiple different shells
3636
with shared components and different shell roots.
3737

38-
<DocsCollapsible title="Shell search paths and manifests" client:visible>
38+
<Collapsible title="Shell search paths and manifests">
3939
Quickshell can be launched with configurations in locations other than the default one.
4040

4141
The `-p` or `--path` option will launch the shell root at the given path.
@@ -68,7 +68,7 @@ myconf4 = ~/.config/quickshell/myconf
6868
You can use `quickshell --current` to print the current values of any of these
6969
options and what set them.
7070

71-
</DocsCollapsible>
71+
</Collapsible>
7272

7373
## <MD_Title titleVar={2}> Creating Windows </MD_Title>
7474

src/pages/docs/configuration/qml-overview.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: "@layouts/ConfigLayout.astro"
33
title: "QML Overview"
44
---
55
import MD_Title from "@components/MD_Title.tsx"
6-
import { DocsCollapsible } from "@components/Collapsible.tsx";
6+
import Collapsible from "@components/Collapsible.astro";
77

88
# {frontmatter.title}
99

@@ -140,7 +140,7 @@ import QtQuick.Layouts 6.0 as L
140140
import "jsfile.js" as JsFile
141141
```
142142

143-
<DocsCollapsible title="When no module version" client:visible>
143+
<Collapsible title="When no module version">
144144

145145
By default, when no module version is requested, the QML engine will pick
146146
the latest available version of the module. Requesting a specific version
@@ -151,7 +151,7 @@ While Qt's types usually don't majorly change across versions, quickshell's
151151
are much more likely to break. To put off dealing with the breakage we suggest
152152
specifying a version at least when importing quickshell modules.
153153

154-
</DocsCollapsible>
154+
</Collapsible>
155155

156156
<span class="small">
157157
[Qt Documentation: Import
@@ -321,14 +321,14 @@ the object a name it can be referred to throughout the current file. The id must
321321
}
322322
```
323323

324-
<DocsCollapsible title="The `id` property compared to normal properties" client:visible>
324+
<Collapsible title="The `id` property compared to normal properties">
325325

326326
The `id` property isn't really a property, and doesn't do anything other than
327327
expose the object to the current file. It is only called a property because it
328328
uses very similar syntax to one, and is the only exception to standard property
329329
definition rules. The name `id` is always reserved for the id property.
330330

331-
</DocsCollapsible>
331+
</Collapsible>
332332

333333
##### <MD_Title titleVar={5}> Property access scopes </MD_Title>
334334

src/styles/components/accordion.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.accordion {
2+
& summary {
3+
list-style: none;
4+
}
5+
6+
& .accordion-container {
7+
/* fixes jumps due to margins on inline items */
8+
display: flex;
9+
}
10+
11+
& .accordion-container.animate {
12+
/* this somehow breaks if both min AND max aren't animated */
13+
transition: min-height 0.3s ease, max-height 0.3s ease;
14+
min-height: var(--height);
15+
max-height: var(--height);
16+
}
17+
}

src/styles/css-config/animations.css

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,6 @@
5757
}
5858
}
5959

60-
@keyframes rotateIn90 {
61-
from {
62-
transform: rotate(0deg);
63-
}
64-
65-
to {
66-
transform: rotate(90deg);
67-
}
68-
}
69-
70-
@keyframes rotateOut90 {
71-
from {
72-
transform: rotate(90deg);
73-
}
74-
75-
to {
76-
transform: rotate(0deg);
77-
}
78-
}
79-
8060
@keyframes percentToFifty {
8161
from {
8262
--percent: 0%;

src/styles/docs/docs.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,41 @@ ul {
142142
min-width: 33.8rem;
143143
}
144144
}
145+
146+
.docs-collapsible {
147+
background-color: hsl(var(--white) 40 50 / 0.1);
148+
border-radius: 0.618rem;
149+
overflow: hidden;
150+
151+
& summary {
152+
padding: 1.2rem;
153+
user-select: none;
154+
155+
& > div {
156+
display: flex;
157+
flex-direction: row;
158+
align-items: center;
159+
gap: 0.1em;
160+
font-size: 1.117rem;
161+
font-weight: 500;
162+
163+
& svg {
164+
transition: transform 0.3s ease;
165+
font-size: 1.1em;
166+
}
167+
}
168+
}
169+
170+
& .accordion-container > div {
171+
padding: 0 1.2rem;
172+
173+
& p:first-child {
174+
padding-top: 0;
175+
margin-top: 0;
176+
}
177+
}
178+
}
179+
180+
.docs-collapsible[open]:not(.closing) > summary > div > svg {
181+
transform: rotate(90deg);
182+
}

0 commit comments

Comments
 (0)