diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2025-04-28 18:03:28 +0200 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2025-04-28 18:03:28 +0200 |
| commit | 0539d6963ebedd554cd3cd36b6c94df9659d6a6b (patch) | |
| tree | 9408c7928d0725b114d0adfa811ba2bb3859f495 /src/components/Button.tsx | |
| download | rustberry-frontend-master.tar.gz rustberry-frontend-master.tar.zst rustberry-frontend-master.zip | |
Simple frontend version with mock API
Diffstat (limited to 'src/components/Button.tsx')
| -rw-r--r-- | src/components/Button.tsx | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/components/Button.tsx b/src/components/Button.tsx new file mode 100644 index 0000000..031fc73 --- /dev/null +++ b/src/components/Button.tsx @@ -0,0 +1,57 @@ +import styles from "./Button.module.css"; +import { createEffect, createSignal } from "solid-js"; + +enum BtnType { + click = 0, + switch = 1, +} +export type Button = + | { + type: BtnType.click; + name: string; + color?: string; + } + | { + type: BtnType.switch; + name: string; + }; + +export default function Button(props: Button) { + const [value, setValue] = createSignal(false); + const [bgColor, setBgColor] = createSignal<string>(); + + createEffect(() => { + if (props.type === BtnType.click) { + setBgColor(value() ? "pink" : "blue"); + } else { + setBgColor(value() ? "green" : "red"); + } + }); + + function onClick() { + if (props.type === BtnType.click) { + if (value() === true) { + return; + } + setValue(true); + setTimeout(() => { + setValue(false); + }, 3000); + } else { + setValue((old) => !old); + } + } + + return ( + <button + on:click={onClick} + class={styles.btn} + style={{ "background-color": bgColor() }} + > + { + //btnText() + } + {props.name} + </button> + ); +} |
