pyjs 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyjs/__init__.py +6 -0
- pyjs/__main__.py +6 -0
- pyjs/cli.py +816 -0
- pyjs/decorators.py +170 -0
- pyjs/docs/__init__.py +6 -0
- pyjs/docs/builder.py +351 -0
- pyjs/docs/cli.py +55 -0
- pyjs/docs/config.py +45 -0
- pyjs/docs/favicon.svg +18 -0
- pyjs/docs/markdown.py +61 -0
- pyjs/docs/models.py +38 -0
- pyjs/docs/navigation.py +61 -0
- pyjs/docs/style.css +901 -0
- pyjs/docs/ui.py +349 -0
- pyjs/nativescript/__init__.py +77 -0
- pyjs/scaffolding/__init__.py +418 -0
- pyjs/scaffolding/templates/app/README.md.template +33 -0
- pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__PYJS_PACKAGE__.py.template +81 -0
- pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__init__.py.template +0 -0
- pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__main__.py.template +5 -0
- pyjs/scaffolding/templates/app/tests/test_app.py.template +22 -0
- pyjs/scaffolding/templates/app/tests/test_browser_app.py.template +19 -0
- pyjs/scaffolding/templates/app_test.py.template +8 -0
- pyjs/server.py +468 -0
- pyjs/skills/pyjs/SKILL.md +161 -0
- pyjs/state.py +101 -0
- pyjs/testing/__init__.py +3 -0
- pyjs/testing/android.py +248 -0
- pyjs/testing/artifacts.py +37 -0
- pyjs/testing/assertion_rewriter.py +125 -0
- pyjs/testing/builder.py +191 -0
- pyjs/testing/capture.py +133 -0
- pyjs/testing/client/__init__.py +1 -0
- pyjs/testing/client/app.py +718 -0
- pyjs/testing/client/assertions.py +49 -0
- pyjs/testing/client/runtime.py +123 -0
- pyjs/testing/client/sidebar.py +377 -0
- pyjs/testing/client/state.py +107 -0
- pyjs/testing/client/viewer.py +361 -0
- pyjs/testing/daemon.py +641 -0
- pyjs/testing/helpers.py +155 -0
- pyjs/testing/protocol.py +56 -0
- pyjs/testing/pytest_plugin.py +797 -0
- pyjs/testing/web.py +97 -0
- pyjs/testing/webgpu.py +27 -0
- pyjs/tooling/__init__.py +4 -0
- pyjs/tooling/android.py +138 -0
- pyjs/tooling/browser.py +676 -0
- pyjs/tooling/command.py +75 -0
- pyjs/tooling/nativescript.py +156 -0
- pyjs/tooling/node.py +170 -0
- pyjs/tooling/perf.py +163 -0
- pyjs/transpiler/__init__.py +23 -0
- pyjs/transpiler/_builtins.py +485 -0
- pyjs/transpiler/analyzer.py +1495 -0
- pyjs/transpiler/objects.py +1015 -0
- pyjs/transpiler/source.py +189 -0
- pyjs/transpiler/transpiler.py +748 -0
- pyjs/transpiler/utils.py +150 -0
- pyjs/web/__init__.py +5 -0
- pyjs/web/console.py +16 -0
- pyjs/web/dom.py +1529 -0
- pyjs/web/domx.py +474 -0
- pyjs/web/dragdrop.py +102 -0
- pyjs/web/events.py +1306 -0
- pyjs/web/files.py +203 -0
- pyjs/web/geometry.py +475 -0
- pyjs/web/html.py +927 -0
- pyjs/web/indexeddb.py +410 -0
- pyjs/web/javascript.py +112 -0
- pyjs/web/network.py +193 -0
- pyjs/web/ssr.py +70 -0
- pyjs/web/streams.py +17 -0
- pyjs/web/svg.py +684 -0
- pyjs/web/timers.py +29 -0
- pyjs/web/ui/__init__.py +18 -0
- pyjs/web/ui/accordion.py +166 -0
- pyjs/web/ui/alert.py +52 -0
- pyjs/web/ui/alert_dialog.py +102 -0
- pyjs/web/ui/aspect_ratio.py +12 -0
- pyjs/web/ui/attachment.py +80 -0
- pyjs/web/ui/avatar.py +105 -0
- pyjs/web/ui/badge.py +48 -0
- pyjs/web/ui/breadcrumb.py +85 -0
- pyjs/web/ui/bubble.py +38 -0
- pyjs/web/ui/button.py +86 -0
- pyjs/web/ui/calendar.py +124 -0
- pyjs/web/ui/card.py +58 -0
- pyjs/web/ui/carousel.py +99 -0
- pyjs/web/ui/chart.py +56 -0
- pyjs/web/ui/checkbox.py +31 -0
- pyjs/web/ui/collapsible.py +71 -0
- pyjs/web/ui/combobox.py +36 -0
- pyjs/web/ui/command.py +118 -0
- pyjs/web/ui/context_menu.py +65 -0
- pyjs/web/ui/date_picker.py +24 -0
- pyjs/web/ui/dialog.py +289 -0
- pyjs/web/ui/direction.py +9 -0
- pyjs/web/ui/drawer.py +72 -0
- pyjs/web/ui/dropdown_menu.py +239 -0
- pyjs/web/ui/empty.py +69 -0
- pyjs/web/ui/field.py +96 -0
- pyjs/web/ui/floating.py +90 -0
- pyjs/web/ui/hover_card.py +128 -0
- pyjs/web/ui/input.py +48 -0
- pyjs/web/ui/input_group.py +77 -0
- pyjs/web/ui/input_otp.py +76 -0
- pyjs/web/ui/item.py +78 -0
- pyjs/web/ui/kbd.py +26 -0
- pyjs/web/ui/label.py +14 -0
- pyjs/web/ui/marker.py +29 -0
- pyjs/web/ui/menubar.py +52 -0
- pyjs/web/ui/message.py +57 -0
- pyjs/web/ui/message_scroller.py +45 -0
- pyjs/web/ui/native_select.py +47 -0
- pyjs/web/ui/navigation_menu.py +110 -0
- pyjs/web/ui/pagination.py +63 -0
- pyjs/web/ui/popover.py +217 -0
- pyjs/web/ui/progress.py +44 -0
- pyjs/web/ui/radio_group.py +129 -0
- pyjs/web/ui/resizable.py +194 -0
- pyjs/web/ui/scroll_area.py +29 -0
- pyjs/web/ui/select.py +83 -0
- pyjs/web/ui/separator.py +24 -0
- pyjs/web/ui/sheet.py +77 -0
- pyjs/web/ui/sidebar.py +162 -0
- pyjs/web/ui/skeleton.py +15 -0
- pyjs/web/ui/slider.py +46 -0
- pyjs/web/ui/sonner.py +70 -0
- pyjs/web/ui/spinner.py +14 -0
- pyjs/web/ui/switch.py +35 -0
- pyjs/web/ui/table.py +84 -0
- pyjs/web/ui/tabs.py +167 -0
- pyjs/web/ui/text.py +15 -0
- pyjs/web/ui/textarea.py +28 -0
- pyjs/web/ui/toggle.py +109 -0
- pyjs/web/ui/tooltip.py +164 -0
- pyjs/web/ui/typography.py +79 -0
- pyjs/web/url.py +76 -0
- pyjs/web/webgpu.py +496 -0
- pyjs-0.0.1.dist-info/METADATA +441 -0
- pyjs-0.0.1.dist-info/RECORD +146 -0
- pyjs-0.0.1.dist-info/WHEEL +5 -0
- pyjs-0.0.1.dist-info/entry_points.txt +5 -0
- pyjs-0.0.1.dist-info/licenses/LICENSE +28 -0
- pyjs-0.0.1.dist-info/top_level.txt +1 -0
pyjs/web/ui/separator.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.domx import tag, tw
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@js
|
|
6
|
+
def Separator(orientation: str = "horizontal", decorative: bool = True):
|
|
7
|
+
if orientation == "vertical":
|
|
8
|
+
style = tw("h-full w-px shrink-0 self-stretch bg-slate-200")
|
|
9
|
+
else:
|
|
10
|
+
style = tw("h-px w-full shrink-0 bg-slate-200")
|
|
11
|
+
if decorative:
|
|
12
|
+
attributes = {
|
|
13
|
+
"data-orientation": orientation,
|
|
14
|
+
"data-slot": "separator",
|
|
15
|
+
"role": "none",
|
|
16
|
+
}
|
|
17
|
+
else:
|
|
18
|
+
attributes = {
|
|
19
|
+
"aria-orientation": orientation,
|
|
20
|
+
"data-orientation": orientation,
|
|
21
|
+
"data-slot": "separator",
|
|
22
|
+
"role": "separator",
|
|
23
|
+
}
|
|
24
|
+
return tag("div", style, attributes)
|
pyjs/web/ui/sheet.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.domx import ProxyElement, button, div, p, tag, tw
|
|
3
|
+
from pyjs.web.ui.dialog import Dialog, DialogContent, DialogTrigger
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@js
|
|
7
|
+
class SheetTrigger(DialogTrigger):
|
|
8
|
+
def __init__(self, *children):
|
|
9
|
+
super().__init__(*children)
|
|
10
|
+
self.setAttribute("data-slot", "sheet-trigger")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@js
|
|
14
|
+
class SheetClose(ProxyElement):
|
|
15
|
+
def __init__(self, *children):
|
|
16
|
+
self.element = button(
|
|
17
|
+
tw(
|
|
18
|
+
"inline-flex h-9 items-center justify-center rounded-md border border-slate-300 "
|
|
19
|
+
"bg-white px-4 text-sm font-medium text-slate-950 shadow-sm hover:bg-slate-100"
|
|
20
|
+
),
|
|
21
|
+
{"data-dialog-close": "", "data-slot": "sheet-close", "type": "button"},
|
|
22
|
+
*children,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@js
|
|
27
|
+
def SheetHeader(*children):
|
|
28
|
+
return div(
|
|
29
|
+
tw("grid gap-1.5 text-left"),
|
|
30
|
+
{"data-slot": "sheet-header"},
|
|
31
|
+
*children,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@js
|
|
36
|
+
def SheetFooter(*children):
|
|
37
|
+
return div(
|
|
38
|
+
tw("mt-auto flex flex-col-reverse gap-2 sm:flex-row sm:justify-end"),
|
|
39
|
+
{"data-slot": "sheet-footer"},
|
|
40
|
+
*children,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@js
|
|
45
|
+
def SheetTitle(*children):
|
|
46
|
+
return tag(
|
|
47
|
+
"h2",
|
|
48
|
+
tw("text-lg font-semibold text-slate-950"),
|
|
49
|
+
{"data-slot": "sheet-title"},
|
|
50
|
+
*children,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@js
|
|
55
|
+
def SheetDescription(*children):
|
|
56
|
+
return p(
|
|
57
|
+
tw("text-sm leading-6 text-slate-500"),
|
|
58
|
+
{"data-slot": "sheet-description"},
|
|
59
|
+
*children,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@js
|
|
64
|
+
class SheetContent(DialogContent):
|
|
65
|
+
def __init__(self, label: str, *children, side: str = "right"):
|
|
66
|
+
super().__init__(
|
|
67
|
+
label,
|
|
68
|
+
*children,
|
|
69
|
+
component="sheet",
|
|
70
|
+
placement=side,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@js
|
|
75
|
+
class Sheet(Dialog):
|
|
76
|
+
def __init__(self, trigger: SheetTrigger, content: SheetContent):
|
|
77
|
+
super().__init__(trigger, content, component="sheet")
|
pyjs/web/ui/sidebar.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.dom import Element
|
|
3
|
+
from pyjs.web.domx import a, button, div, input, tag, tw
|
|
4
|
+
from pyjs.web.events import Event
|
|
5
|
+
from pyjs.web.ui import Widget
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@js
|
|
9
|
+
def Sidebar(*children, side: str = "left"):
|
|
10
|
+
return tag(
|
|
11
|
+
"aside",
|
|
12
|
+
tw(
|
|
13
|
+
"flex w-64 shrink-0 flex-col border-slate-200 bg-slate-50 text-slate-950 "
|
|
14
|
+
"data-[side=left]:border-r data-[side=right]:border-l "
|
|
15
|
+
"group-data-[state=collapsed]/sidebar-layout:w-0 "
|
|
16
|
+
"group-data-[state=collapsed]/sidebar-layout:overflow-hidden"
|
|
17
|
+
),
|
|
18
|
+
{"data-side": side, "data-slot": "sidebar"},
|
|
19
|
+
*children,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@js
|
|
24
|
+
def SidebarTrigger(*children, label: str = "Toggle sidebar"):
|
|
25
|
+
return button(
|
|
26
|
+
tw(
|
|
27
|
+
"inline-flex size-9 items-center justify-center rounded-md hover:bg-slate-100"
|
|
28
|
+
),
|
|
29
|
+
{
|
|
30
|
+
"aria-label": label,
|
|
31
|
+
"data-sidebar-toggle": "",
|
|
32
|
+
"data-slot": "sidebar-trigger",
|
|
33
|
+
"type": "button",
|
|
34
|
+
},
|
|
35
|
+
*children,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@js
|
|
40
|
+
def SidebarInset(*children):
|
|
41
|
+
return tag("main", tw("min-w-0 flex-1"), {"data-slot": "sidebar-inset"}, *children)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@js
|
|
45
|
+
def SidebarInput(placeholder: str = "Search", name: str = ""):
|
|
46
|
+
return input(
|
|
47
|
+
tw(
|
|
48
|
+
"h-8 w-full rounded-md border border-slate-300 bg-white px-2 text-sm outline-none"
|
|
49
|
+
),
|
|
50
|
+
{"data-slot": "sidebar-input", "name": name, "placeholder": placeholder},
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@js
|
|
55
|
+
def SidebarHeader(*children):
|
|
56
|
+
return div(tw("grid gap-2 p-3"), {"data-slot": "sidebar-header"}, *children)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@js
|
|
60
|
+
def SidebarFooter(*children):
|
|
61
|
+
return div(tw("mt-auto grid gap-2 p-3"), {"data-slot": "sidebar-footer"}, *children)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@js
|
|
65
|
+
def SidebarContent(*children):
|
|
66
|
+
return div(
|
|
67
|
+
tw("min-h-0 flex-1 overflow-auto p-2"),
|
|
68
|
+
{"data-slot": "sidebar-content"},
|
|
69
|
+
*children,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@js
|
|
74
|
+
def SidebarGroup(*children):
|
|
75
|
+
return div(tw("grid gap-1 p-2"), {"data-slot": "sidebar-group"}, *children)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@js
|
|
79
|
+
def SidebarGroupLabel(*children):
|
|
80
|
+
return div(
|
|
81
|
+
tw("px-2 py-1 text-xs font-medium text-slate-500"),
|
|
82
|
+
{"data-slot": "sidebar-group-label"},
|
|
83
|
+
*children,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@js
|
|
88
|
+
def SidebarGroupContent(*children):
|
|
89
|
+
return div({"data-slot": "sidebar-group-content"}, *children)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@js
|
|
93
|
+
def SidebarMenu(*children):
|
|
94
|
+
return tag("ul", tw("grid gap-1"), {"data-slot": "sidebar-menu"}, *children)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@js
|
|
98
|
+
def SidebarMenuItem(*children):
|
|
99
|
+
return tag("li", {"data-slot": "sidebar-menu-item"}, *children)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@js
|
|
103
|
+
def SidebarMenuButton(href: str, *children, current: bool = False):
|
|
104
|
+
attributes = {"data-slot": "sidebar-menu-button", "href": href}
|
|
105
|
+
if current:
|
|
106
|
+
attributes["aria-current"] = "page"
|
|
107
|
+
return a(
|
|
108
|
+
tw(
|
|
109
|
+
"flex h-8 items-center gap-2 rounded-md px-2 text-sm hover:bg-slate-200 "
|
|
110
|
+
"aria-[current=page]:bg-slate-200 aria-[current=page]:font-medium"
|
|
111
|
+
),
|
|
112
|
+
attributes,
|
|
113
|
+
*children,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@js
|
|
118
|
+
def SidebarMenuBadge(*children):
|
|
119
|
+
return tag(
|
|
120
|
+
"span",
|
|
121
|
+
tw("ml-auto rounded-full bg-slate-200 px-1.5 text-xs"),
|
|
122
|
+
{"data-slot": "sidebar-menu-badge"},
|
|
123
|
+
*children,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@js
|
|
128
|
+
def SidebarSeparator():
|
|
129
|
+
return div(tw("mx-2 h-px bg-slate-200"), {"data-slot": "sidebar-separator"})
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@js
|
|
133
|
+
class SidebarLayout(Widget):
|
|
134
|
+
def __init__(self, sidebar: Element, inset: Element, *, default_open: bool = True):
|
|
135
|
+
super().__init__()
|
|
136
|
+
self.add(
|
|
137
|
+
tw("group/sidebar-layout flex min-h-screen w-full"),
|
|
138
|
+
{
|
|
139
|
+
"data-slot": "sidebar-layout",
|
|
140
|
+
"data-state": "expanded" if default_open else "collapsed",
|
|
141
|
+
},
|
|
142
|
+
sidebar,
|
|
143
|
+
inset,
|
|
144
|
+
)
|
|
145
|
+
self.addEventListener("click", self.clicked)
|
|
146
|
+
|
|
147
|
+
def is_open(self) -> bool:
|
|
148
|
+
return self.getAttribute("data-state") == "expanded"
|
|
149
|
+
|
|
150
|
+
def set_open(self, open: bool):
|
|
151
|
+
self.setAttribute("data-state", "expanded" if open else "collapsed")
|
|
152
|
+
triggers: list[Element] = self.querySelectorAll("[data-sidebar-toggle]")
|
|
153
|
+
for trigger in triggers:
|
|
154
|
+
trigger.setAttribute("aria-expanded", "true" if open else "false")
|
|
155
|
+
|
|
156
|
+
def toggle(self):
|
|
157
|
+
self.set_open(not self.is_open())
|
|
158
|
+
|
|
159
|
+
def clicked(self, event: Event):
|
|
160
|
+
target: Element = event.target
|
|
161
|
+
if target.closest("[data-sidebar-toggle]") is not None:
|
|
162
|
+
self.toggle()
|
pyjs/web/ui/skeleton.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.domx import tag, tw
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@js
|
|
6
|
+
def Skeleton(width: str = "100%", height: str = "1rem"):
|
|
7
|
+
return tag(
|
|
8
|
+
"div",
|
|
9
|
+
tw("animate-pulse rounded-md bg-slate-200"),
|
|
10
|
+
{
|
|
11
|
+
"aria-hidden": "true",
|
|
12
|
+
"data-slot": "skeleton",
|
|
13
|
+
"style": "width: " + width + "; height: " + height,
|
|
14
|
+
},
|
|
15
|
+
)
|
pyjs/web/ui/slider.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.domx import ProxyElement, input, tw
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@js
|
|
6
|
+
class Slider(ProxyElement):
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
value: int = 0,
|
|
10
|
+
minimum: int = 0,
|
|
11
|
+
maximum: int = 100,
|
|
12
|
+
step: int = 1,
|
|
13
|
+
label: str = "",
|
|
14
|
+
name: str = "",
|
|
15
|
+
):
|
|
16
|
+
if maximum <= minimum:
|
|
17
|
+
raise ValueError("Slider maximum must be greater than minimum")
|
|
18
|
+
if value < minimum:
|
|
19
|
+
value = minimum
|
|
20
|
+
if value > maximum:
|
|
21
|
+
value = maximum
|
|
22
|
+
self.element = input(
|
|
23
|
+
tw(
|
|
24
|
+
"h-5 w-full cursor-pointer appearance-none bg-transparent accent-slate-950 "
|
|
25
|
+
"disabled:cursor-not-allowed disabled:opacity-50"
|
|
26
|
+
),
|
|
27
|
+
{
|
|
28
|
+
"aria-label": label,
|
|
29
|
+
"data-slot": "slider",
|
|
30
|
+
"max": str(maximum),
|
|
31
|
+
"min": str(minimum),
|
|
32
|
+
"name": name,
|
|
33
|
+
"step": str(step),
|
|
34
|
+
"type": "range",
|
|
35
|
+
"value": str(value),
|
|
36
|
+
},
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def get_value(self) -> str:
|
|
40
|
+
return self.element.value
|
|
41
|
+
|
|
42
|
+
def set_value(self, value: int):
|
|
43
|
+
self.element.value = str(value)
|
|
44
|
+
|
|
45
|
+
def on_input(self, callback: callable):
|
|
46
|
+
self.element.addEventListener("input", callback)
|
pyjs/web/ui/sonner.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.dom import Element
|
|
3
|
+
from pyjs.web.domx import button, div, p, tw
|
|
4
|
+
from pyjs.web.events import Event
|
|
5
|
+
from pyjs.web.ui import Widget
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@js
|
|
9
|
+
class Toaster(Widget):
|
|
10
|
+
def __init__(self, position: str = "bottom-right"):
|
|
11
|
+
super().__init__()
|
|
12
|
+
self.next_id = 0
|
|
13
|
+
self.add(
|
|
14
|
+
tw(
|
|
15
|
+
"fixed z-[100] flex w-full max-w-sm flex-col gap-2 p-4 "
|
|
16
|
+
"data-[position=bottom-right]:bottom-0 data-[position=bottom-right]:right-0 "
|
|
17
|
+
"data-[position=top-right]:right-0 data-[position=top-right]:top-0"
|
|
18
|
+
),
|
|
19
|
+
{
|
|
20
|
+
"aria-label": "Notifications",
|
|
21
|
+
"aria-live": "polite",
|
|
22
|
+
"data-position": position,
|
|
23
|
+
"data-slot": "toaster",
|
|
24
|
+
"role": "region",
|
|
25
|
+
},
|
|
26
|
+
)
|
|
27
|
+
self.addEventListener("click", self.clicked)
|
|
28
|
+
|
|
29
|
+
def notify(self, title: str, description: str = "", variant: str = "default") -> str:
|
|
30
|
+
self.next_id += 1
|
|
31
|
+
toast_id = "toast-" + str(self.next_id)
|
|
32
|
+
toast = div(
|
|
33
|
+
tw(
|
|
34
|
+
"relative grid gap-1 rounded-lg border border-slate-200 bg-white p-4 pr-10 "
|
|
35
|
+
"text-sm shadow-lg data-[variant=destructive]:border-red-300"
|
|
36
|
+
),
|
|
37
|
+
{
|
|
38
|
+
"data-slot": "toast",
|
|
39
|
+
"data-toast-id": toast_id,
|
|
40
|
+
"data-variant": variant,
|
|
41
|
+
"role": "status",
|
|
42
|
+
},
|
|
43
|
+
div(tw("font-semibold"), {"data-slot": "toast-title"}, title),
|
|
44
|
+
p(tw("text-slate-500"), {"data-slot": "toast-description"}, description),
|
|
45
|
+
button(
|
|
46
|
+
tw("absolute right-2 top-2 size-7 rounded-md hover:bg-slate-100"),
|
|
47
|
+
{
|
|
48
|
+
"aria-label": "Dismiss notification",
|
|
49
|
+
"data-toast-close": "",
|
|
50
|
+
"type": "button",
|
|
51
|
+
},
|
|
52
|
+
"×",
|
|
53
|
+
),
|
|
54
|
+
)
|
|
55
|
+
self.append(toast)
|
|
56
|
+
return toast_id
|
|
57
|
+
|
|
58
|
+
def dismiss(self, toast_id: str):
|
|
59
|
+
toast = self.querySelector("[data-toast-id='" + toast_id + "']")
|
|
60
|
+
if toast is not None:
|
|
61
|
+
toast.remove()
|
|
62
|
+
|
|
63
|
+
def clicked(self, event: Event):
|
|
64
|
+
target: Element = event.target
|
|
65
|
+
close_button = target.closest("[data-toast-close]")
|
|
66
|
+
if close_button is None:
|
|
67
|
+
return
|
|
68
|
+
toast = close_button.closest("[data-slot=toast]")
|
|
69
|
+
if toast is not None:
|
|
70
|
+
toast.remove()
|
pyjs/web/ui/spinner.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.domx import tag, tw
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@js
|
|
6
|
+
def Spinner(label: str = "Loading"):
|
|
7
|
+
return tag(
|
|
8
|
+
"span",
|
|
9
|
+
tw(
|
|
10
|
+
"inline-block size-4 animate-spin rounded-full border-2 border-slate-300 "
|
|
11
|
+
"border-t-slate-950"
|
|
12
|
+
),
|
|
13
|
+
{"aria-label": label, "data-slot": "spinner", "role": "status"},
|
|
14
|
+
)
|
pyjs/web/ui/switch.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.domx import ProxyElement, input, tw
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@js
|
|
6
|
+
class Switch(ProxyElement):
|
|
7
|
+
def __init__(self, name: str = "", checked: bool = False):
|
|
8
|
+
self.element = input(
|
|
9
|
+
tw(
|
|
10
|
+
"relative inline-flex h-5 w-9 shrink-0 cursor-pointer appearance-none "
|
|
11
|
+
"items-center rounded-full bg-slate-200 transition-colors before:block "
|
|
12
|
+
"before:size-4 before:translate-x-0.5 before:rounded-full before:bg-white "
|
|
13
|
+
"before:shadow-sm before:transition-transform checked:bg-slate-950 "
|
|
14
|
+
"checked:before:translate-x-[1.125rem] focus-visible:outline-none "
|
|
15
|
+
"focus-visible:ring-2 focus-visible:ring-slate-400 disabled:opacity-50"
|
|
16
|
+
),
|
|
17
|
+
{
|
|
18
|
+
"data-slot": "switch",
|
|
19
|
+
"name": name,
|
|
20
|
+
"role": "switch",
|
|
21
|
+
"type": "checkbox",
|
|
22
|
+
},
|
|
23
|
+
)
|
|
24
|
+
self.element.checked = checked
|
|
25
|
+
if checked:
|
|
26
|
+
self.element.setAttribute("checked", "")
|
|
27
|
+
|
|
28
|
+
def is_checked(self) -> bool:
|
|
29
|
+
return self.element.checked
|
|
30
|
+
|
|
31
|
+
def set_checked(self, checked: bool):
|
|
32
|
+
self.element.checked = checked
|
|
33
|
+
|
|
34
|
+
def on_change(self, callback: callable):
|
|
35
|
+
self.element.addEventListener("change", callback)
|
pyjs/web/ui/table.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
from pyjs import js
|
|
2
|
+
from pyjs.web.domx import tag, tw
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@js
|
|
6
|
+
def Table(*children):
|
|
7
|
+
return tag(
|
|
8
|
+
"div",
|
|
9
|
+
tw("relative w-full overflow-x-auto"),
|
|
10
|
+
{"data-slot": "table-container"},
|
|
11
|
+
tag(
|
|
12
|
+
"table",
|
|
13
|
+
tw("w-full caption-bottom text-sm"),
|
|
14
|
+
{"data-slot": "table"},
|
|
15
|
+
*children,
|
|
16
|
+
),
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@js
|
|
21
|
+
def TableHeader(*children):
|
|
22
|
+
return tag(
|
|
23
|
+
"thead",
|
|
24
|
+
tw("border-b border-slate-200"),
|
|
25
|
+
{"data-slot": "table-header"},
|
|
26
|
+
*children,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@js
|
|
31
|
+
def TableBody(*children):
|
|
32
|
+
return tag("tbody", {"data-slot": "table-body"}, *children)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@js
|
|
36
|
+
def TableFooter(*children):
|
|
37
|
+
return tag(
|
|
38
|
+
"tfoot",
|
|
39
|
+
tw("border-t border-slate-200 bg-slate-50 font-medium"),
|
|
40
|
+
{"data-slot": "table-footer"},
|
|
41
|
+
*children,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@js
|
|
46
|
+
def TableRow(*children):
|
|
47
|
+
return tag(
|
|
48
|
+
"tr",
|
|
49
|
+
tw("border-b border-slate-200 transition-colors hover:bg-slate-50"),
|
|
50
|
+
{"data-slot": "table-row"},
|
|
51
|
+
*children,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@js
|
|
56
|
+
def TableHead(*children):
|
|
57
|
+
return tag(
|
|
58
|
+
"th",
|
|
59
|
+
tw(
|
|
60
|
+
"h-10 whitespace-nowrap px-2 text-left align-middle font-medium text-slate-700"
|
|
61
|
+
),
|
|
62
|
+
{"data-slot": "table-head", "scope": "col"},
|
|
63
|
+
*children,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@js
|
|
68
|
+
def TableCell(*children):
|
|
69
|
+
return tag(
|
|
70
|
+
"td",
|
|
71
|
+
tw("whitespace-nowrap p-2 align-middle text-slate-700"),
|
|
72
|
+
{"data-slot": "table-cell"},
|
|
73
|
+
*children,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@js
|
|
78
|
+
def TableCaption(*children):
|
|
79
|
+
return tag(
|
|
80
|
+
"caption",
|
|
81
|
+
tw("mt-4 text-sm text-slate-500"),
|
|
82
|
+
{"data-slot": "table-caption"},
|
|
83
|
+
*children,
|
|
84
|
+
)
|