Skip to content

Commit

Permalink
🐛 Fix showPopupParams, upgrade PopupButton
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisDmitry committed Sep 4, 2023
1 parent b7f78d9 commit f1b864b
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
interface BasePopupButton {
/**
* Identifier of the button, 0-64 characters. Set to empty string by
* default.
*
* If the button is pressed, its *id* is returned in the callback and the
* *popupClosed* event.
*/
id?: string
}

interface DefaultDestructivePopupButton extends BasePopupButton {
/**
* Type of the button. Set to *default* by default.
*
* Can be one of these values:
* - *default*, a button with the default style,
* - *destructive*, a button with a style that indicates a destructive action (e.g.
* “Remove”, “Delete”, etc.).
*/
type?: 'default' | 'destructive'
/**
* The text to be displayed on the button, 0-64 characters.
*/
text: string
}

interface OkCloseCancelPopupButton extends BasePopupButton {
/**
* Type of the button.
*
* Can be one of these values:
* - *ok*, a button with the localized text “OK”,
* - *close*, a button with the localized text “Close”,
* - *cancel*, a button with the localized text “Cancel”.
*/
type: 'ok' | 'close' | 'cancel'
}

export declare namespace TelegramWebApps {
/**
* To connect your Web App to the Telegram client, place the script telegram-web-app.js
Expand Down Expand Up @@ -312,7 +351,7 @@ export declare namespace TelegramWebApps {
* *callback* function will be called and the field *id* of the pressed button will be
* passed as the first argument.
*/
showPopup(params: PopupParams, callback?: PopupClosedEventHandler): void
showPopup(params: PopupParams, callback?: (id: string) => void): void
/**
* `Bot API 6.2+` A method that shows *message* in a simple alert with a 'Close'
* button. If an optional *callback* parameter was passed, the *callback* function
Expand Down Expand Up @@ -456,33 +495,7 @@ export declare namespace TelegramWebApps {
/**
* This object describes the native popup button.
*/
interface PopupButton {
/**
* Identifier of the button, 0-64 characters. Set to empty string by
* default.
*
* If the button is pressed, its *id* is returned in the callback and the
* *popupClosed* event.
*/
id?: string
/**
* Type of the button. Set to *default* by default.
*
* Can be one of these values:
* - *default*, a button with the default style,
* - *ok*, a button with the localized text “OK”,
* - *close*, a button with the localized text “Close”,
* - *cancel*, a button with the localized text “Cancel”,
* - *destructive*, a button with a style that indicates a destructive action (e.g.
* “Remove”, “Delete”, etc.).
*/
type?: 'default' | 'ok' | 'close' | 'cancel' | 'destructive'
/**
* The text to be displayed on the button, 0-64 characters. Required if
* *type* is *default* or *destructive*. Irrelevant for other types.
*/
text?: string
}
type PopupButton = DefaultDestructivePopupButton | OkCloseCancelPopupButton

/**
* This object controls the back button, which can be displayed in the header of the Web
Expand Down

0 comments on commit f1b864b

Please sign in to comment.