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. 10
      app/containers/Root.js
  7. 19
      app/styles/app.global.scss
  8. 23
      test/unit/components/UI/__snapshots__/Notification.spec.js.snap

2
app/components/Activity/Activity.scss

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

33
app/components/GlobalError/GlobalError.js

@ -1,8 +1,9 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' 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 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 { class GlobalError extends React.Component {
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
@ -16,14 +17,26 @@ class GlobalError extends React.Component {
const { error, clearError } = this.props const { error, clearError } = this.props
return ( return (
<div className={`${styles.container} ${!error ? styles.closed : undefined}`}> <Transition from={{ opacity: 0 }} enter={{ opacity: 1 }} leave={{ opacity: 0 }} native>
<div className={styles.content}> {error &&
<div className={styles.close} onClick={clearError}> (springStyles => (
<MdClose /> <Box
</div> mt="22px"
<h2>{errorToUserFriendly(error)}</h2> px={3}
</div> width={1}
</div> 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' import { createGlobalStyle } from 'styled-components'
const GlobalStyle = createGlobalStyle` const GlobalStyle = createGlobalStyle`
@font-face { html {
font-family: 'Roboto'; box-sizing: border-box;
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');
} }
* { box-sizing: border-box; }
body { body {
position: relative;
overflow-y: hidden;
margin: 0; margin: 0;
font-family: 'Roboto Light', 'Roboto', Arial, Helvetica, sans-serif; padding: 0;
font-size: 13px;
line-height: 1.4;
-webkit-font-smoothing: antialiased; -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 React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { Card, Flex, Text } from 'rebass' 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 SystemSuccess from 'components/Icon/SystemSuccess'
import SystemWarning from 'components/Icon/SystemWarning' import SystemWarning from 'components/Icon/SystemWarning'
import SystemError from 'components/Icon/SystemError' import SystemError from 'components/Icon/SystemError'
@ -27,10 +27,34 @@ class Notification extends React.Component {
variant: PropTypes.string 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() { render() {
const { children, processing, variant } = this.props const { children, processing, variant } = this.props
const { hover } = this.state
return ( 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 justifyContent="space-between">
<Flex> <Flex>
{processing && <Spinner size="2em" mr="0.5em" />} {processing && <Spinner size="2em" mr="0.5em" />}
@ -39,7 +63,7 @@ class Notification extends React.Component {
{!processing && variant === 'error' && <SystemError />} {!processing && variant === 'error' && <SystemError />}
<Text ml={2}>{children}</Text> <Text ml={2}>{children}</Text>
</Flex> </Flex>
<MdClose /> <X strokeWidth={hover ? 2 : null} />
</Flex> </Flex>
</Card> </Card>
) )

10
app/containers/Root.js

@ -4,6 +4,7 @@ import { ConnectedRouter } from 'react-router-redux'
import { Switch, Route } from 'react-router' import { Switch, Route } from 'react-router'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { ThemeProvider } from 'styled-components' import { ThemeProvider } from 'styled-components'
import GlobalStyle from 'components/UI/GlobalStyle'
import GlobalError from 'components/GlobalError' import GlobalError from 'components/GlobalError'
import { clearError } from 'reducers/error' import { clearError } from 'reducers/error'
@ -238,6 +239,8 @@ class Root extends Component {
if (!onboardingProps.onboarding.onboarded) { if (!onboardingProps.onboarding.onboarded) {
return ( return (
<React.Fragment>
<GlobalStyle />
<ThemeProvider theme={currentThemeSettings}> <ThemeProvider theme={currentThemeSettings}>
<div> <div>
<LoadingBolt <LoadingBolt
@ -249,6 +252,7 @@ class Root extends Component {
<Syncing {...syncingProps} /> <Syncing {...syncingProps} />
</div> </div>
</ThemeProvider> </ThemeProvider>
</React.Fragment>
) )
} }
@ -259,13 +263,18 @@ class Root extends Component {
lnd.syncStatus !== 'complete' lnd.syncStatus !== 'complete'
) { ) {
return ( return (
<React.Fragment>
<GlobalStyle />
<ThemeProvider theme={currentThemeSettings}> <ThemeProvider theme={currentThemeSettings}>
<Syncing {...syncingProps} /> <Syncing {...syncingProps} />
</ThemeProvider> </ThemeProvider>
</React.Fragment>
) )
} }
return ( return (
<React.Fragment>
<GlobalStyle />
<ConnectedRouter history={history}> <ConnectedRouter history={history}>
<ThemeProvider theme={currentThemeSettings}> <ThemeProvider theme={currentThemeSettings}>
<div> <div>
@ -286,6 +295,7 @@ class Root extends Component {
</div> </div>
</ThemeProvider> </ThemeProvider>
</ConnectedRouter> </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 'reset.scss';
@import 'variables.scss'; @import 'variables.scss';
@import 'tooltip.scss'; @import 'tooltip.scss';
@ -8,26 +8,19 @@
font-family: 'Roboto'; font-family: 'Roboto';
font-style: normal; font-style: normal;
font-weight: 300; 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 { 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; font-family: 'Roboto', Arial, Helvetica, sans-serif;
} }
// disable the pinball scrollers for windows // disable the pinball scrollers for windows
*, *,
input[type=text], input[type='text'],
input[type=number] { input[type='number'] {
&::-webkit-inner-spin-button, &::-webkit-inner-spin-button,
&::-webkit-outer-spin-button { &::-webkit-outer-spin-button {
-webkit-appearance: none; -webkit-appearance: none;

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

Loading…
Cancel
Save