Skip to content

Commit

Permalink
Flyout: show a caret on flyout (#394)
Browse files Browse the repository at this point in the history
Small POC to showcase how it could look like #393

![Peek 2024-10-03
12-29](https://github.com/user-attachments/assets/3632b4d5-ddba-46c8-a17e-0bcbb8d2a1f9)

Closes #393 
Closes #364
  • Loading branch information
humitos committed Jan 22, 2025
1 parent 481c7f6 commit f8c7c30
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
30 changes: 9 additions & 21 deletions dist/readthedocs-addons.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/readthedocs-addons.js.map

Large diffs are not rendered by default.

23 changes: 16 additions & 7 deletions src/flyout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { ajv } from "./data-validation";
import READTHEDOCS_LOGO_WORDMARK from "./images/logo-wordmark-light.svg";
import READTHEDOCS_LOGO from "./images/logo-light.svg";
import { library, icon } from "@fortawesome/fontawesome-svg-core";
import { faCodeBranch, faLanguage } from "@fortawesome/free-solid-svg-icons";
import {
faCodeBranch,
faCaretDown,
faLanguage,
} from "@fortawesome/free-solid-svg-icons";
import { html, nothing, render, LitElement } from "lit";
import { classMap } from "lit/directives/class-map.js";
import { default as objectPath } from "object-path";
Expand Down Expand Up @@ -81,23 +85,28 @@ export class FlyoutElement extends LitElement {
this.config.projects.current.versioning_scheme !==
"single_version_without_translations"
) {
version = html`<span class="version"
>${iconCodeBranch.node[0]} ${this.config.versions.current.slug}</span
>`;
version = html`<span class="version">
${iconCodeBranch.node[0]} ${this.config.versions.current.slug}
</span> `;
}

const iconCaretDown = icon(faCaretDown, {
classes: ["icon"],
});

let translation = nothing;
if (this.config.projects.translations.length > 0) {
translation = html`<span class="language"
>${iconLanguage.node[0]}
translation = html`<span class="language">
${iconLanguage.node[0]}
${this.config.projects.current.language.code}</span
>`;
> `;
}

return html`
<header @click="${this._toggleOpen}">
<img class="logo" src="${this.readthedocsLogo}" alt="Read the Docs" />
${translation} ${version}
<span class="caret">${iconCaretDown.node[0]}</span>
</header>
`;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/__snapshots__/flyout.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ snapshots["Flyout addon snapshot flyout completely"] =
<span class="version">
latest
</span>
<span class="caret">
</span>
</header>
<main class="closed">
<dl class="languages">
Expand Down Expand Up @@ -132,6 +134,8 @@ snapshots["Flyout addon snapshot flyout with search disabled"] =
<span class="version">
latest
</span>
<span class="caret">
</span>
</header>
<main class="closed">
<dl class="languages">
Expand Down
1 change: 1 addition & 0 deletions tests/flyout.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
<img class="logo" alt="Read the Docs" />
<span class="language">en</span>
<span class="version">latest</span>
<span class="caret"></span>
</header>
`,
{ ignoreAttributes: [{ tags: ["img"], attributes: ["src"] }] },
Expand Down

0 comments on commit f8c7c30

Please sign in to comment.