Skip to content

Commit

Permalink
feat: Opt-out Error page from dark scheme color (#36951)
Browse files Browse the repository at this point in the history
* feat: Opt-out Error page from dark scheme color

* fix: Narrow `withDarkMode` to the media-query

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
icyJoseph and ijjk authored May 22, 2022
1 parent 7e57432 commit 8bdee98
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/next/pages/_error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const statusCodes: { [code: number]: string } = {
export type ErrorProps = {
statusCode: number
title?: string
withDarkMode?: boolean
}

function _getInitialProps({
Expand All @@ -33,7 +34,7 @@ export default class Error<P = {}> extends React.Component<P & ErrorProps> {
static origGetInitialProps = _getInitialProps

render() {
const { statusCode } = this.props
const { statusCode, withDarkMode = true } = this.props
const title =
this.props.title ||
statusCodes[statusCode] ||
Expand All @@ -56,14 +57,20 @@ export default class Error<P = {}> extends React.Component<P & ErrorProps> {
.next-error-h1 {
border-right: 1px solid rgba(0, 0, 0, .3);
}
@media (prefers-color-scheme: dark) {
${
withDarkMode
? `@media (prefers-color-scheme: dark) {
body { color: #fff; background: #000; }
.next-error-h1 {
border-right: 1px solid rgba(255, 255, 255, .3);
}
}`
: ''
}`,
}}
/>

{statusCode ? (
<h1 className="next-error-h1" style={styles.h1}>
{statusCode}
Expand Down

0 comments on commit 8bdee98

Please sign in to comment.