主题参数 💠组件 负责 Telegram Mini Apps 主题参数。 安装在使用该组件之前,必须对其进行安装,以确保属性配置正确。 ,使用 mount 方法更新 isMounted 信号属性。 Variable : - import { themeParams } from '@telegram-apps/sdk';
% x G6 A* [' c3 |& V( \/ D4 M
1 ~* T0 {( R) V5 p+ X% `- themeParams.mount(); 2 w& E. z. k" |( z: O8 U
- themeParams.isMounted(); // true
复制代码Function : - import {
7 b- h" w: q2 F1 J* t9 ^$ j( S - mountThemeParams,& u$ v- r5 |% G7 E5 x
- isThemeParamsMounted,. ~# z$ q* V$ ]! O) F9 w" K1 C5 a
- } from '@telegram-apps/sdk';
9 M# |1 b& }/ ?( M! w! {1 G+ n - 2 [) ~& Y7 O# \" I/ K( N
- mountThemeParams(); & P9 ~, Y. _1 j$ q& g- F9 F7 J
- isThemeParamsMounted(); // true
复制代码 8 q$ R! f" h0 `' ?& ?
要卸载,请使用 unmount 方法: Variable : - themeParams.unmount();
( v' [4 C! C1 d8 j) ^% t) k - themeParams.isMounted(); // false
复制代码Functions : - import {
7 n4 _2 J& ?' y- A3 A) j - unmountThemeParams,5 i! _+ i0 S. b
- isThemeParamsMounted,
' ?4 x4 X$ P, d+ n/ o - } from '@telegram-apps/sdk';! R: D9 w' h& o7 n3 x3 J
7 o' Z! O' M* k5 x2 h& p3 \) d- unmountThemeParams();
4 `# f& G0 G; W5 k* Y4 g4 \ - isThemeParamsMounted(); // false
复制代码 绑定 CSS 变量该作用域允许通过 CSS 变量公开其属性。 要创建新的 CSS 变量,请使用 bindCssVars 方法。 调用时,它会更新 isCssVarsBound 信号属性。 该方法可选择接受一个函数,该函数接收驼峰格式的主题调色板键, 返回 CSS 变量名。 默认情况下,该方法使用这些规则转换调色板键: - 将数值转换为 kebab 大小写。
- 预置 --tg-theme- 前缀。% R% I: Y) f# Z5 @9 g; C: P
! Q0 @ `7 K) I3 I2 i; s" R( `- U1 |Variable :! t% k# o- d7 x9 _4 v2 L7 n
- themeParams.bindCssVars();
( s% ]( q( c( w3 R: U% _! \1 ~ - // Creates CSS variables like:- c' ^$ T O3 t# h
- // --tg-theme-button-color: #aabbcc0 H2 s6 ^3 ]7 Z) B
- // --tg-theme-accent-text-color: #aabbcc$ ~0 n8 y/ Y( _8 c) X$ l
- // --tg-theme-bg-color: #aabbcc
9 q( a4 _+ g* v+ ^% }- p - // ...3 p( a1 `" R. M* }9 a U& u
- ; a' I; [9 |+ q0 o! @
- themeParams.bindCssVars(key => `--my-prefix-${key}`);
Z! g) D! \; D1 j - // Creates CSS variables like:
2 y! a. c% }0 C+ D! r - // --my-prefix-buttonColor: #aabbcc* |1 p1 Y1 F2 v
- // --my-prefix-accentTextColor: #aabbcc9 h6 w* S* u# p% Y8 r
- // --my-prefix-bgColor: #aabbcc3 ?2 d1 ]% [8 [
- // ...( e$ G* c# y x2 G
- # z% Q/ x! P m* d8 `3 y0 u+ h
- // themeParams.isCssVarsBound() -> true
复制代码 Functions :
$ S% F3 x4 X3 F) l# i! o- import {% S- k6 e6 h1 U4 T4 M
- bindThemeParamsCssVars,
( [5 a: R: ] b/ ], j) {4 ` - isThemeParamsCssVarsBound,
% K: U4 [1 T3 e% N# M" ]) H - } from '@telegram-apps/sdk';
: n- g( `- r6 x- ?" ]4 s3 L! g
$ i7 t' H f( j5 a$ H- bindThemeParamsCssVars();
1 B4 ]5 I* `* ]! b - // Creates CSS variables like:
4 U) ~5 [; K, A+ ?1 [ - // --tg-theme-button-color: #aabbcc
L! w/ k) ^ M' v7 E - // --tg-theme-accent-text-color: #aabbcc
" Q$ }: Z3 \1 B& j9 @ - // --tg-theme-bg-color: #aabbcc
& l: W% v; ^# c2 c/ e8 `( b4 `+ i - // ... @; E: D5 b/ g0 i8 ~0 z& ^
- , t: u$ M. \# o0 u3 c
- bindThemeParamsCssVars(key => `--my-prefix-${key}`);
5 E$ C7 {1 G9 ~2 D" V [+ Y/ ?% k - // Creates CSS variables like:
' n- D! L! X' S% W! r {& S - // --my-prefix-buttonColor: #aabbcc& w% n9 l7 K9 F4 m/ |
- // --my-prefix-accentTextColor: #aabbcc- i; @7 X0 C0 d0 F2 t
- // --my-prefix-bgColor: #aabbcc
) y$ Q: `! D* _ - // ...7 p/ m4 t: h/ \
- , g$ I. g; _; }8 C
- // isThemeParamsCssVarsBound() -> true
复制代码 属性
: E/ q* j' H1 @ a0 @: @Variable :4 c, W g; _" t: M$ S$ U
- themeParams.accentTextColor(); // RGB | undefined9 W9 u5 g# o; p
- themeParams.backgroundColor(); // RGB | undefined) f, ?6 t4 S5 _- {/ @( D+ l
- themeParams.buttonTextColor(); // RGB | undefined% \3 s4 `' |) C T( T$ X, L
- themeParams.buttonColor(); // RGB | undefined
3 B+ L8 M6 V5 Q0 V- y$ v- W3 A - themeParams.destructiveTextColor(); // RGB | undefined
1 U3 ^ T/ P0 y+ u/ k& J( p! y - themeParams.headerBackgroundColor(); // RGB | undefined, L) K5 ^) {7 Z9 v- @, H o8 T
- themeParams.hintColor(); // RGB | undefined
' J# L& K6 g& f" q+ p4 d0 f A: T - themeParams.linkColor(); // RGB | undefined- i% G3 _$ W0 a8 G1 y. p0 U& {% Q
- themeParams.subtitleTextColor(); // RGB | undefined: \! b) k0 _& R8 h4 N( g/ |
- themeParams.sectionBackgroundColor(); // RGB | undefined: }( T' D, p# y: Q! V" k- P, E
- themeParams.secondaryBackgroundColor(); // RGB | undefined
# Q% k% W7 `1 v7 O: o - themeParams.sectionSeparatorColor(); // RGB | undefined4 r( o. b' m% t
- themeParams.sectionHeaderTextColor(); // RGB | undefined
) g3 Y% `8 G' L3 t. z$ S$ r$ F - themeParams.textColor(); // RGB | undefined
6 @! X! [. d4 F+ a: N) k" L - 6 r) _0 N# e' n
- themeParams.state(); // Record<string, RGB>;
复制代码 Functions :
( M% x% U7 C$ V) u- import {5 R. P) l! k) T _
- themeParamsAccentTextColor,3 d% Q6 X% a5 t; R/ ]1 b9 @7 `2 _
- themeParamsBackgroundColor, }9 g9 w" N) \0 o2 C. I8 z
- themeParamsButtonTextColor,0 z. u+ ~2 d5 w, U
- themeParamsButtonColor,
$ A) Z7 [. X* h- T8 M - themeParamsDestructiveTextColor,& g: z" O) S$ \# d% \' G6 Q
- themeParamsHeaderBackgroundColor,
+ h9 V+ U# r, o - themeParamsHintColor,
) a9 t: v7 X2 w! L) K4 J4 ^ - themeParamsLinkColor,
; j* j: _: G B- { - themeParamsSubtitleTextColor,
+ u. N; j7 F" ?- z/ Y - themeParamsSectionBackgroundColor,$ Y* P9 F$ Q( U. z$ G6 I
- themeParamsSecondaryBackgroundColor,( R; c( `9 x7 X" b" L8 X# k
- themeParamsSectionSeparatorColor,* u9 v8 J" ]0 ~3 K% n
- themeParamsSectionHeaderTextColor,+ Q% M* C; P7 f/ c8 `% W! h
- themeParamsTextColor,. U# ~+ |/ b4 \) u7 j& P: w
- themeParamsState,1 W+ c4 X- g3 b4 P# j) {5 \
- } from '@telegram-apps/sdk';3 V; L3 r; V) {2 y2 j9 n g
- " e& E0 u, P2 D
- themeParamsAccentTextColor(); // RGB | undefined- {0 `) V) i" D
- themeParamsBackgroundColor(); // RGB | undefined
" n5 O. n; p+ A# ?, f e; k - themeParamsButtonTextColor(); // RGB | undefined
" i. f: i2 s/ g( e& h - themeParamsButtonColor(); // RGB | undefined: m; K+ ]2 h8 U0 d \& a' F
- themeParamsDestructiveTextColor(); // RGB | undefined4 p; V& f, e) Y8 ^! D" A
- themeParamsHeaderBackgroundColor(); // RGB | undefined
4 u/ B2 \' Y' ?# w2 c2 a# { - themeParamsHintColor(); // RGB | undefined: H5 A8 E1 K, f- V
- themeParamsLinkColor(); // RGB | undefined8 c6 Z: g4 r6 u, S& D
- themeParamsSubtitleTextColor(); // RGB | undefined
: y- f2 @1 B3 y; s1 E - themeParamsSectionBackgroundColor(); // RGB | undefined
' e- H+ b( Z! H/ a' b# l' _' w$ e - themeParamsSecondaryBackgroundColor(); // RGB | undefined
. o0 b" r) M9 T9 ]) W - themeParamsSectionSeparatorColor(); // RGB | undefined4 p: W' w+ r' j* L) y) F& G; B7 S7 ?
- themeParamsSectionHeaderTextColor(); // RGB | undefined! }+ ?. ~( R7 B9 b1 a
- themeParamsTextColor(); // RGB | undefined
3 c5 p' F# h6 a9 n7 \ - 3 d$ Q! ^- v8 z* y B2 b
- themeParamsState(); // Record<string, RGB>;
复制代码 * v$ _$ z7 u7 I. S; ~5 [: D6 k
; V( q1 z% x3 `
3 E: e8 S* P" Y- H+ z |