Media type icon mappings and badge color definitions for the gallery.
Media Type Icon Mapping
Maps file types to Lucide icon names for consistent iconography across the gallery.
# Test icon mappingassert MEDIA_TYPE_ICONS[FileType.AUDIO] =="file-music"assert MEDIA_TYPE_ICONS[FileType.VIDEO] =="file-video-camera"assert MEDIA_TYPE_ICONS[FileType.IMAGE] =="image"assert MEDIA_TYPE_ICONS[FileType.DOCUMENT] =="file-text"assert MEDIA_TYPE_ICONS[FileType.OTHER] =="file"# Verify all FileTypes have an iconfor file_type in FileType:assert file_type in MEDIA_TYPE_ICONS, f"Missing icon for {file_type}"print("MEDIA_TYPE_ICONS tests passed!")
MEDIA_TYPE_ICONS tests passed!
Gallery UI Icons
Icons used in the gallery UI controls and preview modal.
# Test badge colorsassert"badge-info"in MEDIA_TYPE_BADGE_COLORS[FileType.AUDIO]assert"badge-primary"in MEDIA_TYPE_BADGE_COLORS[FileType.VIDEO]assert"badge-success"in MEDIA_TYPE_BADGE_COLORS[FileType.IMAGE]# Verify all FileTypes have a badge colorfor file_type in FileType:assert file_type in MEDIA_TYPE_BADGE_COLORS, f"Missing badge color for {file_type}"print("MEDIA_TYPE_BADGE_COLORS tests passed!")
MEDIA_TYPE_BADGE_COLORS tests passed!
# Test text colorsassert"text-info"in MEDIA_TYPE_TEXT_COLORS[FileType.AUDIO]assert"text-primary"in MEDIA_TYPE_TEXT_COLORS[FileType.VIDEO]assert"text-success"in MEDIA_TYPE_TEXT_COLORS[FileType.IMAGE]print("MEDIA_TYPE_TEXT_COLORS tests passed!")
MEDIA_TYPE_TEXT_COLORS tests passed!
Icon Helper Functions
Convenience functions for rendering icons with appropriate styling.
get_media_type_icon
def get_media_type_icon( file_type:FileType, # File type to get icon for size:int=4, # Icon size (Tailwind scale) with_color:bool=True, # Apply semantic color)->Any: # Lucide icon component
Get the appropriate icon for a file type.
from fasthtml.common import to_xml# Test get_media_type_iconaudio_icon = get_media_type_icon(FileType.AUDIO)html = to_xml(audio_icon)assert"<svg"in html.lower()assert"text-info"in html # Color appliedvideo_icon = get_media_type_icon(FileType.VIDEO, size=6)html = to_xml(video_icon)assert"text-primary"in html# Test without coloricon_no_color = get_media_type_icon(FileType.IMAGE, with_color=False)html = to_xml(icon_no_color)assert"text-success"notin htmlprint("get_media_type_icon tests passed!")