1
Fork 0
mirror of https://github.com/Steffo99/bluelib.git synced 2024-12-22 11:34:21 +00:00

Add Heading component

This commit is contained in:
Steffo 2021-08-24 04:30:48 +02:00
parent 8b7c57aae6
commit 4cb5cd803e
Signed by: steffo
GPG key ID: 6965406171929D01
2 changed files with 79 additions and 0 deletions

View file

@ -0,0 +1,50 @@
import * as React from "react"
import * as ReactDOM from "react-dom"
import * as Decorators from "../../utils/Decorators"
import { Heading as HeadingComponent } from "./Heading"
export default {
component: HeadingComponent,
title: "Common/Heading",
decorators: [Decorators.Bluelib],
}
const HeadingTemplate = props => (
<HeadingComponent {...props}>
The United Cantons capitulate!
</HeadingComponent>
)
export const HeadingLevel1 = HeadingTemplate.bind({})
HeadingLevel1.args = {
level: 1,
}
export const HeadingLevel2 = HeadingTemplate.bind({})
HeadingLevel2.args = {
level: 2,
}
export const HeadingLevel3 = HeadingTemplate.bind({})
HeadingLevel3.args = {
level: 3,
}
export const HeadingLevel4 = HeadingTemplate.bind({})
HeadingLevel4.args = {
level: 4,
}
export const HeadingLevel5 = HeadingTemplate.bind({})
HeadingLevel5.args = {
level: 5,
}
export const HeadingLevel6 = HeadingTemplate.bind({})
HeadingLevel6.args = {
level: 6,
}

View file

@ -0,0 +1,29 @@
import * as React from "react"
import * as ReactDOM from "react-dom"
import * as Types from "../../types"
import {BaseElement} from "../BaseElement"
import mergeClassNames from "classnames"
export interface HeadingProps extends Types.BluelibHTMLProps<HTMLHeadingElement> {
level: 1 | 2 | 3 | 4 | 5 | 6,
}
const HEADING_KINDS_BY_LEVEL = {
1: "h1",
2: "h2",
3: "h3",
4: "h4",
5: "h5",
6: "h6",
}
export function Heading({level, ...props}: HeadingProps): JSX.Element {
props.bluelibClassNames = mergeClassNames(props.bluelibClassNames, "heading")
return (
<BaseElement kind={HEADING_KINDS_BY_LEVEL[level]} {...props}/>
)
}