Added first controls

This commit is contained in:
2025-11-26 20:53:12 +01:00
parent 459c89bae2
commit ce5328fe34
68 changed files with 37849 additions and 87048 deletions

View File

@@ -5,12 +5,33 @@ from myfasthtml.core.commands import Command
from myfasthtml.core.utils import merge_classes
class Ids:
# Please keep the alphabetical order
Root = "mf-root"
UserSession = "mf-user_session"
class mk:
@staticmethod
def button(element, command: Command = None, binding: Binding = None, **kwargs):
return mk.mk(Button(element, **kwargs), command=command, binding=binding)
@staticmethod
def dialog_buttons(ok_title: str = "OK",
cancel_title: str = "Cancel",
on_ok: Command = None,
on_cancel: Command = None,
cls=None):
return Div(
Div(
mk.button(ok_title, cls="btn btn-primary btn-sm mr-2", command=on_ok),
mk.button(cancel_title, cls="btn btn-ghost btn-sm", command=on_cancel),
cls="flex justify-end"
),
cls=merge_classes("flex justify-end w-full mt-1", cls)
)
@staticmethod
def icon(icon, size=20,
can_select=True,
@@ -27,6 +48,27 @@ class mk:
return mk.mk(Div(icon, cls=merged_cls, **kwargs), command=command, binding=binding)
@staticmethod
def label(text: str,
icon=None,
size: str = "sm",
cls='',
command: Command = None,
binding: Binding = None,
**kwargs):
merged_cls = merge_classes("flex", cls, kwargs)
icon_part = Span(icon, cls=f"mf-icon-{mk.convert_size(size)} mr-1") if icon else None
text_part = Span(text, cls=f"text-{size}")
return mk.mk(Label(icon_part, text_part, cls=merged_cls, **kwargs), command=command, binding=binding)
@staticmethod
def convert_size(size: str):
return (size.replace("xs", "16").
replace("sm", "20").
replace("md", "24").
replace("lg", "28").
replace("xl", "32"))
@staticmethod
def manage_command(ft, command: Command):
if command:
@@ -50,6 +92,6 @@ class mk:
@staticmethod
def mk(ft, command: Command = None, binding: Binding = None, init_binding=True):
ft = mk.manage_command(ft, command)
ft = mk.manage_binding(ft, binding, init_binding=init_binding)
ft = mk.manage_command(ft, command) if command else ft
ft = mk.manage_binding(ft, binding, init_binding=init_binding) if binding else ft
return ft