mirror of
https://github.com/anotherhadi/ilovetui.git
synced 2026-10-05 19:08:25 +02:00
rewrite bubbletea -> opentui
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { type ColorInput, TextAttributes } from "@opentui/core";
|
||||
import { Show } from "solid-js";
|
||||
import { theme } from "../index.ts";
|
||||
import { Badge } from "./Badge.tsx";
|
||||
|
||||
export interface ToggleProps {
|
||||
on: boolean;
|
||||
onToggle?: () => void;
|
||||
onColor?: ColorInput;
|
||||
offColor?: ColorInput;
|
||||
withNerdfont?: boolean;
|
||||
}
|
||||
|
||||
export function Toggle(props: ToggleProps) {
|
||||
const onColor = () => props.onColor ?? theme.success;
|
||||
const offColor = () => props.offColor ?? theme.muted;
|
||||
const nerdFonts = () => props.withNerdfont ?? theme.nerdFonts;
|
||||
|
||||
return (
|
||||
<box onMouseDown={theme.mouse ? props.onToggle : undefined}>
|
||||
<Show
|
||||
when={nerdFonts()}
|
||||
fallback={
|
||||
<text fg={props.on ? onColor() : offColor()} attributes={TextAttributes.BOLD}>
|
||||
{props.on ? "on" : "off"}
|
||||
</text>
|
||||
}
|
||||
>
|
||||
<Badge label={props.on ? " ●" : "● "} color={props.on ? onColor() : offColor()} withNerdfont />
|
||||
</Show>
|
||||
</box>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user