@teactjs/react 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,208 @@
1
+ # @teactjs/react
2
+
3
+ Telegram UI components for Teact. Each component maps to a Telegram message type and renders through the Teact reconciler.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ bun add @teactjs/react
9
+ ```
10
+
11
+ ## Components
12
+
13
+ ### Message
14
+
15
+ Send a text message. Supports `parseMode` (`"HTML"` | `"Markdown"` | `"MarkdownV2"`).
16
+
17
+ ```tsx
18
+ <Message text="Hello, world!" parseMode="HTML" />
19
+ ```
20
+
21
+ Children render as inline keyboard:
22
+
23
+ ```tsx
24
+ <Message text="Pick one">
25
+ <InlineKeyboard>
26
+ <Button text="A" onClick={() => pick("a")} />
27
+ <Button text="B" onClick={() => pick("b")} />
28
+ </InlineKeyboard>
29
+ </Message>
30
+ ```
31
+
32
+ ### InlineKeyboard, ButtonRow, Button
33
+
34
+ Declarative inline keyboards. Buttons support `onClick` (callback or string), `url`, and `conversation` triggers.
35
+
36
+ ```tsx
37
+ <InlineKeyboard>
38
+ <ButtonRow>
39
+ <Button text="Visit" url="https://example.com" />
40
+ <Button text="Start chat" conversation="onboarding" />
41
+ </ButtonRow>
42
+ </InlineKeyboard>
43
+ ```
44
+
45
+ Compound syntax: `InlineKeyboard.Row`, `InlineKeyboard.Button`.
46
+
47
+ ### WebAppButton
48
+
49
+ Opens a Telegram Web App.
50
+
51
+ ```tsx
52
+ <WebAppButton text="Open App" url="https://my-webapp.com" />
53
+ ```
54
+
55
+ ### Photo
56
+
57
+ ```tsx
58
+ <Photo src="https://example.com/image.jpg" caption="A nice photo" hasSpoiler />
59
+ ```
60
+
61
+ ### Video
62
+
63
+ ```tsx
64
+ <Video src="./clip.mp4" caption="Watch this" width={640} height={480} supportsStreaming />
65
+ ```
66
+
67
+ ### Animation, Voice, Audio, VideoNote, Sticker, Document
68
+
69
+ ```tsx
70
+ <Audio src="./song.mp3" title="My Song" performer="Artist" duration={180} />
71
+ <Sticker src="./sticker.webp" emoji="fire" />
72
+ <Document src="./report.pdf" filename="report.pdf" caption="Monthly report" />
73
+ ```
74
+
75
+ ### Contact
76
+
77
+ ```tsx
78
+ <Contact phoneNumber="+1234567890" firstName="Alice" lastName="Smith" />
79
+ ```
80
+
81
+ ### Location, LiveLocation, Venue
82
+
83
+ ```tsx
84
+ <Location lat={40.7128} lon={-74.006} />
85
+ <LiveLocation lat={40.7128} lon={-74.006} livePeriod={3600} />
86
+ <Venue lat={40.7128} lon={-74.006} title="Central Park" address="New York, NY" />
87
+ ```
88
+
89
+ Compound syntax: `Location.Live`, `Location.Venue`.
90
+
91
+ ### MediaGroup
92
+
93
+ Group multiple photos and videos into a single message.
94
+
95
+ ```tsx
96
+ <MediaGroup>
97
+ <MediaPhoto src="./a.jpg" caption="First" />
98
+ <MediaVideo src="./b.mp4" caption="Second" />
99
+ </MediaGroup>
100
+ ```
101
+
102
+ Compound syntax: `MediaGroup.Photo`, `MediaGroup.Video`.
103
+
104
+ ### ReplyKeyboard
105
+
106
+ Custom keyboard that replaces the user's default keyboard.
107
+
108
+ ```tsx
109
+ <ReplyKeyboard resizeKeyboard oneTimeKeyboard placeholder="Choose...">
110
+ <ReplyRow>
111
+ <ReplyButton text="Option A" />
112
+ <ReplyButton text="Option B" />
113
+ </ReplyRow>
114
+ <ReplyRow>
115
+ <RequestContactButton text="Share contact" />
116
+ <RequestLocationButton text="Share location" />
117
+ </ReplyRow>
118
+ </ReplyKeyboard>
119
+ ```
120
+
121
+ Use `<ReplyKeyboardRemove />` to remove it.
122
+
123
+ ### Poll
124
+
125
+ ```tsx
126
+ <Poll question="Favorite color?" options={["Red", "Blue", "Green"]} />
127
+ ```
128
+
129
+ Quiz variant with `Poll.Quiz`:
130
+
131
+ ```tsx
132
+ <Poll.Quiz question="2 + 2?" options={["3", "4", "5"]} correctOptionId={1} />
133
+ ```
134
+
135
+ ### Notification
136
+
137
+ Answer a callback query with a toast or alert.
138
+
139
+ ```tsx
140
+ <Notification text="Saved!" showAlert />
141
+ ```
142
+
143
+ ### Formatting
144
+
145
+ ```tsx
146
+ <Message text={<>
147
+ <Bold>Important:</Bold> Use <Code language="typescript">useState</Code> for state.
148
+ <Italic>Simple as that.</Italic>
149
+ </>} />
150
+ ```
151
+
152
+ ### Alert, List, Divider
153
+
154
+ ```tsx
155
+ <Alert variant="warning" title="Heads up">Something happened</Alert>
156
+
157
+ <List ordered>
158
+ <ListItem>First</ListItem>
159
+ <ListItem>Second</ListItem>
160
+ </List>
161
+
162
+ <Divider char="=" length={30} />
163
+ ```
164
+
165
+ ### SuspenseFallback
166
+
167
+ Placeholder while a `<Suspense>` boundary resolves.
168
+
169
+ ```tsx
170
+ <SuspenseFallback text="Loading data..." />
171
+ ```
172
+
173
+ ### ErrorBoundary
174
+
175
+ Catches render errors in child components.
176
+
177
+ ```tsx
178
+ <ErrorBoundary fallback={<Message text="Something went wrong" />} onError={console.error}>
179
+ <RiskyComponent />
180
+ </ErrorBoundary>
181
+ ```
182
+
183
+ ## Data Hooks
184
+
185
+ ### useQuery
186
+
187
+ ```tsx
188
+ const { data, isLoading, error, refetch } = useQuery({
189
+ key: "pokemon",
190
+ fn: () => fetchPokemon(id),
191
+ staleTime: 60_000,
192
+ refetchInterval: 30_000,
193
+ });
194
+ ```
195
+
196
+ ### useMutation
197
+
198
+ ```tsx
199
+ const { mutate, isLoading, error, reset } = useMutation({
200
+ fn: (name: string) => createUser(name),
201
+ onSuccess: (user) => console.log("Created", user),
202
+ });
203
+ ```
204
+
205
+ ## See Also
206
+
207
+ - [`@teactjs/core`](../core) for the barrel import
208
+ - [`@teactjs/runtime`](../runtime) for runtime hooks