daybrush / selecto

Selecto.js is a component that allows you to select elements in the drag area using the mouse or touch.
https://daybrush.com/selecto
MIT License
2k stars 81 forks source link

How can I change the color of a selection area? #156

Closed ManucherKM closed 10 months ago

ManucherKM commented 10 months ago

Using the react-selecto package in my web application I ran into a problem. My web application has its own dominant colors. I use them to show user activity in the interface, on hover, focus, and so on. But the default blue color in the package is not suitable for the style of my web application, otherwise everything suits me. How can I solve this problem?

jadiagaurang commented 10 months ago

Hi @ManucherKM

You can use className prop to setup a CSS Class to customize selection area color!

ManucherKM commented 10 months ago

@jadiagaurang Could you please provide an example of working code. My code doesn't work (I apologize for the formatting.): `<Selecto className="bg-red-400 border-red-400 text-red-400" container={blockForSelection.current} selectableTargets={[".file"]} selectByClick selectFromInside continueSelect={false} toggleContinueSelect={"shift"} hitRate={100} onSelect={e => { const activeClass = "_active_kq2ra_39"

    e.added.forEach(el => el.classList.add(activeClass))
    e.removed.forEach(el => el.classList.remove(activeClass))
}}

/>` image image

jadiagaurang commented 10 months ago

Hi @ManucherKM

I am very sorry for the delayed response.

You need to create a CSS class in the dom!

Example:

.mpr-designer-selection {
  background: rgba(255, 0, 0, 0.5) !important; /* Red Color with half opacity */
}

And use the same class name in the Selecto Config.

window.SelectoRef = new Selecto({
    className: "mpr-designer-selection",
    container: designCanvas,
    dragContainer: designCanvas,
    selectableTargets: [".el"],
    hitRate: 0,
    selectByClick: true,
    preventClickEventOnDrag: true,
    selectFromInside: false,
    toggleContinueSelect: ["shift"],
    ratio: 0
});

Take a look at the Codepen Example at https://codepen.io/jadiagaurang/pen/QWJyEaE

CC @daybrush Please make corrections if needed!