-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Help Needed: Custom Block Plugin #357
Comments
Hi @Quietscher 👋 |
Hey 👋
|
This is what i currently have |
Hey @Darginec05 😊 |
Hi @Quietscher 👋 |
@Quietscher I'm finally here :D |
Nice!
That all in one custom block So after creating the block, the user can set a title a content, pictures, a date and so on. Id like to save the content that the user creates in the block separately in an object ill push to My backend. |
Habe you had some time yet? @Darginec05 😄 |
@Quietscher I checked your code, but still really hard to understand what you want to build :D |
maybe this helps |
@Quietscher yes! much better |
Nice 😁 yeah sure |
I did approximate elements structure for your plugin. It should be like this: type SuperCarouselContainerElement = SlateElement<'super-carousel'>;
type CarouselListlement = SlateElement<'carousel-list'>;
type CarouselItemElement = SlateElement<'carousel-item'>;
type CarouselItemImageElement = SlateElement<'carousel-item-image'>;
type UserInputElement = SlateElement<'user-input'>;
type SelectorItem = SlateElement<'selector-item'>;
type DateSelector = SlateElement<'date-selector'>;
type LocationSelector = SlateElement<'location-selector'>;
type SuperBlockPluginMap = {
'super-carousel': SuperCarouselContainerElement;
'carousel-list': CarouselListlement;
'carousel-item': CarouselItemElement;
'carousel-item-image': CarouselItemImageElement;
'user-input': UserInputElement;
'date-selector': DateSelector;
'location-selector': LocationSelector;
'selector-item': SelectorItem;
};
const SuperCarouselBlock = new YooptaPlugin<SuperBlockPluginMap>({
type: 'SuperCarousel',
elements: {
'super-carousel': {
children: ['selector-item', 'carousel-list', 'user-input'],
asRoot: true,
render: ({ attributes, children, element }) => {
return (
<div {...attributes} style={{ border: '1px solid red', padding: 10 }}>
{children}
</div>
);
},
},
'carousel-list': {
// do it using Commands API and use onBeforeCreate event to build block with three or more images
children: ['carousel-item', 'carousel-item', 'carousel-item'],
render: ({ attributes, children, element }) => {
return (
<div {...attributes} style={{ border: '1px solid red', display: 'flex', padding: 10 }}>
{children}
</div>
);
},
},
'carousel-item': {
children: ['carousel-item-image'],
render: ({ attributes, children, element }) => {
return (
<div {...attributes} style={{ border: '1px solid green', padding: 10, width: 150 }}>
{children}
</div>
);
},
},
'carousel-item-image': {
children: [],
render: ({ attributes, children, element }) => {
return (
<div {...attributes} contentEditable={false} style={{ border: '1px solid blue', padding: 10 }}>
{children}
<img
src="https://res.cloudinary.com/ench-app/image/upload/v1731103395/c0dc98f5-da0b-430a-b9b4-144f9a25b3b9_rqcqcc_utkcnh.webp"
width={150}
height={150}
/>
</div>
);
},
props: {
nodeType: 'void',
},
},
'user-input': {
children: [],
render: ({ attributes, children, element }) => {
return (
<div {...attributes} style={{ border: '1px solid yellow', padding: 10 }}>
{children}
</div>
);
},
},
'selector-item': {
children: ['location-selector', 'date-selector'],
render: ({ attributes, children, element }) => {
return (
<div {...attributes} style={{ border: '1px solid pink', padding: 10, display: 'flex', width: '100%' }}>
{children}
</div>
);
},
},
'location-selector': {
children: [],
render: ({ attributes, children, element }) => {
return (
<div {...attributes} contentEditable={false} style={{ border: '1px solid pink', padding: 10, flex: 1 }}>
{children}
<input type="date" />
</div>
);
},
props: {
nodeType: 'void',
},
},
'date-selector': {
children: [],
render: ({ attributes, children, element }) => {
return (
<div {...attributes} contentEditable={false} style={{ border: '1px solid purple', padding: 10, flex: 1 }}>
{children}
<input type="date" />
</div>
);
},
props: {
nodeType: 'void',
},
},
},
}); P.S. if you want fully functional plugin for your needs, then I can develop it after support/donation |
@Quietscher did this example help you? |
Hey 👋🏻 |
What's the example?
Hello!
I want to create a custom block component, and I've looked at the carousel example.
It should have multiple text inputs and subcomponents.
I can't get it to work that the use can input text (that is saved and so on)...
You can think of it as
Card
CardHeader
CardContent
(where one can enter text as header and as content)
I would be very glad for some explanation, thanks!
Code of Conduct
The text was updated successfully, but these errors were encountered: