@jztack/ui-native 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.
Files changed (100) hide show
  1. package/README.md +128 -2
  2. package/dist/Alert.d.ts +20 -0
  3. package/dist/Alert.js +14 -0
  4. package/dist/AppBar.d.ts +21 -0
  5. package/dist/AppBar.js +16 -0
  6. package/dist/Avatar.d.ts +21 -0
  7. package/dist/Avatar.js +23 -0
  8. package/dist/Badge.d.ts +15 -0
  9. package/dist/Badge.js +27 -0
  10. package/dist/BottomTabBar.d.ts +26 -0
  11. package/dist/BottomTabBar.js +39 -0
  12. package/dist/Button.d.ts +21 -0
  13. package/dist/Button.js +63 -0
  14. package/dist/Card.d.ts +37 -0
  15. package/dist/Card.js +41 -0
  16. package/dist/Checkbox.d.ts +11 -0
  17. package/dist/Checkbox.js +11 -0
  18. package/dist/ConfirmActionModal.d.ts +27 -0
  19. package/dist/ConfirmActionModal.js +43 -0
  20. package/dist/DeleteButton.d.ts +20 -0
  21. package/dist/DeleteButton.js +41 -0
  22. package/dist/Dialog.d.ts +10 -0
  23. package/dist/Dialog.js +10 -0
  24. package/dist/DropdownMenu.d.ts +25 -0
  25. package/dist/DropdownMenu.js +57 -0
  26. package/dist/EmptyState.d.ts +13 -0
  27. package/dist/EmptyState.js +10 -0
  28. package/dist/ErrorBoundary.d.ts +33 -0
  29. package/dist/ErrorBoundary.js +37 -0
  30. package/dist/Field.d.ts +24 -0
  31. package/dist/Field.js +20 -0
  32. package/dist/FormFields.d.ts +37 -0
  33. package/dist/FormFields.js +24 -0
  34. package/dist/FormPanel.d.ts +20 -0
  35. package/dist/FormPanel.js +14 -0
  36. package/dist/Input.d.ts +30 -0
  37. package/dist/Input.js +52 -0
  38. package/dist/OptionList.d.ts +25 -0
  39. package/dist/OptionList.js +15 -0
  40. package/dist/PageHeader.d.ts +13 -0
  41. package/dist/PageHeader.js +10 -0
  42. package/dist/Primitives.d.ts +636 -0
  43. package/dist/Primitives.js +5 -0
  44. package/dist/Progress.d.ts +8 -0
  45. package/dist/Progress.js +42 -0
  46. package/dist/RadioGroup.d.ts +15 -0
  47. package/dist/RadioGroup.js +11 -0
  48. package/dist/ScrollOverflowContainer.d.ts +14 -0
  49. package/dist/ScrollOverflowContainer.js +83 -0
  50. package/dist/SegmentedControl.d.ts +19 -0
  51. package/dist/SegmentedControl.js +15 -0
  52. package/dist/Select.d.ts +9 -0
  53. package/dist/Select.js +27 -0
  54. package/dist/Select.web.d.ts +10 -0
  55. package/dist/Select.web.js +41 -0
  56. package/dist/SelectTypes.d.ts +17 -0
  57. package/dist/SelectTypes.js +1 -0
  58. package/dist/Separator.d.ts +6 -0
  59. package/dist/Separator.js +9 -0
  60. package/dist/Sheet.d.ts +31 -0
  61. package/dist/Sheet.js +43 -0
  62. package/dist/Skeleton.d.ts +11 -0
  63. package/dist/Skeleton.js +30 -0
  64. package/dist/StartupScreen.d.ts +9 -0
  65. package/dist/StartupScreen.js +9 -0
  66. package/dist/StateViews.d.ts +13 -0
  67. package/dist/StateViews.js +14 -0
  68. package/dist/Switch.d.ts +13 -0
  69. package/dist/Switch.js +42 -0
  70. package/dist/Table.d.ts +22 -0
  71. package/dist/Table.js +17 -0
  72. package/dist/TextField.d.ts +22 -0
  73. package/dist/TextField.js +116 -0
  74. package/dist/Toast.d.ts +34 -0
  75. package/dist/Toast.js +92 -0
  76. package/dist/ToastHost.d.ts +6 -0
  77. package/dist/ToastHost.js +4 -0
  78. package/dist/ToastHost.web.d.ts +7 -0
  79. package/dist/ToastHost.web.js +11 -0
  80. package/dist/Toggle.d.ts +16 -0
  81. package/dist/Toggle.js +7 -0
  82. package/dist/ToggleGroup.d.ts +27 -0
  83. package/dist/ToggleGroup.js +27 -0
  84. package/dist/haptics.d.ts +45 -0
  85. package/dist/haptics.js +96 -0
  86. package/dist/index.d.ts +41 -0
  87. package/dist/index.js +46 -0
  88. package/dist/shadows.d.ts +28 -0
  89. package/dist/shadows.js +19 -0
  90. package/dist/theme.d.ts +23 -0
  91. package/dist/theme.js +19 -0
  92. package/dist/useDismissOnEscape.d.ts +7 -0
  93. package/dist/useDismissOnEscape.js +10 -0
  94. package/dist/useDismissOnEscape.web.d.ts +2 -0
  95. package/dist/useDismissOnEscape.web.js +14 -0
  96. package/dist/useResponsive.d.ts +28 -0
  97. package/dist/useResponsive.js +23 -0
  98. package/dist/useTextFieldCurrency.d.ts +9 -0
  99. package/dist/useTextFieldCurrency.js +45 -0
  100. package/package.json +52 -3
@@ -0,0 +1,28 @@
1
+ import { type ViewStyle } from 'react-native';
2
+ /**
3
+ * Centralized elevation/shadow scale for the design system.
4
+ *
5
+ * One spec, two renderings (tokens DESIGN §7 assigns this platform-forked
6
+ * helper to ui-native): web uses the CSS `boxShadow` property; native uses
7
+ * RN shadow* props. Android `elevation` is not folded in — Card passes its
8
+ * elevation through restyle, as TWJS always has.
9
+ */
10
+ export interface ShadowSpec {
11
+ readonly offsetY: number;
12
+ readonly radius: number;
13
+ readonly opacity: number;
14
+ }
15
+ export declare const shadows: {
16
+ readonly card: {
17
+ readonly offsetY: 4;
18
+ readonly radius: 12;
19
+ readonly opacity: 0.04;
20
+ };
21
+ readonly table: {
22
+ readonly offsetY: 2;
23
+ readonly radius: 6;
24
+ readonly opacity: 0.03;
25
+ };
26
+ };
27
+ export type ShadowLevel = keyof typeof shadows;
28
+ export declare function getShadowStyle(level: ShadowLevel): ViewStyle;
@@ -0,0 +1,19 @@
1
+ import { Platform } from 'react-native';
2
+ export const shadows = {
3
+ card: { offsetY: 4, radius: 12, opacity: 0.04 },
4
+ table: { offsetY: 2, radius: 6, opacity: 0.03 },
5
+ };
6
+ export function getShadowStyle(level) {
7
+ const spec = shadows[level];
8
+ if (Platform.OS === 'web') {
9
+ return {
10
+ boxShadow: `0px ${spec.offsetY}px ${spec.radius}px rgba(0,0,0,${spec.opacity})`,
11
+ };
12
+ }
13
+ return {
14
+ shadowColor: '#000',
15
+ shadowOffset: { width: 0, height: spec.offsetY },
16
+ shadowOpacity: spec.opacity,
17
+ shadowRadius: spec.radius,
18
+ };
19
+ }
@@ -0,0 +1,23 @@
1
+ import { getThemeForLocale } from '@jztack/tokens/restyle';
2
+ export declare const theme: {
3
+ colors: Record<string, string>;
4
+ spacing: Record<string, number>;
5
+ borderRadii: Record<string, number>;
6
+ breakpoints: Record<string, number>;
7
+ textVariants: Record<string, import("@jztack/tokens/restyle").RestyleTextVariant>;
8
+ layout: {
9
+ readonly minTableWidth: 600;
10
+ };
11
+ };
12
+ export declare const darkTheme: {
13
+ colors: Record<string, string>;
14
+ spacing: Record<string, number>;
15
+ borderRadii: Record<string, number>;
16
+ breakpoints: Record<string, number>;
17
+ textVariants: Record<string, import("@jztack/tokens/restyle").RestyleTextVariant>;
18
+ layout: {
19
+ readonly minTableWidth: 600;
20
+ };
21
+ };
22
+ export type Theme = typeof theme;
23
+ export { getThemeForLocale };
package/dist/theme.js ADDED
@@ -0,0 +1,19 @@
1
+ import { createThemeData, getThemeForLocale } from '@jztack/tokens/restyle';
2
+ import { createTheme } from '@shopify/restyle';
3
+ /**
4
+ * The twin owns no token values. The restyle theme is the tokens factory
5
+ * output wrapped in restyle's `createTheme` exactly once (DESIGN.md §5.1),
6
+ * plus the `layout` token TWJS's Table has always carried (the tokens
7
+ * contract has no layout slot; minTableWidth stays a package-level
8
+ * constant, per tokens DESIGN §4's platform-forked token note).
9
+ */
10
+ const layout = { minTableWidth: 600 };
11
+ export const theme = createTheme({
12
+ ...createThemeData('twjs', 'light'),
13
+ layout,
14
+ });
15
+ export const darkTheme = createTheme({
16
+ ...createThemeData('twjs', 'dark'),
17
+ layout,
18
+ });
19
+ export { getThemeForLocale };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Native resolution of the dismiss-on-Escape hook: there is no document
3
+ * keydown stream on native (Android back is handled by Modal's
4
+ * onRequestClose), so the hook is a no-op with the identical signature.
5
+ * The .web.tsx resolution carries the real listener.
6
+ */
7
+ export declare function useDismissOnEscape(active: boolean, close: () => void): void;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Native resolution of the dismiss-on-Escape hook: there is no document
3
+ * keydown stream on native (Android back is handled by Modal's
4
+ * onRequestClose), so the hook is a no-op with the identical signature.
5
+ * The .web.tsx resolution carries the real listener.
6
+ */
7
+ export function useDismissOnEscape(active, close) {
8
+ void active;
9
+ void close;
10
+ }
@@ -0,0 +1,2 @@
1
+ /** Web resolution: Escape dismisses the open overlay (DESIGN.md §7.2). */
2
+ export declare function useDismissOnEscape(active: boolean, close: () => void): void;
@@ -0,0 +1,14 @@
1
+ import { useEffect } from 'react';
2
+ /** Web resolution: Escape dismisses the open overlay (DESIGN.md §7.2). */
3
+ export function useDismissOnEscape(active, close) {
4
+ useEffect(() => {
5
+ if (!active || typeof document === 'undefined')
6
+ return;
7
+ const dismiss = (event) => {
8
+ if (event.key === 'Escape')
9
+ close();
10
+ };
11
+ document.addEventListener('keydown', dismiss);
12
+ return () => document.removeEventListener('keydown', dismiss);
13
+ }, [active, close]);
14
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Breakpoints come from the token contract — the single source the restyle
3
+ * theme is also emitted from, so responsive props and imperative checks
4
+ * cannot drift (DESIGN.md §5.5). The hand-synced duplicate const TWJS used
5
+ * to keep beside its theme is gone; this re-export exists so consumers keep
6
+ * one import surface.
7
+ */
8
+ export declare const BREAKPOINTS: {
9
+ readonly phone: 0;
10
+ readonly tablet: 768;
11
+ readonly desktop: 1024;
12
+ readonly wide: 1440;
13
+ };
14
+ /** Global maximum application container width (px) — `breakpoints.wide`. */
15
+ export declare const APP_MAX_WIDTH: 1440;
16
+ export interface ResponsiveInfo {
17
+ width: number;
18
+ height: number;
19
+ /** width < 768 — single-column / stacked layout, bottom-tab navigation. */
20
+ isPhone: boolean;
21
+ /** width >= 768 — wide enough for side-by-side layouts. */
22
+ isDesktop: boolean;
23
+ /** width >= 1024 — true desktop; opt into roomier multi-column layouts. */
24
+ isLargeScreen: boolean;
25
+ /** width >= 1440 — very wide monitors. */
26
+ isWideScreen: boolean;
27
+ }
28
+ export declare function useResponsive(): ResponsiveInfo;
@@ -0,0 +1,23 @@
1
+ import { breakpoints } from '@jztack/tokens';
2
+ import { useWindowDimensions } from 'react-native';
3
+ /**
4
+ * Breakpoints come from the token contract — the single source the restyle
5
+ * theme is also emitted from, so responsive props and imperative checks
6
+ * cannot drift (DESIGN.md §5.5). The hand-synced duplicate const TWJS used
7
+ * to keep beside its theme is gone; this re-export exists so consumers keep
8
+ * one import surface.
9
+ */
10
+ export const BREAKPOINTS = breakpoints;
11
+ /** Global maximum application container width (px) — `breakpoints.wide`. */
12
+ export const APP_MAX_WIDTH = breakpoints.wide;
13
+ export function useResponsive() {
14
+ const { width, height } = useWindowDimensions();
15
+ return {
16
+ width,
17
+ height,
18
+ isPhone: width < BREAKPOINTS.tablet,
19
+ isDesktop: width >= BREAKPOINTS.tablet,
20
+ isLargeScreen: width >= BREAKPOINTS.desktop,
21
+ isWideScreen: width >= BREAKPOINTS.wide,
22
+ };
23
+ }
@@ -0,0 +1,9 @@
1
+ type Currency = 'USD' | 'THB';
2
+ export type BaseValuation = {
3
+ amount: number;
4
+ currency: Currency;
5
+ };
6
+ export type ExchangeRateResolver = (currency: Currency) => Promise<number | undefined>;
7
+ export declare function registerExchangeRateResolver(resolver: ExchangeRateResolver): void;
8
+ export declare function useCurrencyConversion(baseValuation?: BaseValuation): string | null;
9
+ export {};
@@ -0,0 +1,45 @@
1
+ import { useEffect, useState } from 'react';
2
+ // Keep conversions available offline when the price book cannot supply a rate.
3
+ // (Deliberate offline-first behaviour, ported verbatim from TWJS — the twin
4
+ // does not silently change it; rates remain the resolver's concern.)
5
+ const FALLBACK_RATES_MMK = {
6
+ USD: 4200,
7
+ THB: 115,
8
+ };
9
+ let rateResolver = null;
10
+ export function registerExchangeRateResolver(resolver) {
11
+ rateResolver = resolver;
12
+ }
13
+ async function convertWithRate(currency, update) {
14
+ const fallbackRate = FALLBACK_RATES_MMK[currency];
15
+ try {
16
+ const rate = rateResolver ? await rateResolver(currency) : undefined;
17
+ update(rate === undefined ? fallbackRate : rate);
18
+ }
19
+ catch (error) {
20
+ console.warn('Failed to perform currency conversion in TextField:', error);
21
+ update(fallbackRate);
22
+ }
23
+ }
24
+ export function useCurrencyConversion(baseValuation) {
25
+ const [convertedValue, setConvertedValue] = useState(null);
26
+ const amount = baseValuation?.amount;
27
+ const currency = baseValuation?.currency;
28
+ useEffect(() => {
29
+ if (amount === undefined || !currency) {
30
+ setConvertedValue(null);
31
+ return;
32
+ }
33
+ let active = true;
34
+ void convertWithRate(currency, (rate) => {
35
+ if (active) {
36
+ const kyatAmount = Math.round(amount * rate);
37
+ setConvertedValue(`${kyatAmount.toLocaleString()} MMK`);
38
+ }
39
+ });
40
+ return () => {
41
+ active = false;
42
+ };
43
+ }, [amount, currency]);
44
+ return convertedValue;
45
+ }
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
+ "dependencies": {
3
+ "@jztack/tokens": "0.2.0"
4
+ },
5
+ "description": "The React Native twin of @jztack/ui: same component names, variants, and prop specs, implemented on @shopify/restyle and consuming @jztack/tokens' restyle emitter. Rebuild of TWJS's @burma-inventory/ui-components.",
6
+ "devDependencies": {
7
+ "@babel/core": "^7.29.7",
8
+ "@react-native/jest-preset": "0.88.0",
9
+ "@shopify/restyle": "^2.4.5",
10
+ "@testing-library/react": "^16.3.2",
11
+ "@testing-library/react-native": "14.1.0",
12
+ "@types/jest": "30.0.0",
13
+ "@types/node": "24.19.2",
14
+ "@types/react": "^19.3.0",
15
+ "@types/react-dom": "^19.3.0",
16
+ "babel-jest": "^30.5.0",
17
+ "babel-preset-expo": "~58.0.17",
18
+ "expo-haptics": "~58.0.8",
19
+ "jest": "^30.5.0",
20
+ "jest-environment-jsdom": "^30.5.0",
21
+ "lucide-react-native": "^1.14.0",
22
+ "react": "^19.3.1",
23
+ "react-dom": "^19.3.1",
24
+ "react-native": "0.88.0",
25
+ "react-native-svg": "15.16.0",
26
+ "react-native-web": "~0.21.4",
27
+ "typescript": "^7.0.2"
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "default": "./dist/index.js",
32
+ "types": "./dist/index.d.ts"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist"
37
+ ],
2
38
  "name": "@jztack/ui-native",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
39
+ "peerDependencies": {
40
+ "@shopify/restyle": "^2.4.5",
41
+ "expo-haptics": "~58.0.8",
42
+ "lucide-react-native": "^1.14.0",
43
+ "react": "19.3.1",
44
+ "react-native": "0.88.0"
45
+ },
46
+ "sideEffects": false,
47
+ "type": "module",
48
+ "version": "0.2.0",
49
+ "scripts": {
50
+ "build": "tsc -p tsconfig.build.json",
51
+ "test": "jest",
52
+ "test:coverage": "jest --coverage",
53
+ "typecheck": "tsc -p tsconfig.json --noEmit"
54
+ }
6
55
  }