Skip to content

Instantly share code, notes, and snippets.

@mtt87
Created October 16, 2019 12:51
Show Gist options
  • Save mtt87/ad4a847b65c3f690ee9182977b4db845 to your computer and use it in GitHub Desktop.
Save mtt87/ad4a847b65c3f690ee9182977b4db845 to your computer and use it in GitHub Desktop.
React Native Button using styled-system
import styled from '@emotion/native';
import {useTheme} from 'emotion-theming';
import theme from '../theme';
import {space, layout, typography, color, variant} from 'styled-system';
type Variants = keyof typeof theme.buttons;
const BtnWrapper = styled.View`
${space}
${layout}
${typography}
${color}
${variant}
`;
const BtnText = styled.Text`
${color}
${typography}
`;
interface Props {
variant: string;
children: string;
disabled?: boolean;
}
interface Theme {
buttons: Variants;
}
function Button({variant, children, disabled = false, ...rest}: Props) {
const theme = useTheme<Theme>();
return (
<BtnWrapper
{...theme.buttons[variant]}
opacity={disabled ? 0.3 : 1}
{...rest}>
<BtnText {...theme.buttons[variant]}>{children}</BtnText>
</BtnWrapper>
);
}
export default Button;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment