diff --git a/pkg-py/src/brand_yaml/typography.py b/pkg-py/src/brand_yaml/typography.py index c9b1d276..4cb912ef 100644 --- a/pkg-py/src/brand_yaml/typography.py +++ b/pkg-py/src/brand_yaml/typography.py @@ -308,42 +308,49 @@ class BrandNamedColor(RootModel): root: str -class BrandTypographyOptionsColor(BaseModel): +class BrandTypographyOptionsBackgroundColor(BaseModel): model_config = ConfigDict(populate_by_name=True) - color: BrandNamedColor | None = None background_color: BrandNamedColor | None = Field( None, alias="background-color" ) -class BrandTypographyOptionsWeight(BaseModel): - weight: BrandTypographyFontWeightSimpleType | None = None - - @field_validator("weight", mode="before") - @classmethod - def validate_weight(cls, value: int | str): - return validate_font_weight(value) +class BrandTypographyOptionsColor(BaseModel): + color: BrandNamedColor | None = None -class BrandTypographyOptionsGenericText(BrandTypographyOptionsWeight): +class BrandTypographyOptionsFamily(BaseModel): family: str | None = None - style: SingleOrList[BrandTypographyFontStyleType] | None = None + + +class BrandTypographyOptionsLineHeight(BaseModel): + line_height: float | None = Field(None, alias="line-height") class BrandTypographyOptionsSize(BaseModel): size: str | None = None -class BrandTypographyOptionsBlockText(BaseModel): - line_height: float | None = Field(None, alias="line-height") +class BrandTypographyOptionsStyle(BaseModel): + style: SingleOrList[BrandTypographyFontStyleType] | None = None + + +class BrandTypographyOptionsWeight(BaseModel): + weight: BrandTypographyFontWeightSimpleType | None = None + + @field_validator("weight", mode="before") + @classmethod + def validate_weight(cls, value: int | str): + return validate_font_weight(value) class BrandTypographyBase( BrandBase, - BrandTypographyOptionsGenericText, + BrandTypographyOptionsFamily, + BrandTypographyOptionsWeight, BrandTypographyOptionsSize, - BrandTypographyOptionsBlockText, + BrandTypographyOptionsLineHeight, BrandTypographyOptionsColor, ): model_config = ConfigDict(extra="forbid") @@ -351,8 +358,10 @@ class BrandTypographyBase( class BrandTypographyHeadings( BrandBase, - BrandTypographyOptionsGenericText, - BrandTypographyOptionsBlockText, + BrandTypographyOptionsFamily, + BrandTypographyOptionsWeight, + BrandTypographyOptionsStyle, + BrandTypographyOptionsLineHeight, BrandTypographyOptionsColor, ): model_config = ConfigDict(extra="forbid") @@ -360,7 +369,8 @@ class BrandTypographyHeadings( class BrandTypographyMonospace( BrandBase, - BrandTypographyOptionsGenericText, + BrandTypographyOptionsFamily, + BrandTypographyOptionsWeight, BrandTypographyOptionsSize, ): model_config = ConfigDict(extra="forbid") @@ -369,14 +379,16 @@ class BrandTypographyMonospace( class BrandTypographyMonospaceInline( BrandTypographyMonospace, BrandTypographyOptionsColor, + BrandTypographyOptionsBackgroundColor, ): model_config = ConfigDict(extra="forbid") class BrandTypographyMonospaceBlock( BrandTypographyMonospace, - BrandTypographyOptionsBlockText, + BrandTypographyOptionsLineHeight, BrandTypographyOptionsColor, + BrandTypographyOptionsBackgroundColor, ): model_config = ConfigDict(extra="forbid") @@ -385,6 +397,7 @@ class BrandTypographyLink( BrandBase, BrandTypographyOptionsWeight, BrandTypographyOptionsColor, + BrandTypographyOptionsBackgroundColor, ): model_config = ConfigDict(extra="forbid") diff --git a/pkg-py/tests/test_typography.py b/pkg-py/tests/test_typography.py index 281e3b33..b84d695d 100644 --- a/pkg-py/tests/test_typography.py +++ b/pkg-py/tests/test_typography.py @@ -124,11 +124,9 @@ def test_brand_typography_fields_base(): assert base_fields == { "family", "weight", - "style", "size", "line_height", "color", - "background_color", } @@ -141,14 +139,13 @@ def test_brand_typography_fields_headings(): "style", "line_height", "color", - "background_color", } def test_brand_typography_fields_monospace(): fields = set(BrandTypographyMonospace.model_fields.keys()) - assert fields == {"family", "weight", "style", "size"} + assert fields == {"family", "weight", "size"} def test_brand_typography_fields_monospace_inline(): @@ -157,7 +154,6 @@ def test_brand_typography_fields_monospace_inline(): assert fields == { "family", "weight", - "style", "size", "color", "background_color", @@ -170,7 +166,6 @@ def test_brand_typography_fields_monospace_block(): assert fields == { "family", "weight", - "style", "size", "line_height", "color",