@txnlab/use-wallet-ui-react 0.3.1 → 0.4.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/README.md +80 -1
- package/dist/cjs/index.cjs +59 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +3937 -3857
- package/dist/esm/index.js.map +1 -1
- package/dist/style.css +176 -231
- package/dist/types/index.d.cts +31 -1
- package/dist/types/index.d.ts +31 -1
- package/package.json +3 -1
- package/src/theme.css +76 -0
package/README.md
CHANGED
|
@@ -105,6 +105,7 @@ That's it! You now have a fully functional wallet connection system with:
|
|
|
105
105
|
- [Styling Options](#styling-options)
|
|
106
106
|
- [Without Tailwind CSS](#without-tailwind-css)
|
|
107
107
|
- [With Tailwind CSS](#with-tailwind-css)
|
|
108
|
+
- [Theming](#theming)
|
|
108
109
|
- [Basic Usage](#basic-usage)
|
|
109
110
|
- [Component API](#component-api)
|
|
110
111
|
- [NFD Integration](#nfd-integration)
|
|
@@ -205,6 +206,83 @@ function App() {
|
|
|
205
206
|
|
|
206
207
|
While this approach offers less flexibility for customization compared to Tailwind, it provides a simple way to use the components with minimal setup.
|
|
207
208
|
|
|
209
|
+
## Theming
|
|
210
|
+
|
|
211
|
+
The library supports light and dark modes out of the box. You can control the theme using the `theme` prop on `WalletUIProvider`.
|
|
212
|
+
|
|
213
|
+
### Theme Options
|
|
214
|
+
|
|
215
|
+
```jsx
|
|
216
|
+
<WalletUIProvider theme="system"> {/* Default: follows OS/browser preference */}
|
|
217
|
+
{/* ... */}
|
|
218
|
+
</WalletUIProvider>
|
|
219
|
+
|
|
220
|
+
<WalletUIProvider theme="light"> {/* Always use light mode */}
|
|
221
|
+
{/* ... */}
|
|
222
|
+
</WalletUIProvider>
|
|
223
|
+
|
|
224
|
+
<WalletUIProvider theme="dark"> {/* Always use dark mode */}
|
|
225
|
+
{/* ... */}
|
|
226
|
+
</WalletUIProvider>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### How Theming Works
|
|
230
|
+
|
|
231
|
+
The library uses CSS custom properties for colors, which are automatically applied based on the theme setting:
|
|
232
|
+
|
|
233
|
+
1. **`theme="system"` (default)**: The library respects the user's OS/browser preference via the `prefers-color-scheme` media query.
|
|
234
|
+
|
|
235
|
+
2. **`theme="light"` or `theme="dark"`**: Explicitly sets the theme regardless of system preference.
|
|
236
|
+
|
|
237
|
+
3. **Tailwind `.dark` class**: The library also respects the `.dark` class on ancestor elements (common Tailwind convention). If a `.dark` class is present on an ancestor, dark mode will be used unless explicitly overridden with `theme="light"`.
|
|
238
|
+
|
|
239
|
+
### Accessing Theme in Your App
|
|
240
|
+
|
|
241
|
+
You can access the current theme state using the `useWalletUI` hook:
|
|
242
|
+
|
|
243
|
+
```jsx
|
|
244
|
+
import { useWalletUI } from '@txnlab/use-wallet-ui-react'
|
|
245
|
+
|
|
246
|
+
function MyComponent() {
|
|
247
|
+
const { theme, resolvedTheme } = useWalletUI()
|
|
248
|
+
|
|
249
|
+
// theme: 'light' | 'dark' | 'system' (the prop value)
|
|
250
|
+
// resolvedTheme: 'light' | 'dark' (the actual applied theme)
|
|
251
|
+
|
|
252
|
+
return <div>Current theme: {resolvedTheme}</div>
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Custom Theme Colors
|
|
257
|
+
|
|
258
|
+
The library uses CSS custom properties that you can override in your own CSS to customize the color scheme:
|
|
259
|
+
|
|
260
|
+
```css
|
|
261
|
+
/* Override theme colors */
|
|
262
|
+
[data-wallet-ui] {
|
|
263
|
+
--wui-color-primary: #your-primary-color;
|
|
264
|
+
--wui-color-primary-hover: #your-primary-hover;
|
|
265
|
+
--wui-color-primary-text: #your-primary-text;
|
|
266
|
+
--wui-color-bg: #your-background;
|
|
267
|
+
--wui-color-bg-secondary: #your-secondary-bg;
|
|
268
|
+
--wui-color-bg-tertiary: #your-tertiary-bg;
|
|
269
|
+
--wui-color-bg-hover: #your-hover-bg;
|
|
270
|
+
--wui-color-text: #your-text-color;
|
|
271
|
+
--wui-color-text-secondary: #your-secondary-text;
|
|
272
|
+
--wui-color-text-tertiary: #your-tertiary-text;
|
|
273
|
+
--wui-color-border: #your-border-color;
|
|
274
|
+
--wui-color-link: #your-link-color;
|
|
275
|
+
--wui-color-link-hover: #your-link-hover;
|
|
276
|
+
--wui-color-overlay: rgba(0, 0, 0, 0.3);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/* Override dark mode colors */
|
|
280
|
+
[data-wallet-ui][data-theme='dark'] {
|
|
281
|
+
--wui-color-primary: #your-dark-primary;
|
|
282
|
+
/* ... other dark mode overrides */
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
208
286
|
## Basic Usage
|
|
209
287
|
|
|
210
288
|
This library builds on top of `@txnlab/use-wallet-react` to provide UI components for wallet connectivity. Here's the basic setup:
|
|
@@ -278,11 +356,12 @@ The library provides several components that can be used independently or togeth
|
|
|
278
356
|
|
|
279
357
|
### WalletUIProvider
|
|
280
358
|
|
|
281
|
-
Required wrapper that enables NFD lookups
|
|
359
|
+
Required wrapper that enables NFD lookups, data prefetching, and theming:
|
|
282
360
|
|
|
283
361
|
```jsx
|
|
284
362
|
<WalletUIProvider
|
|
285
363
|
// Optional configurations
|
|
364
|
+
theme="system" // Theme setting: 'light' | 'dark' | 'system' (default: 'system')
|
|
286
365
|
enablePrefetching={false} // Prefetch data for all accounts in a wallet (default: true)
|
|
287
366
|
prefetchNfdView="brief" // Data view for NFD prefetching (default: 'thumbnail')
|
|
288
367
|
queryClient={yourQueryClient} // Optional: integrate with existing Tanstack Query
|