Skip to content

Instantly share code, notes, and snippets.

View tomas-wrobel's full-sized avatar

Tomáš Wróbel tomas-wrobel

View GitHub Profile
* {
box-sizing: border-box;
}
html {
font-family: sans-serif;
}
* {
box-sizing: border-box;
}
html {
font-family: sans-serif;
}
* {
box-sizing: border-box;
}
html {
font-family: sans-serif;
}
@tomas-wrobel
tomas-wrobel / events.ts
Last active May 21, 2023 10:44
Emitting events natively.
class Emitter<E extends Record<string, new (...args: any[]) => Event>> extends EventTarget {
constructor(public events: E) {
super();
}
on<T extends keyof E>(event: T, listener: (e: InstanceType<E[T]>) => void) {
this.addEventListener(event as string, listener as (e: Event) => void);
return this;
}
@tomas-wrobel
tomas-wrobel / _svg_gradient.scss
Last active April 16, 2022 20:14
(Firefox only) SVG gradients set up via SASS
@function svg-gradient($type, $transform, $colors...) {
$stops: "";
@each $color, $offset in $colors {
$stops: $stops + "<stop offset='#{$offset}' stop-color='#{$color}' />";
}
@return url(
"data:image/svg+xml;utf8,\
<svg xmlns='http://www.w3.org/2000/svg'> \
<#{$type}Gradient id='grad' style='gradient-transform: #{$transform};'> \
#{$stops} \
@tomas-wrobel
tomas-wrobel / useDarkScheme.js
Created August 24, 2021 08:56
useDarkScheme React hook – simple hook for detecting dark scheme in native settings
import {useState, useEffect, useRef} from "react"
export default function () {
const {current} = useRef(matchMedia("(prefers-color-scheme: dark)"));
const [match, setMatches] = useState(current.matches);
useEffect(() => {
const updateMatch = () => {
setMatch(current.matches);
};