|
| 1 | +import { withGlobalBind } from 'feature-react/state'; |
| 2 | +import React, { useState } from 'react'; |
| 3 | +import { WidgetGrid } from './components'; |
| 4 | +import './index.css'; |
| 5 | +import { TWidgetGridPresetKey, widgetGridPresets } from './widget-grid'; |
| 6 | + |
| 7 | +const App: React.FC = () => { |
| 8 | + const [currentWidgetGridPresetKey, setWidgetGridPresetKey] = |
| 9 | + useState<TWidgetGridPresetKey>('playground'); |
| 10 | + |
| 11 | + const preset = React.useMemo( |
| 12 | + () => withGlobalBind('__widgetGrid', widgetGridPresets[currentWidgetGridPresetKey]), |
| 13 | + [currentWidgetGridPresetKey] |
| 14 | + ); |
| 15 | + |
| 16 | + return ( |
| 17 | + <div style={{ width: '100%', height: '100vh', backgroundColor: 'blue', padding: '48px' }}> |
| 18 | + <div style={{ marginBottom: '20px' }}> |
| 19 | + <select |
| 20 | + value={currentWidgetGridPresetKey} |
| 21 | + onChange={(e) => setWidgetGridPresetKey(e.target.value as TWidgetGridPresetKey)} |
| 22 | + style={{ marginRight: '10px' }} |
| 23 | + > |
| 24 | + <option value="playground">Playground</option> |
| 25 | + <option value="performance">Performance Test</option> |
| 26 | + </select> |
| 27 | + |
| 28 | + {preset.actions.map((action, index) => ( |
| 29 | + <button |
| 30 | + key={index} |
| 31 | + onClick={() => action.action(preset.grid as any)} |
| 32 | + style={{ marginRight: '10px' }} |
| 33 | + > |
| 34 | + {action.label} |
| 35 | + </button> |
| 36 | + ))} |
| 37 | + </div> |
| 38 | + |
| 39 | + <WidgetGrid |
| 40 | + widgetGrid={preset.grid as any} |
| 41 | + renderItem={(item) => { |
| 42 | + return ( |
| 43 | + <div |
| 44 | + style={{ |
| 45 | + backgroundColor: 'red', |
| 46 | + width: '100%', |
| 47 | + height: '100%', |
| 48 | + display: 'flex', |
| 49 | + justifyContent: 'center', |
| 50 | + alignItems: 'center', |
| 51 | + border: '1px solid black' |
| 52 | + }} |
| 53 | + > |
| 54 | + {item.id} |
| 55 | + </div> |
| 56 | + ); |
| 57 | + }} |
| 58 | + /> |
| 59 | + </div> |
| 60 | + ); |
| 61 | +}; |
| 62 | + |
| 63 | +export default App; |
0 commit comments