Skip to content

Instantly share code, notes, and snippets.

View Temzasse's full-sized avatar

Teemu Taskula Temzasse

View GitHub Profile
@Temzasse
Temzasse / GalleryItem.js
Last active February 17, 2017 09:22
React - "Cannot read property 'getNativeNode' of null" bug
// In GalleryItemContainer.js
componentWillMount() {
// some stuff here...
this.props.fetchGalleryItem(slug);
}
...
// In my sagas
function* fetchGalleryItem({ payload }) {
@Temzasse
Temzasse / ToggleSwitch.js
Last active March 12, 2017 18:34
iOS styled toggle switch UI component
import React, { PropTypes, Component } from 'react';
import styled from 'styled-components';
// Styled components
const ToggleSwitchWrapper = styled.div`
display: flex;
flex-direction: column;
`;
const Toggle = styled.div`
@Temzasse
Temzasse / ToggleSwitchWithLabels.js
Last active March 13, 2017 12:27
iOS styled toggle switch UI component with labels
import React, { PropTypes, Component } from 'react';
import styled from 'styled-components';
// Styled components
const ToggleSwitchWrapper = styled.div`
display: flex;
flex-direction: column;
position: relative;
`;
import { combineReducers } from 'redux';
// Import subreducers
import editReducer from './edit/ducks';
import detailsReducer from './details/ducks';
import listReducer from './list/ducks';
const initialState = {
// common stuff here
};
/*
* EDIT DUCKS
*/
const initialState = {
// edit stuff here
};
export default function reducer(state = initialState, action = {}) {
switch (action.type) {
@Temzasse
Temzasse / withRippleHOC.js
Created April 27, 2017 13:33
A Higher-Order React component that provides the Material Design ripple effect.
import React, { Component } from 'react';
import styled from 'styled-components';
const RippleWrapper = styled.div`
position: relative;
overflow: hidden;
transform: translate3d(0, 0, 0);
&:after {
content: "";
@Temzasse
Temzasse / RippleExample.js
Last active April 27, 2017 13:47
Example for withRipple HOC
const RippleBlock = withRipple(styled.div`
width: 100px;
height: 100px;
background-color: ${props => props.bg || '#eee'};
`);
// or
const Block = styled.div`
width: 100px;
@Temzasse
Temzasse / toast.index.js
Last active May 28, 2017 20:20
A container for React.js Toaster component
import React, { Component, PropTypes } from 'react';
import styled from 'styled-components';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
import { addToast, removeToast, getToasts } from './ducks';
// Components
import Toast from './components/Toast';
@Temzasse
Temzasse / toast.ducks.js
Last active May 28, 2017 20:20
All necessary Redux reducers, actions, selectors etc for React.js Toaster component
import update from 'immutability-helper';
import { createAction } from 'redux-actions';
// Action types
export const TOAST_ADD_MESSAGE = 'TOAST_ADD_MESSAGE';
export const TOAST_REMOVE_MESSAGE = 'TOAST_REMOVE_MESSAGE';
export const initialState = {
messages: [],
@Temzasse
Temzasse / Toast.js
Created May 28, 2017 20:20
A React.js UI component for Redux Toaster component
import React from 'react';
import styled from 'styled-components';
// TODO: allow overriding these via props
const errorColor = '#e02d2d';
const errorColorDark = '#801313';
const warnColor = '#ffc715';
const warnColorDark = '#b78e0d';
const successColor = '#22ce33';
const successColorDark = '#14841f';