From 9cadfed0e4e541b8a65f4083800da6bf25c965da Mon Sep 17 00:00:00 2001 From: Aylur Date: Thu, 23 Jan 2025 17:58:38 +0100 Subject: update popover example --- examples/gtk3/js/popover/app.tsx | 102 ++++++++------------------------------- 1 file changed, 21 insertions(+), 81 deletions(-) (limited to 'examples/gtk3/js/popover/app.tsx') diff --git a/examples/gtk3/js/popover/app.tsx b/examples/gtk3/js/popover/app.tsx index 6358297..6b0286f 100644 --- a/examples/gtk3/js/popover/app.tsx +++ b/examples/gtk3/js/popover/app.tsx @@ -1,75 +1,12 @@ -import { App, Astal, Gdk, Gtk } from "astal/gtk3" - -const { TOP, RIGHT, BOTTOM, LEFT } = Astal.WindowAnchor - -type PopupProps = { - child?: unknown - marginBottom?: number - marginTop?: number - marginLeft?: number - marginRight?: number - halign?: Gtk.Align - valign?: Gtk.Align -} - -function Popup({ - child, - marginBottom, - marginTop, - marginLeft, - marginRight, - halign = Gtk.Align.CENTER, - valign = Gtk.Align.CENTER, -}: PopupProps) { - return ( - { - const [, _x, _y] = event.get_coords() - const { x, y, width, height } = self - .get_child()! - .get_allocation() - - const xOut = _x < x || _x > x + width - const yOut = _y < y || _y > y + height - - // clicked outside - if (xOut || yOut) self.hide() - }} - // close when hitting Escape - onKeyPressEvent={(self, event: Gdk.Event) => { - if (event.get_keyval()[1] === Gdk.KEY_Escape) { - self.hide() - } - }} - > - true} // make sure click event does not bubble up - // child can be positioned with `halign` `valign` and margins - expand - halign={halign} - valign={valign} - marginBottom={marginBottom} - marginTop={marginTop} - marginStart={marginLeft} - marginEnd={marginRight} - > - {child} - - - ) -} +import { App, Astal, Gtk } from "astal/gtk3" +import { Variable } from "astal" +import Popup from "./Popover" +const { TOP, RIGHT, LEFT } = Astal.WindowAnchor App.start({ instanceName: "popup-example", css: ` - .Popup { + .Popup>box { background-color: @theme_bg_color; box-shadow: 2px 3px 7px 0 rgba(0,0,0,0.4); border-radius: 12px; @@ -77,25 +14,28 @@ App.start({ } `, main() { - const popup = ( - - - - ) + const visible = Variable(false); + + visible.set(false)} + visible={visible()} + marginTop={36} + marginRight={60} + valign={Gtk.Align.START} + halign={Gtk.Align.END} + > + + return ( - -- cgit v1.2.3