mirror of
https://github.com/Steffo99/bluelib.git
synced 2024-12-22 11:34:21 +00:00
✨ Add support for Keyboard
element
This commit is contained in:
parent
87aa38b542
commit
a66bc5a420
2 changed files with 82 additions and 0 deletions
57
src/components/semantics/Keyboard.stories.jsx
Normal file
57
src/components/semantics/Keyboard.stories.jsx
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
import * as React from "react"
|
||||||
|
import * as ReactDOM from "react-dom"
|
||||||
|
import * as Decorators from "../../utils/Decorators"
|
||||||
|
import { Keyboard as KeyboardComponent } from "./Keyboard"
|
||||||
|
|
||||||
|
|
||||||
|
export default {
|
||||||
|
component: KeyboardComponent,
|
||||||
|
title: "Semantics/Keyboard",
|
||||||
|
decorators: [Decorators.Bluelib],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const Simple = props => (
|
||||||
|
<KeyboardComponent {...props}>Ctrl</KeyboardComponent>
|
||||||
|
)
|
||||||
|
Simple.args = {
|
||||||
|
builtinColor: "red",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const Pressed = props => (
|
||||||
|
<KeyboardComponent {...props}>↓ Ctrl</KeyboardComponent>
|
||||||
|
)
|
||||||
|
Pressed.args = {
|
||||||
|
builtinColor: "red",
|
||||||
|
press: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const Released = props => (
|
||||||
|
<KeyboardComponent {...props}>↑ Ctrl</KeyboardComponent>
|
||||||
|
)
|
||||||
|
Released.args = {
|
||||||
|
builtinColor: "red",
|
||||||
|
release: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const Combination = props => (
|
||||||
|
<KeyboardComponent {...props}>
|
||||||
|
<KeyboardComponent>
|
||||||
|
Ctrl
|
||||||
|
</KeyboardComponent>
|
||||||
|
+
|
||||||
|
<KeyboardComponent>
|
||||||
|
Alt
|
||||||
|
</KeyboardComponent>
|
||||||
|
+
|
||||||
|
<KeyboardComponent>
|
||||||
|
Del
|
||||||
|
</KeyboardComponent>
|
||||||
|
</KeyboardComponent>
|
||||||
|
)
|
||||||
|
Combination.args = {
|
||||||
|
builtinColor: "red",
|
||||||
|
}
|
25
src/components/semantics/Keyboard.tsx
Normal file
25
src/components/semantics/Keyboard.tsx
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
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 KeyboardProps extends Types.BluelibHTMLProps<HTMLPreElement> {
|
||||||
|
press?: boolean,
|
||||||
|
release?: boolean,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function Keyboard({press = false, release = false, ...props}: KeyboardProps): JSX.Element {
|
||||||
|
props.bluelibClassNames = mergeClassNames(
|
||||||
|
props.bluelibClassNames,
|
||||||
|
"semantic-kbd",
|
||||||
|
press && !release ? "semantic-kbd-press" : null,
|
||||||
|
release && !press ? "semantic-kbd-release" : null,
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BaseElement kind={"kbd"} {...props}/>
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in a new issue