@bchconnect/ui 0.0.0-stage → 0.1.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 +269 -2
- package/custom-elements.json +1771 -0
- package/dist/assets.generated.js +28 -0
- package/dist/assets.generated.js.map +1 -0
- package/dist/bchconnect-modal.d.ts +69 -0
- package/dist/bchconnect-modal.js +96 -0
- package/dist/bchconnect-modal.js.map +1 -0
- package/dist/code.js +130 -0
- package/dist/code.js.map +1 -0
- package/dist/defaults.d.ts +50 -0
- package/dist/defaults.js +139 -0
- package/dist/defaults.js.map +1 -0
- package/dist/define.d.ts +17 -0
- package/dist/define.js +23 -0
- package/dist/define.js.map +1 -0
- package/dist/directory.js +37 -0
- package/dist/directory.js.map +1 -0
- package/dist/faces.js +80 -0
- package/dist/faces.js.map +1 -0
- package/dist/gesture.js +78 -0
- package/dist/gesture.js.map +1 -0
- package/dist/headless.d.ts +99 -0
- package/dist/headless.js +190 -0
- package/dist/headless.js.map +1 -0
- package/dist/html.js +17 -0
- package/dist/html.js.map +1 -0
- package/dist/icons.js +21 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +8 -0
- package/dist/locales/es.d.ts +12 -0
- package/dist/locales/es.js +50 -0
- package/dist/locales/es.js.map +1 -0
- package/dist/messages.d.ts +95 -0
- package/dist/messages.js +63 -0
- package/dist/messages.js.map +1 -0
- package/dist/modal.d.ts +112 -0
- package/dist/modal.js +694 -0
- package/dist/modal.js.map +1 -0
- package/dist/motion.js +160 -0
- package/dist/motion.js.map +1 -0
- package/dist/page-scroll.js +28 -0
- package/dist/page-scroll.js.map +1 -0
- package/dist/register.js +14 -0
- package/dist/register.js.map +1 -0
- package/dist/sheet-query.js +8 -0
- package/dist/sheet-query.js.map +1 -0
- package/dist/sheet.js +329 -0
- package/dist/sheet.js.map +1 -0
- package/dist/state.d.ts +175 -0
- package/dist/state.js +11 -0
- package/dist/state.js.map +1 -0
- package/dist/styles/modal.css.sheet.js +13 -0
- package/dist/styles/modal.css.sheet.js.map +1 -0
- package/dist/styles/theme.generated.css.sheet.js +13 -0
- package/dist/styles/theme.generated.css.sheet.js.map +1 -0
- package/dist/styles/toast.css.sheet.js +13 -0
- package/dist/styles/toast.css.sheet.js.map +1 -0
- package/dist/styles/tokens.css.sheet.js +13 -0
- package/dist/styles/tokens.css.sheet.js.map +1 -0
- package/dist/theme.generated.d.ts +105 -0
- package/dist/theme.generated.js +96 -0
- package/dist/theme.generated.js.map +1 -0
- package/dist/toast.d.ts +96 -0
- package/dist/toast.js +180 -0
- package/dist/toast.js.map +1 -0
- package/package.json +87 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BCH Connect
|
|
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
CHANGED
|
@@ -1,3 +1,270 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bchconnect/ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The connect modal and success toast of
|
|
4
|
+
[BCH Connect](https://github.com/BCH-Connect/bchconnect), a wallet-connection
|
|
5
|
+
library for Bitcoin Cash dapps. They are custom elements that work with vanilla JS/TS or any framework.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
> This package is in alpha and not yet stable. Expect breaking changes.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
**With BCH Connect** (most dapps): the built-in modal, plugged into the client.
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @bchconnect/core @bchconnect/connector-wizardconnect @bchconnect/ui
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
One line in `createClient()` turns it on: `ui: bchconnectModal()`. See [Usage](#usage).
|
|
20
|
+
|
|
21
|
+
**Standalone**: `<bchc-modal>` and `<bchc-toast>` without BCH Connect core package, driven
|
|
22
|
+
by your own code. See [Standalone use](#standalone-use).
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
npm install @bchconnect/ui
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`@bchconnect/core` is an optional peer dependency. Only `@bchconnect/ui/modal`
|
|
29
|
+
and `@bchconnect/ui/headless` need it, so your dapp and the modal share one
|
|
30
|
+
client. If you import those entries without `@bchconnect/core`, your bundler
|
|
31
|
+
will report the missing import at build time.
|
|
32
|
+
|
|
33
|
+
**Recommended font**: the modal is designed with
|
|
34
|
+
[Plus Jakarta Sans](https://fonts.google.com/specimen/Plus+Jakarta+Sans). The
|
|
35
|
+
package doesn't ship it, so install it alongside to get the intended look:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npm install @fontsource-variable/plus-jakarta-sans
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then set it up in two steps:
|
|
42
|
+
|
|
43
|
+
1. Import the package once in your app's entry file, such as `main.ts`:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import "@fontsource-variable/plus-jakarta-sans";
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
2. In your global stylesheet, tell the modal to use it:
|
|
50
|
+
|
|
51
|
+
```css
|
|
52
|
+
:root {
|
|
53
|
+
--bchc-font-brand-family: "Plus Jakarta Sans Variable";
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Without it, text falls back to the system font. To use another font, see
|
|
58
|
+
[Fonts](#fonts).
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
Pass the built-in modal as the client's `ui`, then call `connect()`.
|
|
63
|
+
The modal lists wallets, shows the QR code or wallet link, and closes
|
|
64
|
+
with a success toast once the wallet connects.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { createClient } from "@bchconnect/core";
|
|
68
|
+
import { wizardConnect } from "@bchconnect/connector-wizardconnect";
|
|
69
|
+
import { bchconnectModal } from "@bchconnect/ui/modal";
|
|
70
|
+
|
|
71
|
+
const client = createClient({
|
|
72
|
+
connectors: [wizardConnect()],
|
|
73
|
+
network: "mainnet",
|
|
74
|
+
appMetadata: { name: "My example dapp", url: "https://example.com" },
|
|
75
|
+
ui: bchconnectModal(),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await client.init();
|
|
79
|
+
const session = await client.connect();
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The element code, Lit and the QR library load on the first `connect()`, so
|
|
83
|
+
creating the client costs almost nothing up front and is safe on a server.
|
|
84
|
+
|
|
85
|
+
Pass an options object to configure the modal. Each option is optional and
|
|
86
|
+
falls back to a sensible default:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { BCHC_WALLETS } from "@bchconnect/ui";
|
|
90
|
+
import { bchconnectModal } from "@bchconnect/ui/modal";
|
|
91
|
+
|
|
92
|
+
bchconnectModal({
|
|
93
|
+
// Which wallets to list, in order. Defaults to the built-in list.
|
|
94
|
+
wallets: BCHC_WALLETS.filter((wallet) => wallet.id !== "optn"),
|
|
95
|
+
// Protocol tabs order.
|
|
96
|
+
protocols: ["wizardconnect", "bch-wc2"],
|
|
97
|
+
// What are the options selected by default.
|
|
98
|
+
defaults: { wallet: "selene", protocol: "wizardconnect" },
|
|
99
|
+
// Reword any string, merged over English.
|
|
100
|
+
messages: { connectTitle: "Sign in with a wallet" },
|
|
101
|
+
// Tune the modal and the toast.
|
|
102
|
+
theme: { accent: "blue", mode: "dark" },
|
|
103
|
+
// `false` skips the success toast; a duration sets how long it stays, in ms.
|
|
104
|
+
toast: { duration: 4000 },
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The session names the wallet picked in the modal but doesn't carry its logo,
|
|
109
|
+
so the saved session stays small. To show the logo, look it up by id, in your
|
|
110
|
+
own `wallets` list if you pass one:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { BCHC_WALLETS } from "@bchconnect/ui";
|
|
114
|
+
|
|
115
|
+
const logo =
|
|
116
|
+
BCHC_WALLETS.find((wallet) => wallet.id === session.wallet.id)?.logo ??
|
|
117
|
+
session.wallet.icon;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Theming
|
|
121
|
+
|
|
122
|
+
The modal and the toast are built to be restyled. Pick an accent, a neutral
|
|
123
|
+
family, a corner radius, a font, a backdrop blur and a colour scheme, and the
|
|
124
|
+
whole palette follows, in light and dark:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
bchconnectModal({
|
|
128
|
+
theme: {
|
|
129
|
+
accent: "violet",
|
|
130
|
+
radius: "large",
|
|
131
|
+
font: "system",
|
|
132
|
+
blur: "small",
|
|
133
|
+
mode: "auto",
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| Option | Values |
|
|
139
|
+
| --------- | ------------------------------------------------------------------------------------ |
|
|
140
|
+
| `accent` | `green` (default), `cyan`, `blue`, `violet`, `pink`, `red`, `amber`, `ink` |
|
|
141
|
+
| `neutral` | `sage`, `slate`, `sand`, `pure`. Defaults to the one paired with the selected accent |
|
|
142
|
+
| `radius` | `none`, `small`, `medium`, `large`, `full` |
|
|
143
|
+
| `font` | `brand`, `system`, `mono` |
|
|
144
|
+
| `blur` | `none`, `small`, `large` |
|
|
145
|
+
| `mode` | `auto` (follows the system), `light`, `dark` |
|
|
146
|
+
|
|
147
|
+
Set only the options you want to change; the rest keep their defaults. Each
|
|
148
|
+
accent comes paired with a neutral family, so leave `neutral` unset to keep the
|
|
149
|
+
pairing and set it only to mix families on purpose.
|
|
150
|
+
|
|
151
|
+
When you create the elements yourself, set the same options as `data-bchc-*`
|
|
152
|
+
attributes on the element: `data-bchc-accent`, `data-bchc-neutral`,
|
|
153
|
+
`data-bchc-radius`, `data-bchc-font`, `data-bchc-blur` and `data-bchc-mode`.
|
|
154
|
+
|
|
155
|
+
### Fonts
|
|
156
|
+
|
|
157
|
+
Any font works the way Plus Jakarta Sans does in [Install](#install): load it on
|
|
158
|
+
your page and set `--bchc-font-brand-family` to its family name. The variable
|
|
159
|
+
reaches the elements' shadow roots through inheritance, but a `@font-face` rule
|
|
160
|
+
inside a shadow root doesn't apply, so the font must be loaded on the page
|
|
161
|
+
itself.
|
|
162
|
+
|
|
163
|
+
## Choosing a ui for BCH Connect
|
|
164
|
+
|
|
165
|
+
`createClient()` from `@bchconnect/core` takes a `ui` option: an object whose
|
|
166
|
+
`connect(ctx)` method runs when your dapp calls `client.connect()` without
|
|
167
|
+
passing a protocol. Without `ui`, `connect()` needs an explicit protocol.
|
|
168
|
+
|
|
169
|
+
| `ui` | Rendering | Connection flow logic |
|
|
170
|
+
| --------------------------- | -------------------------------------------------------------------------------------------------- | --------------------- |
|
|
171
|
+
| `bchconnectModal()` | Built-in modal | Built-in |
|
|
172
|
+
| `headlessModal(myRenderer)` | Your own modal, as an object with `open`, `update` and `close` ([Headless modal](#headless-modal)) | Built-in |
|
|
173
|
+
| `{ connect(ctx) { … } }` | Your code | Your code |
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
import { bchconnectModal } from "@bchconnect/ui/modal";
|
|
177
|
+
import { headlessModal } from "@bchconnect/ui/headless";
|
|
178
|
+
|
|
179
|
+
createClient({ /* … */ ui: bchconnectModal() });
|
|
180
|
+
createClient({ /* … */ ui: headlessModal(myRenderer) });
|
|
181
|
+
createClient({
|
|
182
|
+
/* … */ ui: {
|
|
183
|
+
async connect(ctx) {
|
|
184
|
+
/* … */
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The connection flow lists wallets, starts the chosen protocol, and handles
|
|
191
|
+
retries, timeouts and cancellation until a session is returned. To write it
|
|
192
|
+
yourself, implement `connect(ctx)`:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
const client = createClient({
|
|
196
|
+
// …
|
|
197
|
+
ui: {
|
|
198
|
+
async connect(ctx) {
|
|
199
|
+
// A protocol passed to client.connect() is the only one allowed.
|
|
200
|
+
const protocol =
|
|
201
|
+
ctx.protocol ?? (await myProtocolPicker(ctx.protocols, ctx.signal));
|
|
202
|
+
return ctx.connect(protocol, { onPairing: showMyQrCode });
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Translations
|
|
209
|
+
|
|
210
|
+
Every string comes from a typed catalogue. Pass a built-in locale, or a partial
|
|
211
|
+
catalogue merged over English:
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
import { bchconnectModal } from "@bchconnect/ui/modal";
|
|
215
|
+
import { BCHC_MESSAGES_ES } from "@bchconnect/ui/locales/es";
|
|
216
|
+
|
|
217
|
+
bchconnectModal({ messages: BCHC_MESSAGES_ES });
|
|
218
|
+
bchconnectModal({ messages: { connectTitle: "Sign in with a wallet" } });
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Headless modal
|
|
222
|
+
|
|
223
|
+
To draw the modal yourself, keep its logic and supply a renderer.
|
|
224
|
+
`headlessModal()` runs the connection and hands your renderer a view to draw;
|
|
225
|
+
the renderer reports back what the person does.
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
import { headlessModal } from "@bchconnect/ui/headless";
|
|
229
|
+
|
|
230
|
+
const ui = headlessModal({
|
|
231
|
+
open(view, actions) {
|
|
232
|
+
myModal.show(view, actions);
|
|
233
|
+
},
|
|
234
|
+
update(view) {
|
|
235
|
+
myModal.render(view);
|
|
236
|
+
},
|
|
237
|
+
close() {
|
|
238
|
+
return myModal.hide();
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The `@bchconnect/ui/headless` entry carries no element code.
|
|
244
|
+
|
|
245
|
+
## Standalone use
|
|
246
|
+
|
|
247
|
+
`<bchc-modal>` and `<bchc-toast>` can also be used on their own, without
|
|
248
|
+
`@bchconnect/core`: register them with `defineElements()`, set `view`, and
|
|
249
|
+
listen for `bchc-*` events. Your code then drives the connection. Import the
|
|
250
|
+
package in the click handler to load it only when needed:
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
button.addEventListener("click", async () => {
|
|
254
|
+
const { defineElements } = await import("@bchconnect/ui");
|
|
255
|
+
defineElements();
|
|
256
|
+
const modal = document.createElement("bchc-modal");
|
|
257
|
+
// set modal.view and listen for bchc-* events
|
|
258
|
+
document.body.append(modal);
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Requirements
|
|
263
|
+
|
|
264
|
+
- A browser with custom elements and shadow DOM. The package is ESM only.
|
|
265
|
+
- A page that enforces Trusted Types must allow the `lit-html` policy in its
|
|
266
|
+
`trusted-types` directive.
|
|
267
|
+
|
|
268
|
+
## License
|
|
269
|
+
|
|
270
|
+
[MIT](https://github.com/BCH-Connect/bchconnect/blob/main/LICENSE)
|