/** @jsxImportSource solid-js */ import { useStore } from "@nanostores/solid"; import { createSignal, type JSX } from "solid-js"; import AstroLogo from "../../images/astro.png?url"; import OutSystemsLogo from "../../images/outsystems.png?url"; import { Operation, setCounterCount } from "../../lib/setCounterCount"; import { setupStore } from "../../stores/demo"; interface DemoProps { children?: JSX.Element; header?: JSX.Element; initialCount: number; showMessage: string; } export default function Demo(props: DemoProps) { const [count, setCount] = createSignal(props.initialCount); const store = setupStore("solidStore"); const nanoStoreValue = useStore(store); const add = () => setCount((i) => setCounterCount(i, Operation.Add)); const subtract = () => setCount((i) => setCounterCount(i, Operation.Subtract)); const showParentMessage = () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const messageFunc = (window as any)[props.showMessage]; if (typeof messageFunc === "function") { messageFunc(count()); } }; return ( <> {props.header}
Solid counter component
Internal counter controls. It keeps state within the component.
{count()}
The button sends the current count value to a function in the parent component.
Nano Stores
Value:
{nanoStoreValue()}
Slot content
{props.children}
OutSystems logo Astro logo
); }