主题参数 💠组件 负责 Telegram Mini Apps 主题参数。 安装在使用该组件之前,必须对其进行安装,以确保属性配置正确。 ,使用 mount 方法更新 isMounted 信号属性。 Variable : - import { themeParams } from '@telegram-apps/sdk';: b: b1 ^( G) _
% x7 f7 |* U+ g& _ l) G: ]- themeParams.mount(); ( c; i" [; d, @* x; [% K1 ^
- themeParams.isMounted(); // true
复制代码Function : - import {
- E6 P* b- X: N/ r7 h% M. }4 } - mountThemeParams,
* ^1 N, Z1 G. p - isThemeParamsMounted,
% Q [! W1 }1 [' V3 |( g2 ^ - } from '@telegram-apps/sdk';
& Z1 O- C" A* F: }. k - 9 j7 U( e5 t1 l- v1 u: i
- mountThemeParams(); 8 |5 W" Q7 V5 `
- isThemeParamsMounted(); // true
复制代码
/ z% t/ A2 Y. v8 z0 i1 h* n5 K要卸载,请使用 unmount 方法: Variable : - themeParams.unmount(); . o3 U4 b& }$ Q0 R
- themeParams.isMounted(); // false
复制代码Functions : - import {
! Z" l( D5 V& @- o5 G# A - unmountThemeParams,( P5 G" w# K( [- K* T
- isThemeParamsMounted,
7 P( R4 K" V* Y4 _+ U - } from '@telegram-apps/sdk';# O- u' l: d4 O
- 5 n& ]. j" E. s
- unmountThemeParams();" R: i( E6 g4 @) r6 }! ^: L7 |
- 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
- themeParams.bindCssVars();1 d" X+ C9 ?7 e
- // Creates CSS variables like:5 v7 \" o, e- _3 u4 G2 A( t
- // --tg-theme-button-color: #aabbcc
+ `1 F* u- G9 G - // --tg-theme-accent-text-color: #aabbcc3 M! q8 N- D$ h6 j
- // --tg-theme-bg-color: #aabbcc: N9 c- `5 N6 k. D
- // ...
$ q! ]1 F! Q# w2 b7 l
6 r/ x6 `' `1 {- themeParams.bindCssVars(key => `--my-prefix-${key}`);& \/ K! i& u- x+ [4 O
- // Creates CSS variables like:
$ B1 E* z/ p- v# U" f6 [# V - // --my-prefix-buttonColor: #aabbcc" ]1 K- V# `5 F7 j3 y9 _
- // --my-prefix-accentTextColor: #aabbcc
9 x: A+ R. k! x7 b$ |+ V - // --my-prefix-bgColor: #aabbcc! x" \% s* C! D% _: |& c8 l) m5 |
- // ...# Q3 {. }5 I- A! U Y+ S W1 n
- 4 k7 H4 ^- u$ K/ r1 V- V4 R4 T9 @
- // themeParams.isCssVarsBound() -> true
复制代码 Functions :' c$ z8 a, L A# ]; S
- import {
; I/ ^, B8 \& k- x - bindThemeParamsCssVars,
u; x( y9 R8 S6 u1 W- d# h - isThemeParamsCssVarsBound,' l$ @7 H' |2 |( L7 a
- } from '@telegram-apps/sdk';
" k" B1 x" _" u/ J) x5 t: G
6 A2 j' V D$ t/ \6 k6 X- bindThemeParamsCssVars();: m% `; \" t( ~, `( }
- // Creates CSS variables like:4 `: d* b; G8 B$ k5 i) B' X. Z
- // --tg-theme-button-color: #aabbcc, t ~7 X: G6 i+ {3 M
- // --tg-theme-accent-text-color: #aabbcc
8 K2 E; l. a y5 t J6 u; J - // --tg-theme-bg-color: #aabbcc
2 D0 v5 O# `0 O - // ...( e- ~' F/ h& y5 v, Q+ }
' S0 @5 s2 d8 Y$ {/ U- bindThemeParamsCssVars(key => `--my-prefix-${key}`);4 N; i" ^0 e# ^. H x
- // Creates CSS variables like:
- S" S! A2 G: V+ X; r - // --my-prefix-buttonColor: #aabbcc- @4 |- A ^* b1 F3 D- A3 t
- // --my-prefix-accentTextColor: #aabbcc$ H6 J' `7 u+ y& I) G9 ~8 H" M0 e+ L
- // --my-prefix-bgColor: #aabbcc
- o9 c6 C. o3 x: K9 e. i1 C - // ...6 I3 ]4 N! O2 U" v8 \* h, l R. I8 S
" Q5 j0 T( g( O- // isThemeParamsCssVarsBound() -> true
复制代码 属性8 X0 n* f+ l% X# }* Q: d
Variable :* g7 m) F; y. _# B
- themeParams.accentTextColor(); // RGB | undefined
, D$ ]' o$ n# {5 r& k1 l5 h4 L - themeParams.backgroundColor(); // RGB | undefined5 y) U/ C. T' |5 N
- themeParams.buttonTextColor(); // RGB | undefined1 U! O+ H" K+ V# c4 r9 I
- themeParams.buttonColor(); // RGB | undefined
) c( u1 m. i- a Z' Q - themeParams.destructiveTextColor(); // RGB | undefined
) O% L4 z! e5 A - themeParams.headerBackgroundColor(); // RGB | undefined/ i& _- C& i4 F! N. o2 P, E
- themeParams.hintColor(); // RGB | undefined Z8 v& K. p9 I# j" n- h$ Q+ c
- themeParams.linkColor(); // RGB | undefined
& Y# l6 [9 f/ s) t+ F( {* H - themeParams.subtitleTextColor(); // RGB | undefined
8 M6 L5 N; y# d6 l* R# I) i - themeParams.sectionBackgroundColor(); // RGB | undefined
4 [6 V9 z0 W5 J3 k# l0 O6 _ - themeParams.secondaryBackgroundColor(); // RGB | undefined7 f) T; G% F; Q% K- V, G
- themeParams.sectionSeparatorColor(); // RGB | undefined
& G. Z4 T. ^. b$ V: l - themeParams.sectionHeaderTextColor(); // RGB | undefined; z; |1 i: v* Q2 Y5 `
- themeParams.textColor(); // RGB | undefined
# o$ q. B8 f0 `$ U% o - 8 Q- [* c" ?' T3 z
- themeParams.state(); // Record<string, RGB>;
复制代码 Functions :1 b9 l! B. i+ @
- import {
- \% j( | D4 C6 @# X0 o0 w - themeParamsAccentTextColor,
8 y0 D/ F. _6 _ y/ M6 v. C9 d - themeParamsBackgroundColor,
1 b1 {2 l8 u+ \ - themeParamsButtonTextColor,
: ~$ w% m( u$ p/ Z8 T - themeParamsButtonColor,9 y. T5 o& H; j! z
- themeParamsDestructiveTextColor,
( N" n+ g7 Z. l' N: w) N; ^% | - themeParamsHeaderBackgroundColor,
2 W5 { Q6 I3 n$ V - themeParamsHintColor,
* m! `: |+ f; V# }/ r- {6 V - themeParamsLinkColor,8 ~! n; e% `& o8 u: Q
- themeParamsSubtitleTextColor,2 G# v6 M$ T; W i2 a$ L
- themeParamsSectionBackgroundColor,
, T# m( F) [& T4 h; h; P t. D - themeParamsSecondaryBackgroundColor,/ G! V3 d8 M3 U
- themeParamsSectionSeparatorColor,
$ m. U, L& k6 _ - themeParamsSectionHeaderTextColor,
2 n) S& {0 q$ i: f - themeParamsTextColor,6 T* V; T" z% G) ]
- themeParamsState,
% _ }: d8 @) Z3 r2 u - } from '@telegram-apps/sdk';2 @" J+ E: V" v h
; l6 K4 P5 ]6 ~6 @- themeParamsAccentTextColor(); // RGB | undefined+ [* `9 W; h! ~, @
- themeParamsBackgroundColor(); // RGB | undefined: p# w* {: B) c! `
- themeParamsButtonTextColor(); // RGB | undefined
( e0 I. c6 x+ |8 }: F4 v: _ - themeParamsButtonColor(); // RGB | undefined5 ~$ }2 q6 @3 I. R$ N I- D
- themeParamsDestructiveTextColor(); // RGB | undefined1 A/ J7 e7 [8 m& `
- themeParamsHeaderBackgroundColor(); // RGB | undefined
, h7 r! k2 N0 H0 j' ]$ k - themeParamsHintColor(); // RGB | undefined% l0 s' q B+ [% H$ W
- themeParamsLinkColor(); // RGB | undefined
0 [' J8 r% b V1 Q- o4 ^1 } - themeParamsSubtitleTextColor(); // RGB | undefined
4 }( H* D" x5 y" j - themeParamsSectionBackgroundColor(); // RGB | undefined- H0 f+ X1 J& L
- themeParamsSecondaryBackgroundColor(); // RGB | undefined% t( G) Q+ p0 {6 y! I9 ^
- themeParamsSectionSeparatorColor(); // RGB | undefined2 B; G( Z D( g; k
- themeParamsSectionHeaderTextColor(); // RGB | undefined
& C! V6 i7 o+ t' x - themeParamsTextColor(); // RGB | undefined @! o' ^! S% i4 w
6 a6 S) d9 N2 K- 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 _ |