Skip to content

Instantly share code, notes, and snippets.

View srph's full-sized avatar
🛠️
Building @Stride-Labs Frontend

Kier Borromeo srph

🛠️
Building @Stride-Labs Frontend
View GitHub Profile
@srph
srph / readme.md
Last active December 19, 2017 04:36
react stack manager

Stack Manager

We want a component that handles modal stack, which would allow us to:

  • Properly set z-index for modals
  • Close modals properly (e.g., on escape)
<StackManager self={this}>
  {(n, handler) => (
 
@srph
srph / readme.md
Last active December 19, 2017 04:03
react-confirmable idea // see https://github.com/srph/react-confirm
import {confirm, Confirm, ConfirmNode} from 'react-confirm';

// Root
<Confirm />

// Event handler
confirm('hi');

// In case you need to check if it's open or not
import React, {Component} from 'react';
export default class AssignedMembersWidget extends Component {
state = {
// List of users to select from
selection: [],
fetching: false
}
componentDidMount() {
import React, {Component} from 'react'
export default class AssignedMembersWidget extends Component {
state = {
selection: [],
fetching: false,
error: '',
loading: false
}
@srph
srph / Popover.js
Created July 22, 2017 00:56
React.js: Popover with boundary checking
import PropTypes from 'prop-types';
import React, { Component, cloneElement } from 'react';
import {findDOMNode} from 'react-dom';
import Transition from 'react-addons-css-transition-group';
import {Gateway} from 'react-gateway';
import Outside from 'react-click-outside';
import classnames from 'classnames';
import withinBoundaries from './withinBoundaries';
// @TODO: Animations. This became "undoable" when we added boundary checking
@srph
srph / ButtonLoader.js
Created July 8, 2017 16:29
React.js: Basic button loader
import React, {Component, PropTypes as T} from 'react';
import DotLoader from '@/components/DotLoader';
function ButtonLoader({loading, ...props}) {
return (
<button {...props} disabled={loading || disabled}>
{loading ? <DotLoader /> : props.children}
</button>
);
}
@srph
srph / index.js
Created June 16, 2017 08:26
React: react-gateway context workaround (https://github.com/cloudflare/react-gateway/issues/4)
class PassContext extends React.Component {
getChildContext() {
return {
dragDropManager: this.props.dragDropManager
};
}
render() {
return this.props.children;
}
@srph
srph / SearchInput.js
Last active June 13, 2017 06:22
React: Example SearchInput
import React, {Component, PropTypes as T} from 'react';
import history from 'app/history';
class SearchInput extends Component {
constructor(props, context) {
super(props);
this.state = {
input: context.location.query.search || ''
}
@srph
srph / Column.js
Last active June 10, 2017 05:54
React: DataTable API idea
import React, {Component, PropTypes as T} from 'react';
export default class Column extends Component {
render() {
return null;
}
}
Column.propTypes = {
heading: T.string,
@srph
srph / index.js
Created June 5, 2017 02:43
JS: Get placeholder index
/**
* Get placeholder index, like for example in a list, through node top offset.
* Used for drag-n-drops.
*
* @param {number} y The actual top offset
* @param {number} scroll Scroll count
* @return {number}
*/
function getPlaceholderIndex(y, scroll) {
const height = 70;