-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 문서에서 바로 사용해볼 수 있는 Sandpack MDX 컴포넌트 구현 #200
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9a88214
chore: sandpack 및 remark-sandpack 추가
kangju2000 b879b2c
feat: Sandpack MDX 컴포넌트 추가
kangju2000 8d0eb60
feat: choseongIncludes의 데모 컴포넌트를 Sandpack으로 변경
kangju2000 39d8b50
feat: 재컴파일되었을 때 딜레이 세팅
kangju2000 6f59ef5
feat: changeset 추가
kangju2000 c577f25
chore: yarn.lock 업데이트
kangju2000 df3f699
Revert "chore: yarn.lock 업데이트"
kangju2000 01dd3b7
Merge branch 'main' into feat/add-sanpack
okinawaa b282e49
Merge branch 'main' into feat/add-sanpack
kangju2000 8c97e29
chore: cspell 단어 추가 및 eslint 에러 수정
kangju2000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'docs': patch | ||
--- | ||
|
||
feat: 문서에서 바로 실행해볼 수 있는 Sandpack MDX 컴포넌트를 구현합니다. |
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,33 @@ | ||
import { | ||
SandpackCodeEditor, | ||
SandpackConsole, | ||
SandpackLayout, | ||
useLoadingOverlayState, | ||
useSandpackNavigation, | ||
} from '@codesandbox/sandpack-react'; | ||
import { RefreshButton } from './RefreshButton'; | ||
import { useRef } from 'react'; | ||
import { Loading } from './Loading'; | ||
|
||
export function CustomPreset() { | ||
const ref = useRef<{ reset: () => void }>(null); | ||
const { refresh } = useSandpackNavigation(); | ||
const state = useLoadingOverlayState(); | ||
|
||
const handleRefresh = () => { | ||
refresh(); | ||
ref.current?.reset(); | ||
}; | ||
|
||
return ( | ||
<SandpackLayout> | ||
<SandpackCodeEditor showRunButton={false} /> | ||
<SandpackConsole | ||
ref={ref} | ||
standalone | ||
showResetConsoleButton={state !== 'LOADING'} | ||
actionsChildren={state === 'LOADING' ? <Loading /> : <RefreshButton onRefresh={handleRefresh} />} | ||
/> | ||
</SandpackLayout> | ||
); | ||
} |
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,37 @@ | ||
export function Loading({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) { | ||
return ( | ||
<div className={`sp-cube-wrapper absolute right-2 bottom-2 z-50 w-8 h-8 rounded ${className}`} {...props}> | ||
<div className="sp-cube flex transform -translate-x-1 translate-y-[9px] scale-[0.13]"> | ||
<div | ||
className={`sp-sides absolute w-24 h-24 animate-[cube-rotate_1s_linear_infinite]`} | ||
style={{ transform: 'rotateX(-25.5deg) rotateY(45deg)', transformStyle: 'preserve-3d' }} | ||
> | ||
<div | ||
className="absolute w-24 h-24 border-[10px] border-solid border-[#808080] dark:border-[#a8b1c2] rounded-lg bg-white dark:bg-[#282c34] origin-center" | ||
style={{ transform: 'rotateX(90deg) translateZ(44px)' }} | ||
/> | ||
<div | ||
className="absolute w-24 h-24 border-[10px] border-solid border-[#808080] dark:border-[#a8b1c2] rounded-lg bg-white dark:bg-[#282c34] origin-center" | ||
style={{ transform: 'rotateY(90deg) translateZ(44px)' }} | ||
/> | ||
<div | ||
className="absolute w-24 h-24 border-[10px] border-solid border-[#808080] dark:border-[#a8b1c2] rounded-lg bg-white dark:bg-[#282c34] origin-center" | ||
style={{ transform: 'rotateX(-90deg) translateZ(44px)' }} | ||
/> | ||
<div | ||
className="absolute w-24 h-24 border-[10px] border-solid border-[#808080] dark:border-[#a8b1c2] rounded-lg bg-white dark:bg-[#282c34] origin-center" | ||
style={{ transform: 'rotateY(-90deg) translateZ(44px)' }} | ||
/> | ||
<div | ||
className="absolute w-24 h-24 border-[10px] border-solid border-[#808080] dark:border-[#a8b1c2] rounded-lg bg-white dark:bg-[#282c34] origin-center" | ||
style={{ transform: 'rotateY(0deg) translateZ(44px)' }} | ||
/> | ||
<div | ||
className="absolute w-24 h-24 border-[10px] border-solid border-[#808080] dark:border-[#a8b1c2] rounded-lg bg-white dark:bg-[#282c34] origin-center" | ||
style={{ transform: 'rotateY(-180deg) translateZ(44px)' }} | ||
/> | ||
</div> | ||
</div> | ||
</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,9 @@ | ||
import { RefreshIcon, RoundedButton } from '@codesandbox/sandpack-react'; | ||
|
||
export function RefreshButton({ onRefresh }: { onRefresh: () => void }) { | ||
return ( | ||
<RoundedButton onClick={onRefresh}> | ||
<RefreshIcon /> | ||
</RoundedButton> | ||
); | ||
} |
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,34 @@ | ||
import { SandpackProps, SandpackProvider } from '@codesandbox/sandpack-react'; | ||
import { atomDark } from '@codesandbox/sandpack-themes'; | ||
import { baseTemplate } from './baseTemplate'; | ||
import { CustomPreset } from './CustomPreset'; | ||
import { useIsDarkMode } from '@/hooks/use-is-dark-mode'; | ||
import { SandpackLogLevel } from '@codesandbox/sandpack-client'; | ||
|
||
export function Sandpack({ files }: SandpackProps) { | ||
const isDarkMode = useIsDarkMode(); | ||
|
||
return ( | ||
<SandpackProvider | ||
template="vanilla-ts" | ||
theme={isDarkMode ? atomDark : undefined} | ||
files={{ | ||
...baseTemplate.files, | ||
...files, | ||
}} | ||
customSetup={{ | ||
dependencies: baseTemplate.dependencies, | ||
devDependencies: baseTemplate.devDependencies, | ||
}} | ||
options={{ | ||
recompileDelay: 300, | ||
initMode: 'user-visible', | ||
initModeObserverOptions: { rootMargin: '1400px 0px' }, | ||
bundlerURL: 'https://sandpack-bundler.codesandbox.io/', | ||
logLevel: SandpackLogLevel.None, | ||
}} | ||
> | ||
<CustomPreset /> | ||
</SandpackProvider> | ||
); | ||
} |
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,9 @@ | ||
export const baseTemplate = { | ||
files: { | ||
'index.ts': ``, | ||
}, | ||
dependencies: { | ||
'es-hangul': 'latest', | ||
}, | ||
devDependencies: {}, | ||
}; |
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 @@ | ||
export { Sandpack } from './Sandpack'; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sandpack의 로딩 컴포넌트가 export되지 않고 있어 직접 구현했습니다.