Skip to content

Commit

Permalink
Merge pull request #111 from communitiesuk/warning-message-component
Browse files Browse the repository at this point in the history
pkupdate warning text component
  • Loading branch information
robertblincoe committed Jun 26, 2023
2 parents bb7d873 + cb0bbca commit f9cd45a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
58 changes: 46 additions & 12 deletions gov_uk_dashboards/components/plotly/warning_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,52 @@ def warning_text(text: str):
Return Gov UK Design component warning text component, ! with text.
"""
text = html.Div(
[
html.Span(
["!"], className="govuk-warning-text__icon", **{"aria-hidden": "true"}
),
html.Strong(
[
html.Span(["Warning"], className="govuk-warning-text__assistive"),
text,
],
className="govuk-warning-text__text",
),
],
format_text(text),
className="govuk-warning-text",
)
return text


def format_text(text: str) -> list:
"""
Formats a segment of text.
If the tag <b> is found the process transform the text in bold
If the tag <a> is found the process transform the text in link
Args:
text (str): The text to be formatted.
Returns:
list of components.
"""
formatted_text = []
formatted_text.append(
html.Span(["Warning"], className="govuk-warning-text__assistive"),
)
segments = text.split("$")
for segment in segments:
if segment.startswith("<b>"):
raw_text = segment.replace("<b>", "")
formatted_text.append(html.B(raw_text))
elif segment.startswith("<a>"):
info_link = segment.replace("<a>", "")
link_description = info_link.split("|")[0]
link = info_link.split("|")[1]
formatted_text.append(
html.A(
link_description,
href=link,
)
)
else:
formatted_text.append(segment)

return [
html.Span(
["!"], className="govuk-warning-text__icon", **{"aria-hidden": "true"}
),
html.Strong(
formatted_text,
className="govuk-warning-text__text",
),
]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
author="Department for Levelling Up, Housing and Communities",
description="Provides access to functionality common to creating a data dashboard.",
name="gov_uk_dashboards",
version="9.8.0",
version="9.9.0",
long_description=long_description,
long_description_content_type="text/markdown",
packages=find_packages(),
Expand Down

0 comments on commit f9cd45a

Please sign in to comment.