Конструктор класса
Инициализирует пустой массив кнопок
Массив кнопок для отображения
Static
Readonly
GROUP_Ключ для группировки кнопок
const vkButton = new VkButton();
// Группировка кнопок
const button1 = new Button();
button1.initBtn('Кнопка 1', '', null, { [VkButton.GROUP_NAME]: '0' });
const button2 = new Button();
button2.initBtn('Кнопка 2', '', null, { [VkButton.GROUP_NAME]: '0' });
const button3 = new Button();
button3.initBtn('Кнопка 3', '', null, { [VkButton.GROUP_NAME]: '1' });
vkButton.buttons = [button1, button2, button3];
const result = vkButton.getButtons();
// result: {
// one_time: true,
// buttons: [
// [{ action: { type: 'text', label: 'Кнопка 1' } },
// { action: { type: 'text', label: 'Кнопка 2' } }],
// [{ action: { type: 'text', label: 'Кнопка 3' } }]
// ]
// }
Получение кнопок в формате ВКонтакте
Поддерживаемые типы кнопок:
Поддерживаемые цвета кнопок:
const vkButton = new VkButton();
// Создание кнопки оплаты
const payButton = new Button();
payButton.initBtn('Оплатить', '', null, {
type: Button.VK_TYPE_PAY,
hash: 'payment_hash'
});
vkButton.buttons = [payButton];
const payResult = vkButton.getButtons();
// payResult: {
// one_time: true,
// buttons: [{
// action: { type: 'pay', label: 'Оплатить' },
// hash: 'payment_hash'
// }]
// }
// Создание кнопок с разными цветами
const confirmButton = new Button();
confirmButton.initBtn('Подтвердить', '', null, { color: 'positive' });
const cancelButton = new Button();
cancelButton.initBtn('Отменить', '', null, { color: 'negative' });
vkButton.buttons = [confirmButton, cancelButton];
const colorResult = vkButton.getButtons();
// colorResult: {
// one_time: true,
// buttons: [
// { action: { type: 'text', label: 'Подтвердить' }, color: 'positive' },
// { action: { type: 'text', label: 'Отменить' }, color: 'negative' }
// ]
// }
VkButton Класс для работы с кнопками в ВКонтакте
Предоставляет функциональность для создания и отображения кнопок в ВКонтакте:
Example