@onlynative/components 0.1.1-alpha.1 → 0.1.1-alpha.3

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 CHANGED
@@ -5,7 +5,13 @@ Material Design 3 UI components for React Native, part of [OnlyNative UI](https:
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- pnpm add @onlynative/core @onlynative/components @expo/vector-icons react-native-safe-area-context
8
+ pnpm add @onlynative/core @onlynative/components react-native-safe-area-context
9
+ ```
10
+
11
+ **Optional** — only needed if you plan to use icons in your app:
12
+
13
+ ```bash
14
+ pnpm add @expo/vector-icons
9
15
  ```
10
16
 
11
17
  Wrap your app with `ThemeProvider` from `@onlynative/core` (see [@onlynative/core](https://www.npmjs.com/package/@onlynative/core)).
@@ -6,6 +6,19 @@ import '@expo/vector-icons/MaterialCommunityIcons';
6
6
 
7
7
  /** Size/layout variant of the AppBar. */
8
8
  type AppBarVariant = 'small' | 'center-aligned' | 'medium' | 'large';
9
+ /**
10
+ * Color scheme that determines the default container and content colors.
11
+ *
12
+ * - `'surface'` — `surface` / `onSurface` (default, elevated uses `surfaceContainer`)
13
+ * - `'surfaceContainerLowest'` — `surfaceContainerLowest` / `onSurface`
14
+ * - `'surfaceContainerLow'` — `surfaceContainerLow` / `onSurface`
15
+ * - `'surfaceContainer'` — `surfaceContainer` / `onSurface`
16
+ * - `'surfaceContainerHigh'` — `surfaceContainerHigh` / `onSurface`
17
+ * - `'surfaceContainerHighest'` — `surfaceContainerHighest` / `onSurface`
18
+ * - `'primary'` — `primary` / `onPrimary`
19
+ * - `'primaryContainer'` — `primaryContainer` / `onPrimaryContainer`
20
+ */
21
+ type AppBarColorScheme = 'surface' | 'surfaceContainerLowest' | 'surfaceContainerLow' | 'surfaceContainer' | 'surfaceContainerHigh' | 'surfaceContainerHighest' | 'primary' | 'primaryContainer';
9
22
  /** A single action item rendered in the AppBar trailing slot. */
10
23
  interface AppBarAction {
11
24
  /** MaterialCommunityIcons icon name to render. */
@@ -28,6 +41,12 @@ interface AppBarProps {
28
41
  * @default 'small'
29
42
  */
30
43
  variant?: AppBarVariant;
44
+ /**
45
+ * Color scheme that determines the default container and content colors.
46
+ * `containerColor` and `contentColor` props override these defaults.
47
+ * @default 'surface'
48
+ */
49
+ colorScheme?: AppBarColorScheme;
31
50
  /**
32
51
  * When `true`, renders a back button in the leading slot.
33
52
  * @default false
@@ -66,6 +85,6 @@ interface AppBarProps {
66
85
  style?: StyleProp<ViewStyle>;
67
86
  }
68
87
 
69
- declare function AppBar({ title, variant, canGoBack, onBackPress, insetTop, elevated, leading, trailing, actions, containerColor, contentColor, titleStyle, style, }: AppBarProps): react_jsx_runtime.JSX.Element;
88
+ declare function AppBar({ title, variant, colorScheme, canGoBack, onBackPress, insetTop, elevated, leading, trailing, actions, containerColor, contentColor, titleStyle, style, }: AppBarProps): react_jsx_runtime.JSX.Element;
70
89
 
71
- export { AppBar, type AppBarAction, type AppBarProps, type AppBarVariant };
90
+ export { AppBar, type AppBarAction, type AppBarColorScheme, type AppBarProps, type AppBarVariant };
@@ -648,21 +648,74 @@ function Typography({
648
648
  // src/appbar/styles.ts
649
649
  var import_react_native6 = require("react-native");
650
650
  var import_core3 = require("@onlynative/core");
651
- function createStyles2(theme) {
651
+ function getColorSchemeColors(theme, colorScheme) {
652
+ switch (colorScheme) {
653
+ case "surfaceContainerLowest":
654
+ return {
655
+ containerColor: theme.colors.surfaceContainerLowest,
656
+ elevatedContainerColor: theme.colors.surfaceContainerLowest,
657
+ contentColor: theme.colors.onSurface
658
+ };
659
+ case "surfaceContainerLow":
660
+ return {
661
+ containerColor: theme.colors.surfaceContainerLow,
662
+ elevatedContainerColor: theme.colors.surfaceContainerLow,
663
+ contentColor: theme.colors.onSurface
664
+ };
665
+ case "surfaceContainer":
666
+ return {
667
+ containerColor: theme.colors.surfaceContainer,
668
+ elevatedContainerColor: theme.colors.surfaceContainer,
669
+ contentColor: theme.colors.onSurface
670
+ };
671
+ case "surfaceContainerHigh":
672
+ return {
673
+ containerColor: theme.colors.surfaceContainerHigh,
674
+ elevatedContainerColor: theme.colors.surfaceContainerHigh,
675
+ contentColor: theme.colors.onSurface
676
+ };
677
+ case "surfaceContainerHighest":
678
+ return {
679
+ containerColor: theme.colors.surfaceContainerHighest,
680
+ elevatedContainerColor: theme.colors.surfaceContainerHighest,
681
+ contentColor: theme.colors.onSurface
682
+ };
683
+ case "primary":
684
+ return {
685
+ containerColor: theme.colors.primary,
686
+ elevatedContainerColor: theme.colors.primary,
687
+ contentColor: theme.colors.onPrimary
688
+ };
689
+ case "primaryContainer":
690
+ return {
691
+ containerColor: theme.colors.primaryContainer,
692
+ elevatedContainerColor: theme.colors.primaryContainer,
693
+ contentColor: theme.colors.onPrimaryContainer
694
+ };
695
+ case "surface":
696
+ default:
697
+ return {
698
+ containerColor: theme.colors.surface,
699
+ elevatedContainerColor: theme.colors.surfaceContainer,
700
+ contentColor: theme.colors.onSurface
701
+ };
702
+ }
703
+ }
704
+ function createStyles2(theme, schemeColors) {
652
705
  var _a;
653
706
  const topAppBar = (_a = theme.topAppBar) != null ? _a : import_core3.defaultTopAppBarTokens;
654
707
  return import_react_native6.StyleSheet.create({
655
708
  root: {
656
- backgroundColor: theme.colors.surface
709
+ backgroundColor: schemeColors.containerColor
657
710
  },
658
711
  safeArea: {
659
- backgroundColor: theme.colors.surface
712
+ backgroundColor: schemeColors.containerColor
660
713
  },
661
714
  elevatedRoot: {
662
- backgroundColor: theme.colors.surfaceContainer
715
+ backgroundColor: schemeColors.elevatedContainerColor
663
716
  },
664
717
  elevatedSafeArea: {
665
- backgroundColor: theme.colors.surfaceContainer
718
+ backgroundColor: schemeColors.elevatedContainerColor
666
719
  },
667
720
  smallContainer: {
668
721
  height: topAppBar.smallContainerHeight,
@@ -779,6 +832,7 @@ function measureWidth(event) {
779
832
  function AppBar({
780
833
  title,
781
834
  variant = "small",
835
+ colorScheme = "surface",
782
836
  canGoBack = false,
783
837
  onBackPress,
784
838
  insetTop = false,
@@ -794,12 +848,20 @@ function AppBar({
794
848
  var _a;
795
849
  const theme = (0, import_core4.useTheme)();
796
850
  const topAppBar = (_a = theme.topAppBar) != null ? _a : import_core4.defaultTopAppBarTokens;
797
- const styles = (0, import_react3.useMemo)(() => createStyles2(theme), [theme]);
851
+ const schemeColors = (0, import_react3.useMemo)(
852
+ () => getColorSchemeColors(theme, colorScheme),
853
+ [theme, colorScheme]
854
+ );
855
+ const resolvedContentColor = contentColor != null ? contentColor : schemeColors.contentColor;
856
+ const styles = (0, import_react3.useMemo)(
857
+ () => createStyles2(theme, schemeColors),
858
+ [theme, schemeColors]
859
+ );
798
860
  const [leadingWidth, setLeadingWidth] = (0, import_react3.useState)(0);
799
861
  const [actionsWidth, setActionsWidth] = (0, import_react3.useState)(0);
800
862
  const titleColorStyle = (0, import_react3.useMemo)(
801
- () => ({ color: contentColor != null ? contentColor : theme.colors.onSurface }),
802
- [contentColor, theme.colors.onSurface]
863
+ () => ({ color: resolvedContentColor }),
864
+ [resolvedContentColor]
803
865
  );
804
866
  const size = resolveSize(variant);
805
867
  const titleVariant = titleVariantBySize[size];
@@ -829,19 +891,12 @@ function AppBar({
829
891
  icon: getBackIcon(),
830
892
  size: "medium",
831
893
  variant: "standard",
832
- iconColor: contentColor != null ? contentColor : theme.colors.onSurface,
894
+ iconColor: resolvedContentColor,
833
895
  accessibilityLabel: "Go back",
834
896
  onPress: onBackPress
835
897
  }
836
898
  ) });
837
- }, [
838
- canGoBack,
839
- contentColor,
840
- leading,
841
- onBackPress,
842
- styles.iconFrame,
843
- theme.colors.onSurface
844
- ]);
899
+ }, [canGoBack, resolvedContentColor, leading, onBackPress, styles.iconFrame]);
845
900
  const actionsContent = (0, import_react3.useMemo)(() => {
846
901
  if (trailing) {
847
902
  return trailing;
@@ -859,7 +914,7 @@ function AppBar({
859
914
  icon: action.icon,
860
915
  size: "medium",
861
916
  variant: "standard",
862
- iconColor: contentColor,
917
+ iconColor: resolvedContentColor,
863
918
  accessibilityLabel: action.accessibilityLabel,
864
919
  onPress: action.onPress,
865
920
  disabled: action.disabled
@@ -868,7 +923,7 @@ function AppBar({
868
923
  },
869
924
  `${String(action.icon)}-${index}`
870
925
  )) });
871
- }, [actions, contentColor, styles.actionsRow, styles.iconFrame, trailing]);
926
+ }, [actions, resolvedContentColor, styles.actionsRow, styles.iconFrame, trailing]);
872
927
  const onLeadingLayout = (0, import_react3.useCallback)((event) => {
873
928
  const nextWidth = measureWidth(event);
874
929
  setLeadingWidth((currentWidth) => {
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { Box, BoxProps, Column, ColumnProps, Grid, GridProps, Layout, LayoutProp
3
3
  export { Button, ButtonProps, ButtonVariant } from './button/index.js';
4
4
  export { IconButton } from './icon-button/index.js';
5
5
  export { I as IconButtonProps, a as IconButtonSize, b as IconButtonVariant } from './types-D3hlyvz-.js';
6
- export { AppBar, AppBarAction, AppBarProps, AppBarVariant } from './appbar/index.js';
6
+ export { AppBar, AppBarAction, AppBarColorScheme, AppBarProps, AppBarVariant } from './appbar/index.js';
7
7
  export { Card, CardProps, CardVariant } from './card/index.js';
8
8
  export { Chip, ChipProps, ChipVariant } from './chip/index.js';
9
9
  export { Checkbox, CheckboxProps } from './checkbox/index.js';
package/dist/index.js CHANGED
@@ -1280,21 +1280,74 @@ var import_core8 = require("@onlynative/core");
1280
1280
  // src/appbar/styles.ts
1281
1281
  var import_react_native13 = require("react-native");
1282
1282
  var import_core7 = require("@onlynative/core");
1283
- function createStyles3(theme) {
1283
+ function getColorSchemeColors(theme, colorScheme) {
1284
+ switch (colorScheme) {
1285
+ case "surfaceContainerLowest":
1286
+ return {
1287
+ containerColor: theme.colors.surfaceContainerLowest,
1288
+ elevatedContainerColor: theme.colors.surfaceContainerLowest,
1289
+ contentColor: theme.colors.onSurface
1290
+ };
1291
+ case "surfaceContainerLow":
1292
+ return {
1293
+ containerColor: theme.colors.surfaceContainerLow,
1294
+ elevatedContainerColor: theme.colors.surfaceContainerLow,
1295
+ contentColor: theme.colors.onSurface
1296
+ };
1297
+ case "surfaceContainer":
1298
+ return {
1299
+ containerColor: theme.colors.surfaceContainer,
1300
+ elevatedContainerColor: theme.colors.surfaceContainer,
1301
+ contentColor: theme.colors.onSurface
1302
+ };
1303
+ case "surfaceContainerHigh":
1304
+ return {
1305
+ containerColor: theme.colors.surfaceContainerHigh,
1306
+ elevatedContainerColor: theme.colors.surfaceContainerHigh,
1307
+ contentColor: theme.colors.onSurface
1308
+ };
1309
+ case "surfaceContainerHighest":
1310
+ return {
1311
+ containerColor: theme.colors.surfaceContainerHighest,
1312
+ elevatedContainerColor: theme.colors.surfaceContainerHighest,
1313
+ contentColor: theme.colors.onSurface
1314
+ };
1315
+ case "primary":
1316
+ return {
1317
+ containerColor: theme.colors.primary,
1318
+ elevatedContainerColor: theme.colors.primary,
1319
+ contentColor: theme.colors.onPrimary
1320
+ };
1321
+ case "primaryContainer":
1322
+ return {
1323
+ containerColor: theme.colors.primaryContainer,
1324
+ elevatedContainerColor: theme.colors.primaryContainer,
1325
+ contentColor: theme.colors.onPrimaryContainer
1326
+ };
1327
+ case "surface":
1328
+ default:
1329
+ return {
1330
+ containerColor: theme.colors.surface,
1331
+ elevatedContainerColor: theme.colors.surfaceContainer,
1332
+ contentColor: theme.colors.onSurface
1333
+ };
1334
+ }
1335
+ }
1336
+ function createStyles3(theme, schemeColors) {
1284
1337
  var _a;
1285
1338
  const topAppBar = (_a = theme.topAppBar) != null ? _a : import_core7.defaultTopAppBarTokens;
1286
1339
  return import_react_native13.StyleSheet.create({
1287
1340
  root: {
1288
- backgroundColor: theme.colors.surface
1341
+ backgroundColor: schemeColors.containerColor
1289
1342
  },
1290
1343
  safeArea: {
1291
- backgroundColor: theme.colors.surface
1344
+ backgroundColor: schemeColors.containerColor
1292
1345
  },
1293
1346
  elevatedRoot: {
1294
- backgroundColor: theme.colors.surfaceContainer
1347
+ backgroundColor: schemeColors.elevatedContainerColor
1295
1348
  },
1296
1349
  elevatedSafeArea: {
1297
- backgroundColor: theme.colors.surfaceContainer
1350
+ backgroundColor: schemeColors.elevatedContainerColor
1298
1351
  },
1299
1352
  smallContainer: {
1300
1353
  height: topAppBar.smallContainerHeight,
@@ -1411,6 +1464,7 @@ function measureWidth(event) {
1411
1464
  function AppBar({
1412
1465
  title,
1413
1466
  variant = "small",
1467
+ colorScheme = "surface",
1414
1468
  canGoBack = false,
1415
1469
  onBackPress,
1416
1470
  insetTop = false,
@@ -1426,12 +1480,20 @@ function AppBar({
1426
1480
  var _a;
1427
1481
  const theme = (0, import_core8.useTheme)();
1428
1482
  const topAppBar = (_a = theme.topAppBar) != null ? _a : import_core8.defaultTopAppBarTokens;
1429
- const styles3 = (0, import_react9.useMemo)(() => createStyles3(theme), [theme]);
1483
+ const schemeColors = (0, import_react9.useMemo)(
1484
+ () => getColorSchemeColors(theme, colorScheme),
1485
+ [theme, colorScheme]
1486
+ );
1487
+ const resolvedContentColor = contentColor != null ? contentColor : schemeColors.contentColor;
1488
+ const styles3 = (0, import_react9.useMemo)(
1489
+ () => createStyles3(theme, schemeColors),
1490
+ [theme, schemeColors]
1491
+ );
1430
1492
  const [leadingWidth, setLeadingWidth] = (0, import_react9.useState)(0);
1431
1493
  const [actionsWidth, setActionsWidth] = (0, import_react9.useState)(0);
1432
1494
  const titleColorStyle = (0, import_react9.useMemo)(
1433
- () => ({ color: contentColor != null ? contentColor : theme.colors.onSurface }),
1434
- [contentColor, theme.colors.onSurface]
1495
+ () => ({ color: resolvedContentColor }),
1496
+ [resolvedContentColor]
1435
1497
  );
1436
1498
  const size = resolveSize(variant);
1437
1499
  const titleVariant = titleVariantBySize[size];
@@ -1461,19 +1523,12 @@ function AppBar({
1461
1523
  icon: getBackIcon(),
1462
1524
  size: "medium",
1463
1525
  variant: "standard",
1464
- iconColor: contentColor != null ? contentColor : theme.colors.onSurface,
1526
+ iconColor: resolvedContentColor,
1465
1527
  accessibilityLabel: "Go back",
1466
1528
  onPress: onBackPress
1467
1529
  }
1468
1530
  ) });
1469
- }, [
1470
- canGoBack,
1471
- contentColor,
1472
- leading,
1473
- onBackPress,
1474
- styles3.iconFrame,
1475
- theme.colors.onSurface
1476
- ]);
1531
+ }, [canGoBack, resolvedContentColor, leading, onBackPress, styles3.iconFrame]);
1477
1532
  const actionsContent = (0, import_react9.useMemo)(() => {
1478
1533
  if (trailing) {
1479
1534
  return trailing;
@@ -1491,7 +1546,7 @@ function AppBar({
1491
1546
  icon: action.icon,
1492
1547
  size: "medium",
1493
1548
  variant: "standard",
1494
- iconColor: contentColor,
1549
+ iconColor: resolvedContentColor,
1495
1550
  accessibilityLabel: action.accessibilityLabel,
1496
1551
  onPress: action.onPress,
1497
1552
  disabled: action.disabled
@@ -1500,7 +1555,7 @@ function AppBar({
1500
1555
  },
1501
1556
  `${String(action.icon)}-${index}`
1502
1557
  )) });
1503
- }, [actions, contentColor, styles3.actionsRow, styles3.iconFrame, trailing]);
1558
+ }, [actions, resolvedContentColor, styles3.actionsRow, styles3.iconFrame, trailing]);
1504
1559
  const onLeadingLayout = (0, import_react9.useCallback)((event) => {
1505
1560
  const nextWidth = measureWidth(event);
1506
1561
  setLeadingWidth((currentWidth) => {
package/package.json CHANGED
@@ -1,67 +1,97 @@
1
1
  {
2
2
  "name": "@onlynative/components",
3
- "version": "0.1.1-alpha.1",
3
+ "version": "0.1.1-alpha.3",
4
4
  "description": "Material Design 3 UI components for React Native — Button, Card, Chip, TextField, and more.",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.js",
9
9
  "types": "dist/index.d.ts",
10
+ "react-native": "src/index.ts",
11
+ "source": "src/index.ts",
10
12
  "exports": {
11
13
  ".": {
12
14
  "types": "./dist/index.d.ts",
15
+ "react-native": "./src/index.ts",
16
+ "browser": "./src/index.ts",
13
17
  "default": "./dist/index.js"
14
18
  },
15
19
  "./typography": {
16
20
  "types": "./dist/typography/index.d.ts",
21
+ "react-native": "./src/typography/index.ts",
22
+ "browser": "./src/typography/index.ts",
17
23
  "default": "./dist/typography/index.js"
18
24
  },
19
25
  "./layout": {
20
26
  "types": "./dist/layout/index.d.ts",
27
+ "react-native": "./src/layout/index.ts",
28
+ "browser": "./src/layout/index.ts",
21
29
  "default": "./dist/layout/index.js"
22
30
  },
23
31
  "./button": {
24
32
  "types": "./dist/button/index.d.ts",
33
+ "react-native": "./src/button/index.ts",
34
+ "browser": "./src/button/index.ts",
25
35
  "default": "./dist/button/index.js"
26
36
  },
27
37
  "./icon-button": {
28
38
  "types": "./dist/icon-button/index.d.ts",
39
+ "react-native": "./src/icon-button/index.ts",
40
+ "browser": "./src/icon-button/index.ts",
29
41
  "default": "./dist/icon-button/index.js"
30
42
  },
31
43
  "./appbar": {
32
44
  "types": "./dist/appbar/index.d.ts",
45
+ "react-native": "./src/appbar/index.ts",
46
+ "browser": "./src/appbar/index.ts",
33
47
  "default": "./dist/appbar/index.js"
34
48
  },
35
49
  "./card": {
36
50
  "types": "./dist/card/index.d.ts",
51
+ "react-native": "./src/card/index.ts",
52
+ "browser": "./src/card/index.ts",
37
53
  "default": "./dist/card/index.js"
38
54
  },
39
55
  "./chip": {
40
56
  "types": "./dist/chip/index.d.ts",
57
+ "react-native": "./src/chip/index.ts",
58
+ "browser": "./src/chip/index.ts",
41
59
  "default": "./dist/chip/index.js"
42
60
  },
43
61
  "./checkbox": {
44
62
  "types": "./dist/checkbox/index.d.ts",
63
+ "react-native": "./src/checkbox/index.ts",
64
+ "browser": "./src/checkbox/index.ts",
45
65
  "default": "./dist/checkbox/index.js"
46
66
  },
47
67
  "./radio": {
48
68
  "types": "./dist/radio/index.d.ts",
69
+ "react-native": "./src/radio/index.ts",
70
+ "browser": "./src/radio/index.ts",
49
71
  "default": "./dist/radio/index.js"
50
72
  },
51
73
  "./switch": {
52
74
  "types": "./dist/switch/index.d.ts",
75
+ "react-native": "./src/switch/index.ts",
76
+ "browser": "./src/switch/index.ts",
53
77
  "default": "./dist/switch/index.js"
54
78
  },
55
79
  "./text-field": {
56
80
  "types": "./dist/text-field/index.d.ts",
81
+ "react-native": "./src/text-field/index.ts",
82
+ "browser": "./src/text-field/index.ts",
57
83
  "default": "./dist/text-field/index.js"
58
84
  },
59
85
  "./list": {
60
86
  "types": "./dist/list/index.d.ts",
87
+ "react-native": "./src/list/index.ts",
88
+ "browser": "./src/list/index.ts",
61
89
  "default": "./dist/list/index.js"
62
90
  },
63
91
  "./keyboard-avoiding-wrapper": {
64
92
  "types": "./dist/keyboard-avoiding-wrapper/index.d.ts",
93
+ "react-native": "./src/keyboard-avoiding-wrapper/index.ts",
94
+ "browser": "./src/keyboard-avoiding-wrapper/index.ts",
65
95
  "default": "./dist/keyboard-avoiding-wrapper/index.js"
66
96
  }
67
97
  },
@@ -109,8 +139,7 @@
109
139
  }
110
140
  },
111
141
  "publishConfig": {
112
- "access": "public",
113
- "provenance": true
142
+ "access": "public"
114
143
  },
115
144
  "files": [
116
145
  "dist"
@@ -136,7 +165,7 @@
136
165
  },
137
166
  "peerDependencies": {
138
167
  "@expo/vector-icons": ">=14.0.0",
139
- "@onlynative/core": ">=0.1.1-alpha.1",
168
+ "@onlynative/core": ">=0.1.1-alpha.3",
140
169
  "react": ">=18.0.0",
141
170
  "react-native": ">=0.72.0",
142
171
  "react-native-safe-area-context": ">=4.0.0"