Skip to content

Commit 88ef87c

Browse files
Verestraverestra
and
verestra
authored
fix: remove deprecated use of defaultProps for Button, Card, Input, text (#83)
Co-authored-by: verestra <[email protected]>
1 parent 1bb9370 commit 88ef87c

File tree

4 files changed

+133
-297
lines changed

4 files changed

+133
-297
lines changed

src/Button.js

+43-71
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,49 @@ export const ButtonInstance = ({
1515
...props
1616
}) => <Touchable {...props}>{children}</Touchable>;
1717

18-
const Button = (props) => {
19-
const {
20-
disabled,
21-
opacity,
22-
outlined,
23-
flex,
24-
height,
25-
width,
26-
borderWidth,
27-
// colors
28-
color,
29-
transparent,
30-
primary,
31-
secondary,
32-
tertiary,
33-
black,
34-
white,
35-
gray,
36-
error,
37-
warning,
38-
success,
39-
info,
40-
borderColor,
41-
// support for touchables
42-
highlight,
43-
nativeFeedback,
44-
withoutFeedback,
45-
theme,
46-
style,
47-
children,
48-
// sizing props
49-
margin,
50-
marginHorizontal,
51-
marginVertical,
52-
marginTop,
53-
marginBottom,
54-
marginLeft,
55-
marginRight,
56-
padding,
57-
paddingHorizontal,
58-
paddingVertical,
59-
paddingTop,
60-
paddingBottom,
61-
paddingLeft,
62-
paddingRight,
63-
...rest
64-
} = props;
65-
18+
const Button = ({
19+
disabled = false,
20+
opacity = 0.8,
21+
outlined = false,
22+
flex = 0,
23+
height,
24+
width,
25+
borderWidth,
26+
color = null,
27+
transparent = false,
28+
primary = false,
29+
secondary = false,
30+
tertiary = false,
31+
black = false,
32+
white = false,
33+
gray = false,
34+
error = false,
35+
warning = false,
36+
success = false,
37+
info = false,
38+
borderColor,
39+
highlight,
40+
nativeFeedback,
41+
withoutFeedback,
42+
theme = {},
43+
style = {},
44+
children,
45+
margin = null,
46+
marginHorizontal,
47+
marginVertical,
48+
marginTop,
49+
marginBottom,
50+
marginLeft,
51+
marginRight,
52+
padding = null,
53+
paddingHorizontal,
54+
paddingVertical,
55+
paddingTop,
56+
paddingBottom,
57+
paddingLeft,
58+
paddingRight,
59+
...rest
60+
}) => {
6661
const { SIZES, COLORS } = mergeTheme({ ...expoTheme }, theme);
6762

6863
const marginSpacing = getMargins({
@@ -147,27 +142,4 @@ const Button = (props) => {
147142
);
148143
};
149144

150-
Button.defaultProps = {
151-
color: null,
152-
disabled: false,
153-
opacity: 0.8,
154-
outlined: false,
155-
margin: null,
156-
padding: null,
157-
flex: 0,
158-
transparent: false,
159-
primary: false,
160-
secondary: false,
161-
tertiary: false,
162-
black: false,
163-
white: false,
164-
gray: false,
165-
error: false,
166-
warning: false,
167-
success: false,
168-
info: false,
169-
theme: {},
170-
style: {}
171-
};
172-
173145
export default Button;

src/Card.js

+17-30
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
import React from "react";
22
import { StyleSheet } from "react-native";
3-
43
import Block from "./Block";
54
import expoTheme from "./theme";
65
import { mergeTheme, rgba } from "./utils/index";
76

8-
const Card = (props) => {
9-
const {
10-
color,
11-
radius,
12-
padding,
13-
shadow,
14-
elevation,
15-
outlined,
16-
theme,
17-
style,
18-
children,
19-
...rest
20-
} = props;
21-
7+
const Card = ({
8+
color = null,
9+
radius = null,
10+
padding = null,
11+
shadow = false,
12+
elevation = 3,
13+
outlined = false,
14+
theme = {},
15+
style = {},
16+
children,
17+
...rest
18+
}) => {
2219
const { SIZES, COLORS } = mergeTheme({ ...expoTheme }, theme);
2320

2421
const cardStyles = StyleSheet.flatten([
@@ -27,13 +24,13 @@ const Card = (props) => {
2724
shadowColor: COLORS.black,
2825
shadowOffset: { width: 0, height: elevation - 1 },
2926
shadowOpacity: 0.1,
30-
shadowRadius: elevation
27+
shadowRadius: elevation,
3128
},
3229
outlined && {
3330
borderWidth: 1,
34-
borderColor: rgba(COLORS.black, 0.16)
31+
borderColor: rgba(COLORS.black, 0.16),
3532
},
36-
style
33+
style,
3734
]);
3835

3936
return (
@@ -42,21 +39,11 @@ const Card = (props) => {
4239
color={color || COLORS.white}
4340
radius={radius || SIZES.radius}
4441
padding={padding || SIZES.base}
45-
style={cardStyles}>
42+
style={cardStyles}
43+
>
4644
{children}
4745
</Block>
4846
);
4947
};
5048

51-
Card.defaultProps = {
52-
color: null,
53-
radius: null,
54-
padding: null,
55-
shadow: false,
56-
elevation: 3,
57-
outlined: false,
58-
theme: {},
59-
style: {}
60-
};
61-
6249
export default Card;

src/Input.js

+19-36
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,27 @@ export const reducer = (state, action) => {
3333
}
3434
};
3535

36-
const Input = (props) => {
36+
const Input = ({
37+
pattern = null,
38+
onFocus = null,
39+
onBlur = null,
40+
onChangeText = null,
41+
onValidation = null,
42+
placeholder = null,
43+
autoCorrect = false,
44+
autoCapitalize = "none",
45+
internalRef = null,
46+
theme = {},
47+
style = {},
48+
children,
49+
borderWidth,
50+
borderColor,
51+
type,
52+
...rest
53+
}) => {
3754
const [state, dispatch] = useReducer(reducer, INITIAL_STATE);
3855

3956
const handleValidation = (value) => {
40-
const { pattern } = props;
4157
if (!pattern) return true;
4258

4359
// string pattern, one validation rule
@@ -54,21 +70,18 @@ const Input = (props) => {
5470
};
5571

5672
const handleChange = (value) => {
57-
const { onChangeText, onValidation } = props;
5873
const isValid = handleValidation(value);
5974
dispatch(change(value));
6075
onValidation && onValidation(isValid);
6176
onChangeText && onChangeText(value);
6277
};
6378

6479
const handleFocus = (event) => {
65-
const { onFocus } = props;
6680
dispatch(focus());
6781
onFocus && onFocus(event);
6882
};
6983

7084
const handleBlur = (event) => {
71-
const { onBlur } = props;
7285
dispatch(blur());
7386
onBlur && onBlur(event);
7487
};
@@ -81,22 +94,6 @@ const Input = (props) => {
8194
: type;
8295
};
8396

84-
const {
85-
autoCorrect,
86-
autoCapitalize,
87-
placeholder,
88-
children,
89-
borderWidth,
90-
borderColor,
91-
type,
92-
style,
93-
theme,
94-
internalRef,
95-
onFocus,
96-
onBlur,
97-
onChangeText,
98-
...rest
99-
} = props;
10097
const { SIZES, COLORS } = mergeTheme({ ...expoTheme }, theme);
10198

10299
const textStyles = StyleSheet.flatten([
@@ -129,26 +126,12 @@ const Input = (props) => {
129126
return (
130127
<TextInput
131128
ref={internalRef}
132-
{...props}
129+
{...rest}
133130
{...internalProps}
134131
testID="text-input">
135132
{children}
136133
</TextInput>
137134
);
138135
};
139136

140-
Input.defaultProps = {
141-
pattern: null,
142-
onFocus: null,
143-
onBlur: null,
144-
onChangeText: null,
145-
onValidation: null,
146-
placeholder: null,
147-
autoCorrect: false,
148-
autoCapitalize: "none",
149-
internalRef: null,
150-
theme: {},
151-
style: {}
152-
};
153-
154137
export default Input;

0 commit comments

Comments
 (0)