Skip to content

Commit

Permalink
Ensure styling is applied to the response tag
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Jul 26, 2024
1 parent dc70c4c commit e0a692f
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/posting/widgets/response/response_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class ResponseArea(Vertical):
The response area.
"""

COMPONENT_CLASSES = {
"border-title-status",
}

DEFAULT_CSS = """\
ResponseArea {
border-subtitle-color: $text-muted;
Expand All @@ -36,6 +40,20 @@ class ResponseArea(Vertical):
display: none;
}
}
&.success .border-title-status {
color: $text;
background: $success;
}
&.warning .border-title-status {
color: $text;
background: $warning;
}
&.error .border-title-status {
color: $text;
background: $error;
}
}
"""
response: Reactive[httpx.Response | None] = reactive(None)
Expand Down Expand Up @@ -100,13 +118,15 @@ def watch_response(self, response: httpx.Response | None) -> None:
[(name, value) for name, value in response.cookies.items()]
)

self.remove_class("success", "warning", "error")
if response.status_code < 300:
style = "#ecfccb on #4d7c0f"
self.add_class("success")
elif response.status_code < 400:
style = "black on yellow"
self.add_class("warning")
else:
style = "black on red"
self.add_class("error")

style = self.get_component_rich_style("border-title-status")
self.border_title = (
f"Response [{style}] {response.status_code} {response.reason_phrase} [/]"
)
Expand Down

0 comments on commit e0a692f

Please sign in to comment.