Skip to content

Commit 7e79a4f

Browse files
Finally got this to work
1 parent ea2b776 commit 7e79a4f

File tree

2 files changed

+136
-22
lines changed

2 files changed

+136
-22
lines changed

assets/theme-css/sphinx-design/_dropdown.scss

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,31 @@ details.sd-dropdown {
55
font-weight: 700;
66
// don't overlap the chevron
77
padding-right: 3em !important;
8-
-moz-user-select: none;
9-
-ms-user-select: none;
10-
-webkit-user-select: none;
118
user-select: none;
9+
display: inline-flex;
10+
justify-content: space-between;
11+
align-items: center;
12+
width: 100%;
13+
14+
.sd-summary-text {
15+
flex-grow: 1;
16+
line-height: 1.5;
17+
padding-right: 0.5rem;
18+
}
19+
20+
.sd-summary-state-marker {
21+
position: absolute;
22+
right: 1em;
23+
top: 50%;
24+
transform: translateY(-50%);
25+
pointer-events: none;
26+
display: inline-flex;
27+
align-items: center;
28+
}
29+
30+
&:hover .sd-summary-state-marker svg {
31+
opacity: 1;
32+
}
1233
}
1334

1435
&:hover {
@@ -54,7 +75,6 @@ details.sd-dropdown {
5475
summary:hover .sd-summary-up svg,
5576
summary:hover .sd-summary-down svg {
5677
opacity: 1;
57-
transform: scale(1.1);
5878
}
5979

6080
.sd-summary-up svg,
@@ -79,6 +99,42 @@ details.sd-dropdown {
7999
visibility: hidden;
80100
}
81101

102+
// Chevron transitions
103+
.sd-summary-chevron-right i,
104+
.sd-summary-chevron-down i {
105+
display: inline-block;
106+
transform-origin: center;
107+
transition:
108+
transform 0.25s ease-in-out,
109+
opacity 0.25s ease-in-out;
110+
opacity: 0.6;
111+
}
112+
113+
// The chevron rotation animations are applied to
114+
// the icon inside the dropdown title div
115+
&[open] > .sd-summary-title .sd-summary-chevron-right i {
116+
transform: rotate(90deg);
117+
}
118+
119+
&[open] > .sd-summary-title .sd-summary-chevron-down i {
120+
transform: rotate(180deg);
121+
}
122+
123+
&:hover .sd-summary-chevron-right i,
124+
&:hover .sd-summary-chevron-down i {
125+
opacity: 1;
126+
transform: scale(1.1);
127+
}
128+
129+
// Combined transform for open state with hover
130+
&[open]:hover > .sd-summary-title .sd-summary-chevron-right i {
131+
transform: rotate(90deg) scale(1.1);
132+
}
133+
134+
&[open]:hover > .sd-summary-title .sd-summary-chevron-down i {
135+
transform: rotate(180deg) scale(1.1);
136+
}
137+
82138
// Hide the card body border when not open
83139
&:not([open]).sd-card {
84140
border: none;

layouts/shortcodes/dropdown.html

Lines changed: 76 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,89 @@
3131
body="And some content and an icon!"
3232
>}}
3333

34+
{{< dropdown
35+
title="Open dropdown by default"
36+
icon="fa-solid fa-eye"
37+
color="info"
38+
open="true"
39+
body="This dropdown is open by default!"
40+
>}}
41+
42+
{{< dropdown
43+
title="Fade in animation"
44+
icon="fa-solid fa-magic"
45+
animate="fade-in"
46+
body="This dropdown fades in when opened."
47+
>}}
48+
49+
{{< dropdown
50+
title="Fade in and slide down animation"
51+
icon="fa-solid fa-chart-line"
52+
animate="fade-in-slide-down"
53+
body="This dropdown fades in and slides down when opened."
54+
>}}
55+
56+
{{< dropdown
57+
title="Using chevron: `down-up`"
58+
icon="fa-solid fa-cog"
59+
chevron="down-up"
60+
body="Notice the different chevron direction!"
61+
>}}
62+
63+
{{< dropdown
64+
title="A custom chevron with an animation"
65+
icon="fa-solid fa-star"
66+
chevron="down-up"
67+
animate="fade-in"
68+
color="warning"
69+
body="Here's to combining different features!"
70+
>}}
71+
3472
*/}}
3573

3674
{{- $dropdown := dict -}}
3775
{{- range $key, $value := .Params -}}
3876
{{- $dropdown = merge $dropdown (dict $key $value) -}}
3977
{{- end -}}
4078

41-
<details class="sd-card sd-dropdown sd-mb-3">
42-
{{- with $dropdown.color }}
43-
<summary class="sd-summary-title sd-card-header sd-bg-{{ . }} sd-bg-text-{{ . }}">
44-
{{- else }}
45-
<summary class="sd-summary-title sd-card-header">
46-
{{- end }}
47-
{{- with $dropdown.icon }}
48-
<span class="sd-summary-icon"><i class="fa {{ . }}"></i></span>
49-
{{- end }}
50-
{{- with $dropdown.title }}
51-
{{- . }}
52-
{{- else }}
53-
<i class="fas fa-ellipsis-h"></i>&nbsp;
54-
{{- end }}
55-
</summary>
56-
<div class="sd-summary-content sd-card-body">
57-
{{- with (trim $dropdown.body "\n") }}
58-
{{- . | markdownify }}
79+
{{- /* Determine chevron type based on chevron parameter, and with some defaults */ -}}
80+
{{- $chevronClass := "sd-summary-chevron-right" -}}
81+
{{- $chevronIcon := "fa-chevron-right" -}}
82+
{{- if eq $dropdown.chevron "down-up" -}}
83+
{{- $chevronClass = "sd-summary-chevron-down" -}}
84+
{{- $chevronIcon = "fa-chevron-down" -}}
85+
{{- end -}}
86+
87+
{{- $detailsClasses := slice "sd-sphinx-override" "sd-dropdown" "sd-card" "sd-mb-3" -}}
88+
{{- with $dropdown.animate -}}
89+
{{- $detailsClasses = $detailsClasses | append (printf "sd-%s" .) -}}
90+
{{- end -}}
91+
92+
<details class="{{ delimit $detailsClasses " " }}"{{ if eq $dropdown.open "true" }} open="open"{{ end }}>
93+
{{- $summaryClasses := slice "sd-summary-title" "sd-card-header" -}}
94+
{{- with $dropdown.color -}}
95+
{{- $summaryClasses = $summaryClasses | append (printf "sd-bg-%s" .) -}}
96+
{{- $summaryClasses = $summaryClasses | append (printf "sd-bg-text-%s" .) -}}
97+
{{- end -}}
98+
99+
<summary class="{{ delimit $summaryClasses " " }}">
100+
{{- with $dropdown.icon }}
101+
<span class="sd-summary-icon"><i class="fa {{ . }}"></i></span>
102+
{{- end }}
103+
<span class="sd-summary-text">
104+
{{- with $dropdown.title }}
105+
{{- . }}
106+
{{- else }}
107+
<i class="fas fa-ellipsis-h no-title sd-octicon"></i>
59108
{{- end }}
109+
</span>
110+
<span class="sd-summary-state-marker {{ $chevronClass }}">
111+
<i class="fas {{ $chevronIcon }}"></i>
112+
</span>
113+
</summary>
114+
<div class="sd-summary-content sd-card-body docutils">
115+
{{ with (trim $dropdown.body "\n") }}
116+
<p class="sd-card-text">{{ . | markdownify | plainify }}</p>
117+
{{ end }}
60118
</div>
61119
</details>

0 commit comments

Comments
 (0)