🧩 Components

Material Design components for FastHTML using BeerCSS

🎯 Overview

This module provides a comprehensive set of Material Design components for building FastHTML applications.

Category Components Purpose
πŸ”˜ Buttons ButtonT, NavToggleButton Button variants and navigation toggles
πŸ”— Links AT (AnchorChain) Styled anchor/link variants
πŸ“ Layout Grid, GridCell, DivHStacked, DivVStacked, DivCentered Grid system and flex layouts
🎨 Icons Icon Material Design icons
🧭 Navigation NavBar, NavContainer, NavSideBarContainer, BottomNav Navigation components
πŸ’¬ Modals Modal, ModalButton, ModalTitle, ModalBody, ModalFooter Dialog windows
πŸ“ Forms Field, LabelInput, CheckboxX, Radio, Switch, TextArea, Range, Select, FormGrid Form inputs and layout
⏳ Feedback Progress, LoadingIndicator, Toast, Snackbar Loading and notifications
πŸ“Š Tables Table, Td, Th, TableFromLists, TableFromDicts, Pagination Data tables
πŸƒ Cards Card, Toolbar Content containers
πŸ”€ Typography TextT, TextPresets, CodeSpan, CodeBlock, Blockquote Text styling
πŸͺ Misc FAQItem, CookiesBanner, Divider, Avatar Utility components

πŸ“š Table of Contents

  1. πŸ”˜ Buttons - Button variants and chains
  2. πŸ”— Anchor - Link styling
  3. πŸ“ Grid - Grid system and layout
  4. 🎨 Icon - Material icons
  5. 🧭 NavBar - Top navigation
  6. πŸ’¬ Modal Dialog - Dialogs and popups
  7. πŸ“ Label Input - Input fields with labels
  8. 🏷️ Form Label - Standalone form labels
  9. β˜‘οΈ Checkbox - Checkbox inputs
  10. πŸ”˜ Radio - Radio buttons
  11. πŸ”€ Switch - Toggle switches
  12. πŸ“„ Text Area - Multi-line text
  13. πŸ“Š Range - Slider inputs
  14. πŸ“‹ Select - Dropdown menus
  15. πŸ“ FormGrid - Form layouts
  16. πŸ“ˆ Progress - Progress bars
  17. ⏳ Loading Indicator - Spinners
  18. πŸ“Š Tables - Data tables
  19. πŸ“„ Pagination - Page navigation
  20. πŸƒ Card - Content cards
  21. πŸ”§ Toolbar - Action bars
  22. πŸ”” Toast / Snackbar - Notifications
  23. πŸ“¦ Nav Container - Navigation drawers
  24. πŸ“‘ Sidebar - Side navigation
  25. πŸ”€ Typography - Text styling

πŸ”˜ Buttons

Button variants and navigation toggle helpers.

Export Description
ButtonT Chainable button styles (ButtonT.primary, ButtonT.secondary, etc.)
NavToggleButton Button that toggles navigation rail visibility

πŸ’‘ Use case: Button("Click", cls=ButtonT.primary.large) creates a large primary button.


source

πŸ”— Anchor

Chainable anchor/link styles.

Export Description
AT Chainable anchor styles (AT.primary, AT.chip, AT.button, etc.)

πŸ’‘ Use case: A("Learn More", href="/docs", cls=AT.button.primary) creates a button-styled link.

Code
def ex_links(): 
    return Article(
        A('Default Link'),
        Hr(),
        A('Muted Link', cls=AT.muted),
        Hr(),
        A('Text Link',  cls=AT.text), 
        Hr(),
        A('Reset Link', cls=AT.reset), 
        Hr(),
        A('Primary Link', cls=AT.primary), 
        Hr(),
        A('Classic Link', cls=AT.classic),  
        Hr(),
        cls="padding")

preview(ex_links())

πŸ“ Grid

Responsive grid system and flex layout helpers.

Export Description
Grid Responsive grid container
GridCell Grid cell with span control
SpaceT Spacing enum (SpaceT.small_space, etc.)
GridSpanT Grid span enum
DivHStacked Horizontal flex container
DivVStacked Vertical flex container
DivCentered Centered flex container
DivFullySpaced Space-between flex container
DivLAligned / DivRAligned Left/right aligned containers

Grid Parameters

Parameter Default Description
cells - Grid children, auto-wrapped with span classes based on cols
space SpaceT.medium_space Spacing between grid cells
cols_min 1 Minimum columns at smallest breakpoint
cols_max 4 Maximum columns at largest breakpoint
cols None Fixed column count for all breakpoints
cols_sm None Column count for small screens
cols_md None Column count for medium screens
cols_lg None Column count for large screens
responsive True Center grid with responsive max-width
padding True Add padding around the grid

GridCell Parameters

Parameter Description
span String like 's12 m6 l4' or tuple of GridSpanT values
cls Additional CSS classes

πŸ’‘ Use case: Grid(GridCell("A", span=6), GridCell("B", span=6)) creates a 2-column layout.


source

Grid


def Grid(
    cells:VAR_POSITIONAL, space:SpaceT=<SpaceT.medium_space: 'medium-space'>, cols_min:int=1, cols_max:int=4,
    cols:int=None, cols_sm:int=None, cols_md:int=None, cols_lg:int=None, responsive:bool=True, padding:bool=True,
    cls:str='', kwargs:VAR_KEYWORD
):

BeerCSS responsive grid with smart column defaults and mobile-first design.

MonsterUI-compatible API: cols parameter auto-derives responsive breakpoints: cols=4 -> cols_sm=1, cols_md=2, cols_lg=4 (mobile stacks, tablet halves, desktop full)

For explicit control, use cols_sm, cols_md, cols_lg directly.


source

GridCell


def GridCell(
    c:VAR_POSITIONAL, span:tuple=(), cls:str='', kwargs:VAR_KEYWORD
):

Wrap content as a BeerCSS grid cell with responsive span control.


source

GridSpanT


def GridSpanT(
    args:VAR_POSITIONAL, kwds:VAR_KEYWORD
):

Grid span classes for responsive layouts (BeerCSS)


source

SpaceT


def SpaceT(
    args:VAR_POSITIONAL, kwds:VAR_KEYWORD
):

Space types using BeerCSS spacing classes

Code
def ex_grid():
    return Grid(
        Div(
            P("Column 1 Item 1"), 
            P("Column 1 Item 2"), 
            P("Column 1 Item 3")),
        Div(
            P("Column 2 Item 1"), 
            P("Column 2 Item 2"), 
            P("Column 2 Item 2")),
        Div(
            P("Column 3 Item 1"), 
            P("Column 3 Item 2"), 
            P("Column 3 Item 3")))


preview(ex_grid())
Code
def ex_product_grid():
    products = [
        {"name": "Laptop", "price": "$999", "img": "https://picsum.photos/200/100?random=1"},
        {"name": "Smartphone", "price": "$599", "img": "https://picsum.photos/200/100?random=2"},
        {"name": "Headphones", "price": "$199", "img": "https://picsum.photos/200/100?random=3"},
        {"name": "Smartwatch", "price": "$299", "img": "https://picsum.photos/200/100?random=4"},
        {"name": "Tablet", "price": "$449", "img": "https://picsum.photos/200/100?random=5"},
        {"name": "Camera", "price": "$799", "img": "https://picsum.photos/200/100?random=6"},
    ]
    
    product_cards = [
        Card(
            Img(src=p["img"], alt=p["name"], style="width:100%; height:100px; object-fit:cover;"),
            H4(p["name"], cls="mt-2"),
            P(p["price"]),
            Button("Add to Cart", cls=(ButtonT.primary, "mt-2"))
        ) for p in products
    ]
    
    return Grid(*product_cards, cols_lg=3)

preview(ex_product_grid())

source

DivHStacked


def DivHStacked(
    c:VAR_POSITIONAL, responsive:bool=True, padding:bool=True, cls:str='', kwargs:VAR_KEYWORD
):

Responsive horizontal stack with padding and mobile compatibility.


source

DivLAligned


def DivLAligned(
    c:VAR_POSITIONAL, cls:str='', kwargs:VAR_KEYWORD
):

MonsterUI-compatible left-aligned row using BeerCSS tokens.

Code
def ex_l_aligned_div():
    return Article(
        DivLAligned(
            Img(src="https://picsum.photos/100/100?random=1", style="max-width: 100px;"),
            H4("Left Aligned Title"),
            P("Some text that's left-aligned with the title and image.")
        ),
        cls="padding")

preview(ex_l_aligned_div())

source

DivVStacked


def DivVStacked(
    c:VAR_POSITIONAL, responsive:bool=True, padding:bool=True, cls:str='', kwargs:VAR_KEYWORD
):

Responsive vertical stack with padding and mobile compatibility.

Code
def ex_v_stacked_div():
    return Article(
        DivVStacked(
            H2("Vertical Stack"),
            P("First paragraph in the stack"),
            P("Second paragraph in the stack"),
            Button("Action Button", cls=ButtonT.secondary)
        ),
        cls="padding")

preview(ex_v_stacked_div())
Code
def ex_h_stacked_div():
    return Article(
        DivHStacked(
            Div(H4("Column 1"), P("Content for column 1")),
            Div(H4("Column 2"), P("Content for column 2")),
            Div(H4("Column 3"), P("Content for column 3"))
        ),
        cls="padding")

preview(ex_h_stacked_div())

source

DivRAligned


def DivRAligned(
    c:VAR_POSITIONAL, cls:str='', kwargs:VAR_KEYWORD
):

MonsterUI-compatible right-aligned row using BeerCSS tokens.

Code
def ex_r_aligned_div():
    return Article(
        DivRAligned(
            Button("Action", cls=ButtonT.primary),
            P("Right-aligned text"),
            Img(src="https://picsum.photos/100/100?random=3", style="max-width: 100px;")
        ),
        cls="padding")

preview(ex_r_aligned_div())

source

DivCentered


def DivCentered(
    c:VAR_POSITIONAL, cls:str='', kwargs:VAR_KEYWORD
):

Center-aligned container using BeerCSS tokens.

Code
def ex_centered_div():
    return Article(
        DivCentered(
            H3("Centered Title"),
            P("This content is centered both horizontally and vertically.")
        ),
        cls="padding")

preview(ex_centered_div())

source

DivFullySpaced


def DivFullySpaced(
    c:VAR_POSITIONAL, cls:str='', kwargs:VAR_KEYWORD
):

Row with children stretched to far ends using BeerCSS max spacers.

Code
def ex_fully_spaced_div():
    return Article(
        DivFullySpaced(
            Button("Left", cls=ButtonT.primary),
            Button("Center", cls=ButtonT.secondary),
            Button("Right", cls=ButtonT.destructive),
            Button("Right2", cls=ButtonT.destructive)
        ),
        cls="padding"
    )

preview(ex_fully_spaced_div())

🎨 Icon

Material Design icon component.

Export Description
Icon Material icon with optional click handler

πŸ’‘ Use case: Icon("settings", cls="large primary") creates a large primary settings icon.


source

Icon


def Icon(
    icon:str, size:str=None, fill:bool=False, cls:tuple=(), kwargs:VAR_KEYWORD
):

Material Design icon with optional size and fill

Code
def ex_icon():
    return Article(
        Grid(
            Icon('menu', size='large'),     
            Icon('settings', cls='primary-text'),
            Icon('favorite', fill=True)
        ),
        cls="padding")

preview(ex_icon())

πŸ“ Label Input

Component Purpose
Field Wrapper for form inputs with border/label/prefix/suffix styling
LabelInput Complete labeled input with floating label and optional icons

πŸ’‘ Use case: Building consistent form fields with Material Design floating labels and icon support.


source

LabelInput


def LabelInput(
    label:str, id:str=None, placeholder:str=None, input_type:str='text', prefix_icon:str=None, suffix_icon:str=None,
    value:str=None, cls:str='', kwargs:VAR_KEYWORD
):

Labeled input field with floating label and optional icons.


source

Field


def Field(
    c:VAR_POSITIONAL, label:bool=False, prefix:bool=False, suffix:bool=False, cls:str='', kwargs:VAR_KEYWORD
):

BeerCSS field wrapper for inputs with border/label/prefix/suffix styling.

Code
def ex_input(): 
    return Article(
        LabelInput(label="Input", id='myid'),
        cls="padding")


preview(ex_input())

🏷️ Form Label

Component Purpose
FormLabel Label element with proper for attribute linking

πŸ’‘ Use case: Creating accessible form labels that click-focus their associated inputs.


source

FormLabel


def FormLabel(
    c:VAR_POSITIONAL, cls:tuple=(), kwargs:VAR_KEYWORD
):

Standalone form label element with MonsterUI-compatible signature.


source

LabelInput


def LabelInput(
    label:str, id:str=None, placeholder:str=None, input_type:str='text', prefix_icon:str=None, suffix_icon:str=None,
    value:str=None, cls:str='', kwargs:VAR_KEYWORD
):

Labeled input field with floating label and optional icons.

Code
def ex_form_label(): 
    return Article(
        FormLabel("Username", fr="username-input"),
        LabelInput("Email", input_type="email"),
        cls="padding")


preview(ex_form_label())

β˜‘οΈ Checkbox

Component Purpose
CheckboxX BeerCSS checkbox with label support

πŸ’‘ Use case: Boolean form inputs with Material Design styling.


source

CheckboxX


def CheckboxX(
    c:VAR_POSITIONAL, cls:tuple=(), kwargs:VAR_KEYWORD
):

BeerCSS checkbox with label support.

Code
def ex_checkbox(): 
    return Article(
        CheckboxX(),
        CheckboxX("Accept terms"),
        CheckboxX("Enabled", checked=True),
        CheckboxX("Option 1", name="options", value="opt1"),
        cls="padding")
        
preview(ex_checkbox())

πŸ”˜ Radio

Component Purpose
Radio BeerCSS radio button with label

πŸ’‘ Use case: Single-selection from mutually exclusive options.


source

Radio


def Radio(
    c:VAR_POSITIONAL, cls:tuple=(), kwargs:VAR_KEYWORD
):

BeerCSS radio button with label.

Code
def ex_Radio(): 
    return Article(
        Radio("Option 1", name="group1", value="opt1"),
        Radio("Option 2", name="group1", value="opt2", checked=True),
        cls="padding")

preview(ex_Radio())

πŸ”€ Switch

Component Purpose
Switch Toggle switch for on/off states

πŸ’‘ Use case: Binary settings like dark mode, notifications, feature toggles.


source

Switch


def Switch(
    c:VAR_POSITIONAL, cls:tuple=(), kwargs:VAR_KEYWORD
):

BeerCSS toggle switch for on/off states.

If label text is provided, wraps in a nav with the label on the left and the switch on the right (standard BeerCSS pattern).

Code
def ex_switch(): 
    return Article(
        Switch("Enable notifications", name="notifications", checked=False),
        Switch("Dark mode", name="dark_mode", checked=True),
        Switch(name="no_label"),  # Switch without label
        cls="padding")

preview(ex_switch())

πŸ“„ Text Area

Component Purpose
TextArea Multi-line text input with field wrapper

πŸ’‘ Use case: Comments, descriptions, long-form text input.


source

TextArea


def TextArea(
    c:VAR_POSITIONAL, cls:tuple=(), kwargs:VAR_KEYWORD
):

BeerCSS textarea with field wrapper for consistent styling.

Code
def ex_TextArea(): 
    return Article(
        TextArea(placeholder="Enter description..."),
        TextArea("Initial text", rows=5),
        TextArea(placeholder=" "),
        cls="padding")

preview(ex_TextArea())

πŸ“Š Range

Component Purpose
Range Slider input for numeric ranges

πŸ’‘ Use case: Volume controls, price filters, numeric value selection within bounds.


source

Range


def Range(
    c:VAR_POSITIONAL, min:NoneType=None, max:NoneType=None, step:NoneType=None, cls:tuple=(), kwargs:VAR_KEYWORD
):

BeerCSS range slider with two-tone fill effect.

Code
def ex_range(): 
    return Article(
        Range(value=25),
        Range(min=0, max=100, value=50),
        cls="padding")

preview(ex_range())

πŸ“‹ Select & SelectMenu

Component Purpose
Select Native HTML select for forms - uses standard change event, works with HTMX
SelectMenu BeerCSS menu-based dropdown for display menus (profile, actions, navigation)

Select (Native HTML)

Uses the native <select> element with BeerCSS styling. Best for form inputs where you need: - Standard change events for HTMX (hx-trigger="change") - Keyboard navigation and accessibility - Mobile-friendly native picker - Cascading dropdown patterns

# Basic usage with label
Select("Option A", "Option B", "Option C", 
       name="category", label="Category")

# With HTMX for cascading dropdowns
Select("Electronics", "Clothing", "Books",
       name="category",
       label="Category",
       hx_get="/subcategories",
       hx_trigger="change",
       hx_target="#subcategory-wrapper")

Select Parameters

Parameter Type Default Description
*options str|Option|dict - Options (strings, Option elements, or dicts with value/label)
label str None Floating label text
value str '' Currently selected value
name str '' Form field name
id str auto Element ID (auto-generated from name)
placeholder str None Placeholder option (disabled first option)
cls str|tuple () Additional CSS classes

SelectMenu (Display Menus)

Uses BeerCSS menu element for visual dropdowns. Best for: - Profile menus, action dropdowns - Navigation menus - Any non-form UI where you just need a clickable menu

# Simple menu display
SelectMenu("Home", "About", "Contact", value="Home")

# With icon and custom items
SelectMenu(
    Li(Label("Section"), cls="transparent"),
    Li("Item 1"),
    Li("Item 2"),
    prefix_icon="menu"
)

SelectMenu Parameters

Parameter Type Default Description
*items str|Li - Menu items (strings or Li elements)
value str '' Display value text
placeholder str 'Select...' Placeholder text when empty
prefix_icon str None Optional icon before input
id str None Wrapper ID
cls str|tuple () Additional CSS classes

πŸ’‘ Rule of thumb: Use Select for forms, SelectMenu for display-only menus.


source

Select


def Select(
    options:VAR_POSITIONAL, label:NoneType=None, value:str='', name:str='', id:NoneType=None,
    placeholder:NoneType=None, cls:tuple=(), kwargs:VAR_KEYWORD
):

BeerCSS native HTML select with floating label support.

Uses the native