Skip to content

Commit

Permalink
Add support for collapsing groups+categories
Browse files Browse the repository at this point in the history
Resolves #2330
  • Loading branch information
Gerrit0 committed Jun 9, 2024
1 parent 9f78397 commit 1482eb5
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
- New option, `--customFooterHtml` to add custom HTML to the generated page footer, #2559.
- TypeDoc will now copy modifier tags to children if specified in the `--cascadedModifierTags` option, #2056.
- TypeDoc will now warn if mutually exclusive modifier tags are specified for a comment (e.g. both `@alpha` and `@beta`), #2056.
- Groups and categories can now be collapsed in the page body, #2330.
- Added support for JSDoc `@hideconstructor` tag.
This tag should only be used to work around TypeScript#58653, prefer the more general `@hidden`/`@ignore` tag to hide members normally, #2577.
- Added `--useHostedBaseUrlForAbsoluteLinks` option to use the `--hostedBaseUrl` option to produce absolute links to pages on a site, #940.
Expand Down
2 changes: 2 additions & 0 deletions src/lib/models/reflections/kind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export enum ReflectionKind {
export namespace ReflectionKind {
export type KindString = EnumKeys<typeof ReflectionKind>;

/** @internal */
export const All = ReflectionKind.Reference * 2 - 1;

/** @internal */
Expand Down Expand Up @@ -89,6 +90,7 @@ export namespace ReflectionKind {
ReflectionKind.Interface |
ReflectionKind.TypeAlias |
ReflectionKind.Reference;
/** @internal */
export const MayContainDocuments =
SomeExport | ReflectionKind.Project | ReflectionKind.Document;
/** @internal */
Expand Down
2 changes: 1 addition & 1 deletion src/lib/output/themes/default/assets/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { initTheme } from "./typedoc/Theme";
import { initNav } from "./typedoc/Navigation";

registerComponent(Toggle, "a[data-toggle]");
registerComponent(Accordion, ".tsd-index-accordion");
registerComponent(Accordion, ".tsd-accordion");
registerComponent(Filter, ".tsd-filter-item input[type=checkbox]");

const themeChoice = document.getElementById("tsd-theme");
Expand Down
4 changes: 2 additions & 2 deletions src/lib/output/themes/default/assets/typedoc/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ function buildNavElement(
const fullPath = [...path, el.text];
const details = li.appendChild(document.createElement("details"));
details.className = el.class
? `${el.class} tsd-index-accordion`
: "tsd-index-accordion";
? `${el.class} tsd-accordion`
: "tsd-accordion";
details.dataset.key = fullPath.join("$");

const summary = details.appendChild(document.createElement("summary"));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/output/themes/default/partials/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function index(context: DefaultThemeRenderContext, props: ContainerReflec
)
) {
content = (
<details class="tsd-index-content tsd-index-accordion" open={true}>
<details class="tsd-index-content tsd-accordion" open={true}>
<summary class="tsd-accordion-summary tsd-index-summary">
<h5 class="tsd-index-heading uppercase" role="button" aria-expanded="false" tabIndex={0}>
{context.icons.chevronSmall()} {context.i18n.theme_index()}
Expand Down
37 changes: 24 additions & 13 deletions src/lib/output/themes/default/partials/members.group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,34 @@ export function membersGroup(context: DefaultThemeRenderContext, group: Reflecti
if (group.categories) {
return (
<>
{group.categories.map((item) => (
<section class="tsd-panel-group tsd-member-group">
<h2>
{group.title}
{!!item.title && <> - {item.title}</>}
</h2>
{item.children.map((item) => !item.hasOwnDocument && context.member(item))}
</section>
))}
{group.categories.map((item) => {
const title = `${group.title} - ${item.title}`;

return (
<details class="tsd-panel-group tsd-member-group tsd-accordion" open>
<summary class="tsd-accordion-summary" data-key={"section-" + title}>
<h2>
{context.icons.chevronDown()} {title}
</h2>
</summary>
<section>
{item.children.map((item) => !item.hasOwnDocument && context.member(item))}
</section>
</details>
);
})}
</>
);
}

return (
<section class="tsd-panel-group tsd-member-group">
<h2>{group.title}</h2>
{group.children.map((item) => !item.hasOwnDocument && context.member(item))}
</section>
<details class="tsd-panel-group tsd-member-group tsd-accordion" open>
<summary class="tsd-accordion-summary" data-key={"section-" + group.title}>
<h2>
{context.icons.chevronDown()} {group.title}
</h2>
</summary>
<section>{group.children.map((item) => !item.hasOwnDocument && context.member(item))}</section>
</details>
);
}
16 changes: 11 additions & 5 deletions src/lib/output/themes/default/partials/members.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ export function members(context: DefaultThemeRenderContext, props: ContainerRefl
{props.categories.map(
(item) =>
!item.allChildrenHaveOwnDocument() && (
<section
<details
class={classNames(
{ "tsd-panel-group": true, "tsd-member-group": true },
{ "tsd-panel-group": true, "tsd-member-group": true, "tsd-accordion": true },
props instanceof DeclarationReflection ? context.getReflectionClasses(props) : "",
)}
>
<h2>{item.title}</h2>
{item.children.map((item) => !item.hasOwnDocument && context.member(item))}
</section>
<summary class="tsd-accordion-summary" data-key={"section-" + item.title}>
<h2>
{context.icons.chevronDown()} {item.title}
</h2>
</summary>
<section>
{item.children.map((item) => !item.hasOwnDocument && context.member(item))}
</section>
</details>
),
)}
</>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/output/themes/default/partials/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function settings(context: DefaultThemeRenderContext) {

return (
<div class="tsd-navigation settings">
<details class="tsd-index-accordion" open={false}>
<details class="tsd-accordion" open={false}>
<summary class="tsd-accordion-summary">
<h3>
{context.icons.chevronDown()}
Expand Down Expand Up @@ -176,7 +176,7 @@ export function pageNavigation(context: DefaultThemeRenderContext, props: PageEv
finalizeLevel(true);

return (
<details open={true} class="tsd-index-accordion tsd-page-navigation">
<details open={true} class="tsd-accordion tsd-page-navigation">
<summary class="tsd-accordion-summary">
<h3>
{context.icons.chevronDown()}
Expand Down
7 changes: 5 additions & 2 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ a.tsd-index-link {
padding-top: 0;
padding-bottom: 0;
}
.tsd-index-accordion .tsd-accordion-summary > svg {
.tsd-accordion .tsd-accordion-summary > svg {
margin-left: 0.25rem;
}
.tsd-index-content > :not(:first-child) {
Expand Down Expand Up @@ -888,14 +888,17 @@ a.tsd-index-link {
}

.tsd-panel-group {
margin: 4rem 0;
margin: 2rem 0;
}
.tsd-panel-group.tsd-index-group {
margin: 2rem 0;
}
.tsd-panel-group.tsd-index-group details {
margin: 2rem 0;
}
.tsd-panel-group > .tsd-accordion-summary {
margin-bottom: 1rem;
}

#tsd-search {
transition: background-color 0.2s;
Expand Down

0 comments on commit 1482eb5

Please sign in to comment.