-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcomponents.py
90 lines (69 loc) · 2.26 KB
/
components.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from pathlib import Path
from typing import Any
from reactpy import component
from reactpy.core.component import Component
from reactpy.web.module import export, module_from_file
from reactpy.core.types import VdomChild
from .utils import _parse_children
_js_module = module_from_file(
"reactpy-material",
file=Path(__file__).parents[1] / "bundle.js"
)
md_button = export(_js_module, "MDButton")
md_button_group = export(_js_module, "MDButtonGroup")
md_autocomplete = export(_js_module, "MDAutoComplete")
md_checkbox = export(_js_module, "MDCheckbox")
md_select = export(_js_module, "MDSelect")
md_text_field = export(_js_module, "MDTextField")
md_switch = export(_js_module, "MDSwitch")
md_input_label = export(_js_module, "MDInputLabel")
md_menu_item = export(_js_module, "MDMenuItem")
md_chip = export(_js_module, "MDChip")
@component
def button(*children: VdomChild, attrs: Any = {}):
return md_button(attrs, *children)
@component
def button_group(*children: VdomChild, attrs: Any = {}):
return md_button_group(attrs, _parse_children(children))
@component
def autocomplete(attrs: Any = {}):
return md_autocomplete(attrs)
@component
def checkbox(attrs: Any = {}):
return md_checkbox(attrs)
@component
def select(*children: VdomChild, attrs: Any = {}):
children_items = ()
for c in children:
if isinstance(c, Component):
children_items += (c.render(), )
else:
children_items += (c, )
return md_select(attrs, children_items)
@component
def text_field(attrs: Any = {}):
return md_text_field(attrs)
@component
def switch(attrs: Any = {}):
return md_switch(attrs)
@component
def input_label(*children: VdomChild, attrs: Any = {}):
children_items = ()
for c in children:
if isinstance(c, Component):
children_items += (c.render(), )
else:
children_items += (c, )
return md_input_label(attrs, children_items)
@component
def menu_item(*children: VdomChild, attrs: Any = {}):
children_items = ()
for c in children:
if isinstance(c, Component):
children_items += (c.render(), )
else:
children_items += (c, )
return md_menu_item(attrs, children_items)
@component
def chip(attrs: Any = {}):
return md_chip(attrs)