craft.js icon indicating copy to clipboard operation
craft.js copied to clipboard

Override the indicator style

Open lord007tn opened this issue 4 years ago • 6 comments

I didn't know how I can override the indicator and make a custom one maybe have the shape of the dragged component besides that green or red line.

in Docs indicator can only have success color and error color passed from the editor as a string. maybe the indicator can be a whole HTML element. where you can make your custom one and pass it to the editor state to use it.

lord007tn avatar Sep 01 '20 07:09 lord007tn

Render indicator? Sadly it's hard coded inside packages/utils/RenderIndicator.tsx

IMHO all indicators should be divs with classes like 'craftjs-render-indicator' to support some customization.

RaGreen avatar Sep 03 '20 09:09 RaGreen

Can setProp add other attributes to an element?

oc-Design avatar Sep 05 '20 10:09 oc-Design

Can setProp add other attributes to an element?

nope, setProp is more of a useState function where you can change the initial state using it. so when you use setProp you actually setting the value of the declared props of your component.

but you can add other attributes to the element take a look at this where i add the transformation prop from the element state: transformation are inside the useNode() hook image

I hope this answers your question

lord007tn avatar Sep 07 '20 14:09 lord007tn

🙏please make this a function.

That is probably the biggest improvement craft.js could get, actually rendering the correct space for the component you are dragging as react-beautiful-dnd does it: https://github.com/atlassian/react-beautiful-dnd

I was hoping I could at the very least make it a custom component.

MarkLyck avatar Mar 12 '21 02:03 MarkLyck

This also applies in our project— we would like to use a custom indicator. Ideally for us the indicator component would receive some geometry information through props, and a custom component/element would be defined to render it. It might look something like this:

const MyCustomIndicator = ({ error, top, left, width, height, ...props }) => (
  <div style={{ top, left, width, height, position: 'fixed', /* ... */ }} />;
);

// ...

<Editor Indicator={MyCustomIndicator} resolver={/* ... */}>
  {/* ... */}
</Editor>

If you would be open to receiving a PR for this, we may be able to aid with the implementation đź‘Ť

devinivy avatar Mar 30 '21 13:03 devinivy

Personally, without complicating things, I'd like to be able to customize the indicator and transitions. The indicator warping all over the place is unnecessary to me I'd prefer it just snap to the next available drop zone.

EDIT: It turns out this is an available feature that's not documented to my knowledge. The indicator actually has success, error, thickness, and above all transition! All of which are simple strings except thickness which is a number.

trulysinclair avatar Jan 28 '22 06:01 trulysinclair