Skip to content

Commit

Permalink
enhance: replace placeholder with css (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Jan 25, 2025
1 parent b093a06 commit f037e6d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
12 changes: 9 additions & 3 deletions src/code/code.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Code', () => {
[data-codice-code] .sh__line[data-highlight] {
background-color: var(--codice-code-highlight-color);
}
</style><div data-codice-editor-header="true"><style data-codice-style="true">[data-codice-editor-header] {
</style><div data-codice-editor-header="true" data-codice-editor-header-controls="false"><style data-codice-style="true">[data-codice-editor-header] {
position: relative;
display: flex;
padding: 16px 22px 8px;
Expand All @@ -70,6 +70,9 @@ describe('Code', () => {
[data-codice-editor-header] [data-codice-editor-controls-placeholder] {
width: 52px;
}
[data-codice-editor-header-controls="true"] [data-codice-editor-title] {
padding-right: 52px;
}
[data-codice-editor-header] [data-codice-editor-control] {
display: flex;
width: 10px;
Expand Down Expand Up @@ -102,7 +105,7 @@ describe('Code', () => {
[data-codice-code] .sh__line[data-highlight] {
background-color: var(--codice-code-highlight-color);
}
</style><div data-codice-editor-header="true"><style data-codice-style="true">[data-codice-editor-header] {
</style><div data-codice-editor-header="true" data-codice-editor-header-controls="true"><style data-codice-style="true">[data-codice-editor-header] {
position: relative;
display: flex;
padding: 16px 22px 8px;
Expand All @@ -125,6 +128,9 @@ describe('Code', () => {
[data-codice-editor-header] [data-codice-editor-controls-placeholder] {
width: 52px;
}
[data-codice-editor-header-controls="true"] [data-codice-editor-title] {
padding-right: 52px;
}
[data-codice-editor-header] [data-codice-editor-control] {
display: flex;
width: 10px;
Expand All @@ -133,7 +139,7 @@ describe('Code', () => {
border-radius: 50%;
background-color: var(--codice-editor-control-color);
}
</style><div data-codice-editor-controls="true"><span data-codice-editor-control="true"></span><span data-codice-editor-control="true"></span><span data-codice-editor-control="true"></span></div><span data-codice-editor-controls-placeholder="true"></span></div><pre data-codice-code-content="true"><code><span class="sh__line"><span class="sh__token--identifier" style="color:var(--sh-identifier)">test</span></span></code></pre></div>"
</style><div data-codice-editor-controls="true"><span data-codice-editor-control="true"></span><span data-codice-editor-control="true"></span><span data-codice-editor-control="true"></span></div></div><pre data-codice-code-content="true"><code><span class="sh__line"><span class="sh__token--identifier" style="color:var(--sh-identifier)">test</span></span></code></pre></div>"
`)
})
})
8 changes: 5 additions & 3 deletions src/code/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ function generateHighlightedLines(

export function CodeHeader({ title, controls = false }: { title?: string; controls: boolean }) {
if (!title && !controls) return null
// TODO: migrate inline css

return (
<div data-codice-editor-header>
<div
data-codice-editor-header
data-codice-editor-header-controls={controls}
>
<style data-codice-style>{headerCss}</style>
{controls ? (
<div data-codice-editor-controls>
Expand All @@ -76,7 +79,6 @@ export function CodeHeader({ title, controls = false }: { title?: string; contro
</div>
) : null}
{title ? <div data-codice-editor-title>{title}</div> : null}
{controls ? <span data-codice-editor-controls-placeholder /> : null}
</div>
)
}
Expand Down
3 changes: 3 additions & 0 deletions src/code/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ ${H} [data-codice-editor-controls],
${H} [data-codice-editor-controls-placeholder] {
width: 52px;
}
[data-codice-editor-header-controls="true"] [data-codice-editor-title] {
padding-right: 52px;
}
${H} [data-codice-editor-control] {
display: flex;
width: 10px;
Expand Down
14 changes: 10 additions & 4 deletions src/editor/editor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Code', () => {
[data-codice-editor][data-codice-editor-line-numbers="true"] textarea {
padding-left: 55px;
}
</style><div data-codice-editor-header="true"><style data-codice-style="true">[data-codice-editor-header] {
</style><div data-codice-editor-header="true" data-codice-editor-header-controls="true"><style data-codice-style="true">[data-codice-editor-header] {
position: relative;
display: flex;
padding: 16px 22px 8px;
Expand All @@ -82,6 +82,9 @@ describe('Code', () => {
[data-codice-editor-header] [data-codice-editor-controls-placeholder] {
width: 52px;
}
[data-codice-editor-header-controls="true"] [data-codice-editor-title] {
padding-right: 52px;
}
[data-codice-editor-header] [data-codice-editor-control] {
display: flex;
width: 10px;
Expand All @@ -90,7 +93,7 @@ describe('Code', () => {
border-radius: 50%;
background-color: var(--codice-editor-control-color);
}
</style><div data-codice-editor-controls="true"><span data-codice-editor-control="true"></span><span data-codice-editor-control="true"></span><span data-codice-editor-control="true"></span></div><span data-codice-editor-controls-placeholder="true"></span></div><div data-codice-editor-content="true"><div data-codice-code="true"><style data-codice-style="true">[data-codice-code] {
</style><div data-codice-editor-controls="true"><span data-codice-editor-control="true"></span><span data-codice-editor-control="true"></span><span data-codice-editor-control="true"></span></div></div><div data-codice-editor-content="true"><div data-codice-code="true"><style data-codice-style="true">[data-codice-code] {
--codice-code-line-number-color: #a4a4a4;
--codice-code-highlight-color: #555555;
}
Expand Down Expand Up @@ -184,7 +187,7 @@ describe('Code', () => {
[data-codice-editor][data-codice-editor-line-numbers="true"] textarea {
padding-left: 55px;
}
</style><div data-codice-editor-header="true"><style data-codice-style="true">[data-codice-editor-header] {
</style><div data-codice-editor-header="true" data-codice-editor-header-controls="true"><style data-codice-style="true">[data-codice-editor-header] {
position: relative;
display: flex;
padding: 16px 22px 8px;
Expand All @@ -207,6 +210,9 @@ describe('Code', () => {
[data-codice-editor-header] [data-codice-editor-controls-placeholder] {
width: 52px;
}
[data-codice-editor-header-controls="true"] [data-codice-editor-title] {
padding-right: 52px;
}
[data-codice-editor-header] [data-codice-editor-control] {
display: flex;
width: 10px;
Expand All @@ -215,7 +221,7 @@ describe('Code', () => {
border-radius: 50%;
background-color: var(--codice-editor-control-color);
}
</style><div data-codice-editor-controls="true"><span data-codice-editor-control="true"></span><span data-codice-editor-control="true"></span><span data-codice-editor-control="true"></span></div><div data-codice-editor-title="true">file.js</div><span data-codice-editor-controls-placeholder="true"></span></div><div data-codice-editor-content="true"><div data-codice-code="true"><style data-codice-style="true">[data-codice-code] {
</style><div data-codice-editor-controls="true"><span data-codice-editor-control="true"></span><span data-codice-editor-control="true"></span><span data-codice-editor-control="true"></span></div><div data-codice-editor-title="true">file.js</div></div><div data-codice-editor-content="true"><div data-codice-code="true"><style data-codice-style="true">[data-codice-code] {
--codice-code-line-number-color: #a4a4a4;
--codice-code-highlight-color: #555555;
}
Expand Down

0 comments on commit f037e6d

Please sign in to comment.