mirror of
https://github.com/yldio/copilot.git
synced 2024-11-10 21:30:06 +02:00
Merge pull request #237 from yldio/feature/styled-link
styled-link (fixes #226)
This commit is contained in:
commit
935ab4a749
@ -4,6 +4,7 @@ const isString = require('lodash.isstring');
|
||||
const match = require('../../shared/match');
|
||||
const React = require('react');
|
||||
const Styled = require('styled-components');
|
||||
const ReactRouter = require('react-router-dom');
|
||||
|
||||
const {
|
||||
base,
|
||||
@ -23,6 +24,10 @@ const {
|
||||
css
|
||||
} = Styled;
|
||||
|
||||
const {
|
||||
Link
|
||||
} = ReactRouter;
|
||||
|
||||
const background = match({
|
||||
secondary: base.white,
|
||||
disabled: inactive.default
|
||||
@ -141,6 +146,10 @@ const StyledAnchor = styled.a`
|
||||
${style}
|
||||
`;
|
||||
|
||||
const StyledLink = styled(Link)`
|
||||
display: inline-block !important;
|
||||
${style}
|
||||
`;
|
||||
|
||||
const Button = (props) => {
|
||||
// support FormattedMessage
|
||||
@ -152,15 +161,27 @@ const Button = (props) => {
|
||||
);
|
||||
}
|
||||
|
||||
return props.href ? (
|
||||
<StyledAnchor {...props} />
|
||||
) : (
|
||||
<StyledButton {...props} />
|
||||
const {
|
||||
href = '',
|
||||
rr = false
|
||||
} = props;
|
||||
|
||||
const Views = [
|
||||
() => !href ? StyledButton : null,
|
||||
() => !rr ? StyledAnchor : null,
|
||||
() => StyledLink
|
||||
];
|
||||
|
||||
const View = Views.reduce((sel, view) => sel ? sel : view(), null);
|
||||
|
||||
return (
|
||||
<View {...props} />
|
||||
);
|
||||
};
|
||||
|
||||
Button.propTypes = {
|
||||
href: React.PropTypes.string
|
||||
href: React.PropTypes.string,
|
||||
rr: React.PropTypes.bool
|
||||
};
|
||||
|
||||
module.exports = Button;
|
||||
|
Loading…
Reference in New Issue
Block a user