UNPKG

2.47 kBTypeScriptView Raw
1/*
2 * Copyright 2018 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import classNames from "classnames";
18import * as React from "react";
19
20import { IElementRefProps } from "../../common";
21import { BLOCKQUOTE, CODE, CODE_BLOCK, HEADING, LABEL, LIST } from "../../common/classes";
22
23function htmlElement<E extends HTMLElement>(
24 tagName: keyof JSX.IntrinsicElements,
25 tagClassName: string,
26 // eslint-disable-next-line deprecation/deprecation
27): React.FunctionComponent<React.HTMLProps<E> & IElementRefProps<E>> {
28 /* eslint-disable-next-line react/display-name */
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// the following components are linted by blueprint-html-components because
40// they should rarely be used without the Blueprint classes/styles:
41
42export const H1 = htmlElement<HTMLHeadingElement>("h1", HEADING);
43export const H2 = htmlElement<HTMLHeadingElement>("h2", HEADING);
44export const H3 = htmlElement<HTMLHeadingElement>("h3", HEADING);
45export const H4 = htmlElement<HTMLHeadingElement>("h4", HEADING);
46export const H5 = htmlElement<HTMLHeadingElement>("h5", HEADING);
47export const H6 = htmlElement<HTMLHeadingElement>("h6", HEADING);
48
49export const Blockquote = htmlElement<HTMLElement>("blockquote", BLOCKQUOTE);
50export const Code = htmlElement<HTMLElement>("code", CODE);
51export const Pre = htmlElement<HTMLElement>("pre", CODE_BLOCK);
52export const Label = htmlElement<HTMLLabelElement>("label", LABEL);
53
54// these two are not linted by blueprint-html-components because there are valid
55// uses of these elements without Blueprint styles:
56export const OL = htmlElement<HTMLOListElement>("ol", LIST);
57export const UL = htmlElement<HTMLUListElement>("ul", LIST);