Update sandbox example to test animated dark mode toggle

This commit is contained in:
Darren Burns
2022-10-20 10:01:24 +01:00
parent c793869f65
commit ad2af62029
2 changed files with 18 additions and 4 deletions

View File

@@ -0,0 +1,8 @@
* {
transition: color 300ms linear, background 300ms linear;
}
#another-box {
background: $boost;
padding: 1 2;
}

View File

@@ -1,4 +1,5 @@
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.color import Color
from textual.widgets import Static
@@ -7,11 +8,16 @@ END_COLOR = Color.parse("#0000FF0F")
class ColorAnimate(App):
BINDINGS = [Binding("d", action="toggle_dark", description="Dark mode")]
def compose(self) -> ComposeResult:
box = Static("Hello, world", id="box")
box.styles.background = START_COLOR
self.box = box
yield box
self.box = Static("Hello, world", id="box")
self.box.styles.background = START_COLOR
self.another_box = Static("Another box with $boost", id="another-box")
yield self.box
yield self.another_box
def key_a(self):
self.animator.animate(self.box.styles, "background", END_COLOR, duration=2.0)