toast

Toast is a wrapper to stack elements, positioned on the corner of page.

Base Toast

Exported source
toast = SingleValueFactory("toast", "Container element that sticks to the corner of page") # Base toast component

Toast Placement


source

ToastPlacement

 ToastPlacement (value, names=None, module=None, qualname=None, type=None,
                 start=1, boundary=None)

*str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.*

Toast Test Examples


source

test_toast_basic_examples

 test_toast_basic_examples ()

Test basic toast utilities.

Exported source
def test_toast_basic_examples():
    """Test basic toast utilities."""
    # Basic toast
    assert str(toast) == "toast"
    
    # Test with modifiers
    assert str(toast.hover) == "hover:toast"
    assert str(toast.md) == "md:toast"
    assert str(toast.dark) == "dark:toast"

# Run the tests
test_toast_basic_examples()

source

test_toast_placement_examples

 test_toast_placement_examples ()

Test toast placement options.

Exported source
def test_toast_placement_examples():
    """Test toast placement options."""
    # Horizontal alignment
    assert str(toast_placement.start) == "toast-start"
    assert str(toast_placement.center) == "toast-center"
    assert str(toast_placement.end) == "toast-end"
    
    # Vertical position
    assert str(toast_placement.top) == "toast-top"
    assert str(toast_placement.middle) == "toast-middle"
    assert str(toast_placement.bottom) == "toast-bottom"

# Run the tests
test_toast_placement_examples()

source

test_toast_basic_fasthtml_examples

 test_toast_basic_fasthtml_examples ()

Test basic toast with alert inside from daisyUI v5 documentation.

Exported source
def test_toast_basic_fasthtml_examples():
    """Test basic toast with alert inside from daisyUI v5 documentation."""
    from fasthtml.common import Div, Span
    from cjm_fasthtml_daisyui.components.feedback.alert import alert, alert_colors
    
    # Basic toast with alert inside
    basic_toast = Div(
        Div(
            Span("New message arrived."),
            cls=combine_classes(alert, alert_colors.info)
        ),
        cls=str(toast)
    )
    
    # Verify structure
    assert basic_toast.tag == "div"
    assert basic_toast.attrs['class'] == "toast"
    
    # Verify alert inside toast
    alert_element = basic_toast.children[0]
    assert alert_element.tag == "div"
    assert "alert" in alert_element.attrs['class']
    assert "alert-info" in alert_element.attrs['class']
    
    # Verify alert content
    assert alert_element.children[0].tag == "span"
    assert alert_element.children[0].children[0] == "New message arrived."
    
    return basic_toast

# Run the tests
test_toast_basic_fasthtml_examples()
<div class="toast">
  <div class="alert alert-info">
<span>New message arrived.</span>  </div>
</div>
test_func = test_toast_basic_fasthtml_examples
app, rt = create_test_app(theme=DaisyUITheme.LIGHT)

@rt
def index():
    return create_test_page(test_func.__doc__.title().replace('.', ''), test_func())
server = start_test_server(app)
display(HTMX())
server.stop()

source

test_toast_top_positions_fasthtml_examples

 test_toast_top_positions_fasthtml_examples ()

Test toast positioning at top (start, center, end) from daisyUI v5 documentation.

Exported source
def test_toast_top_positions_fasthtml_examples():
    """Test toast positioning at top (start, center, end) from daisyUI v5 documentation."""
    from fasthtml.common import Div, Span
    from cjm_fasthtml_tailwind.utilities.sizing import min_h
    from cjm_fasthtml_daisyui.components.feedback.alert import alert, alert_colors
    
    # Toast top start
    toast_top_start = Div(
        Div(
            Span("New mail arrived."),
            cls=combine_classes(alert, alert_colors.info)
        ),
        Div(
            Span("Message sent successfully."),
            cls=combine_classes(alert, alert_colors.success)
        ),
        cls=combine_classes(toast, toast_placement.top, toast_placement.start)
    )
    
    # Verify structure
    assert toast_top_start.tag == "div"
    assert "toast" in toast_top_start.attrs['class']
    assert "toast-top" in toast_top_start.attrs['class']
    assert "toast-start" in toast_top_start.attrs['class']
    assert len(toast_top_start.children) == 2
    
    # Verify first alert
    first_alert = toast_top_start.children[0]
    assert "alert" in first_alert.attrs['class']
    assert "alert-info" in first_alert.attrs['class']
    assert first_alert.children[0].children[0] == "New mail arrived."
    
    # Verify second alert
    second_alert = toast_top_start.children[1]
    assert "alert" in second_alert.attrs['class']
    assert "alert-success" in second_alert.attrs['class']
    assert second_alert.children[0].children[0] == "Message sent successfully."
    
    # Toast top center
    toast_top_center = Div(
        Div(
            Span("New mail arrived."),
            cls=combine_classes(alert, alert_colors.info)
        ),
        Div(
            Span("Message sent successfully."),
            cls=combine_classes(alert, alert_colors.success)
        ),
        cls=combine_classes(toast, toast_placement.top, toast_placement.center)
    )
    
    assert "toast" in toast_top_center.attrs['class']
    assert "toast-top" in toast_top_center.attrs['class']
    assert "toast-center" in toast_top_center.attrs['class']
    
    # Toast top end
    toast_top_end = Div(
        Div(
            Span("New mail arrived."),
            cls=combine_classes(alert, alert_colors.info)
        ),
        Div(
            Span("Message sent successfully."),
            cls=combine_classes(alert, alert_colors.success)
        ),
        cls=combine_classes(toast, toast_placement.top, toast_placement.end)
    )
    
    assert "toast" in toast_top_end.attrs['class']
    assert "toast-top" in toast_top_end.attrs['class']
    assert "toast-end" in toast_top_end.attrs['class']
    
    # Return all top position variations
    return Div(
        toast_top_start,
        toast_top_center,
        toast_top_end,
        cls=combine_classes(min_h(48))
    )

# Run the tests
test_toast_top_positions_fasthtml_examples()
<div class="min-h-48">
  <div class="toast toast-top toast-start">
    <div class="alert alert-info">
<span>New mail arrived.</span>    </div>
    <div class="alert alert-success">
<span>Message sent successfully.</span>    </div>
  </div>
  <div class="toast toast-top toast-center">
    <div class="alert alert-info">
<span>New mail arrived.</span>    </div>
    <div class="alert alert-success">
<span>Message sent successfully.</span>    </div>
  </div>
  <div class="toast toast-top toast-end">
    <div class="alert alert-info">
<span>New mail arrived.</span>    </div>
    <div class="alert alert-success">
<span>Message sent successfully.</span>    </div>
  </div>
</div>
test_func = test_toast_top_positions_fasthtml_examples
app, rt = create_test_app(theme=DaisyUITheme.LIGHT)

@rt
def index():
    return create_test_page(test_func.__doc__.title().replace('.', ''), test_func())
server = start_test_server(app)
display(HTMX())
server.stop()

source

test_toast_middle_positions_fasthtml_examples

 test_toast_middle_positions_fasthtml_examples ()

Test toast positioning at middle (start, center, end) from daisyUI v5 documentation.

Exported source
def test_toast_middle_positions_fasthtml_examples():
    """Test toast positioning at middle (start, center, end) from daisyUI v5 documentation."""
    from fasthtml.common import Div, Span
    from cjm_fasthtml_tailwind.utilities.sizing import min_h
    from cjm_fasthtml_daisyui.components.feedback.alert import alert, alert_colors
    
    # Toast start middle
    toast_start_middle = Div(
        Div(
            Span("New mail arrived."),
            cls=combine_classes(alert, alert_colors.info)
        ),
        Div(
            Span("Message sent successfully."),
            cls=combine_classes(alert, alert_colors.success)
        ),
        cls=combine_classes(toast, toast_placement.start, toast_placement.middle)
    )
    
    # Verify structure
    assert toast_start_middle.tag == "div"
    assert "toast" in toast_start_middle.attrs['class']
    assert "toast-start" in toast_start_middle.attrs['class']
    assert "toast-middle" in toast_start_middle.attrs['class']
    assert len(toast_start_middle.children) == 2
    
    # Verify alerts
    assert "alert-info" in toast_start_middle.children[0].attrs['class']
    assert toast_start_middle.children[0].children[0].children[0] == "New mail arrived."
    assert "alert-success" in toast_start_middle.children[1].attrs['class']
    assert toast_start_middle.children[1].children[0].children[0] == "Message sent successfully."
    
    # Toast center middle
    toast_center_middle = Div(
        Div(
            Span("New mail arrived."),
            cls=combine_classes(alert, alert_colors.info)
        ),
        Div(
            Span("Message sent successfully."),
            cls=combine_classes(alert, alert_colors.success)
        ),
        cls=combine_classes(toast, toast_placement.center, toast_placement.middle)
    )
    
    assert "toast" in toast_center_middle.attrs['class']
    assert "toast-center" in toast_center_middle.attrs['class']
    assert "toast-middle" in toast_center_middle.attrs['class']
    
    # Toast end middle
    toast_end_middle = Div(
        Div(
            Span("New mail arrived."),
            cls=combine_classes(alert, alert_colors.info)
        ),
        Div(
            Span("Message sent successfully."),
            cls=combine_classes(alert, alert_colors.success)
        ),
        cls=combine_classes(toast, toast_placement.end, toast_placement.middle)
    )
    
    assert "toast" in toast_end_middle.attrs['class']
    assert "toast-end" in toast_end_middle.attrs['class']
    assert "toast-middle" in toast_end_middle.attrs['class']
    
    # Return all middle position variations
    return Div(
        toast_start_middle,
        toast_center_middle,
        toast_end_middle,
        cls=combine_classes(min_h(48))
    )

# Run the tests
test_toast_middle_positions_fasthtml_examples()
<div class="min-h-48">
  <div class="toast toast-start toast-middle">
    <div class="alert alert-info">
<span>New mail arrived.</span>    </div>
    <div class="alert alert-success">
<span>Message sent successfully.</span>    </div>
  </div>
  <div class="toast toast-center toast-middle">
    <div class="alert alert-info">
<span>New mail arrived.</span>    </div>
    <div class="alert alert-success">
<span>Message sent successfully.</span>    </div>
  </div>
  <div class="toast toast-end toast-middle">
    <div class="alert alert-info">
<span>New mail arrived.</span>    </div>
    <div class="alert alert-success">
<span>Message sent successfully.</span>    </div>
  </div>
</div>
test_func = test_toast_middle_positions_fasthtml_examples
app, rt = create_test_app(theme=DaisyUITheme.LIGHT)

@rt
def index():
    return create_test_page(test_func.__doc__.title().replace('.', ''), test_func())
server = start_test_server(app)
display(HTMX())
server.stop()

source

test_toast_bottom_positions_fasthtml_examples

 test_toast_bottom_positions_fasthtml_examples ()

Test toast positioning at bottom (start, center, end) from daisyUI v5 documentation.

Exported source
def test_toast_bottom_positions_fasthtml_examples():
    """Test toast positioning at bottom (start, center, end) from daisyUI v5 documentation."""
    from fasthtml.common import Div, Span
    from cjm_fasthtml_tailwind.utilities.sizing import min_h
    from cjm_fasthtml_daisyui.components.feedback.alert import alert, alert_colors
    
    # Toast start bottom (default)
    toast_start_bottom = Div(
        Div(
            Span("New mail arrived."),
            cls=combine_classes(alert, alert_colors.info)
        ),
        Div(
            Span("Message sent successfully."),
            cls=combine_classes(alert, alert_colors.success)
        ),
        cls=combine_classes(toast, toast_placement.start)
    )
    
    # Verify structure - note that bottom is default, so no toast-bottom class
    assert toast_start_bottom.tag == "div"
    assert "toast" in toast_start_bottom.attrs['class']
    assert "toast-start" in toast_start_bottom.attrs['class']
    # Bottom is default, so toast-bottom is not needed
    assert len(toast_start_bottom.children) == 2
    
    # Verify alerts
    assert "alert-info" in toast_start_bottom.children[0].attrs['class']
    assert toast_start_bottom.children[0].children[0].children[0] == "New mail arrived."
    assert "alert-success" in toast_start_bottom.children[1].attrs['class']
    assert toast_start_bottom.children[1].children[0].children[0] == "Message sent successfully."
    
    # Toast center bottom (default)
    toast_center_bottom = Div(
        Div(
            Span("New mail arrived."),
            cls=combine_classes(alert, alert_colors.info)
        ),
        Div(
            Span("Message sent successfully."),
            cls=combine_classes(alert, alert_colors.success)
        ),
        cls=combine_classes(toast, toast_placement.center)
    )
    
    assert "toast" in toast_center_bottom.attrs['class']
    assert "toast-center" in toast_center_bottom.attrs['class']
    # Bottom is default, so toast-bottom is not needed
    
    # Toast end bottom (both are defaults)
    toast_end_bottom = Div(
        Div(
            Span("New mail arrived."),
            cls=combine_classes(alert, alert_colors.info)
        ),
        Div(
            Span("Message sent successfully."),
            cls=combine_classes(alert, alert_colors.success)
        ),
        cls=combine_classes(toast, toast_placement.end)
    )
    
    assert "toast" in toast_end_bottom.attrs['class']
    assert "toast-end" in toast_end_bottom.attrs['class']
    # Bottom is default, so toast-bottom is not needed
    
    # Return all bottom position variations
    return Div(
        toast_start_bottom,
        toast_center_bottom,
        toast_end_bottom,
        cls=combine_classes(min_h(48))
    )

# Run the tests
test_toast_bottom_positions_fasthtml_examples()
<div class="min-h-48">
  <div class="toast toast-start">
    <div class="alert alert-info">
<span>New mail arrived.</span>    </div>
    <div class="alert alert-success">
<span>Message sent successfully.</span>    </div>
  </div>
  <div class="toast toast-center">
    <div class="alert alert-info">
<span>New mail arrived.</span>    </div>
    <div class="alert alert-success">
<span>Message sent successfully.</span>    </div>
  </div>
  <div class="toast toast-end">
    <div class="alert alert-info">
<span>New mail arrived.</span>    </div>
    <div class="alert alert-success">
<span>Message sent successfully.</span>    </div>
  </div>
</div>
test_func = test_toast_bottom_positions_fasthtml_examples
app, rt = create_test_app(theme=DaisyUITheme.LIGHT)

@rt
def index():
    return create_test_page(test_func.__doc__.title().replace('.', ''), test_func())
server = start_test_server(app)
display(HTMX())
server.stop()