Skip to content

Instantly share code, notes, and snippets.

View searleb's full-sized avatar

Bill Searle searleb

View GitHub Profile
@searleb
searleb / MultiLineEllipsis.js
Created June 29, 2018 06:11
MultiLineEllipsis React with CSSModules
import React from 'react';
import PropTypes from 'prop-types';
import styles from './styles.css';
function getStyles(fontSize, lineHeight, linesToShow) {
return {
fontSize,
lineHeight,
height: fontSize * lineHeight * linesToShow,
WebkitLineClamp: linesToShow,
@searleb
searleb / app.js
Created December 20, 2017 23:34
502 Bad Request Error when deploying node to AWS? Add this line that isn't documented anywhere!
const port = process.env.PORT || 3001 // your local port
app.listen(port, () => {
console.log(`Server running on port ${port}/`)
})
@searleb
searleb / ScrollToTop.js
Created December 15, 2017 03:26
Scroll to top on URL change
// Wrap routes <Switch>
import { Component } from 'react'
import { withRouter } from 'react-router-dom'
import PropTypes from 'prop-types'
class ScrollToTop extends Component {
static propTypes = {
location: PropTypes.object.isRequired,
children: PropTypes.element.isRequired,
}
@searleb
searleb / RippleOverlay.js
Created September 20, 2017 00:24
Ripple Overlay
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Color from 'color'
import styled, { keyframes } from 'styled-components'
const getCircleSize = () => {
let circleSize = window.outerWidth * 2.5
if (window.outerHeight > window.outerWidth) {
circleSize = window.outerHeight * 2.5
}
@searleb
searleb / ScrollPane.js
Created September 4, 2017 00:52
React ScrollPane
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
const Scroll = styled.div`
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
height: ${props => props.reduceHeight ? `calc(100% - ${props.reduceHeight})` : '100%'};
width: 100%;
&::-webkit-scrollbar {
@searleb
searleb / Accordion.js
Last active November 24, 2020 15:34
React accordion with rc-collapse and styled-components
import React from 'react'
import Collapse, { Panel } from 'rc-collapse'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import 'rc-collapse/assets/index.css'
const StyledCollapse = styled(Collapse)`
&.rc-collapse {
width: 100%;
border-radius: 0px;
@searleb
searleb / removeItem.js
Created August 11, 2017 00:55
Remove Item From Array
function removeItem(array, action) {
const actionIndex = array.indexOf(action)
const newArray = array.slice()
newArray.splice(actionIndex, 1)
return newArray
}
@searleb
searleb / IfDevelopment
Created August 10, 2017 02:35
IfDevelopment: React Component
import PropTypes from 'prop-types'
/**
* Takes a render prop which will render if we are in development environment
* @method IfDevelopment
* @param {Func} render callback function to render JSX
*/
const IfDevelopment = ({ render }) => (
process.env.NODE_ENV === 'development' ? render() : null
)
@searleb
searleb / check number only
Created June 29, 2017 05:11
Function that takes an input string and returns true if the string matches a number between 0 and 9.
/**
* Checks if the value is a number 0-9 or .
* @method isNumberOnly
* @param {String} value String to test
* @return {Boolean} Result of regex test
*/
export function isNumberOnly(value) {
const regexp = /\d|\./g
return regexp.test(value)
}
@searleb
searleb / installing-polymer-laravel.md
Last active April 15, 2017 22:43
Setting up Polymer with Laravel

Setting up Polymer with Laravel

This guide will help you get a starting point for implementing Polymer into a default install of Laravel v5.3.

Install Polymer

cd application/resources
bower init
bower install --save polymer

Include the components in the <head> of application/resources/views/layout.blade.php: