Skip to content

Instantly share code, notes, and snippets.

View iamdanthedev's full-sized avatar
😃

Dan The Dev iamdanthedev

😃
View GitHub Profile
@iamdanthedev
iamdanthedev / withTheme.tsx
Created December 27, 2017 16:47
react storybook styled-components theme provider decorator
import * as React from 'react';
import { StoryDecorator } from 'storybook__react';
import { ThemeProvider } from 'styled-components';
/**
* Storybook styled-components theme provider
*/
export function withTheme(theme): StoryDecorator {
@iamdanthedev
iamdanthedev / withModal.tsx
Created January 7, 2018 18:28
withModal hoc (semantic-ui-react modal)
import * as React from 'react';
import { Modal, ModalProps } from './semantic';
export function withModal<T extends {} = any>(
modalOptions: ModalProps | ((props: T) => ModalProps),
) {
return BaseComponent => props => {
const modalProps =
typeof modalOptions === 'function' ? modalOptions(props) : modalOptions;
@iamdanthedev
iamdanthedev / withFormBlock.ts
Created January 7, 2018 18:31
react hoc that blocks history transition
import { compose, lifecycle, withState } from 'recompose';
import { History, UnregisterCallback } from 'history';
type Props = {
pristine: boolean;
history: History;
};
type State = {
historyBlock: UnregisterCallback;
@iamdanthedev
iamdanthedev / withConfirn.tsx
Created January 26, 2018 00:03
withConfirm react hoc
import * as React from 'react';
import { compose, withStateHandlers } from 'recompose';
import Confirm from 'semantic-ui-react/dist/commonjs/addons/Confirm/Confirm';
/**
* with confirm hoc
* wraps an underlying component with a modal action confirmation
*/
export type ConfirmOptions = {
@iamdanthedev
iamdanthedev / 3cols.tsx
Created January 26, 2018 00:04
Three column + header layout react component
import * as React from 'react';
import styled from 'styled-components';
import { Col, Grid, Row } from 'react-styled-flexboxgrid';
import Form from 'semantic-ui-react/dist/commonjs/collections/Form/Form';
import { SubheaderCentered } from '../typography/Subheader';
/**
* |-------------------|
* | |
@iamdanthedev
iamdanthedev / 1) item-list-store
Last active January 30, 2018 09:47
redux work example
import { isType } from 'typescript-fsa';
import { Reducer } from 'redux';
import * as actions from './actions';
/**
* Item-List local store
*/
export interface LocalState {
@iamdanthedev
iamdanthedev / actions.ts
Created February 7, 2018 11:28
typescript-fsa redux approach
/**
* Recipe Editor Local Actions
*/
import actionCreatorFactory from 'typescript-fsa';
const actionCreator = actionCreatorFactory('@@local/RecipeEditor');
export const showAddGroupDialog = actionCreator('SHOW_ADD_GROUP_DIALOG');
@iamdanthedev
iamdanthedev / stories-index.js
Created February 19, 2018 13:04
storybook formik decorator
const initialValues = { comment: 'hello'; }
storiesOf('Form Controls: Select', module)
.addDecorator(withFormValues(initialValues)
.add('default', () => (
<Select name="select" label="Country..." options={selectOptions} />
</Formik>
))
@iamdanthedev
iamdanthedev / InlineSelect.tsx
Created March 14, 2018 09:26
Styling material-ui components with not hussle
import React from "react";
import { withStyles } from "material-ui";
import Select, { SelectProps } from "material-ui/Select";
import { MenuItem } from "material-ui/Menu";
type OwnProps = SelectProps & {
options: Array<{ label: string; value: string }>;
}
type Props = OwnProps & {
@iamdanthedev
iamdanthedev / SelectField.js
Created March 15, 2018 08:22
react-select on material-ui in a formik field
import React from "react";
import P from "prop-types";
import ReactSelect, {
Creatable as ReactSelectCreatable,
Async as ReactSelectAsync,
AsyncCreatable as ReactSelectAsyncCreatable
} from "react-select";
import get from "lodash/get";
import { Field } from "formik";
import { withStyles } from "material-ui";