├── .prettierignore ├── tsconfig.prod.json ├── public ├── index.css ├── favicon.ico ├── favicon16x16.png ├── favicon24x24.png ├── favicon32x32.png ├── favicon64x64.png ├── favicon144x144.png ├── manifest.json └── index.html ├── src ├── react-app-env.d.ts ├── pages │ ├── index.ts │ ├── HomePage.tsx │ └── TodoPage.tsx ├── typings.d.ts ├── components │ ├── index.ts │ ├── HomeBox.tsx │ ├── TodoDialog.tsx │ ├── Snackbar.tsx │ ├── TodoTable.tsx │ └── Drawer.tsx ├── index.tsx ├── model │ ├── config.ts │ ├── index.ts │ ├── todo.ts │ └── snackbarEvent.ts ├── actions │ ├── config.ts │ ├── index.ts │ ├── snackbarEvent.ts │ └── todo.ts ├── reducers │ ├── config.ts │ ├── createReducer.ts │ ├── index.ts │ ├── snackbarEvent.ts │ └── todo.ts ├── Router.tsx ├── ReduxRoot.tsx ├── withRoot.tsx ├── configureStore.tsx └── App.tsx ├── .vscode ├── settings.json └── snippets │ └── typescriptreact.json ├── screenshot.png ├── react_factory.png ├── tsconfig.test.json ├── vscode_snippet0.png ├── vscode_snippet1.png ├── vscode_snippet2.png ├── .prettierrc.json ├── .yo-rc.json ├── tsconfig.json ├── .gitignore ├── LICENSE ├── package.json └── README.md /.prettierignore: -------------------------------------------------------------------------------- 1 | build/ 2 | dist/ 3 | lib/build/ 4 | lib/dist/ -------------------------------------------------------------------------------- /tsconfig.prod.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json" 3 | } -------------------------------------------------------------------------------- /public/index.css: -------------------------------------------------------------------------------- 1 | body > #root > div { 2 | height: 100vh; 3 | } 4 | -------------------------------------------------------------------------------- /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /src/pages/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./HomePage"; 2 | export * from "./TodoPage"; 3 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib" 3 | } -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/create-react-app-material-typescript-redux/HEAD/screenshot.png -------------------------------------------------------------------------------- /react_factory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/create-react-app-material-typescript-redux/HEAD/react_factory.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/create-react-app-material-typescript-redux/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "commonjs" 5 | } 6 | } -------------------------------------------------------------------------------- /vscode_snippet0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/create-react-app-material-typescript-redux/HEAD/vscode_snippet0.png -------------------------------------------------------------------------------- /vscode_snippet1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/create-react-app-material-typescript-redux/HEAD/vscode_snippet1.png -------------------------------------------------------------------------------- /vscode_snippet2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/create-react-app-material-typescript-redux/HEAD/vscode_snippet2.png -------------------------------------------------------------------------------- /public/favicon16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/create-react-app-material-typescript-redux/HEAD/public/favicon16x16.png -------------------------------------------------------------------------------- /public/favicon24x24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/create-react-app-material-typescript-redux/HEAD/public/favicon24x24.png -------------------------------------------------------------------------------- /public/favicon32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/create-react-app-material-typescript-redux/HEAD/public/favicon32x32.png -------------------------------------------------------------------------------- /public/favicon64x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/create-react-app-material-typescript-redux/HEAD/public/favicon64x64.png -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'jss-preset-default'; 2 | declare module 'react-jss/*'; 3 | /// 4 | -------------------------------------------------------------------------------- /public/favicon144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innFactory/create-react-app-material-typescript-redux/HEAD/public/favicon144x144.png -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "useTabs": true, 3 | "tabWidth": 4, 4 | "trailingComma": "es5", 5 | "printWidth": 120, 6 | "singleQuote": true 7 | } 8 | -------------------------------------------------------------------------------- /src/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from './HomeBox'; 2 | export * from './Snackbar'; 3 | export * from './TodoDialog'; 4 | export * from './TodoTable'; 5 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | 2 | import * as React from "react"; 3 | import * as ReactDOM from "react-dom"; 4 | import { ReduxRoot } from "./ReduxRoot"; 5 | 6 | 7 | 8 | 9 | const rootEl = document.getElementById("root"); 10 | ReactDOM.render(, rootEl); 11 | 12 | -------------------------------------------------------------------------------- /.yo-rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "generator-react-factory": { 3 | "promptValues": { 4 | "githubUser": "innFactory", 5 | "appName": "create-react-app-material-typescript-redux", 6 | "appVersion": "3.0.0", 7 | "otherFeatures": [ 8 | "Snackbar State and Component" 9 | ] 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/model/config.ts: -------------------------------------------------------------------------------- 1 | export enum ConfigActions { 2 | PURGE_STATE = 'PURGE_STATE', 3 | DRAWER_OPEN = 'DRAWER_OPEN', 4 | } 5 | 6 | interface ConfigActionType { 7 | type: T; 8 | payload: P; 9 | } 10 | 11 | export type ConfigAction = 12 | | ConfigActionType 13 | | ConfigActionType; 14 | -------------------------------------------------------------------------------- /src/model/index.ts: -------------------------------------------------------------------------------- 1 | import { SnackbarEventAction } from './snackbarEvent'; 2 | import { TodoAction } from './todo'; 3 | import { ConfigAction } from './config'; 4 | 5 | export * from './config'; 6 | export * from './todo'; 7 | 8 | export * from './snackbarEvent'; 9 | 10 | export type Action = 11 | | ConfigAction | TodoAction 12 | | SnackbarEventAction 13 | ; 14 | -------------------------------------------------------------------------------- /src/actions/config.ts: -------------------------------------------------------------------------------- 1 | import { ConfigAction, ConfigActions } from '../model'; 2 | 3 | export function purgeState(): ConfigAction { 4 | return { 5 | type: ConfigActions.PURGE_STATE, 6 | payload: undefined, 7 | }; 8 | } 9 | 10 | export function setDrawerOpen(open: boolean): ConfigAction { 11 | return { 12 | type: ConfigActions.DRAWER_OPEN, 13 | payload: open, 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /src/reducers/config.ts: -------------------------------------------------------------------------------- 1 | import { ConfigAction, ConfigActions } from '../model'; 2 | import createReducer from './createReducer'; 3 | 4 | export const drawerOpen = createReducer(false, { 5 | [ConfigActions.DRAWER_OPEN](state: boolean, action: ConfigAction) { 6 | return action.payload; 7 | }, 8 | 9 | [ConfigActions.PURGE_STATE](state: boolean, action: ConfigAction) { 10 | return false; 11 | }, 12 | }); 13 | -------------------------------------------------------------------------------- /src/Router.tsx: -------------------------------------------------------------------------------- 1 | import { Router } from 'react-typesafe-routes'; 2 | import { HomePage, TodoPage } from './pages'; 3 | 4 | // Read more about writing a middleware or add query parameter etc. 5 | // https://github.com/innFactory/react-typesafe-routes 6 | 7 | export const router = Router(route => ({ 8 | home: route('/', { 9 | component: HomePage, 10 | }), 11 | todo: route('todo', { 12 | component: TodoPage, 13 | }), 14 | })); 15 | -------------------------------------------------------------------------------- /src/actions/index.ts: -------------------------------------------------------------------------------- 1 | import { useMemo } from "react"; 2 | import { useDispatch } from "react-redux"; 3 | import { bindActionCreators } from "redux"; 4 | 5 | export function useActions(actions: any, deps?: any): any { 6 | const dispatch = useDispatch(); 7 | return useMemo( 8 | () => { 9 | if (Array.isArray(actions)) { 10 | return actions.map(a => bindActionCreators(a, dispatch)); 11 | } 12 | return bindActionCreators(actions, dispatch); 13 | }, 14 | deps ? [dispatch, ...deps] : deps 15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /src/actions/snackbarEvent.ts: -------------------------------------------------------------------------------- 1 | import { 2 | SnackbarEvent, 3 | SnackbarEventAction, 4 | SnackbarEventActions, 5 | } from "../model/snackbarEvent"; 6 | 7 | export function addSnackbarEvent(event: SnackbarEvent): SnackbarEventAction { 8 | return { 9 | type: SnackbarEventActions.ADD_SNACKBAR_EVENT, 10 | payload: event, 11 | }; 12 | } 13 | 14 | export function deleteSnackbarEvent(event: SnackbarEvent): SnackbarEventAction { 15 | return { 16 | type: SnackbarEventActions.DELETE_SNACKBAR_EVENT, 17 | payload: event, 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /src/reducers/createReducer.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by toni on 12.03.2017. 3 | */ 4 | import { Reducer } from "redux"; 5 | import { Action } from "../model/index"; 6 | 7 | export default function createReducer( 8 | initialState: S, 9 | handlers: any 10 | ): Reducer { 11 | const r = (state: S = initialState, action: Action): S => { 12 | if (handlers.hasOwnProperty(action.type)) { 13 | return handlers[action.type](state, action); 14 | } else { 15 | return state; 16 | } 17 | }; 18 | 19 | return r as Reducer; 20 | } 21 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "noEmit": true, 20 | "jsx": "preserve" 21 | }, 22 | "include": [ 23 | "src" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/ReduxRoot.tsx: -------------------------------------------------------------------------------- 1 | import { Typography } from "@material-ui/core"; 2 | import * as React from "react"; 3 | import { Provider } from "react-redux"; 4 | import { PersistGate } from "redux-persist/integration/react"; 5 | import App from "./App"; 6 | import configureStore from "./configureStore"; 7 | 8 | const { persistor, store } = configureStore(); 9 | 10 | export function ReduxRoot() { 11 | return ( 12 | 13 | Loading...} 15 | persistor={persistor} 16 | > 17 | 18 | 19 | 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /src/reducers/index.ts: -------------------------------------------------------------------------------- 1 | import { History } from "history"; 2 | import { combineReducers } from "redux"; 3 | import { Todo } from "../model/index"; 4 | import * as todoReducer from "./todo"; 5 | import * as configReducer from './config'; 6 | 7 | 8 | 9 | import * as snackbarReducer from './snackbarEvent'; 10 | import { SnackbarEvent } from "../model"; 11 | 12 | 13 | export interface RootState { 14 | drawerOpen: boolean; 15 | todoList: Todo[]; 16 | snackbarEvents: SnackbarEvent[]; 17 | } 18 | 19 | export default (history: History) => 20 | combineReducers({ 21 | ...configReducer, 22 | ...todoReducer, 23 | ...snackbarReducer, 24 | }); 25 | -------------------------------------------------------------------------------- /src/model/todo.ts: -------------------------------------------------------------------------------- 1 | export interface Todo { 2 | id: number; 3 | text: string; 4 | completed: boolean; 5 | } 6 | 7 | export enum TodoActions { 8 | ADD_TODO = "ADD_TODO", 9 | DELETE_TODO = "DELETE_TODO", 10 | COMPLETE_TODO = "COMPLETE_TODO", 11 | UNCOMPLETE_TODO = "UNCOMPLETE_TODO", 12 | } 13 | 14 | interface TodoActionType { 15 | type: T; 16 | payload: P; 17 | } 18 | 19 | export type TodoAction = 20 | | TodoActionType 21 | | TodoActionType 22 | | TodoActionType 23 | | TodoActionType 24 | ; 25 | -------------------------------------------------------------------------------- /src/model/snackbarEvent.ts: -------------------------------------------------------------------------------- 1 | export interface SnackbarEvent { 2 | message: string; 3 | severity: "error" | "success" | "info"; 4 | technicalInfo?: any; 5 | } 6 | 7 | export enum SnackbarEventActions { 8 | ADD_SNACKBAR_EVENT = "ADD_SNACKBAR_EVENT", 9 | DELETE_SNACKBAR_EVENT = "DELETE_SNACKBAR_EVENT", 10 | PURGE_SNACKBARS = "PURGE_SNACKBARS", 11 | } 12 | 13 | interface SnackbarEventActionType { 14 | type: T; 15 | payload: P; 16 | } 17 | 18 | export type SnackbarEventAction = 19 | | SnackbarEventActionType< 20 | typeof SnackbarEventActions.ADD_SNACKBAR_EVENT, 21 | SnackbarEvent 22 | > 23 | | SnackbarEventActionType< 24 | typeof SnackbarEventActions.DELETE_SNACKBAR_EVENT, 25 | SnackbarEvent 26 | >; 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | 23 | # test coverage 24 | /cypress/screenshots 25 | /coverage/src 26 | /coverage/home 27 | /coverage/Users 28 | /coverage/base.css 29 | /coverage/block-navigation.js 30 | /coverage/coverage-final.json 31 | /coverage/coverage-summary.json 32 | /coverage/index.html 33 | /coverage/prettify.css 34 | /coverage/prettify.js 35 | /coverage/sort-arrow-sprite.png 36 | /coverage/sorter.js 37 | /coverage/favicon.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon16x16.png", 7 | "sizes": "16x16", 8 | "type": "image/png" 9 | }, 10 | { 11 | "src": "favicon24x24.png", 12 | "sizes": "24x24", 13 | "type": "image/png" 14 | }, 15 | { 16 | "src": "favicon32x32.png", 17 | "sizes": "32x32", 18 | "type": "image/png" 19 | }, 20 | { 21 | "src": "favicon64x64.png", 22 | "sizes": "64x64", 23 | "type": "image/png" 24 | }, 25 | { 26 | "src": "favicon144x144.png", 27 | "sizes": "144x144", 28 | "type": "image/png" 29 | } 30 | ], 31 | "start_url": "./", 32 | "display": "standalone", 33 | "theme_color": "#000000", 34 | "background_color": "#ffffff" 35 | } 36 | -------------------------------------------------------------------------------- /src/reducers/snackbarEvent.ts: -------------------------------------------------------------------------------- 1 | import { ConfigActions } from '../model/config'; 2 | import { SnackbarEvent, SnackbarEventAction, SnackbarEventActions } from '../model/snackbarEvent'; 3 | import createReducer from './createReducer'; 4 | 5 | export const snackbarEvents = createReducer([], { 6 | [SnackbarEventActions.ADD_SNACKBAR_EVENT](state: SnackbarEvent[], action: SnackbarEventAction) { 7 | return [...state, action.payload]; 8 | }, 9 | [SnackbarEventActions.DELETE_SNACKBAR_EVENT](state: SnackbarEvent[], action: SnackbarEventAction) { 10 | return state.filter(e => e.message !== action.payload.message); 11 | }, 12 | [SnackbarEventActions.PURGE_SNACKBARS](state: SnackbarEvent[], action: SnackbarEventAction) { 13 | return []; 14 | }, 15 | [ConfigActions.PURGE_STATE](state: SnackbarEvent[], action: SnackbarEventAction) { 16 | return []; 17 | }, 18 | }); 19 | -------------------------------------------------------------------------------- /src/actions/todo.ts: -------------------------------------------------------------------------------- 1 | import { Todo, TodoAction, TodoActions } from '../model/index'; 2 | import { RootState } from '../reducers/index'; 3 | 4 | export function addTodo(todo: Todo): TodoAction { 5 | return { 6 | type: TodoActions.ADD_TODO, 7 | payload: todo, 8 | }; 9 | } 10 | 11 | // Async Function expample with redux-thunk 12 | export function completeTodo(todoId: number) { 13 | // here you could do API eg 14 | 15 | return (dispatch: Function, getState: () => RootState) => { 16 | dispatch({ type: TodoActions.COMPLETE_TODO, payload: todoId }); 17 | }; 18 | } 19 | 20 | export function uncompleteTodo(todoId: number): TodoAction { 21 | return { 22 | type: TodoActions.UNCOMPLETE_TODO, 23 | payload: todoId, 24 | }; 25 | } 26 | 27 | export function deleteTodo(todoId: number): TodoAction { 28 | return { 29 | type: TodoActions.DELETE_TODO, 30 | payload: todoId, 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /src/withRoot.tsx: -------------------------------------------------------------------------------- 1 | import { CssBaseline } from "@material-ui/core"; 2 | import { createMuiTheme } from "@material-ui/core/styles"; 3 | import { ThemeProvider } from "@material-ui/styles"; 4 | import * as React from "react"; 5 | 6 | // A theme with custom primary and secondary color. 7 | // It's optional. 8 | const theme = createMuiTheme({ 9 | palette: { 10 | primary: { 11 | light: "#e5e5e5", 12 | main: "#727272", 13 | dark: "#363839", 14 | contrastText: "#fff", 15 | }, 16 | secondary: { 17 | light: "#ff5e50", 18 | main: "#e41e26", 19 | dark: "#a90000", 20 | contrastText: "#fff", 21 | }, 22 | }, 23 | }); 24 | 25 | export function withRoot(Component: any) { 26 | function WithRoot(props: object) { 27 | // MuiThemeProvider makes the theme available down the React tree 28 | // thanks to React context. 29 | return ( 30 | 31 | {/* Reboot kickstart an elegant, consistent, and simple baseline to build upon. */} 32 | 33 | 34 | 35 | ); 36 | } 37 | 38 | return WithRoot; 39 | } 40 | -------------------------------------------------------------------------------- /src/reducers/todo.ts: -------------------------------------------------------------------------------- 1 | import { ConfigActions } from '../model/config'; 2 | import { Todo, TodoAction, TodoActions } from '../model/index'; 3 | import createReducer from './createReducer'; 4 | 5 | export const todoList = createReducer([], { 6 | [TodoActions.ADD_TODO](state: Todo[], action: TodoAction) { 7 | return [...state, action.payload]; 8 | }, 9 | [TodoActions.COMPLETE_TODO](state: Todo[], action: TodoAction) { 10 | // search after todo item with the given id and set completed to true 11 | return state.map(t => (t.id === action.payload ? { ...t, completed: true } : t)); 12 | }, 13 | [TodoActions.UNCOMPLETE_TODO](state: Todo[], action: TodoAction) { 14 | // search after todo item with the given id and set completed to false 15 | return state.map(t => (t.id === action.payload ? { ...t, completed: false } : t)); 16 | }, 17 | [TodoActions.DELETE_TODO](state: Todo[], action: TodoAction) { 18 | // remove all todos with the given id 19 | return state.filter(t => t.id !== action.payload); 20 | }, 21 | [ConfigActions.PURGE_STATE](state: Todo[], action: TodoAction) { 22 | return []; 23 | }, 24 | }); 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 innFactory 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/components/HomeBox.tsx: -------------------------------------------------------------------------------- 1 | import { makeStyles, Paper, Theme, Typography } from "@material-ui/core"; 2 | import * as React from "react"; 3 | 4 | interface Props { 5 | size: number; 6 | color: "red" | "blue" | string; 7 | } 8 | 9 | export function HomeBox(props: Props) { 10 | const { size, ...other } = props; 11 | const classes = useStyles(props); 12 | 13 | return ( 14 | 15 | 16 | I'm an example how to handle dynamic styles based on props 17 | 18 | 19 | ); 20 | } 21 | 22 | const styledBy = (property: string, props: any, mapping: any): string => 23 | mapping[props[property]]; 24 | const useStyles = makeStyles((theme: Theme) => ({ 25 | box: (props: Props) => ({ 26 | display: "flex", 27 | alignItems: "center", 28 | borderRadius: 8, 29 | background: styledBy("color", props, { 30 | red: "linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)", 31 | blue: "linear-gradient(45deg, #2196F3 30%, #21CBF3 90%)", 32 | }), 33 | height: props.size, 34 | width: props.size, 35 | }), 36 | 37 | text: { 38 | color: "white", 39 | }, 40 | })); 41 | -------------------------------------------------------------------------------- /src/configureStore.tsx: -------------------------------------------------------------------------------- 1 | import { createBrowserHistory } from "history"; 2 | import * as localforage from "localforage"; 3 | import { applyMiddleware, createStore } from "redux"; 4 | import { composeWithDevTools } from "redux-devtools-extension"; 5 | import { createLogger } from "redux-logger"; 6 | import { PersistConfig, persistReducer, persistStore } from "redux-persist"; 7 | import thunk from "redux-thunk"; 8 | import rootReducer from "./reducers/index"; 9 | 10 | const persistConfig: PersistConfig = { 11 | key: "root", 12 | version: 1, 13 | storage: localforage, 14 | blacklist: [], 15 | }; 16 | 17 | const logger = (createLogger as any)(); 18 | const history = createBrowserHistory(); 19 | 20 | const dev = process.env.NODE_ENV === "development"; 21 | 22 | let middleware = dev ? applyMiddleware(thunk, logger) : applyMiddleware(thunk); 23 | 24 | if (dev) { 25 | middleware = composeWithDevTools(middleware); 26 | } 27 | 28 | const persistedReducer = persistReducer(persistConfig, rootReducer(history)); 29 | 30 | export default () => { 31 | const store = createStore(persistedReducer, {}, middleware) as any; 32 | const persistor = persistStore(store); 33 | return { store, persistor }; 34 | }; 35 | 36 | export { history }; 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "create-react-app-material-typescript-redux", 3 | "version": "3.0.0", 4 | "dependencies": { 5 | "@material-ui/core": "4.11.1", 6 | "@material-ui/icons": "4.9.1", 7 | "@material-ui/styles": "4.11.1", 8 | "@material-ui/lab": "^4.0.0-alpha.56", 9 | "localforage": "1.7.3", 10 | "redux-devtools-extension": "2.13.8", 11 | "redux-logger": "3.0.6", 12 | "react": "17.0.1", 13 | "react-dom": "17.0.1", 14 | "react-redux": "7.2.2", 15 | "react-router-dom": "5.2.0", 16 | "react-scripts": "3.4.1", 17 | "redux-persist": "6.0.0", 18 | "react-typesafe-routes": "^0.0.6", 19 | "redux-thunk": "2.3.0", 20 | "typescript": "4.1.2" 21 | }, 22 | "scripts": { 23 | "start": "react-scripts start", 24 | "build": "react-scripts build", 25 | "eject": "react-scripts eject", 26 | "test": "react-scripts test" 27 | }, 28 | "browserslist": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all", 32 | "ie 11" 33 | ], 34 | "devDependencies": { 35 | "redux-devtools-extension": "2.13.8", 36 | "eslint": "6.8.0", 37 | "eslint-config-prettier": "^6.10.1", 38 | "eslint-plugin-prettier": "^3.1.2", 39 | "@types/node": "12.12.18", 40 | "@types/react": "17.0.0 ", 41 | "@types/react-dom": "17.0.0", 42 | "@types/react-router-dom": "5.1.6", 43 | "@types/redux-logger": "3.0.8", 44 | "@types/webpack-env": "1.16.0", 45 | "rimraf": "3.0.2", 46 | "@types/react-redux": "7.1.11", 47 | "@types/jest": "24.0.25" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/pages/HomePage.tsx: -------------------------------------------------------------------------------- 1 | import { Button, Typography } from "@material-ui/core"; 2 | import { makeStyles } from "@material-ui/styles"; 3 | import * as React from "react"; 4 | import { useSelector } from "react-redux"; 5 | import { HomeBox } from "../components"; 6 | import { RootState } from "../reducers/index"; 7 | 8 | export function HomePage() { 9 | const classes = useStyles(); 10 | const [boxColor, setBoxColor] = React.useState("red"); 11 | const todoList = useSelector((state: RootState) => state.todoList); 12 | 13 | const onButtonClick = () => 14 | setBoxColor(boxColor === "red" ? "blue" : "red"); 15 | 16 | return ( 17 |
18 | 19 | You have {todoList.length} TODOs in your list! 20 | 21 |
22 | 23 | 31 |
32 |
33 | ); 34 | } 35 | 36 | const useStyles = makeStyles({ 37 | root: { 38 | height: "100%", 39 | textAlign: "center", 40 | paddingTop: 20, 41 | paddingLeft: 15, 42 | paddingRight: 15, 43 | }, 44 | 45 | centerContainer: { 46 | flex: 1, 47 | height: "90%", 48 | display: "flex", 49 | alignItems: "center", 50 | justifyContent: "center", 51 | flexDirection: "column", 52 | }, 53 | 54 | button: { 55 | marginTop: 20, 56 | }, 57 | }); 58 | -------------------------------------------------------------------------------- /src/components/TodoDialog.tsx: -------------------------------------------------------------------------------- 1 | // prettier-ignore 2 | import { Button, Dialog, DialogActions, DialogTitle, TextField } from "@material-ui/core"; 3 | import { makeStyles } from "@material-ui/styles"; 4 | import * as React from "react"; 5 | import { useActions } from "../actions"; 6 | import * as TodoActions from "../actions/todo"; 7 | 8 | interface Props { 9 | open: boolean; 10 | onClose: () => void; 11 | } 12 | 13 | export function TodoDialog(props: Props) { 14 | const { open, onClose } = props; 15 | const classes = useStyles(); 16 | const [newTodoText, setNewTodoText] = React.useState(""); 17 | const todoActions = useActions(TodoActions); 18 | 19 | const handleClose = () => { 20 | todoActions.addTodo({ 21 | id: Math.random(), 22 | completed: false, 23 | text: newTodoText, 24 | }); 25 | onClose(); 26 | 27 | // reset todo text if user reopens the dialog 28 | setNewTodoText(""); 29 | }; 30 | 31 | const handleChange = (event: any) => { 32 | setNewTodoText(event.target.value); 33 | }; 34 | 35 | return ( 36 | 37 | Add a new TODO 38 | 45 | 46 | 49 | 50 | 51 | ); 52 | } 53 | 54 | const useStyles = makeStyles({ 55 | textField: { 56 | width: "80%", 57 | margin: 20, 58 | }, 59 | }); 60 | -------------------------------------------------------------------------------- /src/pages/TodoPage.tsx: -------------------------------------------------------------------------------- 1 | import { Button, Grid, Typography } from "@material-ui/core"; 2 | import { Theme } from "@material-ui/core/styles"; 3 | import { makeStyles } from "@material-ui/styles"; 4 | import * as React from "react"; 5 | import { TodoDialog, TodoTable } from "../components"; 6 | 7 | export function TodoPage() { 8 | const classes = useStyles(); 9 | const [open, setOpen] = React.useState(false); 10 | 11 | const handleClose = () => { 12 | setOpen(false); 13 | }; 14 | 15 | const handleAddTodo = () => { 16 | setOpen(true); 17 | }; 18 | 19 | return ( 20 | 21 | 22 | 23 | 24 | Todo List 25 | 26 | 27 | 28 |
29 | 37 |
38 |
39 | 40 | 41 | 42 |
43 | ); 44 | } 45 | 46 | const useStyles = makeStyles((theme: Theme) => ({ 47 | root: { 48 | padding: 20, 49 | [theme.breakpoints.down("md")]: { 50 | paddingTop: 50, 51 | paddingLeft: 15, 52 | paddingRight: 15, 53 | }, 54 | }, 55 | 56 | buttonContainer: { 57 | width: "100%", 58 | display: "flex", 59 | justifyContent: "flex-end", 60 | }, 61 | 62 | button: { 63 | marginBottom: 15, 64 | }, 65 | })); 66 | -------------------------------------------------------------------------------- /src/components/Snackbar.tsx: -------------------------------------------------------------------------------- 1 | // prettier-ignore 2 | import { makeStyles, Snackbar as MuiSnackbar } from '@material-ui/core'; 3 | import { Alert } from "@material-ui/lab"; 4 | import * as React from "react"; 5 | import { useSelector } from "react-redux"; 6 | import { useActions } from "../actions"; 7 | import * as SnackbarEventActions from "../actions/snackbarEvent"; 8 | import { SnackbarEvent } from "../model/snackbarEvent"; 9 | import { RootState } from "../reducers"; 10 | 11 | export function Snackbar() { 12 | const classes = useStyles(); 13 | const snackbarEvents: SnackbarEvent[] = useSelector( 14 | (state: RootState) => state.snackbarEvents 15 | ); 16 | const snackbarEventActions: typeof SnackbarEventActions = useActions( 17 | SnackbarEventActions 18 | ); 19 | const [currentEvent, setCurrentEvent] = React.useState( 20 | snackbarEvents.length > 0 ? snackbarEvents[0] : undefined 21 | ); 22 | 23 | React.useEffect(() => { 24 | setCurrentEvent( 25 | snackbarEvents.length > 0 ? snackbarEvents[0] : undefined 26 | ); 27 | }, [snackbarEvents]); 28 | 29 | const onClose = ( 30 | event: React.SyntheticEvent | React.MouseEvent, 31 | reason?: string 32 | ) => { 33 | if (reason === "clickaway") { 34 | return; 35 | } 36 | if (currentEvent) { 37 | snackbarEventActions.deleteSnackbarEvent(currentEvent); 38 | } 39 | }; 40 | 41 | if (currentEvent) { 42 | return ( 43 | 53 | 60 | {currentEvent.message} 61 | 62 | 63 | ); 64 | } else { 65 | return <>; 66 | } 67 | } 68 | 69 | const useStyles = makeStyles({ 70 | root: { 71 | zIndex: 99999999, 72 | }, 73 | }); 74 | -------------------------------------------------------------------------------- /src/components/TodoTable.tsx: -------------------------------------------------------------------------------- 1 | // prettier-ignore 2 | import { Checkbox, IconButton, Paper, Table, TableBody, TableCell, TableHead, TableRow } from "@material-ui/core"; 3 | import DeleteIcon from "@material-ui/icons/Delete"; 4 | import { makeStyles } from "@material-ui/styles"; 5 | import * as React from "react"; 6 | import { useSelector } from "react-redux"; 7 | import { useActions } from "../actions"; 8 | import * as TodoActions from "../actions/todo"; 9 | import { Todo } from "../model/index"; 10 | import { RootState } from "../reducers/index"; 11 | 12 | export function TodoTable() { 13 | const classes = useStyles(); 14 | const todoList = useSelector((state: RootState) => state.todoList); 15 | const todoActions = useActions(TodoActions); 16 | 17 | const onRowClick = (todo: Todo) => { 18 | if (todo.completed) { 19 | todoActions.uncompleteTodo(todo.id); 20 | } else { 21 | todoActions.completeTodo(todo.id); 22 | } 23 | }; 24 | 25 | return ( 26 | 27 | 28 | 29 | 30 | Completed 31 | Text 32 | Delete 33 | 34 | 35 | 36 | {todoList.map((n: Todo) => { 37 | return ( 38 | onRowClick(n)} 42 | > 43 | 44 | 45 | 46 | {n.text} 47 | 48 | 52 | todoActions.deleteTodo(n.id) 53 | } 54 | > 55 | 56 | 57 | 58 | 59 | ); 60 | })} 61 | 62 |
63 |
64 | ); 65 | } 66 | 67 | const useStyles = makeStyles({ 68 | paper: { 69 | width: "100%", 70 | minWidth: 260, 71 | display: "inline-block", 72 | }, 73 | table: { 74 | width: "100%", 75 | }, 76 | }); 77 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 35 | 36 | My page 37 | 38 | 39 | 40 | 43 |
44 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # create-react-app-material-typescript-redux derived from Create React App example with Material-UI, TypeScript, Redux and Routing 2 | 3 | Made with our new CLI Tool [react-factory](https://github.com/innFactory/react-factory) for choosing the optional features and configure our individual setup. 4 | 5 | example 6 | 7 | Inspired by: 8 | 9 | - [Material-UI](https://github.com/mui-org/material-ui) 10 | - [react-redux-typescript-boilerplate](https://github.com/rokoroku/react-redux-typescript-boilerplate) 11 | 12 | ## Contains 13 | 14 | - [x] [Material-UI](https://github.com/mui-org/material-ui) 15 | - [x] [Typescript](https://www.typescriptlang.org/) 16 | - [x] [React](https://facebook.github.io/react/) 17 | - [x] [Redux](https://github.com/reactjs/redux) 18 | - [x] [Redux-Thunk](https://github.com/gaearon/redux-thunk) 19 | - [x] [Redux-Persist](https://github.com/rt2zz/redux-persist) 20 | - [x] [React Router](https://github.com/ReactTraining/react-router) 21 | - [x] [Redux DevTools Extension](https://github.com/zalmoxisus/redux-devtools-extension) 22 | - [x] [TodoMVC example](http://todomvc.com) 23 | 24 | Optional: 25 | 26 | - [ ] Cypress-Tests-Environment 27 | - [ ] Firebase-Integration 28 | - [ ] Github Actions (cypress-test, build-and-deploy to firebase) 29 | - [ ] Snackbars 30 | - [ ] Subfolder Library 31 | - [ ] Service Worker 32 | - [ ] PolyFills (IE11) 33 | 34 | 35 | ## How to use 36 | 37 | We made a CLI Tool [react-factory](https://github.com/innFactory/react-factory) to include more options. 38 | 39 | example 40 | 41 | First install [Yeoman](http://yeoman.io) and the CLI Tool: 42 | ```bash 43 | npm install -g yo 44 | npm install -g generator-react-factory 45 | ``` 46 | 47 | Then generate your new project: 48 | 49 | ```bash 50 | yo react-factory 51 | ``` 52 | 53 | 54 | 55 | ## Enable Prettier [OPTIONAL] 56 | 57 | 1. Step: Install the Prettier plugin (e.g. the one of Esben Petersen) 58 | 2. Add the following snippet to your settings in VSCode: 59 | 60 | ```json 61 | "editor.formatOnSave": true, 62 | "editor.codeActionsOnSave": { 63 | "source.organizeImports": true // optional 64 | }, 65 | ``` 66 | 67 | ## Enable project snippets [OPTIONAL] 68 | 69 | Just install following extension: 70 | 71 | Project Snippet 72 | 73 | After that you can start to type `fcomp` (_for function component_) and you get a template for a new component. 74 | 75 | Project Snippet 76 | Project Snippet 77 | 78 | ## The idea behind the example 79 | 80 | This example demonstrate how you can use [Create React App](https://github.com/facebookincubator/create-react-app) with [TypeScript](https://github.com/Microsoft/TypeScript). 81 | 82 | ## Contributors 83 | 84 | - [Anton Spöck](https://github.com/spoeck) 85 | 86 | Powered by [innFactory](https://innfactory.de/) 87 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | // prettier-ignore 2 | import { AppBar, IconButton, Toolbar, Typography, useMediaQuery } from "@material-ui/core"; 3 | import { Theme } from "@material-ui/core/styles"; 4 | import MenuIcon from "@material-ui/icons/Menu"; 5 | import { makeStyles } from "@material-ui/styles"; 6 | import * as React from "react"; 7 | import { Router } from "react-router-dom"; 8 | import { RouterSwitch } from 'react-typesafe-routes'; 9 | import { Drawer } from "./components/Drawer"; 10 | import { history } from "./configureStore"; 11 | import { withRoot } from "./withRoot"; 12 | import { useSelector } from 'react-redux'; 13 | import { useActions } from './actions'; 14 | import * as ConfigActions from './actions/config'; 15 | import { RootState } from "./reducers"; 16 | import { router } from "./Router"; 17 | 18 | import { Snackbar } from './components/Snackbar'; 19 | 20 | function App() { 21 | const classes = useStyles(); 22 | const drawerOpen: boolean = useSelector((state: RootState) => state.drawerOpen); 23 | const configActions: typeof ConfigActions = useActions(ConfigActions); 24 | const isMobile = useMediaQuery((theme: Theme) => 25 | theme.breakpoints.down("sm") 26 | ); 27 | 28 | const handleDrawerToggle = () => { 29 | configActions.setDrawerOpen(!drawerOpen); 30 | }; 31 | 32 | 33 | return ( 34 | 35 |
36 |
37 | 38 | 39 | 40 | 46 | 47 | 48 | 53 | Create-React-App with Material-UI, Typescript, 54 | Redux and Routing 55 | 56 | 57 | 58 | 59 |
60 | 61 |
62 |
63 |
64 |
65 | ); 66 | } 67 | 68 | 69 | const useStyles = makeStyles((theme: Theme) => ({ 70 | root: { 71 | width: "100%", 72 | height: "100%", 73 | zIndex: 1, 74 | overflow: "hidden", 75 | }, 76 | appFrame: { 77 | position: "relative", 78 | display: "flex", 79 | width: "100%", 80 | height: "100%", 81 | }, 82 | appBar: { 83 | zIndex: theme.zIndex.drawer + 1, 84 | position: "absolute", 85 | }, 86 | navIconHide: { 87 | [theme.breakpoints.up("md")]: { 88 | display: "none", 89 | }, 90 | }, 91 | content: { 92 | backgroundColor: theme.palette.background.default, 93 | width: "100%", 94 | height: "calc(100% - 56px)", 95 | marginTop: 56, 96 | [theme.breakpoints.up("sm")]: { 97 | height: "calc(100% - 64px)", 98 | marginTop: 64, 99 | }, 100 | }, 101 | })); 102 | 103 | export default withRoot(App); 104 | -------------------------------------------------------------------------------- /src/components/Drawer.tsx: -------------------------------------------------------------------------------- 1 | // prettier-ignore 2 | import { Badge, Divider, Drawer as DrawerMui, Hidden, List, ListItem, ListItemIcon, ListItemText, makeStyles, Theme } from '@material-ui/core'; 3 | import FormatListNumberedIcon from '@material-ui/icons/FormatListNumbered'; 4 | import HomeIcon from '@material-ui/icons/Home'; 5 | import * as React from 'react'; 6 | import { Todo } from '../model/todo'; 7 | import { useSelector } from 'react-redux'; 8 | import { RootState } from '../reducers'; 9 | import { router } from '../Router'; 10 | import { useRoutesActive } from 'react-typesafe-routes'; 11 | import { useHistory } from 'react-router-dom'; 12 | import { useActions } from '../actions'; 13 | import * as ConfigActions from '../actions/config'; 14 | 15 | export function Drawer() { 16 | const classes = useStyles(); 17 | const drawerOpen: boolean = useSelector((state: RootState) => state.drawerOpen); 18 | const configActions: typeof ConfigActions = useActions(ConfigActions); 19 | 20 | const handleDrawerToggle = () => { 21 | configActions.setDrawerOpen(!drawerOpen); 22 | }; 23 | 24 | return ( 25 | <> 26 | 27 | 39 | 40 | 41 | 42 | 43 | 50 | 51 | 52 | 53 | 54 | ); 55 | } 56 | 57 | function Content() { 58 | const classes = useStyles(); 59 | const todoList = useSelector((state: RootState) => state.todoList); 60 | const history = useHistory(); 61 | 62 | const { home, todo } = useRoutesActive({ 63 | home: router.home, 64 | todo: router.todo, 65 | }); 66 | 67 | return ( 68 |
69 |
70 | 71 | 72 | history.push(router.home().$)} selected={home}> 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | history.push(router.todo().$)} selected={todo}> 82 | 83 | 84 | 85 | 86 | 87 | 88 |
89 | ); 90 | } 91 | 92 | function TodoIcon(props: { todoList: Todo[] }) { 93 | let uncompletedTodos = props.todoList.filter(t => t.completed === false); 94 | 95 | if (uncompletedTodos.length > 0) { 96 | return ( 97 | 98 | 99 | 100 | ); 101 | } else { 102 | return ; 103 | } 104 | } 105 | 106 | const drawerWidth = 240; 107 | const useStyles = makeStyles((theme: Theme) => ({ 108 | drawerHeader: { ...theme.mixins.toolbar }, 109 | drawerPaper: { 110 | width: 250, 111 | backgroundColor: theme.palette.background.default, 112 | [theme.breakpoints.up('md')]: { 113 | width: drawerWidth, 114 | position: 'relative', 115 | height: '100%', 116 | }, 117 | }, 118 | })); 119 | -------------------------------------------------------------------------------- /.vscode/snippets/typescriptreact.json: -------------------------------------------------------------------------------- 1 | { 2 | "Function Component": { 3 | "prefix": "fcomp", 4 | "body": [ 5 | "// prettier-ignore", 6 | "import { makeStyles } from '@material-ui/core';", 7 | "import * as React from 'react';", 8 | "", 9 | "interface Props {", 10 | "", 11 | "}", 12 | "", 13 | "export function $TM_FILENAME_BASE(props: Props) {", 14 | "", 15 | "const { } = props;", 16 | "const classes = useStyles();", 17 | "", 18 | "return (", 19 | "
", 20 | "
", 21 | "
", 22 | ");", 23 | "}", 24 | "", 25 | "const useStyles = makeStyles({", 26 | "", 27 | "root: {", 28 | "", 29 | "},", 30 | "});" 31 | ], 32 | "description": "component + makeStyle" 33 | }, 34 | "Function Component makeStyle + Props": { 35 | "prefix": "fcomp", 36 | "body": [ 37 | "// prettier-ignore", 38 | "import { makeStyles } from '@material-ui/core';", 39 | "import * as React from 'react';", 40 | "", 41 | "interface Props {", 42 | "", 43 | "}", 44 | "", 45 | "export function $TM_FILENAME_BASE(props: Props) {", 46 | "", 47 | "const { } = props;", 48 | "const classes = useStyles(props);", 49 | "", 50 | "return (", 51 | "
", 52 | "
", 53 | "
", 54 | ");", 55 | "}", 56 | "", 57 | "const useStyles = makeStyles({", 58 | "", 59 | "root: (props: Props) => ({", 60 | "", 61 | "}),", 62 | "});" 63 | ], 64 | "description": "component + makeStyle + Props" 65 | }, 66 | "Function Component makeStyle + Props + Theme": { 67 | "prefix": "fcomp", 68 | "body": [ 69 | "// prettier-ignore", 70 | "import { makeStyles, Theme } from '@material-ui/core';", 71 | "import * as React from 'react';", 72 | "", 73 | "interface Props {", 74 | "", 75 | "}", 76 | "", 77 | "export function $TM_FILENAME_BASE(props: Props) {", 78 | "", 79 | "const { } = props;", 80 | "const classes = useStyles(props);", 81 | "", 82 | "return (", 83 | "
", 84 | "
", 85 | "
", 86 | ");", 87 | "}", 88 | "", 89 | "const useStyles = makeStyles((theme: Theme) => ({", 90 | "", 91 | "root: (props: Props) => ({", 92 | "", 93 | "}),", 94 | "}));" 95 | ], 96 | "description": "component + makeStyle + Props + Theme" 97 | }, 98 | "Function Component makeStyle + Theme": { 99 | "prefix": "fcomp", 100 | "body": [ 101 | "// prettier-ignore", 102 | "import { makeStyles, Theme } from '@material-ui/core';", 103 | "import * as React from 'react';", 104 | "", 105 | "interface Props {", 106 | "", 107 | "}", 108 | "", 109 | "export function $TM_FILENAME_BASE(props: Props) {", 110 | "", 111 | "const { } = props;", 112 | "const classes = useStyles();", 113 | "", 114 | "return (", 115 | "
", 116 | "
", 117 | "
", 118 | ");", 119 | "}", 120 | "", 121 | "const useStyles = makeStyles((theme: Theme) => ({", 122 | "", 123 | "root: {", 124 | "", 125 | "},", 126 | "}));" 127 | ], 128 | "description": "component + makeStyle + Theme" 129 | }, 130 | "useState": { 131 | "prefix": "useState", 132 | "body": ["const [${1:value}, set${1/(.*)/${1:/capitalize}/}] = React.useState(${2:value});$0"] 133 | }, 134 | 135 | "lodash": { 136 | "prefix": "lodash", 137 | "body": ["import * as _ from 'lodash';"] 138 | }, 139 | 140 | "useAction": { 141 | "prefix": "useAction", 142 | "body": [ 143 | "// import * as ${1/(.*)/${1:/capitalize}/}Actions from '../actions/${1:actionname}';", 144 | "const ${1:actionname}Actions: typeof ${1/(.*)/${1:/capitalize}/}Actions = useActions(${1/(.*)/${1:/capitalize}/}Actions);" 145 | ] 146 | }, 147 | 148 | "useEffect": { 149 | "prefix": "useEffect", 150 | "body": ["React.useEffect(() => {", "$0", "}, []);"] 151 | }, 152 | 153 | "useSelector": { 154 | "prefix": "useSelector", 155 | "body": "const ${1:varialbe}: ${2:type} = useSelector((state: RootState) => state.${1:varialbe});" 156 | }, 157 | 158 | "useHistory": { 159 | "prefix": "useHistory", 160 | "body": "const history = useHistory();" 161 | }, 162 | 163 | "useMediaQuery - Breakpoint": { 164 | "prefix": "useMedia", 165 | "body": "const isMobile = useMediaQuery((theme: Theme) => theme.breakpoints.down('sm'));" 166 | }, 167 | 168 | "useMediaQuery - ScreenWidth": { 169 | "prefix": "useMedia", 170 | "body": "const showIcon = useMediaQuery('(max-width:400px)');" 171 | }, 172 | 173 | "useResponsive - isMobile": { 174 | "prefix": "isMobile", 175 | "body": "const { isMobile } = useResponsive();" 176 | }, 177 | 178 | "handleTextField": { 179 | "prefix": "handleTextField", 180 | "body": [ 181 | "const handle${1:value} = (e: React.ChangeEvent) => {", 182 | "const value = e.target.value;", 183 | "", 184 | "};" 185 | ] 186 | }, 187 | 188 | "handleSelect": { 189 | "prefix": "handleSelect", 190 | "body": [ 191 | "const handle${1:value} = (e: React.ChangeEvent<{ value: any }>) => {", 192 | "const value = e.target.value as string;", 193 | "", 194 | "};" 195 | ] 196 | }, 197 | 198 | "story": { 199 | "prefix": "story", 200 | "body": [ 201 | "import { Meta } from '@storybook/react';", 202 | "import * as React from 'react';", 203 | "import { withTheme } from './index.stories';", 204 | "import { ${TM_FILENAME_BASE/(.stories)//}Props} from '../src/components/${TM_FILENAME_BASE/(.stories)//}'", 205 | "import { ${TM_FILENAME_BASE/(.stories)//} } from '../src';", 206 | "", 207 | "export default {", 208 | "title: '${TM_FILENAME_BASE/(.stories)//}',", 209 | "component: ${TM_FILENAME_BASE/(.stories)//},", 210 | "// argTypes: { onClick: { action: 'clicked' } },", 211 | "} as Meta;", 212 | "", 213 | "const Template = (args: ${TM_FILENAME_BASE/(.stories)//}Props) =>", 214 | "withTheme(", 215 | "<${TM_FILENAME_BASE/(.stories)//} {...args} />", 216 | ");", 217 | "", 218 | "export const Default = Template.bind({});", 219 | "", 220 | "Default.args = {", 221 | "", 222 | "// add your props here", 223 | "", 224 | "} as ${TM_FILENAME_BASE/(.stories)//}Props;", 225 | "" 226 | ], 227 | "description": "storybook" 228 | } 229 | } 230 | --------------------------------------------------------------------------------