主题参数 💠组件 负责 Telegram Mini Apps 主题参数。 安装在使用该组件之前,必须对其进行安装,以确保属性配置正确。 ,使用 mount 方法更新 isMounted 信号属性。 Variable : - import { themeParams } from '@telegram-apps/sdk';
/ G7 P: |) v5 r2 W& e+ S - 7 e: M$ Y! d! U( Z' w% w
- themeParams.mount(); ( p' W. x& I# i) { |" z
- themeParams.isMounted(); // true
复制代码Function : - import {
! y6 d4 n$ h& n7 U# [. n - mountThemeParams,: ~! T- g) o+ s% F
- isThemeParamsMounted,3 L: O/ H3 M6 O- h. s+ o! @- P
- } from '@telegram-apps/sdk';
$ S; t" C$ z p# s - . v3 ]' a" u" H0 ~
- mountThemeParams(); . h f Q* g+ d
- isThemeParamsMounted(); // true
复制代码 " A4 p) r0 r8 M: W0 `
要卸载,请使用 unmount 方法: Variable : - themeParams.unmount();
, ^' d; C& G' i, E4 V - themeParams.isMounted(); // false
复制代码Functions : - import {
( a2 Q/ S5 Z& x% Q" o) o j5 Z - unmountThemeParams,
: R" H& H, G* R- a - isThemeParamsMounted,
0 }8 B( s- x8 |' v% Z3 w - } from '@telegram-apps/sdk';" u' y! \+ }5 [1 }+ C% ~8 N: X
4 d3 J4 Y& S( X7 x, t- unmountThemeParams();
* U+ b8 f) g+ z0 d+ W( G - isThemeParamsMounted(); // false
复制代码 绑定 CSS 变量该作用域允许通过 CSS 变量公开其属性。 要创建新的 CSS 变量,请使用 bindCssVars 方法。 调用时,它会更新 isCssVarsBound 信号属性。 该方法可选择接受一个函数,该函数接收驼峰格式的主题调色板键, 返回 CSS 变量名。 默认情况下,该方法使用这些规则转换调色板键: - 将数值转换为 kebab 大小写。
- 预置 --tg-theme- 前缀。
, a1 r; q0 i, D- G8 ^& C ( c$ E/ c! y( b% q+ t2 A6 @5 x
Variable :
8 p' s# _; S& I3 v; t n- themeParams.bindCssVars();* }0 h3 _4 G2 X# [9 e& H& @
- // Creates CSS variables like:
* [- D) n% b) C7 ]; C8 V - // --tg-theme-button-color: #aabbcc
- L! a" M" }7 ?' d- f - // --tg-theme-accent-text-color: #aabbcc
/ Q/ d0 h. i0 q - // --tg-theme-bg-color: #aabbcc
) N1 f) t; d/ q( Q - // ...( L" w& L& x3 _% z8 ?$ u
- : O: v* ^8 f9 l; k# g' ~1 |
- themeParams.bindCssVars(key => `--my-prefix-${key}`);
( o' ^! r( ^" r/ o - // Creates CSS variables like:% d) l* B2 g6 H, A7 X; P$ V" m' X
- // --my-prefix-buttonColor: #aabbcc
2 R( M% ^, t" p, \+ ]/ S - // --my-prefix-accentTextColor: #aabbcc
9 t3 [! |. j" @7 R, j" o; U, f, | - // --my-prefix-bgColor: #aabbcc0 n8 R) a4 U1 F0 r- s. J( K
- // ...
- Q6 ^7 O& z4 k$ \( A' W# L - 6 E* y# Z4 S' I7 ?& J
- // themeParams.isCssVarsBound() -> true
复制代码 Functions :
1 y9 d2 p& K0 H' h) J" P. U" T$ O7 C- import {
( u/ f, T. s2 | - bindThemeParamsCssVars,
2 z2 S" a9 W# A7 s) T0 q - isThemeParamsCssVarsBound,7 ]: m0 Z7 R6 Z9 j
- } from '@telegram-apps/sdk';
& n \ e: P" o4 D& V" j8 e; B" s - * m: ]4 G8 s0 n8 M
- bindThemeParamsCssVars();
. ?0 a: r; N. n; p( a - // Creates CSS variables like:5 h" j7 L4 H6 k1 B1 ~! ^
- // --tg-theme-button-color: #aabbcc
7 M& t1 ^$ ~( R4 k- K+ x4 k' M - // --tg-theme-accent-text-color: #aabbcc6 J/ i$ S, S- Z2 Q D- S- N! `: K# O
- // --tg-theme-bg-color: #aabbcc$ e- K2 p1 r- D8 H* I$ D
- // ...
' X& o: |, d0 ?
8 ^# h; \0 d5 c- bindThemeParamsCssVars(key => `--my-prefix-${key}`);; U9 o2 |: V- R/ i
- // Creates CSS variables like:3 }) C$ `& }/ j) D/ u) O
- // --my-prefix-buttonColor: #aabbcc) {/ }' Z7 B2 z$ p3 x$ N- J% W
- // --my-prefix-accentTextColor: #aabbcc$ T% N/ P. U; y
- // --my-prefix-bgColor: #aabbcc
/ m( m6 ]& R; B, a - // ...
) R% }+ y- }; j6 O2 B3 R; i - - {0 X. }2 C6 _$ v% q/ |0 j8 C& _) D
- // isThemeParamsCssVarsBound() -> true
复制代码 属性
& v: q6 q: L1 E8 w( hVariable :
: c0 f/ B' S7 E- W5 s- themeParams.accentTextColor(); // RGB | undefined
+ a8 G: Z, m1 `2 `) H& N, w% d - themeParams.backgroundColor(); // RGB | undefined }7 W |& `& o% l8 Y1 J
- themeParams.buttonTextColor(); // RGB | undefined- d, z0 T' I5 w
- themeParams.buttonColor(); // RGB | undefined
! I% w& X: R9 ~) A/ D1 v) |% i6 M - themeParams.destructiveTextColor(); // RGB | undefined
: t$ R) p4 I0 R6 I- H - themeParams.headerBackgroundColor(); // RGB | undefined
% z6 P; |3 H& j8 [# S4 y - themeParams.hintColor(); // RGB | undefined
2 {' \% S7 S" _0 t! i - themeParams.linkColor(); // RGB | undefined& ^, T+ `, d: h
- themeParams.subtitleTextColor(); // RGB | undefined2 h8 `) ^+ J- Z Y) s/ a' t: {3 s% b
- themeParams.sectionBackgroundColor(); // RGB | undefined( L- z2 M9 B0 B4 _
- themeParams.secondaryBackgroundColor(); // RGB | undefined
9 E# p9 B. ]! E' a- f- n# r - themeParams.sectionSeparatorColor(); // RGB | undefined
( ]( W% L3 J" _: v0 \7 h' J+ f, N - themeParams.sectionHeaderTextColor(); // RGB | undefined' |( R3 I5 a8 F- X1 C, J
- themeParams.textColor(); // RGB | undefined- D" S& [5 H8 L4 u
- 7 @% K- v" d2 S4 P5 e; F
- themeParams.state(); // Record<string, RGB>;
复制代码 Functions :6 _; I8 Q) `# m. [
- import {
8 {+ E% P( b; n' y - themeParamsAccentTextColor,1 x- \ g. Q1 y: Z7 x
- themeParamsBackgroundColor,
9 R# a' z4 v4 K% h1 \ - themeParamsButtonTextColor,7 W1 z0 W* G# K, p" v
- themeParamsButtonColor,6 M2 ~. p; ~/ d: c; O* L
- themeParamsDestructiveTextColor,
9 f* k0 ]1 W/ z; k - themeParamsHeaderBackgroundColor,
- E& X% [" x" C, E - themeParamsHintColor,
0 l6 {3 L$ r, I: s - themeParamsLinkColor,
5 Y, y; D& _; Q, y+ Z/ _* T6 v - themeParamsSubtitleTextColor,
2 Z+ v0 P* f: q7 k+ T - themeParamsSectionBackgroundColor,! m0 N: C- H- H( d2 M8 x w- z
- themeParamsSecondaryBackgroundColor,
$ q' W" P; H% v - themeParamsSectionSeparatorColor,1 q5 _" a( b; d, h$ X9 _- `
- themeParamsSectionHeaderTextColor,
& v' M, \8 N" ?' `' g- ~ - themeParamsTextColor,' S) \ n, U* q$ d3 O! |. u( C- y
- themeParamsState,
1 j7 N% _6 k# E" R8 { s( H - } from '@telegram-apps/sdk';: m% z( j; a6 o; d' F
- U h- M8 s# g* m% H- themeParamsAccentTextColor(); // RGB | undefined
; D/ f2 S" A7 l+ @ - themeParamsBackgroundColor(); // RGB | undefined) l$ S9 O7 {* X$ x
- themeParamsButtonTextColor(); // RGB | undefined3 t3 ^& h' o/ R8 t1 s. {
- themeParamsButtonColor(); // RGB | undefined+ i, }: X. q3 V( D
- themeParamsDestructiveTextColor(); // RGB | undefined) g# W# R; i N. E/ s& @
- themeParamsHeaderBackgroundColor(); // RGB | undefined F m( y. z: I- E0 R, {
- themeParamsHintColor(); // RGB | undefined
, y( D. c0 R! i/ y' g7 l+ N: X - themeParamsLinkColor(); // RGB | undefined, b3 l+ M$ Y: G4 }6 x& S v) m
- themeParamsSubtitleTextColor(); // RGB | undefined
2 C' r# }( F7 A' l% v - themeParamsSectionBackgroundColor(); // RGB | undefined! s4 j( e4 b) F3 `0 ~3 f" H
- themeParamsSecondaryBackgroundColor(); // RGB | undefined
/ j m' h4 Q% b' c. g3 M - themeParamsSectionSeparatorColor(); // RGB | undefined
3 ^6 v+ x$ h% _6 M1 I1 U! t - themeParamsSectionHeaderTextColor(); // RGB | undefined
$ k1 K3 P/ {* j - themeParamsTextColor(); // RGB | undefined
0 e4 c; Q. }* ~5 P. G4 @! Q/ o$ T
$ m9 k6 I5 a; W! o9 ^% g; |5 |) V9 Z$ z- themeParamsState(); // Record<string, RGB>;
复制代码 & Q& B( P0 a) e: V) u
8 {! Z$ D* N: N" c. i* a
2 D' f- h1 |$ Z* Y |