11import { LaconicError , type Trope , darkModeEnabled } from "./api" ;
22import { html } from "common-tags" ;
33
4- /** A small function that generates the custom HTML tippy will show when hovering on a trope
5- *
6- * It changes the title's color depending on whether dark mode
7- * is enabled. The trope's title and laconic description
8- * are interpolated into the html.
9- */
4+ function renderHeader ( title ?: string ) {
5+ return html `
6+ < p style ="color: ${ darkModeEnabled ( ) ? "#71e1bc" : "#0849ab" } "> ${ title } </ p >
7+ < hr class ="laconic-hr " />
8+ ` ;
9+ }
10+
11+ function renderReturnTo ( htmlReturnTo ?: string ) {
12+ if ( ! htmlReturnTo ) {
13+ return null ;
14+ }
15+
16+ return html `
17+ < hr class ="tvtropes-hr " />
18+ ${ htmlReturnTo }
19+ < hr class ="tvtropes-hr " />
20+ ` ;
21+ }
22+
1023export function hoverTemplate ( trope : Trope ) {
1124 return html `
1225 < div class ="laconic-hover ">
13- < p style ="color: ${ darkModeEnabled ( ) ? "#71e1bc" : "#0849ab" } ">
14- ${ trope . title }
15- </ p >
16- < hr class ="laconic-hr " />
26+ ${ renderHeader ( trope . title ) }
1727 < p > ${ trope . laconic } </ p >
18- < hr class ="tvtropes-hr " />
19- ${ trope . returnTo }
20- < hr class ="tvtropes-hr " />
28+ ${ renderReturnTo ( trope . returnTo ) }
2129 </ div >
2230 ` ;
2331}
@@ -26,19 +34,14 @@ export function errorHoverTemplate(error: Error, trope?: Trope) {
2634 if ( error instanceof LaconicError && error . category === "NO_LACONIC" ) {
2735 return html `
2836 < div class ="laconic-hover ">
29- < p style ="color: ${ darkModeEnabled ( ) ? "#71e1bc" : "#0849ab" } ">
30- ${ trope ?. title }
31- </ p >
32- < hr class ="laconic-hr " />
37+ ${ renderHeader ( trope ?. title ) }
3338 < p class ="error-message "> ${ LaconicError . messages . NO_LACONIC } </ p >
3439 </ div >
3540 ` ;
3641 }
3742 return html `
3843 < div class ="laconic-hover ">
39- < p style ="color: ${ darkModeEnabled ( ) ? "#71e1bc" : "#0849ab" } ">
40- ${ trope ?. title }
41- </ p >
44+ ${ renderHeader ( trope ?. title ) }
4245 ${ error . message &&
4346 html `
4447 < hr class ="laconic-hr " />
0 commit comments