Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to i'am using image for props ? #4

Open
FajarFE opened this issue Apr 27, 2024 · 0 comments
Open

How to i'am using image for props ? #4

FajarFE opened this issue Apr 27, 2024 · 0 comments

Comments

@FajarFE
Copy link

FajarFE commented Apr 27, 2024

import {
	Card,
	CardHeader,
	CardFooter,
	CardTitle,
	CardDescription,
	CardContent,
	CardImage,
} from "../ui/card";
import { Element } from "@craftjs/core";
import { SettingsControl } from "../settings-control";
import { withNode } from "./connector";
import { NodeButton } from "./button";

interface NodeCardProps extends React.HTMLAttributes<HTMLDivElement> {}

const draggable = true;
const droppable = true; // Can drop items into to this component

export const NodeCardHeader = withNode(CardHeader, {
	droppable,
});

export const NodeCardTitle = withNode(CardTitle, {
	draggable,
	droppable,
});

NodeCardTitle.craft = {
	...NodeCardTitle.craft,
	related: {
		toolbar: SettingsControl,
	},
};

export const NodeCardDescription = withNode(CardDescription, {
	draggable,
	droppable,
});

NodeCardDescription.craft = {
	...NodeCardDescription.craft,
	related: {
		toolbar: SettingsControl,
	},
};

export const NodeCardContent = withNode(CardContent, {
	droppable,
});

export const NodeCardFooter = withNode(CardFooter, {
	droppable,
});

export const NodeCardContainer = withNode(Card, {
	draggable,
	droppable,
});

export const NodeCardImage = withNode(CardImage, {
	droppable,
	draggable,
});

NodeCardImage.craft = {
	...NodeCardImage.craft,
	related: {
		toolbar: SettingsControl,
	},
};

export const NodeCard = ({ ...props }: NodeCardProps) => {
	return (
		<NodeCardContainer {...props}>
			<Element
				canvas
				id='card-header'
				is={NodeCardHeader as typeof NodeCardHeader & string}>
				<NodeCardTitle>Card Title</NodeCardTitle>
				<NodeCardDescription>Card Description</NodeCardDescription>
			</Element>
			<Element
				canvas
				id='card-content'
				is={NodeCardContent as typeof NodeCardContent & string}>
				<NodeCardImage />
			</Element>
			<Element
				canvas
				id='card-footer'
				is={NodeCardFooter as typeof NodeCardFooter & string}>
				<NodeButton>Footer button</NodeButton>
			</Element>
		</NodeCardContainer>
	);
};

NodeCard.craft = {
	...NodeCard.craft,
	displayName: "Card",
	props: {
		className: "p-6 m-2",
	},
	custom: {
		importPath: "@/components/card",
	},
	related: {
		toolbar: SettingsControl,
	},
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant