Files
notesnook/apps/mobile/src/components/Button/index.js

74 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-09-07 13:12:41 +05:00
import React from 'react';
2020-09-09 12:00:20 +05:00
import { ActivityIndicator, StyleSheet, Text } from 'react-native';
2020-09-09 11:10:35 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
2020-09-09 12:00:20 +05:00
import { useTracked } from '../../provider';
import { PressableButton } from '../PressableButton';
2020-10-13 17:02:14 +05:00
import {ph, pv, SIZE, WEIGHT} from "../../utils/SizeUtils";
2020-09-07 13:12:41 +05:00
export const Button = ({
2020-09-09 11:10:35 +05:00
height = 40,
2020-09-07 13:12:41 +05:00
width = '48%',
onPress = () => {},
loading = false,
grayed,
2020-09-09 11:10:35 +05:00
title = '',
icon,
color = 'accent',
2020-09-07 13:12:41 +05:00
}) => {
const [state, dispatch] = useTracked();
2020-09-24 23:02:30 +05:00
const {colors} = state;
2020-09-09 11:10:35 +05:00
const usedColor = 'accent' ? colors.accent : color;
2020-09-07 13:12:41 +05:00
return (
2020-09-09 11:10:35 +05:00
<PressableButton
2020-09-07 13:12:41 +05:00
onPress={onPress}
2020-09-09 11:10:35 +05:00
color={grayed ? colors.nav : usedColor}
selectedColor={grayed ? colors.nav : usedColor}
alpha={grayed ? (!colors.night ? -0.04 : 0.04) : -0.1}
customStyle={{
height: height,
width: width? width : null,
paddingVertical: pv,
paddingHorizontal: ph,
borderRadius: 5,
alignSelf: 'center',
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
}}>
{loading ? <ActivityIndicator color={usedColor} /> : null}
{icon && !loading ? (
<Icon
name={icon}
style={{
marginRight: 5,
}}
color={grayed ? colors.icon : 'white'}
size={SIZE.lg}
/>
) : null}
2020-09-07 13:12:41 +05:00
<Text
style={[styles.buttonText, {color: grayed ? colors.icon : 'white'}]}>
{title}
</Text>
2020-09-09 11:10:35 +05:00
</PressableButton>
2020-09-07 13:12:41 +05:00
);
};
const styles = StyleSheet.create({
activityText: {
fontSize: SIZE.sm,
textAlign: 'center',
},
activityContainer: {
alignItems: 'center',
justifyContent: 'center',
},
buttonText: {
fontFamily: WEIGHT.medium,
color: 'white',
fontSize: SIZE.sm,
marginLeft: 5,
},
});