Skip to content

Commit

Permalink
[flows] adding support for ChipsSelector component
Browse files Browse the repository at this point in the history
  • Loading branch information
david-lev committed Jan 15, 2025
1 parent 81027da commit 84cc6cd
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/source/content/flows/flow_json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Here you will find all the components that make up a Flow JSON object.

.. autoclass:: CheckboxGroup()

.. autoclass:: ChipsSelector()

.. autoclass:: RadioButtonsGroup()

.. autoclass:: MediaSize()
Expand Down
1 change: 1 addition & 0 deletions docs/source/content/flows/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Every component on the FlowJSON has a corresponding class in :mod:`pywa.types.fl
:class:`TextArea`,
:class:`RadioButtonsGroup`,
:class:`CheckboxGroup`,
:class:`ChipsSelector`,
:class:`Dropdown`,
:class:`OptIn`,
:class:`DatePicker`,
Expand Down
57 changes: 57 additions & 0 deletions pywa/types/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"InputType",
"TextArea",
"CheckboxGroup",
"ChipsSelector",
"RadioButtonsGroup",
"Footer",
"OptIn",
Expand Down Expand Up @@ -1447,6 +1448,7 @@ class ComponentType(utils.StrEnum):
IF = "If"
SWITCH = "Switch"
NAVIGATION_LIST = "NavigationList"
CHIPS_SELECTOR = "ChipsSelector"


class _Expr(abc.ABC):
Expand Down Expand Up @@ -2494,6 +2496,61 @@ class Dropdown(FormComponent):
on_unselect_action: UpdateDataAction | None = None


@dataclasses.dataclass(slots=True, kw_only=True)
class ChipsSelector(FormComponent):
"""
Chips Selector component allows users to pick multiple selections from a list of options.
- Added in v6.3
- Read more at `developers.facebook.com <https://developers.facebook.com/docs/whatsapp/flows/reference/components#chips_selector>`_.
Example:
>>> ChipsSelector(
... name='options',
... data_source=[
... DataSource(id='1', title='Option 1'),
... DataSource(id='2', title='Option 2'),
... DataSource(id='3', title='Option 3'),
... ],
... label='Options',
... min_selected_items=1,
... max_selected_items=2,
... required=True,
... init_value=['1', '2']
... )
Attributes:
name: The unique name (id) for this component.
data_source: The data source of the chips selector.
label: The label of the chips selector. Limited to 80 characters.
description: The description of the chips selector. Limited to 300 characters
min_selected_items: The minimum number of items that can be selected. Minimum value is 1.
max_selected_items: The maximum number of items that can be selected. Maximum value is 20.
required: Whether the chips selector is required or not.
visible: Whether the chips selector is visible or not. Default to ``True``.
enabled: Whether the chips selector is enabled or not. Default to ``True``.
init_value: The default values (IDs of the data sources).
on_select_action: The action to perform when an item is selected.
"""

type: ComponentType = dataclasses.field(
default=ComponentType.CHIPS_SELECTOR, init=False, repr=False
)
name: str
data_source: Iterable[DataSource] | str | ScreenDataRef | ComponentRef
label: str | FlowStr | ScreenDataRef | ComponentRef
description: str | FlowStr | ScreenDataRef | ComponentRef | None = None
min_selected_items: int | str | ScreenDataRef | ComponentRef | None = None
max_selected_items: int | str | ScreenDataRef | ComponentRef | None = None
required: bool | str | ScreenDataRef | ComponentRef | None = None
visible: bool | str | Condition | ScreenDataRef | ComponentRef | None = None
enabled: bool | str | ScreenDataRef | ComponentRef | None = None
init_value: list[str] | str | ScreenDataRef | ComponentRef | None = None
on_select_action: DataExchangeAction | UpdateDataAction | None = None
on_unselect_action: UpdateDataAction | None = None


@dataclasses.dataclass(slots=True, kw_only=True)
class Footer(Component):
"""
Expand Down
1 change: 1 addition & 0 deletions pywa_async/types/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"InputType",
"TextArea",
"CheckboxGroup",
"ChipsSelector",
"RadioButtonsGroup",
"Footer",
"OptIn",
Expand Down

0 comments on commit 84cc6cd

Please sign in to comment.