Skip to content

Instantly share code, notes, and snippets.

View wiegertschouten's full-sized avatar

Wiegert Schouten wiegertschouten

View GitHub Profile
@wiegertschouten
wiegertschouten / example.js
Created May 22, 2024 19:30
A simple JavaScript class to trap focus within a given element.
import { FocusTrap } from './focus-trap.js';
// Select a menu and its toggle button
const menuToggle = document.getElementById('menu-toggle');
const menu = document.getElementById('menu');
// Create a new FocusTrap instance on the menu
const focusTrap = new FocusTrap(menu);
// Prepend the menu toggle button to the focusable elements
@wiegertschouten
wiegertschouten / grid-reloaded.scss
Last active February 21, 2023 14:09
A simple SASS utility to create layouts based on CSS Grid
// These are the mixins
@mixin grid-layout($column-count, $column-gap: 3rem, $row-gap: null) {
$row-gap: if($row-gap == null, $column-gap, $row-gap);
display: grid;
grid-template-columns: repeat($column-count, 1fr);
grid-gap: $row-gap $column-gap;
gap: $row-gap $column-gap;
}
@wiegertschouten
wiegertschouten / slide.js
Last active February 21, 2023 14:13
slideUp, slideDown, slideToggle
// In order for these functions to work, the target element needs a transition CSS property to be set.
function slideUp(element, callback) {
element.style.overflow = 'hidden';
element.style.height = element.clientHeight + 'px';
setTimeout(() => {
element.style.height = 0;
}, 0);
@wiegertschouten
wiegertschouten / find.js
Last active August 24, 2021 12:09
Simple DOM selection utility
document.findFirst = HTMLElement.prototype.findFirst = function(selector) {
return this.querySelector(selector);
}
document.findAll = HTMLElement.prototype.findAll = function(selector) {
return [...this.querySelectorAll(selector)];
}
window.findFirst = document.findFirst.bind(document);
window.findAll = document.findAll.bind(document);
@wiegertschouten
wiegertschouten / grid.scss
Created October 1, 2020 18:38
A very simple grid system built with SASS and CSS grid
$columns: 12;
$gap: 30px;
$breakpoints: (
xs: 480px,
sm: 768px,
md: 960px,
lg: 1170px,
xl: 1280px
);