mirror of
https://github.com/Steffo99/bluelib.git
synced 2024-12-22 19:44:21 +00:00
✨ Implement buttons
This commit is contained in:
parent
09034bb4a0
commit
b226389e5d
5 changed files with 99 additions and 2 deletions
26
src/components/Button/Readme.md
Normal file
26
src/components/Button/Readme.md
Normal 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>
|
||||||
|
```
|
12
src/components/Button/index.js
Normal file
12
src/components/Button/index.js
Normal 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>
|
||||||
|
)
|
||||||
|
}
|
38
src/components/ButtonToggle/Readme.md
Normal file
38
src/components/ButtonToggle/Readme.md
Normal 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>
|
||||||
|
|
||||||
|
<ButtonToggle value={false}>
|
||||||
|
Off
|
||||||
|
</ButtonToggle>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<Color builtin="magenta">
|
||||||
|
<ButtonToggle value={true}>
|
||||||
|
On
|
||||||
|
</ButtonToggle>
|
||||||
|
|
||||||
|
<ButtonToggle value={false}>
|
||||||
|
Off
|
||||||
|
</ButtonToggle>
|
||||||
|
</Color>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<ButtonToggle disabled={true} value={true}>
|
||||||
|
On
|
||||||
|
</ButtonToggle>
|
||||||
|
|
||||||
|
<ButtonToggle disabled={true} value={false}>
|
||||||
|
Off
|
||||||
|
</ButtonToggle>
|
||||||
|
</p>
|
||||||
|
</Bluelib>
|
||||||
|
```
|
23
src/components/ButtonToggle/index.js
Normal file
23
src/components/ButtonToggle/index.js
Normal 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>
|
||||||
|
)
|
||||||
|
}
|
|
@ -24,8 +24,6 @@ export default function Color({children, builtin, custom}) {
|
||||||
extraStyle["--bluelib-color-b"] = c.blue()
|
extraStyle["--bluelib-color-b"] = c.blue()
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Builtin: ${builtin} → ${extraClassName}\nCustom: ${custom} → ${JSON.stringify(extraStyle)}`)
|
|
||||||
|
|
||||||
children = React.Children.map(children, child => {
|
children = React.Children.map(children, child => {
|
||||||
if(!child.props) {
|
if(!child.props) {
|
||||||
return child;
|
return child;
|
||||||
|
|
Loading…
Reference in a new issue