Comments (1)
"use client";
import { Editor, Frame, Element, useEditor, useNode } from "@craftjs/core";
import RenderNode from "./render_node";
import { COMPONENTS_ARRAY } from "../constants__/floater";
const Container = ({ background, padding, children, ...props }) => {
const {
connectors: { connect, drag },
} = useNode();
return (
<div
{...props}
ref={(ref) => connect(drag(ref))}
style={{
margin: "5px 0",
background,
padding: `${padding}px`,
zIndex: 9999,
}}
>
{children}
</div>
);
};
const SideBar = () => {
const { connectors } = useEditor();
return (
<div className="space-y-6 p-5">
{COMPONENTS_ARRAY.map(({ name, components }) => (
<div className="p-2" key={name}>
<div>{name}</div>
<ul className="flex flex-col">
{components.map((comp, index) => (
<button
key={index}
ref={(ref) => connectors.create(ref, comp)}
>{`Varient ${index + 1}`}</button>
))}
</ul>
</div>
))}
</div>
);
};
const all_components = COMPONENTS_ARRAY.reduce((acc, currentComp) => {
return {
...acc,
...currentComp.components.reduce((acc, currentVarient, index) => {
return {
...acc,
[`${currentComp.name}${index + 1}`]: currentVarient,
};
}, {}),
};
}, {});
const App = () => {
return (
<div className="w-full flex page-container">
<Editor
onRender={RenderNode}
resolver={{
Container,
...all_components,
}}
>
<div className="w-3/12">
<SideBar />
</div>
<div className="w-full min-h-screen">
<Frame className="h-56 w-full bg-red-100">
<Element
canvas
is={Container}
width="800px"
height="auto"
background={{ r: 255, g: 255, b: 255, a: 1 }}
padding={["40", "40", "40", "40"]}
custom={{ displayName: "App" }}
>
<div>Drag and Drop your component</div>
</Element>
</Frame>
</div>
</Editor>
</div>
);
};
export default App;
Here is full code
from craft.js.
Related Issues (20)
- Node with other nodes as children HOT 1
- Cannot update a component (`LayerContextProvider`) while rendering a different component (`Frame`) HOT 1
- MJML output question
- useMultipleNode?
- multi select does not update layers
- Decouple @craftjs/layers with styled-components HOT 1
- Small typing issue when you enable strict null check
- change in props of any component is causing rerender for all other components
- How to use methods as a prop in craft js HOT 1
- Allowing type augmentation HOT 2
- A potential infinite loop in example landing
- custom handlers initialized multiple times in production
- Could not find a declaration file for module HOT 3
- Wrong typing for getState?
- Module parse failed: Unexpected token
- When a component containing `craft.js`'s `Element` is dragged onto the `Frame`, a warning appears
- 👉 Tap-and-point mode for touch devices
- Props passed to <Element is={component} someProp={prop}/> do not update HOT 2
- Serialize Throws Circular Json Error HOT 2
- Error occurs when useLayer is called。Prompt: Cannot destroy property 'subscribe' of 'e' as it is undefined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from craft.js.