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

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

回答

收藏

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

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

主题参数

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

安装

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

Variable :

  1. import { themeParams } from '@telegram-apps/sdk';# @1 X% N3 ]  Y" v. `" q0 O' ^

  2. 2 w2 S1 v# ]9 C2 C, u
  3. themeParams.mount(); " Y3 X3 j8 p$ Z" B" V* ]
  4. themeParams.isMounted(); // true
复制代码

Function :

  1. import {
    3 a$ V1 y: [; R& l3 C% D' R
  2.   mountThemeParams,
    , t) c/ m+ O& K$ L  i7 x' R/ L' e
  3.   isThemeParamsMounted,2 n  V2 {) N# ?" t- W% z
  4. } from '@telegram-apps/sdk';1 l7 V9 q! D: S1 F1 V9 {

  5. 2 b5 T8 [& S  B/ D
  6. mountThemeParams();
    8 D& j7 m! P% S0 D
  7. isThemeParamsMounted(); // true
复制代码

, f  y4 h. R9 v/ n# r

要卸载,请使用 unmount 方法:

Variable :

  1. themeParams.unmount();
      [! w: ~9 q/ @" C  y4 d9 }
  2. themeParams.isMounted(); // false
复制代码

Functions :

  1. import {
    ) e9 ~1 d: d7 a. f' ]) u1 @" O
  2.   unmountThemeParams,
    ; K7 G1 r3 H( J- Z) L" r) M( b
  3.   isThemeParamsMounted,& r+ v4 u7 N$ @% i" ^* C) }$ y
  4. } from '@telegram-apps/sdk';1 S/ M# O- m0 M; [; x" i
  5. # E! p! D8 B- y$ J
  6. unmountThemeParams();
    , j, ~6 g8 s7 _) ^0 Z/ }
  7. 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
  1. themeParams.bindCssVars();; C  {  b8 N( P, @5 W$ d
  2. // Creates CSS variables like:  l* O9 ?! t" M8 e. c! J' B) R$ K
  3. // --tg-theme-button-color: #aabbcc; i% z1 n$ B7 C4 X* O. N
  4. // --tg-theme-accent-text-color: #aabbcc- r6 \5 \: W( S5 ?
  5. // --tg-theme-bg-color: #aabbcc
    % V  V1 G" f( f! x% c" C$ p. _
  6. // ...  k% ?9 E6 U8 I  F5 p( o
  7. ! b. G) |) t& X. d) z
  8. themeParams.bindCssVars(key => `--my-prefix-${key}`);( Q4 ?: q1 W$ U' T, T
  9. // Creates CSS variables like:- _- P* y0 C' X
  10. // --my-prefix-buttonColor: #aabbcc) Q  J! f0 B" s7 L
  11. // --my-prefix-accentTextColor: #aabbcc
    : m- t: n6 l2 X5 Q) T
  12. // --my-prefix-bgColor: #aabbcc8 |) b1 s. o) @1 \* J3 A4 G
  13. // ...
    : Z. s; U5 [% |) |
  14. 2 ~. R4 {$ i2 A+ T. v# x4 d
  15. // themeParams.isCssVarsBound() -> true
复制代码
Functions :
2 y7 V' F- f0 a/ |4 g# b
  1. import {) D  s: u: C$ D8 |
  2.   bindThemeParamsCssVars,% O5 _' ?& v( {+ T" n8 k
  3.   isThemeParamsCssVarsBound," b) p8 U& b# Y7 c) k# @
  4. } from '@telegram-apps/sdk';
    , u* {) I- q4 J, I/ w( n; j
  5. ) r, h! n) T. h/ ^, m  h/ i( m
  6. bindThemeParamsCssVars();6 U( I. q) R* w! H+ u
  7. // Creates CSS variables like:
    / x( i! u& r& f' W4 r: j& n
  8. // --tg-theme-button-color: #aabbcc
    , z& `* a3 v  v) Q+ w- o) f
  9. // --tg-theme-accent-text-color: #aabbcc% w5 f7 Z6 j" Y. E
  10. // --tg-theme-bg-color: #aabbcc
    + \, T6 O( w. X9 \$ T' K
  11. // ..." W3 g. Y5 d! X8 P% K; J  o0 }* r+ v

  12. 1 E& R8 c: u: c
  13. bindThemeParamsCssVars(key => `--my-prefix-${key}`);
    1 _5 ^: B3 \' S2 m" w
  14. // Creates CSS variables like:3 c4 X9 C1 _) ?
  15. // --my-prefix-buttonColor: #aabbcc9 w% f4 a# O$ y. p% O
  16. // --my-prefix-accentTextColor: #aabbcc
    * S- n' ^' K& D/ n
  17. // --my-prefix-bgColor: #aabbcc
    ' a0 V0 G& J/ k9 _1 y
  18. // ...
    6 L: J- n0 K* c: J* M9 i
  19. 0 w$ O& I* G) R
  20. // isThemeParamsCssVarsBound() -> true
复制代码
属性8 x- G# u  P4 m% n  d; c
Variable :
, h, j! Y! F. @4 _% Q1 c6 }2 Z
  1. themeParams.accentTextColor(); // RGB | undefined+ g2 b" a4 a! _# G  z" p- c
  2. themeParams.backgroundColor(); // RGB | undefined
    * t$ J3 r* }; K3 d8 j7 g* B- S4 O' D; \
  3. themeParams.buttonTextColor(); // RGB | undefined
    4 Q3 G) N- H. g- {" J2 j9 X1 `* l
  4. themeParams.buttonColor(); // RGB | undefined
    . p- d; ]1 Y' C/ e, m
  5. themeParams.destructiveTextColor(); // RGB | undefined
    7 Q6 [4 ?2 }' B: D0 T2 Q4 Q" g
  6. themeParams.headerBackgroundColor(); // RGB | undefined8 p" I( ^( a9 B" M; z- I+ h
  7. themeParams.hintColor(); // RGB | undefined
    + }8 p! S( K8 s
  8. themeParams.linkColor(); // RGB | undefined9 g/ |" l' S; h# \( b5 _7 _  n
  9. themeParams.subtitleTextColor(); // RGB | undefined" i! y' o: S7 [, W6 h1 J) x7 R
  10. themeParams.sectionBackgroundColor(); // RGB | undefined
    ; U: s8 u& J$ l" z* c
  11. themeParams.secondaryBackgroundColor(); // RGB | undefined
    / d) Y2 N' A8 }1 {! W6 \
  12. themeParams.sectionSeparatorColor(); // RGB | undefined
    7 l( y3 }6 X; u5 D. P
  13. themeParams.sectionHeaderTextColor(); // RGB | undefined: ]7 ?2 o+ _+ e7 R2 k7 X; d% Z
  14. themeParams.textColor(); // RGB | undefined$ A$ k. @' ^$ e8 ]2 U

  15. 7 |4 _# i4 [" _/ l* z, x2 t
  16. themeParams.state(); // Record<string, RGB>;
复制代码
Functions :
; B& H* ?7 H4 B) `& T1 x! |+ O
  1. import {! r) [  x' \! x1 k" O7 i; \. H  S
  2.   themeParamsAccentTextColor,
    ! k& d8 r1 M. a
  3.   themeParamsBackgroundColor,
    6 w6 ?# @7 f/ X, y& {2 t
  4.   themeParamsButtonTextColor,
    % X; t' G; {7 m( p, K) r: y
  5.   themeParamsButtonColor,
    5 r7 y( o% R1 e  d5 Y2 d* |  F
  6.   themeParamsDestructiveTextColor,; b+ D7 E: g0 U) q2 V5 p, [" l
  7.   themeParamsHeaderBackgroundColor,6 P: V% ?+ p9 [# ~
  8.   themeParamsHintColor,
    % U: Z. ?) @/ v# {" f
  9.   themeParamsLinkColor,
      h1 A7 P% L7 i6 C1 d+ }
  10.   themeParamsSubtitleTextColor,) y; G+ [! {( Q, u3 x+ V
  11.   themeParamsSectionBackgroundColor,
    ! f2 v5 }3 o4 E( s! b7 _  T
  12.   themeParamsSecondaryBackgroundColor,/ q5 L: i, @( ?- W1 X7 [( W4 W
  13.   themeParamsSectionSeparatorColor,
    / r* R* o, h# W0 y
  14.   themeParamsSectionHeaderTextColor,6 N1 O3 Z: g$ G& `; o1 M+ D
  15.   themeParamsTextColor,( Y( S7 Y& [& a
  16.   themeParamsState,1 @3 ?- ]+ b6 u" x; n
  17. } from '@telegram-apps/sdk';) Z& u1 A' H5 s. c+ {& V& O
  18. % }- h5 T( O$ x9 _
  19. themeParamsAccentTextColor(); // RGB | undefined7 M% K6 V: _: N  m. F: G; B
  20. themeParamsBackgroundColor(); // RGB | undefined
    1 }7 {$ [( v+ h, k. O! x
  21. themeParamsButtonTextColor(); // RGB | undefined
    - i% Z/ f# z! @' Y0 y, A" T
  22. themeParamsButtonColor(); // RGB | undefined5 E  ~8 S' |% y
  23. themeParamsDestructiveTextColor(); // RGB | undefined. B" w  h" L8 ]" W( [/ P2 s6 D- I
  24. themeParamsHeaderBackgroundColor(); // RGB | undefined" v4 y1 w+ F4 q$ J0 J. u, u3 a% u
  25. themeParamsHintColor(); // RGB | undefined
    , c9 L# S  Y* S, D/ N
  26. themeParamsLinkColor(); // RGB | undefined
    , t6 Z/ R+ o/ R9 r
  27. themeParamsSubtitleTextColor(); // RGB | undefined
    & h% v/ [6 z- c% i1 L# z4 F9 u
  28. themeParamsSectionBackgroundColor(); // RGB | undefined& f( R: ]7 H5 P0 i/ j" E/ V2 M
  29. themeParamsSecondaryBackgroundColor(); // RGB | undefined. X5 j4 O( Y1 R+ e* R
  30. themeParamsSectionSeparatorColor(); // RGB | undefined, }; J6 `/ Z/ x  ^+ u! N
  31. themeParamsSectionHeaderTextColor(); // RGB | undefined, t& |1 H/ m9 d( Z5 I
  32. themeParamsTextColor(); // RGB | undefined" F  Y. B: B: K1 `2 E

  33. ; a) ~- V) N2 v: ~' ~# A
  34. 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
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则