Skip to content

Instantly share code, notes, and snippets.

@clayrisser
Last active February 28, 2019 06:00
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 clayrisser/4fe606bc776078f6caee1004cd853eca to your computer and use it in GitHub Desktop.
Save clayrisser/4fe606bc776078f6caee1004cd853eca to your computer and use it in GitHub Desktop.
Styled components Button
import React, { Component } from "react";
import { Button as NativeButton } from "native-base";
import Text from "../Text";
import PropTypes from "prop-types";
export default class Button extends Component {
static propTypes = {
children: PropTypes.node.isRequired,
onPress: PropTypes.func
};
static defaultProps = {
onPress: f => f
};
handlePress() {
alert("clicked");
}
render() {
return (
<NativeButton {...this.props} onPress={this.handlePress}>
<Text>{this.props.children}</Text>
</NativeButton>
);
}
}
import React from 'react';
import styled, { withTheme } from 'styled-components';
import Button from './Button';
export default styled(
withTheme(props => {
const style = {
backgroundColor: props.emphasis ? 'red' : 'green',
...props.style
};
return <Button {...props} style={style} />;
})
)`
background-color: ${props => (props.emphasis ? 'red' : 'green')};
`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment