diff --git a/gov_uk_dashboards/components/plotly/warning_text.py b/gov_uk_dashboards/components/plotly/warning_text.py index db78043..ca8cc47 100644 --- a/gov_uk_dashboards/components/plotly/warning_text.py +++ b/gov_uk_dashboards/components/plotly/warning_text.py @@ -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 is found the process transform the text in bold + If the tag 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(""): + raw_text = segment.replace("", "") + formatted_text.append(html.B(raw_text)) + elif segment.startswith(""): + info_link = segment.replace("", "") + 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", + ), + ] diff --git a/setup.py b/setup.py index e0ce372..d61e380 100644 --- a/setup.py +++ b/setup.py @@ -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(),