Expose properties of Quasar widgets as properties of NiceGUI elements #384
Replies: 2 comments 2 replies
-
Example of how the definition of a Button would look, with some of the properties exposed: from nicegui.element import Element
from nicegui import ui
class QButton(Element):
"""Quasar has a component called QBtn which is a button with a few extra useful features. For instance, it comes in two shapes: rectangle (default) and round. It also has the material ripple effect baked in (which can be disabled).
The button component also comes with a spinner or loading effect. You would use this for times when app execution may cause a delay and you want to give the user some feedback about that delay. When used, the button will display a spinning animation as soon as the user clicks the button.
"""
def __init__(self, label: str = "", icon: str = "") -> None:
super().__init__("q-btn")
self.set_label(label)
self.set_icon(icon)
def set_label(self, label: str):
"""[label]: String | Number
Description: The text that will be shown on the button
Example: [Button Label]
"""
self._props["label"] = label
def set_icon(self, icon: str):
"""[icon]: String
Description: Icon name following Quasar convention; Make sure you have the icon library installed unless you are using 'img:' prefix; If 'none' (String) is used as value then no icon is rendered (but screen real estate will still be used for it)
Examples: [map] [ion-add] [img:https://cdn.quasar.dev/logo-v2/svg/logo.svg] [img:path/to/some_image.png]
"""
self._props["icon"] = icon
def set_round(self, round: bool):
"""[round]: Boolean
Description: Makes a circle shaped button
"""
self._props["round"] = round
btn = QButton(label="Test", icon="layers_clear")
ui.run() |
Beta Was this translation helpful? Give feedback.
-
Oops, I chose In this case, I tested it yesterday with some Quasar elements, and I replaced the The properties are exposed within these classes, like functions, which receive the value to be set as an argument. I didn't mind adding the
Example of use: from nicegui import ui
from quasar import *
el_1 = avatar("clock")
el_1.qcontent.icon("directions")
el_1.qstyle.color("pink")
el_2 = badge()
el_2.qcontent.label("Hello")
el_2.qcontent.align("center")
el_2.qstyle.color("blue")
el_2.qstyle.outline(True)
el_3 = banner()
el_3.qcontent.inline_actions(True)
el_3.qstyle.rounded(True)
el_3.qstyle.dense(False)
with el_3.style(add="background: red; color: white;"):
ui.label("Hello")
ui.label("World")
el_4 = bar()
el_4.qstyle.dark(True)
el_4.qstyle.dense(True)
with el_4.style(add="background: red; color: white;"):
ui.label("File")
ui.label("Edit")
ui.label("View")
ui.label("Tools")
el_5 = breadcrumbs()
with el_5:
el_5_1 = breadcrumbsEl()
el_5_1.qcontent.label("Home")
el_5_1.qnavigation.href("/")
el_5_1.qstate.disabled(True)
el_5_2 = breadcrumbsEl()
el_5_2.qcontent.label("File")
el_5_2.qnavigation.href("/file")
el_5_1.qnavigation.target("_blank")
ui.run(title="Quasar Example") |
Beta Was this translation helpful? Give feedback.
-
Quasar's widgets have several interesting props, which the NiceGUI developer would only discover by reading Quasar's documentation.
Wouldn't it be interesting to expose these props as properties of NiceGUI elements?
Probably a
ui.button().color = "#000000"
would be extremely useful/cool. I don't know how far I would go to do the direct conversion, since the props are inside the_props
dictionary.Perhaps some
set_xxxx
functions would be ideal, and it would still leave the option to expose docstrings explaining each of the 'configurable' properties.Beta Was this translation helpful? Give feedback.
All reactions