@dryanovski/react-native-components 1.0.6 → 1.0.8

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/lib/module/assets/fonts/CodanBold.ttf +0 -0
  2. package/lib/module/assets/fonts/CodanBook.ttf +0 -0
  3. package/lib/module/assets/fonts/CodanLight.ttf +0 -0
  4. package/lib/module/assets/fonts/CodanMedium.ttf +0 -0
  5. package/lib/module/assets/fonts/CodanRegular.ttf +0 -0
  6. package/lib/module/components/Button/Button.js +41 -0
  7. package/lib/module/components/Button/Button.js.map +1 -0
  8. package/lib/module/components/Button/DangerButton.js +19 -0
  9. package/lib/module/components/Button/DangerButton.js.map +1 -0
  10. package/lib/module/components/Button/GhostButton.js +15 -0
  11. package/lib/module/components/Button/GhostButton.js.map +1 -0
  12. package/lib/module/components/Button/PrimaryButton.js +18 -0
  13. package/lib/module/components/Button/PrimaryButton.js.map +1 -0
  14. package/lib/module/components/Button/SecondaryButton.js +18 -0
  15. package/lib/module/components/Button/SecondaryButton.js.map +1 -0
  16. package/lib/module/components/Button/style.js +66 -0
  17. package/lib/module/components/Button/style.js.map +1 -0
  18. package/lib/module/components/Button/types.js +4 -0
  19. package/lib/module/components/Button/types.js.map +1 -0
  20. package/lib/module/components/Divider/Divider.js +33 -0
  21. package/lib/module/components/Divider/Divider.js.map +1 -0
  22. package/lib/module/components/Divider/styles.js +2 -0
  23. package/lib/module/components/Divider/styles.js.map +1 -0
  24. package/lib/module/components/Divider/types.js +4 -0
  25. package/lib/module/components/Divider/types.js.map +1 -0
  26. package/lib/module/components/Layout/HStack.js +24 -0
  27. package/lib/module/components/Layout/HStack.js.map +1 -0
  28. package/lib/module/components/Layout/VStack.js +24 -0
  29. package/lib/module/components/Layout/VStack.js.map +1 -0
  30. package/lib/module/components/Layout/layout.types.js +4 -0
  31. package/lib/module/components/Layout/layout.types.js.map +1 -0
  32. package/lib/module/index.js +17 -0
  33. package/lib/module/index.js.map +1 -1
  34. package/lib/module/providers/ThemeProvider.js +20 -1
  35. package/lib/module/providers/ThemeProvider.js.map +1 -1
  36. package/lib/module/utils/fontScale.js +66 -0
  37. package/lib/module/utils/fontScale.js.map +1 -0
  38. package/lib/module/utils/getDeviceType.js +20 -0
  39. package/lib/module/utils/getDeviceType.js.map +1 -0
  40. package/lib/module/utils/getScreenSizeCategory.js +16 -0
  41. package/lib/module/utils/getScreenSizeCategory.js.map +1 -0
  42. package/lib/typescript/src/components/Button/Button.d.ts +8 -0
  43. package/lib/typescript/src/components/Button/Button.d.ts.map +1 -0
  44. package/lib/typescript/src/components/Button/DangerButton.d.ts +8 -0
  45. package/lib/typescript/src/components/Button/DangerButton.d.ts.map +1 -0
  46. package/lib/typescript/src/components/Button/GhostButton.d.ts +4 -0
  47. package/lib/typescript/src/components/Button/GhostButton.d.ts.map +1 -0
  48. package/lib/typescript/src/components/Button/PrimaryButton.d.ts +7 -0
  49. package/lib/typescript/src/components/Button/PrimaryButton.d.ts.map +1 -0
  50. package/lib/typescript/src/components/Button/SecondaryButton.d.ts +7 -0
  51. package/lib/typescript/src/components/Button/SecondaryButton.d.ts.map +1 -0
  52. package/lib/typescript/src/components/Button/style.d.ts +64 -0
  53. package/lib/typescript/src/components/Button/style.d.ts.map +1 -0
  54. package/lib/typescript/src/components/Button/types.d.ts +51 -0
  55. package/lib/typescript/src/components/Button/types.d.ts.map +1 -0
  56. package/lib/typescript/src/components/Divider/Divider.d.ts +5 -0
  57. package/lib/typescript/src/components/Divider/Divider.d.ts.map +1 -0
  58. package/lib/typescript/src/components/Divider/styles.d.ts +1 -0
  59. package/lib/typescript/src/components/Divider/styles.d.ts.map +1 -0
  60. package/lib/typescript/src/components/Divider/types.d.ts +31 -0
  61. package/lib/typescript/src/components/Divider/types.d.ts.map +1 -0
  62. package/lib/typescript/src/components/Layout/HStack.d.ts +4 -0
  63. package/lib/typescript/src/components/Layout/HStack.d.ts.map +1 -0
  64. package/lib/typescript/src/components/Layout/VStack.d.ts +4 -0
  65. package/lib/typescript/src/components/Layout/VStack.d.ts.map +1 -0
  66. package/lib/typescript/src/components/Layout/layout.types.d.ts +8 -0
  67. package/lib/typescript/src/components/Layout/layout.types.d.ts.map +1 -0
  68. package/lib/typescript/src/index.d.ts +15 -0
  69. package/lib/typescript/src/index.d.ts.map +1 -1
  70. package/lib/typescript/src/providers/ThemeProvider.d.ts.map +1 -1
  71. package/lib/typescript/src/utils/fontScale.d.ts +2 -0
  72. package/lib/typescript/src/utils/fontScale.d.ts.map +1 -0
  73. package/lib/typescript/src/utils/getDeviceType.d.ts +2 -0
  74. package/lib/typescript/src/utils/getDeviceType.d.ts.map +1 -0
  75. package/lib/typescript/src/utils/getScreenSizeCategory.d.ts +2 -0
  76. package/lib/typescript/src/utils/getScreenSizeCategory.d.ts.map +1 -0
  77. package/package.json +4 -3
  78. package/src/assets/fonts/CodanBold.ttf +0 -0
  79. package/src/assets/fonts/CodanBook.ttf +0 -0
  80. package/src/assets/fonts/CodanLight.ttf +0 -0
  81. package/src/assets/fonts/CodanMedium.ttf +0 -0
  82. package/src/assets/fonts/CodanRegular.ttf +0 -0
  83. package/src/components/Button/Button.tsx +55 -0
  84. package/src/components/Button/DangerButton.tsx +17 -0
  85. package/src/components/Button/GhostButton.tsx +13 -0
  86. package/src/components/Button/PrimaryButton.tsx +16 -0
  87. package/src/components/Button/SecondaryButton.tsx +16 -0
  88. package/src/components/Button/style.ts +76 -0
  89. package/src/components/Button/types.ts +62 -0
  90. package/src/components/Divider/Divider.tsx +28 -0
  91. package/src/components/Divider/styles.ts +0 -0
  92. package/src/components/Divider/types.ts +36 -0
  93. package/src/components/Layout/HStack.tsx +19 -0
  94. package/src/components/Layout/VStack.tsx +19 -0
  95. package/src/components/Layout/layout.types.ts +9 -0
  96. package/src/index.tsx +17 -0
  97. package/src/providers/ThemeProvider.tsx +20 -0
  98. package/src/utils/fontScale.ts +51 -0
  99. package/src/utils/getDeviceType.ts +20 -0
  100. package/src/utils/getScreenSizeCategory.ts +12 -0
@@ -0,0 +1,19 @@
1
+ import { forwardRef } from 'react';
2
+ import { View } from 'react-native';
3
+ import type { ViewRef } from '../../types/general.types';
4
+ import Style from '../../utils/Style';
5
+ import type { HStackProps } from './layout.types';
6
+
7
+ export const HStack = forwardRef<ViewRef, HStackProps>((props, ref) => {
8
+ const { style, ...rest } = props;
9
+
10
+ return <View ref={ref} style={[elementStyle.base, style]} {...rest} />;
11
+ });
12
+
13
+ HStack.displayName = 'HStack';
14
+
15
+ const elementStyle = Style.create({
16
+ base: {
17
+ flexDirection: 'row',
18
+ },
19
+ });
@@ -0,0 +1,19 @@
1
+ import { forwardRef } from 'react';
2
+ import { View } from 'react-native';
3
+ import type { ViewRef } from '../../types/general.types';
4
+ import Style from '../../utils/Style';
5
+ import type { VStackProps } from './layout.types';
6
+
7
+ export const VStack = forwardRef<ViewRef, VStackProps>((props, ref) => {
8
+ const { style, ...rest } = props;
9
+
10
+ return <View ref={ref} style={[elementStyle.base, style]} {...rest} />;
11
+ });
12
+
13
+ VStack.displayName = 'VStack';
14
+
15
+ const elementStyle = Style.create({
16
+ base: {
17
+ flexDirection: 'column',
18
+ },
19
+ });
@@ -0,0 +1,9 @@
1
+ import type { StyleProp, ViewStyle } from 'react-native';
2
+
3
+ export type VStackProps = {
4
+ style?: StyleProp<ViewStyle>;
5
+ };
6
+
7
+ export type HStackProps = {
8
+ style?: StyleProp<ViewStyle>;
9
+ };
package/src/index.tsx CHANGED
@@ -1,5 +1,22 @@
1
1
  // Export Components
2
+ export * from './components/Button/Button';
3
+ export * from './components/Button/DangerButton';
4
+ export * from './components/Button/GhostButton';
5
+ export * from './components/Button/PrimaryButton';
6
+ export * from './components/Button/SecondaryButton';
2
7
  export * from './components/Card/Card';
8
+ export * from './components/Divider/Divider';
9
+ export * from './components/Layout/HStack';
10
+ export * from './components/Layout/VStack';
11
+ export * from './components/Surface/Surface';
12
+
13
+ // types
14
+ export * from './components/Button/types';
15
+ export * from './components/Card/types';
16
+ export * from './components/Divider/types';
17
+ export * from './components/Layout/layout.types';
18
+ export * from './components/Surface/types';
19
+ export * from './types/general.types';
3
20
 
4
21
  // Provider
5
22
  export * from './providers/ThemeProvider';
@@ -6,6 +6,8 @@ import type {
6
6
  ThemeVariants,
7
7
  } from './types';
8
8
 
9
+ import * as Font from 'expo-font';
10
+
9
11
  /**
10
12
  * Create a ThemeContext with default value null
11
13
  * @type {React.Context<ThemeContextType | null>}
@@ -67,6 +69,24 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({
67
69
  [deviceColorscheme]
68
70
  );
69
71
 
72
+ useEffect(() => {
73
+ (async function loadAsyncFonts() {
74
+ try {
75
+ await Font.loadAsync({
76
+ CodanRegular: require('../assets/fonts/CodanRegular.ttf'),
77
+ CodanBold: require('../assets/fonts/CodanBold.ttf'),
78
+ CodanBook: require('../assets/fonts/CodanBook.ttf'),
79
+ CodanLight: require('../assets/fonts/CodanLight.ttf'),
80
+ CodanMedium: require('../assets/fonts/CodanMedium.ttf'),
81
+ });
82
+ } catch (e) {
83
+ console.warn('Error loading fonts:', e);
84
+ } finally {
85
+ console.log('Theme Fonts loaded');
86
+ }
87
+ })();
88
+ }, []);
89
+
70
90
  return (
71
91
  <ThemeContext.Provider value={{ theme: currentTheme, changeTheme }}>
72
92
  {children}
@@ -0,0 +1,51 @@
1
+ import { Dimensions, PixelRatio } from 'react-native';
2
+ import { getDeviceType } from './getDeviceType';
3
+ import { getScreenSizeCategory } from './getScreenSizeCategory';
4
+
5
+ const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window');
6
+
7
+ // Use whichever is smaller, width or height
8
+ const SCALE = SCREEN_WIDTH > SCREEN_HEIGHT ? SCREEN_HEIGHT : SCREEN_WIDTH;
9
+ const BASE_WIDTH = 375;
10
+
11
+ const fontConfig = {
12
+ phone: {
13
+ small: { min: 0.8, max: 1 },
14
+ medium: { min: 0.9, max: 1.1 },
15
+ large: { min: 1, max: 1.2 },
16
+ },
17
+ tablet: {
18
+ small: { min: 1.3, max: 1.4 },
19
+ medium: { min: 1.4, max: 1.5 },
20
+ large: { min: 1.5, max: 1.7 },
21
+ },
22
+ };
23
+
24
+ export function fontScale(size: number) {
25
+ const deviceType = getDeviceType();
26
+ const screenCategory = getScreenSizeCategory();
27
+ const config = fontConfig[deviceType][screenCategory];
28
+
29
+ // Calculate the scale factor
30
+ const scaleFactor = SCALE / BASE_WIDTH;
31
+
32
+ // Clamp the scale factor between the configured min and max
33
+ const clampedScaleFactor = Math.min(
34
+ Math.max(scaleFactor, config.min),
35
+ config.max
36
+ );
37
+
38
+ // Calculate the new size
39
+ let newSize = size * clampedScaleFactor;
40
+
41
+ // Additional scaling for tablets to ensure text isn't too small
42
+ if (deviceType === 'tablet') {
43
+ newSize *= 1.1; // Increase tablet font sizes by an additional 10%
44
+ }
45
+
46
+ // Round the size and adjust for the device's font scale
47
+ return (
48
+ Math.round(PixelRatio.roundToNearestPixel(newSize)) /
49
+ PixelRatio.getFontScale()
50
+ );
51
+ }
@@ -0,0 +1,20 @@
1
+ import { Dimensions, PixelRatio } from 'react-native';
2
+
3
+ const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window');
4
+
5
+ export const getDeviceType = (): 'phone' | 'tablet' => {
6
+ const pixelDensity = PixelRatio.get();
7
+ const adjustedWidth = SCREEN_WIDTH * pixelDensity;
8
+ const adjustedHeight = SCREEN_HEIGHT * pixelDensity;
9
+
10
+ if (pixelDensity < 2 && (adjustedWidth >= 1000 || adjustedHeight >= 1000)) {
11
+ return 'tablet';
12
+ } else if (
13
+ pixelDensity === 2 &&
14
+ (adjustedWidth >= 1920 || adjustedHeight >= 1920)
15
+ ) {
16
+ return 'tablet';
17
+ } else {
18
+ return 'phone';
19
+ }
20
+ };
@@ -0,0 +1,12 @@
1
+ import { Dimensions } from 'react-native';
2
+
3
+ const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window');
4
+
5
+ // Use whichever is smaller, width or height
6
+ const SCALE = SCREEN_WIDTH > SCREEN_HEIGHT ? SCREEN_HEIGHT : SCREEN_WIDTH;
7
+
8
+ export const getScreenSizeCategory = (): 'small' | 'medium' | 'large' => {
9
+ if (SCALE < 350) return 'small';
10
+ if (SCALE > 500) return 'large';
11
+ return 'medium';
12
+ };