Skip to content

Instantly share code, notes, and snippets.

Avatar

Ely De La Cruz elycruz

View GitHub Profile
@elycruz
elycruz / material-icon-font-as-web-component.js
Created February 2, 2023 07:11
Example showing how to wrap an icon font as a web component (example adapted for browser 'snippets'/console).
View material-icon-font-as-web-component.js
// Note: in real world example things would work slightly differntly:
// ----
const matSymStyleSheet = new CSSStyleSheet();
// Load css for custom 'x-icon' element - In realword scenario css can be loaded using import assertions, and/or,
// directly via app facilities (sass, webpack, etc.).
fetch('https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200')
.then(res => res.text())
.then(css => matSymStyleSheet.replace(`
${css.replace('.material-symbols-outlined', ':host .material-symbols-outlined')}
@elycruz
elycruz / dialog-in-right-hand-drawer-layout.js
Created January 30, 2023 13:58
dialog element in 'right-hand' drawer layout
View dialog-in-right-hand-drawer-layout.js
document.body.innerHTML = `
<style>
html, body {
margin: 0;
padding: 0;
font: normal 1rem Arial, Sans-serif;
}
dialog {
margin: 0;
padding: 0;
@elycruz
elycruz / dom-parser-xml-example.js
Created November 26, 2022 22:04
Basic usage of `DOMParser` (for XML)
View dom-parser-xml-example.js
const {log} = console,
groupContent = '.'.repeat(5).split('').reduce((agg, _, i) => {
return agg + `<item>` +
`<title>Item ${i}</title>` +
`</item>`;
}, ''),
docContent = `<group>${groupContent}</group>`,
@elycruz
elycruz / dialog-as-tooltip-and-dialog.js
Created August 11, 2022 18:10
Example showing the use of `dialog` elements in different contexts
View dialog-as-tooltip-and-dialog.js
document.body.innerHTML = `
<style>
.with-overlay {
display: inline-block;
border: 1px solid;
}
.with-overlay {
position: relative;
}
@elycruz
elycruz / flags_with_bitwise_ops.js
Last active September 16, 2022 19:08
Flags system using bitwise operators and binary numerals (in javascript).
View flags_with_bitwise_ops.js
/**
* Storing flags in one variable and checking for
* enabled/disabled states using
* bitwise operators.
* @author elycruz
* @reference:
* - https://www.youtube.com/watch?v=RRyxCmLX_ag
* - https://www.youtube.com/watch?v=6hnLMnid1M0
*/
@elycruz
elycruz / custom-input.js
Created July 18, 2022 22:54
Custom Input - Using Using Web Components Platform (and es2023)
View custom-input.js
const isset = x => x !== null && x !== undefined,
{log, error} = console,
xInputName = 'x-input',
xInputStyles = `
:host {
background-color: green;
}
@elycruz
elycruz / console_ani_keyframes_with_display_none.js
Created September 9, 2021 23:40
Animation keyframes with `display: none;`.
View console_ani_keyframes_with_display_none.js
/**
* Exploring animation keyframes with display `none` etc.
*/
document.body.innerHTML = `
<style>
@keyframes slide-in {
0% {
display: none;
@elycruz
elycruz / sticky-table-headers.js
Created August 26, 2021 13:11
Example of sticky table headers using 'position: sticky' for header columns.
View sticky-table-headers.js
document.body.innerHTML = `
<style>
table {
position: relative;
overflow: auto;
}
table, td, th {
border: 1px solid;
}
thead th {
@elycruz
elycruz / conditional-text-tooltips.js
Created August 11, 2021 21:49
Conditional text tooltips (devtools/snippets copy & paste ready)
View conditional-text-tooltips.js
document.body.innerHTML = `
<style>
html, body {
font-family: Arial, Verdana Helvetica, Sans-serif;
}
table {
width: 80vw;
}
@elycruz
elycruz / tree-map.js
Last active March 3, 2021 03:40
Simple tree-map algo (in *.js).
View tree-map.js
class TN {
constructor(assocList) {
if (assocList) {
assocList.forEach(([k, v]) => {
this.set(k, v);
});
}
}
set(k, v)) {