Skip to content

Commit 329ae83

Browse files
authored
polish codesandbox component (#53)
1 parent 8a4e6fd commit 329ae83

File tree

6 files changed

+75
-79
lines changed

6 files changed

+75
-79
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"@types/react": "^19.0.7",
3232
"@types/react-dom": "^19.0.3",
3333
"bunchee": "^6.3.3",
34-
"codice": "^1.2.1",
35-
"devjar": "link:./",
34+
"codice": "^1.3.2",
35+
"devjar": "link:",
3636
"next": "^15.1.5",
3737
"react": "^19.0.0",
3838
"react-dom": "^19.0.0",

pnpm-lock.yaml

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

site/app/page.tsx

+15-7
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,24 @@ export default function Page() {
123123
</p>
124124
</div>
125125

126-
<h2 className="text-center">Examples</h2>
127-
<div className="codesandboxes">
128-
<Codesandbox title="Tailwind CSS" files={codeSampleTheme} />
129-
<Codesandbox title="Plain CSS" files={codeSampleCssImport} />
130-
</div>
131-
132-
<div className="playground">
126+
<div className="playground section">
133127
<h1>Playground</h1>
134128
<Codesandbox files={codeSamplePlayground} />
135129
</div>
130+
131+
<div className='showcase'>
132+
<h1>Showcase</h1>
133+
<div className="codesandboxes section">
134+
<div>
135+
<h2>Tailwind CSS</h2>
136+
<Codesandbox files={codeSampleTheme} />
137+
</div>
138+
<div>
139+
<h2>Plain CSS</h2>
140+
<Codesandbox files={codeSampleCssImport} />
141+
</div>
142+
</div>
143+
</div>
136144
</main>
137145
)
138146
}

site/styles.css

+41-53
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ html {
1111
body {
1212
margin: 0;
1313
padding: 0 8px;
14-
max-width: 1260px;
15-
margin: 0 auto;
1614
width: 100vw;
1715
}
1816
:root {
@@ -47,21 +45,16 @@ a:hover {
4745
overflow-y: scroll;
4846
justify-content: stretch;
4947
flex-direction: column;
50-
box-shadow: 0 24px 40px 4px rgb(200 200 200 / 50%);
51-
}
52-
.preview--result {
53-
font-family: Consolas, Monaco, monospace;
54-
border: none;
55-
font-size: 16px;
56-
line-height: 1.25em;
5748
}
49+
5850
textarea:focus,
5951
textarea:focus-visible {
6052
outline: none;
6153
}
6254
.preview {
6355
position: relative;
64-
border-top: 1px solid rgb(229, 231, 235);
56+
border-top: 1px solid #dfe0e5;
57+
padding: 1.5rem 1rem;
6558
}
6659
.preview--error {
6760
margin: 0;
@@ -84,78 +77,80 @@ textarea:focus-visible {
8477
color: #fff;
8578
}
8679
.preview--result {
87-
padding: 8px 12px;
80+
font-family: Consolas, Monaco, monospace;
81+
border: none;
82+
font-size: 16px;
83+
line-height: 1.25em;
84+
background-color: #fff;
8885
width: 100%;
89-
background-color: rgb(246 247 249);
90-
box-shadow: 0 16px 40px 4px rgb(200 200 200 / 50%);
9186
}
9287

9388
.filetree {
9489
display: flex;
9590
position: relative;
96-
padding-right: 60px;
97-
border-bottom: 2px solid rgb(235 236 240);
91+
padding-right: 2rem;
9892
}
9993

10094
.filetab {
10195
position: relative;
102-
padding: 3px 12px;
96+
padding: 0.4rem 1.5rem;
10397
border: none;
98+
line-height: 1;
10499
background-color: #fff;
105100
cursor: pointer;
106101
color: #000;
107102
}
108103
.filetab:hover {
109-
opacity: .6;
104+
opacity: .8;
110105
}
111106
.filetab--active {
112-
color: rgb(8, 126, 164);
107+
color: #087ea4;
113108
}
114109
.filetab--active::after {
115110
content: '';
116111
position: absolute;
117112
bottom: -2px;
118113
height: 2px;
119-
background: rgb(8, 126, 164);
114+
background: #087ea4;
120115
left: 0;
121116
width: 100%;
122117
}
123118
.filetab--new {
124-
background-color: #f6f6f6e0;
119+
padding: 0;
120+
color: #087ea4;
121+
background-color: #f0f0f0;
125122
}
126123
.filetab__button {
127-
padding: 0;
124+
display: inline-block;
125+
padding: 0.4rem 1.5rem;
128126
margin: 0;
127+
line-height: 1;
129128
border: none;
130-
background-color: #f6f6f6e0;
129+
background-color: transparent;
131130
cursor: pointer;
132-
color: #000;
131+
color: #70858c;
133132
}
134-
135-
[data-codesandbox] {
136-
max-width: 600px;
137-
width: 100%;
138-
padding: 0 8px;
133+
.filetab__input {
134+
display: inline-block;
135+
outline: none;
136+
border: none;
137+
padding: 0.4rem 1.5rem;
138+
margin: 0;
139+
background-color: #f0f0f0;
139140
}
140141

141-
.codesandboxes {
142-
display: grid;
143-
grid-template-columns: repeat(auto-fill, minmax(600px, 1fr));
144-
gap: 16px;
145-
margin: 54px 0;
142+
[data-codesandbox] {
143+
box-shadow: 0 24px 40px 4px rgb(200 200 200 / 50%);
146144
}
147145

148146
.titles {
149147
display: flex;
150148
flex-direction: column;
151149
justify-content: space-between;
152-
align-items: center;
153-
padding: 32px 0;
150+
padding: 1rem 0;
154151
line-height: 1.4;
155152
width: 100%;
156153
max-width: 680px;
157-
margin: 0 auto;
158-
text-align: center;
159154
color: #404756;
160155
}
161156

@@ -171,7 +166,7 @@ textarea:focus-visible {
171166
}
172167

173168
.titles p {
174-
font-size: 20px;
169+
font-size: 18px;
175170
margin: 0;
176171
padding: 8px 0;
177172
}
@@ -180,26 +175,19 @@ textarea:focus-visible {
180175
display: flex;
181176
flex-direction: column;
182177
justify-content: center;
183-
align-items: center;
184-
padding: 32px 0;
185178
line-height: 1.4;
186179
width: 100%;
187180
max-width: 680px;
188-
margin: 0 auto;
189181
}
190182

191-
@media screen and (max-width: 1260px) {
192-
.codesandboxes {
193-
margin: 32px auto;
194-
display: flex;
195-
flex-direction: column;
196-
align-items: center;
197-
}
183+
.showcase {
184+
justify-content: center;
185+
line-height: 1.4;
186+
margin: 2rem 0;
198187
}
199188

200-
@media screen and (max-width: 680px) {
201-
.titles {
202-
margin: 0 auto;
203-
max-width: 100%;
204-
}
189+
.section {
190+
max-width: 680px;
191+
border-bottom: 1px dashed #e5e7eb;
192+
padding: 32px 0;
205193
}

site/ui/codesandbox.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import FileTab from './file-tab'
88
import { useEffect, useState } from 'react'
99

1010
export function Codesandbox({
11-
title,
1211
files: initialFiles
1312
}: {
14-
title?: string
1513
files: Record<string, string>
1614
}) {
1715
const [activeFile, setActiveFile] = useState('index.js')
@@ -24,7 +22,6 @@ export function Codesandbox({
2422

2523
return (
2624
<div data-codesandbox>
27-
{title ? <h2>{title}</h2> : null}
2825
<div className="filetree">
2926
{Object.keys(files).map((filename) => (
3027
<div
@@ -37,7 +34,6 @@ export function Codesandbox({
3734
{filename + (filename.endsWith('.css') || filename.endsWith('.js') ? '' : '.js')}
3835
</div>
3936
))}
40-
4137
<FileTab files={files} setFiles={setFiles} setActiveFile={setActiveFile} />
4238
</div>
4339
<Editor

site/ui/file-tab.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ function FileTab({ files, setFiles, setActiveFile }) {
2929
}
3030

3131
return (
32-
<div className="filetab filetab--new" role="button">
32+
<div
33+
className="filetab filetab--new"
34+
role="button"
35+
{...(!isEditing && { onClick: () => setIsEditing(true) })}
36+
>
3337
{isEditing ? (
3438
<input
3539
type="text"
@@ -49,9 +53,9 @@ function FileTab({ files, setFiles, setActiveFile }) {
4953
onBlur={handleNewFileSubmit}
5054
/>
5155
) : (
52-
<button className="filetab__button" onClick={() => setIsEditing(true)} aria-label="Add new file">
56+
<span className="filetab__button" aria-label="Add new file">
5357
+ New
54-
</button>
58+
</span>
5559
)}
5660
</div>
5761
)

0 commit comments

Comments
 (0)