xnano.utils.responsive
xnano.utils.responsive
¶
xnano.utils.responsive
Viewport breakpoints and zero-cost detection of responsive render hooks.
Grids and components may declare size-specific render variants
(grid_render_small, compose_large, …). They are opt-in: the base
class defines each as a marked no-op, and a class that overrides none
carries an empty override map — so the per-frame path skips all
breakpoint work entirely rather than probing methods every render.
Functions:
-
breakpoint_for_width–Return the breakpoint name for a viewport
widthin columns. -
responsive_noop–Mark a base render variant as an unoverridden no-op.
-
collect_responsive_overrides–Map each overridden
{prefix}{size}variant to its method name. -
resolve_responsive_variant–Return the variant method name for
width, orNone.
Attributes:
-
Breakpoint(TypeAlias) –One of the ordered viewport size names below.
-
BREAKPOINT_NAMES(tuple[Breakpoint, ...]) –Viewport size names, smallest to largest.
Breakpoint
module-attribute
¶
One of the ordered viewport size names below.
BREAKPOINT_NAMES
module-attribute
¶
BREAKPOINT_NAMES: tuple[Breakpoint, ...] = (
"extra_small",
"small",
"medium",
"large",
"extra_large",
)
Viewport size names, smallest to largest.
breakpoint_for_width
¶
breakpoint_for_width(width: int) -> Breakpoint
Return the breakpoint name for a viewport width in columns.
responsive_noop
¶
Mark a base render variant as an unoverridden no-op.
Detection compares against this marker rather than a base class, so the same helper works for grids and components without either needing to reference the other's base type during class creation.
Source code in xnano/utils/responsive.py
collect_responsive_overrides
¶
collect_responsive_overrides(
cls: type, prefix: str
) -> dict[Breakpoint, str]
Map each overridden {prefix}{size} variant to its method name.
Returns an empty dict when a class overrides none, which callers use to gate every breakpoint computation. Computed once per class at creation time.
Source code in xnano/utils/responsive.py
resolve_responsive_variant
¶
resolve_responsive_variant(
overrides: dict[Breakpoint, str] | None, width: int
) -> str | None
Return the variant method name for width, or None.
None means "use the base method": either the class overrides no
variants, or none covers the current breakpoint.