Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added text and divider component #81

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions vizro-core/src/vizro/models/_controls/divider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Dict, Literal

from dash import html

from vizro.models import VizroBaseModel
from vizro.models._models_utils import _log_call


class Divider(VizroBaseModel):
"""Creates a divider utilizing dash html component.

Args:
type (Literal["divider"]): Defaults to `"divider"`.
style (Dict[str, str]): Style dictionary to pass to html component. Default to
a solid gray line with 100% width.
"""

type: Literal["divider"] = "divider"
style: Dict[str, str] = {
"borderWidth": "0.1vh",
"width": "100%",
"borderColor": "#33353f",
"borderStyle": "solid",
}

@_log_call
def build(self):
return html.Hr(
style=self.style,
className="divider_container",
id=f"{self.id}_outer",
)
32 changes: 32 additions & 0 deletions vizro-core/src/vizro/models/_controls/text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Literal

from dash import dcc, html

from vizro.models import VizroBaseModel
from vizro.models._models_utils import _log_call


class Text(VizroBaseModel):
"""Creates a text utilizing `dcc.Markdown` as text component.

Args:
type (Literal["text"]): Defaults to `"text"`.
text (str): Markdown string to create text that should adhere to the CommonMark Spec.
"""

type: Literal["text"] = "text"
text: str

@_log_call
def build(self):
text = dcc.Markdown(
self.text,
className="text",
dangerously_allow_html=False,
id=self.id,
)
return html.Div(
text,
className="text_container",
id=f"{self.id}_outer",
)
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/models/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class OptionsDictType(TypedDict):
]

ControlType = Annotated[
Union["Filter", "Parameter"],
Union["Divider", "Filter", "Parameter", "Text"],
Field(
discriminator="type",
description="Control that affects components on the page.",
Expand Down