Skip to content

Commit

Permalink
feat: new components added
Browse files Browse the repository at this point in the history
  • Loading branch information
Izet Molla authored and Izet Molla committed Aug 6, 2023
1 parent 744a73b commit a17bc46
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
29 changes: 26 additions & 3 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
/* eslint-disable react-native/no-inline-styles */
import React, { FC, memo } from 'react';

import { TouchableOpacity, StyleSheet } from 'react-native';
import {
TouchableOpacity,
StyleSheet,
ActivityIndicator,
View,
} from 'react-native';
import { usePropsResolution } from '../../hooks/usePropsResolution';
import { ButtonProps } from './types';
import { omit } from '../../utils';
import Text from '../Text';

const Button: FC<ButtonProps> = ({ children, title, ...props }) => {
const { ...resolvedProps } = usePropsResolution('Button', {
style: styles.button,
...props,
...omit(props, 'leftIcon', 'rightIcon'),
});
return (
<TouchableOpacity {...resolvedProps}>
{title ? <Text style={styles.buttonText}>{title}</Text> : children}
{props.loading ? (
<ActivityIndicator />
) : (
<View
style={[
{
flexDirection: 'row',
justifyContent: 'space-around',
},
props?.contentStyle,
]}
>
{props.leftIcon && props.leftIcon}
{title ? <Text style={styles.buttonText}>{title}</Text> : children}
{props.rightIcon && props.rightIcon}
</View>
)}
</TouchableOpacity>
);
};
Expand Down
5 changes: 4 additions & 1 deletion src/components/Button/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ViewProps } from 'react-native';
import { PseudoComponentProps } from '../../contexts/theme';
import { TouchableOpacityProps } from 'react-native';

Expand Down Expand Up @@ -45,7 +46,9 @@ export interface ButtonProps
bottom?: number | string;
left?: number | string;
right?: number | string;

leftIcon?: React.ReactNode;
rightIcon?: React.ReactNode;
contentStyle?: ViewProps['style'];
disabled?: boolean;
loading?: boolean;
loadingColor?: string;
Expand Down
16 changes: 13 additions & 3 deletions src/components/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
/* eslint-disable react-native/no-inline-styles */
import React, { FC, memo } from 'react';
import { TextInput } from 'react-native';
import { InputProps } from './types';
import { usePropsResolution } from '../../hooks/usePropsResolution';
import { omit } from '../../utils';
import FloatingLabelInput from '../TextInput';
import Text from '../Text';
import { styles } from '../TextInput/styles';

const Input: FC<InputProps> = ({ withFloadtingLabel = false, ...props }) => {
const { ...resolvedProps } = usePropsResolution(
withFloadtingLabel ? 'Input' : 'TextInput',
omit(props)
withFloadtingLabel ? 'TextInput' : 'Input',
withFloadtingLabel ? { ...omit(props), ...styles } : omit(props)
);

if (withFloadtingLabel) {
return <FloatingLabelInput {...resolvedProps} />;
return (
<>
<FloatingLabelInput {...resolvedProps} />
{props?.error && (
<Text style={{ color: 'red', paddingLeft: 5 }}>{props.error}</Text>
)}
</>
);
}

return <TextInput {...resolvedProps} />;
Expand Down
1 change: 1 addition & 0 deletions src/components/Input/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export interface InputProps
PseudoComponentProps<TextInputProps['style']>,
PseudoComponentProps<FloatTextInputProps['style']> {
withFloadtingLabel?: boolean;
error?: string;
}
export { TextInputProps };
8 changes: 8 additions & 0 deletions src/hooks/usePropsResolution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,18 @@ export function usePropsResolution(
};
}
if (component === 'TextInput') {

const errorStyles: any = incomingProps?.error ? {
message: incomingProps?.error,
containerStyles: { ...incomingProps?.containerStyles, borderWidth: 2, borderColor: 'red' },
inputStyles: { ...incomingProps?.inputStyles, color: 'red' },
labelStyles: { ...incomingProps?.labelStyles, color: 'red' },
} : {}
return {
...optionalStyle,
inputStyles: { ...style?.inputStyles, ...optionalStyle?.inputStyles, ...incomingProps?.inputStyles },
...incomingProps,
...errorStyles,
}
}

Expand Down

0 comments on commit a17bc46

Please sign in to comment.