{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import panel as pn\n", "import panel_material_ui as pmui\n", "\n", "pn.extension()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `PasswordInput` allows entering any string using an obfuscated text input box.\n", "\n", "Discover more on using widgets to add interactivity to your applications in the [how-to guides on interactivity](https://panel.holoviz.org/how_to/interactivity/index.html). Alternatively, learn [how to set up callbacks and (JS-)links between parameters](https://panel.holoviz.org/how_to/links/index.html) or [how to use them as part of declarative UIs with Param](https://panel.holoviz.org/how_to/param/index.html).\n", "\n", "#### Parameters:\n", "\n", "For details on other options for customizing the component see the [customization guides](https://panel-material-ui.holoviz.org/customization/index.html).\n", "\n", "##### Core\n", "\n", "* **`disabled`** (boolean): Whether the widget is editable\n", "* **`value`** (str): The current value updated when pressing `` key.\n", "* **`value_input`** (str): The current value updated on every key press.\n", "\n", "##### Display\n", "\n", "* **`color`** (str): The color variant of the input, which must be one of `'default'` (white), `'primary'` (blue), `'success'` (green), `'info'` (yellow), `'light'` (light), or `'danger'` (red).\n", "* **`error_state`** (boolean): Indicates an invalid text entry.\n", "* **`max_length`** (int): The maximum number of allowed characters.\n", "* **`label`** (str): The title of the widget\n", "* **`placeholder`** (str): A placeholder string displayed when no value is entered.\n", "* **`size`** (`Literal[\"small\", \"medium\"]`): The size variant of the widget.\n", "* **`variant`** (`Literal[\"filled\", \"outlined\", \"standard\"]`): The variant of the input field.\n", "\n", "##### Styling\n", "\n", "- **`sx`** (dict): Component level styling API.\n", "- **`theme_config`** (dict): Theming API.\n", "\n", "##### Aliases\n", "\n", "For compatibility with Panel certain parameters are allowed as aliases:\n", "\n", "- **`name`**: Alias for `label`\n", "\n", "___" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Basic Usage\n", "\n", "The `PasswordInput` widget provides a simple text entry form and supports a `placeholder` which is displayed when the `value` is empty:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "password_input = pmui.PasswordInput(label='Password', placeholder='Enter your password here...')\n", "password_input" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "``PasswordInput.value`` returns a string type that can be read out and set like other widgets:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "password_input.value" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Value Input" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `PasswordInput.value` is updated after an `enter_pressed` event or when switching focus, i.e. when clicking or tabbing away from the widget. To get the current value after every keystroke you can inspect the `value_input` instead:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "value = pmui.PasswordInput(label='Value Input', value='Hello W')\n", "value_input = pmui.PasswordInput(label='Value Input', value='Hello W')\n", "\n", "pmui.Column(\n", " pmui.Row(value, pmui.Typography(value.param.value)),\n", " pmui.Row(value_input, pmui.Typography(value_input.param.value_input))\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Maximum Length\n", "\n", "The `max_length` controls the maximum number of characters that can be entered:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.PasswordInput(label='Password (max_length=12)', max_length=12)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Error State\n", "\n", "The `error_state` parameter allows setting of the message that is displayed if validation of the input fails." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.PasswordInput(label='PasswordInput (invalid entry)', error_state=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Disabled and Loading\n", "\n", "Like other widgets, the `PasswordInput` can be disabled and/or show a loading indicator." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "pmui.PasswordInput(\n", " label='Text Input', disabled=True, loading=True,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Color Options\n", "\n", "You can set the `color` parameter to visually distinguish the `PasswordInput` when active. Available options include \"default\", \"primary\", \"secondary\", \"error\", \"info\", \"success\", \"warning\", \"light\", \"dark\", and \"danger\":" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "pmui.FlexBox(\n", " *[pmui.PasswordInput(label=color, color=color) for color in pmui.PasswordInput.param.color.objects]\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Size\n", "\n", "The `size` parameter allows toggling between \"small\" and \"medium\" (default) sized input fields:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.FlexBox(\n", " pmui.PasswordInput(label='Small', size=\"small\"),\n", " pmui.PasswordInput(label='Medium', size=\"medium\"),\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Variant\n", "\n", "The `variant` parameter controls the visual style of the input. Choose from \"filled\", \"outlined\" (default), or \"standard\":" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.FlexBox(\n", " pmui.PasswordInput(label='Filled', variant=\"filled\"),\n", " pmui.PasswordInput(label='Outlined', variant=\"outlined\"),\n", " pmui.PasswordInput(label='Standard', variant=\"standard\"),\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### API Reference\n", "\n", "#### Parameters" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.PasswordInput(\n", " label='PasswordInput'\n", ").api(jslink=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### References\n", "\n", "**Panel Documentation:**\n", "\n", "- [How-to guides on interactivity](https://panel.holoviz.org/how_to/interactivity/index.html) - Learn how to add interactivity to your applications using widgets\n", "- [Setting up callbacks and links](https://panel.holoviz.org/how_to/links/index.html) - Connect parameters between components and create reactive interfaces\n", "- [Declarative UIs with Param](https://panel.holoviz.org/how_to/param/index.html) - Build parameter-driven applications\n", "\n", "**Material UI AutoComplete:**\n", "\n", "- [Material UI TextField Reference](https://mui.com/material-ui/react-text-field) - Complete documentation for the underlying Material UI component\n", "- [Material UI TextField API](https://mui.com/material-ui/api/text-field/) - Detailed API reference and configuration options" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.Row(password_input.controls(jslink=True), password_input)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.2" } }, "nbformat": 4, "nbformat_minor": 4 }