Add success/warning/error button variants

This commit is contained in:
Darren Burns
2022-06-10 15:05:48 +01:00
committed by Will McGugan
parent 7c33bf9937
commit 8d6a4adff8
4 changed files with 220 additions and 31 deletions

View File

@@ -1,12 +1,4 @@
#foo {
text-style: underline;
background: rebeccapurple;
}
*:focus {
tint: yellow 50%;
}
#foo:hover {
background: greenyellow;
Button {
padding-left: 1;
padding-right: 1;
}

View File

@@ -1,21 +1,30 @@
from textual import layout, events
from textual.app import App, ComposeResult
from textual.widgets import Button
from textual import layout
class ButtonsApp(App[str]):
def compose(self) -> ComposeResult:
yield layout.Vertical(
Button("foo", id="foo"),
Button("bar", id="bar"),
Button("baz", id="baz"),
Button("default", id="foo"),
Button.success("success", id="bar"),
Button.warning("warning", id="baz"),
Button.error("error", id="baz"),
)
def handle_pressed(self, event: Button.Pressed) -> None:
self.app.bell()
self.log("pressed", event.button.id)
self.exit(event.button.id)
print("pressed", event.button.id)
async def on_key(self, event: events.Key) -> None:
await self.dispatch_key(event)
def key_a(self):
print(f"text-success: {self.stylesheet.variables.get('text-success')}")
print(
f"text-success-darken-1: {self.stylesheet.variables.get('text-success-darken-1')}"
)
self.dark = not self.dark
app = ButtonsApp(