From 84cc6cd18e810252dcbdfc1ced2c2df5cb95d413 Mon Sep 17 00:00:00 2001 From: David Lev Date: Wed, 15 Jan 2025 23:38:30 +0200 Subject: [PATCH] [flows] adding support for `ChipsSelector` component --- docs/source/content/flows/flow_json.rst | 2 + docs/source/content/flows/overview.rst | 1 + pywa/types/flows.py | 57 +++++++++++++++++++++++++ pywa_async/types/flows.py | 1 + 4 files changed, 61 insertions(+) diff --git a/docs/source/content/flows/flow_json.rst b/docs/source/content/flows/flow_json.rst index e3cb7e0..a983568 100644 --- a/docs/source/content/flows/flow_json.rst +++ b/docs/source/content/flows/flow_json.rst @@ -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() diff --git a/docs/source/content/flows/overview.rst b/docs/source/content/flows/overview.rst index 7605023..8fcaacf 100644 --- a/docs/source/content/flows/overview.rst +++ b/docs/source/content/flows/overview.rst @@ -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`, diff --git a/pywa/types/flows.py b/pywa/types/flows.py index b7d6302..c5b5db9 100644 --- a/pywa/types/flows.py +++ b/pywa/types/flows.py @@ -76,6 +76,7 @@ "InputType", "TextArea", "CheckboxGroup", + "ChipsSelector", "RadioButtonsGroup", "Footer", "OptIn", @@ -1447,6 +1448,7 @@ class ComponentType(utils.StrEnum): IF = "If" SWITCH = "Switch" NAVIGATION_LIST = "NavigationList" + CHIPS_SELECTOR = "ChipsSelector" class _Expr(abc.ABC): @@ -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 `_. + + 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): """ diff --git a/pywa_async/types/flows.py b/pywa_async/types/flows.py index 74ef376..b979c30 100644 --- a/pywa_async/types/flows.py +++ b/pywa_async/types/flows.py @@ -38,6 +38,7 @@ "InputType", "TextArea", "CheckboxGroup", + "ChipsSelector", "RadioButtonsGroup", "Footer", "OptIn",