@telegram-apps/sdk
Version:
TypeScript Source Development Kit for Telegram Mini Apps client application.
67 lines (66 loc) • 2.37 kB
TypeScript
import { EventListener } from '@telegram-apps/bridge';
import { State } from './types.js';
/**
* Mounts the Main Button restoring its state.
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @example
* if (mount.isAvailable()) {
* mount();
* }
*/
export declare const mount: import('../../wrappers/wrapSafe.js').SafeWrapped<() => void, false, never>;
/**
* Adds a new Main Button click listener.
* @param fn - event listener.
* @returns A function to remove bound listener.
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @example
* if (onClick.isAvailable()) {
* const off = onClick(() => {
* console.log('User clicked the Main Button');
* off();
* });
* }
*/
export declare const onClick: import('../../wrappers/wrapSafe.js').SafeWrapped<(fn: EventListener<"main_button_pressed">) => VoidFunction, false, never>;
/**
* Removes the Main Button click listener.
* @param fn - an event listener.
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @example
* if (offClick.isAvailable()) {
* function listener() {
* console.log('User clicked the Main Button');
* offClick(listener);
* }
* onClick(listener);
* }
*/
export declare const offClick: import('../../wrappers/wrapSafe.js').SafeWrapped<(fn: EventListener<"main_button_pressed">) => void, false, never>;
/**
* Updates the Main Button state.
* @param updates - state changes to perform.
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @throws {FunctionNotAvailableError} The parent component is not mounted
* @example
* if (setParams.isAvailable()) {
* setParams({
* text: 'Submit',
* isEnabled: true,
* hasShineEffect: true,
* });
* }
*/
export declare const setParams: import('../../wrappers/wrapSafe.js').SafeWrapped<(updates: Partial<State>) => void, false, never>;
/**
* Unmounts the Main Button.
*
* Note that this function does not remove listeners added via the `onClick`
* function, so you have to remove them on your own.
* @see onClick
*/
export declare function unmount(): void;