Skip to content
This repository was archived by the owner on Mar 17, 2023. It is now read-only.

Commit 6d355bc

Browse files
author
Roland Peelen
authored
Merge pull request #82
Remove dnd.js in favour of plain ReasonML Bindings
2 parents 92294eb + 2595e36 commit 6d355bc

File tree

3 files changed

+78
-80
lines changed

3 files changed

+78
-80
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build:storybook": "build-storybook",
88
"build": "yarn build:reason && yarn build:storybook",
99
"clean": "bsb -clean-world",
10-
"start": "bsb -make-world -w -ws _ ",
10+
"start": "bsb -make-world -w",
1111
"server": "start-storybook -p 6006",
1212
"deploy-storybook": "yarn build:reason && storybook-to-ghpages",
1313
"test": "yarn clean && yarn build:reason && jest",

src/Dnd.js

-60
This file was deleted.

src/Dnd.re

+77-19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
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+
112
module Context = {
213
type dragItem = {
314
droppableId: string,
@@ -33,28 +44,75 @@ module Context = {
3344
"DragDropContext";
3445
};
3546

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+
3665
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+
};
4790
};
4891

4992
module Droppable = {
5093
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+
};
60118
};

0 commit comments

Comments
 (0)