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

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

回答

收藏

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

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

主题参数

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

安装

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

Variable :

  1. import { themeParams } from '@telegram-apps/sdk';: b: b1 ^( G) _

  2. % x7 f7 |* U+ g& _  l) G: ]
  3. themeParams.mount(); ( c; i" [; d, @* x; [% K1 ^
  4. themeParams.isMounted(); // true
复制代码

Function :

  1. import {
    - E6 P* b- X: N/ r7 h% M. }4 }
  2.   mountThemeParams,
    * ^1 N, Z1 G. p
  3.   isThemeParamsMounted,
    % Q  [! W1 }1 [' V3 |( g2 ^
  4. } from '@telegram-apps/sdk';
    & Z1 O- C" A* F: }. k
  5. 9 j7 U( e5 t1 l- v1 u: i
  6. mountThemeParams(); 8 |5 W" Q7 V5 `
  7. isThemeParamsMounted(); // true
复制代码

/ z% t/ A2 Y. v8 z0 i1 h* n5 K

要卸载,请使用 unmount 方法:

Variable :

  1. themeParams.unmount(); . o3 U4 b& }$ Q0 R
  2. themeParams.isMounted(); // false
复制代码

Functions :

  1. import {
    ! Z" l( D5 V& @- o5 G# A
  2.   unmountThemeParams,( P5 G" w# K( [- K* T
  3.   isThemeParamsMounted,
    7 P( R4 K" V* Y4 _+ U
  4. } from '@telegram-apps/sdk';# O- u' l: d4 O
  5. 5 n& ]. j" E. s
  6. unmountThemeParams();" R: i( E6 g4 @) r6 }! ^: L7 |
  7. isThemeParamsMounted(); // false
复制代码
绑定 CSS 变量

该作用域允许通过 CSS 变量公开其属性。

要创建新的 CSS 变量,请使用 bindCssVars 方法。 调用时,它会更新 isCssVarsBound 信号属性。

该方法可选择接受一个函数,该函数接收驼峰格式的主题调色板键, 返回 CSS 变量名。 默认情况下,该方法使用这些规则转换调色板键:

  • 将数值转换为 kebab 大小写。
  • 预置 --tg-theme- 前缀。
    " F" l. N8 m, T/ L: a& Q

! y8 r; s! E+ N7 TVariable :& s! D0 d* r# S
  1. themeParams.bindCssVars();1 d" X+ C9 ?7 e
  2. // Creates CSS variables like:5 v7 \" o, e- _3 u4 G2 A( t
  3. // --tg-theme-button-color: #aabbcc
    + `1 F* u- G9 G
  4. // --tg-theme-accent-text-color: #aabbcc3 M! q8 N- D$ h6 j
  5. // --tg-theme-bg-color: #aabbcc: N9 c- `5 N6 k. D
  6. // ...
    $ q! ]1 F! Q# w2 b7 l

  7. 6 r/ x6 `' `1 {
  8. themeParams.bindCssVars(key => `--my-prefix-${key}`);& \/ K! i& u- x+ [4 O
  9. // Creates CSS variables like:
    $ B1 E* z/ p- v# U" f6 [# V
  10. // --my-prefix-buttonColor: #aabbcc" ]1 K- V# `5 F7 j3 y9 _
  11. // --my-prefix-accentTextColor: #aabbcc
    9 x: A+ R. k! x7 b$ |+ V
  12. // --my-prefix-bgColor: #aabbcc! x" \% s* C! D% _: |& c8 l) m5 |
  13. // ...# Q3 {. }5 I- A! U  Y+ S  W1 n
  14. 4 k7 H4 ^- u$ K/ r1 V- V4 R4 T9 @
  15. // themeParams.isCssVarsBound() -> true
复制代码
Functions :' c$ z8 a, L  A# ]; S
  1. import {
    ; I/ ^, B8 \& k- x
  2.   bindThemeParamsCssVars,
      u; x( y9 R8 S6 u1 W- d# h
  3.   isThemeParamsCssVarsBound,' l$ @7 H' |2 |( L7 a
  4. } from '@telegram-apps/sdk';
    " k" B1 x" _" u/ J) x5 t: G

  5. 6 A2 j' V  D$ t/ \6 k6 X
  6. bindThemeParamsCssVars();: m% `; \" t( ~, `( }
  7. // Creates CSS variables like:4 `: d* b; G8 B$ k5 i) B' X. Z
  8. // --tg-theme-button-color: #aabbcc, t  ~7 X: G6 i+ {3 M
  9. // --tg-theme-accent-text-color: #aabbcc
    8 K2 E; l. a  y5 t  J6 u; J
  10. // --tg-theme-bg-color: #aabbcc
    2 D0 v5 O# `0 O
  11. // ...( e- ~' F/ h& y5 v, Q+ }

  12. ' S0 @5 s2 d8 Y$ {/ U
  13. bindThemeParamsCssVars(key => `--my-prefix-${key}`);4 N; i" ^0 e# ^. H  x
  14. // Creates CSS variables like:
    - S" S! A2 G: V+ X; r
  15. // --my-prefix-buttonColor: #aabbcc- @4 |- A  ^* b1 F3 D- A3 t
  16. // --my-prefix-accentTextColor: #aabbcc$ H6 J' `7 u+ y& I) G9 ~8 H" M0 e+ L
  17. // --my-prefix-bgColor: #aabbcc
    - o9 c6 C. o3 x: K9 e. i1 C
  18. // ...6 I3 ]4 N! O2 U" v8 \* h, l  R. I8 S

  19. " Q5 j0 T( g( O
  20. // isThemeParamsCssVarsBound() -> true
复制代码
属性8 X0 n* f+ l% X# }* Q: d
Variable :* g7 m) F; y. _# B
  1. themeParams.accentTextColor(); // RGB | undefined
    , D$ ]' o$ n# {5 r& k1 l5 h4 L
  2. themeParams.backgroundColor(); // RGB | undefined5 y) U/ C. T' |5 N
  3. themeParams.buttonTextColor(); // RGB | undefined1 U! O+ H" K+ V# c4 r9 I
  4. themeParams.buttonColor(); // RGB | undefined
    ) c( u1 m. i- a  Z' Q
  5. themeParams.destructiveTextColor(); // RGB | undefined
    ) O% L4 z! e5 A
  6. themeParams.headerBackgroundColor(); // RGB | undefined/ i& _- C& i4 F! N. o2 P, E
  7. themeParams.hintColor(); // RGB | undefined  Z8 v& K. p9 I# j" n- h$ Q+ c
  8. themeParams.linkColor(); // RGB | undefined
    & Y# l6 [9 f/ s) t+ F( {* H
  9. themeParams.subtitleTextColor(); // RGB | undefined
    8 M6 L5 N; y# d6 l* R# I) i
  10. themeParams.sectionBackgroundColor(); // RGB | undefined
    4 [6 V9 z0 W5 J3 k# l0 O6 _
  11. themeParams.secondaryBackgroundColor(); // RGB | undefined7 f) T; G% F; Q% K- V, G
  12. themeParams.sectionSeparatorColor(); // RGB | undefined
    & G. Z4 T. ^. b$ V: l
  13. themeParams.sectionHeaderTextColor(); // RGB | undefined; z; |1 i: v* Q2 Y5 `
  14. themeParams.textColor(); // RGB | undefined
    # o$ q. B8 f0 `$ U% o
  15. 8 Q- [* c" ?' T3 z
  16. themeParams.state(); // Record<string, RGB>;
复制代码
Functions :1 b9 l! B. i+ @
  1. import {
    - \% j( |  D4 C6 @# X0 o0 w
  2.   themeParamsAccentTextColor,
    8 y0 D/ F. _6 _  y/ M6 v. C9 d
  3.   themeParamsBackgroundColor,
    1 b1 {2 l8 u+ \
  4.   themeParamsButtonTextColor,
    : ~$ w% m( u$ p/ Z8 T
  5.   themeParamsButtonColor,9 y. T5 o& H; j! z
  6.   themeParamsDestructiveTextColor,
    ( N" n+ g7 Z. l' N: w) N; ^% |
  7.   themeParamsHeaderBackgroundColor,
    2 W5 {  Q6 I3 n$ V
  8.   themeParamsHintColor,
    * m! `: |+ f; V# }/ r- {6 V
  9.   themeParamsLinkColor,8 ~! n; e% `& o8 u: Q
  10.   themeParamsSubtitleTextColor,2 G# v6 M$ T; W  i2 a$ L
  11.   themeParamsSectionBackgroundColor,
    , T# m( F) [& T4 h; h; P  t. D
  12.   themeParamsSecondaryBackgroundColor,/ G! V3 d8 M3 U
  13.   themeParamsSectionSeparatorColor,
    $ m. U, L& k6 _
  14.   themeParamsSectionHeaderTextColor,
    2 n) S& {0 q$ i: f
  15.   themeParamsTextColor,6 T* V; T" z% G) ]
  16.   themeParamsState,
    % _  }: d8 @) Z3 r2 u
  17. } from '@telegram-apps/sdk';2 @" J+ E: V" v  h

  18. ; l6 K4 P5 ]6 ~6 @
  19. themeParamsAccentTextColor(); // RGB | undefined+ [* `9 W; h! ~, @
  20. themeParamsBackgroundColor(); // RGB | undefined: p# w* {: B) c! `
  21. themeParamsButtonTextColor(); // RGB | undefined
    ( e0 I. c6 x+ |8 }: F4 v: _
  22. themeParamsButtonColor(); // RGB | undefined5 ~$ }2 q6 @3 I. R$ N  I- D
  23. themeParamsDestructiveTextColor(); // RGB | undefined1 A/ J7 e7 [8 m& `
  24. themeParamsHeaderBackgroundColor(); // RGB | undefined
    , h7 r! k2 N0 H0 j' ]$ k
  25. themeParamsHintColor(); // RGB | undefined% l0 s' q  B+ [% H$ W
  26. themeParamsLinkColor(); // RGB | undefined
    0 [' J8 r% b  V1 Q- o4 ^1 }
  27. themeParamsSubtitleTextColor(); // RGB | undefined
    4 }( H* D" x5 y" j
  28. themeParamsSectionBackgroundColor(); // RGB | undefined- H0 f+ X1 J& L
  29. themeParamsSecondaryBackgroundColor(); // RGB | undefined% t( G) Q+ p0 {6 y! I9 ^
  30. themeParamsSectionSeparatorColor(); // RGB | undefined2 B; G( Z  D( g; k
  31. themeParamsSectionHeaderTextColor(); // RGB | undefined
    & C! V6 i7 o+ t' x
  32. themeParamsTextColor(); // RGB | undefined  @! o' ^! S% i4 w

  33. 6 a6 S) d9 N2 K
  34. themeParamsState(); // Record<string, RGB>;
复制代码

& o6 R# _' I! ]2 O, d: n0 U/ Y8 c2 X) W, N; e) m* Z. N. y

7 ^  L% x2 I7 S) k6 _
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则