diff --git a/.storybook/config.js b/.storybook/config.js index 42040678..8f23abf6 100644 --- a/.storybook/config.js +++ b/.storybook/config.js @@ -12,8 +12,7 @@ import { setIntlConfig, withIntl } from 'storybook-addon-intl' import StoryRouter from 'storybook-react-router' import { dark, light } from 'themes' import { getDefaultLocale, locales } from 'lib/i18n' -import BackgroundDark from 'components/UI/BackgroundDark' -import GlobalStyle from 'components/UI/GlobalStyle' +import { BackgroundDark, GlobalStyle } from 'components/UI' // Register supported locales. import '../app/lib/i18n/locale' diff --git a/app/components/Activity/Activity.js b/app/components/Activity/Activity.js index 8690434a..f1eac664 100644 --- a/app/components/Activity/Activity.js +++ b/app/components/Activity/Activity.js @@ -6,7 +6,7 @@ import FaRepeat from 'react-icons/lib/fa/repeat' import { FormattedMessage, injectIntl } from 'react-intl' import { Flex } from 'rebass' -import Button from 'components/UI/Button' +import { Button } from 'components/UI' import Wallet from 'components/Wallet' import Invoice from './Invoice' import Payment from './Payment' diff --git a/app/components/Activity/InvoiceModal/InvoiceModal.js b/app/components/Activity/InvoiceModal/InvoiceModal.js index 354aa276..35a162ec 100644 --- a/app/components/Activity/InvoiceModal/InvoiceModal.js +++ b/app/components/Activity/InvoiceModal/InvoiceModal.js @@ -4,7 +4,7 @@ import QRCode from 'qrcode.react' import copy from 'copy-to-clipboard' import { showNotification } from 'lib/utils/notifications' import Value from 'components/Value' -import Dropdown from 'components/UI/Dropdown' +import { Dropdown } from 'components/UI' import { FormattedDate, FormattedTime, FormattedMessage } from 'react-intl' import Countdown from '../Countdown' import messages from './messages' diff --git a/app/components/Activity/PaymentModal/PaymentModal.js b/app/components/Activity/PaymentModal/PaymentModal.js index 3f214056..072a8a9b 100644 --- a/app/components/Activity/PaymentModal/PaymentModal.js +++ b/app/components/Activity/PaymentModal/PaymentModal.js @@ -1,8 +1,8 @@ import React from 'react' import PropTypes from 'prop-types' -import Dropdown from 'components/UI/Dropdown' import PaperPlane from 'components/Icon/PaperPlane' import Zap from 'components/Icon/Zap' +import { Dropdown } from 'components/UI' import Value from 'components/Value' import { FormattedDate, FormattedTime, FormattedMessage } from 'react-intl' import messages from './messages' diff --git a/app/components/Activity/TransactionModal/TransactionModal.js b/app/components/Activity/TransactionModal/TransactionModal.js index 70f10274..71bd0c93 100644 --- a/app/components/Activity/TransactionModal/TransactionModal.js +++ b/app/components/Activity/TransactionModal/TransactionModal.js @@ -1,16 +1,13 @@ import React from 'react' import PropTypes from 'prop-types' -import Dropdown from 'components/UI/Dropdown' import PaperPlane from 'components/Icon/PaperPlane' import Hand from 'components/Icon/Hand' import ChainLink from 'components/Icon/ChainLink' +import { Dropdown } from 'components/UI' import { blockExplorer } from 'lib/utils' - import Value from 'components/Value' - import { FormattedDate, FormattedTime, FormattedMessage } from 'react-intl' import messages from './messages' - import styles from './TransactionModal.scss' const TransactionModal = ({ diff --git a/app/components/Contacts/AddChannel/AddChannel.js b/app/components/Contacts/AddChannel/AddChannel.js index 18b7ab31..c8a7fd63 100644 --- a/app/components/Contacts/AddChannel/AddChannel.js +++ b/app/components/Contacts/AddChannel/AddChannel.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types' import X from 'components/Icon/X' import { FormattedMessage } from 'react-intl' -import Button from 'components/UI/Button' +import { Button } from 'components/UI' import messages from './messages' import styles from './AddChannel.scss' diff --git a/app/components/Contacts/ConnectManually/ConnectManually.js b/app/components/Contacts/ConnectManually/ConnectManually.js index 1352ca49..76bed320 100644 --- a/app/components/Contacts/ConnectManually/ConnectManually.js +++ b/app/components/Contacts/ConnectManually/ConnectManually.js @@ -2,7 +2,7 @@ import React from 'react' import PropTypes from 'prop-types' import { FormattedMessage, injectIntl } from 'react-intl' -import Button from 'components/UI/Button' +import { Button } from 'components/UI' import messages from './messages' import styles from './ConnectManually.scss' diff --git a/app/components/Contacts/SubmitChannelForm/SubmitChannelForm.js b/app/components/Contacts/SubmitChannelForm/SubmitChannelForm.js index c35fabb2..a3bc7da4 100644 --- a/app/components/Contacts/SubmitChannelForm/SubmitChannelForm.js +++ b/app/components/Contacts/SubmitChannelForm/SubmitChannelForm.js @@ -1,15 +1,10 @@ import React from 'react' import PropTypes from 'prop-types' - import FaExclamationCircle from 'react-icons/lib/fa/exclamation-circle' - import AmountInput from 'components/AmountInput' -import Button from 'components/UI/Button' -import Dropdown from 'components/UI/Dropdown' - +import { Button, Dropdown } from 'components/UI' import { FormattedNumber, FormattedMessage } from 'react-intl' import messages from './messages' - import styles from './SubmitChannelForm.scss' class SubmitChannelForm extends React.Component { diff --git a/app/components/Form/Pay/Pay.js b/app/components/Form/Pay/Pay.js index fca63e4f..cf3013b6 100644 --- a/app/components/Form/Pay/Pay.js +++ b/app/components/Form/Pay/Pay.js @@ -1,14 +1,10 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' - +import { btc } from 'lib/utils' import PaperPlane from 'components/Icon/PaperPlane' import ChainLink from 'components/Icon/ChainLink' - -import { btc } from 'lib/utils' import AmountInput from 'components/AmountInput' -import Button from 'components/UI/Button' -import Dropdown from 'components/UI/Dropdown' - +import { Button, Dropdown } from 'components/UI' import { FormattedNumber, FormattedMessage, injectIntl } from 'react-intl' import messages from './messages' diff --git a/app/components/Form/Request/Request.js b/app/components/Form/Request/Request.js index 71c1fc06..93501d7a 100644 --- a/app/components/Form/Request/Request.js +++ b/app/components/Form/Request/Request.js @@ -1,16 +1,11 @@ import React from 'react' import PropTypes from 'prop-types' - -import Hand from 'components/Icon/Hand' - import { btc } from 'lib/utils' +import Hand from 'components/Icon/Hand' import AmountInput from 'components/AmountInput' -import Button from 'components/UI/Button' -import Dropdown from 'components/UI/Dropdown' - +import { Button, Dropdown } from 'components/UI' import { FormattedNumber, FormattedMessage, injectIntl } from 'react-intl' import messages from './messages' - import styles from './Request.scss' const Request = ({ diff --git a/app/components/GlobalError/GlobalError.js b/app/components/GlobalError/GlobalError.js index 185d9eac..e49c8a9e 100644 --- a/app/components/GlobalError/GlobalError.js +++ b/app/components/GlobalError/GlobalError.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types' import { animated, Transition } from 'react-spring' import { Box } from 'rebass' import errorToUserFriendly from 'lib/utils/userFriendlyErrors' -import Notification from 'components/UI/Notification' +import { Notification } from 'components/UI' class GlobalError extends React.Component { static propTypes = { diff --git a/app/components/Onboarding/FormContainer/FormContainer.js b/app/components/Onboarding/FormContainer/FormContainer.js index baf89a95..f37c672f 100644 --- a/app/components/Onboarding/FormContainer/FormContainer.js +++ b/app/components/Onboarding/FormContainer/FormContainer.js @@ -6,7 +6,7 @@ import FaAngleLeft from 'react-icons/lib/fa/angle-left' import FaAngleRight from 'react-icons/lib/fa/angle-right' import ZapLogo from 'components/Icon/ZapLogo' import ZapLogoBlack from 'components/Icon/ZapLogoBlack' -import Button from 'components/UI/Button' +import { Button } from 'components/UI' import messages from './messages' import styles from './FormContainer.scss' diff --git a/app/components/Onboarding/Login/Login.js b/app/components/Onboarding/Login/Login.js index 4461064f..db1c13b6 100644 --- a/app/components/Onboarding/Login/Login.js +++ b/app/components/Onboarding/Login/Login.js @@ -1,7 +1,7 @@ import React from 'react' import PropTypes from 'prop-types' import { FormattedMessage, injectIntl } from 'react-intl' -import Button from 'components/UI/Button' +import { Button } from 'components/UI' import messages from './messages' import styles from './Login.scss' diff --git a/app/components/UI/GlobalStyle.js b/app/components/UI/GlobalStyle.js index 1e67fdd4..e38da917 100644 --- a/app/components/UI/GlobalStyle.js +++ b/app/components/UI/GlobalStyle.js @@ -9,7 +9,6 @@ const GlobalStyle = createGlobalStyle` } body { position: relative; - box-sizing: border-box; overflow-y: hidden; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: rgba(255, 255, 255, 0); diff --git a/app/components/UI/Input.js b/app/components/UI/Input.js index 003cbc61..8321e282 100644 --- a/app/components/UI/Input.js +++ b/app/components/UI/Input.js @@ -1,9 +1,28 @@ import React from 'react' import { asField } from 'informed' -import { Input as Base } from 'styled-system-html' import { withTheme } from 'styled-components' +import system from '@rebass/components' +import { styles } from 'styled-system' import { Flex } from 'rebass' -import FormFieldMessage from 'components/UI/FormFieldMessage' +import { FormFieldMessage } from 'components/UI' + +// Create an html input element that accepts all style props from styled-system. +const SystemInput = system( + { + as: 'input', + border: 1, + borderColor: 'gray', + borderRadius: 5, + bg: 'transparent', + color: 'primaryText', + fontFamily: 'sans', + fontSize: 'm', + fontWeight: 'light', + p: 3, + width: 1 + }, + ...Object.keys(styles) +) /** * @render react @@ -11,15 +30,26 @@ import FormFieldMessage from 'components/UI/FormFieldMessage' * @example * */ -class Input extends React.PureComponent { +class Input extends React.Component { static displayName = 'Input' + state = { + hasFocus: false + } + + constructor(props) { + super(props) + const { forwardedRef } = this.props + this.inputRef = forwardedRef || React.createRef() + } + render() { const { + css, onChange, onBlur, + onFocus, initialValue, - field, forwardedRef, theme, fieldApi, @@ -27,42 +57,40 @@ class Input extends React.PureComponent { justifyContent, ...rest } = this.props + const { readOnly } = this.props + const { hasFocus } = this.state const { setValue, setTouched } = fieldApi const { value } = fieldState + const isValid = value && !fieldState.error + // Calculate the border color based on the current field state. let borderColor - - if (fieldState.touched) { - if (fieldState.error) { - borderColor = theme.colors.superRed - } else if (value && !fieldState.error) { - borderColor = theme.colors.superGreen - } + if (readOnly) { + borderColor = theme.colors.gray + } else if (fieldState.error) { + borderColor = theme.colors.superRed + } else if (value && !fieldState.error) { + borderColor = theme.colors.superGreen } return ( - { setValue(e.target.value) if (onChange) { @@ -71,14 +99,33 @@ class Input extends React.PureComponent { }} onBlur={e => { setTouched() + // Make the state aware that the element is now focused. + const newHasFocus = document.activeElement === this.inputRef.current + if (hasFocus !== newHasFocus) { + this.setState({ hasFocus: newHasFocus }) + } if (onBlur) { onBlur(e) } }} + onFocus={e => { + // Make the state aware that the element is no longer focused. + const newHasFocus = document.activeElement === this.inputRef.current + if (hasFocus !== newHasFocus) { + this.setState({ hasFocus: newHasFocus }) + } + if (onFocus) { + onFocus(e) + } + }} error={fieldState.error} /> {fieldState.error && ( - + {fieldState.error} )} diff --git a/app/components/UI/Label.js b/app/components/UI/Label.js index 33f8c999..a375a24e 100644 --- a/app/components/UI/Label.js +++ b/app/components/UI/Label.js @@ -1,5 +1,20 @@ import React from 'react' -import { Label as Base } from 'styled-system-html' +import system from '@rebass/components' +import { styles } from 'styled-system' + +// Create an html input element that accepts all style props from styled-system. +const SystemLabel = system( + { + as: 'label', + display: 'block', + color: 'primaryText', + fontSize: 'm', + fontWeight: 'normal', + width: 1, + mb: 1 + }, + ...Object.keys(styles) +) /** * @render react @@ -7,13 +22,12 @@ import { Label as Base } from 'styled-system-html' * @example *