Skip to content

Commit

Permalink
feat(typography): Update typographic options
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed Sep 17, 2024
1 parent 481d8b6 commit 719b676
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
51 changes: 32 additions & 19 deletions pkg-py/src/brand_yaml/typography.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,59 +308,69 @@ 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")


class BrandTypographyHeadings(
BrandBase,
BrandTypographyOptionsGenericText,
BrandTypographyOptionsBlockText,
BrandTypographyOptionsFamily,
BrandTypographyOptionsWeight,
BrandTypographyOptionsStyle,
BrandTypographyOptionsLineHeight,
BrandTypographyOptionsColor,
):
model_config = ConfigDict(extra="forbid")


class BrandTypographyMonospace(
BrandBase,
BrandTypographyOptionsGenericText,
BrandTypographyOptionsFamily,
BrandTypographyOptionsWeight,
BrandTypographyOptionsSize,
):
model_config = ConfigDict(extra="forbid")
Expand All @@ -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")

Expand All @@ -385,6 +397,7 @@ class BrandTypographyLink(
BrandBase,
BrandTypographyOptionsWeight,
BrandTypographyOptionsColor,
BrandTypographyOptionsBackgroundColor,
):
model_config = ConfigDict(extra="forbid")

Expand Down
7 changes: 1 addition & 6 deletions pkg-py/tests/test_typography.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,9 @@ def test_brand_typography_fields_base():
assert base_fields == {
"family",
"weight",
"style",
"size",
"line_height",
"color",
"background_color",
}


Expand All @@ -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():
Expand All @@ -157,7 +154,6 @@ def test_brand_typography_fields_monospace_inline():
assert fields == {
"family",
"weight",
"style",
"size",
"color",
"background_color",
Expand All @@ -170,7 +166,6 @@ def test_brand_typography_fields_monospace_block():
assert fields == {
"family",
"weight",
"style",
"size",
"line_height",
"color",
Expand Down

0 comments on commit 719b676

Please sign in to comment.