Skip to content

Instantly share code, notes, and snippets.

@nicholasess
Created November 22, 2019 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholasess/be7185b0e113eea23f946d0799929ce8 to your computer and use it in GitHub Desktop.
Save nicholasess/be7185b0e113eea23f946d0799929ce8 to your computer and use it in GitHub Desktop.
Styled components + react native
import React from 'react';
import {TouchableOpacity} from 'react-native';
import styled from 'styled-components';
import Text from 'app/src/components/Text';
const Button = styled(TouchableOpacity)`
width: 100%;
height: 50px;
border-radius: 5px;
background-color: ${({background}) => background};
border-width: 1;
border-color: ${({text}) => text};
align-items: center;
justify-content: center;
`;
export default ({children, onPress, style, type = 'primary', disabled}) => (
<Button
onPress={disabled ? () => {} : onPress}
style={style}
background={typeButton(type).background}
text={typeButton(type).text}>
<Text weight={'bold'} size={18} color={typeButton(type).text}>
{children}
</Text>
</Button>
);
const typeButton = type => {
let primary = {
background: '#2980B9',
text: '#fff',
};
let danger = {
background: '#E74C3C',
text: '#fff',
};
let outline = {
background: '#fff',
text: '#000',
};
let black = {
background: '#2D3436',
text: '#fff',
};
let success = {
background: '#27AE96',
text: '#fff',
};
switch (type) {
case 'primary':
return primary;
case 'danger':
return danger;
case 'outline':
return outline;
case 'black':
return black;
case 'success':
return success;
default: {
return primary;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment