1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-28 09:20:52 +01:00

Fixed element typings

This commit is contained in:
squidfunk 2019-12-19 09:48:16 +01:00
parent 63c8544371
commit 6b1ff5ef1d
4 changed files with 24 additions and 13 deletions

View File

@ -83,7 +83,7 @@ function appendChild(el: Element, child: Child): void {
export function h(
tag: string, attributes: Attributes | null,
...children: Array<Element | Text | string | number>
) {
): Element {
const el = document.createElement(tag)
/* Set attributes, if any */
@ -102,6 +102,17 @@ export function h(
return el
}
/**
* JSX factory wrapper
*
* @param el - JSX element
*
* @return Element
*/
export function toElement(el: JSXInternal.Element): Element {
return el as any // Hack: if you have a better idea, PR!
}
/* ----------------------------------------------------------------------------
* Namespace
* ------------------------------------------------------------------------- */

View File

@ -20,7 +20,7 @@
* IN THE SOFTWARE.
*/
import { h } from "extensions"
import { h, toElement } from "extensions"
import { SearchResult } from "modules"
import { renderArticleDocument } from "../article"
@ -46,12 +46,12 @@ const css = {
*
* @param article - Search result
*
* @return JSX element
* @return Element
*/
export function renderSearchResult(
{ article, sections }: SearchResult
) {
return (
): Element {
return toElement(
<li class={css.item}>
{renderArticleDocument(article)}
{...sections.map(renderSectionDocument)}

View File

@ -20,7 +20,7 @@
* IN THE SOFTWARE.
*/
import { h } from "extensions"
import { h, toElement } from "extensions"
import { ArticleDocument } from "modules"
import { truncate } from "utilities"
@ -47,12 +47,12 @@ const css = {
*
* @param article - Article document
*
* @return JSX element
* @return Element
*/
export function renderArticleDocument(
{ location, title, text }: ArticleDocument
) {
return (
): Element {
return toElement(
<a href={location} title={title} class={css.link} tabIndex={-1}>
<article class={css.article}>
<h1 class={css.title}>{title}</h1>

View File

@ -20,7 +20,7 @@
* IN THE SOFTWARE.
*/
import { h } from "extensions"
import { h, toElement } from "extensions"
import { SectionDocument } from "modules"
import { truncate } from "utilities"
@ -47,12 +47,12 @@ const css = {
*
* @param section - Section document
*
* @return JSX element
* @return Element
*/
export function renderSectionDocument(
{ location, title, text }: SectionDocument
) {
return (
): Element {
return toElement(
<a href={location} title={title} class={css.link} tabIndex={-1}>
<article class={css.article}>
<h1 class={css.title}>{title}</h1>