--- name: opentui-solid description: Expert assistance for OpenTUI with SolidJS. Use for reactive components, signals, fine-grained reactivity, JSX patterns, and SolidJS-specific optimization. --- # OpenTUI SolidJS Integration Expert assistance for building terminal UIs with OpenTUI and SolidJS. ## Quick Start ```bash # Install dependencies bun install @opentui/core @opentui/solid solid-js ``` ## Basic Setup ```tsx import { createCliRenderer } from "@opentui/core" import { createRoot } from "@opentui/solid" function App() { return Hello, OpenTUI SolidJS! } async function main() { const renderer = await createCliRenderer() createRoot(renderer).render(() => ) } main() ``` ## SolidJS Reactivity ### Signals (Core Primitive) Signals are the core of SolidJS reactivity: ```tsx import { createSignal } from "solid-js" function Counter() { const [count, setCount] = createSignal(0) return ( Count: {count()} ) } ``` **Key Concepts:** - `count()` - Access signal value (getter) - `setCount(newValue)` - Update signal value (setter) - Signals automatically track dependencies ### Derived Signals (Memo) ```tsx import { createMemo } from "solid-js" function DoubleCounter() { const [count, setCount] = createSignal(0) const doubleCount = createMemo(() => count() * 2) return ( Count: {count()} Double: {doubleCount()} ) } ``` ### Effects (createEffect) ```tsx import { createEffect } from "solid-js" function Logger() { const [count, setCount] = createSignal(0) createEffect(() => { console.log("Count changed:", count()) }) return Count: {count()} } ``` ## OpenTUI SolidJS Hooks ### useKeyboard ```tsx import { useKeyboard } from "@opentui/solid" function App() { useKeyboard((key) => { if (key.name === "c" && key.ctrl) { process.exit(0) } }) return Press Ctrl+C to exit } ``` ### useRenderer ```tsx import { useRenderer } from "@opentui/solid" function Component() { const renderer = useRenderer() const exit = () => { renderer.destroy() process.exit(0) } return Exit } ``` ### useTerminalDimensions ```tsx import { useTerminalDimensions } from "@opentui/solid" function Responsive() { const dimensions = useTerminalDimensions() return ( Size: {dimensions().width}x{dimensions().height} ) } ``` ### useTimeline ```tsx import { useTimeline } from "@opentui/solid" import { onMount } from "solid-js" function AnimatedBox() { let boxRef: any const timeline = useTimeline({ duration: 1000, easing: (t) => t, }) onMount(() => { timeline.to(boxRef, { backgroundColor: { r: 255, g: 0, b: 0 }, }) timeline.play() }) return ( Animated ) } ``` ## SolidJS Components ### All OpenTUI components available as JSX: ```tsx import { text, box, input, select, scrollbox, code, } from "@opentui/solid" function Form() { const [name, setName] = createSignal("") return ( User Information setName(e.value)} placeholder="Name" /> Submit ) } ``` ## Styling in SolidJS Styles are passed as props: ```tsx function StyledComponent() { return ( Styled Text ) } ``` **Color format:** `{ r: number, g: number, b: number, a?: number }` ## State Management ### Local Signals ```tsx function Counter() { const [count, setCount] = createSignal(0) const [step, setStep] = createSignal(1) const increment = () => setCount(c => c + step()) const decrement = () => setCount(c => c - step()) useKeyboard((key) => { if (key.name === "up") increment() if (key.name === "down") decrement() }) return ( Count: {count()} setStep(parseInt(e.value) || 1)} /> Use arrow keys ) } ``` ### Stores (Objects) ```tsx import { createStore, produce } from "solid-js/store" function Form() { const [formData, setFormData] = createStore({ name: "", email: "", password: "", }) const updateField = (field: string) => (value: string) => { setFormData(field, value) } return ( updateField("name")(e.value)} placeholder="Name" /> updateField("email")(e.value)} placeholder="Email" /> updateField("password")(e.value)} placeholder="Password" password /> ) } ``` ### Context ```tsx import { createContext, useContext } from "solid-js" const ThemeContext = createContext({ theme: "dark", setTheme: (theme: string) => {}, }) function ThemeProvider(props: any) { const [theme, setTheme] = createSignal("dark") return ( {props.children} ) } function ThemedComponent() { const { theme } = useContext(ThemeContext) return ( Current theme: {theme()} ) } ``` ## Common Patterns ### List with Selection ```tsx function SelectList(props: { items: string[] }) { const [selectedIndex, setSelectedIndex] = createSignal(0) useKeyboard((key) => { const len = props.items.length if (key.name === "down" || (key.name === "tab" && !key.shift)) { setSelectedIndex(i => Math.min(i + 1, len - 1)) } if (key.name === "up" || (key.name === "tab" && key.shift)) { setSelectedIndex(i => Math.max(i - 1, 0)) } }) return ( {(item, index) => ( {index() === selectedIndex() ? "> " : " "}{item} )} ) } ``` ### Show/Hide (Conditional Rendering) ```tsx function Modal(props: { isOpen: boolean, onClose: () => void }) { return ( Modal Content ) } ``` ### Switch (Multiple Conditions) ```tsx function StatusIndicator(props: { status: "loading" | "success" | "error" }) { return ( Unknown status}> Loading... Success! Error! ) } ``` ### Dynamic Components ```tsx function DynamicTab(props: { component: () => any }) { return ( ) } ``` ## When to Use This Skill Use `/opentui-solid` for: - Building TUIs with SolidJS - Using signals and fine-grained reactivity - JSX-style component development - High-performance reactive UIs - SolidJS-specific patterns For vanilla TypeScript/JavaScript, use `/opentui` For React development, use `/opentui-react` For project scaffolding, use `/opentui-projects` ## Key SolidJS Differences from React | Feature | React | SolidJS | |---------|-------|---------| | State | `useState` | `createSignal` | | Effects | `useEffect` | `createEffect` | | Memos | `useMemo` | `createMemo` | | Refs | `useRef` | Direct variable assignment | | Lists | `.map()` | `` component | | Conditionals | `&&`, `? :` | ``, `` | | Context | `useContext` | `useContext` (same API) | ## Resources - [Signals & Reactivity](references/SIGNALS.md) - Deep dive on signals - [Components](references/COMPONENTS.md) - SolidJS component patterns - [Performance](references/PERFORMANCE.md) - Optimization techniques - [Integration](references/INTEGRATION.md) - SolidJS with OpenTUI ## Key Knowledge Sources - OpenTUI SolidJS GitHub: https://github.com/sst/opentui/tree/main/packages/solid - SolidJS Docs: https://www.solidjs.com/docs - Context7: `/sst/opentui` - SolidJS integration queries - Research: `.search-data/research/opentui/`