Skip to content

Commit

Permalink
Fix CellStyleBorders based on code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rich-iannone committed Dec 12, 2023
1 parent 9376539 commit 25905ab
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions great_tables/_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,16 @@ class CellStyleBorders(CellStyle):
A CellStyleBorders object, which is used for a `styles` argument if specifying cell borders.
"""

sides: List[str] | str | None = "all"
sides: Literal["all", "top", "bottom", "left", "right"] | List[
Literal["all", "top", "bottom", "left", "right"]
] = "all"
color: str = "#000000"
style: str = "solid"
weight: str = "1px"

def _to_html_style(self) -> str:
# If sides is None, return an empty string
if self.sides is None:
# If sides is an empty list, return an empty string
if self.sides == []:
return ""

# If self.sides is a string, convert to a list
Expand All @@ -213,6 +215,8 @@ def _to_html_style(self) -> str:

border_css_list: List[str] = []
for side in self.sides:
if side not in ["top", "bottom", "left", "right"]:
raise ValueError(f"Invalid side '{side}' provided.")
border_css_list.append(f"border-{side}: {weight} {style} {color};")

border_css = "".join(border_css_list)
Expand Down

0 comments on commit 25905ab

Please sign in to comment.