import { Accessor, With } from "ags"; import { register } from "ags/gobject"; import { Gtk } from "ags/gtk4"; import { variableToBoolean } from "../../modules/utils"; import Pango from "gi://Pango?version=1.0"; export { ResultWidget, ResultWidgetProps }; type ResultWidgetProps = { icon?: string | Accessor | JSX.Element | Accessor; title: string | Accessor; description?: string | Accessor; closeOnClick?: boolean; setup?: () => void; actionClick?: () => void; visible?: boolean; }; @register({ GTypeName: "ResultWidget" }) class ResultWidget extends Gtk.Box { public readonly actionClick: () => void; public readonly setup?: () => void; public icon?: (string | Accessor | JSX.Element | Accessor); public closeOnClick: boolean = true; constructor(props: ResultWidgetProps) { super(); this.add_css_class("result"); this.visible = props.visible ?? true; this.hexpand = true; this.icon = props.icon; this.setup = props.setup; this.closeOnClick = props.closeOnClick ?? true; this.actionClick = () => props.actionClick?.(); if(this.icon !== undefined) { if(this.icon instanceof Accessor) { if(typeof this.icon.get() === "string") { this.prepend( } /> as Gtk.Image); } else { this.prepend( }> {(widget) => widget} as Gtk.Box); } } else { if(typeof this.icon === "string") this.prepend( as Gtk.Image); else this.prepend(this.icon as Gtk.Widget); } } this.append( as Gtk.Box); } }