nicegui-bootstrap-components 0.1.0__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.
- nicegui_bootstrap_components/__init__.py +7 -0
- nicegui_bootstrap_components/_base.py +590 -0
- nicegui_bootstrap_components/_host.py +259 -0
- nicegui_bootstrap_components/assets.py +371 -0
- nicegui_bootstrap_components/bs/__init__.py +267 -0
- nicegui_bootstrap_components/bs/_actions.py +232 -0
- nicegui_bootstrap_components/bs/_alert_spinner.py +423 -0
- nicegui_bootstrap_components/bs/_carousel.py +312 -0
- nicegui_bootstrap_components/bs/_choices.py +779 -0
- nicegui_bootstrap_components/bs/_content.py +1343 -0
- nicegui_bootstrap_components/bs/_forms.py +378 -0
- nicegui_bootstrap_components/bs/_inputs.py +560 -0
- nicegui_bootstrap_components/bs/_layout.py +341 -0
- nicegui_bootstrap_components/bs/_nav.py +650 -0
- nicegui_bootstrap_components/bs/_navbar.py +445 -0
- nicegui_bootstrap_components/bs/_overlay_root.py +73 -0
- nicegui_bootstrap_components/bs/_overlays.py +2633 -0
- nicegui_bootstrap_components/bs/_scope.py +28 -0
- nicegui_bootstrap_components/bs/_tabs.py +605 -0
- nicegui_bootstrap_components/bs/_toast.py +137 -0
- nicegui_bootstrap_components/bs/_tooltip_popover.py +537 -0
- nicegui_bootstrap_components/contracts/dbc-2.0.4.json +16811 -0
- nicegui_bootstrap_components/dbc/__init__.py +108 -0
- nicegui_bootstrap_components/icons.py +29 -0
- nicegui_bootstrap_components/persist.py +201 -0
- nicegui_bootstrap_components/py.typed +0 -0
- nicegui_bootstrap_components/static/dist/fonts/bootstrap-icons.woff +0 -0
- nicegui_bootstrap_components/static/dist/fonts/bootstrap-icons.woff2 +0 -0
- nicegui_bootstrap_components/static/dist/ngbs-bootstrap-unscoped.css +12047 -0
- nicegui_bootstrap_components/static/dist/ngbs-bootstrap.css +12057 -0
- nicegui_bootstrap_components/static/dist/ngbs-cerulean-unscoped.css +12338 -0
- nicegui_bootstrap_components/static/dist/ngbs-cerulean.css +12348 -0
- nicegui_bootstrap_components/static/dist/ngbs-compat-unscoped.css +12 -0
- nicegui_bootstrap_components/static/dist/ngbs-compat.css +12 -0
- nicegui_bootstrap_components/static/dist/ngbs-cosmo-unscoped.css +11825 -0
- nicegui_bootstrap_components/static/dist/ngbs-cosmo.css +11835 -0
- nicegui_bootstrap_components/static/dist/ngbs-cyborg-unscoped.css +12213 -0
- nicegui_bootstrap_components/static/dist/ngbs-cyborg.css +12223 -0
- nicegui_bootstrap_components/static/dist/ngbs-darkly-unscoped.css +12143 -0
- nicegui_bootstrap_components/static/dist/ngbs-darkly.css +12153 -0
- nicegui_bootstrap_components/static/dist/ngbs-flatly-unscoped.css +12129 -0
- nicegui_bootstrap_components/static/dist/ngbs-flatly.css +12139 -0
- nicegui_bootstrap_components/static/dist/ngbs-grid-unscoped.css +4084 -0
- nicegui_bootstrap_components/static/dist/ngbs-grid.css +4094 -0
- nicegui_bootstrap_components/static/dist/ngbs-host-unscoped.css +9 -0
- nicegui_bootstrap_components/static/dist/ngbs-host.css +9 -0
- nicegui_bootstrap_components/static/dist/ngbs-icons-bootstrap.css +5 -0
- nicegui_bootstrap_components/static/dist/ngbs-icons-fontawesome.css +9 -0
- nicegui_bootstrap_components/static/dist/ngbs-journal-unscoped.css +12112 -0
- nicegui_bootstrap_components/static/dist/ngbs-journal.css +12122 -0
- nicegui_bootstrap_components/static/dist/ngbs-litera-unscoped.css +12214 -0
- nicegui_bootstrap_components/static/dist/ngbs-litera.css +12224 -0
- nicegui_bootstrap_components/static/dist/ngbs-lumen-unscoped.css +12377 -0
- nicegui_bootstrap_components/static/dist/ngbs-lumen.css +12387 -0
- nicegui_bootstrap_components/static/dist/ngbs-lux-unscoped.css +12048 -0
- nicegui_bootstrap_components/static/dist/ngbs-lux.css +12058 -0
- nicegui_bootstrap_components/static/dist/ngbs-materia-unscoped.css +13197 -0
- nicegui_bootstrap_components/static/dist/ngbs-materia.css +13207 -0
- nicegui_bootstrap_components/static/dist/ngbs-minty-unscoped.css +12184 -0
- nicegui_bootstrap_components/static/dist/ngbs-minty.css +12194 -0
- nicegui_bootstrap_components/static/dist/ngbs-morph-unscoped.css +12829 -0
- nicegui_bootstrap_components/static/dist/ngbs-morph.css +12839 -0
- nicegui_bootstrap_components/static/dist/ngbs-pulse-unscoped.css +11901 -0
- nicegui_bootstrap_components/static/dist/ngbs-pulse.css +11911 -0
- nicegui_bootstrap_components/static/dist/ngbs-quartz-unscoped.css +12625 -0
- nicegui_bootstrap_components/static/dist/ngbs-quartz.css +12635 -0
- nicegui_bootstrap_components/static/dist/ngbs-sandstone-unscoped.css +12214 -0
- nicegui_bootstrap_components/static/dist/ngbs-sandstone.css +12224 -0
- nicegui_bootstrap_components/static/dist/ngbs-simplex-unscoped.css +12199 -0
- nicegui_bootstrap_components/static/dist/ngbs-simplex.css +12209 -0
- nicegui_bootstrap_components/static/dist/ngbs-sketchy-unscoped.css +12518 -0
- nicegui_bootstrap_components/static/dist/ngbs-sketchy.css +12528 -0
- nicegui_bootstrap_components/static/dist/ngbs-slate-unscoped.css +12527 -0
- nicegui_bootstrap_components/static/dist/ngbs-slate.css +12537 -0
- nicegui_bootstrap_components/static/dist/ngbs-solar-unscoped.css +12152 -0
- nicegui_bootstrap_components/static/dist/ngbs-solar.css +12162 -0
- nicegui_bootstrap_components/static/dist/ngbs-spacelab-unscoped.css +12279 -0
- nicegui_bootstrap_components/static/dist/ngbs-spacelab.css +12289 -0
- nicegui_bootstrap_components/static/dist/ngbs-superhero-unscoped.css +12223 -0
- nicegui_bootstrap_components/static/dist/ngbs-superhero.css +12233 -0
- nicegui_bootstrap_components/static/dist/ngbs-united-unscoped.css +12090 -0
- nicegui_bootstrap_components/static/dist/ngbs-united.css +12100 -0
- nicegui_bootstrap_components/static/dist/ngbs-vapor-unscoped.css +12556 -0
- nicegui_bootstrap_components/static/dist/ngbs-vapor.css +12566 -0
- nicegui_bootstrap_components/static/dist/ngbs-yeti-unscoped.css +12333 -0
- nicegui_bootstrap_components/static/dist/ngbs-yeti.css +12343 -0
- nicegui_bootstrap_components/static/dist/ngbs-zephyr-unscoped.css +12296 -0
- nicegui_bootstrap_components/static/dist/ngbs-zephyr.css +12306 -0
- nicegui_bootstrap_components/static/prototype-ngbs.css +541 -0
- nicegui_bootstrap_components/static/webfonts/fa-brands-400.ttf +0 -0
- nicegui_bootstrap_components/static/webfonts/fa-brands-400.woff2 +0 -0
- nicegui_bootstrap_components/static/webfonts/fa-regular-400.ttf +0 -0
- nicegui_bootstrap_components/static/webfonts/fa-regular-400.woff2 +0 -0
- nicegui_bootstrap_components/static/webfonts/fa-solid-900.ttf +0 -0
- nicegui_bootstrap_components/static/webfonts/fa-solid-900.woff2 +0 -0
- nicegui_bootstrap_components/static/webfonts/fa-v4compatibility.ttf +0 -0
- nicegui_bootstrap_components/static/webfonts/fa-v4compatibility.woff2 +0 -0
- nicegui_bootstrap_components/theme.py +238 -0
- nicegui_bootstrap_components/themes.py +131 -0
- nicegui_bootstrap_components-0.1.0.dist-info/METADATA +234 -0
- nicegui_bootstrap_components-0.1.0.dist-info/RECORD +103 -0
- nicegui_bootstrap_components-0.1.0.dist-info/WHEEL +4 -0
- nicegui_bootstrap_components-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"""Native Bootstrap component surface (PascalCase classes, snake_case aliases)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from ._actions import Button, ButtonGroup, button, button_group
|
|
6
|
+
from ._alert_spinner import Alert, Spinner, alert, spinner
|
|
7
|
+
from ._carousel import Carousel, carousel
|
|
8
|
+
from ._choices import (
|
|
9
|
+
Checkbox,
|
|
10
|
+
Checklist,
|
|
11
|
+
RadioButton,
|
|
12
|
+
RadioItems,
|
|
13
|
+
Select,
|
|
14
|
+
Switch,
|
|
15
|
+
checkbox,
|
|
16
|
+
checklist,
|
|
17
|
+
radio_button,
|
|
18
|
+
radio_items,
|
|
19
|
+
select,
|
|
20
|
+
switch,
|
|
21
|
+
)
|
|
22
|
+
from ._content import (
|
|
23
|
+
Badge,
|
|
24
|
+
Card,
|
|
25
|
+
CardBody,
|
|
26
|
+
CardFooter,
|
|
27
|
+
CardGroup,
|
|
28
|
+
CardHeader,
|
|
29
|
+
CardImg,
|
|
30
|
+
CardImgOverlay,
|
|
31
|
+
CardLink,
|
|
32
|
+
ListGroup,
|
|
33
|
+
ListGroupItem,
|
|
34
|
+
Placeholder,
|
|
35
|
+
Progress,
|
|
36
|
+
Table,
|
|
37
|
+
badge,
|
|
38
|
+
card,
|
|
39
|
+
card_body,
|
|
40
|
+
card_footer,
|
|
41
|
+
card_group,
|
|
42
|
+
card_header,
|
|
43
|
+
card_img,
|
|
44
|
+
card_img_overlay,
|
|
45
|
+
card_link,
|
|
46
|
+
list_group,
|
|
47
|
+
list_group_item,
|
|
48
|
+
placeholder,
|
|
49
|
+
progress,
|
|
50
|
+
table,
|
|
51
|
+
)
|
|
52
|
+
from ._forms import (
|
|
53
|
+
Form,
|
|
54
|
+
FormFeedback,
|
|
55
|
+
FormFloating,
|
|
56
|
+
FormText,
|
|
57
|
+
InputGroup,
|
|
58
|
+
InputGroupText,
|
|
59
|
+
Label,
|
|
60
|
+
form,
|
|
61
|
+
form_feedback,
|
|
62
|
+
form_floating,
|
|
63
|
+
form_text,
|
|
64
|
+
input_group,
|
|
65
|
+
input_group_text,
|
|
66
|
+
label,
|
|
67
|
+
)
|
|
68
|
+
from ._inputs import Input, Textarea, input, textarea
|
|
69
|
+
from ._layout import Col, Container, Row, Stack, col, container, row, stack
|
|
70
|
+
from ._nav import (
|
|
71
|
+
Breadcrumb,
|
|
72
|
+
Nav,
|
|
73
|
+
NavItem,
|
|
74
|
+
NavLink,
|
|
75
|
+
Pagination,
|
|
76
|
+
breadcrumb,
|
|
77
|
+
nav,
|
|
78
|
+
nav_item,
|
|
79
|
+
nav_link,
|
|
80
|
+
pagination,
|
|
81
|
+
)
|
|
82
|
+
from ._navbar import (
|
|
83
|
+
Navbar,
|
|
84
|
+
NavbarBrand,
|
|
85
|
+
NavbarSimple,
|
|
86
|
+
NavbarToggler,
|
|
87
|
+
navbar,
|
|
88
|
+
navbar_brand,
|
|
89
|
+
navbar_simple,
|
|
90
|
+
navbar_toggler,
|
|
91
|
+
)
|
|
92
|
+
from ._overlays import (
|
|
93
|
+
Accordion,
|
|
94
|
+
AccordionItem,
|
|
95
|
+
Collapse,
|
|
96
|
+
DropdownMenu,
|
|
97
|
+
DropdownMenuItem,
|
|
98
|
+
Fade,
|
|
99
|
+
Modal,
|
|
100
|
+
ModalBody,
|
|
101
|
+
ModalFooter,
|
|
102
|
+
ModalHeader,
|
|
103
|
+
ModalTitle,
|
|
104
|
+
Offcanvas,
|
|
105
|
+
accordion,
|
|
106
|
+
accordion_item,
|
|
107
|
+
collapse,
|
|
108
|
+
dropdown_menu,
|
|
109
|
+
dropdown_menu_item,
|
|
110
|
+
fade,
|
|
111
|
+
modal,
|
|
112
|
+
modal_body,
|
|
113
|
+
modal_footer,
|
|
114
|
+
modal_header,
|
|
115
|
+
modal_title,
|
|
116
|
+
offcanvas,
|
|
117
|
+
)
|
|
118
|
+
from ._scope import Scope, scope
|
|
119
|
+
from ._tabs import Tab, Tabs, tab, tabs
|
|
120
|
+
from ._toast import Toast, toast
|
|
121
|
+
from ._tooltip_popover import (
|
|
122
|
+
Popover,
|
|
123
|
+
PopoverBody,
|
|
124
|
+
PopoverHeader,
|
|
125
|
+
Tooltip,
|
|
126
|
+
popover,
|
|
127
|
+
popover_body,
|
|
128
|
+
popover_header,
|
|
129
|
+
tooltip,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
__all__ = [
|
|
133
|
+
"Accordion",
|
|
134
|
+
"AccordionItem",
|
|
135
|
+
"Alert",
|
|
136
|
+
"Badge",
|
|
137
|
+
"Breadcrumb",
|
|
138
|
+
"Button",
|
|
139
|
+
"ButtonGroup",
|
|
140
|
+
"Card",
|
|
141
|
+
"CardBody",
|
|
142
|
+
"CardFooter",
|
|
143
|
+
"CardGroup",
|
|
144
|
+
"CardHeader",
|
|
145
|
+
"CardImg",
|
|
146
|
+
"CardImgOverlay",
|
|
147
|
+
"CardLink",
|
|
148
|
+
"Carousel",
|
|
149
|
+
"Checkbox",
|
|
150
|
+
"Checklist",
|
|
151
|
+
"Col",
|
|
152
|
+
"Collapse",
|
|
153
|
+
"Container",
|
|
154
|
+
"DropdownMenu",
|
|
155
|
+
"DropdownMenuItem",
|
|
156
|
+
"Fade",
|
|
157
|
+
"Form",
|
|
158
|
+
"FormFeedback",
|
|
159
|
+
"FormFloating",
|
|
160
|
+
"FormText",
|
|
161
|
+
"Input",
|
|
162
|
+
"InputGroup",
|
|
163
|
+
"InputGroupText",
|
|
164
|
+
"Label",
|
|
165
|
+
"ListGroup",
|
|
166
|
+
"ListGroupItem",
|
|
167
|
+
"Modal",
|
|
168
|
+
"ModalBody",
|
|
169
|
+
"ModalFooter",
|
|
170
|
+
"ModalHeader",
|
|
171
|
+
"ModalTitle",
|
|
172
|
+
"Nav",
|
|
173
|
+
"NavItem",
|
|
174
|
+
"NavLink",
|
|
175
|
+
"Navbar",
|
|
176
|
+
"NavbarBrand",
|
|
177
|
+
"NavbarSimple",
|
|
178
|
+
"NavbarToggler",
|
|
179
|
+
"Offcanvas",
|
|
180
|
+
"Pagination",
|
|
181
|
+
"Placeholder",
|
|
182
|
+
"Popover",
|
|
183
|
+
"PopoverBody",
|
|
184
|
+
"PopoverHeader",
|
|
185
|
+
"Progress",
|
|
186
|
+
"RadioButton",
|
|
187
|
+
"RadioItems",
|
|
188
|
+
"Row",
|
|
189
|
+
"Scope",
|
|
190
|
+
"Select",
|
|
191
|
+
"Spinner",
|
|
192
|
+
"Stack",
|
|
193
|
+
"Switch",
|
|
194
|
+
"Tab",
|
|
195
|
+
"Table",
|
|
196
|
+
"Tabs",
|
|
197
|
+
"Textarea",
|
|
198
|
+
"Toast",
|
|
199
|
+
"Tooltip",
|
|
200
|
+
"accordion",
|
|
201
|
+
"accordion_item",
|
|
202
|
+
"alert",
|
|
203
|
+
"badge",
|
|
204
|
+
"breadcrumb",
|
|
205
|
+
"button",
|
|
206
|
+
"button_group",
|
|
207
|
+
"card",
|
|
208
|
+
"card_body",
|
|
209
|
+
"card_footer",
|
|
210
|
+
"card_group",
|
|
211
|
+
"card_header",
|
|
212
|
+
"card_img",
|
|
213
|
+
"card_img_overlay",
|
|
214
|
+
"card_link",
|
|
215
|
+
"carousel",
|
|
216
|
+
"checkbox",
|
|
217
|
+
"checklist",
|
|
218
|
+
"col",
|
|
219
|
+
"collapse",
|
|
220
|
+
"container",
|
|
221
|
+
"dropdown_menu",
|
|
222
|
+
"dropdown_menu_item",
|
|
223
|
+
"fade",
|
|
224
|
+
"form",
|
|
225
|
+
"form_feedback",
|
|
226
|
+
"form_floating",
|
|
227
|
+
"form_text",
|
|
228
|
+
"input",
|
|
229
|
+
"input_group",
|
|
230
|
+
"input_group_text",
|
|
231
|
+
"label",
|
|
232
|
+
"list_group",
|
|
233
|
+
"list_group_item",
|
|
234
|
+
"modal",
|
|
235
|
+
"modal_body",
|
|
236
|
+
"modal_footer",
|
|
237
|
+
"modal_header",
|
|
238
|
+
"modal_title",
|
|
239
|
+
"nav",
|
|
240
|
+
"nav_item",
|
|
241
|
+
"nav_link",
|
|
242
|
+
"navbar",
|
|
243
|
+
"navbar_brand",
|
|
244
|
+
"navbar_simple",
|
|
245
|
+
"navbar_toggler",
|
|
246
|
+
"offcanvas",
|
|
247
|
+
"pagination",
|
|
248
|
+
"placeholder",
|
|
249
|
+
"popover",
|
|
250
|
+
"popover_body",
|
|
251
|
+
"popover_header",
|
|
252
|
+
"progress",
|
|
253
|
+
"radio_button",
|
|
254
|
+
"radio_items",
|
|
255
|
+
"row",
|
|
256
|
+
"scope",
|
|
257
|
+
"select",
|
|
258
|
+
"spinner",
|
|
259
|
+
"stack",
|
|
260
|
+
"switch",
|
|
261
|
+
"tab",
|
|
262
|
+
"table",
|
|
263
|
+
"tabs",
|
|
264
|
+
"textarea",
|
|
265
|
+
"toast",
|
|
266
|
+
"tooltip",
|
|
267
|
+
]
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"""Button family: Button, ButtonGroup (native + compat sibling types)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from .._base import BootstrapElement, make_surface_classes
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Button",
|
|
12
|
+
"ButtonGroup",
|
|
13
|
+
"DbcButton",
|
|
14
|
+
"DbcButtonGroup",
|
|
15
|
+
"button",
|
|
16
|
+
"button_dom_attrs",
|
|
17
|
+
"button_group",
|
|
18
|
+
"button_group_classes",
|
|
19
|
+
"button_structural_classes",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
_COLORS = frozenset(
|
|
23
|
+
{
|
|
24
|
+
"primary",
|
|
25
|
+
"secondary",
|
|
26
|
+
"success",
|
|
27
|
+
"info",
|
|
28
|
+
"warning",
|
|
29
|
+
"danger",
|
|
30
|
+
"light",
|
|
31
|
+
"dark",
|
|
32
|
+
"link",
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
_SIZES = frozenset({"sm", "lg", "md"})
|
|
36
|
+
_GROUP_SIZES = frozenset({"sm", "lg", "md"})
|
|
37
|
+
_TYPES = frozenset({"button", "reset", "submit"})
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def button_structural_classes(
|
|
41
|
+
*,
|
|
42
|
+
color: str,
|
|
43
|
+
outline: bool = False,
|
|
44
|
+
size: str | None = None,
|
|
45
|
+
active: bool = False,
|
|
46
|
+
disabled: bool = False,
|
|
47
|
+
as_link: bool = False,
|
|
48
|
+
) -> list[str]:
|
|
49
|
+
"""Return Bootstrap ``btn`` classes. Unknown colors raise ``ValueError``."""
|
|
50
|
+
if color not in _COLORS:
|
|
51
|
+
raise ValueError(f"Unknown Button color: {color!r}")
|
|
52
|
+
if size is not None and size not in _SIZES:
|
|
53
|
+
raise ValueError(f"Invalid Button size: {size!r}")
|
|
54
|
+
classes = ["btn"]
|
|
55
|
+
if color == "link":
|
|
56
|
+
classes.append("btn-link")
|
|
57
|
+
elif outline:
|
|
58
|
+
classes.append(f"btn-outline-{color}")
|
|
59
|
+
else:
|
|
60
|
+
classes.append(f"btn-{color}")
|
|
61
|
+
if size and size != "md":
|
|
62
|
+
classes.append(f"btn-{size}")
|
|
63
|
+
if active:
|
|
64
|
+
classes.append("active")
|
|
65
|
+
if disabled and as_link:
|
|
66
|
+
classes.append("disabled")
|
|
67
|
+
return classes
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def button_dom_attrs(
|
|
71
|
+
*,
|
|
72
|
+
href: str | None,
|
|
73
|
+
external_link: bool | None,
|
|
74
|
+
disabled: bool,
|
|
75
|
+
type: str = "button",
|
|
76
|
+
target: str | None = None,
|
|
77
|
+
download: str | bool | None = None,
|
|
78
|
+
name: str | None = None,
|
|
79
|
+
value: str | None = None,
|
|
80
|
+
) -> tuple[str, dict[str, Any]]:
|
|
81
|
+
"""Return ``(tag, attrs)``. Falsy href is omitted; ``external_link`` never leaks."""
|
|
82
|
+
if type not in _TYPES:
|
|
83
|
+
raise ValueError(f"Invalid Button type: {type!r}")
|
|
84
|
+
as_link = bool(href)
|
|
85
|
+
attrs: dict[str, Any] = {}
|
|
86
|
+
if as_link:
|
|
87
|
+
attrs["href"] = href
|
|
88
|
+
attrs["role"] = "button"
|
|
89
|
+
if external_link is True:
|
|
90
|
+
attrs["target"] = "_blank"
|
|
91
|
+
attrs["rel"] = "noopener noreferrer"
|
|
92
|
+
elif target:
|
|
93
|
+
attrs["target"] = target
|
|
94
|
+
if download is True:
|
|
95
|
+
attrs["download"] = True
|
|
96
|
+
elif download:
|
|
97
|
+
attrs["download"] = download
|
|
98
|
+
if disabled:
|
|
99
|
+
attrs["aria-disabled"] = "true"
|
|
100
|
+
attrs["tabindex"] = "-1"
|
|
101
|
+
else:
|
|
102
|
+
attrs["type"] = type
|
|
103
|
+
if disabled:
|
|
104
|
+
attrs["disabled"] = True
|
|
105
|
+
if name:
|
|
106
|
+
attrs["name"] = name
|
|
107
|
+
if value is not None and value != "":
|
|
108
|
+
attrs["value"] = value
|
|
109
|
+
return ("a" if as_link else "button", attrs)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def button_group_classes(*, size: str | None = None, vertical: bool = False) -> list[str]:
|
|
113
|
+
"""Return Bootstrap ``btn-group`` classes."""
|
|
114
|
+
if size is not None and size not in _GROUP_SIZES:
|
|
115
|
+
raise ValueError(f"Invalid ButtonGroup size: {size!r}")
|
|
116
|
+
classes = ["btn-group"]
|
|
117
|
+
if size in {"sm", "lg"}:
|
|
118
|
+
classes.append(f"btn-group-{size}")
|
|
119
|
+
if vertical:
|
|
120
|
+
classes.append("btn-group-vertical")
|
|
121
|
+
return classes
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _apply_dom_attrs(element: Any, attrs: dict[str, Any]) -> None:
|
|
125
|
+
parts: list[str] = []
|
|
126
|
+
for key, val in attrs.items():
|
|
127
|
+
if val is True:
|
|
128
|
+
parts.append(str(key))
|
|
129
|
+
elif val is False or val is None or val == "":
|
|
130
|
+
continue
|
|
131
|
+
else:
|
|
132
|
+
parts.append(f"{key}={val}")
|
|
133
|
+
if parts:
|
|
134
|
+
element.props(" ".join(parts))
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class _ButtonImpl(BootstrapElement):
|
|
138
|
+
"""Private Button implementation. Click listener is registered in ``__init__`` only."""
|
|
139
|
+
|
|
140
|
+
component_name = "Button"
|
|
141
|
+
children_kind = "phrasing"
|
|
142
|
+
reserved_classes = ("btn",)
|
|
143
|
+
|
|
144
|
+
def __init__(
|
|
145
|
+
self,
|
|
146
|
+
children: object = None,
|
|
147
|
+
*,
|
|
148
|
+
_surface: str,
|
|
149
|
+
color: str = "primary",
|
|
150
|
+
outline: bool = False,
|
|
151
|
+
size: str | None = None,
|
|
152
|
+
disabled: bool = False,
|
|
153
|
+
active: bool = False,
|
|
154
|
+
n_clicks: int = 0,
|
|
155
|
+
type: str = "button",
|
|
156
|
+
href: str | None = None,
|
|
157
|
+
external_link: bool | None = None,
|
|
158
|
+
download: str | bool | None = None,
|
|
159
|
+
target: str | None = None,
|
|
160
|
+
name: str | None = None,
|
|
161
|
+
value: str | None = None,
|
|
162
|
+
on_click: Callable[..., Any] | None = None,
|
|
163
|
+
**kwargs: Any,
|
|
164
|
+
) -> None:
|
|
165
|
+
self._surface = _surface
|
|
166
|
+
tag, attrs = button_dom_attrs(
|
|
167
|
+
href=href,
|
|
168
|
+
external_link=external_link,
|
|
169
|
+
disabled=disabled,
|
|
170
|
+
type=type,
|
|
171
|
+
target=target,
|
|
172
|
+
download=download,
|
|
173
|
+
name=name,
|
|
174
|
+
value=value,
|
|
175
|
+
)
|
|
176
|
+
self._structural_classes = tuple(
|
|
177
|
+
button_structural_classes(
|
|
178
|
+
color=color,
|
|
179
|
+
outline=outline,
|
|
180
|
+
size=size,
|
|
181
|
+
active=active,
|
|
182
|
+
disabled=disabled,
|
|
183
|
+
as_link=tag == "a",
|
|
184
|
+
)
|
|
185
|
+
)
|
|
186
|
+
self._desired_tag = tag
|
|
187
|
+
self._html_attrs = attrs
|
|
188
|
+
self._n_clicks = int(n_clicks)
|
|
189
|
+
self.disabled = bool(disabled)
|
|
190
|
+
self._on_click = on_click
|
|
191
|
+
super().__init__(children, tag=tag, **kwargs)
|
|
192
|
+
_apply_dom_attrs(self, attrs)
|
|
193
|
+
self.on("click", self._handle_click)
|
|
194
|
+
|
|
195
|
+
@property
|
|
196
|
+
def n_clicks(self) -> int:
|
|
197
|
+
"""Compat click counter (read-only observable)."""
|
|
198
|
+
return self._n_clicks
|
|
199
|
+
|
|
200
|
+
def _handle_click(self, *_args: Any, **_kwargs: Any) -> None:
|
|
201
|
+
if self.disabled:
|
|
202
|
+
return
|
|
203
|
+
self._n_clicks += 1
|
|
204
|
+
if self._on_click is not None:
|
|
205
|
+
self._on_click()
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class _ButtonGroupImpl(BootstrapElement):
|
|
209
|
+
"""Private ButtonGroup implementation."""
|
|
210
|
+
|
|
211
|
+
component_name = "ButtonGroup"
|
|
212
|
+
children_kind = "grouping"
|
|
213
|
+
|
|
214
|
+
def __init__(
|
|
215
|
+
self,
|
|
216
|
+
children: object = None,
|
|
217
|
+
*,
|
|
218
|
+
_surface: str,
|
|
219
|
+
size: str | None = None,
|
|
220
|
+
vertical: bool = False,
|
|
221
|
+
**kwargs: Any,
|
|
222
|
+
) -> None:
|
|
223
|
+
self._surface = _surface
|
|
224
|
+
self._structural_classes = tuple(button_group_classes(size=size, vertical=vertical))
|
|
225
|
+
super().__init__(children, **kwargs)
|
|
226
|
+
_apply_dom_attrs(self, {"role": "group"})
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
Button, DbcButton = make_surface_classes("Button", globals())
|
|
230
|
+
button = Button
|
|
231
|
+
ButtonGroup, DbcButtonGroup = make_surface_classes("ButtonGroup", globals())
|
|
232
|
+
button_group = ButtonGroup
|