You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: packages/docs/versioned_docs/version-0.1.0-beta.7/api/Editor.md
+27-26
Original file line number
Diff line number
Diff line change
@@ -17,37 +17,12 @@ Creates the context that stores the editor state.
17
17
["enabled?", "boolean", "Optional. If set to false, all editing capabilities will be disabled"],
18
18
["indicator?", 'Record<"success" | "error", String>', "Optional. The colour to use for the drop indicator. The colour set in 'success' will be used when the indicator shows a droppable location; otherwise the colour set in 'error' will be used."],
19
19
["onRender?", "React.ComponentType<{element: React.ReactElement}>", "Optional. Specify a custom component to render every User Element in the editor."],
20
-
["onNodesChange?", "() => void", "Optional. A callback method when the values of any of the nodes in the state changes"]
20
+
["onNodesChange?", "(query: QueryMethods) => void", "Optional. A callback method when the values of any of the nodes in the state changes"]
<Elementis={Container}canvas> // defines the Root Node
38
-
<h2>Drag me around</h2>
39
-
<MyComptext="You can drag me around too" />
40
-
<Elementis="div"style={{background: "#333" }}>
41
-
<p>You can't drag me because the Element above is not a canvas </p>
42
-
</Element>
43
-
</Element>
44
-
</Frame>
45
-
</Editor>
46
-
</div>
47
-
)
48
-
}
49
-
```
50
-
51
26
### Custom render user elements
52
27
By default, every user element is rendered just as it is. However, if you'd like to, for example, wrap every user element inside a `div`, you can do so through the `onRender` prop:
53
28
@@ -79,6 +54,8 @@ In the above example, every user element will now be wrapped in a black `div`.
79
54
80
55
### Specifying the Drop Indicator colour
81
56
57
+
You could change the colours of the drag and drop indicators like so:
58
+
82
59
```jsx {6-9}
83
60
import {Editor} from"@craftjs/core";
84
61
@@ -100,3 +77,27 @@ const App = () => {
100
77
)
101
78
}
102
79
```
80
+
81
+
82
+
### Callback when Nodes change
83
+
84
+
Perform a callback whenever the Nodes in the editor is updated/changed
85
+
86
+
```jsx {6-11}
87
+
import {Editor} from"@craftjs/core";
88
+
89
+
constApp= () => {
90
+
return (
91
+
<Editor
92
+
// Save the updated JSON whenever the Nodes has been changed
Copy file name to clipboardexpand all lines: packages/docs/versioned_docs/version-0.1.0-beta.7/api/Element.md
+11-80
Original file line number
Diff line number
Diff line change
@@ -8,56 +8,26 @@ import {API, Badge} from "@site/src/components";
8
8
9
9
<Badgetype="component" />
10
10
11
-
Defines a Node to create for a given User Element
11
+
Defines the Node for a given User Element
12
12
13
13
## Reference
14
14
### Props
15
15
<API items={[
16
16
["is", "React.ElementType", "The User Element to render"],
17
-
["id", "String", "Required if the <Node /> is being created inside a User Component"],
17
+
["id", "String", "Required if the <Element /> is being created inside a User Component"],
18
18
["canvas", "boolean", "If true, a Canvas Node will be created."],
19
19
["custom", "Record<string, any>", "Sets the Node's custom properties"],
20
20
["hidden", "boolean", "Sets the Node's hidden property. If true, this will hide the Node"],
21
21
["...elementProps", "Object", "The props of the element specified in 'is'"],
22
22
]} />
23
23
24
24
25
-
## When to specify `id`
26
-
You only need to specify the `id` prop when you are defining Nodes **inside** a User Component's render method.
27
-
```jsx {6,7,9,12,24-25}
28
-
constApp= () => {
29
-
return (
30
-
<Craft resolver={{MyComp, Container}}>
31
-
<h2>My Page Editor</h2>
32
-
<Frame>
33
-
<Element is="div">// not required
34
-
<Element is={MyComp} />// not required
35
-
<div>
36
-
<Element is="div"/>// not required
37
-
</div>
38
-
<Container>
39
-
<Element is="div"/>// not required
40
-
</Container>
41
-
</Element>
42
-
</Frame>
43
-
</Craft>
44
-
)
45
-
}
25
+
## Usage
46
26
47
-
constContainer= () => {
48
-
return (
49
-
<div>
50
-
<h2>Container</h2>
51
-
<Element id="Top" is="div"/>// required
52
-
<Element id="Bottom" is={MyComp} />// required
53
-
</div>
54
-
)
55
-
}
56
-
```
27
+
### Configure Nodes in <Frame />
57
28
58
-
## Examples
29
+
Since the `<Frame />` component creates a Node automatically for all of its children elements, thus the `<Element />` component can be used to simply configure the values of the Node that is being created.
When used inside a User Component, `<Element />` works identically as used inside `<Frame />` but because there isn't a Node in-place, thus it has to create a new Linked Node - which is essentially a Node that is linked to the Node of the containing User Component via an arbitary `id`:
131
58
132
59
```jsx {5}
133
60
constHero= () => {
@@ -142,6 +69,10 @@ const Hero = () => {
142
69
}
143
70
```
144
71
72
+
> `<Element />` used inside User Component must specify an `id` prop
0 commit comments