{ "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 `MultiChoice` widget allows selecting multiple values from a list of options. It falls into the broad category of multi-value, option-selection widgets that provide a compatible API and include the [`MultiSelect`](MultiSelect.ipynb), [`CrossSelector`](CrossSelector.ipynb), [`CheckBoxGroup`](CheckBoxGroup.ipynb) and [`CheckButtonGroup`](CheckButtonGroup.ipynb) widgets. The `MultiChoice` widget provides a much more compact UI than [`MultiSelect`](MultiSelect.ipynb).\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", "* **`bookmarks`** (list): List of bookmarked options that are rendered first.\n", "* **`disabled`** (boolean): Whether the widget is editable\n", "* **`disabled_options`** (list): List of options that are disabled.\n", "* **`filter_on_search`** (boolean): Whether to filter or highlight the matching options on search.\n", "* **`option_limit`** (int): Maximum number of options to display at once.\n", "* **`options`** (list or dict): List or dictionary of options\n", "* **`search_option_limit`** (int): Maximum number of options to display at once if search string is entered.\n", "* **`max_items`** (int): Maximum number of options that can be selected\n", "* **`searchable`** (boolean): Whether to render a search box.\n", "* **`value`** (list): Currently selected option values\n", "\n", "##### Display\n", "\n", "* **`color`** (str): The color variant of the input and indicating the selected item(s), which must be one of `'default'` (white), `'primary'` (blue), `'success'` (green), `'info'` (yellow), `'light'` (light), or `'danger'` (red).\n", "* **`delete_button`** (boolean): Whether to display a button to delete a selected option\n", "* **`dropdown_height`** (int | None): Height of the select dropdown.\n", "* **`label`** (str): The title of the widget\n", "* **`placeholder`** (str): String displayed when no selection has been made.\n", "* **`solid`** (boolean): Whether to display widget with solid or light style.\n", "* **`variant`** (str): One of filled, outlined (default), or standard.\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", "- **`button_style`**: Alias for `variant`\n", "- **`button_type`**: Alias for `color`\n", "- **`name`**: Alias for `label`\n", "___" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Basic Usage\n", "\n", "The `MultiChoice` widget allows selecting multiple values from a list of `options`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "multi_choice = pmui.MultiChoice(label='MultiChoice', value=['Apple', 'Pear'],\n", " options=['Apple', 'Banana', 'Pear', 'Strawberry'])\n", "\n", "pmui.Column(multi_choice, height=250)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "``MultiChoice.value`` returns a list of the currently selected options:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "multi_choice.value" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `options` parameter also accepts a dictionary whose keys are going to be the labels of the dropdown menu. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ages = pmui.MultiChoice(\n", " label='Ages', options={'Ten': 10, 'Twenty': 20, 'Thirty': 30}, height=200\n", ")\n", "\n", "ages" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ages.value" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Updating the value will display the right label." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ages.value = [20, 30]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Filled and Standard Variants" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.Row(\n", " pmui.MultiChoice(label='Fruits', value=['Apple', 'Pear'], options=['Apple', 'Banana', 'Pear', 'Strawberry'], variant=\"standard\"),\n", " pmui.MultiChoice(label='Fruits', value=['Apple', 'Pear'], options=['Apple', 'Banana', 'Pear', 'Strawberry'], variant=\"filled\"),\n", " height=200\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Chips\n", "\n", "By default the selections are rendered as chips, this can be disabled with `chip=False`, alternatively the chip variant can be toggled with `solid=False`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.Row(\n", " pmui.MultiChoice(label='Fruits', value=['Apple', 'Pear'], options=['Apple', 'Banana', 'Pear', 'Strawberry'], chip=False),\n", " pmui.MultiChoice(label='Fruits', value=['Apple', 'Pear'], options=['Apple', 'Banana', 'Pear', 'Strawberry'], solid=False)\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Colors" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pn.FlexBox(*[pmui.MultiChoice(\n", " label=color, value=['Apple', 'Pear'], options=['Apple', 'Banana', 'Pear', 'Strawberry'], color=color\n", ") for color in pmui.Select.param.color.objects])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Disabled & Loading\n", "\n", "Like all widgets the `MultiChoice` supports `disabled` and `loading` states:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.MultiChoice(label='Ages', options=['Ten', 'Twenty', 'Thirty'], disabled=True, loading=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Searchable\n", "\n", "You can make the `MultiChoice` widget `searchable`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty'], searchable=True, height=350)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can configure whether options are filtered or merely highlighted on search." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.Row(\n", " pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty'], searchable=True, filter_on_search=True),\n", " pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty'], searchable=True, filter_on_search=False),\n", " height=350\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You may provide a default string to filter on:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty', 'Fourty', 'Fifty'], searchable=True, filter_str=\"F\", height=250)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Dropdown Height and Open State\n", "\n", "You may control the dropdown height and the drowdown open state" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty', 'Fourty', 'Fifty'], dropdown_height=200, dropdown_open=True, height=250)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Disabled Options\n", "\n", "A subset of the displayed items can be disabled with `disabled_options`. The widget `value` cannot be set to one of the `disabled_options`, either programmatrically or with the user interface." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty'], disabled_options=['Twenty'], height=200)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Bookmarks" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty', 'Fourty', 'Fifty'], bookmarks=['Ten', 'Fourty'], height=250).show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### API Reference\n", "\n", "#### Parameters\n", "\n", "The `MultiChoice` widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty', 'Fourty', 'Fifty']).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 Select:**\n", "\n", "- [Material UI Select Reference](https://mui.com/material-ui/react-select/) - Complete documentation for the underlying Material UI component\n", "- [Material UI Select API](https://mui.com/material-ui/api/select/) - Detailed API reference and configuration options" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pmui.Row(multi_choice.controls(jslink=True), multi_choice)" ] } ], "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 }