Skip to content

Instantly share code, notes, and snippets.

View paigen11's full-sized avatar

Paige Niedringhaus paigen11

View GitHub Profile
@paigen11
paigen11 / nested-template-strings.js
Last active September 15, 2019 00:55
Creating a configurable string via ES6 nested template strings
function isDesktopSize(){
window.innerWidth > 1400 ? true : false;
}
var navbar = {
isOpen: true
};
classes = `header ${ isDesktopSize() ? '' :
`icon-${navbar.isOpen ? 'collapse' : 'expand'}` }`;
@paigen11
paigen11 / tagged-template.js
Created September 15, 2019 17:22
Example using tagged templates
var guy = 'Paul';
var age = 96;
function myTag(strings, personExp, ageExp) {
var str0 = strings[0]; // "That "
var str1 = strings[1]; // " is a "
var ageStr;
if (ageExp > 99){
ageStr = 'centenarian';
@paigen11
paigen11 / raw-strings.js
Last active September 15, 2019 18:11
Example of the .raw argument in a string
function tag(strings) {
console.log(strings.raw[0]);
}
tag`I'd like this line 1 \n to ignore the newline and be in line with 1
\n even though I should be on line 3 at this point`;
/* prints: I'd like this line 1 \n to ignore the newline and be in line with 1
\n even though I should be on line 3 at this point */
@paigen11
paigen11 / raw-string-with-expression-interpolation.js
Last active September 15, 2019 18:31
Another raw string example, but with expression interpolation in the template literal too
var str = String.raw`What's up \n${4+7}?`;
console.log(str);
// prints: What's up \n11?
console.log(str.length);
// prints: 15
console.log(str.split('').join(','));
// prints: W,h,a,t,',s, ,u,p, ,\,n,1,1,?
@paigen11
paigen11 / string-template.js
Last active September 15, 2019 18:38
Template literal examples: single line, multi-line, and expression placeholders
// just a normal string in one line - not much different from a traditional string
const simpleString = `a template literal is surrounded by backticks`;
// a string spread across multiple lines
const multiLineString = `it can be spread across
multiple lines with just
one set of enclosing backticks`;
const name = "Paige";
@paigen11
paigen11 / App.js
Created February 1, 2020 23:11
React Socks breakpoint wrapper example
import React from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import { BreakpointProvider } from 'react-socks';
import NowPlaying from './containers/NowPlaying/NowPlaying';
import Dashboard from './containers/Dashboard/Dashboard';
import Upcoming from './containers/Upcoming/Upcoming';
import MovieSearch from './containers/MovieSearch/MovieSearch';
import Genres from './containers/Genres/Genres';
import Header from './containers/Header/Header';
import './App.css';
@paigen11
paigen11 / genres-with-breakpoints.js
Created February 1, 2020 23:13
Example of React Socks breakpoints being used inside a JSX component.
return (
<div className="genres-page">
<h1>Choose a Genre</h1>
{(error || loading) && <h3 className="genre-info">{info}</h3>}
<Breakpoint large up>
<div className="genre-list">
{this.renderRedirect()}
{genreInfo}
</div>
</Breakpoint>
@paigen11
paigen11 / genres-with-breakpoints.scss
Created February 1, 2020 23:15
The different CSS which gets rendered based on the React Socks component wrapped in breakpoints.
.genre-list {
display: grid;
grid-template-columns: repeat(4, 1fr);
max-width: 1200px;
grid-gap: 15px;
justify-items: center;
margin: auto;
h3 {
margin: 200px auto;
}
@paigen11
paigen11 / header-with-react-socks-breakpoints.js
Created February 1, 2020 23:19
React Socks breakpoints wrappers, which will render a header component or a totally different sidebar component based on the viewport size.
const Header = () => {
return (
<nav className="navbar-wrapper">
<Breakpoint medium up>
<ul className="navbar-links">
<li className="navbar-link-logo">
<NavLink to="/">
<img src={TmdbIcon} alt="logo" />
</NavLink>
</li>
@paigen11
paigen11 / sidebar-component-rendered-with-small-react-breakpoints.js
Created February 1, 2020 23:36
The sidebar navlinks rendered by React Socks when the viewport is mobile sized or smaller.
const Sidebar = () => {
const [expandedLinks, setExpandedLinks] = useState(false);
const toggleLinks = () => () => {
setExpandedLinks(!expandedLinks);
};
return (
<>
<ul className="sidebar-top">