@bloxwap/hig 0.0.0-stage → 0.2.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 +5 -0
- package/README.md +44 -2
- package/chart/README.md +23 -0
- package/chart/dist/index.d.ts +8 -0
- package/chart/dist/index.js +12 -0
- package/contracts/README.md +3 -0
- package/contracts/dist/announcements.d.ts +12 -0
- package/contracts/dist/announcements.js +8 -0
- package/contracts/dist/feedback.d.ts +40 -0
- package/contracts/dist/feedback.js +1 -0
- package/contracts/dist/index.d.ts +41 -0
- package/contracts/dist/index.js +52 -0
- package/contracts/dist/messages.d.ts +162 -0
- package/contracts/dist/messages.js +68 -0
- package/feedback/README.md +7 -0
- package/feedback/assets/error.wav +0 -0
- package/feedback/assets/manifest.json +68 -0
- package/feedback/assets/success.wav +0 -0
- package/feedback/assets/tick.wav +0 -0
- package/feedback/assets/toggle.wav +0 -0
- package/feedback/dist/browser-haptic.d.ts +23 -0
- package/feedback/dist/browser-haptic.js +41 -0
- package/feedback/dist/contract.d.ts +96 -0
- package/feedback/dist/contract.js +58 -0
- package/feedback/dist/native.d.ts +27 -0
- package/feedback/dist/native.js +63 -0
- package/feedback/dist/preferences.d.ts +8 -0
- package/feedback/dist/preferences.js +24 -0
- package/feedback/dist/react.d.ts +19 -0
- package/feedback/dist/react.js +23 -0
- package/feedback/dist/web-haptic.d.ts +6 -0
- package/feedback/dist/web-haptic.js +6 -0
- package/feedback/dist/web-sound.d.ts +5 -0
- package/feedback/dist/web-sound.js +32 -0
- package/feedback/dist/web.d.ts +3 -0
- package/feedback/dist/web.js +4 -0
- package/native/README.md +11 -0
- package/native/android/build.gradle +28 -0
- package/native/android/src/main/java/com/bloxwap/hig/HIGAdjustableView.java +173 -0
- package/native/android/src/main/java/com/bloxwap/hig/HIGAdjustableViewManager.java +23 -0
- package/native/android/src/main/java/com/bloxwap/hig/HIGPackage.java +24 -0
- package/native/dist/animated-number-model.d.ts +24 -0
- package/native/dist/animated-number-model.js +110 -0
- package/native/dist/animated-number.d.ts +9 -0
- package/native/dist/animated-number.js +93 -0
- package/native/dist/brand.d.ts +7 -0
- package/native/dist/brand.js +6 -0
- package/native/dist/button.d.ts +29 -0
- package/native/dist/button.js +34 -0
- package/native/dist/checkbox.d.ts +3 -0
- package/native/dist/checkbox.js +11 -0
- package/native/dist/data.d.ts +40 -0
- package/native/dist/data.js +27 -0
- package/native/dist/field.d.ts +15 -0
- package/native/dist/field.js +13 -0
- package/native/dist/gesture-sheet.d.ts +73 -0
- package/native/dist/gesture-sheet.js +151 -0
- package/native/dist/navigation.d.ts +47 -0
- package/native/dist/navigation.js +16 -0
- package/native/dist/overlay.d.ts +36 -0
- package/native/dist/overlay.js +65 -0
- package/native/dist/provider.d.ts +43 -0
- package/native/dist/provider.js +52 -0
- package/native/dist/radio-group.d.ts +5 -0
- package/native/dist/radio-group.js +53 -0
- package/native/dist/recipes.d.ts +42 -0
- package/native/dist/recipes.js +19 -0
- package/native/dist/roles.d.ts +6 -0
- package/native/dist/roles.js +4 -0
- package/native/dist/select.d.ts +3 -0
- package/native/dist/select.js +9 -0
- package/native/dist/selection-types.d.ts +22 -0
- package/native/dist/selection-types.js +1 -0
- package/native/dist/selection.d.ts +7 -0
- package/native/dist/selection.js +6 -0
- package/native/dist/slider.d.ts +11 -0
- package/native/dist/slider.js +41 -0
- package/native/dist/status.d.ts +75 -0
- package/native/dist/status.js +72 -0
- package/native/dist/surface.d.ts +18 -0
- package/native/dist/surface.js +41 -0
- package/native/dist/switch-row.d.ts +8 -0
- package/native/dist/switch-row.js +18 -0
- package/native/dist/switch.d.ts +10 -0
- package/native/dist/switch.js +23 -0
- package/native/dist/text-content.d.ts +5 -0
- package/native/dist/text-content.js +6 -0
- package/native-fonts/README.md +17 -0
- package/native-fonts/dist/index.d.ts +164 -0
- package/native-fonts/dist/index.js +164 -0
- package/native-fonts/fonts/BloxwapMono-Bold.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono-ExtraBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono-Medium.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-Black.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-Bold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-ExtraBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-Medium.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansKR-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansKR.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansSC-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansSC.ttf +0 -0
- package/native-fonts/fonts/OFL.txt +93 -0
- package/native-fonts/fonts/manifest.json +164 -0
- package/og-fonts/README.md +34 -0
- package/og-fonts/dist/index.d.ts +116 -0
- package/og-fonts/dist/index.js +102 -0
- package/og-fonts/dist/node.d.ts +11 -0
- package/og-fonts/dist/node.js +39 -0
- package/og-fonts/fonts/BloxwapMono-Medium.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans-Black.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans-Bold.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans-Medium.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans.ttf +0 -0
- package/og-fonts/fonts/OFL.txt +93 -0
- package/og-fonts/fonts/manifest.json +65 -0
- package/package.json +358 -4
- package/react/README.md +9 -0
- package/react/dist/animated-number-model.d.ts +20 -0
- package/react/dist/animated-number-model.js +92 -0
- package/react/dist/animated-number.d.ts +8 -0
- package/react/dist/animated-number.js +71 -0
- package/react/dist/base.css +9 -0
- package/react/dist/brand.d.ts +7 -0
- package/react/dist/brand.js +4 -0
- package/react/dist/button.d.ts +14 -0
- package/react/dist/button.js +20 -0
- package/react/dist/data.d.ts +63 -0
- package/react/dist/data.js +23 -0
- package/react/dist/dialog.d.ts +29 -0
- package/react/dist/dialog.js +21 -0
- package/react/dist/field.d.ts +15 -0
- package/react/dist/field.js +19 -0
- package/react/dist/gesture-sheet.d.ts +41 -0
- package/react/dist/gesture-sheet.js +128 -0
- package/react/dist/navigation.d.ts +48 -0
- package/react/dist/navigation.js +69 -0
- package/react/dist/overlay.d.ts +17 -0
- package/react/dist/overlay.js +18 -0
- package/react/dist/provider.d.ts +25 -0
- package/react/dist/provider.js +50 -0
- package/react/dist/recipes/activity-list.d.ts +8 -0
- package/react/dist/recipes/activity-list.js +6 -0
- package/react/dist/recipes/balance-card.d.ts +6 -0
- package/react/dist/recipes/balance-card.js +5 -0
- package/react/dist/recipes/code-window.d.ts +4 -0
- package/react/dist/recipes/code-window.js +4 -0
- package/react/dist/recipes/install-command.d.ts +5 -0
- package/react/dist/recipes/install-command.js +8 -0
- package/react/dist/recipes/market-row.d.ts +25 -0
- package/react/dist/recipes/market-row.js +8 -0
- package/react/dist/recipes/marketing-hero.d.ts +7 -0
- package/react/dist/recipes/marketing-hero.js +5 -0
- package/react/dist/recipes/trade-entry.d.ts +11 -0
- package/react/dist/recipes/trade-entry.js +12 -0
- package/react/dist/recipes.d.ts +8 -0
- package/react/dist/recipes.js +9 -0
- package/react/dist/select.d.ts +4 -0
- package/react/dist/select.js +172 -0
- package/react/dist/selection.d.ts +27 -0
- package/react/dist/selection.js +16 -0
- package/react/dist/slider.d.ts +11 -0
- package/react/dist/slider.js +10 -0
- package/react/dist/status.d.ts +53 -0
- package/react/dist/status.js +43 -0
- package/react/dist/styles.css +228 -0
- package/react/dist/surface.d.ts +291 -0
- package/react/dist/surface.js +9 -0
- package/tokens/README.md +9 -0
- package/tokens/assets/bloxwap-icon.svg +1 -0
- package/tokens/dist/index.d.ts +429 -0
- package/tokens/dist/index.js +507 -0
- package/tokens/dist/manifest.json +197 -0
- package/tokens/dist/theme.d.ts +11 -0
- package/tokens/dist/theme.js +22 -0
- package/tokens/dist/tokens.css +119 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.bloxwap.hig;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
5
|
+
import com.facebook.react.views.view.ReactViewGroup;
|
|
6
|
+
import com.facebook.react.views.view.ReactViewManager;
|
|
7
|
+
|
|
8
|
+
/** A React Native View whose adjustable semantics also expose Android set-progress. */
|
|
9
|
+
public class HIGAdjustableViewManager extends ReactViewManager {
|
|
10
|
+
public static final String NAME = "HIGAdjustableView";
|
|
11
|
+
|
|
12
|
+
@NonNull
|
|
13
|
+
@Override
|
|
14
|
+
public String getName() {
|
|
15
|
+
return NAME;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@NonNull
|
|
19
|
+
@Override
|
|
20
|
+
public ReactViewGroup createViewInstance(@NonNull ThemedReactContext context) {
|
|
21
|
+
return new HIGAdjustableView(context);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package com.bloxwap.hig;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.facebook.react.ReactPackage;
|
|
5
|
+
import com.facebook.react.bridge.NativeModule;
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
8
|
+
import java.util.Collections;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
|
|
11
|
+
/** Registers the HIG native views. Autolinking discovers this package. */
|
|
12
|
+
public class HIGPackage implements ReactPackage {
|
|
13
|
+
@NonNull
|
|
14
|
+
@Override
|
|
15
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext context) {
|
|
16
|
+
return Collections.emptyList();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@NonNull
|
|
20
|
+
@Override
|
|
21
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext context) {
|
|
22
|
+
return Collections.<ViewManager>singletonList(new HIGAdjustableViewManager());
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type NumberTrend = -1 | 0 | 1 | ((previousValue: number, value: number) => -1 | 0 | 1);
|
|
2
|
+
export interface NumberReading {
|
|
3
|
+
known: boolean;
|
|
4
|
+
core: string;
|
|
5
|
+
text: string;
|
|
6
|
+
}
|
|
7
|
+
export interface NumberReelToken {
|
|
8
|
+
key: string;
|
|
9
|
+
kind: 'digit' | 'static';
|
|
10
|
+
type: string;
|
|
11
|
+
value: string;
|
|
12
|
+
partIndex: number;
|
|
13
|
+
digit?: number;
|
|
14
|
+
place?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface NumberReelModel {
|
|
17
|
+
canonical: string;
|
|
18
|
+
digits: readonly string[];
|
|
19
|
+
tokens: readonly NumberReelToken[];
|
|
20
|
+
}
|
|
21
|
+
export declare function formatNumberReadout(value: number | null | undefined, locale: string, options?: Intl.NumberFormatOptions, formattedValue?: string, prefix?: string, suffix?: string): NumberReading;
|
|
22
|
+
export declare function numberTrendDirection(trend: NumberTrend | undefined, previousValue: number | null | undefined, value: number | null | undefined): -1 | 0 | 1;
|
|
23
|
+
export declare function safeNumberLayout(text: string, direction: string): boolean;
|
|
24
|
+
export declare function createNumberReelModel(value: number | null | undefined, locale: string, options: Intl.NumberFormatOptions | undefined, formattedValue: string | undefined, direction: string): NumberReelModel | null;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
2
|
+
const supportedParts = new Set(['integer', 'fraction', 'decimal', 'group', 'plusSign', 'minusSign', 'percentSign', 'currency', 'unit', 'compact', 'literal', 'exponentSeparator', 'exponentInteger', 'exponentMinusSign', 'exponentPlusSign', 'approximatelySign']);
|
|
3
|
+
const bidiControls = /[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/u;
|
|
4
|
+
export function formatNumberReadout(value, locale, options, formattedValue, prefix, suffix) {
|
|
5
|
+
const known = typeof value === 'number' && Number.isFinite(value);
|
|
6
|
+
if (!known)
|
|
7
|
+
return { known: false, core: '—', text: '—' };
|
|
8
|
+
let core;
|
|
9
|
+
if (formattedValue)
|
|
10
|
+
core = formattedValue;
|
|
11
|
+
else {
|
|
12
|
+
try {
|
|
13
|
+
core = formatNumber(value, locale, options);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
core = String(value);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return { known: true, core, text: `${prefix ?? ''}${core}${suffix ?? ''}` };
|
|
20
|
+
}
|
|
21
|
+
export function numberTrendDirection(trend, previousValue, value) {
|
|
22
|
+
if (Object.is(previousValue, value) || typeof previousValue !== 'number' || !Number.isFinite(previousValue) || typeof value !== 'number' || !Number.isFinite(value))
|
|
23
|
+
return 0;
|
|
24
|
+
const resolved = typeof trend === 'function' ? trend(previousValue, value) : trend;
|
|
25
|
+
if (resolved === 1 || resolved === -1)
|
|
26
|
+
return resolved;
|
|
27
|
+
if (resolved === 0)
|
|
28
|
+
return 0;
|
|
29
|
+
return value > previousValue ? 1 : value < previousValue ? -1 : 0;
|
|
30
|
+
}
|
|
31
|
+
function strongRTL(character) {
|
|
32
|
+
const point = character.codePointAt(0);
|
|
33
|
+
if (point === undefined)
|
|
34
|
+
return false;
|
|
35
|
+
if ((point >= 0x0660 && point <= 0x0669) || (point >= 0x06f0 && point <= 0x06f9) || (point >= 0x066a && point <= 0x066c))
|
|
36
|
+
return false;
|
|
37
|
+
return (point >= 0x0590 && point <= 0x08ff) || (point >= 0xfb1d && point <= 0xfdff) || (point >= 0xfe70 && point <= 0xfefc) || (point >= 0x10800 && point <= 0x10fff) || (point >= 0x1e800 && point <= 0x1edff) || (point >= 0x1ee00 && point <= 0x1eeff);
|
|
38
|
+
}
|
|
39
|
+
export function safeNumberLayout(text, direction) {
|
|
40
|
+
if (direction !== 'ltr')
|
|
41
|
+
return false;
|
|
42
|
+
for (const character of Array.from(text))
|
|
43
|
+
if (bidiControls.test(character) || strongRTL(character))
|
|
44
|
+
return false;
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
export function createNumberReelModel(value, locale, options, formattedValue, direction) {
|
|
48
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || formattedValue || direction !== 'ltr' || typeof Intl === 'undefined' || typeof Intl.NumberFormat !== 'function')
|
|
49
|
+
return null;
|
|
50
|
+
try {
|
|
51
|
+
const formatter = new Intl.NumberFormat(locale, options);
|
|
52
|
+
if (typeof formatter.formatToParts !== 'function')
|
|
53
|
+
return null;
|
|
54
|
+
const canonical = formatter.format(value);
|
|
55
|
+
if (canonical !== formatNumberReadout(value, locale, options).core)
|
|
56
|
+
return null;
|
|
57
|
+
const parts = formatter.formatToParts(value);
|
|
58
|
+
if (!parts.length || parts.map(part => part.value).join('') !== canonical)
|
|
59
|
+
return null;
|
|
60
|
+
const numberingSystem = formatter.resolvedOptions().numberingSystem;
|
|
61
|
+
if (!numberingSystem)
|
|
62
|
+
return null;
|
|
63
|
+
const digitFormatter = new Intl.NumberFormat(locale, { numberingSystem, useGrouping: false, minimumFractionDigits: 0, maximumFractionDigits: 0 });
|
|
64
|
+
if (typeof digitFormatter.formatToParts !== 'function')
|
|
65
|
+
return null;
|
|
66
|
+
const digits = Array.from({ length: 10 }, (_, digit) => {
|
|
67
|
+
const formatted = digitFormatter.format(digit), parts = digitFormatter.formatToParts(digit);
|
|
68
|
+
return parts.length === 1 && parts[0].type === 'integer' && parts[0].value === formatted && Array.from(formatted).length === 1 ? formatted : '';
|
|
69
|
+
});
|
|
70
|
+
if (digits.some(digit => !digit) || new Set(digits).size !== 10 || !safeNumberLayout(canonical, direction))
|
|
71
|
+
return null;
|
|
72
|
+
const digitIndexes = new Map(digits.map((digit, index) => [digit, index]));
|
|
73
|
+
const count = (type) => parts.filter(part => part.type === type).reduce((total, part) => total + Array.from(part.value).length, 0);
|
|
74
|
+
const integerCount = count('integer'), exponentCount = count('exponentInteger');
|
|
75
|
+
let integerIndex = 0, fractionIndex = 0, exponentIndex = 0;
|
|
76
|
+
const tokens = [];
|
|
77
|
+
for (let partIndex = 0; partIndex < parts.length; partIndex++) {
|
|
78
|
+
const part = parts[partIndex];
|
|
79
|
+
if (!supportedParts.has(part.type))
|
|
80
|
+
return null;
|
|
81
|
+
if (part.type !== 'integer' && part.type !== 'fraction' && part.type !== 'exponentInteger') {
|
|
82
|
+
tokens.push({ key: `part:${partIndex}:${part.type}`, kind: 'static', type: part.type, value: part.value, partIndex });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
for (const character of Array.from(part.value)) {
|
|
86
|
+
const digit = digitIndexes.get(character);
|
|
87
|
+
if (digit === undefined)
|
|
88
|
+
return null;
|
|
89
|
+
let key, place;
|
|
90
|
+
if (part.type === 'integer') {
|
|
91
|
+
place = integerCount - integerIndex++ - 1;
|
|
92
|
+
key = `integer:${place}`;
|
|
93
|
+
}
|
|
94
|
+
else if (part.type === 'fraction') {
|
|
95
|
+
place = fractionIndex++;
|
|
96
|
+
key = `fraction:${place}`;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
place = exponentCount - exponentIndex++ - 1;
|
|
100
|
+
key = `exponentInteger:${place}`;
|
|
101
|
+
}
|
|
102
|
+
tokens.push({ key, kind: 'digit', type: part.type, value: character, partIndex, digit, place });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return { canonical, digits, tokens };
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type NumberProps } from './data.js';
|
|
3
|
+
import { type NumberTrend } from './animated-number-model.js';
|
|
4
|
+
export type AnimatedNumberTrend = NumberTrend;
|
|
5
|
+
export interface AnimatedNumberProps extends NumberProps {
|
|
6
|
+
duration?: number;
|
|
7
|
+
trend?: AnimatedNumberTrend;
|
|
8
|
+
}
|
|
9
|
+
export declare function AnimatedNumberReadout({ value, options, formattedValue, stale, label, tone, style, testID, maxFontSizeMultiplier, trend, prefix, suffix, duration }: AnimatedNumberProps): React.JSX.Element;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { PixelRatio, StyleSheet, View } from 'react-native';
|
|
5
|
+
import Reanimated, { cancelAnimation, Easing, ReduceMotion, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
6
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
7
|
+
import { createNumberReelModel, formatNumberReadout, numberTrendDirection, safeNumberLayout } from './animated-number-model.js';
|
|
8
|
+
import { useColors, useHIG } from './provider.js';
|
|
9
|
+
import { detectScript, Text } from './surface.js';
|
|
10
|
+
const numberTypographyKeys = new Set(['fontFamily', 'fontSize', 'fontWeight', 'lineHeight', 'letterSpacing', 'textAlign']);
|
|
11
|
+
const clampedDuration = (duration) => Number.isFinite(duration) && duration > 0 ? Math.min(duration, 600) : 0;
|
|
12
|
+
function DigitReel({ digits, digit, trend, duration, reducedMotion, width, height, style, script, maxFontSizeMultiplier }) {
|
|
13
|
+
const position = useSharedValue(digit), previousDigit = useRef(digit);
|
|
14
|
+
const animatedStyle = useAnimatedStyle(() => ({ transform: [{ translateY: -(position.value + 10) * height }] }), [height]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const motionDuration = clampedDuration(duration);
|
|
17
|
+
if (previousDigit.current === digit) {
|
|
18
|
+
if (reducedMotion || !motionDuration) {
|
|
19
|
+
cancelAnimation(position);
|
|
20
|
+
position.value = digit;
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
previousDigit.current = digit;
|
|
25
|
+
cancelAnimation(position);
|
|
26
|
+
if (reducedMotion || !motionDuration) {
|
|
27
|
+
position.value = digit;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const current = position.value;
|
|
31
|
+
if (!Number.isFinite(current)) {
|
|
32
|
+
position.value = digit;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const normalized = current >= 0 && current < 10 ? current : ((current % 10) + 10) % 10;
|
|
36
|
+
if (normalized !== current)
|
|
37
|
+
position.value = normalized;
|
|
38
|
+
let destination = digit;
|
|
39
|
+
if (trend > 0)
|
|
40
|
+
while (destination <= normalized)
|
|
41
|
+
destination += 10;
|
|
42
|
+
else if (trend < 0)
|
|
43
|
+
while (destination >= normalized)
|
|
44
|
+
destination -= 10;
|
|
45
|
+
if (destination === normalized) {
|
|
46
|
+
position.value = digit;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
position.value = withTiming(destination, { duration: motionDuration, easing: Easing.out(Easing.cubic), reduceMotion: ReduceMotion.Never });
|
|
50
|
+
}, [digit, trend, duration, reducedMotion, position]);
|
|
51
|
+
useEffect(() => () => cancelAnimation(position), [position]);
|
|
52
|
+
const rows = Array.from({ length: 30 }, (_, index) => digits[index % 10]);
|
|
53
|
+
return _jsx(View, { collapsable: false, style: { width, height, overflow: 'hidden' }, children: _jsx(Reanimated.View, { style: animatedStyle, children: rows.map((glyph, index) => _jsx(Text, { accessible: false, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier, style: [style, { width, height, textAlign: 'center' }], children: glyph }, `${index}:${glyph}`)) }) });
|
|
54
|
+
}
|
|
55
|
+
function recordGlyph(measurements, key, index, event, setMetrics) {
|
|
56
|
+
const { width, height } = event.nativeEvent.layout;
|
|
57
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0)
|
|
58
|
+
return;
|
|
59
|
+
measurements.current.values.set(index, { width, height });
|
|
60
|
+
if (measurements.current.values.size !== 10)
|
|
61
|
+
return;
|
|
62
|
+
const values = Array.from(measurements.current.values.values()), measuredWidth = Math.max(...values.map(value => value.width)), measuredHeight = Math.max(...values.map(value => value.height));
|
|
63
|
+
if (!Number.isFinite(measuredWidth) || !Number.isFinite(measuredHeight) || measuredWidth <= 0 || measuredHeight <= 0)
|
|
64
|
+
return;
|
|
65
|
+
setMetrics(current => current?.key === key && current.width === measuredWidth && current.height === measuredHeight ? current : { key, width: measuredWidth, height: measuredHeight });
|
|
66
|
+
}
|
|
67
|
+
export function AnimatedNumberReadout({ value, options, formattedValue, stale, label, tone = 'text', style, testID, maxFontSizeMultiplier, trend, prefix, suffix, duration = 180 }) {
|
|
68
|
+
const { locale, messages, direction, reducedMotion, fontFamily, fontFamilies, fontFamiliesByScript, letterSpacingByScript, maxFontSizeMultiplier: providerMaxFontSizeMultiplier } = useHIG(), colors = useColors();
|
|
69
|
+
const reading = formatNumberReadout(value, locale, options, formattedValue, prefix, suffix), staleSuffix = stale ? ` ${messages.stale ?? en.stale}` : '';
|
|
70
|
+
const previousValue = useRef(value), directionTrend = numberTrendDirection(trend, previousValue.current, value);
|
|
71
|
+
useEffect(() => { previousValue.current = value; }, [value]);
|
|
72
|
+
const typography = Object.fromEntries(Object.entries(StyleSheet.flatten(style) ?? {}).filter(([key]) => numberTypographyKeys.has(key)));
|
|
73
|
+
const color = colors[tone === 'positive' || tone === 'negative' || tone === 'muted' ? tone : 'text'];
|
|
74
|
+
const textStyle = [typography, { color, fontVariant: ['tabular-nums'] }];
|
|
75
|
+
const script = detectScript(`${reading.text}${staleSuffix}`, locale);
|
|
76
|
+
const model = createNumberReelModel(value, locale, options, formattedValue, direction);
|
|
77
|
+
const safeModel = model && safeNumberLayout(`${prefix ?? ''}${suffix ?? ''}${staleSuffix}`, direction) ? model : null;
|
|
78
|
+
let fontScale = 0;
|
|
79
|
+
try {
|
|
80
|
+
fontScale = PixelRatio.getFontScale();
|
|
81
|
+
}
|
|
82
|
+
catch { /* Static until native font metrics are available. */ }
|
|
83
|
+
const measurementKey = JSON.stringify([safeModel?.digits, typography, fontScale, maxFontSizeMultiplier, providerMaxFontSizeMultiplier, script, fontFamily, fontFamilies, fontFamiliesByScript, letterSpacingByScript]);
|
|
84
|
+
const measurements = useRef({ key: '', values: new Map() });
|
|
85
|
+
if (measurements.current.key !== measurementKey)
|
|
86
|
+
measurements.current = { key: measurementKey, values: new Map() };
|
|
87
|
+
const [metrics, setMetrics] = useState(null);
|
|
88
|
+
const activeModel = safeModel && fontScale > 0 && Number.isFinite(fontScale) && metrics?.key === measurementKey ? safeModel : null;
|
|
89
|
+
const activeMetrics = activeModel ? metrics : null;
|
|
90
|
+
const justifyContent = typography.textAlign === 'right' ? 'flex-end' : typography.textAlign === 'center' ? 'center' : 'flex-start';
|
|
91
|
+
const visualProps = { accessible: false, script, maxFontSizeMultiplier };
|
|
92
|
+
return _jsxs(View, { collapsable: false, style: { position: 'relative' }, children: [_jsxs(Text, { accessibilityLabel: label ? `${label}: ${reading.text}${staleSuffix}` : undefined, testID: testID, maxFontSizeMultiplier: maxFontSizeMultiplier, style: [textStyle, activeModel ? { color: 'transparent' } : undefined], children: [reading.text, staleSuffix] }), safeModel && _jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', pointerEvents: 'none', style: { position: 'absolute', opacity: 0, flexDirection: 'row' }, children: safeModel.digits.map((glyph, index) => _createElement(Text, { ...visualProps, key: `${measurementKey}:${index}`, onLayout: event => recordGlyph(measurements, measurementKey, index, event, setMetrics), style: textStyle }, glyph)) }), activeModel && activeMetrics && _jsxs(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', pointerEvents: 'none', style: [StyleSheet.absoluteFill, { overflow: 'hidden', flexDirection: 'row', direction: 'ltr', alignItems: 'center', justifyContent }], children: [prefix && _jsx(Text, { ...visualProps, style: textStyle, children: prefix }), activeModel.tokens.map(token => token.kind === 'static' ? _createElement(Text, { ...visualProps, key: token.key, style: textStyle }, token.value) : _jsx(DigitReel, { digits: activeModel.digits, digit: token.digit ?? 0, trend: directionTrend, duration: duration, reducedMotion: reducedMotion, width: activeMetrics.width, height: activeMetrics.height, style: textStyle, script: script, maxFontSizeMultiplier: maxFontSizeMultiplier }, token.key)), (suffix || staleSuffix) && _jsx(Text, { ...visualProps, style: textStyle, children: `${suffix ?? ''}${staleSuffix}` })] })] });
|
|
93
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** The approved mark's #00ff3f fill and #0a0a0a strokes are the action and background tokens, painted in the provider's colour space independently of its primary colour. */
|
|
3
|
+
export declare function BrandMark({ size, label }: {
|
|
4
|
+
size?: number;
|
|
5
|
+
label?: string;
|
|
6
|
+
}): React.JSX.Element;
|
|
7
|
+
export declare function CheckIcon(): React.JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Svg, { Rect, G, Path } from 'react-native-svg';
|
|
3
|
+
import { useColors, useBrandColors } from './provider.js';
|
|
4
|
+
/** The approved mark's #00ff3f fill and #0a0a0a strokes are the action and background tokens, painted in the provider's colour space independently of its primary colour. */
|
|
5
|
+
export function BrandMark({ size = 32, label }) { const colors = useBrandColors(); return _jsxs(Svg, { width: size, height: size, viewBox: '0 0 100 100', accessible: !!label, accessibilityLabel: label, children: [_jsx(Rect, { width: '100', height: '100', rx: '22.37', fill: colors.action }), _jsxs(G, { fill: 'none', stroke: colors.background, strokeWidth: '16', strokeLinecap: 'round', children: [_jsx(Path, { d: 'M25 75L75 25' }), _jsx(Path, { d: 'M24 24L35 35' }), _jsx(Path, { d: 'M65 65L76 76' })] })] }); }
|
|
6
|
+
export function CheckIcon() { const colors = useColors(); return _jsx(Svg, { width: '20', height: '20', viewBox: '0 0 24 24', accessible: false, children: _jsx(Path, { d: 'm5 12 4 4 10-10', fill: 'none', stroke: colors.text, strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round' }) }); }
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, type PressableProps } from 'react-native';
|
|
3
|
+
import type { Intent } from '@bloxwap/hig/contracts';
|
|
4
|
+
import { type TextScript } from './surface.js';
|
|
5
|
+
export interface ButtonProps extends Omit<PressableProps, 'children'> {
|
|
6
|
+
children: React.ReactNode; /** Custom content renders host nodes directly; the host owns visible busy content. Root disabled/busy/feedback semantics stay canonical. */
|
|
7
|
+
contentMode?: 'default' | 'custom';
|
|
8
|
+
intent?: Intent;
|
|
9
|
+
busy?: boolean; /** Busy suffix for this button; defaults to HIGProvider `messages.busy`. `''` hides it (accessibilityState.busy stays set). */
|
|
10
|
+
busyLabel?: string; /** Overrides the provider's text scale cap for the label and busy suffix. */
|
|
11
|
+
maxFontSizeMultiplier?: number;
|
|
12
|
+
script?: TextScript;
|
|
13
|
+
fullWidth?: boolean;
|
|
14
|
+
suppressFeedback?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Android appends its localized busy state; including the suffix there would speak it twice. */
|
|
17
|
+
export declare function busyAccessibilityLabel(text: string, busyText: string, os?: string): string | undefined;
|
|
18
|
+
export declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<React.ComponentRef<typeof View>>>;
|
|
19
|
+
export declare function IconButton({ label, children, style, ...props }: ButtonProps & {
|
|
20
|
+
label: string;
|
|
21
|
+
}): React.JSX.Element;
|
|
22
|
+
export interface LinkProps extends Omit<PressableProps, 'children' | 'onPress' | 'accessibilityRole' | 'role'> {
|
|
23
|
+
href: string;
|
|
24
|
+
children: React.ReactNode; /** Host navigation replaces Linking.openURL, so one press never opens both. */
|
|
25
|
+
onPress?: PressableProps['onPress'];
|
|
26
|
+
onError?: (error: unknown) => void;
|
|
27
|
+
/** Custom content renders host label/icon nodes directly. */ contentMode?: 'default' | 'custom';
|
|
28
|
+
}
|
|
29
|
+
export declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<React.ComponentRef<typeof View>>>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { forwardRef, useId, useRef } from 'react';
|
|
3
|
+
import { Pressable, Linking, Platform, View } from 'react-native';
|
|
4
|
+
import { nativeMetrics as tokens } from '@bloxwap/hig/tokens';
|
|
5
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
6
|
+
import { useColors, useHIG } from './provider.js';
|
|
7
|
+
import { Text } from './surface.js';
|
|
8
|
+
import { plainText } from './text-content.js';
|
|
9
|
+
/** Adjacent text children such as `{label}: {value}` form one Text run so the label wraps as words, not gapped fragments. */
|
|
10
|
+
function labelRuns(children) { const runs = []; for (const child of React.Children.toArray(children)) {
|
|
11
|
+
const text = typeof child === 'string' || typeof child === 'number' ? String(child) : null;
|
|
12
|
+
const last = runs.length - 1;
|
|
13
|
+
if (text !== null && typeof runs[last] === 'string')
|
|
14
|
+
runs[last] += text;
|
|
15
|
+
else
|
|
16
|
+
runs.push(text ?? child);
|
|
17
|
+
} return runs; }
|
|
18
|
+
/** Android appends its localized busy state; including the suffix there would speak it twice. */
|
|
19
|
+
export function busyAccessibilityLabel(text, busyText, os = Platform.OS) { return text ? (busyText && os !== 'android' ? `${text} · ${busyText}` : text) : undefined; }
|
|
20
|
+
export const Button = /* @__PURE__ */ forwardRef(function Button({ children, contentMode = 'default', intent = 'primary', disabled, busy, busyLabel, maxFontSizeMultiplier, script, fullWidth, suppressFeedback, onPress, style, ...props }, ref) { const env = useHIG(); const colors = useColors(); const id = useId(); const sequence = useRef(0); const busyText = busyLabel ?? env.messages.busy ?? en.busy; const filled = intent === 'primary' || intent === 'destructive'; const label = plainText(children); const accessibleLabel = props.accessibilityLabel ?? (busy ? busyAccessibilityLabel(label, busyText) : undefined); const labelStyle = { color: intent === 'destructive' ? colors.background : intent === 'primary' ? colors.onAction : intent === 'ghost' ? colors.muted : colors.text, fontSize: 16, fontWeight: '600', textAlign: 'center' }; return _jsx(Pressable, { ...props, ref: ref, disabled: disabled || busy, accessibilityRole: 'button', accessibilityLabel: accessibleLabel, accessibilityState: { ...props.accessibilityState, disabled: !!disabled || !!busy, busy: !!busy }, "aria-busy": !!busy, onPress: e => { if (disabled || busy)
|
|
21
|
+
return; e.stopPropagation(); onPress?.(e); if (!e.isDefaultPrevented() && !disabled && !busy && !suppressFeedback) {
|
|
22
|
+
try {
|
|
23
|
+
env.onAccepted?.(id);
|
|
24
|
+
env.feedback?.emit({ id: `${id}/${++sequence.current}`, source: id, intent: 'activate', origin: 'native' });
|
|
25
|
+
}
|
|
26
|
+
catch { /* Best effort only. */ }
|
|
27
|
+
} }, style: state => [{ minHeight: Math.max(48, tokens.density[env.density].target), paddingHorizontal: 20, paddingVertical: 12, borderRadius: 9999, alignItems: 'center', justifyContent: 'center', backgroundColor: filled ? (intent === 'destructive' ? colors.negative : colors.action) : intent === 'ghost' && !state.pressed ? 'transparent' : colors.nested, opacity: disabled || busy ? 0.5 : state.pressed ? 0.85 : 1, alignSelf: fullWidth ? 'stretch' : 'flex-start' }, typeof style === 'function' ? style(state) : style], children: contentMode === 'custom' ? children : _jsxs(View, { style: { direction: env.direction, flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', justifyContent: 'center', gap: 8 }, children: [labelRuns(children).map((child, i) => typeof child === 'string' ? _jsx(Text, { script: script, maxFontSizeMultiplier: maxFontSizeMultiplier, style: labelStyle, children: child }, `label-${i}`) : child), busy && busyText ? _jsxs(Text, { script: script, maxFontSizeMultiplier: maxFontSizeMultiplier, style: labelStyle, children: ["\u00B7 ", busyText] }) : null] }) }); });
|
|
28
|
+
export function IconButton({ label, children, style, ...props }) { return _jsx(Button, { ...props, accessibilityLabel: label, style: state => [{ minWidth: 48, paddingHorizontal: 12 }, typeof style === 'function' ? style(state) : style], children: children }); }
|
|
29
|
+
export const Link = /* @__PURE__ */ forwardRef(function Link({ href, children, onError, onPress, contentMode = 'default', disabled, style, ...props }, ref) { const colors = useColors(); const web = Platform.OS === 'web', webHref = web && !disabled ? { href } : {}; return _jsx(Pressable, { ...props, ...webHref, ref: ref, accessibilityRole: 'link', disabled: disabled, accessibilityState: { ...props.accessibilityState, disabled: !!disabled }, "aria-busy": props.accessibilityState?.busy, onPress: event => { if (disabled)
|
|
30
|
+
return; if (onPress)
|
|
31
|
+
onPress(event);
|
|
32
|
+
else
|
|
33
|
+
void Linking.openURL(href).catch(onError ?? (() => { })); if (web)
|
|
34
|
+
event.preventDefault(); }, style: state => [{ minHeight: 48, minWidth: 48, justifyContent: 'center' }, typeof style === 'function' ? style(state) : style], children: contentMode === 'custom' ? children : _jsx(Text, { style: { color: colors.action, textDecorationLine: 'underline' }, children: children }) }); });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Pressable, View } from 'react-native';
|
|
3
|
+
import { nativeMetrics as tokens } from '@bloxwap/hig/tokens';
|
|
4
|
+
import { useColors, useControllable, useHIG } from './provider.js';
|
|
5
|
+
import { Text } from './surface.js';
|
|
6
|
+
export function Checkbox({ label, checked, defaultChecked = false, disabled, onCheckedChange }) {
|
|
7
|
+
const [current, set] = useControllable(checked, defaultChecked, onCheckedChange);
|
|
8
|
+
const colors = useColors(), env = useHIG();
|
|
9
|
+
return _jsxs(Pressable, { accessibilityRole: 'checkbox', "aria-checked": current, "aria-disabled": !!disabled, accessibilityLabel: label, accessibilityState: { checked: current, disabled: !!disabled }, disabled: disabled, onPress: () => { if (!disabled)
|
|
10
|
+
set(!current); }, style: { direction: env.direction, minHeight: 48, flexDirection: 'row', alignItems: 'center', gap: tokens.space.sm, opacity: disabled ? .5 : 1 }, children: [_jsx(View, { pointerEvents: 'none', accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', "aria-hidden": true, style: { width: 20, height: 20, flexShrink: 0, borderWidth: 1.5, borderColor: current ? colors.action : colors.muted, borderRadius: tokens.radius.sm, backgroundColor: current ? colors.action : colors.surface, alignItems: 'center', justifyContent: 'center' }, children: current && _jsx(View, { style: { width: 10, height: 6, borderLeftWidth: 2, borderBottomWidth: 2, borderColor: colors.onAction, transform: [{ translateY: -1 }, { rotate: '-45deg' }] } }) }), _jsx(Text, { style: { flexShrink: 1, minWidth: 0 }, children: label })] });
|
|
11
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type StyleProp, type TextStyle } from 'react-native';
|
|
3
|
+
export type NumberTone = 'text' | 'positive' | 'negative' | 'muted';
|
|
4
|
+
/** Typography only: semantic tone owns colour and numeric glyphs remain tabular. */
|
|
5
|
+
export type NumberReadoutStyle = Pick<TextStyle, 'fontFamily' | 'fontSize' | 'fontWeight' | 'lineHeight' | 'letterSpacing' | 'textAlign'>;
|
|
6
|
+
export interface NumberProps {
|
|
7
|
+
value: number | null | undefined;
|
|
8
|
+
options?: Intl.NumberFormatOptions; /** Host-owned display text for a finite value. Empty text falls back to locale formatting; never parse this text for submission. */
|
|
9
|
+
formattedValue?: string;
|
|
10
|
+
stale?: boolean;
|
|
11
|
+
label?: string; /** Explicit semantic meaning; sign alone never chooses the tone. */
|
|
12
|
+
tone?: NumberTone; /** Text typography, including an explicitly registered mono face. Does not style the animated wrapper. */
|
|
13
|
+
style?: StyleProp<NumberReadoutStyle>;
|
|
14
|
+
testID?: string; /** Font-scale cap for dense readouts, e.g. 2 for 200% at AX5. */
|
|
15
|
+
maxFontSizeMultiplier?: number; /** Display-only affixes, omitted for unknown values. */
|
|
16
|
+
prefix?: string;
|
|
17
|
+
suffix?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function NumberReadout({ value, options, formattedValue, stale, label, tone, style, testID, maxFontSizeMultiplier, prefix, suffix }: NumberProps): React.JSX.Element;
|
|
20
|
+
export declare function Usd(props: NumberProps): React.JSX.Element;
|
|
21
|
+
export declare function Percent(props: NumberProps): React.JSX.Element;
|
|
22
|
+
export declare function Metric({ label, value }: {
|
|
23
|
+
label: string;
|
|
24
|
+
value: React.ReactNode;
|
|
25
|
+
}): React.JSX.Element;
|
|
26
|
+
export declare const Stat: typeof Metric;
|
|
27
|
+
export declare function Row({ children }: React.PropsWithChildren): React.JSX.Element;
|
|
28
|
+
/** Native alternative to dense DOM tables: virtualized labeled rows. */
|
|
29
|
+
export interface ListProps<T> {
|
|
30
|
+
items: readonly T[];
|
|
31
|
+
keyFor: (item: T) => string;
|
|
32
|
+
render: (item: T) => React.ReactNode;
|
|
33
|
+
empty?: string;
|
|
34
|
+
label?: string;
|
|
35
|
+
loading?: boolean;
|
|
36
|
+
error?: string;
|
|
37
|
+
onRetry?: () => void;
|
|
38
|
+
onLoadMore?: () => void;
|
|
39
|
+
}
|
|
40
|
+
export declare function List<T>({ items, keyFor, render, empty, label, loading, error, onRetry, onLoadMore }: ListProps<T>): React.JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { FlatList, View, StyleSheet } from 'react-native';
|
|
3
|
+
import { formatNumberReadout } from './animated-number-model.js';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useColors, useHIG } from './provider.js';
|
|
6
|
+
import { Text, Surface, Separator } from './surface.js';
|
|
7
|
+
import { Button } from './button.js';
|
|
8
|
+
const numberTypographyKeys = new Set(['fontFamily', 'fontSize', 'fontWeight', 'lineHeight', 'letterSpacing', 'textAlign']);
|
|
9
|
+
export function NumberReadout({ value, options, formattedValue, stale, label, tone = 'text', style, testID, maxFontSizeMultiplier, prefix, suffix }) {
|
|
10
|
+
const { locale, messages } = useHIG();
|
|
11
|
+
const colors = useColors();
|
|
12
|
+
const reading = formatNumberReadout(value, locale, options, formattedValue, prefix, suffix).text;
|
|
13
|
+
const staleSuffix = stale ? ` ${messages.stale ?? en.stale}` : '';
|
|
14
|
+
// Keep the same boundary for untyped hosts and registered/array styles: no raw colour, glyph or layout overrides.
|
|
15
|
+
const typography = Object.fromEntries(Object.entries(StyleSheet.flatten(style) ?? {}).filter(([key]) => numberTypographyKeys.has(key)));
|
|
16
|
+
const color = colors[tone === 'positive' || tone === 'negative' || tone === 'muted' ? tone : 'text'];
|
|
17
|
+
return _jsxs(Text, { accessibilityLabel: label ? `${label}: ${reading}${staleSuffix}` : undefined, testID: testID, maxFontSizeMultiplier: maxFontSizeMultiplier, style: [typography, { color, fontVariant: ['tabular-nums'] }], children: [reading, staleSuffix] });
|
|
18
|
+
}
|
|
19
|
+
export function Usd(props) { return _jsx(NumberReadout, { ...props, options: { style: 'currency', currency: 'USD', ...props.options } }); }
|
|
20
|
+
export function Percent(props) { return _jsx(NumberReadout, { ...props, value: props.value == null ? props.value : props.value / 100, options: { maximumFractionDigits: Math.max(3, props.options?.minimumFractionDigits ?? 0), ...props.options, style: 'percent' } }); }
|
|
21
|
+
export function Metric({ label, value }) { return _jsxs(Surface, { children: [_jsx(Text, { children: label }), value] }); }
|
|
22
|
+
export const Stat = Metric;
|
|
23
|
+
export function Row({ children }) { return _jsx(View, { style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', flexWrap: 'wrap', gap: 12, paddingVertical: 12 }, children: children }); }
|
|
24
|
+
export function List({ items, keyFor, render, empty, label, loading = false, error, onRetry, onLoadMore }) {
|
|
25
|
+
const { messages } = useHIG();
|
|
26
|
+
return _jsx(FlatList, { data: items, accessibilityLabel: label, accessibilityState: { busy: loading }, keyExtractor: keyFor, renderItem: ({ item }) => _jsx(View, { children: render(item) }), ItemSeparatorComponent: Separator, ListEmptyComponent: !loading && !error ? _jsx(Text, { children: empty ?? messages.noItems ?? en.noItems }) : null, ListFooterComponent: _jsxs(View, { style: { gap: 12, paddingTop: loading || error || onLoadMore ? 12 : 0 }, children: [loading && _jsx(Text, { accessibilityLiveRegion: 'polite', children: messages.loadingItems ?? en.loadingItems }), error && _jsxs(View, { style: { gap: 12 }, children: [_jsx(Text, { accessibilityRole: 'alert', children: error }), onRetry && _jsx(Button, { disabled: loading, onPress: onRetry, children: messages.retry ?? en.retry })] }), onLoadMore && _jsx(Button, { disabled: loading, onPress: onLoadMore, children: messages.loadMore ?? en.loadMore })] }) });
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TextInput, type TextInputProps } from 'react-native';
|
|
3
|
+
import { Text } from './surface.js';
|
|
4
|
+
export declare function Field({ label, description, error, required, disabled, children }: React.PropsWithChildren<{
|
|
5
|
+
label: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
error?: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}>): React.JSX.Element;
|
|
11
|
+
export declare const Label: typeof Text;
|
|
12
|
+
export declare const Input: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<React.ComponentRef<typeof TextInput>>>;
|
|
13
|
+
export declare const TextArea: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<React.ComponentRef<typeof TextInput>>>;
|
|
14
|
+
export declare const AmountInput: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<React.ComponentRef<typeof TextInput>>>;
|
|
15
|
+
export declare const SearchInput: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<React.ComponentRef<typeof TextInput>>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, forwardRef, useId } from 'react';
|
|
3
|
+
import { TextInput, View } from 'react-native';
|
|
4
|
+
import { Text } from './surface.js';
|
|
5
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
6
|
+
import { useColors, useHIG } from './provider.js';
|
|
7
|
+
const Context = createContext({ label: '' });
|
|
8
|
+
export function Field({ label, description, error, required, disabled, children }) { const id = useId(); const { messages } = useHIG(); const colors = useColors(); const marked = required ? `${label} ${messages.required ?? en.required}` : label; return _jsx(Context.Provider, { value: { label: marked, hint: [description, error].filter(Boolean).join('. '), disabled, invalid: !!error }, children: _jsxs(View, { style: { gap: 8 }, children: [_jsx(Text, { nativeID: id, children: marked }), children, description && _jsx(Text, { style: { color: colors.muted }, children: description }), error && _jsx(Text, { accessibilityLiveRegion: 'polite', style: { color: colors.negative }, children: error })] }) }); }
|
|
9
|
+
export const Label = Text;
|
|
10
|
+
export const Input = forwardRef(function Input({ style, ...props }, ref) { const field = useContext(Context); const colors = useColors(); const env = useHIG(); return _jsx(TextInput, { ...props, ref: ref, accessibilityLabel: props.accessibilityLabel ?? field.label, accessibilityHint: props.accessibilityHint ?? field.hint, accessibilityState: { ...props.accessibilityState, disabled: !!field.disabled || !!props.accessibilityState?.disabled }, editable: field.disabled ? false : props.editable, onChangeText: field.disabled ? undefined : props.onChangeText, onChange: field.disabled ? undefined : props.onChange, placeholderTextColor: props.placeholderTextColor ?? colors.muted, style: [{ color: colors.text, backgroundColor: colors.surface, minHeight: 48, borderWidth: 1, borderColor: field.invalid ? colors.negative : colors.border, borderRadius: props.multiline ? 14 : 9999, paddingVertical: 12, paddingHorizontal: 20, fontSize: 16, fontFamily: env.fontFamilies?.[400] ?? env.fontFamily, opacity: field.disabled ? 0.5 : 1 }, style] }); });
|
|
11
|
+
export const TextArea = forwardRef(function TextArea(props, ref) { return _jsx(Input, { ...props, ref: ref, multiline: true, textAlignVertical: 'top' }); });
|
|
12
|
+
export const AmountInput = forwardRef(function AmountInput(props, ref) { return _jsx(Input, { ...props, ref: ref, keyboardType: props.keyboardType ?? 'decimal-pad' }); });
|
|
13
|
+
export const SearchInput = forwardRef(function SearchInput(props, ref) { return _jsx(Input, { ...props, ref: ref, returnKeyType: props.returnKeyType ?? 'search' }); });
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text as RNText, TextInput, View } from 'react-native';
|
|
3
|
+
import BottomSheet, { BottomSheetModal, type BottomSheetModalProps } from '@gorhom/bottom-sheet';
|
|
4
|
+
interface GestureSheetCommonProps {
|
|
5
|
+
open: boolean;
|
|
6
|
+
onOpenChange: (open: boolean) => void;
|
|
7
|
+
title: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
/** Default anatomy scrolls the title, description, content and Close action. Custom content owns layout, scrolling and dismissal actions. */
|
|
11
|
+
contentMode?: 'default' | 'custom';
|
|
12
|
+
/** In custom mode, attach to the caller-rendered accessible title. Without it, a visually hidden title receives open focus. */
|
|
13
|
+
titleRef?: React.RefObject<React.ComponentRef<typeof View> | React.ComponentRef<typeof RNText> | React.ComponentRef<typeof TextInput> | null>;
|
|
14
|
+
/** Content-heavy hosts may disable content panning while retaining their own scrollable gestures. */
|
|
15
|
+
enableContentPanningGesture?: BottomSheetModalProps['enableContentPanningGesture'];
|
|
16
|
+
/** Host keyboard policies; defaults retain HIG interactive/restore/adjustResize behavior. */
|
|
17
|
+
keyboardBehavior?: BottomSheetModalProps['keyboardBehavior'];
|
|
18
|
+
keyboardBlurBehavior?: BottomSheetModalProps['keyboardBlurBehavior'];
|
|
19
|
+
android_keyboardInputMode?: BottomSheetModalProps['android_keyboardInputMode'];
|
|
20
|
+
dismissible?: boolean;
|
|
21
|
+
returnFocusRef?: React.RefObject<React.ComponentRef<typeof View> | React.ComponentRef<typeof RNText> | React.ComponentRef<typeof TextInput> | null>;
|
|
22
|
+
/** Close button text and accessible name; defaults to HIGProvider `messages.close`. */
|
|
23
|
+
closeLabel?: string;
|
|
24
|
+
/** Called once after an accepted dismissal settles. Rejected or interrupted closes do not clear host card state. */
|
|
25
|
+
onDismiss?: () => void;
|
|
26
|
+
/** Observe backend detent changes after HIG updates its focus and controlled close state. */
|
|
27
|
+
onChange?: BottomSheetModalProps['onChange'];
|
|
28
|
+
/** Return true to consume Android Back, or false to defer to another host BackHandler. Omit for default sheet dismissal. */
|
|
29
|
+
onHardwareBackPress?: () => boolean;
|
|
30
|
+
/** Host geometry overrides; defaults to the real safe-area insets. Zero supports flush card stacks. */
|
|
31
|
+
topInset?: number;
|
|
32
|
+
bottomInset?: number;
|
|
33
|
+
/** Host-drawn handle and background slots. Use useColors() for host surfaces. */
|
|
34
|
+
handleComponent?: BottomSheetModalProps['handleComponent'];
|
|
35
|
+
handleStyle?: BottomSheetModalProps['handleStyle'];
|
|
36
|
+
handleIndicatorStyle?: BottomSheetModalProps['handleIndicatorStyle'];
|
|
37
|
+
backgroundComponent?: BottomSheetModalProps['backgroundComponent'];
|
|
38
|
+
backgroundStyle?: BottomSheetModalProps['backgroundStyle'];
|
|
39
|
+
/** Screen-level inline hosts may retain their existing sibling overlay order. */
|
|
40
|
+
containerStyle?: BottomSheetModalProps['containerStyle'];
|
|
41
|
+
/** Optional host animation and backdrop policies; HIG reduced-motion mapping remains applied. */
|
|
42
|
+
animateOnMount?: BottomSheetModalProps['animateOnMount'];
|
|
43
|
+
animationConfigs?: BottomSheetModalProps['animationConfigs'];
|
|
44
|
+
backdropComponent?: BottomSheetModalProps['backdropComponent'];
|
|
45
|
+
}
|
|
46
|
+
export type GestureSheetProps = GestureSheetCommonProps & (
|
|
47
|
+
/** Modal is the default. Inline retains the screen-level backend and its child state while closed. */
|
|
48
|
+
{
|
|
49
|
+
presentation?: 'modal';
|
|
50
|
+
modalRef?: React.Ref<BottomSheetModal>;
|
|
51
|
+
sheetRef?: never;
|
|
52
|
+
} | {
|
|
53
|
+
presentation: 'inline';
|
|
54
|
+
sheetRef?: React.Ref<BottomSheet>;
|
|
55
|
+
modalRef?: never;
|
|
56
|
+
}) & (
|
|
57
|
+
/** Fixed sizing keeps sorted increasing detents. Changes retain the current index or clamp a removed detent. */
|
|
58
|
+
{
|
|
59
|
+
enableDynamicSizing?: false;
|
|
60
|
+
snapPoints: readonly (number | `${number}%`)[];
|
|
61
|
+
initialIndex?: number;
|
|
62
|
+
maxDynamicContentSize?: never;
|
|
63
|
+
}
|
|
64
|
+
/** Content sizing uses one backend-measured detent and an optional finite positive point ceiling (default: container height), without fixed snap points or an initial detent index. */
|
|
65
|
+
| {
|
|
66
|
+
enableDynamicSizing: true;
|
|
67
|
+
snapPoints?: never;
|
|
68
|
+
initialIndex?: never;
|
|
69
|
+
maxDynamicContentSize?: BottomSheetModalProps['maxDynamicContentSize'];
|
|
70
|
+
});
|
|
71
|
+
/** Optional backend: host supplies GestureHandlerRootView, SafeAreaProvider and BottomSheetModalProvider. */
|
|
72
|
+
export declare function GestureSheet({ open, onOpenChange, title, description, children, contentMode, titleRef, presentation, sheetRef, snapPoints, enableDynamicSizing, maxDynamicContentSize, enableContentPanningGesture, keyboardBehavior, keyboardBlurBehavior, android_keyboardInputMode, initialIndex, dismissible, returnFocusRef, closeLabel, onDismiss, onChange, onHardwareBackPress, topInset, bottomInset, modalRef, handleComponent, handleStyle, handleIndicatorStyle, backgroundComponent, backgroundStyle, containerStyle, animateOnMount, animationConfigs, backdropComponent }: GestureSheetProps): React.JSX.Element;
|
|
73
|
+
export {};
|