Skip to content

Commit 923f881

Browse files
committed
docs: polish examples
1 parent f0de66d commit 923f881

File tree

6 files changed

+180
-110
lines changed

6 files changed

+180
-110
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ jobs:
6363
if: steps.determine_tag.outputs.tag != ''
6464
run: |
6565
echo "Publishing to ${{ steps.determine_tag.outputs.tag }} tag"
66-
pnpm publish --tag ${{ steps.determine_tag.outputs.tag }}
66+
pnpm publish --tag ${{ steps.determine_tag.outputs.tag }} --no-git-check
6767
6868
- name: Publish to latest
6969
if: steps.determine_tag.outputs.tag == ''
7070
run: |
7171
echo "Publishing to latest"
72-
pnpm publish
72+
pnpm publish --no-git-check

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131
"@types/react": "^19.0.7",
3232
"@types/react-dom": "^19.0.3",
3333
"bunchee": "^6.3.2",
34-
"codice": "^0.5.0",
34+
"codice": "1.0.0-beta.3",
3535
"devjar": "link:./",
3636
"next": "^15.1.5",
3737
"react": "^19.0.0",
3838
"react-dom": "^19.0.0",
39-
"sugar-high": "^0.8.2",
4039
"typescript": "^5.7.3"
4140
},
4241
"packageManager": "[email protected]"

pnpm-lock.yaml

+9-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/app/page.tsx

+83-57
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
'use client'
1+
import { Codesandbox } from '../ui/codesandbox'
22

3-
import { useState } from 'react'
4-
import { Editor } from 'codice'
5-
import { DevJar } from 'devjar'
6-
import { highlight } from 'sugar-high'
7-
import FileTab from '../ui/file-tab'
8-
9-
const CDN_HOST = 'https://esm.sh'
10-
11-
const defaultFiles = {
3+
const codeSample4 = {
124
'index.js': `\
135
import { useState } from 'react'
146
@@ -67,63 +59,97 @@ const defaultFiles = {
6759
`,
6860
}
6961

70-
export default function Page() {
71-
const [activeFile, setActiveFile] = useState('index.js')
72-
const [files, setFiles] = useState(defaultFiles)
73-
const [error, setError] = useState(null)
62+
63+
const codeSample2 = {
64+
'index.js': `\
65+
import React, { useState } from "react";
66+
67+
function App() {
68+
const [darkMode, setDarkMode] = useState(false);
7469
7570
return (
76-
<div>
71+
<div
72+
style={{
73+
backgroundColor: darkMode ? "#333" : "#fff",
74+
color: darkMode ? "#fff" : "#000",
75+
height: "100vh",
76+
display: "flex",
77+
justifyContent: "center",
78+
alignItems: "center",
79+
flexDirection: "column",
80+
}}
81+
>
82+
<h1>{darkMode ? "Dark Mode" : "Light Mode"}</h1>
83+
<button onClick={() => setDarkMode(!darkMode)}>
84+
Toggle {darkMode ? "Light" : "Dark"} Mode
85+
</button>
86+
</div>
87+
);
88+
}
89+
90+
export default App;
91+
`,
92+
}
93+
94+
const codeSample3 = {
95+
'index.js': `\
96+
import React, { useState } from "react";
97+
98+
const quotes = [
99+
"The only limit to our realization of tomorrow is our doubts of today.",
100+
"The future belongs to those who believe in the beauty of their dreams.",
101+
"Do not watch the clock. Do what it does. Keep going.",
102+
"You miss 100% of the shots you don't take.",
103+
"Life is 10% what happens to us and 90% how we react to it."
104+
];
105+
106+
function App() {
107+
const [quote, setQuote] = useState(quotes[0]);
108+
109+
const generateQuote = () => {
110+
const randomIndex = Math.floor(Math.random() * quotes.length);
111+
setQuote(quotes[randomIndex]);
112+
};
113+
114+
return (
115+
<div style={{ textAlign: "center", padding: "2rem" }}>
116+
<h1>Random Quote</h1>
117+
<p>"{quote}"</p>
118+
<button onClick={generateQuote}>New Quote</button>
119+
</div>
120+
);
121+
}
122+
123+
export default App;
124+
`,
125+
}
126+
127+
const codeSample1 = {
128+
'index.js': `\
129+
export default function App() {
130+
return "hello world"
131+
}
132+
`,
133+
}
134+
135+
export default function Page() {
136+
return (
137+
<main>
77138
<div>
78139
<h1>Devjar</h1>
79140
<p>
80141
A live-code runtime for React, running directly in the browser. Perfect for interactive demos, documentation,
81142
and real-time code previews. Simple to integrate and highly flexible for any React project.
82143
</p>
83-
<br />
84-
<div className="filetree">
85-
{Object.keys(files).map((filename) => (
86-
<div
87-
role="button"
88-
key={filename}
89-
data-disabled={filename === activeFile}
90-
className={'filetab filetab--' + (filename === activeFile ? 'active' : '')}
91-
onClick={() => setActiveFile(filename)}
92-
>
93-
{filename + (filename.endsWith('.css') || filename.endsWith('.js') ? '' : '.js')}
94-
</div>
95-
))}
96-
97-
<FileTab files={files} setFiles={setFiles} setActiveFile={setActiveFile} />
98-
</div>
99-
<Editor
100-
highlight={highlight}
101-
className="editor"
102-
controls={false}
103-
title={null}
104-
value={files[activeFile]}
105-
onChange={(code) => {
106-
setFiles({
107-
...files,
108-
[activeFile]: code,
109-
})
110-
}}
111-
/>
144+
<br />
112145
</div>
113146

114-
<div className="preview">
115-
<DevJar
116-
className="preview--result"
117-
files={files}
118-
onError={(err) => {
119-
setError(err)
120-
}}
121-
getModuleUrl={(m) => {
122-
return `${CDN_HOST}/${m}`
123-
}}
124-
/>
125-
{error && <pre className="preview--error" dangerouslySetInnerHTML={{ __html: error.toString() }} />}
147+
<div className='codesandboxes'>
148+
<Codesandbox files={codeSample1} />
149+
<Codesandbox files={codeSample4} />
150+
<Codesandbox files={codeSample2} />
151+
<Codesandbox files={codeSample3} />
126152
</div>
127-
</div>
153+
</main>
128154
)
129155
}

site/styles.css

+22-38
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ html {
55
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
66
'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans',
77
'Helvetica Neue', sans-serif;
8+
margin: 0;
9+
padding: 0;
810
}
911
body {
10-
max-width: 600px;
11-
margin: auto;
12-
padding: 0 16px;
12+
margin: 0;
13+
padding: 0 8px;
14+
max-width: 1260px;
15+
}
16+
main {
17+
min-width: 600px;
18+
margin: 0 auto;
1319
}
1420
:root {
1521
--sh-class: #6f42c1;
@@ -21,8 +27,6 @@ body {
2127
--sh-jsxliterals: #24292e;
2228
--sh-entity: #424d5b;
2329
--sh-property: #1d3147;
24-
--codice-editor-text-color: transparent;
25-
--codice-editor-background-color: transparent;
2630
}
2731

2832
a, a:focus, a:visited {
@@ -32,16 +36,6 @@ a:hover {
3236
color: #424d5b;
3337
}
3438

35-
.sh__line::before {
36-
counter-increment: sh-line-number 1;
37-
content: counter(sh-line-number);
38-
width: 24px;
39-
display: inline-block;
40-
margin-right: 18px;
41-
margin-left: -42px;
42-
text-align: right;
43-
color: #a4a4a4;
44-
}
4539
.editor {
4640
position: relative;
4741
max-height: 300px;
@@ -52,12 +46,6 @@ a:hover {
5246
box-shadow: 0 24px 40px 4px rgb(200 200 200 / 50%);
5347
}
5448

55-
.editor[data-codice-editor] code, .editor[data-codice-editor] textarea {
56-
padding: 24px 16px;
57-
padding-left: 54px;
58-
overflow-y: hidden;
59-
}
60-
6149
pre {
6250
width: 100%;
6351
}
@@ -68,26 +56,10 @@ pre, textarea, .preview--result {
6856
line-height: 1.25em;
6957
caret-color: #333;
7058
}
71-
textarea {
72-
position: absolute;
73-
top: 0;
74-
bottom: 0;
75-
left: 0;
76-
right: 0;
77-
height: 100%;
78-
width: 100%;
79-
}
8059
textarea:focus,
8160
textarea:focus-visible {
8261
outline: none;
8362
}
84-
85-
code {
86-
counter-reset: sh-line-number;
87-
overflow-y: auto;
88-
height: 100%;
89-
width: 100%;
90-
}
9163
.preview {
9264
position: relative;
9365
border-top: 1px solid rgb(229, 231, 235);
@@ -97,7 +69,6 @@ code {
9769
padding: 8px;
9870
font-size: 13px;
9971
color: #f47067;
100-
10172
position: absolute;
10273
top: 0;
10374
right: 0;
@@ -160,4 +131,17 @@ code {
160131
background-color: #f6f6f6e0;
161132
cursor: pointer;
162133
color: #000;
134+
}
135+
136+
[data-codesandbox] {
137+
max-width: 600px;
138+
width: 100%;
139+
padding: 0 8px;
140+
}
141+
142+
.codesandboxes {
143+
display: grid;
144+
grid-template-columns: repeat(auto-fill, minmax(600px, 1fr));
145+
gap: 16px;
146+
163147
}

0 commit comments

Comments
 (0)