@deloraprotocol/widget 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/README.md +175 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +2172 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# @deloraprotocol/widget
|
|
2
|
+
|
|
3
|
+
A React widget component library for crypto trading UI, migrated from delora-exchange (Angular). Includes Trade widget, token selection, network selection, and slippage panel. **Consumers do not need Tailwind** — the library ships compiled CSS.
|
|
4
|
+
|
|
5
|
+
**Note:** Wallet connection is not implemented. The widget shows placeholder UI for swap actions.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @deloraprotocol/widget react react-dom
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Import styles
|
|
14
|
+
|
|
15
|
+
You must import the library CSS once in your app (e.g. in your root entry file):
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import "@deloraprotocol/widget/styles.css";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Trade Widget
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { TradeWidget } from "@deloraprotocol/widget";
|
|
27
|
+
|
|
28
|
+
<TradeWidget
|
|
29
|
+
theme="dark"
|
|
30
|
+
config={{
|
|
31
|
+
dataBaseUrl: "https://your-app.com", // or "" for same-origin
|
|
32
|
+
apiBase: "https://api.delora.build",
|
|
33
|
+
}}
|
|
34
|
+
/>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`dataBaseUrl` must point to a server that hosts:
|
|
38
|
+
- `/data/networks.json`
|
|
39
|
+
- `/data/tokens.json`
|
|
40
|
+
- `/data/tokens_search.json`
|
|
41
|
+
|
|
42
|
+
Use `""` for same-origin (e.g. when data is in your app's public folder).
|
|
43
|
+
|
|
44
|
+
### Simple Widget (MyWidget)
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import { MyWidget } from "@deloraprotocol/widget";
|
|
48
|
+
|
|
49
|
+
<MyWidget theme="light" />
|
|
50
|
+
<MyWidget theme="dark" />
|
|
51
|
+
<MyWidget vars={{ accent: "#22c55e", radius: "24px" }} />
|
|
52
|
+
<MyWidget className="max-w-md" style={{ marginLeft: "2rem" }} />
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## API
|
|
56
|
+
|
|
57
|
+
### Exports
|
|
58
|
+
|
|
59
|
+
- `MyWidget` — the widget component
|
|
60
|
+
- `MyWidgetTheme` — `"light" | "dark"`
|
|
61
|
+
- `MyWidgetVars` — typed object for token overrides
|
|
62
|
+
- `MyWidgetProps` — component props
|
|
63
|
+
|
|
64
|
+
### `MyWidgetProps`
|
|
65
|
+
|
|
66
|
+
| Prop | Type | Description |
|
|
67
|
+
|----------|-------------------|--------------------------------------------------|
|
|
68
|
+
| `theme` | `"light" \| "dark"` | Built-in theme (default: `"light"`) |
|
|
69
|
+
| `vars` | `Partial<MyWidgetVars>` | Override theme tokens via CSS variables |
|
|
70
|
+
| `className` | `string` | Applied to root (for host layout/styling) |
|
|
71
|
+
| `style` | `React.CSSProperties` | Applied last for advanced overrides |
|
|
72
|
+
|
|
73
|
+
Extends `React.HTMLAttributes<HTMLDivElement>` for other div props.
|
|
74
|
+
|
|
75
|
+
## Why no Tailwind required in host
|
|
76
|
+
|
|
77
|
+
The library uses Tailwind only at **build time** to author styles. The output is plain compiled CSS shipped in `dist/styles.css`. Your host app imports this CSS file and does not need Tailwind, PostCSS, or any build-time Tailwind configuration.
|
|
78
|
+
|
|
79
|
+
## Style isolation
|
|
80
|
+
|
|
81
|
+
The library provides style isolation **without Shadow DOM**:
|
|
82
|
+
|
|
83
|
+
1. **Our styles don't affect the host**: We disable Tailwind preflight and do not emit global element selectors (e.g. no `button {}` or `h1 {}`). All styling is class-based and scoped within the widget markup.
|
|
84
|
+
|
|
85
|
+
2. **Host styles have limited impact on us**: We add a minimal scoped reset under `[data-delora-widget-root]`:
|
|
86
|
+
- `box-sizing: border-box` on root and descendants
|
|
87
|
+
- Explicit `font-family`, `font-size`, `color`, `line-height` on the root
|
|
88
|
+
|
|
89
|
+
3. **Limitations**: Host global styles (e.g. `* { box-sizing: content-box; }` or `button { font-size: 30px; }`) can still affect the widget in extreme cases. We mitigate by setting explicit values on the widget root and avoiding reliance on inherited defaults.
|
|
90
|
+
|
|
91
|
+
## Build
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npm run build
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Outputs:
|
|
98
|
+
- `dist/index.js` (ESM)
|
|
99
|
+
- `dist/index.d.ts`
|
|
100
|
+
- `dist/styles.css`
|
|
101
|
+
|
|
102
|
+
## Publishing to npm
|
|
103
|
+
|
|
104
|
+
### Prerequisites
|
|
105
|
+
|
|
106
|
+
- [npm account](https://www.npmjs.com/signup)
|
|
107
|
+
- For scoped packages like `@deloraprotocol/widget`: create the org at [npmjs.com/org/create](https://www.npmjs.com/org/create) (or change the scope in `package.json` to your username)
|
|
108
|
+
|
|
109
|
+
### First-time publish
|
|
110
|
+
|
|
111
|
+
1. **Build the package:**
|
|
112
|
+
```bash
|
|
113
|
+
npm run build
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
2. **Log in to npm:**
|
|
117
|
+
```bash
|
|
118
|
+
npm login
|
|
119
|
+
```
|
|
120
|
+
Enter your username, password, and email. If 2FA is enabled, enter the one-time code.
|
|
121
|
+
|
|
122
|
+
3. **Publish (scoped packages require `--access public`):**
|
|
123
|
+
```bash
|
|
124
|
+
npm publish --access public
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Publishing updates
|
|
128
|
+
|
|
129
|
+
1. Bump the version:
|
|
130
|
+
```bash
|
|
131
|
+
npm version patch # 1.0.0 → 1.0.1 (bug fixes)
|
|
132
|
+
npm version minor # 1.0.0 → 1.1.0 (new features)
|
|
133
|
+
npm version major # 1.0.0 → 2.0.0 (breaking changes)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
2. Build and publish:
|
|
137
|
+
```bash
|
|
138
|
+
npm run build
|
|
139
|
+
npm publish --access public
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Org members
|
|
143
|
+
|
|
144
|
+
- Add members under **Organization → Members** on npmjs.com
|
|
145
|
+
- Any member with publish rights can publish and update the package
|
|
146
|
+
- Only one person needs to create the org; others can be invited
|
|
147
|
+
|
|
148
|
+
## Running the widget locally
|
|
149
|
+
|
|
150
|
+
### One-time setup
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
npm install
|
|
154
|
+
npm run build
|
|
155
|
+
cd playground && npm install
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Development
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
npm run playground:dev
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
This runs the library watcher and the playground dev server together. The playground uses the built output from `dist/`.
|
|
165
|
+
|
|
166
|
+
**When errors occur or the UI shows stale/broken code:** run `npm run build` separately to rebuild the library, then restart or refresh the playground. The playground does not auto-rebuild the library.
|
|
167
|
+
|
|
168
|
+
### Alternative: build then run
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
npm run build
|
|
172
|
+
cd playground && npm run dev
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Build the library first, then run only the playground dev server.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
declare interface INativeCurrency {
|
|
4
|
+
name: string;
|
|
5
|
+
symbol: string;
|
|
6
|
+
decimals: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export declare function MyWidget(props: MyWidgetProps): JSX.Element;
|
|
10
|
+
|
|
11
|
+
export declare interface MyWidgetProps extends HTMLAttributes<HTMLDivElement> {
|
|
12
|
+
theme?: MyWidgetTheme;
|
|
13
|
+
vars?: Partial<MyWidgetVars>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export declare type MyWidgetTheme = "light" | "dark";
|
|
17
|
+
|
|
18
|
+
export declare interface MyWidgetVars {
|
|
19
|
+
bg: string;
|
|
20
|
+
fg: string;
|
|
21
|
+
accent: string;
|
|
22
|
+
border: string;
|
|
23
|
+
muted: string;
|
|
24
|
+
surface?: string;
|
|
25
|
+
surfaceAlt?: string;
|
|
26
|
+
surfaceHover?: string;
|
|
27
|
+
textSubtle?: string;
|
|
28
|
+
accentHover?: string;
|
|
29
|
+
success?: string;
|
|
30
|
+
danger?: string;
|
|
31
|
+
overlay?: string;
|
|
32
|
+
shadow?: string;
|
|
33
|
+
radius: string;
|
|
34
|
+
fontFamily: string;
|
|
35
|
+
fontSize: string;
|
|
36
|
+
lineHeight?: string;
|
|
37
|
+
letterSpacing?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export declare interface Network {
|
|
41
|
+
id: number;
|
|
42
|
+
name: string;
|
|
43
|
+
rpcUrls: string[];
|
|
44
|
+
logoURI?: string;
|
|
45
|
+
idHex?: string;
|
|
46
|
+
chainType: string;
|
|
47
|
+
explorerUrl?: string;
|
|
48
|
+
key: string;
|
|
49
|
+
nativeCurrency: INativeCurrency;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export declare interface Token {
|
|
53
|
+
symbol: string;
|
|
54
|
+
imageUrl: string;
|
|
55
|
+
contractAddress: string;
|
|
56
|
+
chainId: number;
|
|
57
|
+
decimals: number;
|
|
58
|
+
priceUSD?: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export declare function TradeWidget(props: TradeWidgetProps): JSX.Element;
|
|
63
|
+
|
|
64
|
+
export declare interface TradeWidgetConfig {
|
|
65
|
+
dataBaseUrl: string;
|
|
66
|
+
apiBase?: string;
|
|
67
|
+
/** Base URL for resolving relative image paths (e.g. /img/...). Defaults to dataBaseUrl or origin. */
|
|
68
|
+
assetBaseUrl?: string;
|
|
69
|
+
/** Whether a wallet is connected. When false, the main button shows "Connect Wallet" (Angular: isWalletConnected). */
|
|
70
|
+
isWalletConnected?: boolean;
|
|
71
|
+
/** Called when user clicks "Connect Wallet". The host should open its connect-wallet UI. */
|
|
72
|
+
onConnectWallet?: () => void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export declare interface TradeWidgetProps extends MyWidgetProps {
|
|
76
|
+
config: TradeWidgetConfig;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { }
|