colors

Semantic color system builders for daisyUI components

Semantic Color Enums

Define enums for the semantic color names used by daisyUI:


source

SemanticColorBrand

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

daisyUI semantic brand color names.


source

SemanticColorStatus

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

daisyUI semantic status color names.


source

SemanticColorBase

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

daisyUI semantic base color names.


source

SemanticColorContent

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

daisyUI semantic content color names.


source

SemanticColor

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

daisyUI semantic color names.

Color Value Types

Define types for semantic color values:

Color Validation

Functions to validate semantic color values:


source

is_valid_semantic_color

 is_valid_semantic_color (value:str)

Check if a value is a valid daisyUI semantic color.

Type Details
value str The value to check
Returns bool True if value is a valid daisyUI semantic color

Colored Utility Class for daisyUI

A utility class that supports daisyUI semantic colors with opacity:


source

ColoredUtilityDaisyUI

 ColoredUtilityDaisyUI (prefix:str,
                        color:Union[__main__.SemanticColor,str,NoneType]=N
                        one, opacity:Union[int,str,NoneType]=None)

Utility class with daisyUI semantic color and opacity support.

Type Default Details
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)

Colored Factory for daisyUI

Factory for creating semantic color-based utilities with convenient API:


source

ColoredFactoryDaisyUI

 ColoredFactoryDaisyUI (prefix:str, doc:Optional[str]=None)

Factory for creating daisyUI semantic color-based utilities.

Type Default Details
prefix str The utility prefix (e.g., ‘bg’, ‘text’, ‘border’)
doc Optional None Optional documentation string

Examples

Test the semantic color system with various use cases:

# 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"
# 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:


source

test_colors_semantic_enum_examples

 test_colors_semantic_enum_examples ()

Test semantic color enum.


source

test_colors_validation_examples

 test_colors_validation_examples ()

Test semantic color validation functions.


source

test_colors_factory_examples

 test_colors_factory_examples ()

Test ColoredFactoryDaisyUI with various semantic color specifications.


source

test_colors_opacity_examples

 test_colors_opacity_examples ()

Test opacity modifiers with semantic color utilities.


source

test_colors_arbitrary_examples

 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:


source

test_colors_multiple_utilities_examples

 test_colors_multiple_utilities_examples ()

Test semantic color system with multiple utility types.


source

test_colors_practical_usage_examples

 test_colors_practical_usage_examples ()

Test practical usage patterns with FastHTML components.


source

test_colors_modifier_examples

 test_colors_modifier_examples ()

Test semantic color utilities with modifiers for conditional styling.

Helper Functions

Utility functions for working with semantic colors:


source

get_all_semantic_colors

 get_all_semantic_colors ()

Get list of all daisyUI semantic color names.


source

get_brand_colors

 get_brand_colors ()

Get list of brand semantic colors.


source

get_base_colors

 get_base_colors ()

Get list of base semantic colors.


source

get_status_colors

 get_status_colors ()

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!