diff --git a/src/aiogram_dialog/widgets/kbd/__init__.py b/src/aiogram_dialog/widgets/kbd/__init__.py index 07b67b98..c955d3b5 100644 --- a/src/aiogram_dialog/widgets/kbd/__init__.py +++ b/src/aiogram_dialog/widgets/kbd/__init__.py @@ -41,15 +41,20 @@ "ListGroup", "ManagedListGroup", "StubScroll", + "CopyText", ] from .base import Keyboard from .button import Button, SwitchInlineQuery, Url, WebApp from .calendar_kbd import ( - Calendar, CalendarConfig, CalendarScope, CalendarUserConfig, + Calendar, + CalendarConfig, + CalendarScope, + CalendarUserConfig, ManagedCalendar, ) from .checkbox import Checkbox, ManagedCheckbox +from .copy import CopyText from .counter import Counter, ManagedCounter from .group import Column, Group, Row from .list_group import ListGroup, ManagedListGroup diff --git a/src/aiogram_dialog/widgets/kbd/copy.py b/src/aiogram_dialog/widgets/kbd/copy.py new file mode 100644 index 00000000..c755180f --- /dev/null +++ b/src/aiogram_dialog/widgets/kbd/copy.py @@ -0,0 +1,37 @@ +from typing import Any + +from aiogram.types import CopyTextButton, InlineKeyboardButton + +from aiogram_dialog import DialogManager +from aiogram_dialog.api.internal import RawKeyboard +from aiogram_dialog.widgets.common import WhenCondition +from aiogram_dialog.widgets.kbd import Keyboard +from aiogram_dialog.widgets.text import Text + + +class CopyText(Keyboard): + def __init__( + self, + text: Text, + copy_text: Text, + when: WhenCondition = None, + ) -> None: + super().__init__(when=when) + self._text = text + self._copy_text = copy_text + + async def _render_keyboard( + self, + data: dict[str, Any], + manager: DialogManager, + ) -> RawKeyboard: + return [ + [ + InlineKeyboardButton( + text=await self._text.render_text(data, manager), + copy_text=CopyTextButton( + text=await self._copy_text.render_text(data, manager), + ), + ), + ], + ]