Merge pull request #11 from andrerfneves/feature/button

Feature/button
This commit is contained in:
George Lima 2018-12-07 00:31:51 -02:00 committed by GitHub
commit a49af76bbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 165 additions and 10 deletions

54
app/components/Button.mdx Normal file
View File

@ -0,0 +1,54 @@
---
name: Button
---
import { Playground, PropsTable } from 'docz'
import { Button } from './button.js'
import { DoczWrapper } from '../theme.js'
# Button
<PropsTable of={Button} />
## Primary
<Playground>
<div style={{ backgroundColor: '#000', padding: '20px' }}>
<DoczWrapper>{() => <Button label="Click me!" />}</DoczWrapper>
</div>
</Playground>
## Secondary
<Playground>
<div style={{ backgroundColor: '#000', padding: '20px' }}>
<DoczWrapper>{() => <Button label="Click me!" onClick={() => alert('Clicked')} variant="secondary" />}</DoczWrapper>
</div>
</Playground>
## Primary Disabled
<Playground>
<div style={{ backgroundColor: '#000', padding: '20px' }}>
<DoczWrapper>{() => <Button label="Click me!" onClick={() => alert('Clicked')} disabled />}</DoczWrapper>
</div>
</Playground>
## Secondary Disabled
<Playground>
<div style={{ backgroundColor: '#000', padding: '20px' }}>
<DoczWrapper>
{() => <Button label="Click me!" onClick={() => alert('Clicked')} disabled variant="secondary" />}
</DoczWrapper>
</div>
</Playground>
## Link Button
<Playground>
<div style={{ backgroundColor: '#000', padding: '20px' }}>
<DoczWrapper>{() => <Button label="Click me!" isLink to="/my-route" />}</DoczWrapper>
</div>
</Playground>

94
app/components/button.js Normal file
View File

@ -0,0 +1,94 @@
// @flow
import React from 'react';
import styled from 'styled-components';
import { Link } from 'react-router-dom';
/* eslint-disable import/no-extraneous-dependencies */
// $FlowFixMe
import { darken } from 'polished';
const defaultStyles = `
padding: 10px 30px;
font-family: ${
// $FlowFixMe
props => props.theme.fontFamily
};
font-weight: bold;
font-size: 0.9em;
cursor: pointer;
outline: none;
min-width: 100px;
border-radius: 100px;
transition: background-color 0.1s ease-in-out;
`;
const Primary = styled.button`
${defaultStyles};
background-color: ${props => props.theme.colors.primary};
color: ${props => props.theme.colors.secondary};
border: none;
&:hover {
background-color: ${props => darken(0.1, props.theme.colors.primary(props))};
}
&:disabled {
background-color: #3e3c42;
cursor: not-allowed;
opacity: 0.8;
}
`;
const Secondary = styled.button`
${defaultStyles};
background-color: Transparent;
color: ${props => props.theme.colors.secondary};
border: 2px solid #3e3c42;
&:hover {
border-color: ${props => props.theme.colors.primary};
}
&:disabled {
background-color: Transparent;
cursor: not-allowed;
color: #3e3c42;
&:hover {
border-color: #3e3c42;
}
}
`;
type Props = {
label: string,
onClick?: () => void,
to?: string,
variant?: 'primary' | 'secondary',
disabled?: boolean,
};
export const Button = ({
onClick, label, to, variant, disabled,
}: Props) => {
if (to && onClick) throw new Error('Should define either "to" or "onClick"');
const component = variant === 'primary' ? (
<Primary onClick={onClick} disabled={disabled}>
{label}
</Primary>
) : (
<Secondary onClick={onClick} disabled={disabled}>
{label}
</Secondary>
);
return to ? <Link to={String(to)}>{component}</Link> : component;
};
Button.defaultProps = {
to: null,
variant: 'primary',
onClick: null,
disabled: false,
};

View File

@ -7,7 +7,7 @@ import { normalize } from 'polished'; // eslint-disable-line
import { DARK } from './constants/themes';
const darkOne = '#212124';
const darkOne = '#7B00DD';
const lightOne = '#ffffff';
const brandOne = '#624cda';
const brandTwo = '#a6ede2';
@ -17,13 +17,13 @@ const appTheme = {
fontFamily: 'PT Sans',
colors: {
primary: theme('mode', {
light: darkOne,
dark: lightOne,
}),
secondary: theme('mode', {
light: lightOne,
dark: darkOne,
}),
secondary: theme('mode', {
light: darkOne,
dark: lightOne,
}),
sidebarBg: brandOne,
sidebarItem: brandTwo,
sidebarItemActive: lightOne,
@ -36,11 +36,7 @@ const appTheme = {
/* eslint-disable react/prop-types */
// $FlowFixMe
export const DoczWrapper = ({ children }) => (
<ThemeProvider theme={appTheme}>
{children()}
</ThemeProvider>
);
export const DoczWrapper = ({ children }) => <ThemeProvider theme={appTheme}>{children()}</ThemeProvider>;
export const GlobalStyle = createGlobalStyle`${normalize()}`;

View File

@ -5,4 +5,14 @@ export default {
title: 'Zcash Foundation',
description: 'Zcash Foundation User Interface Styleguide',
plugins: [css()],
htmlContext: {
head: {
links: [
{
rel: 'stylesheet',
href: 'https://fonts.googleapis.com/css?family=PT+Sans:400,700',
},
],
},
},
};

View File

@ -6,6 +6,7 @@
<meta name="theme-color" content="#000000" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="shortcut icon" href="favicon.ico" />
<link href="https://fonts.googleapis.com/css?family=PT+Sans:400,700" rel="stylesheet" />
<title>Zcash Reference Wallet</title>
</head>