English 简体中文 繁體中文 한국 사람 日本語 Deutsch русский بالعربية TÜRKÇE português คนไทย french

简体中文 繁體中文 English 日本語 Deutsch 한국 사람 بالعربية TÜRKÇE คนไทย Français русский

回答

收藏

Telegram 小程序 | TypeScript @telegram-apps/sdk @2.x | 组件 | 主题参数

开源社区 开源社区 7061 人阅读 | 0 人回复 | 2025-02-25

主题参数

💠组件 负责 Telegram Mini Apps 主题参数

安装

在使用该组件之前,必须对其进行安装,以确保属性配置正确。 ,使用 mount 方法更新 isMounted 信号属性。

Variable :

  1. import { themeParams } from '@telegram-apps/sdk';
    % x  G6 A* [' c3 |& V( \/ D4 M

  2. 1 ~* T0 {( R) V5 p+ X% `
  3. themeParams.mount(); 2 w& E. z. k" |( z: O8 U
  4. themeParams.isMounted(); // true
复制代码

Function :

  1. import {
    7 b- h" w: q2 F1 J* t9 ^$ j( S
  2.   mountThemeParams,& u$ v- r5 |% G7 E5 x
  3.   isThemeParamsMounted,. ~# z$ q* V$ ]! O) F9 w" K1 C5 a
  4. } from '@telegram-apps/sdk';
    9 M# |1 b& }/ ?( M! w! {1 G+ n
  5. 2 [) ~& Y7 O# \" I/ K( N
  6. mountThemeParams(); & P9 ~, Y. _1 j$ q& g- F9 F7 J
  7. isThemeParamsMounted(); // true
复制代码
8 q$ R! f" h0 `' ?& ?

要卸载,请使用 unmount 方法:

Variable :

  1. themeParams.unmount();
    ( v' [4 C! C1 d8 j) ^% t) k
  2. themeParams.isMounted(); // false
复制代码

Functions :

  1. import {
    7 n4 _2 J& ?' y- A3 A) j
  2.   unmountThemeParams,5 i! _+ i0 S. b
  3.   isThemeParamsMounted,
    ' ?4 x4 X$ P, d+ n/ o
  4. } from '@telegram-apps/sdk';! R: D9 w' h& o7 n3 x3 J

  5. 7 o' Z! O' M* k5 x2 h& p3 \) d
  6. unmountThemeParams();
    4 `# f& G0 G; W5 k* Y4 g4 \
  7. 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
  1. themeParams.bindCssVars();
    ( s% ]( q( c( w3 R: U% _! \1 ~
  2. // Creates CSS variables like:- c' ^$ T  O3 t# h
  3. // --tg-theme-button-color: #aabbcc0 H2 s6 ^3 ]7 Z) B
  4. // --tg-theme-accent-text-color: #aabbcc$ ~0 n8 y/ Y( _8 c) X$ l
  5. // --tg-theme-bg-color: #aabbcc
    9 q( a4 _+ g* v+ ^% }- p
  6. // ...3 p( a1 `" R. M* }9 a  U& u
  7. ; a' I; [9 |+ q0 o! @
  8. themeParams.bindCssVars(key => `--my-prefix-${key}`);
      Z! g) D! \; D1 j
  9. // Creates CSS variables like:
    2 y! a. c% }0 C+ D! r
  10. // --my-prefix-buttonColor: #aabbcc* |1 p1 Y1 F2 v
  11. // --my-prefix-accentTextColor: #aabbcc9 h6 w* S* u# p% Y8 r
  12. // --my-prefix-bgColor: #aabbcc3 ?2 d1 ]% [8 [
  13. // ...( e$ G* c# y  x2 G
  14. # z% Q/ x! P  m* d8 `3 y0 u+ h
  15. // themeParams.isCssVarsBound() -> true
复制代码
Functions :
$ S% F3 x4 X3 F) l# i! o
  1. import {% S- k6 e6 h1 U4 T4 M
  2.   bindThemeParamsCssVars,
    ( [5 a: R: ]  b/ ], j) {4 `
  3.   isThemeParamsCssVarsBound,
    % K: U4 [1 T3 e% N# M" ]) H
  4. } from '@telegram-apps/sdk';
    : n- g( `- r6 x- ?" ]4 s3 L! g

  5. $ i7 t' H  f( j5 a$ H
  6. bindThemeParamsCssVars();
    1 B4 ]5 I* `* ]! b
  7. // Creates CSS variables like:
    4 U) ~5 [; K, A+ ?1 [
  8. // --tg-theme-button-color: #aabbcc
      L! w/ k) ^  M' v7 E
  9. // --tg-theme-accent-text-color: #aabbcc
    " Q$ }: Z3 \1 B& j9 @
  10. // --tg-theme-bg-color: #aabbcc
    & l: W% v; ^# c2 c/ e8 `( b4 `+ i
  11. // ...  @; E: D5 b/ g0 i8 ~0 z& ^
  12. , t: u$ M. \# o0 u3 c
  13. bindThemeParamsCssVars(key => `--my-prefix-${key}`);
    5 E$ C7 {1 G9 ~2 D" V  [+ Y/ ?% k
  14. // Creates CSS variables like:
    ' n- D! L! X' S% W! r  {& S
  15. // --my-prefix-buttonColor: #aabbcc& w% n9 l7 K9 F4 m/ |
  16. // --my-prefix-accentTextColor: #aabbcc- i; @7 X0 C0 d0 F2 t
  17. // --my-prefix-bgColor: #aabbcc
    ) y$ Q: `! D* _
  18. // ...7 p/ m4 t: h/ \
  19. , g$ I. g; _; }8 C
  20. // isThemeParamsCssVarsBound() -> true
复制代码
属性
: E/ q* j' H1 @  a0 @: @Variable :4 c, W  g; _" t: M$ S$ U
  1. themeParams.accentTextColor(); // RGB | undefined9 W9 u5 g# o; p
  2. themeParams.backgroundColor(); // RGB | undefined) f, ?6 t4 S5 _- {/ @( D+ l
  3. themeParams.buttonTextColor(); // RGB | undefined% \3 s4 `' |) C  T( T$ X, L
  4. themeParams.buttonColor(); // RGB | undefined
    3 B+ L8 M6 V5 Q0 V- y$ v- W3 A
  5. themeParams.destructiveTextColor(); // RGB | undefined
    1 U3 ^  T/ P0 y+ u/ k& J( p! y
  6. themeParams.headerBackgroundColor(); // RGB | undefined, L) K5 ^) {7 Z9 v- @, H  o8 T
  7. themeParams.hintColor(); // RGB | undefined
    ' J# L& K6 g& f" q+ p4 d0 f  A: T
  8. themeParams.linkColor(); // RGB | undefined- i% G3 _$ W0 a8 G1 y. p0 U& {% Q
  9. themeParams.subtitleTextColor(); // RGB | undefined: \! b) k0 _& R8 h4 N( g/ |
  10. themeParams.sectionBackgroundColor(); // RGB | undefined: }( T' D, p# y: Q! V" k- P, E
  11. themeParams.secondaryBackgroundColor(); // RGB | undefined
    # Q% k% W7 `1 v7 O: o
  12. themeParams.sectionSeparatorColor(); // RGB | undefined4 r( o. b' m% t
  13. themeParams.sectionHeaderTextColor(); // RGB | undefined
    ) g3 Y% `8 G' L3 t. z$ S$ r$ F
  14. themeParams.textColor(); // RGB | undefined
    6 @! X! [. d4 F+ a: N) k" L
  15. 6 r) _0 N# e' n
  16. themeParams.state(); // Record<string, RGB>;
复制代码
Functions :
( M% x% U7 C$ V) u
  1. import {5 R. P) l! k) T  _
  2.   themeParamsAccentTextColor,3 d% Q6 X% a5 t; R/ ]1 b9 @7 `2 _
  3.   themeParamsBackgroundColor,  }9 g9 w" N) \0 o2 C. I8 z
  4.   themeParamsButtonTextColor,0 z. u+ ~2 d5 w, U
  5.   themeParamsButtonColor,
    $ A) Z7 [. X* h- T8 M
  6.   themeParamsDestructiveTextColor,& g: z" O) S$ \# d% \' G6 Q
  7.   themeParamsHeaderBackgroundColor,
    + h9 V+ U# r, o
  8.   themeParamsHintColor,
    ) a9 t: v7 X2 w! L) K4 J4 ^
  9.   themeParamsLinkColor,
    ; j* j: _: G  B- {
  10.   themeParamsSubtitleTextColor,
    + u. N; j7 F" ?- z/ Y
  11.   themeParamsSectionBackgroundColor,$ Y* P9 F$ Q( U. z$ G6 I
  12.   themeParamsSecondaryBackgroundColor,( R; c( `9 x7 X" b" L8 X# k
  13.   themeParamsSectionSeparatorColor,* u9 v8 J" ]0 ~3 K% n
  14.   themeParamsSectionHeaderTextColor,+ Q% M* C; P7 f/ c8 `% W! h
  15.   themeParamsTextColor,. U# ~+ |/ b4 \) u7 j& P: w
  16.   themeParamsState,1 W+ c4 X- g3 b4 P# j) {5 \
  17. } from '@telegram-apps/sdk';3 V; L3 r; V) {2 y2 j9 n  g
  18. " e& E0 u, P2 D
  19. themeParamsAccentTextColor(); // RGB | undefined- {0 `) V) i" D
  20. themeParamsBackgroundColor(); // RGB | undefined
    " n5 O. n; p+ A# ?, f  e; k
  21. themeParamsButtonTextColor(); // RGB | undefined
    " i. f: i2 s/ g( e& h
  22. themeParamsButtonColor(); // RGB | undefined: m; K+ ]2 h8 U0 d  \& a' F
  23. themeParamsDestructiveTextColor(); // RGB | undefined4 p; V& f, e) Y8 ^! D" A
  24. themeParamsHeaderBackgroundColor(); // RGB | undefined
    4 u/ B2 \' Y' ?# w2 c2 a# {
  25. themeParamsHintColor(); // RGB | undefined: H5 A8 E1 K, f- V
  26. themeParamsLinkColor(); // RGB | undefined8 c6 Z: g4 r6 u, S& D
  27. themeParamsSubtitleTextColor(); // RGB | undefined
    : y- f2 @1 B3 y; s1 E
  28. themeParamsSectionBackgroundColor(); // RGB | undefined
    ' e- H+ b( Z! H/ a' b# l' _' w$ e
  29. themeParamsSecondaryBackgroundColor(); // RGB | undefined
    . o0 b" r) M9 T9 ]) W
  30. themeParamsSectionSeparatorColor(); // RGB | undefined4 p: W' w+ r' j* L) y) F& G; B7 S7 ?
  31. themeParamsSectionHeaderTextColor(); // RGB | undefined! }+ ?. ~( R7 B9 b1 a
  32. themeParamsTextColor(); // RGB | undefined
    3 c5 p' F# h6 a9 n7 \
  33. 3 d$ Q! ^- v8 z* y  B2 b
  34. themeParamsState(); // Record<string, RGB>;
复制代码
* v$ _$ z7 u7 I. S; ~5 [: D6 k
; V( q1 z% x3 `

3 E: e8 S* P" Y- H+ z
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则