Skip to content

Commit f98dd02

Browse files
committed
update: minor styling changes
Code snippets refactored into a header.
1 parent ef8fdb2 commit f98dd02

File tree

7 files changed

+37
-34
lines changed

7 files changed

+37
-34
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
.DS_Store

_code-blocks/helpers.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ export const createCopyButton = (id: string) => {
3737
* @param title
3838
* @returns
3939
*/
40-
export const createTitleElement = (title: string): HTMLDivElement => {
40+
export const createDivElement = (className: string, title?: string): HTMLDivElement => {
4141
const titleElement = document.createElement('div');
42-
titleElement.classList.add('codeTitle');
43-
titleElement.textContent = title;
42+
titleElement.classList.add(className);
43+
if (title) titleElement.textContent = title;
44+
4445
return titleElement;
4546
};

_code-blocks/webflow-theme.css

+10-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pre {
88
font-weight: 400;
99
max-width: 600px;
1010
font-size: 14px;
11-
padding: 74px 16px 16px;
11+
padding: 16px 16px 16px;
1212
border-radius: 6px;
1313
margin: 0;
1414
}
@@ -160,13 +160,16 @@ pre {
160160
font-style: italic;
161161
}
162162

163+
/* Header */
164+
.snippetHeader {
165+
display: flex;
166+
align-items: center;
167+
justify-content: space-between;
168+
margin-bottom: 16px;
169+
}
170+
163171
/* Copy Button */
164172
.copyCodeBtn {
165-
position: absolute;
166-
left: auto;
167-
top: 16px;
168-
right: 16px;
169-
bottom: auto;
170173
display: -webkit-box;
171174
display: -webkit-flex;
172175
display: -ms-flexbox;
@@ -193,17 +196,9 @@ pre {
193196

194197
/* Code Title */
195198
.codeTitle {
196-
position: absolute;
197-
left: 16px;
198-
top: 16px;
199-
right: auto;
200-
bottom: auto;
201-
display: -webkit-flex;
202-
display: -ms-flexbox;
203-
display: flex;
204199
font-family: Inter, -apple-system, system-ui, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue',
205200
Helvetica, Arial, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif;
206-
font-size: 25px;
201+
font-size: 16px;
207202
font-weight: normal;
208203
color: #d9d9d9;
209204
line-height: 1.25;

_code-blocks/webflow/embed-code.js

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

_code-blocks/webflow/embed-code.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createCopyButton, createTitleElement, populateCodeElement } from '../helpers';
1+
import { createCopyButton, createDivElement, populateCodeElement } from '../helpers';
22
import initCopyClipboard from '@finsweet/webflow-addons/copy-clipboard';
33
import highlightJS from '../hljs';
44

@@ -22,6 +22,9 @@ document.addEventListener('DOMContentLoaded', async () => {
2222
const codeElement = document.createElement('code');
2323
const codeElementId = `hljs-code-${index}`;
2424
codeElement.id = codeElementId;
25+
const snippetHeader = createDivElement('snippetHeader');
26+
27+
preElement.appendChild(snippetHeader);
2528
preElement.appendChild(codeElement);
2629

2730
// Get the title
@@ -32,8 +35,8 @@ document.addEventListener('DOMContentLoaded', async () => {
3235
const [brackedTitle, title] = titleMatch;
3336
src = src.replace(brackedTitle, '');
3437

35-
const titleElement = createTitleElement(title);
36-
preElement.appendChild(titleElement);
38+
const titleElement = createDivElement('codeTitle', title);
39+
snippetHeader.appendChild(titleElement);
3740
}
3841

3942
// Populate the code element
@@ -43,7 +46,7 @@ document.addEventListener('DOMContentLoaded', async () => {
4346
const copyButton = createCopyButton(codeElementId);
4447

4548
// Append the copy button
46-
preElement.appendChild(copyButton);
49+
snippetHeader.appendChild(copyButton);
4750

4851
// Highlight the element
4952
highlightJS.highlightBlock(codeElement);

_code-blocks/zendesk/embed-code.js

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

_code-blocks/zendesk/embed-code.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createCopyButton, createTitleElement, populateCodeElement } from '../helpers';
1+
import { createCopyButton, createDivElement, populateCodeElement } from '../helpers';
22
import initCopyClipboard from '@finsweet/webflow-addons/copy-clipboard';
33
import highlightJS from '../hljs';
44

@@ -20,6 +20,9 @@ document.addEventListener('DOMContentLoaded', async () => {
2020
const codeElement = document.createElement('code');
2121
const codeElementId = `hljs-code-${index}`;
2222
codeElement.id = codeElementId;
23+
const snippetHeader = createDivElement('snippetHeader');
24+
25+
preElement.appendChild(snippetHeader);
2326
preElement.appendChild(codeElement);
2427

2528
// Get the title
@@ -30,8 +33,8 @@ document.addEventListener('DOMContentLoaded', async () => {
3033
const [brackedTitle, title] = titleMatch;
3134
src = src.replace(brackedTitle, '');
3235

33-
const titleElement = createTitleElement(title);
34-
preElement.appendChild(titleElement);
36+
const titleElement = createDivElement(title);
37+
snippetHeader.appendChild(titleElement);
3538
}
3639

3740
// Populate the code element
@@ -41,7 +44,7 @@ document.addEventListener('DOMContentLoaded', async () => {
4144
const copyButton = createCopyButton(codeElementId);
4245

4346
// Append the copy button
44-
preElement.appendChild(copyButton);
47+
snippetHeader.appendChild(copyButton);
4548

4649
// Highlight the element
4750
highlightJS.highlightBlock(codeElement);

0 commit comments

Comments
 (0)