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

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

回答

收藏

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

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

主题参数

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

安装

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

Variable :

  1. import { themeParams } from '@telegram-apps/sdk';
    / G7 P: |) v5 r2 W& e+ S
  2. 7 e: M$ Y! d! U( Z' w% w
  3. themeParams.mount(); ( p' W. x& I# i) {  |" z
  4. themeParams.isMounted(); // true
复制代码

Function :

  1. import {
    ! y6 d4 n$ h& n7 U# [. n
  2.   mountThemeParams,: ~! T- g) o+ s% F
  3.   isThemeParamsMounted,3 L: O/ H3 M6 O- h. s+ o! @- P
  4. } from '@telegram-apps/sdk';
    $ S; t" C$ z  p# s
  5. . v3 ]' a" u" H0 ~
  6. mountThemeParams(); . h  f  Q* g+ d
  7. isThemeParamsMounted(); // true
复制代码
" A4 p) r0 r8 M: W0 `

要卸载,请使用 unmount 方法:

Variable :

  1. themeParams.unmount();
    , ^' d; C& G' i, E4 V
  2. themeParams.isMounted(); // false
复制代码

Functions :

  1. import {
    ( a2 Q/ S5 Z& x% Q" o) o  j5 Z
  2.   unmountThemeParams,
    : R" H& H, G* R- a
  3.   isThemeParamsMounted,
    0 }8 B( s- x8 |' v% Z3 w
  4. } from '@telegram-apps/sdk';" u' y! \+ }5 [1 }+ C% ~8 N: X

  5. 4 d3 J4 Y& S( X7 x, t
  6. unmountThemeParams();
    * U+ b8 f) g+ z0 d+ W( G
  7. 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
  1. themeParams.bindCssVars();* }0 h3 _4 G2 X# [9 e& H& @
  2. // Creates CSS variables like:
    * [- D) n% b) C7 ]; C8 V
  3. // --tg-theme-button-color: #aabbcc
    - L! a" M" }7 ?' d- f
  4. // --tg-theme-accent-text-color: #aabbcc
    / Q/ d0 h. i0 q
  5. // --tg-theme-bg-color: #aabbcc
    ) N1 f) t; d/ q( Q
  6. // ...( L" w& L& x3 _% z8 ?$ u
  7. : O: v* ^8 f9 l; k# g' ~1 |
  8. themeParams.bindCssVars(key => `--my-prefix-${key}`);
    ( o' ^! r( ^" r/ o
  9. // Creates CSS variables like:% d) l* B2 g6 H, A7 X; P$ V" m' X
  10. // --my-prefix-buttonColor: #aabbcc
    2 R( M% ^, t" p, \+ ]/ S
  11. // --my-prefix-accentTextColor: #aabbcc
    9 t3 [! |. j" @7 R, j" o; U, f, |
  12. // --my-prefix-bgColor: #aabbcc0 n8 R) a4 U1 F0 r- s. J( K
  13. // ...
    - Q6 ^7 O& z4 k$ \( A' W# L
  14. 6 E* y# Z4 S' I7 ?& J
  15. // themeParams.isCssVarsBound() -> true
复制代码
Functions :
1 y9 d2 p& K0 H' h) J" P. U" T$ O7 C
  1. import {
    ( u/ f, T. s2 |
  2.   bindThemeParamsCssVars,
    2 z2 S" a9 W# A7 s) T0 q
  3.   isThemeParamsCssVarsBound,7 ]: m0 Z7 R6 Z9 j
  4. } from '@telegram-apps/sdk';
    & n  \  e: P" o4 D& V" j8 e; B" s
  5. * m: ]4 G8 s0 n8 M
  6. bindThemeParamsCssVars();
    . ?0 a: r; N. n; p( a
  7. // Creates CSS variables like:5 h" j7 L4 H6 k1 B1 ~! ^
  8. // --tg-theme-button-color: #aabbcc
    7 M& t1 ^$ ~( R4 k- K+ x4 k' M
  9. // --tg-theme-accent-text-color: #aabbcc6 J/ i$ S, S- Z2 Q  D- S- N! `: K# O
  10. // --tg-theme-bg-color: #aabbcc$ e- K2 p1 r- D8 H* I$ D
  11. // ...
    ' X& o: |, d0 ?

  12. 8 ^# h; \0 d5 c
  13. bindThemeParamsCssVars(key => `--my-prefix-${key}`);; U9 o2 |: V- R/ i
  14. // Creates CSS variables like:3 }) C$ `& }/ j) D/ u) O
  15. // --my-prefix-buttonColor: #aabbcc) {/ }' Z7 B2 z$ p3 x$ N- J% W
  16. // --my-prefix-accentTextColor: #aabbcc$ T% N/ P. U; y
  17. // --my-prefix-bgColor: #aabbcc
    / m( m6 ]& R; B, a
  18. // ...
    ) R% }+ y- }; j6 O2 B3 R; i
  19. - {0 X. }2 C6 _$ v% q/ |0 j8 C& _) D
  20. // isThemeParamsCssVarsBound() -> true
复制代码
属性
& v: q6 q: L1 E8 w( hVariable :
: c0 f/ B' S7 E- W5 s
  1. themeParams.accentTextColor(); // RGB | undefined
    + a8 G: Z, m1 `2 `) H& N, w% d
  2. themeParams.backgroundColor(); // RGB | undefined  }7 W  |& `& o% l8 Y1 J
  3. themeParams.buttonTextColor(); // RGB | undefined- d, z0 T' I5 w
  4. themeParams.buttonColor(); // RGB | undefined
    ! I% w& X: R9 ~) A/ D1 v) |% i6 M
  5. themeParams.destructiveTextColor(); // RGB | undefined
    : t$ R) p4 I0 R6 I- H
  6. themeParams.headerBackgroundColor(); // RGB | undefined
    % z6 P; |3 H& j8 [# S4 y
  7. themeParams.hintColor(); // RGB | undefined
    2 {' \% S7 S" _0 t! i
  8. themeParams.linkColor(); // RGB | undefined& ^, T+ `, d: h
  9. themeParams.subtitleTextColor(); // RGB | undefined2 h8 `) ^+ J- Z  Y) s/ a' t: {3 s% b
  10. themeParams.sectionBackgroundColor(); // RGB | undefined( L- z2 M9 B0 B4 _
  11. themeParams.secondaryBackgroundColor(); // RGB | undefined
    9 E# p9 B. ]! E' a- f- n# r
  12. themeParams.sectionSeparatorColor(); // RGB | undefined
    ( ]( W% L3 J" _: v0 \7 h' J+ f, N
  13. themeParams.sectionHeaderTextColor(); // RGB | undefined' |( R3 I5 a8 F- X1 C, J
  14. themeParams.textColor(); // RGB | undefined- D" S& [5 H8 L4 u
  15. 7 @% K- v" d2 S4 P5 e; F
  16. themeParams.state(); // Record<string, RGB>;
复制代码
Functions :6 _; I8 Q) `# m. [
  1. import {
    8 {+ E% P( b; n' y
  2.   themeParamsAccentTextColor,1 x- \  g. Q1 y: Z7 x
  3.   themeParamsBackgroundColor,
    9 R# a' z4 v4 K% h1 \
  4.   themeParamsButtonTextColor,7 W1 z0 W* G# K, p" v
  5.   themeParamsButtonColor,6 M2 ~. p; ~/ d: c; O* L
  6.   themeParamsDestructiveTextColor,
    9 f* k0 ]1 W/ z; k
  7.   themeParamsHeaderBackgroundColor,
    - E& X% [" x" C, E
  8.   themeParamsHintColor,
    0 l6 {3 L$ r, I: s
  9.   themeParamsLinkColor,
    5 Y, y; D& _; Q, y+ Z/ _* T6 v
  10.   themeParamsSubtitleTextColor,
    2 Z+ v0 P* f: q7 k+ T
  11.   themeParamsSectionBackgroundColor,! m0 N: C- H- H( d2 M8 x  w- z
  12.   themeParamsSecondaryBackgroundColor,
    $ q' W" P; H% v
  13.   themeParamsSectionSeparatorColor,1 q5 _" a( b; d, h$ X9 _- `
  14.   themeParamsSectionHeaderTextColor,
    & v' M, \8 N" ?' `' g- ~
  15.   themeParamsTextColor,' S) \  n, U* q$ d3 O! |. u( C- y
  16.   themeParamsState,
    1 j7 N% _6 k# E" R8 {  s( H
  17. } from '@telegram-apps/sdk';: m% z( j; a6 o; d' F

  18. - U  h- M8 s# g* m% H
  19. themeParamsAccentTextColor(); // RGB | undefined
    ; D/ f2 S" A7 l+ @
  20. themeParamsBackgroundColor(); // RGB | undefined) l$ S9 O7 {* X$ x
  21. themeParamsButtonTextColor(); // RGB | undefined3 t3 ^& h' o/ R8 t1 s. {
  22. themeParamsButtonColor(); // RGB | undefined+ i, }: X. q3 V( D
  23. themeParamsDestructiveTextColor(); // RGB | undefined) g# W# R; i  N. E/ s& @
  24. themeParamsHeaderBackgroundColor(); // RGB | undefined  F  m( y. z: I- E0 R, {
  25. themeParamsHintColor(); // RGB | undefined
    , y( D. c0 R! i/ y' g7 l+ N: X
  26. themeParamsLinkColor(); // RGB | undefined, b3 l+ M$ Y: G4 }6 x& S  v) m
  27. themeParamsSubtitleTextColor(); // RGB | undefined
    2 C' r# }( F7 A' l% v
  28. themeParamsSectionBackgroundColor(); // RGB | undefined! s4 j( e4 b) F3 `0 ~3 f" H
  29. themeParamsSecondaryBackgroundColor(); // RGB | undefined
    / j  m' h4 Q% b' c. g3 M
  30. themeParamsSectionSeparatorColor(); // RGB | undefined
    3 ^6 v+ x$ h% _6 M1 I1 U! t
  31. themeParamsSectionHeaderTextColor(); // RGB | undefined
    $ k1 K3 P/ {* j
  32. themeParamsTextColor(); // RGB | undefined
    0 e4 c; Q. }* ~5 P. G4 @! Q/ o$ T

  33. $ m9 k6 I5 a; W! o9 ^% g; |5 |) V9 Z$ z
  34. 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
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则