Last active
April 1, 2025 19:50
-
-
Save xaptronic/241704b03fb1fe2d4754cf127e614fa9 to your computer and use it in GitHub Desktop.
nicegui_tldr text component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nicegui import ui | |
from nicegui.element import Element | |
class TLDR(Element): | |
""" | |
from nicegui import ui | |
from vaultscope.components import tldr | |
project_details = tldr( | |
"What will become better/faster/possible?", | |
"The summary of the project goal goes here.", | |
"**What does success look like?**", | |
"Full detailed information about the project's success criteria goes here.", | |
) | |
with project_details.details: | |
with ui.card(): | |
ui.label("WOW") | |
# Run the app | |
ui.run(port=9900) | |
""" | |
def __init__( | |
self, | |
summary_title, | |
summary_md, | |
details_title, | |
details_md, | |
expanded=False, | |
more_text="More", | |
less_text="Less", | |
): | |
super().__init__("div") # Assuming Element uses 'div' | |
self.summary_title = summary_title | |
self.summary_md = summary_md | |
self.details_title = details_title | |
self.details_md = details_md | |
self.expanded = expanded | |
self.more_text = more_text | |
self.less_text = less_text | |
self.details = None | |
self._create_ui() | |
def _create_ui(self): | |
with self: | |
with ui.column().classes("gap-0"): | |
ui.label(self.summary_title).classes("text-lg") | |
ui.markdown(self.summary_md) | |
self.more_link = ui.link(self.more_text).classes("text-xs") | |
self.more_link.on("click", self.expand) | |
self.less_link = ui.link(self.less_text).classes("text-xs") | |
self.less_link.on("click", self.collapse) | |
self.less_link.set_visibility(self.expanded) | |
self.details = ui.column().classes("gap-0") | |
self.details.set_visibility(self.expanded) | |
with self.details: | |
ui.markdown(self.details_title) | |
ui.markdown(self.details_md) | |
def expand(self): | |
self.details.set_visibility(True) | |
self.more_link.set_visibility(False) | |
self.less_link.set_visibility(True) | |
def collapse(self): | |
self.details.set_visibility(False) | |
self.more_link.set_visibility(True) | |
self.less_link.set_visibility(False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment