Skip to content

Commit c849dae

Browse files
authored
docs: refine live playground editor chrome (#97)
* docs: refine live code editor chrome * docs: compose live playground with Nova UI components * docs: polish live editor toolbar styles
1 parent 64ac901 commit c849dae

3 files changed

Lines changed: 48 additions & 32 deletions

File tree

docs/.vitepress/theme/components/LiveCodeEditor.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useContext, useEffect, useRef } from 'react'
22

33
import { LiveContext, LiveEditor } from 'react-live'
4+
import { Flex, Tag, Text } from '@wuyangfan/nova-ui'
45

56
function lineCount(code: string) {
67
if (!code) {
@@ -37,6 +38,7 @@ export function LiveCodeEditor() {
3738

3839
const { code, language } = ctx
3940
const lines = Math.max(lineCount(code), 1)
41+
const badge = languageBadge(language)
4042

4143
const mainRef = useRef<HTMLDivElement>(null)
4244
const gutterRef = useRef<HTMLDivElement>(null)
@@ -76,22 +78,25 @@ export function LiveCodeEditor() {
7678
}, [code])
7779

7880
return (
79-
<div className="live-code-editor">
80-
<div className="live-code-editor-toolbar">
81-
<span className="live-code-editor-lang">{languageBadge(language)}</span>
82-
</div>
83-
<div className="live-code-editor-main" ref={mainRef}>
84-
<div className="live-code-editor-gutter" ref={gutterRef} aria-hidden="true">
81+
<Flex vertical className="live-code-editor">
82+
<Flex className="live-code-editor-toolbar" align="center" justify="between">
83+
<Text className="live-code-editor-title">Code</Text>
84+
<Tag className="live-code-editor-lang" aria-label={`${badge} example code`}>
85+
{badge}
86+
</Tag>
87+
</Flex>
88+
<Flex className="live-code-editor-main" ref={mainRef}>
89+
<Flex vertical className="live-code-editor-gutter" ref={gutterRef} aria-hidden="true">
8590
{Array.from({ length: lines }, (_, index) => (
86-
<div key={index} className="live-code-editor-gutter-line">
91+
<Text key={index} className="live-code-editor-gutter-line">
8792
{index + 1}
88-
</div>
93+
</Text>
8994
))}
90-
</div>
91-
<div className="live-code-editor-editor">
95+
</Flex>
96+
<Flex vertical className="live-code-editor-editor">
9297
<LiveEditor className="live-code-editor-live" />
93-
</div>
94-
</div>
95-
</div>
98+
</Flex>
99+
</Flex>
100+
</Flex>
96101
)
97-
}
102+
}

docs/.vitepress/theme/components/LivePlayground.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ const ReactLiveMount = defineComponent({
8080

8181
root.render(
8282
React.createElement(
83-
'div',
84-
{ className: 'live-wrap' },
83+
NovaUI.Flex,
84+
{ className: 'live-wrap', vertical: true },
8585
React.createElement(
8686
LiveProvider,
8787
{
@@ -90,8 +90,8 @@ const ReactLiveMount = defineComponent({
9090
language: prismLanguage,
9191
enableTypeScript: resolveEnableTypeScript(props.language),
9292
},
93-
React.createElement('div', { className: 'live-pane live-preview' }, React.createElement(LivePreview, null)),
94-
React.createElement('div', { className: 'live-pane live-editor' }, React.createElement(LiveCodeEditor, null)),
93+
React.createElement(NovaUI.Flex, { className: 'live-pane live-preview' }, React.createElement(LivePreview, null)),
94+
React.createElement(NovaUI.Flex, { className: 'live-pane live-editor', vertical: true }, React.createElement(LiveCodeEditor, null)),
9595
React.createElement(LiveError, { className: 'live-error' }),
9696
),
9797
),
@@ -114,4 +114,4 @@ const ReactLiveMount = defineComponent({
114114
},
115115
})
116116

117-
export default ReactLiveMount
117+
export default ReactLiveMount

docs/.vitepress/theme/custom.css

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,28 @@
5252
}
5353

5454
.live-code-editor-toolbar {
55-
display: flex;
56-
justify-content: flex-end;
57-
align-items: center;
58-
padding: 6px 10px;
55+
justify-content: space-between;
56+
padding: 8px 12px;
5957
border-bottom: 1px solid var(--vp-c-divider);
60-
background: var(--vp-code-block-bg, var(--vp-code-bg, var(--vp-c-bg-alt)));
58+
background: color-mix(in srgb, var(--vp-c-bg-soft) 80%, transparent);
59+
}
60+
61+
.live-code-editor-title {
62+
color: var(--vp-c-text-2) !important;
63+
font-size: 12px !important;
64+
font-weight: 600;
65+
letter-spacing: 0.02em;
6166
}
6267

6368
.live-code-editor-lang {
64-
font-size: 11px;
69+
border-color: var(--vp-c-divider) !important;
70+
background: var(--vp-c-bg) !important;
71+
color: var(--vp-c-text-2) !important;
72+
font-size: 11px !important;
6573
font-weight: 600;
6674
letter-spacing: 0.06em;
67-
color: var(--vp-c-text-3);
68-
border: 1px solid var(--vp-c-divider);
69-
border-radius: 6px;
70-
padding: 2px 8px;
75+
border-radius: 999px !important;
76+
padding: 2px 8px !important;
7177
}
7278

7379
.live-code-editor-main {
@@ -95,8 +101,13 @@
95101
}
96102

97103
.live-code-editor-gutter-line {
98-
font-size: 13px;
99-
line-height: 1.55;
104+
display: block;
105+
color: var(--vp-c-text-3) !important;
106+
font-family:
107+
ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
108+
monospace !important;
109+
font-size: 13px !important;
110+
line-height: 1.55 !important;
100111
min-height: calc(13px * 1.55);
101112
}
102113

@@ -175,4 +186,4 @@
175186
white-space: normal;
176187
line-height: 1.6;
177188
color: var(--vp-c-text-2);
178-
}
189+
}

0 commit comments

Comments
 (0)