{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from awesome_panel_extensions.awesome_panel.notebook import Header\n",
"Header(folder=\"examples/reference/frameworks/fast\", notebook=\"FastLiteralAreaInput.ipynb\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Fast LiteralAreaInput - Reference Guide\n",
"\n",
"The `FastLiteralAreaInput` widget is based on the [fast-text-field](https://explore.fast.design/components/fast-text-field) web component and extends the built in [Panel LiteralAreaInput](https://panel.holoviz.org/reference/widgets/LiteralAreaInput.html) widget.\n",
"\n",
"
\n",
" \n",
" | \n",
"
\n",
"
\n",
"\n",
"\n",
"#### Parameters:\n",
"\n",
"##### Core\n",
"\n",
"* **``value``** (str): Parsed value of the indicated type\n",
"* **``type``** (type or tuple(type)): A Python literalarea type (e.g. list, dict, set, int, float, bool, str)\n",
"* **``serializer (str['ast', 'json])``**: The serialization (and deserialization) method to use. 'ast' uses ast.literalarea_eval and 'json' uses json.loads and json.dumps.\n",
"\n",
"###### Display\n",
"\n",
"\n",
"* **``name``** (str): The label of the LiteralAreaInput.\n",
"* **``placeholder``** (string): A placeholder string displayed when no value is entered.\n",
"* **``apperance``** (string): Determines the appearance of the LiteralAreaInput. One of `outline` or `filled`. Defaults to `outline`.\n",
"* **``max_length``** (integer): The maximum number of characters. Default is 5000.\n",
"* **``disabled``** (boolean): Whether or not the LiteralAreaInput is disabled. Defaults to False.\n",
"* **``readonly``** (bool): Whether or not the LiteralAreaInput is read only. Defaults to `False`.\n",
"\n",
"\n",
"\n",
"The `FastLiteralAreaInput` has the same layout and styling parameters as most other widgets. For example `width` and `sizing_mode`.\n",
"\n",
"Please note that you can only use the Fast components inside a custom Panel template that\n",
"\n",
"- Loads the [Fast `javascript` library](https://www.fast.design/docs/components/getting-started#from-cdn).\n",
"- Wraps the content of the `` html tag inside the [fast-design-system-provider](https://www.fast.design/docs/components/getting-started#add-components) tag.\n",
"\n",
"We provide the `FastTemplate` for easy usage. \n",
"\n",
"You can also develop your own custom [Panel template](https://panel.holoviz.org/user_guide/Templates.html) if you need something special. For example combining it with more [fast.design](https://fast.design/) web components and the [Fluent Design System](https://www.microsoft.com/design/fluent/#/) to create **VS Code** and **Microsoft Office** like experiences.\n",
"\n",
"Please note that Fast components will not work in older, legacy browser like Internet Explorer.\n",
"\n",
"___\n",
"\n",
"Let's start by importing the dependencies"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import param\n",
"import panel as pn\n",
"from awesome_panel_extensions.frameworks.fast import FastTemplate, FastLiteralAreaInput\n",
"\n",
"pn.config.sizing_mode = \"stretch_width\"\n",
"pn.extension()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Parameters\n",
"\n",
"Let's explore the parameters of the `FastLiteralAreaInput`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"LiteralAreaInput = FastLiteralAreaInput(name=\"List Input\", sizing_mode=\"fixed\", width=300, appearance=\"outline\", placeholder=\"Input a list. For example ['a', 'b']\", type=list)\n",
"\n",
"app=pn.Row(\n",
" LiteralAreaInput\n",
")\n",
"template=FastTemplate(main=[app])\n",
"template"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"LiteralAreaInput_parameters = [\"name\", \"value\", \"disabled\", \"placeholder\", \"appearance\", \"autofocus\", \"readonly\", \"height\", \"width\", \"sizing_mode\"]\n",
"\n",
"settings_pane = pn.WidgetBox(pn.Param(LiteralAreaInput, parameters=LiteralAreaInput_parameters, show_name=False))\n",
"settings_pane"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## pn.Param\n",
"\n",
"Let's verify that that `FastLiteralAreaInput` can be used as a widget by `pn.Param`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import param\n",
"import panel as pn\n",
"WIDGETS = {\n",
" \"a_literalarea\": {\n",
" \"type\": FastLiteralAreaInput, \"sizing_mode\": \"fixed\", \"width\": 400, \"placeholder\": \"Input a dictionary!\"\n",
" }\n",
"}\n",
"\n",
"class ParameterizedApp(param.Parameterized):\n",
" a_literalarea = param.Dict(default=None, label=\"A Dictionary\")\n",
" view = param.Parameter()\n",
" \n",
" \n",
" def __init__(self, **params):\n",
" super().__init__(**params)\n",
" \n",
" self.view = pn.Param(self, parameters=[\"a_literalarea\"], widgets=WIDGETS)\n",
" \n",
"parameterized_app = ParameterizedApp()\n",
"paremeterized_template = FastTemplate(main=[parameterized_app.view])\n",
"paremeterized_template"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pn.Param(parameterized_app.param.a_literalarea)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Resources\n",
"\n",
"- [fast.design](https://fast.design/)\n",
"- [fast-text-field](https://explore.fast.design/components/fast-text-field)\n",
"\n",
"## Known Issues\n",
"\n",
"- The `fast-text-area` attributes `height` and also `autofocus`, `rows`, `min_length` and `spellcheck` do not seem to work. If you would like them to work please upvote [Fast Github Issue 3874](https://github.com/microsoft/fast/issues/3874).\n",
"- It's not possible to specify the `type` of literalarea in a `pn.Parameterized` class. See [Panel Github 1574](https://github.com/holoviz/panel/issues/1574).\n",
"\n",
"\n",
" \n",
" | \n",
"
\n",
"
\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}