30 lines
995 B
TypeScript
30 lines
995 B
TypeScript
import { Show } from "solid-js"
|
|
import { useTheme } from "../context/theme"
|
|
import { useConfig } from "../config"
|
|
import type { JSX } from "@opentui/solid"
|
|
import type { RGBA } from "@opentui/core"
|
|
import { registerOpencodeSpinner } from "./register-spinner"
|
|
|
|
registerOpencodeSpinner()
|
|
|
|
export const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
|
|
|
|
export function Spinner(props: { children?: JSX.Element; color?: RGBA }) {
|
|
const { theme } = useTheme()
|
|
const config = useConfig().data
|
|
const color = () => props.color ?? theme.textMuted
|
|
return (
|
|
<Show
|
|
when={config.animations ?? true}
|
|
fallback={<text fg={color()}>{props.children ? <>⋯ {props.children}</> : "⋯"}</text>}
|
|
>
|
|
<box flexDirection="row" gap={1}>
|
|
<spinner frames={SPINNER_FRAMES} interval={80} color={color()} />
|
|
<Show when={props.children}>
|
|
<text fg={color()}>{props.children}</text>
|
|
</Show>
|
|
</box>
|
|
</Show>
|
|
)
|
|
}
|