11from textual .app import App , ComposeResult
2+ from textual .color import COLOR_NAME_TO_RGB , Color
23from textual .containers import Horizontal , Vertical , VerticalScroll
34from textual .design import ColorSystem
4- from textual .widgets import Button , Footer , Label , Static
5+ from textual .widgets import Button , Footer , Label , Static , TabbedContent
56
67
7- class ColorButtons (VerticalScroll ):
8+ class ThemeColorButtons (VerticalScroll ):
89 def compose (self ) -> ComposeResult :
9- for border in ColorSystem .COLOR_NAMES :
10- if border :
11- yield Button (border , id = border )
10+ for color_name in ColorSystem .COLOR_NAMES :
11+ yield Button (color_name , id = color_name )
1212
1313
1414class ColorBar (Static ):
@@ -28,6 +28,26 @@ class Content(Vertical):
2828
2929
3030class ColorsView (VerticalScroll ):
31+ pass
32+
33+
34+ class ColorTabs (TabbedContent , inherit_css = False ):
35+ pass
36+
37+
38+ class NamedColorsView (ColorsView ):
39+ def compose (self ) -> ComposeResult :
40+ with ColorGroup (id = f"group-named" ):
41+ for name , rgb in COLOR_NAME_TO_RGB .items ():
42+ color = Color (* rgb )
43+ with ColorItem () as ci :
44+ ci .styles .background = name
45+ yield ColorBar (name , classes = "text" )
46+ yield ColorBar (f"{ color .hex6 } " , classes = "text" )
47+ yield ColorBar (f"{ color .rgb } " , classes = "text text-left" )
48+
49+
50+ class ThemeColorsView (ColorsView ):
3151 def compose (self ) -> ComposeResult :
3252 LEVELS = [
3353 "darken-3" ,
@@ -56,15 +76,17 @@ class ColorsApp(App[None]):
5676 BINDINGS = [("d" , "toggle_dark" , "Toggle dark mode" )]
5777
5878 def compose (self ) -> ComposeResult :
59- yield Content (ColorButtons ())
6079 yield Footer ()
80+ with ColorTabs ("Theme Colors" , "Named Colors" ):
81+ yield Content (ThemeColorButtons ())
82+ yield Vertical (NamedColorsView ())
6183
6284 def on_mount (self ) -> None :
6385 self .call_after_refresh (self .update_view )
6486
6587 def update_view (self ) -> None :
6688 content = self .query_one ("Content" , Content )
67- content .mount (ColorsView ())
89+ content .mount (ThemeColorsView ())
6890
6991 def on_button_pressed (self , event : Button .Pressed ) -> None :
7092 self .query (ColorGroup ).remove_class ("-active" )
0 commit comments