try css stuff
This commit is contained in:
parent
fb2e06d965
commit
a420af36c3
2 changed files with 25 additions and 4 deletions
|
@ -1,20 +1,39 @@
|
||||||
|
// @ts-check
|
||||||
|
|
||||||
class CodeBlockComponent extends HTMLElement {
|
class CodeBlockComponent extends HTMLElement {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
let lang = this.classList.value;
|
|
||||||
lang = lang.replace("language-", "");
|
|
||||||
|
|
||||||
const trimmed = this.innerHTML.trim();
|
const trimmed = this.innerHTML.trim();
|
||||||
|
|
||||||
|
this.css({
|
||||||
|
color: "orange",
|
||||||
|
margin: "1em 0",
|
||||||
|
padding: "1em",
|
||||||
|
fontWeight: "bold",
|
||||||
|
fontSize: "x-large",
|
||||||
|
display: "block",
|
||||||
|
backgroundColor: "#eee",
|
||||||
|
});
|
||||||
|
|
||||||
const template = `
|
const template = `
|
||||||
<div>
|
<div>
|
||||||
<pre class="${this.classList}" id="pre"><code id="code">${trimmed}</code></pre>
|
<pre class="language-${this.lang}" id="pre"><code id="code">${trimmed}</code></pre>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
this.innerHTML = template;
|
this.innerHTML = template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply css to an element
|
||||||
|
* @param {Partial<CSSStyleDeclaration>} style
|
||||||
|
* @param {HTMLElement} element
|
||||||
|
*/
|
||||||
|
css(style, element = null) {
|
||||||
|
let el = element ?? this;
|
||||||
|
for (const property in style) el.style[property] = style[property];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
<p>some text: {{greeting}}</p>
|
<p>some text: {{greeting}}</p>
|
||||||
{{greeting}} hey<br />
|
{{greeting}} hey<br />
|
||||||
<clickable-text></clickable-text>
|
<clickable-text></clickable-text>
|
||||||
|
<code-block lang="css"> const hey = "AYO" </code-block>
|
||||||
</main>
|
</main>
|
||||||
<my-footer></my-footer>
|
<my-footer></my-footer>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const helloWorld = document.querySelector("my-hello-world");
|
const helloWorld = document.querySelector("my-hello-world");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
Loading…
Reference in a new issue