@d13co/use-wallet-ui-react 1.0.0
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/LICENSE +21 -0
- package/README.md +556 -0
- package/dist/cjs/index.cjs +233 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.js +65176 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/style.css +1239 -0
- package/dist/types/index.d.cts +250 -0
- package/dist/types/index.d.ts +250 -0
- package/package.json +98 -0
- package/src/theme.css +108 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TxnLab, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
# @txnlab/use-wallet-ui-react
|
|
2
|
+
|
|
3
|
+
Ready-to-use React UI components for Algorand wallet integration, built as a companion to [@txnlab/use-wallet-react](https://github.com/TxnLab/use-wallet).
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@txnlab/use-wallet-ui-react)
|
|
6
|
+
[](https://github.com/TxnLab/use-wallet-ui/actions/workflows/ci.yml)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
- [Installation](#installation)
|
|
13
|
+
- [Quick Start](#quick-start)
|
|
14
|
+
- [Styling](#styling)
|
|
15
|
+
- [Customization](#customization)
|
|
16
|
+
- [Theming](#theming)
|
|
17
|
+
- [Components](#components)
|
|
18
|
+
- [Hooks](#hooks)
|
|
19
|
+
- [Tanstack Query Integration](#tanstack-query-integration)
|
|
20
|
+
- [Migration from v0.x](#migration-from-v0x)
|
|
21
|
+
- [License](#license)
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @txnlab/use-wallet-ui-react
|
|
27
|
+
# or
|
|
28
|
+
yarn add @txnlab/use-wallet-ui-react
|
|
29
|
+
# or
|
|
30
|
+
pnpm add @txnlab/use-wallet-ui-react
|
|
31
|
+
# or
|
|
32
|
+
bun add @txnlab/use-wallet-ui-react
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Requirements
|
|
36
|
+
|
|
37
|
+
- `@txnlab/use-wallet-react` v4+
|
|
38
|
+
- `algosdk` v3+
|
|
39
|
+
- React 18 or 19
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
```jsx
|
|
44
|
+
import { NetworkId, WalletId, WalletManager, WalletProvider } from '@txnlab/use-wallet-react'
|
|
45
|
+
import { WalletUIProvider, WalletButton } from '@txnlab/use-wallet-ui-react'
|
|
46
|
+
|
|
47
|
+
// Import styles if NOT using Tailwind CSS
|
|
48
|
+
import '@txnlab/use-wallet-ui-react/dist/style.css'
|
|
49
|
+
|
|
50
|
+
const walletManager = new WalletManager({
|
|
51
|
+
wallets: [
|
|
52
|
+
WalletId.PERA,
|
|
53
|
+
WalletId.DEFLY,
|
|
54
|
+
WalletId.LUTE,
|
|
55
|
+
WalletId.EXODUS,
|
|
56
|
+
{
|
|
57
|
+
id: WalletId.WALLETCONNECT,
|
|
58
|
+
options: { projectId: 'your-project-id' },
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
defaultNetwork: NetworkId.TESTNET,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
function App() {
|
|
65
|
+
return (
|
|
66
|
+
<WalletProvider manager={walletManager}>
|
|
67
|
+
<WalletUIProvider>
|
|
68
|
+
<WalletButton />
|
|
69
|
+
</WalletUIProvider>
|
|
70
|
+
</WalletProvider>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The `WalletButton` handles everything:
|
|
76
|
+
|
|
77
|
+
- Shows "Connect Wallet" when disconnected
|
|
78
|
+
- Opens wallet selection dialog
|
|
79
|
+
- Displays wallet address/NFD name and avatar when connected
|
|
80
|
+
- Provides account switching and disconnect options
|
|
81
|
+
|
|
82
|
+
## Styling
|
|
83
|
+
|
|
84
|
+
The library supports two styling approaches:
|
|
85
|
+
|
|
86
|
+
### With Tailwind CSS
|
|
87
|
+
|
|
88
|
+
Components use Tailwind utility classes. Configure Tailwind to scan our package:
|
|
89
|
+
|
|
90
|
+
**Tailwind v4:**
|
|
91
|
+
|
|
92
|
+
```css
|
|
93
|
+
@import 'tailwindcss';
|
|
94
|
+
@source "../node_modules/@txnlab/use-wallet-ui-react";
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Tailwind v3:**
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
// tailwind.config.js
|
|
101
|
+
module.exports = {
|
|
102
|
+
content: [
|
|
103
|
+
'./src/**/*.{js,ts,jsx,tsx}',
|
|
104
|
+
'./node_modules/@txnlab/use-wallet-ui-react/dist/**/*.{js,ts,jsx,tsx}',
|
|
105
|
+
],
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Without Tailwind CSS
|
|
110
|
+
|
|
111
|
+
Import our pre-built CSS:
|
|
112
|
+
|
|
113
|
+
```jsx
|
|
114
|
+
import '@txnlab/use-wallet-ui-react/dist/style.css'
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Customization
|
|
118
|
+
|
|
119
|
+
v1.0 introduces a flexible customization system with multiple approaches.
|
|
120
|
+
|
|
121
|
+
### Size Variants
|
|
122
|
+
|
|
123
|
+
```jsx
|
|
124
|
+
<WalletButton size="sm" /> {/* Small */}
|
|
125
|
+
<WalletButton size="md" /> {/* Medium (default) */}
|
|
126
|
+
<WalletButton size="lg" /> {/* Large */}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### CSS Variable Overrides
|
|
130
|
+
|
|
131
|
+
Theme colors are CSS custom properties that can be overridden globally or per-instance.
|
|
132
|
+
|
|
133
|
+
**Global override (in your CSS):**
|
|
134
|
+
|
|
135
|
+
```css
|
|
136
|
+
[data-wallet-theme] {
|
|
137
|
+
--wui-color-primary: #8b5cf6;
|
|
138
|
+
--wui-color-primary-hover: #7c3aed;
|
|
139
|
+
--wui-color-primary-text: #ffffff;
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Scoped override (on a wrapper):**
|
|
144
|
+
|
|
145
|
+
```css
|
|
146
|
+
.my-purple-button {
|
|
147
|
+
--wui-color-primary: #8b5cf6;
|
|
148
|
+
--wui-color-primary-hover: #7c3aed;
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
```jsx
|
|
153
|
+
<div className="my-purple-button">
|
|
154
|
+
<WalletButton />
|
|
155
|
+
</div>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Inline style override:**
|
|
159
|
+
|
|
160
|
+
```jsx
|
|
161
|
+
<WalletButton
|
|
162
|
+
style={{
|
|
163
|
+
'--wui-color-primary': '#10b981',
|
|
164
|
+
'--wui-color-primary-hover': '#059669',
|
|
165
|
+
} as React.CSSProperties}
|
|
166
|
+
/>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Available CSS Variables
|
|
170
|
+
|
|
171
|
+
| Variable | Description |
|
|
172
|
+
|----------|-------------|
|
|
173
|
+
| `--wui-color-primary` | Primary button background |
|
|
174
|
+
| `--wui-color-primary-hover` | Primary button hover state |
|
|
175
|
+
| `--wui-color-primary-text` | Primary button text |
|
|
176
|
+
| `--wui-color-bg` | Panel/dialog background |
|
|
177
|
+
| `--wui-color-bg-secondary` | Secondary background |
|
|
178
|
+
| `--wui-color-bg-tertiary` | Tertiary background |
|
|
179
|
+
| `--wui-color-bg-hover` | Hover background |
|
|
180
|
+
| `--wui-color-text` | Primary text color |
|
|
181
|
+
| `--wui-color-text-secondary` | Secondary text color |
|
|
182
|
+
| `--wui-color-text-tertiary` | Tertiary text color |
|
|
183
|
+
| `--wui-color-border` | Border color |
|
|
184
|
+
| `--wui-color-link` | Link color |
|
|
185
|
+
| `--wui-color-link-hover` | Link hover color |
|
|
186
|
+
| `--wui-color-overlay` | Modal overlay color |
|
|
187
|
+
| `--wui-color-danger-bg` | Danger button background |
|
|
188
|
+
| `--wui-color-danger-bg-hover` | Danger button hover |
|
|
189
|
+
| `--wui-color-danger-text` | Danger button text |
|
|
190
|
+
| `--wui-color-avatar-bg` | Avatar placeholder background |
|
|
191
|
+
| `--wui-color-avatar-icon` | Avatar placeholder icon |
|
|
192
|
+
|
|
193
|
+
### className Prop
|
|
194
|
+
|
|
195
|
+
Add custom classes (useful with Tailwind):
|
|
196
|
+
|
|
197
|
+
```jsx
|
|
198
|
+
<WalletButton className="rounded-full shadow-lg" />
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Direct CSS Selectors
|
|
202
|
+
|
|
203
|
+
Target the button element directly:
|
|
204
|
+
|
|
205
|
+
```css
|
|
206
|
+
.pill-button [data-wallet-button] {
|
|
207
|
+
border-radius: 9999px;
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
```jsx
|
|
212
|
+
<div className="pill-button">
|
|
213
|
+
<WalletButton />
|
|
214
|
+
</div>
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Custom Trigger Button
|
|
218
|
+
|
|
219
|
+
For complete control, use the Menu components with your own button:
|
|
220
|
+
|
|
221
|
+
```jsx
|
|
222
|
+
import { useWallet } from '@txnlab/use-wallet-react'
|
|
223
|
+
import { ConnectWalletMenu, ConnectedWalletMenu } from '@txnlab/use-wallet-ui-react'
|
|
224
|
+
|
|
225
|
+
function CustomWalletButton() {
|
|
226
|
+
const { activeAddress } = useWallet()
|
|
227
|
+
|
|
228
|
+
if (activeAddress) {
|
|
229
|
+
return (
|
|
230
|
+
<ConnectedWalletMenu>
|
|
231
|
+
<button className="my-connected-button">
|
|
232
|
+
{activeAddress.slice(0, 8)}...
|
|
233
|
+
</button>
|
|
234
|
+
</ConnectedWalletMenu>
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return (
|
|
239
|
+
<ConnectWalletMenu>
|
|
240
|
+
<button className="my-connect-button">Connect Wallet</button>
|
|
241
|
+
</ConnectWalletMenu>
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
The child element becomes the trigger - the library handles all the menu logic.
|
|
247
|
+
|
|
248
|
+
### Theme-Aware Customization
|
|
249
|
+
|
|
250
|
+
Create different styles for light and dark modes:
|
|
251
|
+
|
|
252
|
+
```css
|
|
253
|
+
.amber-theme {
|
|
254
|
+
--wui-color-primary: #f59e0b;
|
|
255
|
+
--wui-color-primary-hover: #d97706;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.dark .amber-theme {
|
|
259
|
+
--wui-color-primary: rgba(245, 179, 71, 0.15);
|
|
260
|
+
--wui-color-primary-hover: rgba(245, 179, 71, 0.25);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.dark .amber-theme [data-wallet-button] {
|
|
264
|
+
border: 1px solid rgba(245, 179, 71, 0.3);
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
See the [react-custom example](../../examples/react-custom) for comprehensive demos.
|
|
269
|
+
|
|
270
|
+
## Theming
|
|
271
|
+
|
|
272
|
+
The library supports automatic light/dark mode.
|
|
273
|
+
|
|
274
|
+
### Theme Options
|
|
275
|
+
|
|
276
|
+
```jsx
|
|
277
|
+
<WalletUIProvider theme="system"> {/* Default: follows OS preference */}
|
|
278
|
+
<WalletUIProvider theme="light"> {/* Always light */}
|
|
279
|
+
<WalletUIProvider theme="dark"> {/* Always dark */}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### How Theme Detection Works
|
|
283
|
+
|
|
284
|
+
The library checks these in order (first match wins):
|
|
285
|
+
|
|
286
|
+
1. **`data-theme` attribute**: Set by the `theme` prop on `WalletUIProvider`
|
|
287
|
+
2. **`.dark` class**: On any ancestor element (Tailwind convention)
|
|
288
|
+
3. **`prefers-color-scheme`**: System/browser preference (when `theme="system"`)
|
|
289
|
+
|
|
290
|
+
### Accessing Theme State
|
|
291
|
+
|
|
292
|
+
```jsx
|
|
293
|
+
import { useWalletUI } from '@txnlab/use-wallet-ui-react'
|
|
294
|
+
|
|
295
|
+
function MyComponent() {
|
|
296
|
+
const { theme, resolvedTheme } = useWalletUI()
|
|
297
|
+
// theme: 'light' | 'dark' | 'system' (the prop value)
|
|
298
|
+
// resolvedTheme: 'light' | 'dark' (the actual theme in use)
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Components
|
|
303
|
+
|
|
304
|
+
### WalletUIProvider
|
|
305
|
+
|
|
306
|
+
Required wrapper that enables theming, NFD lookups, and data prefetching.
|
|
307
|
+
|
|
308
|
+
```jsx
|
|
309
|
+
<WalletUIProvider
|
|
310
|
+
theme="system" // 'light' | 'dark' | 'system'
|
|
311
|
+
enablePrefetching={true} // Prefetch data for all wallet accounts
|
|
312
|
+
prefetchNfdView="thumbnail" // NFD data view: 'tiny' | 'thumbnail' | 'brief' | 'full'
|
|
313
|
+
queryClient={queryClient} // Optional: your existing Tanstack Query client
|
|
314
|
+
>
|
|
315
|
+
{children}
|
|
316
|
+
</WalletUIProvider>
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### WalletButton
|
|
320
|
+
|
|
321
|
+
All-in-one wallet connection component.
|
|
322
|
+
|
|
323
|
+
```jsx
|
|
324
|
+
<WalletButton
|
|
325
|
+
size="md" // 'sm' | 'md' | 'lg'
|
|
326
|
+
className="..." // Additional CSS classes
|
|
327
|
+
style={{...}} // Inline styles (supports CSS variable overrides)
|
|
328
|
+
/>
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### ConnectWalletMenu
|
|
332
|
+
|
|
333
|
+
Dropdown menu for wallet selection (disconnected state).
|
|
334
|
+
|
|
335
|
+
```jsx
|
|
336
|
+
// With default button
|
|
337
|
+
<ConnectWalletMenu />
|
|
338
|
+
|
|
339
|
+
// With customized button
|
|
340
|
+
<ConnectWalletMenu>
|
|
341
|
+
<ConnectWalletButton size="lg">Connect</ConnectWalletButton>
|
|
342
|
+
</ConnectWalletMenu>
|
|
343
|
+
|
|
344
|
+
// With custom trigger
|
|
345
|
+
<ConnectWalletMenu>
|
|
346
|
+
<button>My Custom Button</button>
|
|
347
|
+
</ConnectWalletMenu>
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### ConnectWalletButton
|
|
351
|
+
|
|
352
|
+
Styled button for the connect state.
|
|
353
|
+
|
|
354
|
+
```jsx
|
|
355
|
+
<ConnectWalletButton
|
|
356
|
+
size="md" // 'sm' | 'md' | 'lg'
|
|
357
|
+
className="..." // Additional classes
|
|
358
|
+
style={{...}} // Inline styles
|
|
359
|
+
>
|
|
360
|
+
Connect Wallet {/* Optional: custom text */}
|
|
361
|
+
</ConnectWalletButton>
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### ConnectedWalletMenu
|
|
365
|
+
|
|
366
|
+
Dropdown menu for account management (connected state).
|
|
367
|
+
|
|
368
|
+
```jsx
|
|
369
|
+
// With default button
|
|
370
|
+
<ConnectedWalletMenu />
|
|
371
|
+
|
|
372
|
+
// With customized button
|
|
373
|
+
<ConnectedWalletMenu>
|
|
374
|
+
<ConnectedWalletButton size="sm" />
|
|
375
|
+
</ConnectedWalletMenu>
|
|
376
|
+
|
|
377
|
+
// With custom trigger
|
|
378
|
+
<ConnectedWalletMenu>
|
|
379
|
+
<div className="my-wallet-display">Connected</div>
|
|
380
|
+
</ConnectedWalletMenu>
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
### ConnectedWalletButton
|
|
384
|
+
|
|
385
|
+
Styled button showing wallet address/NFD and avatar.
|
|
386
|
+
|
|
387
|
+
```jsx
|
|
388
|
+
<ConnectedWalletButton
|
|
389
|
+
size="md" // 'sm' | 'md' | 'lg'
|
|
390
|
+
className="..." // Additional classes
|
|
391
|
+
style={{...}} // Inline styles
|
|
392
|
+
/>
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### NfdAvatar
|
|
396
|
+
|
|
397
|
+
Renders NFD avatar images with IPFS gateway handling.
|
|
398
|
+
|
|
399
|
+
```jsx
|
|
400
|
+
import { useNfd, NfdAvatar } from '@txnlab/use-wallet-ui-react'
|
|
401
|
+
|
|
402
|
+
function Profile() {
|
|
403
|
+
const nfdQuery = useNfd()
|
|
404
|
+
|
|
405
|
+
return (
|
|
406
|
+
<NfdAvatar
|
|
407
|
+
nfd={nfdQuery.data}
|
|
408
|
+
size={48}
|
|
409
|
+
className="rounded-full"
|
|
410
|
+
alt="Profile"
|
|
411
|
+
/>
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### WalletList
|
|
417
|
+
|
|
418
|
+
Renders a list of available wallets (used internally by ConnectWalletMenu).
|
|
419
|
+
|
|
420
|
+
```jsx
|
|
421
|
+
<WalletList onWalletSelected={() => closeMenu()} />
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
## Hooks
|
|
425
|
+
|
|
426
|
+
### useNfd
|
|
427
|
+
|
|
428
|
+
Fetch NFD data for the active address.
|
|
429
|
+
|
|
430
|
+
```jsx
|
|
431
|
+
import { useNfd } from '@txnlab/use-wallet-ui-react'
|
|
432
|
+
|
|
433
|
+
function Profile() {
|
|
434
|
+
const nfdQuery = useNfd({
|
|
435
|
+
enabled: true, // Enable/disable the query
|
|
436
|
+
view: 'thumbnail' // 'tiny' | 'thumbnail' | 'brief' | 'full'
|
|
437
|
+
})
|
|
438
|
+
|
|
439
|
+
if (nfdQuery.isLoading) return <div>Loading...</div>
|
|
440
|
+
|
|
441
|
+
return <div>{nfdQuery.data?.name || 'No NFD'}</div>
|
|
442
|
+
}
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### useAccountInfo
|
|
446
|
+
|
|
447
|
+
Fetch account information (balance, assets) for the active address.
|
|
448
|
+
|
|
449
|
+
```jsx
|
|
450
|
+
import { useAccountInfo } from '@txnlab/use-wallet-ui-react'
|
|
451
|
+
|
|
452
|
+
function Balance() {
|
|
453
|
+
const accountQuery = useAccountInfo()
|
|
454
|
+
|
|
455
|
+
if (accountQuery.isLoading) return <div>Loading...</div>
|
|
456
|
+
if (!accountQuery.data) return null
|
|
457
|
+
|
|
458
|
+
const algoBalance = Number(accountQuery.data.amount) / 1_000_000
|
|
459
|
+
|
|
460
|
+
return <div>{algoBalance.toFixed(2)} ALGO</div>
|
|
461
|
+
}
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
### useWalletUI
|
|
465
|
+
|
|
466
|
+
Access the WalletUI context.
|
|
467
|
+
|
|
468
|
+
```jsx
|
|
469
|
+
import { useWalletUI } from '@txnlab/use-wallet-ui-react'
|
|
470
|
+
|
|
471
|
+
function MyComponent() {
|
|
472
|
+
const { theme, resolvedTheme, queryClient } = useWalletUI()
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
### useResolvedTheme
|
|
477
|
+
|
|
478
|
+
Get the resolved theme value (handles 'system' preference detection).
|
|
479
|
+
|
|
480
|
+
```jsx
|
|
481
|
+
import { useResolvedTheme } from '@txnlab/use-wallet-ui-react'
|
|
482
|
+
|
|
483
|
+
function MyComponent() {
|
|
484
|
+
const resolvedTheme = useResolvedTheme('system') // Returns 'light' or 'dark'
|
|
485
|
+
}
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
## Tanstack Query Integration
|
|
489
|
+
|
|
490
|
+
The library uses [Tanstack Query](https://tanstack.com/query) internally. If your app already uses it, share the QueryClient to avoid duplicate caches:
|
|
491
|
+
|
|
492
|
+
```jsx
|
|
493
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
494
|
+
import { WalletProvider } from '@txnlab/use-wallet-react'
|
|
495
|
+
import { WalletUIProvider } from '@txnlab/use-wallet-ui-react'
|
|
496
|
+
|
|
497
|
+
const queryClient = new QueryClient()
|
|
498
|
+
|
|
499
|
+
function App() {
|
|
500
|
+
return (
|
|
501
|
+
<QueryClientProvider client={queryClient}>
|
|
502
|
+
<WalletProvider manager={walletManager}>
|
|
503
|
+
<WalletUIProvider queryClient={queryClient}>
|
|
504
|
+
{/* Your app */}
|
|
505
|
+
</WalletUIProvider>
|
|
506
|
+
</WalletProvider>
|
|
507
|
+
</QueryClientProvider>
|
|
508
|
+
)
|
|
509
|
+
}
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
## Migration from v0.x
|
|
513
|
+
|
|
514
|
+
v1.0 introduces a redesigned CSS architecture. Here's what changed:
|
|
515
|
+
|
|
516
|
+
### Breaking Changes
|
|
517
|
+
|
|
518
|
+
1. **CSS Variable Prefix**: Variables now use `--wui-` prefix (previously undocumented)
|
|
519
|
+
2. **Theme Variables Location**: Defined on `[data-wallet-theme]` element (for CSS variable inheritance)
|
|
520
|
+
3. **Button Data Attribute**: Buttons now have `data-wallet-button` attribute for targeting
|
|
521
|
+
|
|
522
|
+
### New Features
|
|
523
|
+
|
|
524
|
+
1. **Size Variants**: `WalletButton`, `ConnectWalletButton`, and `ConnectedWalletButton` now accept a `size` prop (`'sm' | 'md' | 'lg'`)
|
|
525
|
+
|
|
526
|
+
2. **className/style Props**: All button components accept `className` and `style` props for customization
|
|
527
|
+
|
|
528
|
+
3. **CSS Variable Overrides**: Override any theme color via CSS:
|
|
529
|
+
```css
|
|
530
|
+
[data-wallet-theme] {
|
|
531
|
+
--wui-color-primary: #your-color;
|
|
532
|
+
}
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
4. **Custom Triggers**: Pass any element as a child to `ConnectWalletMenu` or `ConnectedWalletMenu` for full control:
|
|
536
|
+
```jsx
|
|
537
|
+
<ConnectWalletMenu>
|
|
538
|
+
<MyCustomButton />
|
|
539
|
+
</ConnectWalletMenu>
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
5. **Theme Detection**: Now respects `.dark` class on ancestors (Tailwind convention) in addition to `data-theme` attribute and `prefers-color-scheme` media query
|
|
543
|
+
|
|
544
|
+
### Migration Steps
|
|
545
|
+
|
|
546
|
+
1. Update any custom CSS targeting the library:
|
|
547
|
+
- Use `[data-wallet-theme]` for CSS variable overrides
|
|
548
|
+
- Use `[data-wallet-button]` for targeting button elements
|
|
549
|
+
|
|
550
|
+
2. If you were using workarounds for customization, you can likely simplify using the new APIs
|
|
551
|
+
|
|
552
|
+
3. Test dark mode behavior - it should work more reliably with Tailwind's `.dark` class
|
|
553
|
+
|
|
554
|
+
## License
|
|
555
|
+
|
|
556
|
+
MIT
|