ui-rn 1.0.19 → 2.0.1

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.
@@ -1,4 +1,4 @@
1
- import { StyleSheet } from "react-native";
1
+ import { StyleSheet, TextStyle } from "react-native";
2
2
  import { isNaN, isNumber } from "underscore";
3
3
  enum COLORS {
4
4
  "white" = 1,
@@ -11,9 +11,7 @@ enum COLORS {
11
11
  "gray",
12
12
  "primary"
13
13
  }
14
- type ColorModifiers = Partial<Record<keyof typeof COLORS, boolean>>;
15
-
16
- const SHORT_VARIATIONS = {
14
+ const PROPS = {
17
15
  bg: "backgroundColor",
18
16
  background: "backgroundColor",
19
17
  color: "color",
@@ -54,31 +52,54 @@ const SHORT_VARIATIONS = {
54
52
  bottom: 'bottom',
55
53
  right: 'right',
56
54
  opacity: 'opacity',
57
- //
58
55
  size: 'fontSize'
56
+ } as const;
57
+ const isColorKey = (key: string): key is ColorKey => {
58
+ return key in COLORS;
59
+ };
60
+
61
+ const isShortKey = (key: string): key is ShortKey => {
62
+ return key in PROPS;
59
63
  };
60
- export type ShortKey = keyof typeof SHORT_VARIATIONS;
64
+
65
+ export type ColorKey = keyof typeof COLORS;
66
+ export type ShortKey = keyof typeof PROPS;
61
67
  export type Convert<T extends string> = Partial<Record<T, boolean | number | string>>
62
- export type MakeProp = Convert<ShortKey> & ColorModifiers
68
+ export type MakeProp =
69
+ Partial<Record<ShortKey, number | string>> &
70
+ Partial<Record<ColorKey, boolean>> &
71
+ Record<string, any>;
63
72
 
64
73
  export const makeStyle = (props: { [key: string]: any }) => {
65
- const style: { [key: string]: number | string } = {};
74
+ const style: TextStyle = {};
66
75
  Object.keys(props).forEach((key) => {
67
- const match = key.match(/^(\w+)-(\w+)$/) as string[]
68
- if (COLORS[key]) {
69
- style['color'] = key
70
- }
71
- else if (match) {
72
- const value = isNaN(parseInt(match[2], 10)) ? match[2] : parseInt(match[2], 10)
73
- if (SHORT_VARIATIONS[match[1]]) style[SHORT_VARIATIONS[match[1]]] = value
74
- else style[match[1]] = value
76
+ const match = key.match(/^(\w+)-(\w+)$/);
77
+
78
+ if (isColorKey(key)) {
79
+ style.backgroundColor = key;
80
+ return;
75
81
  }
76
- else {
77
- if (SHORT_VARIATIONS[key]) {
78
- style[SHORT_VARIATIONS[key]] = props[key]
82
+
83
+ if (match) {
84
+ const [, rawKey, rawValue] = match;
85
+
86
+ const value = isNaN(Number(rawValue))
87
+ ? rawValue
88
+ : Number(rawValue);
89
+
90
+ if (isShortKey(rawKey)) {
91
+ style[PROPS[rawKey]] = value as any;
92
+ } else {
93
+ (style as any)[rawKey] = value;
79
94
  }
80
- // else style[key] = props[key]
95
+ return;
96
+ }
97
+
98
+ // 🔹 Normal props
99
+ if (isShortKey(key)) {
100
+ style[PROPS[key]] = props[key] as any;
81
101
  }
82
102
  });
103
+
83
104
  return StyleSheet.create({ style }).style;
84
- };
105
+ };
@@ -1,35 +1,18 @@
1
- import React from 'react'
2
- import { StyleSheet, View } from 'react-native'
3
- import { Style } from './Style'
4
- import { Props } from './Props'
5
- import { isArray, isString } from 'underscore';
6
- import LinearGradient from 'react-native-linear-gradient'
1
+ import React from "react";
2
+ import { View } from "react-native";
3
+ import { Style } from "./Style";
4
+ import { Props } from "./Props";
7
5
 
8
- type TouchableOpacityRef = React.ComponentRef<typeof View>
9
- const Block = React.forwardRef<TouchableOpacityRef, Props>(({ style, ...props }, ref) => {
10
- if (props?.hidden) return <></>
11
- //@ts-ignore
12
- if (isArray(props.background) && props.background.length > 1 && props.background.every(i => isString(i)))
6
+ type TouchableOpacityRef = React.ComponentRef<typeof View>;
7
+ const Block = React.forwardRef<TouchableOpacityRef, Props>(
8
+ ({ style, ...props }, ref) => {
9
+ if (props?.hidden) return <></>;
13
10
  return (
14
- <LinearGradient
15
- //@ts-ignore
16
- colors={props.background}
17
- start={props.gradient == "vertical" ? { x: 0, y: 0 } : { x: 0, y: 0 }}
18
- end={props.gradient == "vertical" ? { x: 0, y: 1 } : { x: 1, y: 0 }}
19
- style={[Style(props), style]}>
11
+ <View ref={ref} style={[Style(props), style]} {...props}>
20
12
  {props.children}
21
- </LinearGradient >
22
- )
23
- //@ts-ignore
24
- return (<View ref={ref} style={[Style(props), style]}
25
- {...props}>
26
- {props.children}
27
- </View>
28
- )
29
- })
30
-
31
- export default Block
32
- const styles = StyleSheet.create({
33
- defaultTouch: {
13
+ </View>
14
+ );
34
15
  },
35
- })
16
+ );
17
+
18
+ export default Block;
@@ -1,5 +1,4 @@
1
- import { IColor } from "../config"
2
- import { StyleProp, FlexStyle, TouchableWithoutFeedbackProps, ViewStyle } from "react-native"
1
+ import { FlexStyle, TouchableWithoutFeedbackProps, ViewStyle } from "react-native"
3
2
  import { MakeProp } from "./makeStyle"
4
3
 
5
4
  /**
@@ -29,6 +28,7 @@ export interface PropsApp {
29
28
  h100?: boolean
30
29
  /** Center content both horizontally and vertically */
31
30
  mid?: boolean
31
+ middle?: boolean
32
32
  /** Set flex direction to row */
33
33
  row?: boolean
34
34
  /** Center content horizontally */
@@ -50,7 +50,7 @@ export interface PropsApp {
50
50
  /** Set height to 100% */
51
51
  height100?: boolean
52
52
  /** Background color or gradient colors */
53
- background?: Array<IColor> | Array<(string)> | string
53
+ background?: string
54
54
  /** Gradient direction */
55
55
  gradient?: 'vertical' | 'horizontal'
56
56
  /** Set flex to 1 */
@@ -1,7 +1,6 @@
1
1
  import { StyleProp, ViewStyle, StyleSheet, Dimensions } from "react-native";
2
2
  import { isArray, isEmpty, isNumber, isObject, isString } from "underscore";
3
3
  import { Props } from './Props'
4
- import { Colors } from "../config";
5
4
  import { makeStyle } from "./makeStyle";
6
5
 
7
6
  /**
@@ -1,16 +1,14 @@
1
- import React from 'react'
2
- import { StyleSheet, TouchableOpacity } from 'react-native'
3
- import { Style } from './Style'
4
- import { Props } from './Props'
5
- import { isArray, isString } from 'underscore'
6
- import LinearGradient from 'react-native-linear-gradient'
1
+ import React from "react";
2
+ import { TouchableOpacity } from "react-native";
3
+ import { Style } from "./Style";
4
+ import { Props } from "./Props";
7
5
 
8
- type TouchableOpacityRef = React.ComponentRef<typeof TouchableOpacity>
6
+ type TouchableOpacityRef = React.ComponentRef<typeof TouchableOpacity>;
9
7
 
10
8
  /**
11
9
  * Touch component that extends TouchableOpacity with additional styling capabilities
12
10
  * Supports gradient backgrounds and custom styling options
13
- *
11
+ *
14
12
  * @component
15
13
  * @example
16
14
  * ```tsx
@@ -18,18 +16,10 @@ type TouchableOpacityRef = React.ComponentRef<typeof TouchableOpacity>
18
16
  * <Touch onPress={() => console.log('pressed')}>
19
17
  * <Text>Press me</Text>
20
18
  * </Touch>
21
- *
22
- * // With gradient background
23
- * <Touch
24
- * background={['#ff0000', '#00ff00']}
25
- * gradient="vertical"
26
- * onPress={() => console.log('pressed')}
27
- * >
28
- * <Text>Gradient Button</Text>
29
- * </Touch>
30
- *
19
+ *
20
+ *
31
21
  * // With custom styling
32
- * <Touch
22
+ * <Touch
33
23
  * mid={true}
34
24
  * row={true}
35
25
  * paddingOption={{ all: 10 }}
@@ -39,36 +29,20 @@ type TouchableOpacityRef = React.ComponentRef<typeof TouchableOpacity>
39
29
  * </Touch>
40
30
  * ```
41
31
  */
42
- const Touch = React.forwardRef<TouchableOpacityRef, Props>(({ style, ...props }, ref) => {
43
- if (props?.hidden) return <></>
44
- //@ts-ignore
45
- if (isArray(props.background) && props.background.length > 1 && props.background.every(i => isString(i)))
32
+ const Touch = React.forwardRef<TouchableOpacityRef, Props>(
33
+ ({ style, ...props }, ref) => {
34
+ if (props?.hidden) return <></>;
46
35
  return (
47
36
  <TouchableOpacity
48
37
  ref={ref}
49
- {...props}
50
38
  activeOpacity={props.activeOpacity || 0.5}
39
+ style={[Style(props), style]}
40
+ {...props}
51
41
  >
52
- <LinearGradient
53
- //@ts-ignore
54
- colors={props.background}
55
- start={props.gradient == "vertical" ? { x: 0, y: 0 } : { x: 0, y: 0 }}
56
- end={props.gradient == "vertical" ? { x: 0, y: 1 } : { x: 1, y: 0 }}
57
- style={[Style(props), style]}
58
- >
59
- {props.children}
60
- </LinearGradient >
42
+ {props.children}
61
43
  </TouchableOpacity>
62
- )
63
- return (
64
- <TouchableOpacity
65
- ref={ref}
66
- activeOpacity={props.activeOpacity || 0.5}
67
- style={[Style(props), style]}
68
- {...props}>
69
- {props.children}
70
- </TouchableOpacity>
71
- )
72
- })
44
+ );
45
+ },
46
+ );
73
47
 
74
- export default Touch
48
+ export default Touch;
@@ -1,70 +1,52 @@
1
-
2
- import React, { ReactNode, useCallback } from 'react';
3
- import { Animated, TouchableOpacity, ViewProps, } from 'react-native';
4
- import { Style } from './Style'
5
- import { Props } from './Props'
6
- import { isArray } from 'underscore';
7
- import LinearGradient from 'react-native-linear-gradient'
8
- import isColor from "validate-color";
1
+ import React, { ReactNode, useCallback } from "react";
2
+ import { Animated, TouchableOpacity, ViewProps } from "react-native";
3
+ import { Style } from "./Style";
4
+ import { Props } from "./Props";
9
5
 
10
6
  interface ButtonScaleProps extends Props {
11
- scaleValue?: number
12
- scale?: boolean
13
- containerStyle?: ViewProps['style']
7
+ scaleValue?: number;
8
+ scale?: boolean;
9
+ containerStyle?: ViewProps["style"];
14
10
  }
15
- type TouchableOpacityRef = React.ComponentRef<typeof TouchableOpacity>
11
+ type TouchableOpacityRef = React.ComponentRef<typeof TouchableOpacity>;
16
12
 
17
- const Touch = React.forwardRef<TouchableOpacityRef, ButtonScaleProps>(({ scaleValue = 1.1, style, background, containerStyle, ...props }, ref) => {
18
- if (props?.hidden) return <></>
13
+ const Touch = React.forwardRef<TouchableOpacityRef, ButtonScaleProps>(
14
+ ({ scaleValue = 1.1, style, background, containerStyle, ...props }, ref) => {
15
+ if (props?.hidden) return <></>;
19
16
  const animatedButtonScale = React.useRef(new Animated.Value(1)).current;
20
17
  const onPressIn = useCallback(() => {
21
- Animated.spring(animatedButtonScale, {
22
- toValue: scaleValue,
23
- useNativeDriver: true,
24
- }).start();
18
+ Animated.spring(animatedButtonScale, {
19
+ toValue: scaleValue,
20
+ useNativeDriver: true,
21
+ }).start();
25
22
  }, [scaleValue]);
26
23
  const onPressOut = useCallback(() => {
27
- Animated.spring(animatedButtonScale, {
28
- toValue: 1,
29
- useNativeDriver: true,
30
- }).start();
24
+ Animated.spring(animatedButtonScale, {
25
+ toValue: 1,
26
+ useNativeDriver: true,
27
+ }).start();
31
28
  }, []);
32
- if (isArray(background) && background.length > 1 && background.every(i => isColor(i)))
33
- return (
34
-
35
- <TouchableOpacity
36
- ref={ref}
37
- onPressIn={onPressIn}
38
- onPressOut={onPressOut}
39
- {...props}
40
- activeOpacity={props.activeOpacity || 1}
41
- >
42
- <Animated.View style={[{ transform: [{ scale: animatedButtonScale }] }, Style(props), style]}>
43
- <LinearGradient
44
- colors={background}
45
- start={props.gradient == "vertical" ? { x: 0, y: 0 } : { x: 0, y: 0 }}
46
- end={props.gradient == "vertical" ? { x: 0, y: 1 } : { x: 1, y: 0 }}
47
- style={[Style(props), style,]}
48
- >
49
- {props.children}
50
- </LinearGradient>
51
- </Animated.View>
52
- </TouchableOpacity>
53
-
54
- )
55
29
  return (
56
- <TouchableOpacity
57
- ref={ref}
58
- onPressIn={onPressIn}
59
- onPressOut={onPressOut}
60
- activeOpacity={props.activeOpacity || 1}
61
- style={containerStyle}
62
- {...props}>
63
- <Animated.View style={[{ transform: [{ scale: animatedButtonScale }] }, Style(props), style]}>
64
- {props.children}
65
- </Animated.View>
66
- </TouchableOpacity>
67
- )
68
- });
30
+ <TouchableOpacity
31
+ ref={ref}
32
+ onPressIn={onPressIn}
33
+ onPressOut={onPressOut}
34
+ activeOpacity={props.activeOpacity || 1}
35
+ style={containerStyle}
36
+ {...props}
37
+ >
38
+ <Animated.View
39
+ style={[
40
+ { transform: [{ scale: animatedButtonScale }] },
41
+ Style(props),
42
+ style,
43
+ ]}
44
+ >
45
+ {props.children}
46
+ </Animated.View>
47
+ </TouchableOpacity>
48
+ );
49
+ },
50
+ );
69
51
 
70
- export default Touch
52
+ export default Touch;
@@ -1,9 +1,6 @@
1
- import { StyleSheet } from "react-native";
1
+ import { StyleSheet, ViewStyle } from "react-native";
2
2
  import { isNaN, isNumber } from "underscore";
3
3
 
4
- /**
5
- * Enum of predefined color names that can be used for background colors
6
- */
7
4
  enum COLORS {
8
5
  "white" = 1,
9
6
  "red",
@@ -15,15 +12,7 @@ enum COLORS {
15
12
  "gray",
16
13
  "primary"
17
14
  }
18
-
19
- /** Type for color modifiers that can be used as boolean flags */
20
- type ColorModifiers = Partial<Record<keyof typeof COLORS, boolean>>;
21
-
22
- /**
23
- * Mapping of short property names to their full React Native style property names
24
- * This allows for shorter, more convenient style property names
25
- */
26
- const SHORT_VARIATIONS = {
15
+ const PROPS = {
27
16
  bg: "backgroundColor",
28
17
  background: "backgroundColor",
29
18
  w: "width",
@@ -36,7 +25,9 @@ const SHORT_VARIATIONS = {
36
25
  maxH: "maxHeight",
37
26
  pad: "padding",
38
27
  padH: "paddingHorizontal",
28
+ horizontal: "paddingHorizontal",
39
29
  padV: "paddingVertical",
30
+ vertical: "paddingVertical",
40
31
  padL: "paddingLeft",
41
32
  padT: "paddingTop",
42
33
  padR: "paddingRight",
@@ -51,6 +42,7 @@ const SHORT_VARIATIONS = {
51
42
  border: 'borderWidth',
52
43
  borderW: 'borderWidth',
53
44
  borderR: "borderRadius",
45
+ radius: "borderRadius",
54
46
  borderC: "borderColor",
55
47
  borderLW: "borderLeftWidth",
56
48
  borderTW: "borderTopWidth",
@@ -63,58 +55,58 @@ const SHORT_VARIATIONS = {
63
55
  bottom: 'bottom',
64
56
  right: 'right',
65
57
  opacity: 'opacity'
58
+ } as const;
59
+
60
+ const isColorKey = (key: string): key is ColorKey => {
61
+ return key in COLORS;
66
62
  };
67
63
 
68
- /** Type for short property names */
69
- export type ShortKey = keyof typeof SHORT_VARIATIONS;
64
+ const isShortKey = (key: string): key is ShortKey => {
65
+ return key in PROPS;
66
+ };
70
67
 
71
- /** Type for converting string keys to a record of boolean/number/string values */
68
+ export type ColorKey = keyof typeof COLORS;
69
+ export type ShortKey = keyof typeof PROPS;
72
70
  export type Convert<T extends string> = Partial<Record<T, boolean | number | string>>
71
+ export type MakeProp =
72
+ Partial<Record<ShortKey, number | string>> &
73
+ Partial<Record<ColorKey, boolean>> &
74
+ Record<string, any>;
73
75
 
74
- /** Type combining short property names and color modifiers */
75
- export type MakeProp = Convert<ShortKey> & ColorModifiers
76
76
 
77
- /**
78
- * Creates a React Native style object from props using short property names
79
- * Supports color names, hyphenated properties, and direct style properties
80
- *
81
- * @param props - Object containing style properties
82
- * @returns React Native style object
83
- *
84
- * @example
85
- * ```tsx
86
- * // Using color names
87
- * makeStyle({ white: true }) // { backgroundColor: 'white' }
88
- *
89
- * // Using hyphenated properties
90
- * makeStyle({ 'pad-10': true }) // { padding: 10 }
91
- *
92
- * // Using direct properties
93
- * makeStyle({ width: 100 }) // { width: 100 }
94
- * ```
95
- */
96
- export const makeStyle = (props: { [key: string]: any }) => {
97
- const style: { [key: string]: number | string } = {};
77
+ export const makeStyle = <T>(props: { [key: string]: any }) => {
78
+ const style: ViewStyle = {};
79
+
98
80
  Object.keys(props).forEach((key) => {
99
- const match = key.match(/^(\w+)-(\w+)$/) as string[]
100
- // console.debug(key, match)
101
- if (COLORS[key]) {
102
- style['backgroundColor'] = key
103
- }
104
- else if (match) {
105
- const value = isNaN(parseInt(match[2], 10)) ? match[2] : parseInt(match[2], 10)
106
- // console.debug('value', value)
107
- // console.debug('value', parseInt(match[2], 10))
108
- // console.debug('value', isNumber(parseInt(match[2], 10)))
109
- if (SHORT_VARIATIONS[match[1]]) style[SHORT_VARIATIONS[match[1]]] = value
110
- else style[match[1]] = value
81
+ const match = key.match(/^(\w+)-(\w+)$/);
82
+
83
+ // 🎨 Color
84
+ if (isColorKey(key)) {
85
+ style.backgroundColor = key;
86
+ return;
111
87
  }
112
- else {
113
- if (SHORT_VARIATIONS[key]) {
114
- style[SHORT_VARIATIONS[key]] = props[key]
88
+
89
+ // 🔹 Hyphen syntax (pad-10)
90
+ if (match) {
91
+ const [, rawKey, rawValue] = match;
92
+
93
+ const value = isNaN(Number(rawValue))
94
+ ? rawValue
95
+ : Number(rawValue);
96
+
97
+ if (isShortKey(rawKey)) {
98
+ style[PROPS[rawKey]] = value as any;
99
+ } else {
100
+ (style as any)[rawKey] = value;
115
101
  }
116
- // else style[key] = props[key]
102
+ return;
103
+ }
104
+
105
+ // 🔹 Normal props
106
+ if (isShortKey(key)) {
107
+ style[PROPS[key]] = props[key] as any;
117
108
  }
118
109
  });
110
+
119
111
  return StyleSheet.create({ style }).style;
120
- };
112
+ };
package/src/index.tsx CHANGED
@@ -2,6 +2,4 @@ export { default as Touch } from './Touch/Touch'
2
2
  export { default as Block } from './Touch/Block'
3
3
  export { default as Text } from './Text'
4
4
  export { default as Icon } from './Icon'
5
- export { default as Layout } from './Layout'
6
- export { default as LoadingView } from './Loading'
7
- export { Loading } from './Loading'
5
+ export { default as Layout } from './Layout'
package/Example/index.tsx DELETED
@@ -1,31 +0,0 @@
1
- import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
2
- import React from 'react';
3
- import { Block } from 'ui-rn';
4
- import { LinearGradient } from 'react-native-linear-gradient';
5
- export default function App() {
6
- return (
7
- <>
8
-
9
- <LinearGradient
10
- colors={['#FF6B6B', '#4ECDC4']}
11
- start={{ x: 0, y: 0 }}
12
- end={{ x: 0, y: 1 }}
13
- >
14
- <TouchableOpacity style={{ padding: 20, borderRadius: 10 }}>
15
- <Text style={{ color: 'white' }}>Gradient Block</Text>
16
- </TouchableOpacity>
17
- </LinearGradient>
18
- <Text style={{ fontWeight: 'bold', fontStyle: 'italic', fontSize: 16, color: 'blue', alignItems: 'center' }}></Text>
19
- <TouchableOpacity
20
- style={{
21
- padding: 10,
22
- backgroundColor:'blue',
23
- borderRadius: 10,
24
- }}
25
- >
26
- <Text style={{ color: 'white', alignItems: 'center' }}>Press Me</Text>
27
- </TouchableOpacity>
28
- </>
29
- );
30
- }
31
-