First Working version. I can add table
This commit is contained in:
50
src/components_helpers.py
Normal file
50
src/components_helpers.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from fasthtml.components import *
|
||||
|
||||
from core.utils import merge_classes
|
||||
|
||||
|
||||
def mk_icon(icon, size=20, can_select=True, cls='', **kwargs):
|
||||
merged_cls = merge_classes(f"icon-{size}",
|
||||
'icon-btn' if can_select else '',
|
||||
cls,
|
||||
kwargs)
|
||||
return Div(icon, cls=merged_cls, **kwargs)
|
||||
|
||||
|
||||
def mk_ellipsis(txt: str, cls='', **kwargs):
|
||||
merged_cls = merge_classes("truncate",
|
||||
cls,
|
||||
kwargs)
|
||||
return Div(txt, cls=merged_cls, data_tooltip=txt, **kwargs)
|
||||
|
||||
|
||||
def mk_tooltip_container(component_id):
|
||||
return Div(id=f"tt_{component_id}", style="position: fixed; z-index: 1000;", cls="mmt-tooltip-container"),
|
||||
|
||||
|
||||
def mk_dialog_buttons(ok_title: str = "OK", cancel_title: str = "Cancel", on_ok: dict = None, on_cancel: dict = None):
|
||||
if on_ok is None:
|
||||
on_ok = {}
|
||||
if on_cancel is None:
|
||||
on_cancel = {}
|
||||
|
||||
return Div(
|
||||
Div(
|
||||
Button(ok_title, cls="btn btn-primary btn-sm mr-2", **on_ok),
|
||||
Button(cancel_title, cls="btn btn-ghost btn-sm", **on_cancel),
|
||||
cls="flex justify-end"
|
||||
),
|
||||
cls="flex justify-end w-full"
|
||||
)
|
||||
|
||||
|
||||
def mk_select_option(option: str, value=None, selected_value: str = None, selected=False, enabled=True):
|
||||
attrs = {}
|
||||
if value is not None:
|
||||
attrs["value"] = value
|
||||
if selected_value == option or selected is True:
|
||||
attrs["selected"] = True
|
||||
if not enabled:
|
||||
attrs["disabled"] = True
|
||||
|
||||
return Option(option, **attrs)
|
||||
Reference in New Issue
Block a user