-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add React ^16.0 as a peerDependency, add EuiErrorBoundary (#198)
* Add React 16 as a peer dependency. * Export test module. * Add EuiErrorBoundary. * Fix test template requiredProps import. * Update CHANGELOG. * Move react and react-router to devDependencies.
- Loading branch information
Showing
19 changed files
with
270 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
EuiErrorBoundary, | ||
} from '../../../../src/components'; | ||
|
||
const BadComponent = () => { | ||
throw new Error('There was a terrible error!'); | ||
}; | ||
|
||
export default () => ( | ||
<EuiErrorBoundary> | ||
<BadComponent /> | ||
</EuiErrorBoundary> | ||
); |
35 changes: 35 additions & 0 deletions
35
src-docs/src/views/error_boundary/error_boundary_example.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
|
||
import { renderToHtml } from '../../services'; | ||
|
||
import { | ||
GuideSectionTypes, | ||
} from '../../components'; | ||
|
||
import { | ||
EuiCode, | ||
} from '../../../../src/components'; | ||
|
||
import ErrorBoundary from './error_boundary'; | ||
const errorBoundarySource = require('!!raw-loader!./error_boundary'); | ||
const errorBoundaryHtml = renderToHtml(ErrorBoundary); | ||
|
||
export const ErrorBoundaryExample = { | ||
title: 'ErrorBoundary', | ||
sections: [{ | ||
title: 'ErrorBoundary', | ||
source: [{ | ||
type: GuideSectionTypes.JS, | ||
code: errorBoundarySource, | ||
}, { | ||
type: GuideSectionTypes.HTML, | ||
code: errorBoundaryHtml, | ||
}], | ||
text: ( | ||
<p> | ||
Use <EuiCode>EuiErrorBoundary</EuiCode> to prevent errors from taking down the entire app. | ||
</p> | ||
), | ||
demo: <ErrorBoundary />, | ||
}], | ||
}; |
30 changes: 30 additions & 0 deletions
30
src/components/error_boundary/__snapshots__/error_boundary.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiErrorBoundary is rendered with an error 1`] = ` | ||
<div | ||
aria-label="aria-label" | ||
class="testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
> | ||
<div | ||
class="euiErrorBoundary__text" | ||
> | ||
<div | ||
class="euiText euiText--extraSmall" | ||
> | ||
<h1> | ||
Error | ||
</h1> | ||
<p> | ||
Error: Terrible error! | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`EuiErrorBoundary is rendered without an error 1`] = ` | ||
<div> | ||
No error | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.euiErrorBoundary { | ||
$color1: transparentize($euiColorDanger, .75); | ||
$color2: transparentize($euiColorDanger, .95); | ||
|
||
background: repeating-linear-gradient( | ||
45deg, | ||
$color1, | ||
$color1 1px, | ||
$color2 1px, | ||
$color2 20px | ||
); | ||
overflow: auto; | ||
padding: $euiSize; | ||
} | ||
|
||
.euiErrorBoundary__text { | ||
background-color: $euiColorEmptyShade; | ||
padding: $euiSizeS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import 'error_boundary'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
EuiText, | ||
} from '../text'; | ||
|
||
export class EuiErrorBoundary extends Component { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
} | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
hasError: false, | ||
error: undefined, | ||
}; | ||
} | ||
|
||
componentDidCatch(error) { | ||
// Display fallback UI | ||
this.setState({ | ||
hasError: true, | ||
error | ||
}); | ||
} | ||
|
||
render() { | ||
const { | ||
children, | ||
...rest | ||
} = this.props; | ||
|
||
if (this.state.hasError) { | ||
// You can render any custom fallback UI | ||
return ( | ||
<div className="euiErrorBoundary" {...rest}> | ||
<div className="euiErrorBoundary__text"> | ||
<EuiText size="xs"> | ||
<h1>Error</h1> | ||
<p> | ||
{this.state.error && this.state.error.toString()} | ||
</p> | ||
</EuiText> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
return children; | ||
} | ||
} |
Oops, something went wrong.