Browse Source

fix(styles): clean up global error style

Implement new Notification component in GlobalError.
renovate/lint-staged-8.x
Tom Kirkpatrick 6 years ago
parent
commit
ae19294c15
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 2
      app/components/Activity/Activity.scss
  2. 33
      app/components/GlobalError/GlobalError.js
  3. 44
      app/components/GlobalError/GlobalError.scss
  4. 18
      app/components/UI/GlobalStyle.js
  5. 30
      app/components/UI/Notification.js
  6. 78
      app/containers/Root.js
  7. 19
      app/styles/app.global.scss
  8. 27
      test/unit/components/UI/__snapshots__/Notification.spec.js.snap

2
app/components/Activity/Activity.scss

@ -129,7 +129,7 @@
.activityContainer {
background: var(--primaryBackground);
transition: opacity 0.25s;
height: calc(100vh - 304px);
height: calc(100vh - 225px);
overflow-y: auto;
overflow-x: hidden;
padding-top: 20px;

33
app/components/GlobalError/GlobalError.js

@ -1,8 +1,9 @@
import React from 'react'
import PropTypes from 'prop-types'
import MdClose from 'react-icons/lib/md/close'
import { Transition, animated } from 'react-spring'
import errorToUserFriendly from 'lib/utils/userFriendlyErrors'
import styles from './GlobalError.scss'
import Notification from 'components/UI/Notification'
import { Box } from 'rebass'
class GlobalError extends React.Component {
componentDidUpdate(prevProps) {
@ -16,14 +17,26 @@ class GlobalError extends React.Component {
const { error, clearError } = this.props
return (
<div className={`${styles.container} ${!error ? styles.closed : undefined}`}>
<div className={styles.content}>
<div className={styles.close} onClick={clearError}>
<MdClose />
</div>
<h2>{errorToUserFriendly(error)}</h2>
</div>
</div>
<Transition from={{ opacity: 0 }} enter={{ opacity: 1 }} leave={{ opacity: 0 }} native>
{error &&
(springStyles => (
<Box
mt="22px"
px={3}
width={1}
css={{
position: 'absolute',
'z-index': 100
}}
>
<animated.div style={springStyles}>
<Notification variant="error" onClick={clearError}>
{errorToUserFriendly(error)}
</Notification>
</animated.div>
</Box>
))}
</Transition>
)
}
}

44
app/components/GlobalError/GlobalError.scss

@ -1,44 +0,0 @@
@import 'styles/variables.scss';
.container {
position: absolute;
z-index: z("global-error", "container");
background: $red;
color: $white;
width: 100%;
text-align: center;
padding: 20px;
transition: all 0.25s ease;
&.closed {
max-height: 0;
padding: 0;
.content .close {
opacity: 0;
}
}
.content {
position: relative;
.close {
position: absolute;
top: 50%;
right: 10%;
transform: translateY(-50%);
cursor: pointer;
font-size: 2rem;
}
h2 {
max-width: 75%;
margin-left: auto;
margin-right: auto;
font-size: 15px;
line-height: 20px;
letter-spacing: 1.5px;
font-weight: bold;
}
}
}

18
app/components/UI/GlobalStyle.js

@ -1,21 +1,17 @@
import { createGlobalStyle } from 'styled-components'
const GlobalStyle = createGlobalStyle`
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 300;
src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Fl4y0QdOxyyTHEGMXX8kcaCWcynf_cDxXwCLxiixG1c.ttf) format('truetype');
html {
box-sizing: border-box;
}
* { box-sizing: border-box; }
body {
position: relative;
overflow-y: hidden;
margin: 0;
font-family: 'Roboto Light', 'Roboto', Arial, Helvetica, sans-serif;
font-size: 13px;
line-height: 1.4;
padding: 0;
-webkit-font-smoothing: antialiased;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
font-family: 'Roboto', Arial, Helvetica, sans-serif;
}
`

30
app/components/UI/Notification.js

@ -1,7 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Card, Flex, Text } from 'rebass'
import MdClose from 'react-icons/lib/md/close'
import X from 'components/Icon/X'
import SystemSuccess from 'components/Icon/SystemSuccess'
import SystemWarning from 'components/Icon/SystemWarning'
import SystemError from 'components/Icon/SystemError'
@ -27,10 +27,34 @@ class Notification extends React.Component {
variant: PropTypes.string
}
constructor(props) {
super(props)
this.state = { hover: false }
this.hoverOn = this.hoverOn.bind(this)
this.hoverOff = this.hoverOff.bind(this)
}
hoverOn() {
this.setState({ hover: true })
}
hoverOff() {
this.setState({ hover: false })
}
render() {
const { children, processing, variant } = this.props
const { hover } = this.state
return (
<Card px={3} py={3} borderRadius="5px" {...this.props}>
<Card
px={3}
py={3}
borderRadius="5px"
css={{ cursor: 'pointer' }}
{...this.props}
onMouseEnter={this.hoverOn}
onMouseLeave={this.hoverOff}
>
<Flex justifyContent="space-between">
<Flex>
{processing && <Spinner size="2em" mr="0.5em" />}
@ -39,7 +63,7 @@ class Notification extends React.Component {
{!processing && variant === 'error' && <SystemError />}
<Text ml={2}>{children}</Text>
</Flex>
<MdClose />
<X strokeWidth={hover ? 2 : null} />
</Flex>
</Card>
)

78
app/containers/Root.js

@ -4,6 +4,7 @@ import { ConnectedRouter } from 'react-router-redux'
import { Switch, Route } from 'react-router'
import PropTypes from 'prop-types'
import { ThemeProvider } from 'styled-components'
import GlobalStyle from 'components/UI/GlobalStyle'
import GlobalError from 'components/GlobalError'
import { clearError } from 'reducers/error'
@ -238,17 +239,20 @@ class Root extends Component {
if (!onboardingProps.onboarding.onboarded) {
return (
<ThemeProvider theme={currentThemeSettings}>
<div>
<LoadingBolt
theme={onboardingProps.theme}
visible={!onboardingProps.onboarding.onboarding}
/>
<GlobalError error={error} clearError={clearError} />
<Onboarding {...onboardingProps} />
<Syncing {...syncingProps} />
</div>
</ThemeProvider>
<React.Fragment>
<GlobalStyle />
<ThemeProvider theme={currentThemeSettings}>
<div>
<LoadingBolt
theme={onboardingProps.theme}
visible={!onboardingProps.onboarding.onboarding}
/>
<GlobalError error={error} clearError={clearError} />
<Onboarding {...onboardingProps} />
<Syncing {...syncingProps} />
</div>
</ThemeProvider>
</React.Fragment>
)
}
@ -259,33 +263,39 @@ class Root extends Component {
lnd.syncStatus !== 'complete'
) {
return (
<ThemeProvider theme={currentThemeSettings}>
<Syncing {...syncingProps} />
</ThemeProvider>
<React.Fragment>
<GlobalStyle />
<ThemeProvider theme={currentThemeSettings}>
<Syncing {...syncingProps} />
</ThemeProvider>
</React.Fragment>
)
}
return (
<ConnectedRouter history={history}>
<ThemeProvider theme={currentThemeSettings}>
<div>
<LoadingBolt
theme={onboardingProps.theme}
visible={
(!lnd.lightningGrpcActive && !lnd.walletUnlockerGrpcActive) ||
!currentTicker ||
balance.channelBalance === null ||
balance.walletBalance === null
}
/>
<App>
<Switch>
<Route path="/" component={Activity} />
</Switch>
</App>
</div>
</ThemeProvider>
</ConnectedRouter>
<React.Fragment>
<GlobalStyle />
<ConnectedRouter history={history}>
<ThemeProvider theme={currentThemeSettings}>
<div>
<LoadingBolt
theme={onboardingProps.theme}
visible={
(!lnd.lightningGrpcActive && !lnd.walletUnlockerGrpcActive) ||
!currentTicker ||
balance.channelBalance === null ||
balance.walletBalance === null
}
/>
<App>
<Switch>
<Route path="/" component={Activity} />
</Switch>
</App>
</div>
</ThemeProvider>
</ConnectedRouter>
</React.Fragment>
)
}
}

19
app/styles/app.global.scss

@ -1,4 +1,4 @@
@import "~font-awesome/css/font-awesome.css";
@import '~font-awesome/css/font-awesome.css';
@import 'reset.scss';
@import 'variables.scss';
@import 'tooltip.scss';
@ -8,26 +8,19 @@
font-family: 'Roboto';
font-style: normal;
font-weight: 300;
src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Fl4y0QdOxyyTHEGMXX8kcaCWcynf_cDxXwCLxiixG1c.ttf) format('truetype');
src: local('Roboto Light'), local('Roboto-Light'),
url(https://fonts.gstatic.com/s/roboto/v15/Fl4y0QdOxyyTHEGMXX8kcaCWcynf_cDxXwCLxiixG1c.ttf)
format('truetype');
}
body {
position: relative;
overflow-y: hidden;
margin: 0;
padding: 0;
color: #333;
height: 100vh;
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
font-family: 'Roboto', Arial, Helvetica, sans-serif;
}
// disable the pinball scrollers for windows
*,
input[type=text],
input[type=number] {
input[type='text'],
input[type='number'] {
&::-webkit-inner-spin-button,
&::-webkit-outer-spin-button {
-webkit-appearance: none;

27
test/unit/components/UI/__snapshots__/Notification.spec.js.snap

@ -28,11 +28,14 @@ exports[`component.UI.Notification should render correctly 1`] = `
padding-right: 16px;
padding-top: 16px;
padding-bottom: 16px;
cursor: pointer;
border-radius: 5px;
}
<div
className="c0"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<div
className="c1"
@ -64,23 +67,19 @@ exports[`component.UI.Notification should render correctly 1`] = `
/>
</div>
<svg
fill="currentColor"
className="feather feather-x"
fill="none"
height="1em"
preserveAspectRatio="xMidYMid meet"
style={
Object {
"color": undefined,
"verticalAlign": "middle",
}
}
viewBox="0 0 40 40"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={null}
viewBox="0 0 24 24"
width="1em"
>
<g>
<path
d="m31.6 10.7l-9.3 9.3 9.3 9.3-2.3 2.3-9.3-9.3-9.3 9.3-2.3-2.3 9.3-9.3-9.3-9.3 2.3-2.3 9.3 9.3 9.3-9.3z"
/>
</g>
<path
d="M18 6L6 18M6 6l12 12"
/>
</svg>
</div>
</div>

Loading…
Cancel
Save