From 1956f7f9d768f888ae437857af44108c1528a3f8 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 9 Feb 2023 15:36:04 +0000 Subject: [PATCH] Rename the switch--switch component class to switch--slider Following on from #1751: originally Switch was called Checkbox and the moving part was, for the component class, called a checkbox--switch; after renaming the widget to Switch that component class ended up being switch--switch; which wasn't ideal. We decided to go with it as-is, but I just realised that internally the code calls it a slider. So this leans into that and I'm renaming the component class switch--slider. This removes the doubling-up of the name and also makes the code more consistent. --- docs/examples/widgets/switch.css | 2 +- src/textual/widgets/_switch.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/examples/widgets/switch.css b/docs/examples/widgets/switch.css index fb6a0d220..20fd57ba8 100644 --- a/docs/examples/widgets/switch.css +++ b/docs/examples/widgets/switch.css @@ -22,7 +22,7 @@ Switch { background: darkslategrey; } -#custom-design > .switch--switch { +#custom-design > .switch--slider { color: dodgerblue; background: darkslateblue; } diff --git a/src/textual/widgets/_switch.py b/src/textual/widgets/_switch.py index cdc9f21a6..f6aa88601 100644 --- a/src/textual/widgets/_switch.py +++ b/src/textual/widgets/_switch.py @@ -31,12 +31,12 @@ class Switch(Widget, can_focus=True): """ COMPONENT_CLASSES: ClassVar[set[str]] = { - "switch--switch", + "switch--slider", } """ | Class | Description | | :- | :- | - | `switch--switch` | Targets the switch of the switch. | + | `switch--slider` | Targets the slider of the switch. | """ DEFAULT_CSS = """ @@ -48,7 +48,7 @@ class Switch(Widget, can_focus=True): padding: 0 2; } - Switch > .switch--switch { + Switch > .switch--slider { background: $panel-darken-2; color: $panel-lighten-2; } @@ -65,7 +65,7 @@ class Switch(Widget, can_focus=True): } - Switch.-on > .switch--switch { + Switch.-on > .switch--slider { color: $success; } """ @@ -128,7 +128,7 @@ class Switch(Widget, can_focus=True): self.set_class(slider_pos == 1, "-on") def render(self) -> RenderableType: - style = self.get_component_rich_style("switch--switch") + style = self.get_component_rich_style("switch--slider") return ScrollBarRender( virtual_size=100, window_size=50,