Skip to content

Instantly share code, notes, and snippets.

View Jimmydalecleveland's full-sized avatar

Jimmy Cleveland Jimmydalecleveland

View GitHub Profile
@Jimmydalecleveland
Jimmydalecleveland / index.js
Last active January 22, 2023 17:07
npx gist example
#!/usr/bin/env node
const result = "A gist on Github run with npx"
console.log(result)
@Jimmydalecleveland
Jimmydalecleveland / index.html
Created December 7, 2021 16:22
Minimal example of state and class instantiation/presentation from JS to HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Html JS class example</title>
</head>
<body>
<h1>HTML JS Class Example</h1>
@Jimmydalecleveland
Jimmydalecleveland / styledComponentExample.js
Created March 10, 2020 19:01
Example usage of styled components with theme providers
// First example: using a callback for every line to access theme
export const PretendContainer1 = styled.div`
background-color: ${({ theme }) => theme.colors.primary};
color: ${({ theme }) => theme.colors.secondary};
padding: ${({ theme }) => theme.spacing.medium};
margin-bottom: ${({ theme }) => theme.spacing.small};
`;
// Second example: using a single call back that returns `css` for
// a single reusable theme prop
@Jimmydalecleveland
Jimmydalecleveland / composeContext.js
Created September 15, 2019 14:28
composing context example that Scott T. found
function ProviderComposer({ contexts, children }) {
return contexts.reduceRight(
(kids, parent) =>
React.cloneElement(parent, {
children: kids,
}),
children
);
}
function styled(css, ...variables) {
// . . .
const computedCss = css
.map(
(chunk, index) =>
// now fires a callback at 'variables[index]'
`${chunk}${variables[index] ? variables[index](props) : ''}`
)
.join('')
return computedCss
function styled(css, ...variables) {
const theme = {
spacing: {
min: '2px',
max: '24px',
},
colors: {
primary: 'coral',
secondary: 'peachpuff',
},
const theme = {
spacing: {
min: '2px',
max: '24px',
},
colors: {
primary: 'coral',
secondary: 'peachpuff',
},
}
/**
* To use this function, pass in your damage as the first variable
* and your bonus (modifier) as the second variable.
*
* optional: Start the string with what happens to you for flavor.
* @example:
* doDamage`${18}${3}`
* doDamage`trip on a stone${7}${3}`
* */
function taggedTemplate(stringArray, variable) {
console.log(stringArray)
// [ 'The string will be split here: ', ' Then it resumes here.' ]
console.log(variable)
// I am the great divider!
return `${stringArray[0]}${variable}${stringArray[1]}`
}
@Jimmydalecleveland
Jimmydalecleveland / blog-styled-button-example.js
Created August 22, 2019 00:02
An intro example of styled components from their docs
// Intro example from Styled Components docs
const Button = styled.button`
background: ${props => props.primary ? "palevioletred" : "white"};
color: ${props => props.primary ? "white" : "palevioletred"};
font-size: 1em;
margin: 1em;
padding: 0.25em 1em;
border: 2px solid palevioletred;
border-radius: 3px;