11from __future__ import annotations
22
33from enum import Enum
4- from typing import Dict , Iterable , Optional , TypeVar , Union , cast
4+ from typing import Dict , Iterable , Literal , Optional , Tuple , TypeVar , Union , cast
55from warnings import warn
66
77from htmltools import Tag , TagAttrs , TagAttrValue , TagChild , css
1515T = TypeVar ("T" )
1616
1717
18- class Breakpoints (Enum ):
19- """
20- References
21- ----------
22- * [Available Bootstrap breakpoints](https://getbootstrap.com/docs/5.3/layout/breakpoints/#available-breakpoints)
23- """
18+ Breakpoint = Literal ["xs" , "sm" , "md" , "lg" , "xl" , "xxl" ]
19+ """
20+ References
21+ ----------
22+ * [Available Bootstrap breakpoints](https://getbootstrap.com/docs/5.3/layout/breakpoints/#available-breakpoints)
23+ """
24+
2425
25- xs = "xs"
26- sm = "sm"
27- md = "md"
28- lg = "lg"
29- xl = "xl"
30- xxl = "xxl"
26+ breakpoints : Tuple [Breakpoint , ...] = ("xs" , "sm" , "md" , "lg" , "xl" , "xxl" )
3127
3228
33- BreakpointsSoft = Dict [Breakpoints , Union [Iterable [T ], T , None ]]
34- BreakpointsOptional = Dict [Breakpoints , Union [Iterable [T ], None ]]
35- BreakpointsComplete = Dict [Breakpoints , Iterable [T ]]
29+ BreakpointsSoft = Dict [Breakpoint , Union [Iterable [T ], T , None ]]
30+ BreakpointsOptional = Dict [Breakpoint , Union [Iterable [T ], None ]]
31+ BreakpointsComplete = Dict [Breakpoint , Iterable [T ]]
3632BreakpointsUser = Union [BreakpointsSoft [T ], Iterable [T ], T , None ]
3733
3834
@@ -155,16 +151,15 @@ def as_col_spec(
155151 return None
156152
157153 if not isinstance (col_widths , Dict ):
158- return {Breakpoints . md : validate_col_width (col_widths , n_kids , Breakpoints . md )}
154+ return {"md" : validate_col_width (col_widths , n_kids , "md" )}
159155
160156 ret : BreakpointsOptional [int ] = {}
161157 col_widths_items = cast (BreakpointsSoft [int ], col_widths ).items ()
162158
163159 for brk , value in col_widths_items :
164- bs_breakpoints = [str (bp .value ) for bp in Breakpoints ]
165- if str (brk ) not in bs_breakpoints :
160+ if brk not in breakpoints :
166161 raise ValueError (
167- f"Breakpoint '{ brk } ' is not valid. Valid breakpoints are: { ', ' .join (bs_breakpoints )} '."
162+ f"Breakpoint '{ brk } ' is not valid. Valid breakpoints are: { ', ' .join (breakpoints )} '."
168163 )
169164
170165 if value is None :
@@ -180,7 +175,7 @@ def as_col_spec(
180175
181176
182177def validate_col_width (
183- x : Iterable [int ] | int , n_kids : int , break_name : Breakpoints
178+ x : Iterable [int ] | int , n_kids : int , break_name : Breakpoint
184179) -> Iterable [int ]:
185180 if isinstance (x , int ):
186181 y = [x ]
@@ -266,9 +261,7 @@ def row_heights_attrs(
266261 # row height is derived from xs or defaults to auto in the CSS, so we don't need the
267262 # class to activate it
268263 classes = [
269- f"bslib-grid--row-heights--{ brk } "
270- for brk in x_complete .keys ()
271- if brk != Breakpoints .xs
264+ f"bslib-grid--row-heights--{ brk } " for brk in x_complete .keys () if brk != "xs"
272265 ]
273266
274267 # Create CSS variables, treating numeric values as fractional units, passing strings
0 commit comments