Skip to content

Commit ed17338

Browse files
committed
Expose TypeDoc's icons for use by themes
Resolves #1978.
1 parent 9cf85e8 commit ed17338

File tree

8 files changed

+24
-25
lines changed

8 files changed

+24
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Features
44

55
- The `DEBUG_SEARCH_WEIGHTS` global variable can now be set on `window` to add search scoring information in the search results.
6+
- TypeDoc's icons are now available on `DefaultThemeRenderContext.icons` for use/modification by themes.
67

78
## v0.23.4 (2022-07-02)
89

src/lib/output/themes/default/DefaultThemeRenderContext.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { comment } from "./partials/comment";
1010
import { footer } from "./partials/footer";
1111
import { header } from "./partials/header";
1212
import { hierarchy } from "./partials/hierarchy";
13+
import { icons } from "./partials/icon";
1314
import { member } from "./partials/member";
1415
import { memberDeclaration } from "./partials/member.declaration";
1516
import { memberGetterSetter } from "./partials/member.getterSetter";
@@ -40,6 +41,8 @@ export class DefaultThemeRenderContext {
4041
this.options = options;
4142
}
4243

44+
icons = icons;
45+
4346
hook = (name: keyof RendererHooks) =>
4447
this.theme.owner.hooks.emit(name, this);
4548

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { JSX } from "../../../../utils";
2-
import { icons } from "./icon";
2+
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
33

4-
export const anchorIcon = (anchor: string | undefined) => (
4+
export const anchorIcon = (context: DefaultThemeRenderContext, anchor: string | undefined) => (
55
<a href={`#${anchor}`} aria-label="Permalink" class="tsd-anchor-icon">
6-
{icons.anchor()}
6+
{context.icons.anchor()}
77
</a>
88
);

src/lib/output/themes/default/partials/icon.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { ReflectionKind } from "../../../../models";
22
import { JSX } from "../../../../utils";
33

4-
type UtilityIcons = Record<
5-
"chevronDown" | "checkbox" | "menu" | "search" | "chevronSmall" | "anchor",
6-
() => JSX.Element
7-
>;
8-
94
const seenIcons = new Set<unknown>();
105

116
export function clearSeenIconCache() {
@@ -46,7 +41,10 @@ const kindIcon = (kind: ReflectionKind, letterPath: JSX.Element, color: string,
4641
</svg>
4742
);
4843

49-
export const icons: Record<ReflectionKind, () => JSX.Element> & UtilityIcons = {
44+
export const icons: Record<
45+
ReflectionKind | "chevronDown" | "checkbox" | "menu" | "search" | "chevronSmall" | "anchor",
46+
() => JSX.Element
47+
> = {
5048
[ReflectionKind.Accessor]: () =>
5149
kindIcon(
5250
ReflectionKind.Accessor,

src/lib/output/themes/default/partials/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { classNames, wbr } from "../../lib";
22
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
33
import { JSX } from "../../../../utils";
44
import type { ContainerReflection, ReflectionCategory } from "../../../../models";
5-
import { icons } from "./icon";
65

7-
function renderCategory({ urlTo }: DefaultThemeRenderContext, item: ReflectionCategory, prependName = "") {
6+
function renderCategory({ urlTo, icons }: DefaultThemeRenderContext, item: ReflectionCategory, prependName = "") {
87
return (
98
<section class="tsd-index-section">
109
<h3 class="tsd-index-heading">{prependName ? `${prependName} - ${item.title}` : item.title}</h3>
@@ -52,7 +51,7 @@ export function index(context: DefaultThemeRenderContext, props: ContainerReflec
5251
<details class="tsd-index-content tsd-index-accordion" open={true}>
5352
<summary class="tsd-accordion-summary tsd-index-summary">
5453
<h5 class="tsd-index-heading uppercase" role="button" aria-expanded="false" tabIndex={0}>
55-
{icons.chevronSmall()} Index
54+
{context.icons.chevronSmall()} Index
5655
</h5>
5756
</summary>
5857
<div class="tsd-accordion-details">{content}</div>

src/lib/output/themes/default/partials/member.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const member = (context: DefaultThemeRenderContext, props: DeclarationRef
1111
<h3 class="tsd-anchor-link">
1212
{renderFlags(props.flags, props.comment)}
1313
<span class={classNames({ deprecated: props.isDeprecated() })}>{wbr(props.name)}</span>
14-
{anchorIcon(props.anchor)}
14+
{anchorIcon(context, props.anchor)}
1515
</h3>
1616
)}
1717
{props.signatures

src/lib/output/themes/default/partials/navigation.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { JSX, partition } from "../../../../utils";
33
import type { PageEvent } from "../../../events";
44
import { classNames, camelToTitleCase, wbr } from "../../lib";
55
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
6-
import { icons } from "./icon";
76

87
export function navigation(context: DefaultThemeRenderContext, props: PageEvent<Reflection>) {
98
return (
@@ -15,12 +14,12 @@ export function navigation(context: DefaultThemeRenderContext, props: PageEvent<
1514
);
1615
}
1716

18-
function buildFilterItem(name: string, displayName: string, defaultValue: boolean) {
17+
function buildFilterItem(context: DefaultThemeRenderContext, name: string, displayName: string, defaultValue: boolean) {
1918
return (
2019
<li class="tsd-filter-item">
2120
<label class="tsd-filter-input">
2221
<input type="checkbox" id={`tsd-filter-${name}`} name={name} checked={defaultValue} />
23-
{icons.checkbox()}
22+
{context.icons.checkbox()}
2423
<span>{displayName}</span>
2524
</label>
2625
</li>
@@ -40,15 +39,15 @@ function settings(context: DefaultThemeRenderContext) {
4039
.toLowerCase();
4140

4241
visibilityOptions.push(
43-
buildFilterItem(filterName, camelToTitleCase(key.substring(1)), defaultFilters[key])
42+
buildFilterItem(context, filterName, camelToTitleCase(key.substring(1)), defaultFilters[key])
4443
);
4544
} else if (
4645
(key === "protected" && !context.options.getValue("excludeProtected")) ||
4746
(key === "private" && !context.options.getValue("excludePrivate")) ||
4847
(key === "external" && !context.options.getValue("excludeExternals")) ||
4948
key === "inherited"
5049
) {
51-
visibilityOptions.push(buildFilterItem(key, camelToTitleCase(key), defaultFilters[key]));
50+
visibilityOptions.push(buildFilterItem(context, key, camelToTitleCase(key), defaultFilters[key]));
5251
}
5352
}
5453

@@ -58,7 +57,7 @@ function settings(context: DefaultThemeRenderContext) {
5857
<div class="tsd-navigation settings">
5958
<details class="tsd-index-accordion" open={false}>
6059
<summary class="tsd-accordion-summary">
61-
<h3>{icons.chevronDown()} Settings</h3>
60+
<h3>{context.icons.chevronDown()} Settings</h3>
6261
</summary>
6362
<div class="tsd-accordion-details">
6463
{visibilityOptions.length && (
@@ -96,7 +95,7 @@ function primaryNavigation(context: DefaultThemeRenderContext, props: PageEvent<
9695
<nav class="tsd-navigation primary">
9796
<details class="tsd-index-accordion" open={true}>
9897
<summary class="tsd-accordion-summary">
99-
<h3>{icons.chevronDown()} Modules</h3>
98+
<h3>{context.icons.chevronDown()} Modules</h3>
10099
</summary>
101100
<div class="tsd-accordion-details">
102101
<ul>
@@ -153,7 +152,7 @@ function secondaryNavigation(context: DefaultThemeRenderContext, props: PageEven
153152
)}
154153
>
155154
<a href={context.urlTo(child)} class="tsd-index-link">
156-
{icons[child.kind]()}
155+
{context.icons[child.kind]()}
157156
{wbr(child.name)}
158157
</a>
159158
</li>
@@ -181,7 +180,7 @@ function secondaryNavigation(context: DefaultThemeRenderContext, props: PageEven
181180
)}
182181
>
183182
<a href={context.urlTo(effectivePageParent)} class="tsd-index-link">
184-
{icons[effectivePageParent.kind]()}
183+
{context.icons[effectivePageParent.kind]()}
185184
<span>{wbr(effectivePageParent.name)}</span>
186185
</a>
187186
{!!pageNavigation.length && <ul>{pageNavigation}</ul>}

src/lib/output/themes/default/partials/toolbar.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import type { Reflection } from "../../../../models";
22
import { JSX } from "../../../../utils";
33
import type { PageEvent } from "../../../events";
44
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
5-
import { icons } from "./icon";
65

76
export const toolbar = (context: DefaultThemeRenderContext, props: PageEvent<Reflection>) => (
87
<header class="tsd-page-toolbar">
98
<div class="tsd-toolbar-contents container">
109
<div class="table-cell" id="tsd-search" data-base={context.relativeURL("./")}>
1110
<div class="field">
1211
<label for="tsd-search-field" class="tsd-widget search no-caption">
13-
{icons.search()}
12+
{context.icons.search()}
1413
</label>
1514
<input type="text" id="tsd-search-field" aria-label="Search" />
1615
</div>
@@ -27,7 +26,7 @@ export const toolbar = (context: DefaultThemeRenderContext, props: PageEvent<Ref
2726

2827
<div class="table-cell" id="tsd-widgets">
2928
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu" aria-label="Menu">
30-
{icons.menu()}
29+
{context.icons.menu()}
3130
</a>
3231
</div>
3332
</div>

0 commit comments

Comments
 (0)