Skip to content

Instantly share code, notes, and snippets.

View knowler's full-sized avatar

Nathan Knowler knowler

View GitHub Profile
@jakelazaroff
jakelazaroff / i-frame.js
Last active December 4, 2023 10:16
simple web component that sandboxes its slotted elements inside an iframe
customElements.define(
"i-frame",
class extends HTMLElement {
#shadow = this.attachShadow({ mode: "closed" });
constructor() {
super();
this.#shadow.innerHTML = `
<slot></slot>
<iframe part="frame" srcdoc=""></iframe>

This gist is a simple no-brainer description of the 3 ways (actually 2.5) the Web handle events.

<tag onclick />

The declarative inline HTML event listener is mostly an indirection of DOM Level 0 events, meaning this simply uses the equivalent of tag.onclick = listener behind the scene.

Example

click me
import { riff, route, html, indexRoute } from "../riff/riff.mjs";
import { serve } from "../riff/riff-express.mjs";
import {
deleteTask,
getProjects,
getTasks,
getUser,
sendEmail,
updateTask,
createTask,
@jacob-ebey
jacob-ebey / deferred-overview.md
Last active September 11, 2023 09:10
Deferred Overview

Remix Deferred

Remix Deferred is currently implemented on top of React's Suspense model but is not limited to React. This will be a quick dive into how "promise over the wire" is accomplished.

SSR + Hydration

It isn't rocket science, but a quick recap of how frameworks such as react do SSR:

  1. Load data
  2. Render the app
import invariant from "tiny-invariant";
class AmalgoBox extends HTMLElement {
get input() {
return this.querySelector("input") as HTMLInputElement;
}
get button() {
return this.querySelector("button") as HTMLButtonElement;
}
@kristoferjoseph
kristoferjoseph / my-message.mjs
Last active November 28, 2023 19:30
Single file MyMessage Custom Element pure function that enables adding tags dynamically in the browser with JavaScript
export default function MyMessage({ html, state }) {
const { attrs } = state
const { message='' } = attrs
return html`
<h1>${ message }</h1>
<script type="module">
class MyMessage extends HTMLElement {
constructor() {
super()
@EllyLoel
EllyLoel / reset.css
Last active April 13, 2024 18:14
CSS Reset
/*
Made by Elly Loel - https://ellyloel.com/
With inspiration from:
- Josh W Comeau - https://courses.joshwcomeau.com/css-for-js/treasure-trove/010-global-styles/
- Andy Bell - https://piccalil.li/blog/a-modern-css-reset/
- Adam Argyle - https://unpkg.com/open-props@1.3.16/normalize.min.css / https://codepen.io/argyleink/pen/KKvRORE
Notes:
- `:where()` is used to lower specificity for easy overriding.
*/
@kristoferjoseph
kristoferjoseph / single-file-web-component.html
Last active November 22, 2023 01:17
Single file Web Component
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Single File Web Component</title>
</head>
<body>
<template id=single-file>
<style>
h1 {
@mcansh
mcansh / heroicon-symbols.mjs
Last active November 14, 2023 16:35
convert heroicons to an svg <symbol> so you can do `<svg><use href="..."></svg>` with them and not have them all inlined everytime
import path from "node:path";
import fse from "fs-extra";
import svgstore from "svgstore";
import { glob } from "glob";
import prettier from "prettier";
let HEROICONS_PATH = path.join(process.cwd(), "node_modules/heroicons");
let ASSETS_PATH = path.join(process.cwd(), "assets");
let OUTFILE = path.join(process.cwd(), "app/components/sprite/index.svg");
@rajesh-s
rajesh-s / note-link-janitor-gh-action-workflow.yml
Last active January 2, 2023 06:22
Github Workflow to automatically run note-link-janitor on each push