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

Implement buttons

This commit is contained in:
Steffo 2021-03-23 16:58:35 +01:00
parent 09034bb4a0
commit b226389e5d
Signed by: steffo
GPG key ID: 6965406171929D01
5 changed files with 99 additions and 2 deletions

View file

@ -0,0 +1,26 @@
A clickable button that should trigger an action on click.
```jsx
import Bluelib from "../Bluelib";
import Color from "../Color";
<Bluelib>
<p>
<Button onClick={event => console.debug(event)}>
Click here
</Button>
</p>
<p>
<Color builtin="blue">
<Button onClick={event => console.debug(event)}>
such blue wow
</Button>
</Color>
</p>
<p>
<Button disabled={true}>
Disabled
</Button>
</p>
</Bluelib>
```

View file

@ -0,0 +1,12 @@
import React from "react"
import useBluelibClassNames from "../../hooks/useBluelibClassNames"
import classNames from "classnames"
export default function Button({children, className, disabled, ...props}) {
return (
<button className={useBluelibClassNames(classNames("button", disabled ? "status-disabled" : "status-clickable"), className)} {...props}>
{children}
</button>
)
}

View file

@ -0,0 +1,38 @@
A clickable button that should trigger an action on click.
```jsx
import Bluelib from "../Bluelib";
import Color from "../Color";
<Bluelib>
<p>
<ButtonToggle value={true}>
On
</ButtonToggle>
&nbsp;
<ButtonToggle value={false}>
Off
</ButtonToggle>
</p>
<p>
<Color builtin="magenta">
<ButtonToggle value={true}>
On
</ButtonToggle>
&nbsp;
<ButtonToggle value={false}>
Off
</ButtonToggle>
</Color>
</p>
<p>
<ButtonToggle disabled={true} value={true}>
On
</ButtonToggle>
&nbsp;
<ButtonToggle disabled={true} value={false}>
Off
</ButtonToggle>
</p>
</Bluelib>
```

View file

@ -0,0 +1,23 @@
import React from "react"
import useBluelibClassNames from "../../hooks/useBluelibClassNames"
import classNames from "classnames"
import Button from "../Button"
export default function ButtonToggle({children, className, disabled, value, ...props}) {
return (
<Button
className={useBluelibClassNames(
classNames(
"button",
"button-toggle",
value ? "button-toggle-on" : "button-toggle-off",
disabled ? "status-disabled" : "status-clickable",
), className
)}
{...props}
>
{children}
</Button>
)
}

View file

@ -24,8 +24,6 @@ export default function Color({children, builtin, custom}) {
extraStyle["--bluelib-color-b"] = c.blue()
}
console.log(`Builtin: ${builtin}${extraClassName}\nCustom: ${custom}${JSON.stringify(extraStyle)}`)
children = React.Children.map(children, child => {
if(!child.props) {
return child;