From 13b6c88dd090bfc8997a2916f0c0cc44bdce2c74 Mon Sep 17 00:00:00 2001 From: Aylur Date: Sat, 7 Sep 2024 13:00:42 +0000 Subject: docs: touchups * code block langs * ags faq * fix broken links --- docs/ags/widget.md | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) (limited to 'docs/ags/widget.md') diff --git a/docs/ags/widget.md b/docs/ags/widget.md index 122fa3e..be2243e 100644 --- a/docs/ags/widget.md +++ b/docs/ags/widget.md @@ -123,14 +123,12 @@ function MyWidget() { return { console.log(self.rgba) }} @@ -143,3 +141,42 @@ Signal properties have to be annotated manually for TypeScript. You can reference [Gtk3](https://gjs-docs.gnome.org/gtk30~3.0/) and [Astal](https://aylur.github.io/libastal/index.html#classes) for available signals. ::: + +## TypeScript + +Type of widgets are available through `Widget`. +Here is an example Widget that takes in and handles a possibly `Binding` prop. + +```tsx +import { Binding, Variable, Widget } from "astal" + +export interface ToggleButtonProps extends Widget.ButtonProps { + onToggled?: (self: Widget.Button, on: boolean) => void + state?: Binding | boolean + child?: JSX.Element +} + +export default function ToggleButton(btnprops: ToggleButtonProps) { + const { state = false, onToggled, setup, child, ...props } = btnprops + const innerState = Variable(state instanceof Binding ? state.get() : state) + + return +} +``` -- cgit v1.2.3