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
const COLORS = { | |
info: ['#1E88E5', '#90CAF9'], | |
success: ['#388E3C', '#A5D6A7'], | |
error: ['#E53935', '#EF9A9A'], | |
warning: ['#F4511E', '#FFAB91'], | |
} | |
const print = Object.entries(COLORS).reduce( | |
(api, [name, colors]) => ({ | |
[name]: (shortLabel, longerMessage, optionalSuffix = '') => |
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 axios, { get, CancelToken } from 'axios' | |
import faker from 'faker' | |
// | |
// Only data property will be returned from the reuquest. This will simplify | |
// data processing, as it won't be neccesary to call .then() each time | |
// to return the request.data. | |
// See: https://github.com/axios/axios#response-schema | |
// | |
// The status codes validation, if needed, should be done in 'validateStatus' |
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
const hexToRGB = (hex, alpha) => { | |
const r = parseInt(hex.slice(1, 3), 16) | |
const g = parseInt(hex.slice(3, 5), 16) | |
const b = parseInt(hex.slice(5, 7), 16) | |
if (alpha) return `rgba(${r}, ${g}, ${b}, ${alpha})` | |
return `rgb(${r}, ${g}, ${b})` | |
} |
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
const f = (a, b) => [].concat(...a.map(d => b.map(e => [].concat(d, e)))) | |
const cartesian = (a, b, ...c) => (b ? cartesian(f(a, b), ...c) : a) | |
cartesian.apply(this, [["A", "B"], ["C", "D"]]) |
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
const stylesFilter = v => v.hasStyle('HIGHLIGHT') | |
editorState.getCurrentContent().getBlockForKey(anchorKey).findStyleRanges(stylesFilter, (start, end) => { | |
contentState = removeStyle(contentState, anchorKey, start, end, 'HIGHLIGHT') | |
}) |
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
const children = [].slice.call(this.snippetsList.node.children) | |
console.log( | |
data.node, | |
children.indexOf(data.node) | |
) |
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
const startKey = editorState.getSelection().getStartKey() | |
const startOffset = editorState.getSelection().getStartOffset() | |
const block = editorState.getCurrentContent().getBlockForKey(startKey) | |
const entityKey = block.getEntityAt(startOffset) |
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, { PropTypes } from 'react' | |
/** | |
* Moving click handler function outside of the component | |
* follows the separation of concerns principle (SoC). | |
*/ | |
const _handleClick = (onSelect, event, id) => { | |
// Additional steps before handling action. | |
event.preventDefault() | |
event.stopPropagation() |
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
onDrop = (acceptedFiles, rejectedFiles) => { | |
const file = acceptedFiles.find(f => f) | |
const i = new Image() | |
i.onload = () => { | |
let reader = new FileReader() | |
reader.readAsDataURL(file) | |
reader.onload = () => { | |
console.log({ | |
src: file.preview, |
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
// Required Draf-js version: 0.10. | |
// Live example: https://jsfiddle.net/schabluk/gh2gt22n/ | |
import React from 'react' | |
import ReactDOM from 'react-dom' | |
import {Editor, EditorState, EditorBlock} from 'draft-js' | |
class Line extends React.Component { | |
render () { | |
const blockMap = this.props.contentState.getBlockMap().toArray() |