Code Monkey home page Code Monkey logo

Comments (4)

ablamunits avatar ablamunits commented on May 13, 2024 2

Thanks for the quick reply @FezVrasta, and thank you for pointing me in the right direction. This helped me achieve what I wanted. However I did get to it only after a bit of trial and error. For example, what eventually worked for me was this:

const myExampleModifier = {
	enabled: true,
	order: 860,
	fn: (data: any) => {
		const isVisible = this.state.isVisible;

		const left = Math.floor(data.popper.left);
		const top = Math.floor(data.popper.top);
		const newTop = isVisible ? top : top - 10; // Change the top position if popper is hidden

		const transform = `translate3d(${left}px, ${newTop}px, 0px)`;

		// Update popper, offsets and styles object
		const popper = {...data.popper, left, top: newTop};
		const offsets = {...data.offsets, popper};
		const styles = {...data.styles, opacity, transform};

		return {...data, offsets, styles};
	}
};

What I did not understand is why it was necessary for me to change the offsets and styles objects to make this work? Is this the correct way I should go to achieve the desired effect? Sorry for the vague question - I am just making sure I am not missing anything as I am still studying this library :)

Thank you for your help.

from react-popper.

FezVrasta avatar FezVrasta commented on May 13, 2024

Yes sure,

here is where Popper.js computes the styles that need to be applied to the popper element.

After that, the applyStyle is just going to set the styles that have been computed in the previous step.

react-popper replaces the applyStyle modifier with its own React specific code

You can then inject a custom modifier after computeStyles that replaces the value of the data.styles.transform with whatever you prefer.

from react-popper.

jackson-sandland avatar jackson-sandland commented on May 13, 2024

Bueller? Would be great to know if the solution is a hack or considered idiomatic. :)

from react-popper.

FezVrasta avatar FezVrasta commented on May 13, 2024

the modifier system is at the core of Popper.js, feel free to use it, definitely not an hack!

from react-popper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.