# Test basic semantic color usage
bg_dui = ColoredFactoryDaisyUI("bg", "Background color utilities for daisyUI semantic colors")
# Test semantic colors
assert str(bg_dui.primary) == "bg-primary"
assert str(bg_dui.secondary) == "bg-secondary"
assert str(bg_dui.accent) == "bg-accent"
assert str(bg_dui.neutral) == "bg-neutral"colors
Semantic Color Enums
Define enums for the semantic color names used by daisyUI:
SemanticColorBrand
def SemanticColorBrand(
args:VAR_POSITIONAL, kwds:VAR_KEYWORD
):
daisyUI semantic brand color names.
SemanticColorStatus
def SemanticColorStatus(
args:VAR_POSITIONAL, kwds:VAR_KEYWORD
):
daisyUI semantic status color names.
SemanticColorBase
def SemanticColorBase(
args:VAR_POSITIONAL, kwds:VAR_KEYWORD
):
daisyUI semantic base color names.
SemanticColorContent
def SemanticColorContent(
args:VAR_POSITIONAL, kwds:VAR_KEYWORD
):
daisyUI semantic content color names.
SemanticColor
def SemanticColor(
args:VAR_POSITIONAL, kwds:VAR_KEYWORD
):
daisyUI semantic color names.
Color Value Types
Define types for semantic color values:
Color Validation
Functions to validate semantic color values:
is_valid_semantic_color
def is_valid_semantic_color(
value:str, # The value to check
)->bool: # True if value is a valid daisyUI semantic color
Check if a value is a valid daisyUI semantic color.
Colored Utility Class for daisyUI
A utility class that supports daisyUI semantic colors with opacity:
ColoredUtilityDaisyUI
def ColoredUtilityDaisyUI(
prefix:str, # The utility prefix (e.g., 'bg', 'text', 'border')
color:Union=None, # The semantic color value
opacity:Union=None, # Optional opacity value (0-100 or arbitrary)
):
Utility class with daisyUI semantic color and opacity support.
Colored Factory for daisyUI
Factory for creating semantic color-based utilities with convenient API:
ColoredFactoryDaisyUI
def ColoredFactoryDaisyUI(
prefix:str, # The utility prefix (e.g., 'bg', 'text', 'border')
doc:Optional=None, # Optional documentation string
):
Factory for creating daisyUI semantic color-based utilities.
Examples
Test the semantic color system with various use cases:
# Test base colors
assert str(bg_dui.base_100) == "bg-base-100"
assert str(bg_dui.base_200) == "bg-base-200"
assert str(bg_dui.base_300) == "bg-base-300"
assert str(bg_dui.base_content) == "bg-base-content"# Test status colors
assert str(bg_dui.info) == "bg-info"
assert str(bg_dui.success) == "bg-success"
assert str(bg_dui.warning) == "bg-warning"
assert str(bg_dui.error) == "bg-error"# Test content colors
assert str(bg_dui.primary_content) == "bg-primary-content"
assert str(bg_dui.secondary_content) == "bg-secondary-content"
assert str(bg_dui.accent_content) == "bg-accent-content"
assert str(bg_dui.neutral_content) == "bg-neutral-content"Semantic Color Opacity
Control the opacity of semantic colors:
# Test opacity modifiers
assert str(bg_dui.primary.opacity(50)) == "bg-primary/50"
assert str(bg_dui.secondary.opacity(75)) == "bg-secondary/75"
assert str(bg_dui.base_100.opacity(10)) == "bg-base-100/10"
assert str(bg_dui.base_content.opacity(70)) == "bg-base-content/70"
# Test arbitrary opacity values
assert str(bg_dui.success.opacity("[0.87]")) == "bg-success/[0.87]"
assert str(bg_dui.error.opacity("(--my-opacity)")) == "bg-error/(--my-opacity)"Arbitrary Color Values
Support for custom colors alongside semantic colors:
# Test arbitrary color values
assert str(bg_dui("#ff0000")) == "bg-[#ff0000]"
assert str(bg_dui("rgb(255, 0, 0)")) == "bg-[rgb(255, 0, 0)]"
assert str(bg_dui("hsl(0, 100%, 50%)")) == "bg-[hsl(0, 100%, 50%)]"
# Test CSS custom properties
assert str(bg_dui("--custom-bg")) == "bg-(--custom-bg)"
assert str(bg_dui("--theme-primary")) == "bg-(--theme-primary)"
# Test with opacity
assert str(bg_dui("--custom-bg", opacity=50)) == "bg-(--custom-bg)/50"Factory Call Syntax
Test using the factory with call syntax:
# Test factory call syntax
assert str(bg_dui("primary")) == "bg-primary"
assert str(bg_dui("secondary", opacity=75)) == "bg-secondary/75"
assert str(bg_dui(SemanticColor.ACCENT)) == "bg-accent"
assert str(bg_dui(SemanticColor.BASE_100, opacity=50)) == "bg-base-100/50"Test Functions
Comprehensive test functions following the project’s naming convention:
test_colors_semantic_enum_examples
def test_colors_semantic_enum_examples(
):
Test semantic color enum.
test_colors_validation_examples
def test_colors_validation_examples(
):
Test semantic color validation functions.
test_colors_factory_examples
def test_colors_factory_examples(
):
Test ColoredFactoryDaisyUI with various semantic color specifications.
test_colors_opacity_examples
def test_colors_opacity_examples(
):
Test opacity modifiers with semantic color utilities.
test_colors_arbitrary_examples
def test_colors_arbitrary_examples(
):
Test arbitrary color values and custom properties.
Practical Examples
Test with multiple utility prefixes to show the semantic color system is reusable:
test_colors_multiple_utilities_examples
def test_colors_multiple_utilities_examples(
):
Test semantic color system with multiple utility types.
test_colors_practical_usage_examples
def test_colors_practical_usage_examples(
):
Test practical usage patterns with FastHTML components.
test_colors_modifier_examples
def test_colors_modifier_examples(
):
Test semantic color utilities with modifiers for conditional styling.
Helper Functions
Utility functions for working with semantic colors:
get_all_semantic_colors
def get_all_semantic_colors(
)->List:
Get list of all daisyUI semantic color names.
get_brand_colors
def get_brand_colors(
)->List:
Get list of brand semantic colors.
get_base_colors
def get_base_colors(
)->List:
Get list of base semantic colors.
get_status_colors
def get_status_colors(
)->List:
Get list of status semantic colors.
# Test helper functions
colors = get_all_semantic_colors()
assert len(colors) == 20
assert "primary" in colors
assert "base-100" in colors
assert "error-content" in colors
brand = get_brand_colors()
assert len(brand) == 4
assert brand == ["primary", "secondary", "accent", "neutral"]
base = get_base_colors()
assert len(base) == 4
assert base == ["base-100", "base-200", "base-300", "base-content"]
status = get_status_colors()
assert len(status) == 4
assert status == ["info", "success", "warning", "error"]
print("✅ All semantic color helper functions work correctly!")✅ All semantic color helper functions work correctly!