Skip to content

Instantly share code, notes, and snippets.

View tomfordweb's full-sized avatar
🏠
Working from home

Tom Ford tomfordweb

🏠
Working from home
View GitHub Profile
@tomfordweb
tomfordweb / Modal.jsx
Last active November 14, 2018 19:00
React - Modal
import React from 'react';
import PropTypes from 'prop-types';
import styles from './modal.module.scss';
import { generateClassList } from './helpers'; // https://gist.github.com/tomfordweb/cb13de2f6d780f296141b6e4a406e6c7
const Modal = ({ handleClose, show, children, className, }) => {
const showHideClassName = show ? styles.displayBlock : styles.displayNone;
return (
<div className={generateClassList(styles.modal, showHideClassName, className)}>
<section className={styles.main}>
@tomfordweb
tomfordweb / Expire.jsx
Created October 31, 2018 18:50
React - Hide content after a timer
'use strict';
import React from 'react';
import update from 'immutability-helper';
export default class Expire extends React.Component {
constructor(props) {
super(props);
this.state = {
delay: props.delay || 1000,
@tomfordweb
tomfordweb / HideIfClickedOutside.js
Created October 31, 2018 18:49
Hide if clicked outside - React Component
import React from 'react';
import update from 'immutability-helper';
export default class HideIfClickedOutside extends React.Component {
constructor(props) {
super(props);
this.state = {
@tomfordweb
tomfordweb / chunk.js
Last active October 30, 2018 15:31
Chunk Array - ES6
/**
* Non-destructive chunk method for arrays
*/
export const chunk = (array, chunk) => {
var i, j, temparray = [];
for (i = 0, j = array.length; i < j; i += chunk) {
temparray.push(array.slice(i, i + chunk));
// do whatever
}
return temparray;
@tomfordweb
tomfordweb / wooc_email_redundancy.php
Created September 10, 2018 20:22
Woocommerce - BCC email for all order information
add_filter( 'woocommerce_email_headers', 'tfw_wooc_order_multiple_recipients', 10, 2);
function tfw_wooc_order_multiple_recipients( $headers = '', $id = '') {
$order_statuses = array(
'new_order',
'cancelled_order',
'customer_processing_order',
'customer_invoice',
'customer_refunded_order',
@tomfordweb
tomfordweb / HandleIfClickedOutside.jsx
Last active September 6, 2018 13:16
Will hide children if clicked outside of the component. Must pass a boolean to show/hide content. Useful for things like search results.
'use strict';
import React from 'react';
import update from 'immutability-helper';
export default class HideIfClickedOutside extends React.Component {
constructor(props) {
super(props);
@tomfordweb
tomfordweb / Expire.jsx
Last active August 30, 2018 17:16
React - Hide Component after X seconds
import React from 'react';
import update from 'immutability-helper';
export default class Expire extends React.Component {
constructor(props) {
super(props);
this.state = {
delay: props.delay || 1000,
visible: true
@tomfordweb
tomfordweb / columns.scss
Created June 18, 2018 16:13
SASS Columns
@mixin flex-content() {
display: flex;
justify-content: space-between;
align-content: space-between;
flex-flow: row wrap;
align-items: baseline;
& > * { // all 1st gen children of flex-content should be inline-block
display: inline-block
}
@tomfordweb
tomfordweb / index.js
Created April 24, 2018 12:03
jQuery image hover boilerplate
// handles hover for images
$('.home .callout').hover(function() {
// hover in
$(this).find('img').attr('src', function(index, attr) {
// foo1.png -> foo2.png
return attr.replace('1.png','2.png');
});
}, function() {
// hover out
$(this).find('img').attr('src', function(index, attr) {
@tomfordweb
tomfordweb / index.js
Created March 21, 2018 17:15
Add attributes to Element
/**
* Pass an object of attributes and their values and the element to modify
* @param {object} attributes Key-value pairs consisting of the attribute, and it's value
* @param {DOM Elem} element A queried or generated dom element
*/
function addAttributesToElement(attributes, element) {
for(var key in attributes) {
if (attributes.hasOwnProperty(key)) {
var attrKey = document.createAttribute(key);