|
| 1 | +module OpaqueTypes = { |
| 2 | + type draggableProps; |
| 3 | + type dragHandleProps; |
| 4 | + type provided = { |
| 5 | + innerRef: ReactDOM.Ref.t, |
| 6 | + placeholder: React.element, |
| 7 | + draggableProps, |
| 8 | + dragHandleProps, |
| 9 | + }; |
| 10 | +}; |
| 11 | + |
1 | 12 | module Context = {
|
2 | 13 | type dragItem = {
|
3 | 14 | droppableId: string,
|
@@ -33,28 +44,75 @@ module Context = {
|
33 | 44 | "DragDropContext";
|
34 | 45 | };
|
35 | 46 |
|
| 47 | +module Provided = { |
| 48 | + let augmentChildren: (OpaqueTypes.provided, React.element) => React.element = [%bs.raw |
| 49 | + {| |
| 50 | + function (provided, children) { |
| 51 | + return { |
| 52 | + ...children, |
| 53 | + ref: provided.innerRef, |
| 54 | + props: { |
| 55 | + ...children.props, |
| 56 | + ...provided.draggableProps, |
| 57 | + ...provided.dragHandleProps, |
| 58 | + } |
| 59 | + }; |
| 60 | + } |
| 61 | + |} |
| 62 | + ]; |
| 63 | +}; |
| 64 | + |
36 | 65 | module Draggable = {
|
37 |
| - [@bs.module "./Dnd.js"] [@react.component] |
38 |
| - external make: |
39 |
| - ( |
40 |
| - ~isDragDisabled: bool=?, |
41 |
| - ~draggableId: string, |
42 |
| - ~index: int, |
43 |
| - ~children: React.element=? |
44 |
| - ) => |
45 |
| - React.element = |
46 |
| - "DraggableWrapper"; |
| 66 | + module Wrapper = { |
| 67 | + [@bs.module "react-beautiful-dnd"] [@react.component] |
| 68 | + external make: |
| 69 | + ( |
| 70 | + ~isDragDisabled: bool=?, |
| 71 | + ~draggableId: string, |
| 72 | + ~index: int, |
| 73 | + ~children: OpaqueTypes.provided => React.element=? |
| 74 | + ) => |
| 75 | + React.element = |
| 76 | + "Draggable"; |
| 77 | + }; |
| 78 | + |
| 79 | + [@react.component] |
| 80 | + let make = (~draggableId, ~index, ~isDragDisabled, ~children) => { |
| 81 | + <Wrapper draggableId index isDragDisabled> |
| 82 | + {(provided: OpaqueTypes.provided) => { |
| 83 | + <> |
| 84 | + {Provided.augmentChildren(provided, children)} |
| 85 | + {provided.placeholder} |
| 86 | + </>; |
| 87 | + }} |
| 88 | + </Wrapper>; |
| 89 | + }; |
47 | 90 | };
|
48 | 91 |
|
49 | 92 | module Droppable = {
|
50 | 93 | type direction = [ | `vertical | `horizontal];
|
51 |
| - [@bs.module "./Dnd.js"] [@react.component] |
52 |
| - external make: |
53 |
| - ( |
54 |
| - ~droppableId: string, |
55 |
| - ~direction: direction=?, |
56 |
| - ~children: React.element=? |
57 |
| - ) => |
58 |
| - React.element = |
59 |
| - "DroppableWrapper"; |
| 94 | + |
| 95 | + module Wrapper = { |
| 96 | + [@bs.module "react-beautiful-dnd"] [@react.component] |
| 97 | + external make: |
| 98 | + ( |
| 99 | + ~droppableId: string, |
| 100 | + ~direction: direction=?, |
| 101 | + ~children: OpaqueTypes.provided => React.element=? |
| 102 | + ) => |
| 103 | + React.element = |
| 104 | + "Droppable"; |
| 105 | + }; |
| 106 | + |
| 107 | + [@react.component] |
| 108 | + let make = (~droppableId, ~direction, ~children) => { |
| 109 | + <Wrapper droppableId direction> |
| 110 | + {(provided: OpaqueTypes.provided) => { |
| 111 | + <> |
| 112 | + {Provided.augmentChildren(provided, children)} |
| 113 | + {provided.placeholder} |
| 114 | + </>; |
| 115 | + }} |
| 116 | + </Wrapper>; |
| 117 | + }; |
60 | 118 | };
|
0 commit comments