github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/util/decorators.tsx (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 import React from "react"; 12 import { RenderFunction } from "storybook__react"; 13 import { Provider } from "react-redux"; 14 import { combineReducers, createStore } from "redux"; 15 import { ConnectedRouter, connectRouter } from "connected-react-router"; 16 import { createMemoryHistory } from "history"; 17 18 const history = createMemoryHistory(); 19 const routerReducer = connectRouter(history); 20 21 const store = createStore( 22 combineReducers({ 23 router: routerReducer, 24 }), 25 ); 26 27 export const styledWrapper = (styles: React.CSSProperties) => ( 28 storyFn: RenderFunction, 29 ) => <div style={styles}>{storyFn()}</div>; 30 31 export const withRouterDecorator = (storyFn: RenderFunction) => ( 32 <Provider store={store}> 33 <ConnectedRouter history={history}>{storyFn()}</ConnectedRouter> 34 </Provider> 35 );