Skip to content

Instantly share code, notes, and snippets.

View kag359six's full-sized avatar

Kristopher Guzman kag359six

View GitHub Profile
@kag359six
kag359six / passingProps.js
Created June 7, 2019 11:58
example of passing props in styled components
import {calculateStuff, fontSizes} from 'who-knows';
// we can define breakpoints and use them
const breakpoints = {
sm: '(max-width: 420px)',
md: '(max-width: 1024px)',
lg: '(max-width: 1300px)'
}
export const BodyText = styled.p`
@kag359six
kag359six / extendStyles.js
Created June 7, 2019 12:01
Example of extending Styled Components
export const DefaultButton = styled.button`
width: 200px;
height: 60px;
font-size: 15px;
`;
export const FancyButton = styled(DefaultButton)`
background-color: gold;
`
@kag359six
kag359six / bodyText.js
Last active June 7, 2019 12:03
Example Body Text Component
export const BodyText = styled.span`
font-size: 15px;
color: red;
`
// we dynamically swap our span element for a link element by using "as" prop
return (
<BodyText as="a"> This is now a link! </BodyText>
)
@kag359six
kag359six / themeExample.js
Created June 7, 2019 12:04
leveraging themes in styled components
const theme = {
fontSizes: {
sm: '10px',
md: '15px',
lg: '25px'
}
}
const BodyText = styled.p`
font-size: ${props => props.theme.fontSizes.sm}
@kag359six
kag359six / childThemeExample.js
Created June 7, 2019 12:05
Example of child themes
import { UserPage, FacebookHeader, FacebookFooter } from 'facebook-ripoff-components';
import { myUsersTheme } from 'file-that-gets-users-theme';
const myUserTheme = (parentTheme) => ({
backgroundColor: 'ugly-green'
})
const facebookTheme = {
backgroundColor: 'facebook-blue'
}
@kag359six
kag359six / globalStylesEx.js
Created June 7, 2019 12:06
global styles example
import { createGlobalStyle } from 'styled-components/macro';
export default createGlobalStyle`
html {
font-size: 10px;
}
body {
margin: 0;
@kag359six
kag359six / globalStylesEx2.js
Created June 7, 2019 12:07
second part of global styles example
import RestOfOurApp from 'rest-of-our-app';
import GlobalStyles from './globalStyles'; // importing our global styles
export const App = () => {
return (
<ThemeProvider theme={theme}>
<GlobalStyles /> // we place it as a sibling of our root app component
<RestOfOurApp/>
<ThemeProvider/>
);
@kag359six
kag359six / referenceStyledComp.js
Created June 7, 2019 12:08
Referencing styled components in CSS
// this example was taken directly from the styled components docs
// I stripped out some styling since it's not really necessary to get the point
const Link = styled.a`
color: purple;
`;
const Icon = styled.svg`
width: 48px;
height: 48px;
@kag359six
kag359six / basicComponent.js
Last active June 23, 2019 18:30
Basic component to animate
import React, { useEffect } from "react";
import { setTargetPosition } from "./actions";
const animatedCompStyle = {
position: "fixed",
top: 0,
left: 0,
transform: "none",
width: "50px",
height: "50px",
@kag359six
kag359six / animAction.js
Created June 23, 2019 18:18
basic action for our animation
/*
I'm assuming you have a super simple store setup somewhere
(look at the codesandbox for details)
*/
import store from "./store";
export const setTargetPosition = ({ x, y }) => {
store.dispatch({
type: "ACTION_SET_TARGET_POSITION",
payload: {