-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
134 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.highlight { | ||
background: #1ea7fd2b; | ||
border-radius: 4px; | ||
} | ||
.widget { | ||
border: 1px solid #1ea7fd; | ||
border-radius: 2px; | ||
padding: 2px 4px 2px 12px; | ||
margin-left: 6px; | ||
position: relative; | ||
cursor: pointer; | ||
} | ||
|
||
.widget:before { | ||
content: attr(data-id); | ||
background: #1ea7fd; | ||
border-radius: 100%; | ||
position: absolute; | ||
width: 16px; | ||
display: block; | ||
height: 16px; | ||
left: -8px; | ||
top: 2px; | ||
font-size: 11px; | ||
text-align: center; | ||
color: white; | ||
line-height: 17px; | ||
} |
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,31 @@ | ||
'use client' | ||
|
||
import { | ||
CodeViewerProps, | ||
SandpackFiles, | ||
SandpackCodeViewer as SPCodeViewer, | ||
useSandpack, | ||
} from '@codesandbox/sandpack-react' | ||
|
||
import { useEffect, useState } from 'react' | ||
import './Sandpack.css' | ||
|
||
type Decorators = CodeViewerProps['decorators'] | ||
|
||
export function SandpackCodeViewer( | ||
props: CodeViewerProps & { filesDecorators?: Record<keyof SandpackFiles, Decorators> }, | ||
) { | ||
const { sandpack } = useSandpack() | ||
const { activeFile } = sandpack | ||
|
||
const { filesDecorators, ...restCodeViewerProps } = props ?? {} | ||
|
||
const [decorators, setDecorators] = useState<Decorators>(undefined) | ||
useEffect(() => { | ||
if (!filesDecorators) return | ||
|
||
setDecorators(filesDecorators[activeFile]) | ||
}, [activeFile, filesDecorators]) | ||
|
||
return <SPCodeViewer {...restCodeViewerProps} decorators={decorators} /> | ||
} |