This file contains hidden or 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
// curry :: ((a, b, ...) -> c) -> a -> b -> ... -> c | |
function curry(fn) { | |
const arity = fn.length; | |
return function $curry(...args) { | |
if (args.length < arity) { | |
return $curry.bind(null, ...args); | |
} | |
return fn.call(null, ...args); |
This file contains hidden or 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 ifProp = (prop, pass, fail) => props => props[prop] ? pass : fail; |
This file contains hidden or 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, { Component } from 'react'; | |
import { arrayOf, node, oneOfType } from 'prop-types'; | |
class Media extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
matches: window.matchMedia(this.props.query).matches, | |
}; |
This file contains hidden or 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 getScrollbarWidth = () => { | |
const scrollDiv = document.createElement('div'); | |
scrollDiv.style.cssText = ` | |
position: absolute; | |
top: -9999px; | |
width: 50px; | |
height: 50px; | |
overflow: scroll | |
`; |
This file contains hidden or 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 function putContent(el: HTMLElement, currentPosition: string, isOpen: boolean): string { | |
let height = el.offsetHeight | |
var rect = el.getBoundingClientRect() | |
var elemTop = (isOpen ? rect.top : rect.top - height) | |
var elemBottom = (isOpen ? rect.bottom : rect.bottom + height) | |
if (elemTop <= 0) { return 'below' } | |
if (elemBottom >= window.innerHeight) { return 'above' } | |
return (isOpen ? currentPosition : 'below') | |
} |
This file contains hidden or 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
// debounce :: Number -> (Args -> Any) -> (Args -> Undefined) | |
// Args = Any | |
export const debounce = time => (fn) => { | |
let timeout; | |
return (...args) => { | |
clearTimeout(timeout); | |
timeout = setTimeout(() => fn(...args), time); | |
}; | |
}; |
This file contains hidden or 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
// Escapes a string for use in a regular expression. | |
str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") |
This file contains hidden or 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
componentDidUpdate(prevProps, prevState) { | |
if (isBrowser()) { | |
const { open, bodyAlign } = this.state; | |
if (prevState.open !== open) { | |
const { right } = this.body.current.getBoundingClientRect(); | |
if (right > Root.innerWidth && bodyAlign === 'left') { | |
// Do not go beyond the right window border | |
this.setState({ bodyAlign: 'right' }); |
This file contains hidden or 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 withContext = propName => Component => props => ( | |
<Context.Consumer> | |
{value => ( | |
<Component | |
{...{[propName]: value}} | |
{...props} | |
/> | |
)} | |
</Context.Consumer> | |
); |
This file contains hidden or 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
withPropsOnChange( | |
['handlerName'], | |
({ handlerName }) => ({ | |
handlerName: throttle(100, handlerName), | |
}) | |
), | |