@telegram-apps/sdk
Version:
TypeScript Source Development Kit for Telegram Mini Apps client application.
76 lines (75 loc) • 2.86 kB
TypeScript
import { EventListener } from '@telegram-apps/bridge';
import { State } from './types.js';
/**
* Signal indicating if the Secondary Button is supported.
*/
export declare const isSupported: import('@telegram-apps/signals').Computed<boolean>;
/**
* Mounts the Secondary Button restoring its state.
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @throws {FunctionNotAvailableError} The function is not supported
* @example
* if (mount.isAvailable()) {
* mount();
* }
*/
export declare const mount: import('../../wrappers/wrapSafe.js').SafeWrapped<() => void, true, never>;
/**
* Adds a new Secondary 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
* @throws {FunctionNotAvailableError} The function is not supported
* @example
* if (onClick.isAvailable()) {
* const off = onClick(() => {
* console.log('User clicked the Secondary Button');
* off();
* });
* }
*/
export declare const onClick: import('../../wrappers/wrapSafe.js').SafeWrapped<(fn: EventListener<"secondary_button_pressed">) => VoidFunction, true, never>;
/**
* Removes the Secondary Button click listener.
* @param fn - an event listener.
* @throws {FunctionNotAvailableError} The environment is unknown
* @throws {FunctionNotAvailableError} The SDK is not initialized
* @throws {FunctionNotAvailableError} The function is not supported
* @example
* if (offClick.isAvailable()) {
* function listener() {
* console.log('User clicked the Secondary Button');
* offClick(listener);
* }
* onClick(listener);
* }
*/
export declare const offClick: import('../../wrappers/wrapSafe.js').SafeWrapped<(fn: EventListener<"secondary_button_pressed">) => void, true, never>;
/**
* Updates the Secondary 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
* @throws {FunctionNotAvailableError} The function is not supported
* @example
* if (setParams.isAvailable()) {
* setParams({
* text: 'Submit',
* isEnabled: true,
* isVisible: true,
* position: 'left',
* });
* }
*/
export declare const setParams: import('../../wrappers/wrapSafe.js').SafeWrapped<(updates: Partial<State>) => void, true, never>;
/**
* Unmounts the Secondary 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;