1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import classNames from "classnames";
|
18 | import * as React from "react";
|
19 |
|
20 | import { IElementRefProps } from "../../common";
|
21 | import { BLOCKQUOTE, CODE, CODE_BLOCK, HEADING, LABEL, LIST } from "../../common/classes";
|
22 |
|
23 | function htmlElement<E extends HTMLElement>(
|
24 | tagName: keyof JSX.IntrinsicElements,
|
25 | tagClassName: string,
|
26 |
|
27 | ): React.FunctionComponent<React.HTMLProps<E> & IElementRefProps<E>> {
|
28 |
|
29 | return props => {
|
30 | const { className, elementRef, ...htmlProps } = props;
|
31 | return React.createElement(tagName, {
|
32 | ...htmlProps,
|
33 | className: classNames(tagClassName, className),
|
34 | ref: elementRef,
|
35 | });
|
36 | };
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export const H1 = htmlElement<HTMLHeadingElement>("h1", HEADING);
|
43 | export const H2 = htmlElement<HTMLHeadingElement>("h2", HEADING);
|
44 | export const H3 = htmlElement<HTMLHeadingElement>("h3", HEADING);
|
45 | export const H4 = htmlElement<HTMLHeadingElement>("h4", HEADING);
|
46 | export const H5 = htmlElement<HTMLHeadingElement>("h5", HEADING);
|
47 | export const H6 = htmlElement<HTMLHeadingElement>("h6", HEADING);
|
48 |
|
49 | export const Blockquote = htmlElement<HTMLElement>("blockquote", BLOCKQUOTE);
|
50 | export const Code = htmlElement<HTMLElement>("code", CODE);
|
51 | export const Pre = htmlElement<HTMLElement>("pre", CODE_BLOCK);
|
52 | export const Label = htmlElement<HTMLLabelElement>("label", LABEL);
|
53 |
|
54 |
|
55 |
|
56 | export const OL = htmlElement<HTMLOListElement>("ol", LIST);
|
57 | export const UL = htmlElement<HTMLUListElement>("ul", LIST);
|