Skip to content

Instantly share code, notes, and snippets.

@benknight
benknight / README.md
Last active August 16, 2023 04:59
[use-carousel] Headless UI React hook for building a scroll-based carousel

[use-carousel] Headless UI React hook for building a scroll-based carousel

BYO-UI. No CSS necessary. Inspired by react-table.

Usage:

const {
  getLeftNavProps,
 getRightNavProps,
@benknight
benknight / BusinessRenderData.js
Last active August 11, 2019 08:08
Using a JavaScript class for derived render data
// lib/BusinessRenderData.js
import _get from 'lodash/get';
import React from 'react';
import { SocialFacebookSmall } from '@thumbtack/thumbprint-icons';
import vnmmLogo from '../assets/vnmm-logo.svg';
import messengerLogo from '../assets/messenger-logo.svg';
import { getLocalizedURL, getLocalizedVNMMURL } from '../lib/i18n';
import { getBadgesFromSurvey } from './badges';
class BusinessRenderData {
@benknight
benknight / example.jsx
Last active August 9, 2019 06:22
Using mock data to represent a best-case-scenario local data schema, then mapping API data to that
// src/mocks/Posts.js
export default [
{
id: 'p0',
title: 'Post 0',
body: 'Blah blah blah',
},
// etc.
];
@benknight
benknight / Rules.js
Last active August 14, 2017 02:09
CSS in JS ideas
import { cx } from 'css-in-js';
import { flex, flexAuto, noWrap } from '../styles/utilities';
import { Button, Button__green } from './styles';
const Button = props => {
const className = cx([
flex,
flexAuto,
Button,
props.isGreen && Button__green
@benknight
benknight / before-unload-bookmarklet.md
Last active November 28, 2018 04:41
Before Unload Bookmarklet

Before Unload Bookmarklet

Clicking this bookmarklet on a browser tab will cause the above alert to display when you try to close it. Handy if you have work you really don't want to lose.

// Route:
<Route name="agent-detail" path=":name" handler={AgentProfile}>
<Route name="agent-detail-tab" path=":tab" handler={AgentProfile} />
</Route>
// Handler function
handleTabToggle(key) {
this.replaceWith('agent-detail-tab', {name: this.state.slug, tab: key});
},
@benknight
benknight / gist:0a13088c4f152639ed97
Last active August 29, 2015 14:21
100vh workaround
var mediaQueryList = window.matchMedia('(orientation: portrait)');
function setMaxHeight (mediaQueryList) {
var vh = window.innerHeight;
var vw = window.innerWidth;
var header = document.querySelector('.site-header');
if (mediaQueryList.matches) {
header.style.height = Math.max(vh, vw);
} else {
@benknight
benknight / SassMeister-input.scss
Created April 1, 2015 21:39
Generated by SassMeister.com.
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
@function em($target, $context: $baseFontSize) {
@if $target == 0 {
@return 0;
}
@return $target / $context + 0em;
@benknight
benknight / gist:6ec1989d994e3e39ba1d
Last active August 29, 2015 14:16
Media query mixin
$on-wide: 'screen and (min-width: 1600px)';
$off-wide: 'screen and (max-width: 1599px)';
$on-desktop: 'screen and (min-width: 850px)';
$off-desktop: 'screen and (max-width: 849px)';
$on-medium: 'screen and (max-width: 600px)';
$off-medium: 'screen and (min-width: 600px)';
$on-mobile: 'screen and (max-width: 480px)';
$off-mobile: 'screen and (min-width: 481px)';
$on-portrait: 'screen and (max-width: 400px)';
$on-retina: '(-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi)';
@benknight
benknight / SassMeister-input.scss
Last active August 29, 2015 14:08
Google Play Music Dark UI Theme
// ----
// Sass (v3.4.6)
// Compass (v1.0.1)
// ----
// Make text more legible.
html {
-webkit-font-smoothing: antialiased;
}