Skip to content

Instantly share code, notes, and snippets.

View Temzasse's full-sized avatar

Teemu Taskula Temzasse

View GitHub Profile
@Temzasse
Temzasse / useParsedSearchParams.tsx
Last active April 6, 2024 10:12
A utility hook to parse and type URL search params based on a configuration object. This hook is useful when you want to access URL search params in a typesafe way and with proper casting.
import { useMemo } from "react";
import { useSearchParams } from "react-router-dom";
type ParseConfig = Record<
string,
| { type: "string"; defaultValue?: string }
| { type: "number"; defaultValue?: number }
| { parse: (value: URLSearchParams) => unknown }
>;
@Temzasse
Temzasse / Tabs_example.js
Created November 1, 2017 21:46
An example React.js component for using Tabs component.
import React from 'react';
import Tabs from './Tabs';
const TabsExample = () => (
<Tabs>
<Tabs.Panel label='Tab label 1'>
<h4>Tab content 1</h4>
<p>
Disrupt minimum viable product pivot waterfall is so 2000 and
late viral long shadow cortado SpaceTeam unicorn venture
@Temzasse
Temzasse / Tabs.js
Created November 1, 2017 09:21
A React.js + styled-components Tabs component
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import withRipple from './withRipple';
const TabContent = styled.div`
flex: 1;
width: 100%;
`;
@Temzasse
Temzasse / TwerkForm.js
Created August 17, 2017 21:36
Form component with a shake validation gesture.
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import styled, { keyframes } from 'styled-components';
import { darken } from 'polished';
import TextField from './TextField';
const propTypes = {
onAuthSuccess: PropTypes.func.isRequired,
};
@Temzasse
Temzasse / TextField.js
Created August 17, 2017 18:47
TextField with floating label (with styles)
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import styled, { css } from 'styled-components';
import { darken } from 'polished';
const propTypes = {
label: PropTypes.string,
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
};
@Temzasse
Temzasse / TextField_no_styles.js
Created August 17, 2017 18:41
TextField with floating label (no styles)
const propTypes = {
label: PropTypes.string,
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
};
class TextField extends Component {
state = {
isFocused: false,
}
@Temzasse
Temzasse / Toast.css
Last active June 6, 2017 15:28
CSS animations given to CSSTransitionGroup used inside React.js Toaster component
.toastAnimEnter, .toastAnimAppear {
opacity: 0.01;
transition: opacity .5s cubic-bezier(.03, .83, .76, .98);
}
.toastAnimEnter.toastAnimEnterActive, .toastAnimAppear.toastAnimAppearActive {
opacity: 1;
}
.toastAnimLeave {
@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';
@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.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';