This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useRef, useEffect } from 'react' | |
// found: https://stackoverflow.com/a/21015393 | |
function getTextWidth(text, font) { | |
// re-use canvas object for better performance | |
var canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement('canvas')) | |
var context = canvas.getContext('2d') | |
context.font = font | |
var metrics = context.measureText(text) | |
return metrics.width |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const styles = (arg) => { | |
if (typeof arg === 'string') return arg | |
if (arg instanceof Array) { | |
return arg | |
.reduce((acc, arg) => { | |
return [...acc, styles(arg)] | |
}, []) | |
.map((x) => x.trim()) | |
.filter((x) => x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const data = { | |
prop: 'red', | |
prop2: 'blue', | |
prop3: 'green', | |
prop4: 'black', | |
collection: [ | |
{ | |
id: 1, | |
txt: 'a' | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from 'react' | |
const getPath = function(event) { | |
const path = [] | |
let currentElem = event.target | |
while (currentElem) { | |
path.push(currentElem) | |
currentElem = currentElem.parentElement | |
} | |
if (path.indexOf(window) === -1 && path.indexOf(document) === -1) path.push(document) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<title>Document</title> | |
<style> | |
body { | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useRef, useCallback } from 'react' | |
const useWeakReducer = (reducer, initialState) => { | |
const ref = useRef(initialState) | |
const dispatch = useCallback((action) => { | |
ref.current = reducer(ref.current, action) | |
}, []) | |
return [ref.current, dispatch] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useRef, useCallback } from 'react' | |
const useWeakState = (initialVal) => { | |
const ref = useRef(initialVal) | |
const set = useCallback((val) => { | |
if (typeof val === 'function') ref.current = val(ref.current) | |
else ref.current = val | |
}, []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { render } from 'react-testing-library' | |
export default hookfn => { | |
const Comp = ({ children, args }) => children(hookfn(...args)) | |
const setup = (...args) => { | |
let output = {} | |
render( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>FACE</title> | |
<style> | |
video { display: none; } | |
#canvas2 { display: none; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Film & 40's player</title> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css"> | |
<style> | |
body { |