From 4b8348da8cc50ef0da6e6b2bb7d276f1246437cf Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 3 Oct 2018 16:20:39 -0700 Subject: Add some ui components --- packages/instant/src/components/ui/button.tsx | 68 ++++++++++++++++++++ packages/instant/src/components/ui/text.tsx | 75 ++++++++++++++++++++++ .../instant/src/components/zero_ex_instant.tsx | 3 + 3 files changed, 146 insertions(+) create mode 100644 packages/instant/src/components/ui/button.tsx create mode 100644 packages/instant/src/components/ui/text.tsx (limited to 'packages/instant/src/components') diff --git a/packages/instant/src/components/ui/button.tsx b/packages/instant/src/components/ui/button.tsx new file mode 100644 index 000000000..ec0a87345 --- /dev/null +++ b/packages/instant/src/components/ui/button.tsx @@ -0,0 +1,68 @@ +import { darken, saturate } from 'polished'; +import * as React from 'react'; + +import { ColorOption, styled } from '../../style/theme'; + +export interface ButtonProps { + fontColor: ColorOption; + backgroundColor: ColorOption; + borderColor?: ColorOption; + fontSize?: string; + fontFamily?: string; + width?: string; + padding?: string; + type?: string; + isDisabled?: boolean; + onClick?: (event: React.MouseEvent) => void; + className?: string; +} + +const PlainButton: React.StatelessComponent = ({ children, isDisabled, onClick, type, className }) => ( + +); + +const darkenOnHoverAmount = 0.1; +const darkenOnActiveAmount = 0.2; +const saturateOnFocusAmount = 0.2; +export const Button = styled(PlainButton)` + cursor: ${props => (props.isDisabled ? 'default' : 'pointer')}; + font-size: ${props => props.fontSize}; + color: ${props => props.fontColor}; + transition: background-color, opacity 0.5s ease; + padding: ${props => props.padding}; + border-radius: 6px; + font-weight: 500; + outline: none; + font-family: ${props => props.fontFamily}; + width: ${props => props.width}; + background-color: ${props => props.backgroundColor}; + border: ${props => (props.borderColor ? `1px solid ${props.theme[props.borderColor]}` : 'none')}; + &:hover { + background-color: ${props => + !props.isDisabled ? darken(darkenOnHoverAmount, props.theme[props.backgroundColor]) : ''} !important; + } + &:active { + background-color: ${props => + !props.isDisabled ? darken(darkenOnActiveAmount, props.theme[props.backgroundColor]) : ''}; + } + &:disabled { + opacity: 0.5; + } + &:focus { + background-color: ${props => saturate(saturateOnFocusAmount, props.theme[props.backgroundColor])}; + } +`; + +Button.defaultProps = { + fontSize: '12px', + fontColor: ColorOption.white, + backgroundColor: ColorOption.primaryColor, + width: 'auto', + fontFamily: 'Inter UI', + isDisabled: false, + padding: '0.8em 2.2em', +}; + +Button.displayName = 'Button'; diff --git a/packages/instant/src/components/ui/text.tsx b/packages/instant/src/components/ui/text.tsx new file mode 100644 index 000000000..a4b9d60d7 --- /dev/null +++ b/packages/instant/src/components/ui/text.tsx @@ -0,0 +1,75 @@ +import { darken } from 'polished'; +import * as React from 'react'; + +import { ColorOption, styled } from '../../style/theme'; + +export type TextTag = 'p' | 'div' | 'span' | 'label' | 'h1' | 'h2' | 'h3' | 'h4' | 'i'; + +export interface TextProps { + fontColor: ColorOption; + fontFamily: string; + fontStyle: string; + fontSize: string; + lineHeight: string; + className?: string; + Tag?: TextTag; + minHeight?: string; + center?: boolean; + fontWeight?: number | string; + textDecorationLine?: string; + onClick?: (event: React.MouseEvent) => void; + hoverColor?: string; + noWrap?: boolean; + display?: string; +} + +const PlainText: React.StatelessComponent = ({ children, className, onClick, Tag }) => ( + + {children} + +); + +const darkenOnHoverAmount = 0.3; +export const Text = styled(PlainText)` + font-family: ${props => props.fontFamily}; + font-style: ${props => props.fontStyle}; + font-weight: ${props => props.fontWeight}; + font-size: ${props => props.fontSize}; + text-decoration-line: ${props => props.textDecorationLine}; + ${props => (props.lineHeight ? `line-height: ${props.lineHeight}` : '')}; + ${props => (props.center ? 'text-align: center' : '')}; + color: ${props => props.theme[props.fontColor]}; + ${props => (props.minHeight ? `min-height: ${props.minHeight}` : '')}; + ${props => (props.onClick ? 'cursor: pointer' : '')}; + transition: color 0.5s ease; + ${props => (props.noWrap ? 'white-space: nowrap' : '')}; + ${props => (props.display ? `display: ${props.display}` : '')}; + &:hover { + ${props => (props.onClick ? `color: ${props.hoverColor || darken(darkenOnHoverAmount, props.fontColor)}` : '')}; + } +`; + +Text.defaultProps = { + fontFamily: 'Inter UI', + fontStyle: 'normal', + fontWeight: 400, + fontColor: ColorOption.black, + fontSize: '15px', + lineHeight: '1.5em', + textDecorationLine: 'none', + Tag: 'div', + noWrap: false, +}; + +Text.displayName = 'Text'; + +export const Title: React.StatelessComponent = props => ; + +Title.defaultProps = { + Tag: 'h2', + fontSize: '20px', + fontWeight: 600, + fontColor: ColorOption.primaryColor, +}; + +Title.displayName = 'Title'; diff --git a/packages/instant/src/components/zero_ex_instant.tsx b/packages/instant/src/components/zero_ex_instant.tsx index 9ba390be9..99f9bb3ba 100644 --- a/packages/instant/src/components/zero_ex_instant.tsx +++ b/packages/instant/src/components/zero_ex_instant.tsx @@ -2,8 +2,11 @@ import * as React from 'react'; import { Provider } from 'react-redux'; import { store } from '../redux/store'; +import { fonts } from '../style/fonts'; import { theme, ThemeProvider } from '../style/theme'; +fonts.include(); + export interface ZeroExInstantProps {} export const ZeroExInstant: React.StatelessComponent = () => ( -- cgit