Exported source
toast = SingleValueFactory("toast", "Container element that sticks to the corner of page") # Base toast componentToastPlacement (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’.*
test_toast_basic_examples ()
Test basic toast utilities.
test_toast_placement_examples ()
Test toast placement options.
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()test_toast_basic_fasthtml_examples ()
Test basic toast with alert inside from daisyUI v5 documentation.
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()test_toast_top_positions_fasthtml_examples ()
Test toast positioning at top (start, center, end) from daisyUI v5 documentation.
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_toast_middle_positions_fasthtml_examples ()
Test toast positioning at middle (start, center, end) from daisyUI v5 documentation.
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_toast_bottom_positions_fasthtml_examples ()
Test toast positioning at bottom (start, center, end) from daisyUI v5 documentation.
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>