Add loading to editor

This commit is contained in:
2024-01-09 17:50:59 +08:00
parent d802844516
commit e846c28082
3 changed files with 104 additions and 47 deletions

View File

@@ -1,4 +1,31 @@
.monaco-editor-light { @mixin keyframes($animationName) {
@-webkit-keyframes #{$animationName} {
@content
}
@-moz-keyframes #{$animationName} {
@content
}
@-o-keyframes #{$animationName} {
@content
}
@keyframes #{$animationName} {
@content
}
}
@mixin unique-keyframes {
$animationName: unique-id();
animation-name: $animationName;
@include keyframes($animationName) {
@content
}
}
[data-component=playground-code-editor-editor] {
position: relative;
height: 0;
.monaco-editor-light {
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
background-color: var(--border); background-color: var(--border);
@@ -18,9 +45,9 @@
.jsx-tag-attribute-key { .jsx-tag-attribute-key {
color: #f00; color: #f00;
} }
} }
.monaco-editor-vs-dark { .monaco-editor-vs-dark {
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
background-color: var(--border); background-color: var(--border);
@@ -40,4 +67,32 @@
.jsx-tag-attribute-key { .jsx-tag-attribute-key {
color: #9cdcfe; color: #9cdcfe;
} }
}
.playground-code-editor-loading {
position: absolute;
top: 0;
right: 0;
margin: 4px;
width: 10px;
height: 10px;
border-radius: 50%;
border: {
top: 2px #666 solid;
bottom: 2px #ddd solid;
left: 2px #ddd solid;
right: 2px #ddd solid;
};
animation: .6s linear infinite;
@include unique-keyframes {
0% {
transform: rotateZ(0);
}
100% {
transform: rotateZ(360deg);
}
}
}
} }

View File

@@ -36,7 +36,7 @@ const Editor: React.FC<EditorProps> = ({
highlighter: () => undefined, highlighter: () => undefined,
dispose: () => undefined dispose: () => undefined
}) })
const { onWatch } = useTypesProgress() const { total, finished, onWatch } = useTypesProgress()
const file = files[selectedFileName] ?? { name: 'Untitled' } const file = files[selectedFileName] ?? { name: 'Untitled' }
const handleOnEditorDidMount = (editor: editor.IStandaloneCodeEditor, monaco: Monaco) => { const handleOnEditorDidMount = (editor: editor.IStandaloneCodeEditor, monaco: Monaco) => {
@@ -87,6 +87,7 @@ const Editor: React.FC<EditorProps> = ({
return ( return (
<> <>
<div data-component={'playground-code-editor-editor'}>
<MonacoEditor <MonacoEditor
theme={theme} theme={theme}
path={file.name} path={file.name}
@@ -102,6 +103,8 @@ const Editor: React.FC<EditorProps> = ({
readOnly: readonly readOnly: readonly
}} }}
/> />
{total > 0 && !finished && <div className={'playground-code-editor-loading'} />}
</div>
</> </>
) )
} }

View File

@@ -1,7 +1,6 @@
import React from 'react' import React from 'react'
import { IPlayground } from '@/components/Playground/shared'
const ReactPlayground: React.FC<IPlayground> = () => { const ReactPlayground: React.FC = () => {
return <></> return <></>
} }