mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Widget collapsible (#2989)
* Collapsible container widget. * Expose collapsible widget. * Add collapsible container example * Rename member variables as label and apply formatting * Apply hover effect * Apply formatting * Add collapsible construction example with children. * Wrap contents within Container and move _collapsed flag to Collapsible class from Summary for easier access. * Add collapsible example that is expanded by default. * Update collapsed property to be reactive * Add footer to collapse and expand all with bound keys. * Expose summary property of Collapsible * Assign ids of ollapsed, expanded label instead of classes * Add unit tests of Collapsible * Rename class Summary to Title * Rename variables of expanded/collapsed symbols and add it to arguments.. * Add documentation for Collapsible * Update symbol ids of Collapsible title * Update src/textual/widgets/_collapsible.py Correct import path Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> * Sort module names in alphabetical order * Clarify that collapsible is non-focusable in documentation. * Add version hint * Fix documentation of Collapsible. * Add snapshot test for collapsible widget * Stop on click event from Collapsible. * Handle Title.Toggle event to prevent event in Contents from propagating to the children or parents Collapsible widgets. * Update Collapsible default css to have 1 fraction of width instead of 100% * Update Collapsible custom symbol snapshot * Add Collapsible custom symbol snapshot as an example * Update docs/widgets/collapsible.md Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> * Update src/textual/widgets/_collapsible.py Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> * Fix typo in Collapsible docs * Rework collapsible documentation. --------- Co-authored-by: Sunyoung Yoo <luysunyoung@aifactory.page> Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
This commit is contained in:
47
docs/examples/widgets/collapsible.py
Normal file
47
docs/examples/widgets/collapsible.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Collapsible, Footer, Label, Markdown
|
||||
|
||||
LETO = """
|
||||
# Duke Leto I Atreides
|
||||
|
||||
Head of House Atreides.
|
||||
"""
|
||||
|
||||
JESSICA = """
|
||||
# Lady Jessica
|
||||
|
||||
Bene Gesserit and concubine of Leto, and mother of Paul and Alia.
|
||||
"""
|
||||
|
||||
PAUL = """
|
||||
# Paul Atreides
|
||||
|
||||
Son of Leto and Jessica.
|
||||
"""
|
||||
|
||||
|
||||
class CollapsibleApp(App[None]):
|
||||
"""An example of colllapsible container."""
|
||||
|
||||
BINDINGS = [
|
||||
("c", "collapse_or_expand(True)", "Collapse All"),
|
||||
("e", "collapse_or_expand(False)", "Expand All"),
|
||||
]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
"""Compose app with collapsible containers."""
|
||||
yield Footer()
|
||||
with Collapsible(collapsed=False, title="Leto"):
|
||||
yield Label(LETO)
|
||||
yield Collapsible(Markdown(JESSICA), collapsed=False, title="Jessica")
|
||||
with Collapsible(collapsed=True, title="Paul"):
|
||||
yield Markdown(PAUL)
|
||||
|
||||
def action_collapse_or_expand(self, collapse: bool) -> None:
|
||||
for child in self.walk_children(Collapsible):
|
||||
child.collapsed = collapse
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = CollapsibleApp()
|
||||
app.run()
|
||||
25
docs/examples/widgets/collapsible_custom_symbol.py
Normal file
25
docs/examples/widgets/collapsible_custom_symbol.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.containers import Horizontal
|
||||
from textual.widgets import Collapsible, Label
|
||||
|
||||
|
||||
class CollapsibleApp(App[None]):
|
||||
def compose(self) -> ComposeResult:
|
||||
with Horizontal():
|
||||
with Collapsible(
|
||||
collapsed_symbol=">>>",
|
||||
expanded_symbol="v",
|
||||
):
|
||||
yield Label("Hello, world.")
|
||||
|
||||
with Collapsible(
|
||||
collapsed_symbol=">>>",
|
||||
expanded_symbol="v",
|
||||
collapsed=False,
|
||||
):
|
||||
yield Label("Hello, world.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = CollapsibleApp()
|
||||
app.run()
|
||||
14
docs/examples/widgets/collapsible_nested.py
Normal file
14
docs/examples/widgets/collapsible_nested.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Collapsible, Label
|
||||
|
||||
|
||||
class CollapsibleApp(App[None]):
|
||||
def compose(self) -> ComposeResult:
|
||||
with Collapsible(collapsed=False):
|
||||
with Collapsible():
|
||||
yield Label("Hello, world.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = CollapsibleApp()
|
||||
app.run()
|
||||
Reference in New Issue
Block a user