Skip to content

Commit 399663d

Browse files
committed
hide prompt speech
1 parent 114d2eb commit 399663d

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

script.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,41 @@ function el(tag, className, text) {
134134
return node;
135135
}
136136

137-
function createAudioPanel(label, src) {
137+
function createAudioPanel(label, src, options = {}) {
138+
const { collapsible = false } = options;
138139
const wrap = el("div", "audio-panel");
139-
const lbl = el("p", "audio-label", label);
140140
const audio = document.createElement("audio");
141141
audio.controls = true;
142142
audio.preload = "none";
143143
audio.src = src;
144+
145+
if (collapsible) {
146+
wrap.classList.add("audio-panel-collapsible");
147+
audio.hidden = true;
148+
149+
const toggle = document.createElement("button");
150+
toggle.type = "button";
151+
toggle.className = "audio-label audio-label-button";
152+
toggle.textContent = label;
153+
toggle.setAttribute("aria-expanded", "false");
154+
toggle.setAttribute("aria-label", `Show ${label.toLowerCase()} audio`);
155+
toggle.addEventListener("click", () => {
156+
const isExpanded = toggle.getAttribute("aria-expanded") === "true";
157+
const nextExpanded = !isExpanded;
158+
audio.hidden = !nextExpanded;
159+
toggle.setAttribute("aria-expanded", String(nextExpanded));
160+
toggle.setAttribute(
161+
"aria-label",
162+
`${nextExpanded ? "Hide" : "Show"} ${label.toLowerCase()} audio`,
163+
);
164+
if (!nextExpanded) audio.pause();
165+
});
166+
167+
wrap.append(toggle, audio);
168+
return wrap;
169+
}
170+
171+
const lbl = el("p", "audio-label", label);
144172
wrap.append(lbl, audio);
145173
return wrap;
146174
}
@@ -172,7 +200,7 @@ function createSampleCard(sample, index) {
172200
// Body
173201
card.append(
174202
header,
175-
createAudioPanel("Prompt speech", sample.promptSpeech),
203+
createAudioPanel("Prompt speech", sample.promptSpeech, { collapsible: true }),
176204
createTextPanel(sample.text),
177205
createAudioPanel("Generated speech", sample.generatedSpeech),
178206
);

styles.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,29 @@ h3 {
668668
letter-spacing: 0.1em;
669669
}
670670

671+
.audio-label-button {
672+
appearance: none;
673+
border: 0;
674+
background: transparent;
675+
padding: 0;
676+
text-align: left;
677+
width: fit-content;
678+
cursor: pointer;
679+
transition: color 140ms, opacity 140ms, text-decoration-color 140ms;
680+
}
681+
682+
.audio-label-button:hover {
683+
color: var(--text);
684+
text-decoration: underline;
685+
text-underline-offset: 3px;
686+
}
687+
688+
.audio-label-button[aria-expanded="true"] {
689+
color: var(--text);
690+
text-decoration: underline;
691+
text-underline-offset: 3px;
692+
}
693+
671694
.text-panel {
672695
background: rgba(44, 37, 30, 0.04);
673696
border-radius: 6px;

0 commit comments

Comments
 (0)