主题参数 💠组件 负责 Telegram Mini Apps 主题参数。 安装在使用该组件之前,必须对其进行安装,以确保属性配置正确。 ,使用 mount 方法更新 isMounted 信号属性。 Variable : - import { themeParams } from '@telegram-apps/sdk';# @1 X% N3 ] Y" v. `" q0 O' ^
2 w2 S1 v# ]9 C2 C, u- themeParams.mount(); " Y3 X3 j8 p$ Z" B" V* ]
- themeParams.isMounted(); // true
复制代码Function : - import {
3 a$ V1 y: [; R& l3 C% D' R - mountThemeParams,
, t) c/ m+ O& K$ L i7 x' R/ L' e - isThemeParamsMounted,2 n V2 {) N# ?" t- W% z
- } from '@telegram-apps/sdk';1 l7 V9 q! D: S1 F1 V9 {
2 b5 T8 [& S B/ D- mountThemeParams();
8 D& j7 m! P% S0 D - isThemeParamsMounted(); // true
复制代码
, f y4 h. R9 v/ n# r要卸载,请使用 unmount 方法: Variable : - themeParams.unmount();
[! w: ~9 q/ @" C y4 d9 } - themeParams.isMounted(); // false
复制代码Functions : - import {
) e9 ~1 d: d7 a. f' ]) u1 @" O - unmountThemeParams,
; K7 G1 r3 H( J- Z) L" r) M( b - isThemeParamsMounted,& r+ v4 u7 N$ @% i" ^* C) }$ y
- } from '@telegram-apps/sdk';1 S/ M# O- m0 M; [; x" i
- # E! p! D8 B- y$ J
- unmountThemeParams();
, j, ~6 g8 s7 _) ^0 Z/ } - isThemeParamsMounted(); // false
复制代码 绑定 CSS 变量该作用域允许通过 CSS 变量公开其属性。 要创建新的 CSS 变量,请使用 bindCssVars 方法。 调用时,它会更新 isCssVarsBound 信号属性。 该方法可选择接受一个函数,该函数接收驼峰格式的主题调色板键, 返回 CSS 变量名。 默认情况下,该方法使用这些规则转换调色板键: - 将数值转换为 kebab 大小写。
- 预置 --tg-theme- 前缀。0 N& W- ?) F6 u- | c& n
. ~8 Y! P/ k5 Z6 m5 c0 N6 \Variable : L$ }/ L" u& h7 W+ |" Z
- themeParams.bindCssVars();; C { b8 N( P, @5 W$ d
- // Creates CSS variables like: l* O9 ?! t" M8 e. c! J' B) R$ K
- // --tg-theme-button-color: #aabbcc; i% z1 n$ B7 C4 X* O. N
- // --tg-theme-accent-text-color: #aabbcc- r6 \5 \: W( S5 ?
- // --tg-theme-bg-color: #aabbcc
% V V1 G" f( f! x% c" C$ p. _ - // ... k% ?9 E6 U8 I F5 p( o
- ! b. G) |) t& X. d) z
- themeParams.bindCssVars(key => `--my-prefix-${key}`);( Q4 ?: q1 W$ U' T, T
- // Creates CSS variables like:- _- P* y0 C' X
- // --my-prefix-buttonColor: #aabbcc) Q J! f0 B" s7 L
- // --my-prefix-accentTextColor: #aabbcc
: m- t: n6 l2 X5 Q) T - // --my-prefix-bgColor: #aabbcc8 |) b1 s. o) @1 \* J3 A4 G
- // ...
: Z. s; U5 [% |) | - 2 ~. R4 {$ i2 A+ T. v# x4 d
- // themeParams.isCssVarsBound() -> true
复制代码 Functions :
2 y7 V' F- f0 a/ |4 g# b- import {) D s: u: C$ D8 |
- bindThemeParamsCssVars,% O5 _' ?& v( {+ T" n8 k
- isThemeParamsCssVarsBound," b) p8 U& b# Y7 c) k# @
- } from '@telegram-apps/sdk';
, u* {) I- q4 J, I/ w( n; j - ) r, h! n) T. h/ ^, m h/ i( m
- bindThemeParamsCssVars();6 U( I. q) R* w! H+ u
- // Creates CSS variables like:
/ x( i! u& r& f' W4 r: j& n - // --tg-theme-button-color: #aabbcc
, z& `* a3 v v) Q+ w- o) f - // --tg-theme-accent-text-color: #aabbcc% w5 f7 Z6 j" Y. E
- // --tg-theme-bg-color: #aabbcc
+ \, T6 O( w. X9 \$ T' K - // ..." W3 g. Y5 d! X8 P% K; J o0 }* r+ v
1 E& R8 c: u: c- bindThemeParamsCssVars(key => `--my-prefix-${key}`);
1 _5 ^: B3 \' S2 m" w - // Creates CSS variables like:3 c4 X9 C1 _) ?
- // --my-prefix-buttonColor: #aabbcc9 w% f4 a# O$ y. p% O
- // --my-prefix-accentTextColor: #aabbcc
* S- n' ^' K& D/ n - // --my-prefix-bgColor: #aabbcc
' a0 V0 G& J/ k9 _1 y - // ...
6 L: J- n0 K* c: J* M9 i - 0 w$ O& I* G) R
- // isThemeParamsCssVarsBound() -> true
复制代码 属性8 x- G# u P4 m% n d; c
Variable :
, h, j! Y! F. @4 _% Q1 c6 }2 Z- themeParams.accentTextColor(); // RGB | undefined+ g2 b" a4 a! _# G z" p- c
- themeParams.backgroundColor(); // RGB | undefined
* t$ J3 r* }; K3 d8 j7 g* B- S4 O' D; \ - themeParams.buttonTextColor(); // RGB | undefined
4 Q3 G) N- H. g- {" J2 j9 X1 `* l - themeParams.buttonColor(); // RGB | undefined
. p- d; ]1 Y' C/ e, m - themeParams.destructiveTextColor(); // RGB | undefined
7 Q6 [4 ?2 }' B: D0 T2 Q4 Q" g - themeParams.headerBackgroundColor(); // RGB | undefined8 p" I( ^( a9 B" M; z- I+ h
- themeParams.hintColor(); // RGB | undefined
+ }8 p! S( K8 s - themeParams.linkColor(); // RGB | undefined9 g/ |" l' S; h# \( b5 _7 _ n
- themeParams.subtitleTextColor(); // RGB | undefined" i! y' o: S7 [, W6 h1 J) x7 R
- themeParams.sectionBackgroundColor(); // RGB | undefined
; U: s8 u& J$ l" z* c - themeParams.secondaryBackgroundColor(); // RGB | undefined
/ d) Y2 N' A8 }1 {! W6 \ - themeParams.sectionSeparatorColor(); // RGB | undefined
7 l( y3 }6 X; u5 D. P - themeParams.sectionHeaderTextColor(); // RGB | undefined: ]7 ?2 o+ _+ e7 R2 k7 X; d% Z
- themeParams.textColor(); // RGB | undefined$ A$ k. @' ^$ e8 ]2 U
7 |4 _# i4 [" _/ l* z, x2 t- themeParams.state(); // Record<string, RGB>;
复制代码 Functions :
; B& H* ?7 H4 B) `& T1 x! |+ O- import {! r) [ x' \! x1 k" O7 i; \. H S
- themeParamsAccentTextColor,
! k& d8 r1 M. a - themeParamsBackgroundColor,
6 w6 ?# @7 f/ X, y& {2 t - themeParamsButtonTextColor,
% X; t' G; {7 m( p, K) r: y - themeParamsButtonColor,
5 r7 y( o% R1 e d5 Y2 d* | F - themeParamsDestructiveTextColor,; b+ D7 E: g0 U) q2 V5 p, [" l
- themeParamsHeaderBackgroundColor,6 P: V% ?+ p9 [# ~
- themeParamsHintColor,
% U: Z. ?) @/ v# {" f - themeParamsLinkColor,
h1 A7 P% L7 i6 C1 d+ } - themeParamsSubtitleTextColor,) y; G+ [! {( Q, u3 x+ V
- themeParamsSectionBackgroundColor,
! f2 v5 }3 o4 E( s! b7 _ T - themeParamsSecondaryBackgroundColor,/ q5 L: i, @( ?- W1 X7 [( W4 W
- themeParamsSectionSeparatorColor,
/ r* R* o, h# W0 y - themeParamsSectionHeaderTextColor,6 N1 O3 Z: g$ G& `; o1 M+ D
- themeParamsTextColor,( Y( S7 Y& [& a
- themeParamsState,1 @3 ?- ]+ b6 u" x; n
- } from '@telegram-apps/sdk';) Z& u1 A' H5 s. c+ {& V& O
- % }- h5 T( O$ x9 _
- themeParamsAccentTextColor(); // RGB | undefined7 M% K6 V: _: N m. F: G; B
- themeParamsBackgroundColor(); // RGB | undefined
1 }7 {$ [( v+ h, k. O! x - themeParamsButtonTextColor(); // RGB | undefined
- i% Z/ f# z! @' Y0 y, A" T - themeParamsButtonColor(); // RGB | undefined5 E ~8 S' |% y
- themeParamsDestructiveTextColor(); // RGB | undefined. B" w h" L8 ]" W( [/ P2 s6 D- I
- themeParamsHeaderBackgroundColor(); // RGB | undefined" v4 y1 w+ F4 q$ J0 J. u, u3 a% u
- themeParamsHintColor(); // RGB | undefined
, c9 L# S Y* S, D/ N - themeParamsLinkColor(); // RGB | undefined
, t6 Z/ R+ o/ R9 r - themeParamsSubtitleTextColor(); // RGB | undefined
& h% v/ [6 z- c% i1 L# z4 F9 u - themeParamsSectionBackgroundColor(); // RGB | undefined& f( R: ]7 H5 P0 i/ j" E/ V2 M
- themeParamsSecondaryBackgroundColor(); // RGB | undefined. X5 j4 O( Y1 R+ e* R
- themeParamsSectionSeparatorColor(); // RGB | undefined, }; J6 `/ Z/ x ^+ u! N
- themeParamsSectionHeaderTextColor(); // RGB | undefined, t& |1 H/ m9 d( Z5 I
- themeParamsTextColor(); // RGB | undefined" F Y. B: B: K1 `2 E
; a) ~- V) N2 v: ~' ~# A- themeParamsState(); // Record<string, RGB>;
复制代码 # h* y( f5 K! g. D, O; a9 j
- c* P- @4 j& X L- b( [" U3 ]) e! h6 f$ p& {! `0 h* Q
|