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
renderImageSelect () { | |
var selectPrefix = this.props.selectPrefix; | |
var self = this; | |
var getOptions = function (input, callback) { | |
// build our url, accounting for selectPrefix | |
var uri = Keystone.adminPath + '/api/cloudinary/autocomplete'; | |
if (selectPrefix) { | |
uri = uri + '?prefix=' + selectPrefix; | |
} |
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, { Component } from 'react'; | |
export default function withPseudoState(WrappedComponent) { | |
return class ComponentWithPseudoState extends Component { | |
actionKeys = ['Enter', ' '] | |
state = { | |
isActive: false, | |
isFocus: false, | |
isHover: false, | |
} |
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, { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
const DefaultBaseComponent = props => <div {...props} />; | |
const withContextFromProps = ( | |
propTypes: PropTypes.object, | |
BaseComponent: PropTypes.func = DefaultBaseComponent | |
) => { | |
class ContextProps extends Component { |
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 raf from 'raf'; | |
/** | |
@param t: time (elapsed) | |
@param b: initial value | |
@param c: amount of change | |
@param d: duration | |
*/ | |
function easeOutCubic(t: number, b: number, c: number, d: number): number { | |
return c * ((t = t / d - 1) * t * t + 1) + b; |
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
function get(obj, ...props) { | |
const val = obj[props[0]]; | |
if (props.length === 1 || !val) return val; | |
const rest = props.slice(1); | |
return get.apply(null, [val, ...rest]); | |
} |
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
// @flow | |
import React, { PureComponent } from 'react'; | |
type ObjectType = { [key: string]: string }; | |
type Keys = Array<string>; | |
type Props = { | |
attributes: ObjectType, | |
styles: ObjectType, | |
target: HTMLElement, |
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
function requiredParam (param) { | |
const requiredParamError = new Error( | |
`Required parameter, "${param}" is missing.` | |
) | |
// preserve original stack trace | |
if (typeof Error.captureStackTrace === ‘function’) { | |
Error.captureStackTrace( | |
requiredParamError, | |
requiredParam | |
) |
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
function pipe(...fns) { | |
return param => fns.reduce( | |
(result, fn) => fn(result), | |
param | |
) | |
} | |
/* | |
The above function takes a list of functions and returns a function that can | |
apply the list from left to right, starting with a given parameter and then |
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
/** | |
* Clamp value between | |
* Creates a function that will restrict a given value between `min` and `max` | |
* @param {number} min | |
* @param {number} max | |
* @return {number} | |
*/ | |
const clamp = (min, max) => (v) => Math.min(Math.max(v, min), max); | |
/* |
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 "babel-polyfill"; | |
const asyncQuerySelector = async (node, query) => { | |
try { | |
return await (query ? node.querySelector(query) : node); | |
} catch (error) { | |
console.error(`Cannot find ${query ? `${query} in`: ''} ${node}.`, error); | |
return null; | |
} | |
}; |
OlderNewer