Skip to content

Commit

Permalink
expose html global jsx attributes to enable extending them for custom…
Browse files Browse the repository at this point in the history
… elements or api holes

document how to extend jsx attributes and elements

add popover attribute to global jsx attribute interface

fix lint
  • Loading branch information
SacDeNoeuds authored and Gerrit0 committed Dec 12, 2024
1 parent 288856c commit 993c0f5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
48 changes: 48 additions & 0 deletions site/development/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,51 @@ export function load(app: Application) {
```

[RendererHooks]: https://typedoc.org/api/interfaces/RendererHooks.html

## Registering your own custom elements/attributes

Start by writing a `jsx.d.ts` file somewhere.

````ts
// src/jsx.d.ts
import { JSX as TypeDocJSX } from "typedoc";

declare module "typedoc" {
namespace JSX {
namespace JSX {
interface IntrinsicAttributes {
popover?: boolean;
popovertarget?: string;
popovertargetaction?: "hide" | "show" | "toggle";
}
interface IntrinsicElements {
// add your custom elements here, ie:
/**
* @example
* ```tsx
* <drop-down trigger="#my-trigger" class="header-menu">
* <button>Option #1</button>
* <button>Option #2</button>
* </drop-down>
* ```
*/
"drop-down": IntrinsicAttributes & {
/**
* A query selector, ie: '#my-trigger'
*/
trigger: string;
};
}
}
}
}
````

Then in your plugin entry point, reference the `jsx.d.ts` file with a triple-slash directive.

```ts
// src/index.ts
/// <reference types="./jsx.d.ts" />

export function load(app: Application) { … }
```
13 changes: 13 additions & 0 deletions src/lib/utils/jsx.elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ export interface JsxHtmlGlobalProps {
tabIndex?: number;
title?: string;
translate?: boolean;

// popover attributes
/**
* Default: 'auto'. true and 'auto' are equivalent
*
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API) for more details
*/
popover?: boolean | "auto" | "manual";
/**
* It must be the popover element id, see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API)
*/
popovertarget?: string;
popovertargetaction?: "hide" | "show" | "toggle";
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/lib/utils/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
JsxElement,
JsxChildren,
JsxComponent,
JsxHtmlGlobalProps,
} from "./jsx.elements.js";
import { JsxFragment } from "./jsx.elements.js";

Expand Down Expand Up @@ -50,7 +51,11 @@ export function Raw(_props: { html: string }) {
* @hidden
*/
export declare namespace JSX {
export { IntrinsicElements, JsxElement as Element };
export {
IntrinsicElements,
JsxElement as Element,
JsxHtmlGlobalProps as IntrinsicAttributes,
};
}

const voidElements = new Set([
Expand Down

0 comments on commit 993c0f5

Please sign in to comment.