|
1 |
| -import FormRenderer from '@data-driven-forms/react-form-renderer/form-renderer'; |
2 |
| -import React from 'react'; |
| 1 | +import React, { useReducer } from 'react'; |
3 | 2 | import ReactDOM from 'react-dom';
|
4 | 3 |
|
5 |
| -const App = () => <span>"dnd"</span>; |
| 4 | +import reducer, { initialState } from '../src/reducer'; |
| 5 | +import Provider from '../src/provider'; |
| 6 | +import useContainer from '../src/use-container'; |
| 7 | +import useComponent from '../src/use-component'; |
| 8 | +import useHandle from '../src/use-handle'; |
| 9 | + |
| 10 | +const Component : React.FC<{id: string; container: string}> = ({ id, container }) => { |
| 11 | + const { ref } = useComponent({ id }); |
| 12 | + const handlers = useHandle({ component: id, sourceContainer: container}); |
| 13 | + |
| 14 | + return <div ref={ref} {...handlers} style={{ |
| 15 | + background: 'blue', |
| 16 | + minHeight: 100, |
| 17 | + minWidth: 308, |
| 18 | + margin: 4, |
| 19 | + color: 'white', |
| 20 | + textAlign: 'center', |
| 21 | + fontSize: 48 |
| 22 | + }}>{id}</div>; |
| 23 | +}; |
| 24 | + |
| 25 | +const Container = () => { |
| 26 | + const { ref, container, id } = useContainer({ isRoot: true }); |
| 27 | + |
| 28 | + return <div ref={ref} style={{ |
| 29 | + background: 'gray', |
| 30 | + minHeight: 400, |
| 31 | + minWidth: 400, |
| 32 | + padding: 4 |
| 33 | + }}> |
| 34 | + {container.children.map((key: string) => |
| 35 | + <Component key={key} id={key} container={id} /> |
| 36 | + )} |
| 37 | + </div>; |
| 38 | +}; |
| 39 | + |
| 40 | +const App = () => { |
| 41 | + const [state, dispatch] = useReducer(reducer, { |
| 42 | + ...initialState, |
| 43 | + components: { |
| 44 | + '#1': {}, |
| 45 | + '#2': {}, |
| 46 | + '#3': {} |
| 47 | + }, |
| 48 | + containers: { |
| 49 | + root: { |
| 50 | + children: ['#1', '#2', '#3'], |
| 51 | + ref: null |
| 52 | + } |
| 53 | + }, |
| 54 | + }); |
| 55 | + |
| 56 | + return <Provider state={state} dispatch={dispatch}> |
| 57 | + <Container /> |
| 58 | + </Provider>; |
| 59 | +}; |
6 | 60 |
|
7 | 61 | ReactDOM.render(
|
8 | 62 | <App />,
|
|
0 commit comments