from awesome_panel_extensions.awesome_panel.notebook import Header
Header(folder="examples/reference/frameworks/fast", notebook="FastSwitch.ipynb")
The FastSwitch
widget is based on the fast-switch web component and extends the built in Panel Checkbox.
name
(str): The label of the Switch. Defaults to "".value
(boolean): Whether or not the Switch is checked. Defaults to False.checked_message
(str): The message shown when checked. Default to "".unchecked_message
(str): The message shown when not checked. Default to "".disabled
(boolean): Whether or not the Switch is disabled. Defaults to False.readonly
(boolean): Whether or not the Switch is readonly. Defaults to False.The FastSwitch
has the same layout and styling parameters as most other widgets. For example width
and sizing_mode
.
Please note that you can only use the Fast components inside a custom Panel template that
javascript
library.<body>
html tag inside the fast-design-system-provider tag.We provide the FastTemplate
for easy usage.
You can also develop your own custom Panel template if you need something special. For example combining it with more fast.design web components and the Fluent Design System to create VS Code and Microsoft Office like experiences.
Please note that Fast components will not work in older, legacy browser like Internet Explorer.
Let's start by importing the dependencies
import param
import panel as pn
from awesome_panel_extensions.frameworks.fast import FastTemplate, FastSwitch
pn.config.sizing_mode = "stretch_width"
pn.extension()
Let's explore the parameters of the FastSwitch
.
switch = FastSwitch(name="I'm a fast-switch!", sizing_mode="fixed", value=True, checked_message="Sure you are!", unchecked_message="No. You are now a Panel FastSwitch 😉")
app=pn.Row(
switch
)
template=FastTemplate(main=[app])
template
switch_parameters = ["name", "value", "checked_message", "unchecked_message", "disabled", "readonly", "width", "height", "sizing_mode"]
settings_pane = pn.WidgetBox(pn.Param(switch, parameters=switch_parameters, show_name=False))
settings_pane
Let's verify that that FastSwitch
can be used as a widget by pn.Param
.
WIDGETS = {
"panel_is_awesome": {"type": FastSwitch, "checked_message": ".. and very powerful 💪", "unchecked_message": ".. But it takes time to learn 🧠 and discover the power 💪! "}
}
class ParameterizedApp(param.Parameterized):
panel_is_awesome = param.Boolean(default=True, label="Panel is awesome")
view = param.Parameter()
def __init__(self, **params):
super().__init__(**params)
self.view = pn.Param(self, parameters=["panel_is_awesome"], widgets=WIDGETS, name="Parameterized Switch App")
parameterized_app = ParameterizedApp()
paremeterized_template = FastTemplate(main=[parameterized_app.view])
paremeterized_template
readonly
only the name/ label has the readonly hover icon. See Fast Github Issue 3893.