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

feat: allow customising dnd indicator classname/style #683

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/modern-socks-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@craftjs/utils': patch
'@craftjs/core': patch
---

Allow customising dnd indicator style/classname
2 changes: 2 additions & 0 deletions packages/core/src/events/RenderEditorIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const RenderEditorIndicator = () => {
}

return React.createElement(RenderIndicator, {
className: indicatorOptions.className,
style: {
...movePlaceholder(
indicator.placement,
Expand All @@ -47,6 +48,7 @@ export const RenderEditorIndicator = () => {
? indicatorOptions.error
: indicatorOptions.success,
transition: indicatorOptions.transition || '0.2s ease-in',
...(indicatorOptions.style ?? {}),
},
parentDom: indicator.placement.parent.dom,
});
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/interfaces/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type Options = {
error: string;
transition: string;
thickness: number;
className: string;
style: React.CSSProperties;
}>;
handlers: (store: EditorStore) => CoreEventHandlers;
normalizeNodes: (
Expand Down
8 changes: 7 additions & 1 deletion packages/utils/src/RenderIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import ReactDOM from 'react-dom';

type RenderIndicatorProps = {
style: React.CSSProperties;
className?: string;
parentDom?: HTMLElement;
};

export const RenderIndicator = ({ style, parentDom }: RenderIndicatorProps) => {
export const RenderIndicator = ({
style,
className,
parentDom,
}: RenderIndicatorProps) => {
const indicator = (
<div
className={className}
style={{
position: 'fixed',
display: 'block',
Expand Down
10 changes: 7 additions & 3 deletions site/docs/api/Editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ const App = () => {
```
In the above example, every user element will now be wrapped in a black `div`.

### Specifying the Drop Indicator colour
### Customising the drag-and-drop indicator

You could change the colours of the drag and drop indicators like so:
You could also change the colours/style of the drag-and-drop indicator like so:

```jsx {6-9}
import {Editor} from "@craftjs/core";
Expand All @@ -65,7 +65,11 @@ const App = () => {
<Editor
indicator={{
'success': '#2d9d78', // green
'error': '#e34850' // red
'error': '#e34850', // red
'style': { // custom CSS properties
boxShadow: '...
},
'className': 'your-css-class' // custom CSS class
}}
>
<Frame resolver={{Hero}}>
Expand Down
Loading