Skip to content

Commit

Permalink
pass down props for button components
Browse files Browse the repository at this point in the history
  • Loading branch information
Savinvadim1312 authored and danstepanov committed Jun 17, 2024
1 parent 5eefd28 commit 0aee640
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-rings-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-expo-stack': patch
---

Pass down props for button components
5 changes: 2 additions & 3 deletions cli/src/templates/base/components/Button.tsx.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { forwardRef } from 'react';
import { StyleSheet, Text, TouchableOpacity, TouchableOpacityProps } from 'react-native';

type ButtonProps = {
onPress?: TouchableOpacityProps['onPress'];
title?: string;
} & TouchableOpacityProps;

export const Button = forwardRef<TouchableOpacity, ButtonProps>(({ onPress, title }, ref) => {
export const Button = forwardRef<TouchableOpacity, ButtonProps>(({ title, ...touchableProps }, ref) => {
return (
<TouchableOpacity ref={ref} style={styles.button} onPress={onPress}>
<TouchableOpacity ref={ref} {...touchableProps} style={[styles.button, touchableProps.style]}>
<Text style={styles.buttonText}>{title}</Text>
</TouchableOpacity>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { forwardRef } from 'react';
import { Text, TouchableOpacity, TouchableOpacityProps } from 'react-native';

interface ButtonProps extends TouchableOpacityProps {
onPress?: () => void;
type ButtonProps = {
title: string;
}
} & TouchableOpacityProps;

export const Button = forwardRef<TouchableOpacity, ButtonProps>(({ onPress, title }, ref) => {
export const Button = forwardRef<TouchableOpacity, ButtonProps>(({ title, ...touchableProps }, ref) => {
return (
<TouchableOpacity ref={ref} className={styles.button} onPress={onPress}>
<TouchableOpacity ref={ref} {...touchableProps} className={`${styles.button} ${touchableProps.className}`}>
<Text className={styles.buttonText}>{title}</Text>
</TouchableOpacity>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { forwardRef } from 'react';
import { StyleSheet, Text, TouchableOpacity, TouchableOpacityProps } from 'react-native';

type ButtonProps = {
onPress?: TouchableOpacityProps['onPress'];
title?: string;
} & TouchableOpacityProps;

export const Button = forwardRef<TouchableOpacity, ButtonProps>(({ onPress, title }, ref) => {
export const Button = forwardRef<TouchableOpacity, ButtonProps>(({ title, ...touchableProps }, ref) => {
return (
<TouchableOpacity ref={ref} style={styles.button} onPress={onPress}>
<TouchableOpacity ref={ref} {...touchableProps} style={[styles.button, touchableProps.style]}>
<Text style={styles.buttonText}>{title}</Text>
</TouchableOpacity>
);
Expand Down
10 changes: 7 additions & 3 deletions cli/src/templates/packages/restyle/components/Button.tsx.ejs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { forwardRef } from 'react';
import { TouchableOpacity } from 'react-native';
import { TouchableOpacity, TouchableOpacityProps } from 'react-native';
import { Text, makeStyles } from 'theme';

export const Button = forwardRef<TouchableOpacity, ButtonProps>(({ onPress, title }, ref) => {
type ButtonProps = {
title?: string;
} & TouchableOpacityProps;

export const Button = forwardRef<TouchableOpacity, ButtonProps>(({ title, ...touchableProps }, ref) => {
const styles = useStyles();

return (
<TouchableOpacity style={styles.button} onPress={onPress}>
<TouchableOpacity ref={ref} {...touchableProps} style={[styles.button, touchableProps.style]}>
<Text variant="body" textAlign="center" color="white" fontWeight="600">
{title}
</Text>
Expand Down
11 changes: 8 additions & 3 deletions cli/src/templates/packages/unistyles/components/Button.tsx.ejs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { forwardRef } from 'react';
import { Text, TouchableOpacity } from 'react-native';
import { Text, TouchableOpacity, TouchableOpacityProps } from 'react-native';
import { useStyles } from 'react-native-unistyles';

export const Button = forwardRef<TouchableOpacity, ButtonProps>(({ onPress, title }, ref) => {
type ButtonProps = {
title?: string;
} & TouchableOpacityProps;


export const Button = forwardRef<TouchableOpacity, ButtonProps>(({ title, ...touchableProps }, ref) => {
const { theme } = useStyles();

return (
<TouchableOpacity style={theme.components.button} onPress={onPress}>
<TouchableOpacity ref={ref} {...touchableProps} style={[theme.components.button, touchableProps.style]}>
<Text style={theme.components.buttonText}>{title}</Text>
</TouchableOpacity>
);
Expand Down

0 comments on commit 0aee640

Please sign in to comment.