-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move ErrorIndicator to separate file
- Loading branch information
1 parent
c9ccf7f
commit 0df6543
Showing
3 changed files
with
129 additions
and
40 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...t-dev-overlay/_experimental/internal/components/ErrorIndicator/ErrorIndicator.stories.tsx
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,64 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { ErrorIndicator } from './ErrorIndicator' | ||
import { withShadowPortal } from '../../storybook/with-shadow-portal' | ||
|
||
const meta: Meta<typeof ErrorIndicator> = { | ||
title: 'ErrorIndicator', | ||
component: ErrorIndicator, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
decorators: [withShadowPortal], | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof ErrorIndicator> | ||
|
||
// Mock error for stories | ||
const mockError = { | ||
id: 1, | ||
runtime: true as const, | ||
error: new Error('Test error'), | ||
frames: [ | ||
{ | ||
error: true, | ||
reason: null, | ||
external: false, | ||
ignored: false, | ||
sourceStackFrame: { | ||
file: 'test.js', | ||
methodName: '<unknown>', | ||
arguments: [], | ||
lineNumber: 1, | ||
column: 1, | ||
}, | ||
}, | ||
], | ||
} | ||
|
||
export const SingleError: Story = { | ||
args: { | ||
hasStaticIndicator: false, | ||
readyErrors: [mockError], | ||
fullscreen: () => console.log('Fullscreen clicked'), | ||
hide: () => console.log('Hide clicked'), | ||
}, | ||
} | ||
|
||
export const MultipleErrors: Story = { | ||
args: { | ||
hasStaticIndicator: false, | ||
readyErrors: [mockError, { ...mockError, id: 2 }, { ...mockError, id: 3 }], | ||
fullscreen: () => console.log('Fullscreen clicked'), | ||
hide: () => console.log('Hide clicked'), | ||
}, | ||
} | ||
|
||
export const WithStaticIndicator: Story = { | ||
args: { | ||
hasStaticIndicator: true, | ||
readyErrors: [mockError], | ||
fullscreen: () => console.log('Fullscreen clicked'), | ||
hide: () => console.log('Hide clicked'), | ||
}, | ||
} |
58 changes: 58 additions & 0 deletions
58
...nts/react-dev-overlay/_experimental/internal/components/ErrorIndicator/ErrorIndicator.tsx
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,58 @@ | ||
import type { ReadyRuntimeError } from '../../helpers/get-error-by-type' | ||
import { Toast } from '../Toast' | ||
import { CloseIcon } from '../../icons/CloseIcon' | ||
|
||
type ErrorIndicatorProps = { | ||
readyErrors: ReadyRuntimeError[] | ||
fullscreen: () => void | ||
hide: () => void | ||
hasStaticIndicator?: boolean | ||
} | ||
|
||
export function ErrorIndicator({ | ||
hasStaticIndicator, | ||
readyErrors, | ||
fullscreen, | ||
hide, | ||
}: ErrorIndicatorProps) { | ||
return ( | ||
<Toast | ||
data-nextjs-toast | ||
className={`nextjs-toast-errors-parent${hasStaticIndicator ? ' nextjs-error-with-static' : ''}`} | ||
onClick={fullscreen} | ||
> | ||
<div className="nextjs-toast-errors"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
> | ||
<circle cx="12" cy="12" r="10"></circle> | ||
<line x1="12" y1="8" x2="12" y2="12"></line> | ||
<line x1="12" y1="16" x2="12.01" y2="16"></line> | ||
</svg> | ||
<span> | ||
{readyErrors.length} issue{readyErrors.length > 1 ? 's' : ''} | ||
</span> | ||
<button | ||
data-nextjs-toast-errors-hide-button | ||
className="nextjs-toast-hide-button" | ||
type="button" | ||
onClick={(e) => { | ||
e.stopPropagation() | ||
hide() | ||
}} | ||
aria-label="Hide Issues" | ||
> | ||
<CloseIcon /> | ||
</button> | ||
</div> | ||
</Toast> | ||
) | ||
} |
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