Skip to content

Instantly share code, notes, and snippets.

View jonwaldstein's full-sized avatar

Jon Waldstein jonwaldstein

View GitHub Profile
@jonwaldstein
jonwaldstein / package.json
Created March 21, 2020 23:31
Eslint with prettier packages
{
"babel-eslint": "^9.0.0",
"eslint": "^6.1.0",
"eslint-config-airbnb": "^18.0.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-html": "^5.0.3",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.14.2",
@jonwaldstein
jonwaldstein / settings.json
Last active December 26, 2021 04:53
Vscode settings with eslint
{
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[php]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
},
"breadcrumbs.enabled": false,
"diffEditor.renderSideBySide": false,
"editor.autoIndent": "full",
@jonwaldstein
jonwaldstein / reducer.js
Created March 16, 2020 19:05
React context state reducer
const UPDATE_STATE = 'update_state';
export default function reducer(state, action) {
switch (action.type) {
case UPDATE_STATE:
return {
...state,
...action.newData,
};
@jonwaldstein
jonwaldstein / store.jsx
Last active April 13, 2020 18:25
React context store provider & hook
import React, {createContext, useContext, useReducer} from 'react';
import PropTypes from 'prop-types';
// Creates the initial React Context to be consumed by our custom provider and custom hook below
const StateContext = createContext(null);
const StateContextDispatch = createContext(null);
/**
* Creates a custom Provider Component where children can update state through a reducer
*
@jonwaldstein
jonwaldstein / settings.json
Last active March 16, 2020 16:06
VS Code Settings
{
"editor.fontFamily": "Fira Code, Menlo, Monaco, 'Courier New', monospace",
"editor.fontSize": 12,
"editor.lineHeight": 26,
"editor.quickSuggestionsDelay": 30,
"editor.letterSpacing": 0.5,
"html.format.enable": true,
"html.format.preserveNewLines": true,
"files.trimTrailingWhitespace": true,
"editor.cursorWidth": 5,
@jonwaldstein
jonwaldstein / mdx.json
Created October 4, 2019 15:43
VCODE SNIPPET - storybook mdx
{
"Scaffolds a Storybook Story in MDX": {
"prefix": "storymdx",
"body": [
"import {Meta, Story, Preview} from '@storybook/addon-docs/blocks';",
"import {action} from '@storybook/addon-actions';",
"",
"import ${TM_FILENAME_BASE/(.*)\\..+$/$1/} from './index';",
"",
"<Meta title=\"Components|${TM_FILENAME_BASE/(.*)\\..+$/$1/}\" component={${TM_FILENAME_BASE/(.*)\\..+$/$1/}} />",
@jonwaldstein
jonwaldstein / acf-field-name-generator.js
Last active November 28, 2018 20:45
ACF Field Name Generator
var fieldNames = document.querySelectorAll('.li-field-name');
var fieldNameList = [];
fieldNames.forEach(function(name){
fieldNameList.push("$"+name.textContent.replace(/\s+/g, '')+" "+"="+" "+"get_field("+"'"+name.textContent.replace(/\s+/g, '')+"'"+");");
});
console.log(fieldNameList.join('\r\n'));
@jonwaldstein
jonwaldstein / index.js
Created July 5, 2018 21:59
Gravity Forms add aria-describedby to fields on validation
jQuery(document).bind('gform_post_render', function(){
let InvalidFields = document.querySelectorAll('.gform_wrapper *[aria-invalid="true"]');
let InvalidFieldsArray = Array.from(InvalidFields, (field) => {
let validationMessages = field.parentElement.parentElement.querySelectorAll('.validation_message');
let fieldID = field.id;
let fieldIDArray = [];
var count = 0;
let ValidationMessagesArray = Array.from(validationMessages, (message) => {
if (validationMessages.length > 1){
@jonwaldstein
jonwaldstein / WPCLI-PluginInstallBoilerplate.txt
Last active March 2, 2017 19:39
WP-CLI Plugin Install Boilerplate
for p in "debug-bar" "debug-bar-console" "autodescription" "AJAX Thumbnail Rebuild" "Duplicate Post" "https://github.com/roots/soil/archive/master.zip" "carbon-fields"; do wp plugin install "$p" --activate; done
@jonwaldstein
jonwaldstein / cf_page_builder.php
Created December 9, 2016 22:37
Carbon Fields Page Builder Add-on
<?php
use Carbon_Fields\Container;
use Carbon_Fields\Field;
use Carbon_Fields\Field\Complex_Field;
Container::make( 'post_meta', 'Page Builder' )//PAGE BUILDER FIELDS
->show_on_post_type('page')
->add_fields( array(
Field::make( 'complex', 'crb_layouts' )
->set_layout('tabbed-vertical')