ui-rn 2.0.4 → 2.0.6
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/Example.tsx +15 -0
- package/dist/Example.d.ts +2 -0
- package/dist/Example.js +11 -0
- package/dist/src/Layout.d.ts +13 -0
- package/dist/src/Layout.js +21 -0
- package/dist/src/Text/Props.d.ts +29 -0
- package/dist/src/Text/Props.js +1 -0
- package/dist/src/Text/Style.d.ts +1 -0
- package/dist/src/Text/Style.js +17 -0
- package/dist/src/Text/index.d.ts +4 -0
- package/dist/src/Text/index.js +44 -0
- package/dist/src/Text/makeStyle.d.ts +64 -0
- package/dist/src/Text/makeStyle.js +91 -0
- package/dist/src/Touch/Block.d.ts +5 -0
- package/dist/src/Touch/Block.js +11 -0
- package/dist/src/Touch/Props.d.ts +128 -0
- package/dist/src/Touch/Props.js +1 -0
- package/dist/src/Touch/Style.d.ts +31 -0
- package/dist/src/Touch/Style.js +118 -0
- package/dist/src/Touch/Touch.d.ts +28 -0
- package/dist/src/Touch/Touch.js +35 -0
- package/dist/src/Touch/TouchScale.d.ts +10 -0
- package/dist/src/Touch/TouchScale.js +30 -0
- package/dist/src/Touch/makeStyle.d.ts +65 -0
- package/dist/src/Touch/makeStyle.js +94 -0
- package/dist/src/Touch/utils.d.ts +5 -0
- package/dist/src/Touch/utils.js +23 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +5 -0
- package/package.json +3 -2
- package/src/Icon/PropsStyle.tsx +32 -0
- package/src/Icon/index.tsx +102 -0
- package/src/Icon/makeProps.ts +91 -0
- package/src/Text/index.tsx +7 -7
- package/src/Text/makeStyle.ts +2 -5
- package/src/Touch/Block.tsx +1 -1
- package/src/Touch/makeStyle.ts +2 -5
- package/tsconfig.json +1 -1
- /package/{src → dist/src}/Icon/PropsStyle.d.ts +0 -0
- /package/{src → dist/src}/Icon/PropsStyle.js +0 -0
- /package/{src → dist/src}/Icon/index.d.ts +0 -0
- /package/{src → dist/src}/Icon/index.js +0 -0
- /package/{src → dist/src}/Icon/makeProps.d.ts +0 -0
- /package/{src → dist/src}/Icon/makeProps.js +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { TouchableOpacity } from "react-native";
|
|
3
|
+
import { Style } from "./Style";
|
|
4
|
+
/**
|
|
5
|
+
* Touch component that extends TouchableOpacity with additional styling capabilities
|
|
6
|
+
* Supports gradient backgrounds and custom styling options
|
|
7
|
+
*
|
|
8
|
+
* @component
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* // Basic usage
|
|
12
|
+
* <Touch onPress={() => console.log('pressed')}>
|
|
13
|
+
* <Text>Press me</Text>
|
|
14
|
+
* </Touch>
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
* // With custom styling
|
|
18
|
+
* <Touch
|
|
19
|
+
* mid={true}
|
|
20
|
+
* row={true}
|
|
21
|
+
* paddingOption={{ all: 10 }}
|
|
22
|
+
* onPress={() => console.log('pressed')}
|
|
23
|
+
* >
|
|
24
|
+
* <Text>Styled Button</Text>
|
|
25
|
+
* </Touch>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
const Touch = React.forwardRef(({ style, ...props }, ref) => {
|
|
29
|
+
if (props?.hidden)
|
|
30
|
+
return <></>;
|
|
31
|
+
return (<TouchableOpacity ref={ref} activeOpacity={props.activeOpacity || 0.5} style={[Style(props), style]} {...props}>
|
|
32
|
+
{props.children}
|
|
33
|
+
</TouchableOpacity>);
|
|
34
|
+
});
|
|
35
|
+
export default Touch;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ViewProps } from "react-native";
|
|
3
|
+
import { Props } from "./Props";
|
|
4
|
+
interface ButtonScaleProps extends Props {
|
|
5
|
+
scaleValue?: number;
|
|
6
|
+
scale?: boolean;
|
|
7
|
+
containerStyle?: ViewProps["style"];
|
|
8
|
+
}
|
|
9
|
+
declare const Touch: React.ForwardRefExoticComponent<ButtonScaleProps & React.RefAttributes<import("react-native").View>>;
|
|
10
|
+
export default Touch;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { useCallback } from "react";
|
|
2
|
+
import { Animated, TouchableOpacity } from "react-native";
|
|
3
|
+
import { Style } from "./Style";
|
|
4
|
+
const Touch = React.forwardRef(({ scaleValue = 1.1, style, background, containerStyle, ...props }, ref) => {
|
|
5
|
+
if (props?.hidden)
|
|
6
|
+
return <></>;
|
|
7
|
+
const animatedButtonScale = React.useRef(new Animated.Value(1)).current;
|
|
8
|
+
const onPressIn = useCallback(() => {
|
|
9
|
+
Animated.spring(animatedButtonScale, {
|
|
10
|
+
toValue: scaleValue,
|
|
11
|
+
useNativeDriver: true,
|
|
12
|
+
}).start();
|
|
13
|
+
}, [scaleValue]);
|
|
14
|
+
const onPressOut = useCallback(() => {
|
|
15
|
+
Animated.spring(animatedButtonScale, {
|
|
16
|
+
toValue: 1,
|
|
17
|
+
useNativeDriver: true,
|
|
18
|
+
}).start();
|
|
19
|
+
}, []);
|
|
20
|
+
return (<TouchableOpacity ref={ref} onPressIn={onPressIn} onPressOut={onPressOut} activeOpacity={props.activeOpacity || 1} style={containerStyle} {...props}>
|
|
21
|
+
<Animated.View style={[
|
|
22
|
+
{ transform: [{ scale: animatedButtonScale }] },
|
|
23
|
+
Style(props),
|
|
24
|
+
style,
|
|
25
|
+
]}>
|
|
26
|
+
{props.children}
|
|
27
|
+
</Animated.View>
|
|
28
|
+
</TouchableOpacity>);
|
|
29
|
+
});
|
|
30
|
+
export default Touch;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ViewStyle } from "react-native";
|
|
2
|
+
declare enum COLORS {
|
|
3
|
+
"white" = 1,
|
|
4
|
+
"red" = 2,
|
|
5
|
+
"blue" = 3,
|
|
6
|
+
"black" = 4,
|
|
7
|
+
"green" = 5,
|
|
8
|
+
"yellow" = 6,
|
|
9
|
+
"pink" = 7,
|
|
10
|
+
"gray" = 8,
|
|
11
|
+
"primary" = 9
|
|
12
|
+
}
|
|
13
|
+
declare const PROPS: {
|
|
14
|
+
readonly bg: "backgroundColor";
|
|
15
|
+
readonly background: "backgroundColor";
|
|
16
|
+
readonly w: "width";
|
|
17
|
+
readonly width: "width";
|
|
18
|
+
readonly minW: "minWidth";
|
|
19
|
+
readonly maxW: "maxWidth";
|
|
20
|
+
readonly h: "height";
|
|
21
|
+
readonly height: "height";
|
|
22
|
+
readonly minH: "minHeight";
|
|
23
|
+
readonly maxH: "maxHeight";
|
|
24
|
+
readonly pad: "padding";
|
|
25
|
+
readonly padH: "paddingHorizontal";
|
|
26
|
+
readonly horizontal: "paddingHorizontal";
|
|
27
|
+
readonly padV: "paddingVertical";
|
|
28
|
+
readonly vertical: "paddingVertical";
|
|
29
|
+
readonly padL: "paddingLeft";
|
|
30
|
+
readonly padT: "paddingTop";
|
|
31
|
+
readonly padR: "paddingRight";
|
|
32
|
+
readonly padB: "paddingBottom";
|
|
33
|
+
readonly mar: "margin";
|
|
34
|
+
readonly marH: "marginHorizontal";
|
|
35
|
+
readonly marV: "marginVertical";
|
|
36
|
+
readonly marL: "marginLeft";
|
|
37
|
+
readonly marT: "marginTop";
|
|
38
|
+
readonly marR: "marginRight";
|
|
39
|
+
readonly marB: "marginBottom";
|
|
40
|
+
readonly border: "borderWidth";
|
|
41
|
+
readonly borderW: "borderWidth";
|
|
42
|
+
readonly borderR: "borderRadius";
|
|
43
|
+
readonly radius: "borderRadius";
|
|
44
|
+
readonly borderC: "borderColor";
|
|
45
|
+
readonly borderLW: "borderLeftWidth";
|
|
46
|
+
readonly borderTW: "borderTopWidth";
|
|
47
|
+
readonly borderRW: "borderRightWidth";
|
|
48
|
+
readonly borderBW: "borderBottomWidth";
|
|
49
|
+
readonly flex: "flex";
|
|
50
|
+
readonly zIndex: "zIndex";
|
|
51
|
+
readonly left: "left";
|
|
52
|
+
readonly top: "top";
|
|
53
|
+
readonly bottom: "bottom";
|
|
54
|
+
readonly right: "right";
|
|
55
|
+
readonly opacity: "opacity";
|
|
56
|
+
};
|
|
57
|
+
export type ColorKey = keyof typeof COLORS;
|
|
58
|
+
export type ShortKey = keyof typeof PROPS;
|
|
59
|
+
export type Convert<T extends string> = Partial<Record<T, boolean | number | string>>;
|
|
60
|
+
export type ColorModifiers = Partial<Record<keyof typeof COLORS, boolean>>;
|
|
61
|
+
export type MakeProp = Convert<ShortKey> & ColorModifiers;
|
|
62
|
+
export declare const makeStyle: <T>(props: {
|
|
63
|
+
[key: string]: any;
|
|
64
|
+
}) => ViewStyle;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { isNaN } from "underscore";
|
|
3
|
+
var COLORS;
|
|
4
|
+
(function (COLORS) {
|
|
5
|
+
COLORS[COLORS["white"] = 1] = "white";
|
|
6
|
+
COLORS[COLORS["red"] = 2] = "red";
|
|
7
|
+
COLORS[COLORS["blue"] = 3] = "blue";
|
|
8
|
+
COLORS[COLORS["black"] = 4] = "black";
|
|
9
|
+
COLORS[COLORS["green"] = 5] = "green";
|
|
10
|
+
COLORS[COLORS["yellow"] = 6] = "yellow";
|
|
11
|
+
COLORS[COLORS["pink"] = 7] = "pink";
|
|
12
|
+
COLORS[COLORS["gray"] = 8] = "gray";
|
|
13
|
+
COLORS[COLORS["primary"] = 9] = "primary";
|
|
14
|
+
})(COLORS || (COLORS = {}));
|
|
15
|
+
const PROPS = {
|
|
16
|
+
bg: "backgroundColor",
|
|
17
|
+
background: "backgroundColor",
|
|
18
|
+
w: "width",
|
|
19
|
+
width: "width",
|
|
20
|
+
minW: "minWidth",
|
|
21
|
+
maxW: "maxWidth",
|
|
22
|
+
h: "height",
|
|
23
|
+
height: "height",
|
|
24
|
+
minH: "minHeight",
|
|
25
|
+
maxH: "maxHeight",
|
|
26
|
+
pad: "padding",
|
|
27
|
+
padH: "paddingHorizontal",
|
|
28
|
+
horizontal: "paddingHorizontal",
|
|
29
|
+
padV: "paddingVertical",
|
|
30
|
+
vertical: "paddingVertical",
|
|
31
|
+
padL: "paddingLeft",
|
|
32
|
+
padT: "paddingTop",
|
|
33
|
+
padR: "paddingRight",
|
|
34
|
+
padB: "paddingBottom",
|
|
35
|
+
mar: "margin",
|
|
36
|
+
marH: "marginHorizontal",
|
|
37
|
+
marV: "marginVertical",
|
|
38
|
+
marL: "marginLeft",
|
|
39
|
+
marT: "marginTop",
|
|
40
|
+
marR: "marginRight",
|
|
41
|
+
marB: "marginBottom",
|
|
42
|
+
border: 'borderWidth',
|
|
43
|
+
borderW: 'borderWidth',
|
|
44
|
+
borderR: "borderRadius",
|
|
45
|
+
radius: "borderRadius",
|
|
46
|
+
borderC: "borderColor",
|
|
47
|
+
borderLW: "borderLeftWidth",
|
|
48
|
+
borderTW: "borderTopWidth",
|
|
49
|
+
borderRW: "borderRightWidth",
|
|
50
|
+
borderBW: "borderBottomWidth",
|
|
51
|
+
flex: 'flex',
|
|
52
|
+
zIndex: 'zIndex',
|
|
53
|
+
left: 'left',
|
|
54
|
+
top: 'top',
|
|
55
|
+
bottom: 'bottom',
|
|
56
|
+
right: 'right',
|
|
57
|
+
opacity: 'opacity'
|
|
58
|
+
};
|
|
59
|
+
const isColorKey = (key) => {
|
|
60
|
+
return key in COLORS;
|
|
61
|
+
};
|
|
62
|
+
const isShortKey = (key) => {
|
|
63
|
+
return key in PROPS;
|
|
64
|
+
};
|
|
65
|
+
export const makeStyle = (props) => {
|
|
66
|
+
const style = {};
|
|
67
|
+
Object.keys(props).forEach((key) => {
|
|
68
|
+
const match = key.match(/^(\w+)-(\w+)$/);
|
|
69
|
+
// 🎨 Color
|
|
70
|
+
if (isColorKey(key)) {
|
|
71
|
+
style.backgroundColor = key;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// 🔹 Hyphen syntax (pad-10)
|
|
75
|
+
if (match) {
|
|
76
|
+
const [, rawKey, rawValue] = match;
|
|
77
|
+
const value = isNaN(Number(rawValue))
|
|
78
|
+
? rawValue
|
|
79
|
+
: Number(rawValue);
|
|
80
|
+
if (isShortKey(rawKey)) {
|
|
81
|
+
style[PROPS[rawKey]] = value;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
style[rawKey] = value;
|
|
85
|
+
}
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// 🔹 Normal props
|
|
89
|
+
if (isShortKey(key)) {
|
|
90
|
+
style[PROPS[key]] = props[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return StyleSheet.create({ style }).style;
|
|
94
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function sliceTextAndNumber(input) {
|
|
2
|
+
let text = "";
|
|
3
|
+
let number = "";
|
|
4
|
+
let mid = false;
|
|
5
|
+
for (let i = 0; i < input.length; i++) {
|
|
6
|
+
const currentChar = input[i];
|
|
7
|
+
if (!isNaN(parseInt(currentChar)) && mid == false) {
|
|
8
|
+
mid = i;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
if (mid) {
|
|
12
|
+
text = input.slice(0, mid);
|
|
13
|
+
number = input.slice(mid);
|
|
14
|
+
}
|
|
15
|
+
// Log.d('mid', { mid, text, number })
|
|
16
|
+
return {
|
|
17
|
+
text: mid ? text : null,
|
|
18
|
+
number: mid ? Number(number) : null,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function replaceAll(str = '', search = '', replacement = '') {
|
|
22
|
+
return str.replace(new RegExp(search, 'g'), replacement); //[g] ~~ search global
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ui-rn",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"repository": "https://github.com/package-dev/ui-rn",
|
|
5
5
|
"description": "ui-rn",
|
|
6
6
|
"author": "Phamha98",
|
|
7
|
-
"main": "
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
8
9
|
"peerDependencies": {
|
|
9
10
|
"react": ">=18",
|
|
10
11
|
"react-native": ">=0.70"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RNVectorIcon,
|
|
3
|
+
} from "./index"
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import {
|
|
6
|
+
FlexStyle,
|
|
7
|
+
StyleProp,
|
|
8
|
+
StyleSheet,
|
|
9
|
+
TextProps,
|
|
10
|
+
TextStyle,
|
|
11
|
+
TouchableOpacity,
|
|
12
|
+
ViewProps,
|
|
13
|
+
ViewStyle,
|
|
14
|
+
} from 'react-native'
|
|
15
|
+
|
|
16
|
+
import { isArray, isEmpty, isNumber, isObject, isString } from "underscore";
|
|
17
|
+
import { MakeProp } from "./makeProps";
|
|
18
|
+
export interface Props extends MakeProp {
|
|
19
|
+
name: string
|
|
20
|
+
size?: number
|
|
21
|
+
type?: keyof typeof RNVectorIcon
|
|
22
|
+
onPress?: () => void
|
|
23
|
+
styleContainer?: StyleProp<ViewStyle>
|
|
24
|
+
style?: StyleProp<TextStyle>
|
|
25
|
+
alignSelf?: FlexStyle['alignSelf']
|
|
26
|
+
disabled?: boolean
|
|
27
|
+
activeOpacity?: number
|
|
28
|
+
color?: string
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { StyleSheet, TouchableOpacity } from "react-native";
|
|
3
|
+
import Ionicons from "react-native-vector-icons/Ionicons";
|
|
4
|
+
import EvilIcons from "react-native-vector-icons/EvilIcons";
|
|
5
|
+
import FontAwesome from "react-native-vector-icons/FontAwesome";
|
|
6
|
+
import FontAwesome5 from "react-native-vector-icons/FontAwesome5";
|
|
7
|
+
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
|
|
8
|
+
import MaterialIcons from "react-native-vector-icons/MaterialIcons";
|
|
9
|
+
import Entypo from "react-native-vector-icons/Entypo";
|
|
10
|
+
import AntDesign from "react-native-vector-icons/AntDesign";
|
|
11
|
+
import SimpleLineIcons from "react-native-vector-icons/SimpleLineIcons";
|
|
12
|
+
import Feather from "react-native-vector-icons/Feather";
|
|
13
|
+
import Octicons from "react-native-vector-icons/Octicons";
|
|
14
|
+
import Fontisto from "react-native-vector-icons/Fontisto";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Collection of React Native Vector Icons
|
|
18
|
+
* Provides access to various icon sets from react-native-vector-icons
|
|
19
|
+
*/
|
|
20
|
+
export const RNVectorIcon = {
|
|
21
|
+
Ionicons,
|
|
22
|
+
AntDesign,
|
|
23
|
+
Entypo,
|
|
24
|
+
EvilIcons,
|
|
25
|
+
MaterialIcons,
|
|
26
|
+
MaterialCommunityIcons,
|
|
27
|
+
FontAwesome,
|
|
28
|
+
FontAwesome5,
|
|
29
|
+
SimpleLineIcons,
|
|
30
|
+
Feather,
|
|
31
|
+
Octicons,
|
|
32
|
+
Fontisto,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type IconType = keyof typeof RNVectorIcon;
|
|
36
|
+
|
|
37
|
+
import { Props } from "./PropsStyle";
|
|
38
|
+
import { makeProps } from "./makeProps";
|
|
39
|
+
|
|
40
|
+
export default class IconApp extends React.PureComponent<Props> {
|
|
41
|
+
static defaultProps: Props = {
|
|
42
|
+
size: 23,
|
|
43
|
+
color: "gray",
|
|
44
|
+
name: "home",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
res: { color: string; style: any; size: number };
|
|
48
|
+
|
|
49
|
+
constructor(props: Props) {
|
|
50
|
+
super(props);
|
|
51
|
+
this.res = makeProps(props);
|
|
52
|
+
}
|
|
53
|
+
render() {
|
|
54
|
+
const { size, color, style } = this.res;
|
|
55
|
+
if (this.props.name === "none") return null;
|
|
56
|
+
const IconView = RNVectorIcon[this.props.type || "Ionicons"];
|
|
57
|
+
if (typeof this.props.onPress != "function") {
|
|
58
|
+
return (
|
|
59
|
+
<IconView
|
|
60
|
+
size={size}
|
|
61
|
+
color={color}
|
|
62
|
+
style={style}
|
|
63
|
+
name={this.props.name}
|
|
64
|
+
onPress={this.props.onPress}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return (
|
|
69
|
+
<TouchableOpacity
|
|
70
|
+
activeOpacity={this.props.activeOpacity || 0.5}
|
|
71
|
+
disabled={
|
|
72
|
+
typeof this.props.onPress == "function" ? this.props.disabled : true
|
|
73
|
+
}
|
|
74
|
+
style={[
|
|
75
|
+
styles.container,
|
|
76
|
+
{ ...(this.props.alignSelf && { alignSelf: this.props.alignSelf }) },
|
|
77
|
+
this.props.style,
|
|
78
|
+
this.props.styleContainer,
|
|
79
|
+
]}
|
|
80
|
+
>
|
|
81
|
+
<IconView
|
|
82
|
+
size={size}
|
|
83
|
+
color={color}
|
|
84
|
+
style={style}
|
|
85
|
+
name={this.props.name}
|
|
86
|
+
onPress={this.props.onPress}
|
|
87
|
+
/>
|
|
88
|
+
</TouchableOpacity>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Default styles for the IconApp component
|
|
95
|
+
*/
|
|
96
|
+
const styles = StyleSheet.create({
|
|
97
|
+
container: {
|
|
98
|
+
alignItems: "center",
|
|
99
|
+
justifyContent: "center",
|
|
100
|
+
alignSelf: "flex-start",
|
|
101
|
+
},
|
|
102
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { StyleSheet, ViewStyle } from "react-native";
|
|
2
|
+
|
|
3
|
+
enum COLORS {
|
|
4
|
+
white = 1,
|
|
5
|
+
red,
|
|
6
|
+
blue,
|
|
7
|
+
black,
|
|
8
|
+
green,
|
|
9
|
+
yellow,
|
|
10
|
+
pink,
|
|
11
|
+
gray,
|
|
12
|
+
primary,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type ColorKey = keyof typeof COLORS;
|
|
16
|
+
type ColorModifiers = Partial<Record<ColorKey, boolean>>;
|
|
17
|
+
|
|
18
|
+
const PROPS = {
|
|
19
|
+
mar: "margin",
|
|
20
|
+
marH: "marginHorizontal",
|
|
21
|
+
marV: "marginVertical",
|
|
22
|
+
marL: "marginLeft",
|
|
23
|
+
marT: "marginTop",
|
|
24
|
+
marR: "marginRight",
|
|
25
|
+
marB: "marginBottom",
|
|
26
|
+
zIndex: "zIndex",
|
|
27
|
+
opacity: "opacity",
|
|
28
|
+
size: "size",
|
|
29
|
+
} as const;
|
|
30
|
+
|
|
31
|
+
export type ShortKey = keyof typeof PROPS;
|
|
32
|
+
|
|
33
|
+
export type Convert<T extends string> = Partial<
|
|
34
|
+
Record<T, boolean | number | string>
|
|
35
|
+
>;
|
|
36
|
+
|
|
37
|
+
export type MakeProp = Convert<ShortKey> & ColorModifiers;
|
|
38
|
+
|
|
39
|
+
/** type guards */
|
|
40
|
+
const isColorKey = (key: string): key is ColorKey => key in COLORS;
|
|
41
|
+
const isShortKey = (key: string): key is ShortKey =>
|
|
42
|
+
key in PROPS;
|
|
43
|
+
|
|
44
|
+
type Result = {
|
|
45
|
+
size: number;
|
|
46
|
+
color: string;
|
|
47
|
+
name: string;
|
|
48
|
+
style: ViewStyle;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const makeProps = (props: Record<string, any>): Result => {
|
|
52
|
+
const style: ViewStyle = {};
|
|
53
|
+
|
|
54
|
+
const res: Omit<Result, "style"> = {
|
|
55
|
+
size: props.size ?? 23,
|
|
56
|
+
color: props.color ?? "gray",
|
|
57
|
+
name: props.name ?? "home",
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
Object.keys(props).forEach((key) => {
|
|
61
|
+
const match = key.match(/^(\w+)-(\w+)$/);
|
|
62
|
+
|
|
63
|
+
// color modifier
|
|
64
|
+
if (isColorKey(key)) {
|
|
65
|
+
res.color = key;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (match) {
|
|
70
|
+
const rawKey = match[1];
|
|
71
|
+
const rawValue = match[2];
|
|
72
|
+
|
|
73
|
+
const value = isNaN(Number(rawValue))
|
|
74
|
+
? rawValue
|
|
75
|
+
: Number(rawValue);
|
|
76
|
+
|
|
77
|
+
if (rawKey === "size") {
|
|
78
|
+
res.size = Number(rawValue);
|
|
79
|
+
} else if (rawKey === "color") {
|
|
80
|
+
res.color = rawValue;
|
|
81
|
+
} else if (isShortKey(rawKey)) {
|
|
82
|
+
(style as any)[PROPS[rawKey]] = value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
...res,
|
|
89
|
+
style: StyleSheet.create({ style }).style,
|
|
90
|
+
};
|
|
91
|
+
};
|
package/src/Text/index.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { isValidElement } from "react";
|
|
2
|
-
import { StyleSheet, Text } from "react-native";
|
|
2
|
+
import { StyleSheet, Text as RNText } from "react-native";
|
|
3
3
|
import { Style } from "./Style";
|
|
4
4
|
import { Props } from "./Props";
|
|
5
5
|
import { isArray, isObject } from "underscore";
|
|
6
|
-
const
|
|
6
|
+
const Text: React.FC<Props> = ({ style, children, ...props }) => {
|
|
7
7
|
const Children = () => {
|
|
8
8
|
const content = props?.lang ?? undefined;
|
|
9
9
|
if (typeof content !== "undefined") {
|
|
@@ -16,7 +16,7 @@ const TextApp: React.FC<Props> = ({ style, children, ...props }) => {
|
|
|
16
16
|
if (typeof content == "function") return "Error content == 'function'";
|
|
17
17
|
if (isObject(children)) return JSON.stringify(children);
|
|
18
18
|
if (isValidElement(content)) return content;
|
|
19
|
-
return React.createElement(
|
|
19
|
+
return React.createElement(RNText, {});
|
|
20
20
|
}
|
|
21
21
|
if (typeof children !== "undefined") {
|
|
22
22
|
if (
|
|
@@ -28,16 +28,16 @@ const TextApp: React.FC<Props> = ({ style, children, ...props }) => {
|
|
|
28
28
|
if (isObject(children)) return JSON.stringify(children);
|
|
29
29
|
if (typeof children == "function") return "Error children == 'function'";
|
|
30
30
|
if (isValidElement(children)) return children;
|
|
31
|
-
return React.createElement(
|
|
31
|
+
return React.createElement(RNText, {}, children);
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
return (
|
|
35
|
-
<
|
|
35
|
+
<RNText style={[styles.default, Style(props), style]} {...props}>
|
|
36
36
|
{Children()}
|
|
37
|
-
</
|
|
37
|
+
</RNText>
|
|
38
38
|
);
|
|
39
39
|
};
|
|
40
|
-
export default
|
|
40
|
+
export default Text;
|
|
41
41
|
const styles = StyleSheet.create({
|
|
42
42
|
default: {
|
|
43
43
|
fontSize: 14,
|
package/src/Text/makeStyle.ts
CHANGED
|
@@ -65,11 +65,8 @@ const isShortKey = (key: string): key is ShortKey => {
|
|
|
65
65
|
export type ColorKey = keyof typeof COLORS;
|
|
66
66
|
export type ShortKey = keyof typeof PROPS;
|
|
67
67
|
export type Convert<T extends string> = Partial<Record<T, boolean | number | string>>
|
|
68
|
-
export type
|
|
69
|
-
|
|
70
|
-
Partial<Record<ColorKey, boolean>> &
|
|
71
|
-
Record<string, any>;
|
|
72
|
-
|
|
68
|
+
export type ColorModifiers = Partial<Record<keyof typeof COLORS, boolean>>;
|
|
69
|
+
export type MakeProp = Convert<ShortKey> & ColorModifiers
|
|
73
70
|
export const makeStyle = (props: { [key: string]: any }) => {
|
|
74
71
|
const style: TextStyle = {};
|
|
75
72
|
Object.keys(props).forEach((key) => {
|
package/src/Touch/Block.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { Style } from "./Style";
|
|
|
4
4
|
import { Props } from "./Props";
|
|
5
5
|
|
|
6
6
|
type TouchableOpacityRef = React.ComponentRef<typeof View>;
|
|
7
|
-
const Block = React.forwardRef<
|
|
7
|
+
const Block = React.forwardRef<View, Props>(
|
|
8
8
|
({ style, ...props }, ref) => {
|
|
9
9
|
if (props?.hidden) return <></>;
|
|
10
10
|
return (
|
package/src/Touch/makeStyle.ts
CHANGED
|
@@ -68,11 +68,8 @@ const isShortKey = (key: string): key is ShortKey => {
|
|
|
68
68
|
export type ColorKey = keyof typeof COLORS;
|
|
69
69
|
export type ShortKey = keyof typeof PROPS;
|
|
70
70
|
export type Convert<T extends string> = Partial<Record<T, boolean | number | string>>
|
|
71
|
-
export type
|
|
72
|
-
|
|
73
|
-
Partial<Record<ColorKey, boolean>> &
|
|
74
|
-
Record<string, any>;
|
|
75
|
-
|
|
71
|
+
export type ColorModifiers = Partial<Record<keyof typeof COLORS, boolean>>;
|
|
72
|
+
export type MakeProp = Convert<ShortKey> & ColorModifiers
|
|
76
73
|
|
|
77
74
|
export const makeStyle = <T>(props: { [key: string]: any }) => {
|
|
78
75
|
const style: ViewStyle = {};
|
package/tsconfig.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|