Skip to content

Instantly share code, notes, and snippets.

View jamiejohnsonkc's full-sized avatar

Jamie Johnson jamiejohnsonkc

View GitHub Profile
@jamiejohnsonkc
jamiejohnsonkc / instructions.md
Last active June 6, 2020 20:42
Check-peer-dependencies usage

From https://www.npmjs.com/package/check-peer-dependencies

Checks peer dependencies of the current NodeJS package. Offers solutions for any that are unmet.

This utility will recursively find all peerDependencies in your project's dependencies list. It checks if you have installed a package that meets the required peer dependency versions. If any peer dependencies are unmet, it will search for a compatible version to install.

Note: you must run npm install or yarn first in order to install all normal dependencies.

usage:

@jamiejohnsonkc
jamiejohnsonkc / props & template literals
Last active July 25, 2020 00:30
using termplate literal to pass variant as prop
<Text variant={`text.${props.textVariant}`}>
//
<component textVariant="caption"/>
@jamiejohnsonkc
jamiejohnsonkc / Functional Values Theme-Ui.jsx
Last active June 4, 2020 16:21
For shorthand properties or ones not automaically mapped to values in the theme, use an inline function to reference values from the theme object
/** @jsx jsx */
import { jsx } from 'theme-ui'
export default props => (
<div
{...props}
sx={{
boxShadow: theme => `0 0 4px ${theme.colors.primary}`,
}}
/>
)
@jamiejohnsonkc
jamiejohnsonkc / TestComp.jsx
Last active August 25, 2020 19:24
DynamicSplitCompExample
/** @jsx jsx */
import { jsx, Card, Text, Image, Button } from "theme-ui"
import { StaticQuery, graphql } from "gatsby"
import React from "react"
import PropTypes from "prop-types"
import TestCompItem from "../TestCompItem"
const TestComp = (children) => (
<StaticQuery
query={graphql`
@jamiejohnsonkc
jamiejohnsonkc / MonoCompTest.jsx
Last active June 3, 2020 16:34
DynamicCompExample
/** @jsx jsx */
import { jsx, Card, Text, Image, Button } from "theme-ui"
import { StaticQuery, graphql } from "gatsby"
import React from "react"
import PropTypes from "prop-types"
const MonoCompTest = (children) => (
<StaticQuery
query={graphql`
{
@jamiejohnsonkc
jamiejohnsonkc / CardImageWCaption.jsx
Last active June 1, 2020 22:18
SourcingQueriedContentJsonContent
/** @jsx jsx */
import { jsx, Card, Image, Text } from "theme-ui"
import { useStaticQuery, graphql } from "gatsby"
import React from "react"
import PropTypes from "prop-types"
const CardImageWCaption = () => {
const data = useStaticQuery(graphql`
{
imageWCaptionJson {
@jamiejohnsonkc
jamiejohnsonkc / GatsbyThemeUi Static Image
Last active June 1, 2020 16:51
Source static image using the Theme-Ui Image Component
/** @jsx jsx */
import { jsx, Card, Text, Image } from "theme-ui"
import React from "react"
import PropTypes from "prop-types"
import workshopImg from "../../../images/workshop.jpg"
const ThreeCards = (props) => (
<Card
{...props}
as="div"
import React from "react"
import Foo from "./New-My-JSON-Content.json"
const JsonComponent = () => (
<div style={{ maxWidth: `960px`, margin: `1.45rem` }}>
<h1>{Foo.title}</h1>
<ul>
{Foo.content.map((data, index) => {
return <li key={`content_item_${index}`}>{data.item}</li>
})}
@jamiejohnsonkc
jamiejohnsonkc / GastbyBlogPostTemplateWMappedContent
Created May 31, 2020 21:02
From part seven of gatsby tutorial
import React from "react"
import { graphql } from "gatsby"
import Layout from "../components/layout"
export default function BlogPost({ data }) {
const post = data.markdownRemark
return (
<Layout>
<div>
<h1>{post.frontmatter.title}</h1>
@jamiejohnsonkc
jamiejohnsonkc / Creating Pages and Slugs via Query
Created May 31, 2020 20:52
Use graphql to generate slugs, create pages and map content to templates via node.js. code corresponds with step seven of gatsby tutorial
const path = require(`path`)
const { createFilePath } = require(`gatsby-source-filesystem`)
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions
if (node.internal.type === `MarkdownRemark`) {
const slug = createFilePath({ node, getNode, basePath: `pages` })
createNodeField({
node,
name: `slug`,