Inline Buttons: Support colors and icons (#6700)

This commit is contained in:
zubiden 2026-02-22 23:43:44 +01:00 committed by Alexander Zinchuk
parent f65b568cfb
commit 5a7b0b1492
17 changed files with 1385 additions and 1210 deletions

View File

@ -16,6 +16,8 @@ import type {
ApiInlineQueryPeerType, ApiInlineQueryPeerType,
ApiInlineResultType, ApiInlineResultType,
ApiKeyboardButton, ApiKeyboardButton,
ApiKeyboardButtonBase,
ApiKeyboardButtonStyle,
ApiMessagesBotApp, ApiMessagesBotApp,
ApiReplyKeyboard, ApiReplyKeyboard,
MediaContainer, MediaContainer,
@ -23,7 +25,7 @@ import type {
} from '../../types'; } from '../../types';
import { int2hex } from '../../../util/colors'; import { int2hex } from '../../../util/colors';
import { pick } from '../../../util/iteratees'; import { omitUndefined, pick } from '../../../util/iteratees';
import { toJSNumber } from '../../../util/numbers'; import { toJSNumber } from '../../../util/numbers';
import { addDocumentToLocalDb } from '../helpers/localDb'; import { addDocumentToLocalDb } from '../helpers/localDb';
import { serializeBytes } from '../helpers/misc'; import { serializeBytes } from '../helpers/misc';
@ -50,10 +52,15 @@ export function buildReplyButtons(
const markup = replyMarkup.rows.map(({ buttons }) => { const markup = replyMarkup.rows.map(({ buttons }) => {
return buttons.map((button): ApiKeyboardButton | undefined => { return buttons.map((button): ApiKeyboardButton | undefined => {
const { text } = button; const { text, style } = button;
const baseButton = omitUndefined<ApiKeyboardButtonBase>({
style: style && buildApiKeyboardButtonStyle(style),
});
if (button instanceof GramJs.KeyboardButton) { if (button instanceof GramJs.KeyboardButton) {
return { return {
...baseButton,
type: 'command', type: 'command',
text, text,
}; };
@ -62,12 +69,14 @@ export function buildReplyButtons(
if (button instanceof GramJs.KeyboardButtonUrl) { if (button instanceof GramJs.KeyboardButtonUrl) {
if (button.url.includes('?startgroup=')) { if (button.url.includes('?startgroup=')) {
return { return {
...baseButton,
type: 'unsupported', type: 'unsupported',
text, text,
}; };
} }
return { return {
...baseButton,
type: 'url', type: 'url',
text, text,
url: button.url, url: button.url,
@ -77,12 +86,14 @@ export function buildReplyButtons(
if (button instanceof GramJs.KeyboardButtonCallback) { if (button instanceof GramJs.KeyboardButtonCallback) {
if (button.requiresPassword) { if (button.requiresPassword) {
return { return {
...baseButton,
type: 'unsupported', type: 'unsupported',
text, text,
}; };
} }
return { return {
...baseButton,
type: 'callback', type: 'callback',
text, text,
data: serializeBytes(button.data), data: serializeBytes(button.data),
@ -91,6 +102,7 @@ export function buildReplyButtons(
if (button instanceof GramJs.KeyboardButtonRequestPoll) { if (button instanceof GramJs.KeyboardButtonRequestPoll) {
return { return {
...baseButton,
type: 'requestPoll', type: 'requestPoll',
text, text,
isQuiz: button.quiz, isQuiz: button.quiz,
@ -99,6 +111,7 @@ export function buildReplyButtons(
if (button instanceof GramJs.KeyboardButtonRequestPhone) { if (button instanceof GramJs.KeyboardButtonRequestPhone) {
return { return {
...baseButton,
type: 'requestPhone', type: 'requestPhone',
text, text,
}; };
@ -107,11 +120,13 @@ export function buildReplyButtons(
if (button instanceof GramJs.KeyboardButtonBuy) { if (button instanceof GramJs.KeyboardButtonBuy) {
if (receiptMessageId) { if (receiptMessageId) {
return { return {
...baseButton,
type: 'receipt', type: 'receipt',
receiptMessageId, receiptMessageId,
}; };
} }
return { return {
...baseButton,
type: 'buy', type: 'buy',
text, text,
}; };
@ -119,6 +134,7 @@ export function buildReplyButtons(
if (button instanceof GramJs.KeyboardButtonGame) { if (button instanceof GramJs.KeyboardButtonGame) {
return { return {
...baseButton,
type: 'game', type: 'game',
text, text,
}; };
@ -126,6 +142,7 @@ export function buildReplyButtons(
if (button instanceof GramJs.KeyboardButtonSwitchInline) { if (button instanceof GramJs.KeyboardButtonSwitchInline) {
return { return {
...baseButton,
type: 'switchBotInline', type: 'switchBotInline',
text, text,
query: button.query, query: button.query,
@ -135,6 +152,7 @@ export function buildReplyButtons(
if (button instanceof GramJs.KeyboardButtonUserProfile) { if (button instanceof GramJs.KeyboardButtonUserProfile) {
return { return {
...baseButton,
type: 'userProfile', type: 'userProfile',
text, text,
userId: button.userId.toString(), userId: button.userId.toString(),
@ -143,6 +161,7 @@ export function buildReplyButtons(
if (button instanceof GramJs.KeyboardButtonSimpleWebView) { if (button instanceof GramJs.KeyboardButtonSimpleWebView) {
return { return {
...baseButton,
type: 'simpleWebView', type: 'simpleWebView',
text, text,
url: button.url, url: button.url,
@ -151,6 +170,7 @@ export function buildReplyButtons(
if (button instanceof GramJs.KeyboardButtonWebView) { if (button instanceof GramJs.KeyboardButtonWebView) {
return { return {
...baseButton,
type: 'webView', type: 'webView',
text, text,
url: button.url, url: button.url,
@ -159,6 +179,7 @@ export function buildReplyButtons(
if (button instanceof GramJs.KeyboardButtonUrlAuth) { if (button instanceof GramJs.KeyboardButtonUrlAuth) {
return { return {
...baseButton,
type: 'urlAuth', type: 'urlAuth',
text, text,
url: button.url, url: button.url,
@ -168,6 +189,7 @@ export function buildReplyButtons(
if (button instanceof GramJs.KeyboardButtonCopy) { if (button instanceof GramJs.KeyboardButtonCopy) {
return { return {
...baseButton,
type: 'copy', type: 'copy',
text, text,
copyText: button.copyText, copyText: button.copyText,
@ -175,6 +197,7 @@ export function buildReplyButtons(
} }
return { return {
...baseButton,
type: 'unsupported', type: 'unsupported',
text, text,
}; };
@ -193,6 +216,17 @@ export function buildReplyButtons(
}; };
} }
export function buildApiKeyboardButtonStyle(
style: GramJs.TypeKeyboardButtonStyle,
): ApiKeyboardButtonStyle | undefined {
const { bgPrimary, bgDanger, bgSuccess, icon } = style;
return {
type: bgPrimary ? 'primary' : bgDanger ? 'destructive' : bgSuccess ? 'success' : undefined,
iconId: icon?.toString(),
};
}
export function buildBotInlineMessage( export function buildBotInlineMessage(
sendMessage: GramJs.TypeBotInlineMessage, type: string, document?: GramJs.TypeDocument, photo?: GramJs.TypePhoto, sendMessage: GramJs.TypeBotInlineMessage, type: string, document?: GramJs.TypeDocument, photo?: GramJs.TypePhoto,
): MediaContainer & { replyMarkup?: ApiReplyKeyboard } { ): MediaContainer & { replyMarkup?: ApiReplyKeyboard } {

View File

@ -874,85 +874,94 @@ export type ApiSponsoredMessage = {
// KeyboardButtons // KeyboardButtons
interface ApiKeyboardButtonSimple { export interface ApiKeyboardButtonStyle {
type?: 'primary' | 'success' | 'destructive';
iconId?: string;
}
export interface ApiKeyboardButtonBase {
style?: ApiKeyboardButtonStyle;
}
interface ApiKeyboardButtonSimple extends ApiKeyboardButtonBase {
type: 'unsupported' | 'buy' | 'command' | 'requestPhone' | 'game'; type: 'unsupported' | 'buy' | 'command' | 'requestPhone' | 'game';
text: string; text: string;
} }
interface ApiKeyboardButtonReceipt { interface ApiKeyboardButtonReceipt extends ApiKeyboardButtonBase {
type: 'receipt'; type: 'receipt';
receiptMessageId: number; receiptMessageId: number;
} }
interface ApiKeyboardButtonUrl { interface ApiKeyboardButtonUrl extends ApiKeyboardButtonBase {
type: 'url'; type: 'url';
text: string; text: string;
url: string; url: string;
} }
interface ApiKeyboardButtonSimpleWebView { interface ApiKeyboardButtonSimpleWebView extends ApiKeyboardButtonBase {
type: 'simpleWebView'; type: 'simpleWebView';
text: string; text: string;
url: string; url: string;
} }
interface ApiKeyboardButtonWebView { interface ApiKeyboardButtonWebView extends ApiKeyboardButtonBase {
type: 'webView'; type: 'webView';
text: string; text: string;
url: string; url: string;
} }
interface ApiKeyboardButtonCallback { interface ApiKeyboardButtonCallback extends ApiKeyboardButtonBase {
type: 'callback'; type: 'callback';
text: string; text: string;
data: string; data: string;
} }
interface ApiKeyboardButtonRequestPoll { interface ApiKeyboardButtonRequestPoll extends ApiKeyboardButtonBase {
type: 'requestPoll'; type: 'requestPoll';
text: string; text: string;
isQuiz?: boolean; isQuiz?: boolean;
} }
interface ApiKeyboardButtonSwitchBotInline { interface ApiKeyboardButtonSwitchBotInline extends ApiKeyboardButtonBase {
type: 'switchBotInline'; type: 'switchBotInline';
text: string; text: string;
query: string; query: string;
isSamePeer?: boolean; isSamePeer?: boolean;
} }
interface ApiKeyboardButtonUserProfile { interface ApiKeyboardButtonUserProfile extends ApiKeyboardButtonBase {
type: 'userProfile'; type: 'userProfile';
text: string; text: string;
userId: string; userId: string;
} }
interface ApiKeyboardButtonUrlAuth { interface ApiKeyboardButtonUrlAuth extends ApiKeyboardButtonBase {
type: 'urlAuth'; type: 'urlAuth';
text: string; text: string;
url: string; url: string;
buttonId: number; buttonId: number;
} }
interface ApiKeyboardButtonCopy { interface ApiKeyboardButtonCopy extends ApiKeyboardButtonBase {
type: 'copy'; type: 'copy';
text: string; text: string;
copyText: string; copyText: string;
} }
export interface KeyboardButtonSuggestedMessage { export interface KeyboardButtonSuggestedMessage extends ApiKeyboardButtonBase {
type: 'suggestedMessage'; type: 'suggestedMessage';
text: string; text: string;
buttonType: 'approve' | 'decline' | 'suggestChanges'; buttonType: 'approve' | 'decline' | 'suggestChanges';
disabled?: boolean; disabled?: boolean;
} }
export interface KeyboardButtonOpenThread { export interface KeyboardButtonOpenThread extends ApiKeyboardButtonBase {
type: 'openThread'; type: 'openThread';
text: string; text: string;
} }
export interface KeyboardButtonGiftOffer { export interface KeyboardButtonGiftOffer extends ApiKeyboardButtonBase {
type: 'giftOffer'; type: 'giftOffer';
text: string; text: string;
buttonType: 'accept' | 'reject'; buttonType: 'accept' | 'reject';

View File

@ -81,7 +81,7 @@
height: var(--base-height); height: var(--base-height);
margin-left: 0.5rem; margin-left: 0.5rem;
&:not(.danger) { &:not(.danger):not(:hover) {
color: var(--color-composer-button); color: var(--color-composer-button);
} }

View File

@ -13,8 +13,6 @@
color: white; color: white;
text-align: center; text-align: center;
background: var(--color-gray);
:global(body.is-ios) &, :global(body.is-ios) &,
:global(body.is-macos) & { :global(body.is-macos) & {
line-height: 1.375rem; line-height: 1.375rem;
@ -53,8 +51,8 @@
} }
.mention, .mention,
.unread:not(.muted), .unread,
.unopened:not(.muted) { .unopened {
color: var(--color-white); color: var(--color-white);
background: var(--color-green); background: var(--color-green);
} }
@ -78,11 +76,11 @@
font-size: 1rem; font-size: 1rem;
color: var(--color-list-icon); color: var(--color-list-icon);
background: transparent; background-color: transparent;
} }
.reaction:not(.muted) { .reaction {
background: #ed504f; background-color: #ed504f;
} }
.round { .round {
@ -103,14 +101,18 @@
font-size: 0.875rem !important; font-size: 0.875rem !important;
} }
.muted {
background-color: var(--color-gray);
}
.selected:not(.onAvatar) { .selected:not(.onAvatar) {
.badge:not(.pinned) { .badge:not(.pinned) {
color: var(--color-chat-active); color: var(--color-chat-active);
background: var(--color-white); background-color: var(--color-white);
&.muted { &.muted {
color: var(--color-white); color: var(--color-white);
background: #ffffff33; background-color: #ffffff33;
} }
} }
} }

View File

@ -143,26 +143,27 @@ const ChatBadge = ({
}); });
function renderContent() { function renderContent() {
const baseClassName = buildClassName(styles.badge, !shouldBeUnMuted && styles.muted, badgeClassName); const baseClassName = buildClassName(styles.badge, badgeClassName);
const statefulClassName = buildClassName(baseClassName, !shouldBeUnMuted && styles.muted);
const unreadReactionsElement = unreadReactionsCount && ( const unreadReactionsElement = unreadReactionsCount && (
<div className={buildClassName(baseClassName, styles.reaction, styles.round)}> <div className={buildClassName(statefulClassName, styles.reaction, styles.round)}>
<Icon name="heart" /> <Icon name="heart" />
</div> </div>
); );
const unreadMentionsElement = unreadMentionsCount && ( const unreadMentionsElement = unreadMentionsCount && (
<div className={buildClassName(baseClassName, styles.mention, styles.round)}> <div className={buildClassName(statefulClassName, styles.mention, styles.round)}>
<Icon name="mention" /> <Icon name="mention" />
</div> </div>
); );
const unopenedTopicElement = isTopicUnopened && ( const unopenedTopicElement = isTopicUnopened && (
<div className={buildClassName(baseClassName, styles.unopened)} /> <div className={buildClassName(statefulClassName, styles.unopened)} />
); );
const unreadCountElement = isUnread ? ( const unreadCountElement = isUnread ? (
<div className={buildClassName(baseClassName, styles.unread)}> <div className={buildClassName(statefulClassName, styles.unread)}>
{!hasUnreadMark && <AnimatedCounter text={formatIntegerCompact(lang, unreadCount!)} />} {!hasUnreadMark && <AnimatedCounter text={formatIntegerCompact(lang, unreadCount!)} />}
</div> </div>
) : undefined; ) : undefined;

View File

@ -0,0 +1,109 @@
@use "../../../styles/mixins";
.root {
:global(.bubble) {
width: 100% !important;
max-width: 27rem;
border-radius: var(--border-radius-default-small);
}
}
.content {
overflow-y: scroll;
display: flex;
flex-direction: column;
max-height: 75vh;
padding: 0.1875rem 0.625rem;
@include mixins.adapt-padding-to-scrollbar(0.625rem);
}
.row {
display: flex;
flex-direction: row;
& + & {
margin-top: 0.375rem;
}
}
.button {
--secondary-bg: transparent;
flex: 1;
width: auto;
height: auto;
min-height: 3.0625rem;
border: 2px solid var(--color-primary);
border-radius: var(--border-radius-messages-small);
font-weight: var(--font-weight-medium);
color: var(--color-primary);
background: var(--color-background);
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: inherit;
opacity: 80%;
background-color: var(--secondary-bg);
}
& + & {
margin-left: 0.375rem;
}
&:hover {
border-color: var(--color-primary-shade);
color: #fff;
background: var(--color-primary-shade);
}
}
.inlineButtonText {
z-index: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.customEmojiIcon {
margin-inline-end: 0.125rem;
vertical-align: text-top;
}
.primaryTint,
.successTint,
.destructiveTint {
border-width: 0;
color: #fff;
background-color: transparent;
&:hover {
border-color: transparent;
opacity: 75%;
background-color: transparent;
}
}
.primaryTint {
--secondary-bg: var(--color-primary);
}
.successTint {
--secondary-bg: var(--color-success);
}
.destructiveTint {
--secondary-bg: var(--color-error);
}

View File

@ -1,55 +0,0 @@
@use "../../../styles/mixins";
.BotKeyboardMenu {
.bubble {
width: 100% !important;
max-width: 27rem;
border-radius: var(--border-radius-default-small);
}
.content {
overflow-y: scroll;
display: flex;
flex-direction: column;
max-height: 75vh;
padding: 0.1875rem 0.625rem;
@include mixins.adapt-padding-to-scrollbar(0.625rem);
.row {
display: flex;
flex-direction: row;
}
.row + .row {
margin-top: 0.375rem;
}
.Button {
flex: 1;
width: auto;
height: auto;
min-height: 3.0625rem;
border: 2px solid var(--color-primary);
border-radius: var(--border-radius-messages-small);
font-weight: var(--font-weight-medium);
color: var(--color-primary);
text-transform: none;
background: var(--color-background);
&:hover {
border-color: var(--color-primary-shade);
color: #fff;
background: var(--color-primary-shade);
}
}
.Button + .Button {
margin-left: 0.375rem;
}
}
}

View File

@ -1,4 +1,4 @@
import type { FC, TeactNode } from '../../../lib/teact/teact'; import type { TeactNode } from '../../../lib/teact/teact';
import { memo, useMemo } from '../../../lib/teact/teact'; import { memo, useMemo } from '../../../lib/teact/teact';
import { getActions, withGlobal } from '../../../global'; import { getActions, withGlobal } from '../../../global';
@ -7,15 +7,17 @@ import type { ThreadId } from '../../../types';
import { selectChatMessage, selectCurrentMessageList } from '../../../global/selectors'; import { selectChatMessage, selectCurrentMessageList } from '../../../global/selectors';
import { IS_TOUCH_ENV } from '../../../util/browser/windowEnvironment'; import { IS_TOUCH_ENV } from '../../../util/browser/windowEnvironment';
import buildClassName from '../../../util/buildClassName';
import renderKeyboardButtonText from './helpers/renderKeyboardButtonText'; import renderKeyboardButtonText from './helpers/renderKeyboardButtonText';
import useLang from '../../../hooks/useLang'; import useLang from '../../../hooks/useLang';
import useMouseInside from '../../../hooks/useMouseInside'; import useMouseInside from '../../../hooks/useMouseInside';
import CustomEmoji from '../../common/CustomEmoji';
import Button from '../../ui/Button'; import Button from '../../ui/Button';
import Menu from '../../ui/Menu'; import Menu from '../../ui/Menu';
import './BotKeyboardMenu.scss'; import styles from './BotKeyboardMenu.module.scss';
export type OwnProps = { export type OwnProps = {
isOpen: boolean; isOpen: boolean;
@ -28,9 +30,11 @@ type StateProps = {
message?: ApiMessage; message?: ApiMessage;
}; };
const BotKeyboardMenu: FC<OwnProps & StateProps> = ({ const ICON_SIZE = 16;
const BotKeyboardMenu = ({
isOpen, threadId, message, onClose, isOpen, threadId, message, onClose,
}) => { }: OwnProps & StateProps) => {
const { clickBotInlineButton } = getActions(); const { clickBotInlineButton } = getActions();
const lang = useLang(); const lang = useLang();
@ -58,25 +62,38 @@ const BotKeyboardMenu: FC<OwnProps & StateProps> = ({
positionX="right" positionX="right"
positionY="bottom" positionY="bottom"
onClose={onClose} onClose={onClose}
className="BotKeyboardMenu" className={styles.root}
onCloseAnimationEnd={onClose} onCloseAnimationEnd={onClose}
onMouseEnter={!IS_TOUCH_ENV ? handleMouseEnter : undefined} onMouseEnter={!IS_TOUCH_ENV ? handleMouseEnter : undefined}
onMouseLeave={!IS_TOUCH_ENV ? handleMouseLeave : undefined} onMouseLeave={!IS_TOUCH_ENV ? handleMouseLeave : undefined}
noCompact noCompact
> >
<div className="content custom-scroll"> <div className={buildClassName(styles.content, 'custom-scroll')}>
{message.keyboardButtons.map((row, i) => ( {message.keyboardButtons.map((row, i) => (
<div className="row"> <div className={styles.row}>
{row.map((button, j) => ( {row.map((button, j) => (
<Button <Button
className={buildClassName(
styles.button,
button.style?.type && styles[`${button.style.type}Tint`],
)}
ripple ripple
noForcedUpperCase
disabled={button.type === 'unsupported'} disabled={button.type === 'unsupported'}
onClick={() => clickBotInlineButton({ onClick={() => clickBotInlineButton({
chatId: message.chatId, messageId: message.id, threadId, button, chatId: message.chatId, messageId: message.id, threadId, button,
})} })}
> >
<span className={styles.inlineButtonText}>
{button.style?.iconId && (
<CustomEmoji
className={styles.customEmojiIcon}
documentId={button.style.iconId}
size={ICON_SIZE}
/>
)}
{buttonTexts?.[i][j]} {buttonTexts?.[i][j]}
</span>
</Button> </Button>
))} ))}
</div> </div>

View File

@ -86,10 +86,10 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
:global(.InlineButtons) {
width: 100%;
} }
.inlineButtons {
width: 100%;
} }
.contextContainer { .contextContainer {

View File

@ -616,6 +616,7 @@ const ActionMessage = ({
{fullContent} {fullContent}
{shouldRenderInlineButtons && ( {shouldRenderInlineButtons && (
<InlineButtons <InlineButtons
className={styles.inlineButtons}
inlineButtons={giftOfferInlineButtons} inlineButtons={giftOfferInlineButtons}
onClick={handleInlineButtonClick} onClick={handleInlineButtonClick}
/> />

View File

@ -0,0 +1,124 @@
.root {
display: flex;
flex-direction: column;
max-width: var(--max-width);
}
.button {
--secondary-bg: transparent;
flex: 1;
width: auto;
margin: 0.125rem;
border-radius: var(--border-radius-messages-small);
font-weight: var(--font-weight-medium);
line-height: 1.25;
background-color: var(--action-message-bg);
transition: background-color 150ms, color 150ms, backdrop-filter 150ms, filter 150ms;
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: inherit;
opacity: 50%;
background-color: var(--secondary-bg);
}
&:active,
&:hover,
&:focus {
background-color: var(--action-message-bg) !important;
backdrop-filter: brightness(115%);
@supports not (backdrop-filter: brightness(115%)) {
filter: brightness(115%);
}
}
&:first-of-type {
margin-left: 0;
}
&:last-of-type {
margin-right: 0;
}
}
.cornerIcon {
position: absolute;
top: 0.1875rem;
right: 0.1875rem;
display: block;
font-size: 0.875rem;
&:global(.icon-arrow-right) {
top: 0.125rem;
right: 0.125rem;
transform: rotate(-45deg);
font-size: 0.75rem;
}
}
.leftIcon {
margin-right: 0.25rem;
font-size: 1rem !important;
}
.inlineButtonText {
z-index: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.row {
display: grid;
grid-auto-columns: minmax(0, 1fr);
grid-auto-flow: column;
&:first-of-type .button {
margin-top: 0.25rem !important;
}
&:last-of-type .button {
margin-bottom: 0;
&:first-of-type {
border-bottom-left-radius: var(--border-radius-messages);
}
&:last-of-type {
border-bottom-right-radius: var(--border-radius-messages);
}
}
}
.primaryTint {
--secondary-bg: var(--color-primary);
}
.successTint {
--secondary-bg: var(--color-success);
}
.destructiveTint {
--secondary-bg: var(--color-error);
}
.customEmojiIcon {
margin-inline-end: 0.125rem;
vertical-align: text-top;
}

View File

@ -1,89 +0,0 @@
.InlineButtons {
display: flex;
flex-direction: column;
max-width: var(--max-width);
.row {
display: grid;
grid-auto-columns: minmax(0, 1fr);
grid-auto-flow: column;
}
.Button {
flex: 1;
width: auto;
margin: 0.125rem;
border-radius: var(--border-radius-messages-small);
font-weight: var(--font-weight-medium);
text-transform: none;
background: var(--action-message-bg);
transition: background-color 150ms, color 150ms, backdrop-filter 150ms, filter 150ms;
&:active,
&:hover,
&:focus {
background: var(--action-message-bg) !important;
backdrop-filter: brightness(115%);
@supports not (backdrop-filter: brightness(115%)) {
filter: brightness(115%);
}
}
&:first-of-type {
margin-left: 0;
}
&:last-of-type {
margin-right: 0;
}
.corner-icon {
position: absolute;
top: 0.1875rem;
right: 0.1875rem;
display: block;
font-size: 0.875rem;
&.icon-arrow-right {
top: 0.125rem;
right: 0.125rem;
transform: rotate(-45deg);
font-size: 0.75rem;
}
}
}
.left-icon {
margin-right: 0.25rem;
font-size: 1rem !important;
}
.inline-button-text {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.row:first-of-type .Button {
margin-top: 0.25rem !important;
}
.row:last-of-type .Button {
margin-bottom: 0;
&:first-of-type {
border-bottom-left-radius: var(--border-radius-messages);
}
&:last-of-type {
border-bottom-right-radius: var(--border-radius-messages);
}
}
}

View File

@ -4,21 +4,26 @@ import { memo, useMemo } from '../../../lib/teact/teact';
import type { ApiKeyboardButton } from '../../../api/types'; import type { ApiKeyboardButton } from '../../../api/types';
import { RE_TME_LINK, TME_LINK_PREFIX } from '../../../config'; import { RE_TME_LINK, TME_LINK_PREFIX } from '../../../config';
import buildClassName from '../../../util/buildClassName';
import renderKeyboardButtonText from '../composer/helpers/renderKeyboardButtonText'; import renderKeyboardButtonText from '../composer/helpers/renderKeyboardButtonText';
import useLang from '../../../hooks/useLang'; import useLang from '../../../hooks/useLang';
import CustomEmoji from '../../common/CustomEmoji';
import Icon from '../../common/icons/Icon'; import Icon from '../../common/icons/Icon';
import Button from '../../ui/Button'; import Button from '../../ui/Button';
import './InlineButtons.scss'; import styles from './InlineButtons.module.scss';
type OwnProps = { type OwnProps = {
className?: string;
inlineButtons: ApiKeyboardButton[][]; inlineButtons: ApiKeyboardButton[][];
onClick: (payload: ApiKeyboardButton) => void; onClick: (payload: ApiKeyboardButton) => void;
}; };
const InlineButtons = ({ inlineButtons, onClick }: OwnProps) => { const ICON_SIZE = 16;
const InlineButtons = ({ className, inlineButtons, onClick }: OwnProps) => {
const lang = useLang(); const lang = useLang();
const renderIcon = (button: ApiKeyboardButton) => { const renderIcon = (button: ApiKeyboardButton) => {
@ -28,42 +33,42 @@ const InlineButtons = ({ inlineButtons, onClick }: OwnProps) => {
const { url } = button; const { url } = button;
if (url.startsWith(TME_LINK_PREFIX) && url.includes('?startapp')) { if (url.startsWith(TME_LINK_PREFIX) && url.includes('?startapp')) {
return <Icon className="corner-icon" name="webapp" />; return <Icon className={styles.cornerIcon} name="webapp" />;
} else if (!RE_TME_LINK.test(url)) { } else if (!RE_TME_LINK.test(url)) {
return <Icon className="corner-icon" name="arrow-right" />; return <Icon className={styles.cornerIcon} name="arrow-right" />;
} }
return; return;
} }
case 'urlAuth': case 'urlAuth':
return <Icon className="corner-icon" name="arrow-right" />; return <Icon className={styles.cornerIcon} name="arrow-right" />;
case 'buy': case 'buy':
case 'receipt': case 'receipt':
return <Icon className="corner-icon" name="card" />; return <Icon className={styles.cornerIcon} name="card" />;
case 'switchBotInline': case 'switchBotInline':
return <Icon className="corner-icon" name="share-filled" />; return <Icon className={styles.cornerIcon} name="share-filled" />;
case 'webView': case 'webView':
case 'simpleWebView': case 'simpleWebView':
return <Icon className="corner-icon" name="webapp" />; return <Icon className={styles.cornerIcon} name="webapp" />;
case 'copy': case 'copy':
return <Icon className="corner-icon" name="copy" />; return <Icon className={styles.cornerIcon} name="copy" />;
case 'suggestedMessage': case 'suggestedMessage':
if (button.buttonType === 'suggestChanges') { if (button.buttonType === 'suggestChanges') {
return <Icon className="left-icon" name="edit" />; return <Icon className={styles.leftIcon} name="edit" />;
} }
if (button.buttonType === 'approve') { if (button.buttonType === 'approve') {
return <Icon className="left-icon" name="check" />; return <Icon className={styles.leftIcon} name="check" />;
} }
if (button.buttonType === 'decline') { if (button.buttonType === 'decline') {
return <Icon className="left-icon" name="close" />; return <Icon className={styles.leftIcon} name="close" />;
} }
break; break;
case 'giftOffer': case 'giftOffer':
if (button.buttonType === 'accept') { if (button.buttonType === 'accept') {
return <Icon className="left-icon" name="check" />; return <Icon className={styles.leftIcon} name="check" />;
} }
if (button.buttonType === 'reject') { if (button.buttonType === 'reject') {
return <Icon className="left-icon" name="close" />; return <Icon className={styles.leftIcon} name="close" />;
} }
break; break;
} }
@ -80,19 +85,29 @@ const InlineButtons = ({ inlineButtons, onClick }: OwnProps) => {
}, [lang, inlineButtons]); }, [lang, inlineButtons]);
return ( return (
<div className="InlineButtons"> <div className={buildClassName(styles.root, className)}>
{inlineButtons.map((row, i) => ( {inlineButtons.map((row, i) => (
<div className="row"> <div className={styles.row}>
{row.map((button, j) => ( {row.map((button, j) => (
<Button <Button
className={buildClassName(
styles.button, button.style?.type && styles[`${button.style.type}Tint`],
)}
size="tiny" size="tiny"
ripple ripple
noForcedUpperCase
disabled={button.type === 'unsupported' || (button.type === 'suggestedMessage' && button.disabled)} disabled={button.type === 'unsupported' || (button.type === 'suggestedMessage' && button.disabled)}
onClick={() => onClick(button)} onClick={() => onClick(button)}
> >
{renderIcon(button)} {renderIcon(button)}
<span className="inline-button-text"> <span className={styles.inlineButtonText}>
{button.style?.iconId && (
<CustomEmoji
className={styles.customEmojiIcon}
documentId={button.style.iconId}
size={ICON_SIZE}
/>
)}
{buttonTexts[i][j]} {buttonTexts[i][j]}
</span> </span>
</Button> </Button>

View File

@ -24,8 +24,9 @@
} }
} }
@layer ui.button {
.Button { .Button {
--premium-gradient: linear-gradient(88.39deg, #6C93FF -2.56%, #976FFF 51.27%, #DF69D1 107.39%); --premium-gradient: linear-gradient(88.39deg, #6c93ff -2.56%, #976fff 51.27%, #df69d1 107.39%);
cursor: var(--custom-cursor, pointer); cursor: var(--custom-cursor, pointer);
@ -53,7 +54,10 @@
background-size: cover; background-size: cover;
outline: none !important; outline: none !important;
transition: background-color 0.2s, color 0.2s, opacity 0.2s; transition:
background-color 0.2s,
color 0.2s,
opacity 0.2s;
white-space-collapse: preserve; white-space-collapse: preserve;
@ -308,18 +312,18 @@
--ripple-color: rgba(0, 0, 0, 0.08); --ripple-color: rgba(0, 0, 0, 0.08);
color: var(--color-white); color: var(--color-white);
background-color: #FFB727; background-color: #ffb727;
.theme-dark & { .theme-dark & {
background-color: #CF8920; background-color: #cf8920;
} }
@include active-styles() { @include active-styles() {
background-color: #FFB727CC; background-color: #ffb727cc;
} }
@include no-ripple-styles() { @include no-ripple-styles() {
background-color: #FFB727; background-color: #ffb727;
} }
} }
@ -365,6 +369,7 @@
&.tiny { &.tiny {
--emoji-size: 1rem; --emoji-size: 1rem;
--custom-emoji-size: var(--emoji-size);
height: 2.25rem; height: 2.25rem;
padding: 0.4375rem; padding: 0.4375rem;
@ -383,6 +388,7 @@
&.pill { &.pill {
--emoji-size: 1.25rem; --emoji-size: 1.25rem;
--custom-emoji-size: var(--emoji-size);
height: 1.75rem; height: 1.75rem;
padding: 0.25rem 0.5rem; padding: 0.25rem 0.5rem;
@ -424,7 +430,8 @@
} }
} }
&.pill, &.badge { &.pill,
&.badge {
padding-right: 1.75rem; padding-right: 1.75rem;
padding-left: 1.75rem; padding-left: 1.75rem;
border-radius: 1.75rem; border-radius: 1.75rem;
@ -436,7 +443,6 @@
position: relative; position: relative;
.Spinner { .Spinner {
--spinner-size: 1.8125rem; --spinner-size: 1.8125rem;
position: absolute; position: absolute;
@ -522,3 +528,4 @@
} }
} }
} }
}

View File

@ -51,6 +51,9 @@
<link rel="manifest" id="the-manifest-placeholder" href="./<%= htmlWebpackPlugin.options.manifest %>"> <link rel="manifest" id="the-manifest-placeholder" href="./<%= htmlWebpackPlugin.options.manifest %>">
<script src="./redirect.js"></script> <script src="./redirect.js"></script>
<style>
@layer reset, variables, ui, components;
</style>
</head> </head>
<body id="root"> <body id="root">

View File

@ -18,6 +18,7 @@
@return rgb($bm-red, $bm-green, $bm-blue); @return rgb($bm-red, $bm-green, $bm-blue);
} }
@layer variables {
$color-primary: #3390ec; $color-primary: #3390ec;
$color-links: #3390ec; $color-links: #3390ec;
@ -237,8 +238,8 @@ $color-message-story-mention-to: #74bcff;
--folders-sidebar-width: 5rem; --folders-sidebar-width: 5rem;
--window-controls-width: 0rem; --window-controls-width: 0rem;
--header-height: 3.5rem; --header-height: 3.5rem;
--custom-emoji-size: 1.25rem; --emoji-size: 1.25em;
--emoji-size: 1.25rem; --custom-emoji-size: var(--emoji-size);
--custom-emoji-border-radius: 0; --custom-emoji-border-radius: 0;
--symbol-menu-width: 24rem; --symbol-menu-width: 24rem;
@ -350,3 +351,4 @@ $color-message-story-mention-to: #74bcff;
--symbol-menu-height: 17.6875rem; --symbol-menu-height: 17.6875rem;
} }
} }
}

View File

@ -1,4 +1,6 @@
/* stylelint-disable selector-max-type */
/* stylelint-disable plugin/selector-tag-no-without-class */ /* stylelint-disable plugin/selector-tag-no-without-class */
@layer reset {
*, *,
*::before, *::before,
*::after { *::after {
@ -9,16 +11,10 @@ html {
font-family: sans-serif; font-family: sans-serif;
line-height: 1.15; line-height: 1.15;
-webkit-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
-ms-overflow-style: scrollbar;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
} }
@-ms-viewport {
width: device-width;
}
article, article,
aside, aside,
dialog, dialog,
@ -163,8 +159,6 @@ pre {
overflow: auto; overflow: auto;
margin-top: 0; margin-top: 0;
margin-bottom: 1rem; margin-bottom: 1rem;
-ms-overflow-style: scrollbar;
} }
img { img {
@ -329,3 +323,4 @@ template {
[hidden] { [hidden] {
display: none !important; display: none !important;
} }
}