@bloxwap/hig 0.5.1 → 0.6.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 +1 -1
- package/chart/README.md +1 -1
- package/contracts/README.md +1 -1
- package/contracts/dist/messages.d.ts +31 -4
- package/contracts/dist/messages.js +11 -2
- package/feedback/README.md +1 -1
- package/native/README.md +1 -1
- package/native/dist/account-block.d.ts +46 -0
- package/native/dist/account-block.js +28 -0
- package/native/dist/asset-balance-row.d.ts +20 -0
- package/native/dist/asset-balance-row.js +21 -0
- package/native/dist/bar-mark.d.ts +45 -0
- package/native/dist/bar-mark.js +34 -0
- package/native/dist/bar-pnl.d.ts +50 -0
- package/native/dist/bar-pnl.js +59 -0
- package/native/dist/blocks.d.ts +44 -0
- package/native/dist/{recipes.js → blocks.js} +20 -9
- package/native/dist/field.d.ts +0 -1
- package/native/dist/field.js +0 -1
- package/native/dist/icons.d.ts +8 -0
- package/native/dist/icons.js +4 -0
- package/native/dist/language-block.d.ts +31 -0
- package/native/dist/language-block.js +30 -0
- package/native/dist/list-group.d.ts +26 -0
- package/native/dist/list-group.js +27 -0
- package/native/dist/manage-position-block.d.ts +69 -0
- package/native/dist/manage-position-block.js +57 -0
- package/native/dist/notifications-block.d.ts +25 -0
- package/native/dist/notifications-block.js +14 -0
- package/native/dist/pickers.d.ts +13 -5
- package/native/dist/pickers.js +10 -6
- package/native/dist/position-block.d.ts +51 -0
- package/native/dist/position-block.js +21 -0
- package/native/dist/profile-block.d.ts +42 -0
- package/native/dist/profile-block.js +28 -0
- package/native/dist/reward-block.d.ts +83 -0
- package/native/dist/reward-block.js +35 -0
- package/native/dist/setting-header.d.ts +8 -0
- package/native/dist/setting-header.js +11 -0
- package/native/dist/setting-switch.d.ts +18 -0
- package/native/dist/setting-switch.js +17 -0
- package/native/dist/signals-block.d.ts +37 -0
- package/native/dist/signals-block.js +16 -0
- package/native/dist/sound-haptics-block.d.ts +39 -0
- package/native/dist/sound-haptics-block.js +21 -0
- package/native/dist/{swap-panel.d.ts → swap-panel-block.d.ts} +28 -9
- package/native/dist/{swap-panel.js → swap-panel-block.js} +24 -14
- package/native/dist/swap-parts.d.ts +14 -3
- package/native/dist/swap-parts.js +16 -1
- package/native/dist/swap-shared.d.ts +18 -6
- package/native/dist/swap-shared.js +3 -2
- package/native/dist/swap-sheet.d.ts +4 -4
- package/native/dist/swap-sheet.js +4 -4
- package/native/dist/swap-views.d.ts +1 -1
- package/native/dist/swap-views.js +11 -8
- package/native/dist/target-block.d.ts +83 -0
- package/native/dist/target-block.js +61 -0
- package/native/dist/token-action-block.d.ts +39 -0
- package/native/dist/token-action-block.js +20 -0
- package/native/dist/trade-history-detail-block.d.ts +59 -0
- package/native/dist/trade-history-detail-block.js +38 -0
- package/native/dist/trade-history-list-block.d.ts +44 -0
- package/native/dist/trade-history-list-block.js +29 -0
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +246 -41
- package/react/README.md +1 -1
- package/react/dist/asset-balance-row.d.ts +19 -0
- package/react/dist/asset-balance-row.js +10 -0
- package/react/dist/bar-mark.d.ts +35 -0
- package/react/dist/bar-mark.js +21 -0
- package/react/dist/bar-pnl.d.ts +49 -0
- package/react/dist/bar-pnl.js +45 -0
- package/react/dist/blocks/account-block.d.ts +46 -0
- package/react/dist/blocks/account-block.js +27 -0
- package/react/dist/blocks/language-block.d.ts +32 -0
- package/react/dist/blocks/language-block.js +51 -0
- package/react/dist/blocks/manage-position-block.d.ts +67 -0
- package/react/dist/blocks/manage-position-block.js +28 -0
- package/react/dist/blocks/notifications-block.d.ts +23 -0
- package/react/dist/blocks/notifications-block.js +8 -0
- package/react/dist/{recipes → blocks}/pickers.d.ts +12 -4
- package/react/dist/{recipes → blocks}/pickers.js +9 -6
- package/react/dist/blocks/position-block.d.ts +49 -0
- package/react/dist/blocks/position-block.js +14 -0
- package/react/dist/blocks/profile-block.d.ts +48 -0
- package/react/dist/blocks/profile-block.js +15 -0
- package/react/dist/blocks/reward-block.d.ts +81 -0
- package/react/dist/blocks/reward-block.js +24 -0
- package/react/dist/blocks/screen-header.d.ts +9 -0
- package/react/dist/blocks/screen-header.js +12 -0
- package/react/dist/blocks/setting-switch.d.ts +10 -0
- package/react/dist/blocks/setting-switch.js +8 -0
- package/react/dist/blocks/signals-block.d.ts +35 -0
- package/react/dist/blocks/signals-block.js +15 -0
- package/react/dist/blocks/sound-haptics-block.d.ts +37 -0
- package/react/dist/blocks/sound-haptics-block.js +18 -0
- package/react/dist/{recipes → blocks}/swap/picker.d.ts +1 -1
- package/react/dist/{recipes → blocks}/swap/picker.js +4 -4
- package/react/dist/{recipes → blocks}/swap/settings.js +5 -7
- package/react/dist/{recipes → blocks}/swap/shared.d.ts +44 -6
- package/react/dist/{recipes → blocks}/swap/shared.js +25 -5
- package/react/dist/{recipes/swap-panel.d.ts → blocks/swap-panel-block.d.ts} +29 -9
- package/react/dist/{recipes/swap-panel.js → blocks/swap-panel-block.js} +22 -14
- package/react/dist/{recipes → blocks}/swap-sheet.d.ts +4 -4
- package/react/dist/{recipes → blocks}/swap-sheet.js +4 -4
- package/react/dist/blocks/target-block.d.ts +81 -0
- package/react/dist/blocks/target-block.js +65 -0
- package/react/dist/blocks/token-action-block.d.ts +37 -0
- package/react/dist/blocks/token-action-block.js +18 -0
- package/react/dist/{recipes → blocks}/trade-entry.js +2 -2
- package/react/dist/blocks/trade-history-detail-block.d.ts +58 -0
- package/react/dist/blocks/trade-history-detail-block.js +16 -0
- package/react/dist/blocks/trade-history-list-block.d.ts +43 -0
- package/react/dist/blocks/trade-history-list-block.js +21 -0
- package/react/dist/blocks.d.ts +20 -0
- package/react/dist/blocks.js +21 -0
- package/react/dist/field.d.ts +0 -2
- package/react/dist/field.js +0 -2
- package/react/dist/list-group.d.ts +26 -0
- package/react/dist/list-group.js +20 -0
- package/react/dist/styles.css +275 -8
- package/tokens/README.md +1 -1
- package/native/dist/recipes.d.ts +0 -45
- package/react/dist/recipes/activity-list.d.ts +0 -8
- package/react/dist/recipes/activity-list.js +0 -6
- package/react/dist/recipes/balance-card.d.ts +0 -6
- package/react/dist/recipes/balance-card.js +0 -5
- package/react/dist/recipes/code-window.d.ts +0 -4
- package/react/dist/recipes/code-window.js +0 -4
- package/react/dist/recipes.d.ts +0 -10
- package/react/dist/recipes.js +0 -11
- /package/react/dist/{recipes → blocks}/install-command.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/install-command.js +0 -0
- /package/react/dist/{recipes → blocks}/market-row.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/market-row.js +0 -0
- /package/react/dist/{recipes → blocks}/marketing-hero.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/marketing-hero.js +0 -0
- /package/react/dist/{recipes → blocks}/swap/amount-card.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/swap/amount-card.js +0 -0
- /package/react/dist/{recipes → blocks}/swap/settings.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/trade-entry.d.ts +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Image, Pressable, View } from 'react-native';
|
|
3
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
4
|
+
import { useColors, useFills, useHIG, useMessages } from './provider.js';
|
|
5
|
+
import { Text } from './surface.js';
|
|
6
|
+
import { IconButton } from './button.js';
|
|
7
|
+
import { ChevronIcon } from './icons.js';
|
|
8
|
+
import { AnimatedNumberReadout } from './animated-number.js';
|
|
9
|
+
const pnlFormat = { style: 'currency', currency: 'USD', signDisplay: 'exceptZero', minimumSignificantDigits: 4, maximumSignificantDigits: 4 };
|
|
10
|
+
/** How a row reads its side: `Short 20×`, or `Short` without leverage. */
|
|
11
|
+
export const tradeHistorySide = (trade, labels, locale) => `${trade.side === 'long' ? labels.long : labels.short}${trade.leverage != null ? ` ${formatNumber(trade.leverage, locale)}×` : ''}`;
|
|
12
|
+
const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
|
|
13
|
+
const avatar = 40;
|
|
14
|
+
/** Points up; a short turns it over. */
|
|
15
|
+
function Arrow({ color, down }) { return _jsxs(View, { style: { width: 12, height: 14, alignItems: 'center', transform: down ? [{ rotate: '180deg' }] : undefined }, children: [_jsx(View, { style: { position: 'absolute', top: 1, width: 7, height: 7, borderLeftWidth: 1.75, borderTopWidth: 1.75, borderColor: color, transform: [{ rotate: '45deg' }] } }), _jsx(View, { style: { width: 1.75, height: 14, borderRadius: 1, backgroundColor: color } })] }); }
|
|
16
|
+
/** A history of closed trades as one screen: a header, then one row per trade with the asset, its side and leverage in the direction colour, and the net result in the result colour over its age. */
|
|
17
|
+
export function TradeHistoryListBlock({ labels, trades, onSelect, onBack, headerAction, pnlOptions = pnlFormat, testID }) {
|
|
18
|
+
const colors = useColors(), fills = useFills(), t = useMessages(), { direction, locale } = useHIG();
|
|
19
|
+
const shape = { width: avatar, height: avatar, borderRadius: avatar / 2, backgroundColor: fills.raised, alignItems: 'center', justifyContent: 'center', overflow: 'hidden' };
|
|
20
|
+
const row = (pressed) => ({ flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 56, paddingVertical: 8, paddingStart: 8, paddingEnd: 16, borderRadius: 28, backgroundColor: pressed ? fills.raised : fills.well });
|
|
21
|
+
return _jsxs(View, { testID: testID, style: { direction, padding: 16, gap: 16 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', minHeight: 44 }, children: [_jsx(View, { style: { minWidth: 44, alignItems: 'flex-start' }, children: onBack ? _jsx(IconButton, { intent: 'ghost', label: t.back, suppressFeedback: true, testID: testID ? `${testID}-back` : undefined, onPress: onBack, children: _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '-90deg' : '90deg' }] }, children: _jsx(ChevronIcon, { color: colors.text }) }) }) : null }), _jsx(Text, { testID: testID ? `${testID}-title` : undefined, accessibilityRole: 'header', numberOfLines: 1, style: { flex: 1, textAlign: 'center', fontSize: 17, lineHeight: 24, fontWeight: '600', color: colors.text }, children: labels.title }), _jsx(View, { style: { minWidth: 44, alignItems: 'flex-end' }, children: headerAction })] }), trades.length === 0 ? _jsx(Text, { testID: testID ? `${testID}-empty` : undefined, style: { paddingVertical: 32, textAlign: 'center', fontSize: 14, lineHeight: 20, color: colors.muted }, children: labels.empty }) :
|
|
22
|
+
_jsx(View, { testID: testID ? `${testID}-rows` : undefined, style: { gap: 8 }, children: trades.map(trade => {
|
|
23
|
+
const side = colors[trade.side === 'long' ? 'positive' : 'negative'];
|
|
24
|
+
const reading = [trade.name, tradeHistorySide(trade, labels, locale), formatNumber(trade.pnl, locale, pnlOptions), trade.time].filter(Boolean).join(', ');
|
|
25
|
+
const content = _jsxs(_Fragment, { children: [_jsx(View, { ...hidden, children: typeof trade.icon === 'string' ? _jsx(Image, { accessible: false, accessibilityIgnoresInvertColors: true, source: { uri: trade.icon }, style: shape }) : _jsx(View, { style: shape, children: trade.icon ?? _jsx(Text, { accessible: false, maxFontSizeMultiplier: 1, style: { fontSize: 12, lineHeight: 16, fontWeight: '600', color: colors.muted }, children: trade.name.slice(0, 3) }) }) }), _jsxs(View, { ...hidden, style: { flex: 1, flexShrink: 1, minWidth: 0 }, children: [_jsx(Text, { numberOfLines: 1, style: { fontSize: 16, lineHeight: 24, fontWeight: '600', color: colors.text }, children: trade.name }), _jsxs(View, { testID: testID ? `${testID}-${trade.id}-side` : undefined, style: { flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [_jsx(Arrow, { color: side, down: trade.side === 'short' }), trade.leverage != null ? _jsx(Text, { style: { fontSize: 14, lineHeight: 20, fontWeight: '600', color: side }, children: `${formatNumber(trade.leverage, locale)}×` }) : null] })] }), _jsxs(View, { ...hidden, style: { alignItems: 'flex-end', justifyContent: 'center' }, children: [_jsx(AnimatedNumberReadout, { value: trade.pnl, options: pnlOptions, tone: trade.pnl == null || trade.pnl === 0 ? 'text' : trade.pnl > 0 ? 'positive' : 'negative', testID: testID ? `${testID}-${trade.id}-pnl` : undefined, style: { fontSize: 16, lineHeight: 24, fontWeight: '600' } }), trade.time ? _jsx(Text, { style: { fontSize: 14, lineHeight: 20, color: colors.muted }, children: trade.time }) : null] })] });
|
|
26
|
+
return onSelect ? _jsxs(Pressable, { testID: testID ? `${testID}-${trade.id}` : undefined, accessibilityRole: 'button', accessibilityLabel: reading, onPress: () => onSelect(trade), style: ({ pressed }) => row(pressed), children: [content, _jsx(View, { ...hidden, style: { transform: [{ rotate: direction === 'rtl' ? '90deg' : '-90deg' }] }, children: _jsx(ChevronIcon, { color: colors.muted }) })] }, trade.id)
|
|
27
|
+
: _jsx(View, { testID: testID ? `${testID}-${trade.id}` : undefined, accessible: true, accessibilityLabel: reading, style: row(false), children: content }, trade.id);
|
|
28
|
+
}) })] });
|
|
29
|
+
}
|
package/native-fonts/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @bloxwap/hig/native-fonts
|
|
2
2
|
|
|
3
|
-
Version 0.
|
|
3
|
+
Version 0.6.0, an entry of `@bloxwap/hig`. Static Bloxwap Sans/Mono (and Korean/Simplified Chinese Sans) TTF faces for React Native and Expo hosts, derived reproducibly from pinned `@bloxwap/font` 0.1.4 by `npm run generate:fonts`.
|
|
4
4
|
|
|
5
5
|
Web hosts never import this entry: load fonts through `@bloxwap/font` and use `@bloxwap/hig/tokens/css`. Open Graph card renderers (Satori, `next/og`) use the much smaller `@bloxwap/hig/og-fonts` entry instead (#99).
|
|
6
6
|
|
package/og-fonts/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @bloxwap/hig/og-fonts
|
|
2
2
|
|
|
3
|
-
Version 0.
|
|
3
|
+
Version 0.6.0, an entry of `@bloxwap/hig`. Five static Latin Bloxwap Sans/Mono TTF faces for Open Graph card renderers: Satori, `next/og` `ImageResponse` and `@vercel/og`. Satori reads TTF/OTF but not WOFF2, and `@bloxwap/font` ships only WOFF2.
|
|
4
4
|
|
|
5
5
|
| Face | File | Weight |
|
|
6
6
|
| --- | --- | --- |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloxwap/hig",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Bloxwap Human Interface Guidelines: tokens, contracts, React and React Native components, chart adapter, feedback and fonts in one package.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -155,60 +155,90 @@
|
|
|
155
155
|
"import": "./react/dist/brand.js",
|
|
156
156
|
"default": "./react/dist/brand.js"
|
|
157
157
|
},
|
|
158
|
+
"./react/blocks": {
|
|
159
|
+
"types": "./react/dist/blocks.d.ts",
|
|
160
|
+
"import": "./react/dist/blocks.js",
|
|
161
|
+
"default": "./react/dist/blocks.js"
|
|
162
|
+
},
|
|
158
163
|
"./react/recipes": {
|
|
159
|
-
"types": "./react/dist/
|
|
160
|
-
"import": "./react/dist/
|
|
161
|
-
"default": "./react/dist/
|
|
164
|
+
"types": "./react/dist/blocks.d.ts",
|
|
165
|
+
"import": "./react/dist/blocks.js",
|
|
166
|
+
"default": "./react/dist/blocks.js"
|
|
167
|
+
},
|
|
168
|
+
"./react/blocks/market-row": {
|
|
169
|
+
"types": "./react/dist/blocks/market-row.d.ts",
|
|
170
|
+
"import": "./react/dist/blocks/market-row.js",
|
|
171
|
+
"default": "./react/dist/blocks/market-row.js"
|
|
162
172
|
},
|
|
163
173
|
"./react/recipes/market-row": {
|
|
164
|
-
"types": "./react/dist/
|
|
165
|
-
"import": "./react/dist/
|
|
166
|
-
"default": "./react/dist/
|
|
174
|
+
"types": "./react/dist/blocks/market-row.d.ts",
|
|
175
|
+
"import": "./react/dist/blocks/market-row.js",
|
|
176
|
+
"default": "./react/dist/blocks/market-row.js"
|
|
167
177
|
},
|
|
168
|
-
"./react/
|
|
169
|
-
"types": "./react/dist/
|
|
170
|
-
"import": "./react/dist/
|
|
171
|
-
"default": "./react/dist/
|
|
178
|
+
"./react/blocks/trade-entry": {
|
|
179
|
+
"types": "./react/dist/blocks/trade-entry.d.ts",
|
|
180
|
+
"import": "./react/dist/blocks/trade-entry.js",
|
|
181
|
+
"default": "./react/dist/blocks/trade-entry.js"
|
|
172
182
|
},
|
|
173
183
|
"./react/recipes/trade-entry": {
|
|
174
|
-
"types": "./react/dist/
|
|
175
|
-
"import": "./react/dist/
|
|
176
|
-
"default": "./react/dist/
|
|
184
|
+
"types": "./react/dist/blocks/trade-entry.d.ts",
|
|
185
|
+
"import": "./react/dist/blocks/trade-entry.js",
|
|
186
|
+
"default": "./react/dist/blocks/trade-entry.js"
|
|
187
|
+
},
|
|
188
|
+
"./react/blocks/swap-panel-block": {
|
|
189
|
+
"types": "./react/dist/blocks/swap-panel-block.d.ts",
|
|
190
|
+
"import": "./react/dist/blocks/swap-panel-block.js",
|
|
191
|
+
"default": "./react/dist/blocks/swap-panel-block.js"
|
|
192
|
+
},
|
|
193
|
+
"./react/blocks/swap-panel": {
|
|
194
|
+
"types": "./react/dist/blocks/swap-panel-block.d.ts",
|
|
195
|
+
"import": "./react/dist/blocks/swap-panel-block.js",
|
|
196
|
+
"default": "./react/dist/blocks/swap-panel-block.js"
|
|
177
197
|
},
|
|
178
198
|
"./react/recipes/swap-panel": {
|
|
179
|
-
"types": "./react/dist/
|
|
180
|
-
"import": "./react/dist/
|
|
181
|
-
"default": "./react/dist/
|
|
199
|
+
"types": "./react/dist/blocks/swap-panel-block.d.ts",
|
|
200
|
+
"import": "./react/dist/blocks/swap-panel-block.js",
|
|
201
|
+
"default": "./react/dist/blocks/swap-panel-block.js"
|
|
202
|
+
},
|
|
203
|
+
"./react/blocks/pickers": {
|
|
204
|
+
"types": "./react/dist/blocks/pickers.d.ts",
|
|
205
|
+
"import": "./react/dist/blocks/pickers.js",
|
|
206
|
+
"default": "./react/dist/blocks/pickers.js"
|
|
182
207
|
},
|
|
183
208
|
"./react/recipes/pickers": {
|
|
184
|
-
"types": "./react/dist/
|
|
185
|
-
"import": "./react/dist/
|
|
186
|
-
"default": "./react/dist/
|
|
209
|
+
"types": "./react/dist/blocks/pickers.d.ts",
|
|
210
|
+
"import": "./react/dist/blocks/pickers.js",
|
|
211
|
+
"default": "./react/dist/blocks/pickers.js"
|
|
212
|
+
},
|
|
213
|
+
"./react/blocks/swap-sheet": {
|
|
214
|
+
"types": "./react/dist/blocks/swap-sheet.d.ts",
|
|
215
|
+
"import": "./react/dist/blocks/swap-sheet.js",
|
|
216
|
+
"default": "./react/dist/blocks/swap-sheet.js"
|
|
187
217
|
},
|
|
188
218
|
"./react/recipes/swap-sheet": {
|
|
189
|
-
"types": "./react/dist/
|
|
190
|
-
"import": "./react/dist/
|
|
191
|
-
"default": "./react/dist/
|
|
219
|
+
"types": "./react/dist/blocks/swap-sheet.d.ts",
|
|
220
|
+
"import": "./react/dist/blocks/swap-sheet.js",
|
|
221
|
+
"default": "./react/dist/blocks/swap-sheet.js"
|
|
222
|
+
},
|
|
223
|
+
"./react/blocks/install-command": {
|
|
224
|
+
"types": "./react/dist/blocks/install-command.d.ts",
|
|
225
|
+
"import": "./react/dist/blocks/install-command.js",
|
|
226
|
+
"default": "./react/dist/blocks/install-command.js"
|
|
192
227
|
},
|
|
193
228
|
"./react/recipes/install-command": {
|
|
194
|
-
"types": "./react/dist/
|
|
195
|
-
"import": "./react/dist/
|
|
196
|
-
"default": "./react/dist/
|
|
229
|
+
"types": "./react/dist/blocks/install-command.d.ts",
|
|
230
|
+
"import": "./react/dist/blocks/install-command.js",
|
|
231
|
+
"default": "./react/dist/blocks/install-command.js"
|
|
197
232
|
},
|
|
198
|
-
"./react/
|
|
199
|
-
"types": "./react/dist/
|
|
200
|
-
"import": "./react/dist/
|
|
201
|
-
"default": "./react/dist/
|
|
233
|
+
"./react/blocks/marketing-hero": {
|
|
234
|
+
"types": "./react/dist/blocks/marketing-hero.d.ts",
|
|
235
|
+
"import": "./react/dist/blocks/marketing-hero.js",
|
|
236
|
+
"default": "./react/dist/blocks/marketing-hero.js"
|
|
202
237
|
},
|
|
203
238
|
"./react/recipes/marketing-hero": {
|
|
204
|
-
"types": "./react/dist/
|
|
205
|
-
"import": "./react/dist/
|
|
206
|
-
"default": "./react/dist/
|
|
207
|
-
},
|
|
208
|
-
"./react/recipes/activity-list": {
|
|
209
|
-
"types": "./react/dist/recipes/activity-list.d.ts",
|
|
210
|
-
"import": "./react/dist/recipes/activity-list.js",
|
|
211
|
-
"default": "./react/dist/recipes/activity-list.js"
|
|
239
|
+
"types": "./react/dist/blocks/marketing-hero.d.ts",
|
|
240
|
+
"import": "./react/dist/blocks/marketing-hero.js",
|
|
241
|
+
"default": "./react/dist/blocks/marketing-hero.js"
|
|
212
242
|
},
|
|
213
243
|
"./react/css": {
|
|
214
244
|
"types": "./css.d.ts",
|
|
@@ -228,6 +258,91 @@
|
|
|
228
258
|
"import": "./react/dist/wallet-address.js",
|
|
229
259
|
"default": "./react/dist/wallet-address.js"
|
|
230
260
|
},
|
|
261
|
+
"./react/asset-balance-row": {
|
|
262
|
+
"types": "./react/dist/asset-balance-row.d.ts",
|
|
263
|
+
"import": "./react/dist/asset-balance-row.js",
|
|
264
|
+
"default": "./react/dist/asset-balance-row.js"
|
|
265
|
+
},
|
|
266
|
+
"./react/blocks/account-block": {
|
|
267
|
+
"types": "./react/dist/blocks/account-block.d.ts",
|
|
268
|
+
"import": "./react/dist/blocks/account-block.js",
|
|
269
|
+
"default": "./react/dist/blocks/account-block.js"
|
|
270
|
+
},
|
|
271
|
+
"./react/blocks/token-action-block": {
|
|
272
|
+
"types": "./react/dist/blocks/token-action-block.d.ts",
|
|
273
|
+
"import": "./react/dist/blocks/token-action-block.js",
|
|
274
|
+
"default": "./react/dist/blocks/token-action-block.js"
|
|
275
|
+
},
|
|
276
|
+
"./react/blocks/language-block": {
|
|
277
|
+
"types": "./react/dist/blocks/language-block.d.ts",
|
|
278
|
+
"import": "./react/dist/blocks/language-block.js",
|
|
279
|
+
"default": "./react/dist/blocks/language-block.js"
|
|
280
|
+
},
|
|
281
|
+
"./react/blocks/manage-position-block": {
|
|
282
|
+
"types": "./react/dist/blocks/manage-position-block.d.ts",
|
|
283
|
+
"import": "./react/dist/blocks/manage-position-block.js",
|
|
284
|
+
"default": "./react/dist/blocks/manage-position-block.js"
|
|
285
|
+
},
|
|
286
|
+
"./react/blocks/target-block": {
|
|
287
|
+
"types": "./react/dist/blocks/target-block.d.ts",
|
|
288
|
+
"import": "./react/dist/blocks/target-block.js",
|
|
289
|
+
"default": "./react/dist/blocks/target-block.js"
|
|
290
|
+
},
|
|
291
|
+
"./react/blocks/position-block": {
|
|
292
|
+
"types": "./react/dist/blocks/position-block.d.ts",
|
|
293
|
+
"import": "./react/dist/blocks/position-block.js",
|
|
294
|
+
"default": "./react/dist/blocks/position-block.js"
|
|
295
|
+
},
|
|
296
|
+
"./react/blocks/reward-block": {
|
|
297
|
+
"types": "./react/dist/blocks/reward-block.d.ts",
|
|
298
|
+
"import": "./react/dist/blocks/reward-block.js",
|
|
299
|
+
"default": "./react/dist/blocks/reward-block.js"
|
|
300
|
+
},
|
|
301
|
+
"./react/blocks/sound-haptics-block": {
|
|
302
|
+
"types": "./react/dist/blocks/sound-haptics-block.d.ts",
|
|
303
|
+
"import": "./react/dist/blocks/sound-haptics-block.js",
|
|
304
|
+
"default": "./react/dist/blocks/sound-haptics-block.js"
|
|
305
|
+
},
|
|
306
|
+
"./react/blocks/signals-block": {
|
|
307
|
+
"types": "./react/dist/blocks/signals-block.d.ts",
|
|
308
|
+
"import": "./react/dist/blocks/signals-block.js",
|
|
309
|
+
"default": "./react/dist/blocks/signals-block.js"
|
|
310
|
+
},
|
|
311
|
+
"./react/blocks/notifications-block": {
|
|
312
|
+
"types": "./react/dist/blocks/notifications-block.d.ts",
|
|
313
|
+
"import": "./react/dist/blocks/notifications-block.js",
|
|
314
|
+
"default": "./react/dist/blocks/notifications-block.js"
|
|
315
|
+
},
|
|
316
|
+
"./react/blocks/trade-history-list-block": {
|
|
317
|
+
"types": "./react/dist/blocks/trade-history-list-block.d.ts",
|
|
318
|
+
"import": "./react/dist/blocks/trade-history-list-block.js",
|
|
319
|
+
"default": "./react/dist/blocks/trade-history-list-block.js"
|
|
320
|
+
},
|
|
321
|
+
"./react/blocks/trade-history-detail-block": {
|
|
322
|
+
"types": "./react/dist/blocks/trade-history-detail-block.d.ts",
|
|
323
|
+
"import": "./react/dist/blocks/trade-history-detail-block.js",
|
|
324
|
+
"default": "./react/dist/blocks/trade-history-detail-block.js"
|
|
325
|
+
},
|
|
326
|
+
"./react/blocks/profile-block": {
|
|
327
|
+
"types": "./react/dist/blocks/profile-block.d.ts",
|
|
328
|
+
"import": "./react/dist/blocks/profile-block.js",
|
|
329
|
+
"default": "./react/dist/blocks/profile-block.js"
|
|
330
|
+
},
|
|
331
|
+
"./react/bar-mark": {
|
|
332
|
+
"types": "./react/dist/bar-mark.d.ts",
|
|
333
|
+
"import": "./react/dist/bar-mark.js",
|
|
334
|
+
"default": "./react/dist/bar-mark.js"
|
|
335
|
+
},
|
|
336
|
+
"./react/bar-pnl": {
|
|
337
|
+
"types": "./react/dist/bar-pnl.d.ts",
|
|
338
|
+
"import": "./react/dist/bar-pnl.js",
|
|
339
|
+
"default": "./react/dist/bar-pnl.js"
|
|
340
|
+
},
|
|
341
|
+
"./react/list-group": {
|
|
342
|
+
"types": "./react/dist/list-group.d.ts",
|
|
343
|
+
"import": "./react/dist/list-group.js",
|
|
344
|
+
"default": "./react/dist/list-group.js"
|
|
345
|
+
},
|
|
231
346
|
"./react/gesture-sheet": {
|
|
232
347
|
"types": "./react/dist/gesture-sheet.d.ts",
|
|
233
348
|
"import": "./react/dist/gesture-sheet.js",
|
|
@@ -243,6 +358,91 @@
|
|
|
243
358
|
"import": "./native/dist/wallet-address.js",
|
|
244
359
|
"default": "./native/dist/wallet-address.js"
|
|
245
360
|
},
|
|
361
|
+
"./native/asset-balance-row": {
|
|
362
|
+
"types": "./native/dist/asset-balance-row.d.ts",
|
|
363
|
+
"import": "./native/dist/asset-balance-row.js",
|
|
364
|
+
"default": "./native/dist/asset-balance-row.js"
|
|
365
|
+
},
|
|
366
|
+
"./native/account-block": {
|
|
367
|
+
"types": "./native/dist/account-block.d.ts",
|
|
368
|
+
"import": "./native/dist/account-block.js",
|
|
369
|
+
"default": "./native/dist/account-block.js"
|
|
370
|
+
},
|
|
371
|
+
"./native/token-action-block": {
|
|
372
|
+
"types": "./native/dist/token-action-block.d.ts",
|
|
373
|
+
"import": "./native/dist/token-action-block.js",
|
|
374
|
+
"default": "./native/dist/token-action-block.js"
|
|
375
|
+
},
|
|
376
|
+
"./native/language-block": {
|
|
377
|
+
"types": "./native/dist/language-block.d.ts",
|
|
378
|
+
"import": "./native/dist/language-block.js",
|
|
379
|
+
"default": "./native/dist/language-block.js"
|
|
380
|
+
},
|
|
381
|
+
"./native/manage-position-block": {
|
|
382
|
+
"types": "./native/dist/manage-position-block.d.ts",
|
|
383
|
+
"import": "./native/dist/manage-position-block.js",
|
|
384
|
+
"default": "./native/dist/manage-position-block.js"
|
|
385
|
+
},
|
|
386
|
+
"./native/target-block": {
|
|
387
|
+
"types": "./native/dist/target-block.d.ts",
|
|
388
|
+
"import": "./native/dist/target-block.js",
|
|
389
|
+
"default": "./native/dist/target-block.js"
|
|
390
|
+
},
|
|
391
|
+
"./native/position-block": {
|
|
392
|
+
"types": "./native/dist/position-block.d.ts",
|
|
393
|
+
"import": "./native/dist/position-block.js",
|
|
394
|
+
"default": "./native/dist/position-block.js"
|
|
395
|
+
},
|
|
396
|
+
"./native/reward-block": {
|
|
397
|
+
"types": "./native/dist/reward-block.d.ts",
|
|
398
|
+
"import": "./native/dist/reward-block.js",
|
|
399
|
+
"default": "./native/dist/reward-block.js"
|
|
400
|
+
},
|
|
401
|
+
"./native/sound-haptics-block": {
|
|
402
|
+
"types": "./native/dist/sound-haptics-block.d.ts",
|
|
403
|
+
"import": "./native/dist/sound-haptics-block.js",
|
|
404
|
+
"default": "./native/dist/sound-haptics-block.js"
|
|
405
|
+
},
|
|
406
|
+
"./native/signals-block": {
|
|
407
|
+
"types": "./native/dist/signals-block.d.ts",
|
|
408
|
+
"import": "./native/dist/signals-block.js",
|
|
409
|
+
"default": "./native/dist/signals-block.js"
|
|
410
|
+
},
|
|
411
|
+
"./native/notifications-block": {
|
|
412
|
+
"types": "./native/dist/notifications-block.d.ts",
|
|
413
|
+
"import": "./native/dist/notifications-block.js",
|
|
414
|
+
"default": "./native/dist/notifications-block.js"
|
|
415
|
+
},
|
|
416
|
+
"./native/trade-history-list-block": {
|
|
417
|
+
"types": "./native/dist/trade-history-list-block.d.ts",
|
|
418
|
+
"import": "./native/dist/trade-history-list-block.js",
|
|
419
|
+
"default": "./native/dist/trade-history-list-block.js"
|
|
420
|
+
},
|
|
421
|
+
"./native/trade-history-detail-block": {
|
|
422
|
+
"types": "./native/dist/trade-history-detail-block.d.ts",
|
|
423
|
+
"import": "./native/dist/trade-history-detail-block.js",
|
|
424
|
+
"default": "./native/dist/trade-history-detail-block.js"
|
|
425
|
+
},
|
|
426
|
+
"./native/profile-block": {
|
|
427
|
+
"types": "./native/dist/profile-block.d.ts",
|
|
428
|
+
"import": "./native/dist/profile-block.js",
|
|
429
|
+
"default": "./native/dist/profile-block.js"
|
|
430
|
+
},
|
|
431
|
+
"./native/bar-mark": {
|
|
432
|
+
"types": "./native/dist/bar-mark.d.ts",
|
|
433
|
+
"import": "./native/dist/bar-mark.js",
|
|
434
|
+
"default": "./native/dist/bar-mark.js"
|
|
435
|
+
},
|
|
436
|
+
"./native/bar-pnl": {
|
|
437
|
+
"types": "./native/dist/bar-pnl.d.ts",
|
|
438
|
+
"import": "./native/dist/bar-pnl.js",
|
|
439
|
+
"default": "./native/dist/bar-pnl.js"
|
|
440
|
+
},
|
|
441
|
+
"./native/list-group": {
|
|
442
|
+
"types": "./native/dist/list-group.d.ts",
|
|
443
|
+
"import": "./native/dist/list-group.js",
|
|
444
|
+
"default": "./native/dist/list-group.js"
|
|
445
|
+
},
|
|
246
446
|
"./native/pickers": {
|
|
247
447
|
"types": "./native/dist/pickers.d.ts",
|
|
248
448
|
"import": "./native/dist/pickers.js",
|
|
@@ -303,10 +503,15 @@
|
|
|
303
503
|
"import": "./native/dist/brand.js",
|
|
304
504
|
"default": "./native/dist/brand.js"
|
|
305
505
|
},
|
|
506
|
+
"./native/blocks": {
|
|
507
|
+
"types": "./native/dist/blocks.d.ts",
|
|
508
|
+
"import": "./native/dist/blocks.js",
|
|
509
|
+
"default": "./native/dist/blocks.js"
|
|
510
|
+
},
|
|
306
511
|
"./native/recipes": {
|
|
307
|
-
"types": "./native/dist/
|
|
308
|
-
"import": "./native/dist/
|
|
309
|
-
"default": "./native/dist/
|
|
512
|
+
"types": "./native/dist/blocks.d.ts",
|
|
513
|
+
"import": "./native/dist/blocks.js",
|
|
514
|
+
"default": "./native/dist/blocks.js"
|
|
310
515
|
},
|
|
311
516
|
"./native/switch": {
|
|
312
517
|
"types": "./native/dist/switch.d.ts",
|
package/react/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @bloxwap/hig/react
|
|
2
2
|
|
|
3
|
-
Version 0.
|
|
3
|
+
Version 0.6.0, an entry of `@bloxwap/hig`. Import individual entries; see docs/components for platform and accessibility contracts.
|
|
4
4
|
|
|
5
5
|
Set a brand accent with `<HIGProvider primaryColor='#ff0000'>` from
|
|
6
6
|
`@bloxwap/hig/react/provider`. It accepts opaque sRGB hex (`#RGB` or `#RRGGBB`),
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** Artwork for an asset: an image URL, or an element the host draws. */
|
|
3
|
+
export type AssetArtwork = string | React.ReactElement;
|
|
4
|
+
export interface AssetBalanceRowProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onSelect'> {
|
|
5
|
+
name: string;
|
|
6
|
+
symbol: string;
|
|
7
|
+
/** A missing icon falls back to the first letters of the symbol. */
|
|
8
|
+
icon?: AssetArtwork;
|
|
9
|
+
/** Dollar value of the holding. `null` reads as unknown. */
|
|
10
|
+
value?: number | null;
|
|
11
|
+
/** The holding in token units, shown under the value. Omit it to show the value alone, as for a dollar stablecoin. */
|
|
12
|
+
balance?: number | null;
|
|
13
|
+
/** Format of the units line. Defaults to at most six fraction digits. */
|
|
14
|
+
balanceOptions?: Intl.NumberFormatOptions;
|
|
15
|
+
/** Makes the whole row a button. */
|
|
16
|
+
onSelect?: () => void;
|
|
17
|
+
}
|
|
18
|
+
/** One holding in a list: round artwork, the asset's name over its symbol, and its dollar value over its units. Both numbers update place by place. */
|
|
19
|
+
export declare function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions, onSelect, className, ...rest }: AssetBalanceRowProps): React.JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { AnimatedNumberReadout } from './animated-number.js';
|
|
4
|
+
const usd = { style: 'currency', currency: 'USD' }, units = { maximumFractionDigits: 6 };
|
|
5
|
+
/** One holding in a list: round artwork, the asset's name over its symbol, and its dollar value over its units. Both numbers update place by place. */
|
|
6
|
+
export function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions = units, onSelect, className, ...rest }) {
|
|
7
|
+
const content = _jsxs(_Fragment, { children: [_jsx("span", { className: 'hig-asset-row-icon', "aria-hidden": 'true', children: typeof icon === 'string' ? _jsx("img", { src: icon, alt: '' }) : icon ?? symbol.slice(0, 3) }), _jsxs("span", { className: 'hig-asset-row-identity', children: [_jsx("strong", { children: name }), _jsx("span", { children: symbol })] }), _jsxs("span", { className: 'hig-asset-row-amounts', children: [_jsx("strong", { children: _jsx(AnimatedNumberReadout, { value: value, options: usd }) }), balance !== undefined && _jsx("span", { children: _jsx(AnimatedNumberReadout, { value: balance, options: balanceOptions }) })] })] });
|
|
8
|
+
const classes = `hig-asset-row${className ? ` ${className}` : ''}`;
|
|
9
|
+
return onSelect ? _jsx("button", { type: 'button', ...rest, className: classes, onClick: onSelect, children: content }) : _jsx("div", { ...rest, className: classes, children: content });
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** Colour roles a segment can take. They follow the token palette (and a host's market colours) like any other role. */
|
|
3
|
+
export type BarMarkTone = 'positive' | 'info' | 'warning' | 'negative' | 'muted' | 'faint';
|
|
4
|
+
/** The order segments take tones in when they name neither a `tone` nor a `color`. */
|
|
5
|
+
export declare const barMarkTones: readonly BarMarkTone[];
|
|
6
|
+
/** One part of the bar. `value` is in the host's own unit; only its share of the whole is drawn. `detail` is host-formatted text shown after the label, such as `12.4 GB`. `color` is a host hex for a category outside the tone roles. */
|
|
7
|
+
export interface BarMarkElement {
|
|
8
|
+
id?: string;
|
|
9
|
+
label: string;
|
|
10
|
+
value: number;
|
|
11
|
+
tone?: BarMarkTone;
|
|
12
|
+
color?: string;
|
|
13
|
+
detail?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface BarMarkProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
16
|
+
title: string;
|
|
17
|
+
/** A line on the trailing edge of the title row, such as `59.2 GB of 64 GB used`. */
|
|
18
|
+
description?: React.ReactNode;
|
|
19
|
+
elements: readonly BarMarkElement[];
|
|
20
|
+
/** The whole the elements are parts of. When it is larger than their sum the remainder stays empty track. Defaults to the sum. */
|
|
21
|
+
total?: number;
|
|
22
|
+
/** Set false to hide the legend; the labels and shares stay available to assistive technology. */
|
|
23
|
+
legend?: boolean;
|
|
24
|
+
/** `small` draws a 12-unit bar for a secondary breakdown under a main one. */
|
|
25
|
+
size?: 'default' | 'small';
|
|
26
|
+
/** Set false to draw no card: no surface fill, padding or radius. The title row, bar and legend keep their spacing. Default `true`. */
|
|
27
|
+
surface?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Shares of the whole for each element, and the empty remainder, as fractions of 1. Negative and non-finite values count as nothing. */
|
|
30
|
+
export declare function barMarkShares(elements: readonly BarMarkElement[], total?: number): {
|
|
31
|
+
shares: number[];
|
|
32
|
+
rest: number;
|
|
33
|
+
};
|
|
34
|
+
/** A one-dimensional stacked bar: a titled card whose single bar is divided among its elements, with a legend naming each part. */
|
|
35
|
+
export declare function BarMark({ title, description, elements, total, legend, size, surface, className, ...rest }: BarMarkProps): React.JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId } from 'react';
|
|
4
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
+
import { useHIG } from './provider.js';
|
|
6
|
+
/** The order segments take tones in when they name neither a `tone` nor a `color`. */
|
|
7
|
+
export const barMarkTones = ['positive', 'info', 'warning', 'negative', 'muted', 'faint'];
|
|
8
|
+
const amount = (value) => Number.isFinite(value) && value > 0 ? value : 0;
|
|
9
|
+
/** Shares of the whole for each element, and the empty remainder, as fractions of 1. Negative and non-finite values count as nothing. */
|
|
10
|
+
export function barMarkShares(elements, total) {
|
|
11
|
+
const values = elements.map(element => amount(element.value)), sum = values.reduce((a, b) => a + b, 0), whole = Math.max(amount(total ?? 0), sum);
|
|
12
|
+
return whole > 0 ? { shares: values.map(value => value / whole), rest: (whole - sum) / whole } : { shares: values.map(() => 0), rest: 1 };
|
|
13
|
+
}
|
|
14
|
+
/** A one-dimensional stacked bar: a titled card whose single bar is divided among its elements, with a legend naming each part. */
|
|
15
|
+
export function BarMark({ title, description, elements, total, legend = true, size = 'default', surface = true, className, ...rest }) {
|
|
16
|
+
const { locale } = useHIG();
|
|
17
|
+
const id = useId();
|
|
18
|
+
const { shares, rest: remainder } = barMarkShares(elements, total);
|
|
19
|
+
const paint = (element, index) => element.color ? { style: { '--hig-bar-mark-color': element.color } } : { 'data-tone': element.tone ?? barMarkTones[index % barMarkTones.length] };
|
|
20
|
+
return _jsxs("section", { ...rest, className: `${surface ? 'hig-surface ' : ''}hig-bar-mark${className ? ` ${className}` : ''}`, "data-surface": surface ? undefined : 'false', "data-size": size === 'small' ? size : undefined, "aria-labelledby": id, children: [_jsxs("div", { className: 'hig-bar-mark-header', children: [_jsx("strong", { id: id, className: 'hig-bar-mark-title', children: title }), description != null && _jsx("span", { className: 'hig-bar-mark-description', children: description })] }), _jsxs("div", { className: 'hig-bar-mark-bar', "aria-hidden": 'true', children: [elements.map((element, index) => shares[index] > 0 && _jsx("span", { className: 'hig-bar-mark-segment', ...paint(element, index), style: { ...paint(element, index).style, flexGrow: shares[index] } }, element.id ?? index)), remainder > 0 && _jsx("span", { className: 'hig-bar-mark-rest', style: { flexGrow: remainder } })] }), _jsx("ul", { className: legend ? 'hig-bar-mark-legend' : 'hig-sr-only', children: elements.map((element, index) => _jsxs("li", { children: [_jsx("span", { className: 'hig-bar-mark-dot', "aria-hidden": 'true', ...paint(element, index) }), _jsx("span", { children: element.label }), element.detail && _jsx("span", { className: 'hig-bar-mark-detail', children: element.detail }), _jsx("span", { className: 'hig-sr-only', children: formatNumber(shares[index], locale, { style: 'percent', maximumFractionDigits: 1 }) })] }, element.id ?? index)) })] });
|
|
21
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type BarPnlSide = 'long' | 'short';
|
|
3
|
+
export type BarPnlResult = 'profit' | 'loss' | 'flat';
|
|
4
|
+
export type BarPnlKind = 'liquidation' | 'mark' | 'entry';
|
|
5
|
+
export interface BarPnlProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
|
|
6
|
+
/** Price the position was opened at. */
|
|
7
|
+
entry: number;
|
|
8
|
+
/** Current mark price. `null` or omitted reads as unknown and draws no profit or loss. */
|
|
9
|
+
mark?: number | null;
|
|
10
|
+
/** Liquidation price. Omit it, or pass `null`, for a position that cannot be liquidated. */
|
|
11
|
+
liquidation?: number | null;
|
|
12
|
+
/** Direction of the position. Defaults to `long` when the liquidation price is below entry (or unknown) and `short` when it is above. */
|
|
13
|
+
side?: BarPnlSide;
|
|
14
|
+
/** Host text for the three prices, for example `{liquidation:'Liquidation',mark:'Mark',entry:'Entry'}`. HIG ships no trading terms of its own. */
|
|
15
|
+
labels: Record<BarPnlKind, string>;
|
|
16
|
+
/** Heading on the leading edge above the bar, such as `BTC Long 10×`. */
|
|
17
|
+
title?: string;
|
|
18
|
+
/** A line on the trailing edge of the title row, such as the profit or loss in dollars. */
|
|
19
|
+
description?: React.ReactNode;
|
|
20
|
+
/** Format of the three prices. Defaults to US dollars. */
|
|
21
|
+
priceOptions?: Intl.NumberFormatOptions;
|
|
22
|
+
/** Shortens the three prices for narrow screens: `$64,700` for `$64,700.00`, `$142.96`, `$0.4821`. Trailing zeros are dropped. Default `false`. */
|
|
23
|
+
compact?: boolean;
|
|
24
|
+
/** Scales the bar to the prices themselves, so the stretch from entry to mark fills it. For a finished trade, where the move is the whole story. Default `false`. */
|
|
25
|
+
fit?: boolean;
|
|
26
|
+
/** Set false to draw no card: no surface fill, padding or radius. The title row, bar and readouts keep their spacing. Default `true`. */
|
|
27
|
+
surface?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Price format for `compact`: no fraction at 1,000 and above, at most two fraction digits from 1, and four significant digits below 1, with trailing zeros dropped. Host `priceOptions` (such as the currency) are kept. */
|
|
30
|
+
export declare function barPnlCompactOptions(value: number | null | undefined, base?: Intl.NumberFormatOptions): Intl.NumberFormatOptions;
|
|
31
|
+
/**
|
|
32
|
+
* Where each price sits on the bar, as a fraction of its width from the low-price edge, the readouts in price order, and
|
|
33
|
+
* whether the position is in profit. With a liquidation price the bar runs from it to the same distance on the other side
|
|
34
|
+
* of entry, so entry sits in the middle; a mark beyond either end stretches the bar. Without one the bar is centred on entry.
|
|
35
|
+
*/
|
|
36
|
+
export declare function barPnlLayout({ entry, mark, liquidation, side, fit }: {
|
|
37
|
+
entry: number;
|
|
38
|
+
mark?: number | null;
|
|
39
|
+
liquidation?: number | null;
|
|
40
|
+
side?: BarPnlSide;
|
|
41
|
+
fit?: boolean;
|
|
42
|
+
}): {
|
|
43
|
+
side: BarPnlSide;
|
|
44
|
+
result: BarPnlResult;
|
|
45
|
+
positions: Partial<Record<BarPnlKind, number>>;
|
|
46
|
+
order: BarPnlKind[];
|
|
47
|
+
};
|
|
48
|
+
/** A position's profit or loss as one bar: the stretch between entry and mark is filled solid in the result colour, a tick marks each price, and the liquidation, mark and entry prices read under the bar in price order, so mark and entry trade places as the position moves. */
|
|
49
|
+
export declare function BarPnl({ entry, mark, liquidation, side, labels, title, description, priceOptions, compact, fit, surface, className, ...rest }: BarPnlProps): React.JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId } from 'react';
|
|
4
|
+
import { AnimatedNumberReadout } from './animated-number.js';
|
|
5
|
+
const usd = { style: 'currency', currency: 'USD' };
|
|
6
|
+
const finite = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
7
|
+
/** Price format for `compact`: no fraction at 1,000 and above, at most two fraction digits from 1, and four significant digits below 1, with trailing zeros dropped. Host `priceOptions` (such as the currency) are kept. */
|
|
8
|
+
export function barPnlCompactOptions(value, base = usd) {
|
|
9
|
+
const size = finite(value) ? Math.abs(value) : 0;
|
|
10
|
+
return size > 0 && size < 1 ? { ...base, minimumFractionDigits: undefined, maximumFractionDigits: undefined, maximumSignificantDigits: 4 } : { ...base, minimumFractionDigits: 0, maximumFractionDigits: size >= 1000 ? 0 : 2 };
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Where each price sits on the bar, as a fraction of its width from the low-price edge, the readouts in price order, and
|
|
14
|
+
* whether the position is in profit. With a liquidation price the bar runs from it to the same distance on the other side
|
|
15
|
+
* of entry, so entry sits in the middle; a mark beyond either end stretches the bar. Without one the bar is centred on entry.
|
|
16
|
+
*/
|
|
17
|
+
export function barPnlLayout({ entry, mark, liquidation, side, fit }) {
|
|
18
|
+
const liq = finite(liquidation) ? liquidation : null;
|
|
19
|
+
const direction = side ?? (liq !== null && liq > entry ? 'short' : 'long');
|
|
20
|
+
const result = !finite(entry) || !finite(mark) || mark === entry ? 'flat' : (mark > entry) === (direction === 'long') ? 'profit' : 'loss';
|
|
21
|
+
if (!finite(entry))
|
|
22
|
+
return { side: direction, result, positions: {}, order: [] };
|
|
23
|
+
const price = finite(mark) ? mark : entry;
|
|
24
|
+
const reach = liq !== null ? Math.abs(entry - liq) : Math.max(Math.abs(price - entry) * 2, Math.abs(entry) * 0.01, Number.MIN_VALUE);
|
|
25
|
+
// `fit` scales the bar to the prices themselves, so the stretch from entry to mark fills it.
|
|
26
|
+
const points = liq !== null ? [entry, price, liq] : [entry, price];
|
|
27
|
+
const low = fit ? Math.min(...points) : Math.min(entry - reach, price), high = fit ? Math.max(...points) : Math.max(entry + reach, price), span = high - low;
|
|
28
|
+
const at = (value) => span > 0 ? Math.min(1, Math.max(0, (value - low) / span)) : 0.5;
|
|
29
|
+
const positions = { entry: at(entry), mark: at(price) };
|
|
30
|
+
if (liq !== null)
|
|
31
|
+
positions.liquidation = at(liq);
|
|
32
|
+
// Ties keep liquidation outermost and put mark on the side it would move to next.
|
|
33
|
+
const rank = { liquidation: direction === 'long' ? 0 : 2, entry: 1, mark: direction === 'long' ? (result === 'loss' ? 0.5 : 1.5) : (result === 'loss' ? 1.5 : 0.5) };
|
|
34
|
+
const values = { liquidation: liq ?? 0, entry, mark: price };
|
|
35
|
+
const order = Object.keys(positions).sort((a, b) => values[a] - values[b] || rank[a] - rank[b]);
|
|
36
|
+
return { side: direction, result, positions, order };
|
|
37
|
+
}
|
|
38
|
+
/** A position's profit or loss as one bar: the stretch between entry and mark is filled solid in the result colour, a tick marks each price, and the liquidation, mark and entry prices read under the bar in price order, so mark and entry trade places as the position moves. */
|
|
39
|
+
export function BarPnl({ entry, mark, liquidation, side, labels, title, description, priceOptions = usd, compact = false, fit = false, surface = true, className, ...rest }) {
|
|
40
|
+
const id = useId();
|
|
41
|
+
const { result, positions, order } = barPnlLayout({ entry, mark, liquidation, side, fit });
|
|
42
|
+
const from = Math.min(positions.entry ?? 0.5, positions.mark ?? 0.5), to = Math.max(positions.entry ?? 0.5, positions.mark ?? 0.5);
|
|
43
|
+
const values = { liquidation, mark, entry };
|
|
44
|
+
return _jsxs("section", { ...rest, className: `${surface ? 'hig-surface ' : ''}hig-bar-pnl${className ? ` ${className}` : ''}`, "data-surface": surface ? undefined : 'false', "data-result": result, "aria-labelledby": title ? id : undefined, children: [(title || description != null) && _jsxs("div", { className: 'hig-bar-mark-header', children: [title && _jsx("strong", { id: id, className: 'hig-bar-mark-title', children: title }), description != null && _jsx("span", { className: 'hig-bar-mark-description', children: description })] }), _jsxs("div", { className: 'hig-bar-pnl-bar', "aria-hidden": 'true', children: [_jsx("span", { className: 'hig-bar-pnl-rest', style: { flexGrow: from } }), _jsx("span", { className: 'hig-bar-pnl-move', "data-lead": (positions.mark ?? 0) < (positions.entry ?? 0) ? 'mark' : 'entry', style: { flexGrow: to - from } }), _jsx("span", { className: 'hig-bar-pnl-rest', style: { flexGrow: 1 - to } }), positions.liquidation !== undefined && _jsx("span", { className: 'hig-bar-pnl-liquidation', style: { insetInlineStart: `${positions.liquidation * 100}%` } })] }), _jsx("dl", { className: 'hig-bar-pnl-readouts', children: order.map(kind => _jsxs("div", { "data-kind": kind, children: [_jsx("dt", { children: labels[kind] }), _jsx("dd", { children: _jsx(AnimatedNumberReadout, { value: values[kind], options: compact ? barPnlCompactOptions(values[kind], priceOptions) : priceOptions }) })] }, kind)) })] });
|
|
45
|
+
}
|