Skip to content

Commit a118f8a

Browse files
committed
Move styles to css
1 parent 23761a7 commit a118f8a

File tree

6 files changed

+31
-21
lines changed

6 files changed

+31
-21
lines changed

packages/mini-editor/src/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import "~@code-hike/mini-frame/dist/index.scss";
22
@import "~@code-hike/mini-terminal/dist/index.scss";
3+
@import "~@code-hike/smooth-code/dist/index.scss";
34

45
/** tabs */
56

packages/smooth-code/src/index.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.ch-code-line-number {
2+
user-select: none;
3+
text-align: right;
4+
display: inline-block;
5+
box-sizing: border-box;
6+
padding-right: 1.5ch;
7+
font-variant-numeric: tabular-nums;
8+
}

packages/smooth-code/src/smooth-container.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export function SmoothContainer({
5454

5555
const lineNumberPad =
5656
(dimensions?.lineNumberWidth || 0) * zoom
57-
const leftPad = 16 + lineNumberPad
57+
58+
const leftPad = lineNumberPad || 16
5859

5960
const width = Math.max(
6061
focusWidth + leftPad,
@@ -221,10 +222,14 @@ function getContentProps({
221222
} = dimensions!
222223
const originalFocusHeight =
223224
(extremes[1] - extremes[0] + 3) * lineHeight
225+
226+
const leftPadding = dimensions?.lineNumberWidth || 16
227+
const rightPadding = 16
228+
224229
const zoom = Math.max(
225230
Math.min(
226-
// TODO consider line number width
227-
(containerWidth - 16 * 2) / lineWidth,
231+
(containerWidth - leftPadding - rightPadding) /
232+
lineWidth,
228233
containerHeight / originalFocusHeight,
229234
maxZoom
230235
),

packages/smooth-code/src/smooth-lines.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,16 @@ function LineGroup({
159159
<React.Fragment key={key}>
160160
{lineNumberWidth ? (
161161
<span
162+
className="ch-code-line-number"
162163
style={{
164+
position: "absolute",
163165
top: 0,
164166
left: 0,
165167
transform: `translate(${
166168
dx * focusWidth
167169
}px, ${(dy - startY) * lineHeight}px)`,
168-
position: "absolute",
169-
userSelect: "none",
170170
width: lineNumberWidth,
171-
textAlign: "right",
172-
display: "inline-block",
173-
boxSizing: "border-box",
174-
paddingRight: "1ch",
175171
opacity,
176-
fontVariantNumeric: "tabular-nums",
177172
color: getColor(
178173
theme,
179174
ColorName.LineNumberForeground

packages/smooth-code/src/use-dimensions.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,11 @@ function useDimensions(
7979
}
8080
key={i}
8181
>
82-
<span
83-
style={{
84-
display: "inline-block",
85-
width: lineNumbers ? "auto" : 0,
86-
}}
87-
>
88-
{lineCount}0
89-
</span>
82+
{lineNumbers ? (
83+
<span className="ch-code-line-number">
84+
_{lineCount}
85+
</span>
86+
) : undefined}
9087
<div style={{ display: "inline-block" }}>
9188
<span>{line}</span>
9289
</div>
@@ -119,7 +116,9 @@ function useDimensions(
119116
const lineNumberSpan = pll?.querySelector(
120117
":scope > span"
121118
) as HTMLElement
122-
const lnw = getWidthWithoutPadding(lineNumberSpan)
119+
const lnw = lineNumberSpan
120+
? getWidthWithPadding(lineNumberSpan)
121+
: 0
123122

124123
const plw = getWidthWithoutPadding(lineContentDiv)
125124
const colWidth = plw / prevLongestLine.length || 1
@@ -195,6 +194,10 @@ function getWidthWithoutPadding(element: HTMLElement) {
195194
parseFloat(computedStyle.paddingRight)
196195
)
197196
}
197+
function getWidthWithPadding(element: HTMLElement) {
198+
const computedStyle = getComputedStyle(element)
199+
return parseFloat(computedStyle.width)
200+
}
198201
function getHeightWithoutPadding(
199202
element: HTMLElement | null
200203
) {

packages/storybook/src/code-tween.story.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ const x = (y) => y++ * foobarbaz
6565
)
6666
}, [])
6767

68-
console.log({ tween })
69-
7068
return (
7169
<WithProgress>
7270
{progress => (

0 commit comments

Comments
 (0)