From 7e8e572f6a81206800d2e35485c3ae93743d0e03 Mon Sep 17 00:00:00 2001 From: George Lima Date: Thu, 7 Feb 2019 00:06:48 -0300 Subject: [PATCH] type(flow): upgrade flow-bin and add styled-components typedefs --- app/components/button.js | 40 +-- app/components/column.js | 13 +- app/components/confirm-dialog.js | 14 +- app/components/divider.js | 15 +- app/components/dropdown.js | 41 +-- app/components/error-modal.js | 30 +- app/components/header.js | 34 +- app/components/input-label.js | 8 +- app/components/input.js | 55 +-- app/components/layout.js | 10 +- app/components/loading-screen.js | 11 +- app/components/row.js | 12 +- app/components/select.js | 31 +- app/components/sidebar.js | 33 +- app/components/status-pill.js | 10 +- app/components/text.js | 20 +- app/components/transaction-daily.js | 48 ++- app/components/transaction-details.js | 37 +- app/components/transaction-item.js | 24 +- app/components/wallet-address.js | 10 +- app/components/wallet-summary.js | 32 +- app/theme.js | 10 +- app/views/console.js | 13 +- app/views/receive.js | 48 +-- app/views/send.js | 47 ++- app/views/settings.js | 12 +- flow-custom-typedefs/styled-components.js | 419 ---------------------- flow-custom-typedefs/theme.js | 62 ++++ package.json | 2 +- yarn.lock | 8 +- 30 files changed, 368 insertions(+), 781 deletions(-) delete mode 100644 flow-custom-typedefs/styled-components.js create mode 100644 flow-custom-typedefs/theme.js diff --git a/app/components/button.js b/app/components/button.js index 8869843..18eb795 100644 --- a/app/components/button.js +++ b/app/components/button.js @@ -3,37 +3,33 @@ import React, { type ElementProps } from 'react'; import styled from 'styled-components'; import { Link } from 'react-router-dom'; -/* eslint-disable import/no-extraneous-dependencies */ -/* eslint-disable max-len */ -// $FlowFixMe -import { darken } from 'polished'; const DefaultButton = styled.button` align-items: center; display: flex; justify-content: center; padding: 10px 30px; - font-family: ${props => props.theme.fontFamily}; - font-weight: ${props => props.theme.fontWeight.bold}; - font-size: ${props => `${props.theme.fontSize.regular}em`}; + font-family: ${(props: PropsWithTheme<>) => props.theme.fontFamily}; + font-weight: ${(props: PropsWithTheme<>) => String(props.theme.fontWeight.bold)}; + font-size: ${(props: PropsWithTheme<>) => `${props.theme.fontSize.regular}em`}; cursor: pointer; outline: none; min-width: 100px; border-radius: 100px; - transition: background-color 0.1s ${props => props.theme.colors.transitionEase}; + transition: background-color 0.1s ${(props: PropsWithTheme<>) => props.theme.transitionEase}; `; const Primary = styled(DefaultButton)` - background-color: ${props => props.theme.colors.primary}; - color: ${props => props.theme.colors.secondary}; + background-color: ${(props: PropsWithTheme<>) => props.theme.colors.primary}; + color: ${(props: PropsWithTheme<>) => props.theme.colors.secondary}; border: none; &:hover { - background-color: ${props => darken(0.1, props.theme.colors.primary(props))}; + opacity: 0.9; } &:disabled { - background-color: ${props => props.theme.colors.buttonBorderColor}; + background-color: ${(props: PropsWithTheme<>) => props.theme.colors.buttonBorderColor}; cursor: not-allowed; opacity: 0.8; } @@ -41,20 +37,20 @@ const Primary = styled(DefaultButton)` const Secondary = styled(DefaultButton)` background-color: transparent; - color: ${props => props.theme.colors.secondary}; - border: 2px solid ${props => props.theme.colors.buttonBorderColor}; + color: ${(props: PropsWithTheme<>) => props.theme.colors.secondary}; + border: 2px solid ${(props: PropsWithTheme<>) => props.theme.colors.buttonBorderColor}; &:hover { - border-color: ${props => props.theme.colors.primary}; + border-color: ${(props: PropsWithTheme<>) => props.theme.colors.primary}; } &:disabled { background-color: Transparent; cursor: not-allowed; - color: ${props => props.theme.colors.buttonBorderColor}; + color: ${(props: PropsWithTheme<>) => props.theme.colors.buttonBorderColor}; &:hover { - border-color: ${props => props.theme.colors.buttonBorderColor}; + border-color: ${(props: PropsWithTheme<>) => props.theme.colors.buttonBorderColor}; } } `; @@ -101,18 +97,12 @@ export const Button = ({ const buttonLabel = isLoading ? 'Loading...' : label; const component = variant === 'primary' ? ( - + {icon ? : null} {buttonLabel} ) : ( - + {icon ? : null} {buttonLabel} diff --git a/app/components/column.js b/app/components/column.js index 44b0e0a..53f3d46 100644 --- a/app/components/column.js +++ b/app/components/column.js @@ -3,12 +3,19 @@ import React, { type Node, type ElementProps } from 'react'; import styled from 'styled-components'; +type FlexProps = + | { + alignItems: string, + justifyContent: string, + width: string, + } + | Object; const Flex = styled.div` display: flex; flex-direction: column; - align-items: ${props => props.alignItems}; - justify-content: ${props => props.justifyContent}; - ${props => props.width && `width: ${props.width};`} + align-items: ${(props: FlexProps) => props.alignItems}; + justify-content: ${(props: FlexProps) => props.justifyContent}; + ${(props: FlexProps) => props.width && `width: ${props.width};`} `; type Props = { diff --git a/app/components/confirm-dialog.js b/app/components/confirm-dialog.js index 844f7c6..a982465 100644 --- a/app/components/confirm-dialog.js +++ b/app/components/confirm-dialog.js @@ -12,8 +12,8 @@ import CloseIcon from '../assets/images/close_icon.svg'; const Wrapper = styled.div` display: flex; - width: ${props => `${props.width}px`}; - background-color: ${props => props.theme.colors.background}; + width: ${(props: PropsWithTheme<{ width: number }>) => `${props.width}px`}; + background-color: ${(props: PropsWithTheme<>) => props.theme.colors.background}; flex-direction: column; align-items: center; border-radius: 6px; @@ -83,16 +83,10 @@ export const ConfirmDialogComponent = ({ {toggle => ( - + - + {children(handleClose(toggle))} diff --git a/app/components/divider.js b/app/components/divider.js index 0d7e924..bb0649f 100644 --- a/app/components/divider.js +++ b/app/components/divider.js @@ -2,11 +2,18 @@ import styled from 'styled-components'; +type Props = PropsWithTheme<{ + color: ?string, + opacity: number, + marginBottom: string, + marginTop: string, +}>; + export const Divider = styled.div` width: 100%; height: 1px; - background-color: ${props => props.color || props.theme.colors.text}; - opacity: ${props => props.opacity || 1}; - margin-bottom: ${props => props.marginBottom || 0}; - margin-top: ${props => props.marginTop || 0}; + background-color: ${(props: Props) => props.color || props.theme.colors.text}; + opacity: ${(props: Props) => String(props.opacity || 1)}; + margin-bottom: ${(props: Props) => props.marginBottom || '0'}; + margin-top: ${(props: Props) => props.marginTop || '0'}; `; diff --git a/app/components/dropdown.js b/app/components/dropdown.js index b8e4bca..c541aa0 100644 --- a/app/components/dropdown.js +++ b/app/components/dropdown.js @@ -14,10 +14,10 @@ import { truncateAddress } from '../utils/truncate-address'; /* eslint-disable max-len */ const MenuWrapper = styled.div` - background-image: ${props => `linear-gradient(to right, ${darken(0.05, props.theme.colors.activeItem)}, ${ + background-image: ${(props: PropsWithTheme<>) => `linear-gradient(to right, ${darken(0.05, props.theme.colors.activeItem)}, ${ props.theme.colors.activeItem })`}; - border-radius: ${props => props.theme.boxBorderRadius}; + border-radius: ${(props: PropsWithTheme<>) => props.theme.boxBorderRadius}; margin-left: -10px; max-width: 400px; overflow: hidden; @@ -28,7 +28,7 @@ const MenuItem = styled.button` background-color: transparent; border: none; border-bottom-style: solid; - border-bottom-color: ${props => props.theme.colors.text}; + border-bottom-color: ${(props: PropsWithTheme<>) => props.theme.colors.text}; border-bottom-width: 1px; padding: 15px; cursor: pointer; @@ -68,7 +68,7 @@ const Option = styled(TextComponent)` const PopoverWithStyle = styled(Popover)` & > .Popover-tip { - fill: ${props => props.theme.colors.activeItem}; + fill: ${(props: PropsWithTheme<>) => props.theme.colors.activeItem}; } `; @@ -100,30 +100,16 @@ export class DropdownComponent extends Component { } = this.props; const body = [ - this.setState(() => ({ isOpen: false }))} - > + this.setState(() => ({ isOpen: false }))}> {label && ( - - + + )} {options.map(({ label: optionLabel, onClick }) => ( - - @@ -138,9 +124,12 @@ export class DropdownComponent extends Component { tipSize={7} body={body} > - {renderTrigger(() => this.setState(state => ({ - isOpen: !state.isOpen, - })), isOpen)} + {renderTrigger( + () => this.setState(state => ({ + isOpen: !state.isOpen, + })), + isOpen, + )} ); } diff --git a/app/components/error-modal.js b/app/components/error-modal.js index 34bbaa2..c6b35a0 100644 --- a/app/components/error-modal.js +++ b/app/components/error-modal.js @@ -23,7 +23,7 @@ const ModalWrapper = styled.div` const ChildrenWrapper = styled.div` width: 350px; - background-color: ${props => props.theme.colors.background}; + background-color: ${(props: PropsWithTheme<>) => props.theme.colors.background}; display: flex; flex-direction: column; align-items: center; @@ -79,21 +79,17 @@ export class ErrorModalComponent extends PureComponent { render() { const { isVisible, message, onRequestClose } = this.props; - return !isVisible ? null : createPortal( - - - - -