summaryrefslogtreecommitdiff
path: root/lang/gjs/src/gtk4/jsx-runtime.ts
blob: 80a3e87f2ffc051926cc2595e9be61ef89e80a0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import Gtk from "gi://Gtk?version=4.0"
import { type BindableChild } from "./astalify.js"
import { mergeBindings, jsx as _jsx } from "../_astal.js"
import * as Widget from "./widget.js"

export function Fragment({ children = [], child }: {
    child?: BindableChild
    children?: Array<BindableChild>
}) {
    if (child) children.push(child)
    return mergeBindings(children)
}

export function jsx(
    ctor: keyof typeof ctors | typeof Gtk.Widget,
    props: any,
) {
    return _jsx(ctors, ctor as any, props)
}

const ctors = {
    box: Widget.Box,
    button: Widget.Button,
    centerbox: Widget.CenterBox,
    // circularprogress: Widget.CircularProgress,
    // drawingarea: Widget.DrawingArea,
    entry: Widget.Entry,
    image: Widget.Image,
    label: Widget.Label,
    levelbar: Widget.LevelBar,
    overlay: Widget.Overlay,
    revealer: Widget.Revealer,
    slider: Widget.Slider,
    stack: Widget.Stack,
    switch: Widget.Switch,
    window: Widget.Window,
    menubutton: Widget.MenuButton,
    popover: Widget.Popover,
}

declare global {
    // eslint-disable-next-line @typescript-eslint/no-namespace
    namespace JSX {
        type Element = Gtk.Widget
        type ElementClass = Gtk.Widget
        interface IntrinsicElements {
            box: Widget.BoxProps
            button: Widget.ButtonProps
            centerbox: Widget.CenterBoxProps
            // circularprogress: Widget.CircularProgressProps
            // drawingarea: Widget.DrawingAreaProps
            entry: Widget.EntryProps
            image: Widget.ImageProps
            label: Widget.LabelProps
            levelbar: Widget.LevelBarProps
            overlay: Widget.OverlayProps
            revealer: Widget.RevealerProps
            slider: Widget.SliderProps
            stack: Widget.StackProps
            switch: Widget.SwitchProps
            window: Widget.WindowProps
            menubutton: Widget.MenuButtonProps
            popover: Widget.PopoverProps
        }
    }
}

export const jsxs = jsx