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

How to change the Margin of Shepherd Step without using Offset and FloatingUIOption #2507

Open
mvksages opened this issue Oct 19, 2023 · 10 comments
Labels

Comments

@mvksages
Copy link

I was trying to change the margin:0px to 20px from Tour.When.show() method - however it does not reflect. We are using Shepherd.js in a legacy project which does not need additional offset object for making the margin change.

Is there anyway I can achieve this ? Below is the example code

        createTourObj: function () {
            const tour = new Shepherd.Tour({
                useModalOverlay: true,
                defaultStepOptions: {
                    //floatingUIOptions: {middleware: [offset({ mainAxis: 64, crossAxis: 12 })]},
                    when: {
                        show() {
                            // This is where I was trying to modify the style... Its NOT working.           
                            const currentStepElement = tour.currentStep.el;
                            currentStepElement.style['margin'] = "20px"
                        }
                    }
                }
            });

            return tour;
        },
@mvksages
Copy link
Author

Even if its possible to create a dummy offset object inline in the javascript method that would be great as well. This is for legacy project with vanilla javascript libraries pulled as a file and no NPM or CDN.

@RobbieTheWagner
Copy link
Member

The offsets are part of floating UI, so you'll have to use their offset to do it. I imagine they have a way to include it globally, rather than import it.

@mvksages
Copy link
Author

Thanks for your response @RobbieTheWagner ,

Let me reachout to floatingUI library or if anyone have a sample example that should also help. Even if it means to have it as part of the window object like window.offset. I can use this in our code during the site tour as well.

We are unable to use the import as mentioned earlier, Working on Legacy project with plain vanilla JS libraries. Even CDN are downloaded into specific folders for shepherd.js to use it for site tour.

@mvksages
Copy link
Author

I was able to bring CDN file into our page using CDN: https://cdn.jsdelivr.net/npm/@floating-ui/[email protected]/dist/floating-ui.core.umd.js

However the floatingUIOption is not affecting anything on the dialog. Below is the code. If we are not using Import. Is there a way we can relate or connect the offset object with the Step appearing on the screen somehow ? (Sorry for the trouble if its confusing. )

        createTourObj: function () {
            const tour = new Shepherd.Tour({
                useModalOverlay: true,
                confirmCancel: true,
                confirmCancelMessage: 'Are you sure ? you want to exit the Tour?',

                defaultStepOptions: {
                    scrollTo: true,
                    exitOnEsc: true,
                    keyboardNavigation: true,
                    floatingUIOptions: { middleware: [FloatingUICore.offset({ mainAxis: 100, crossAxis: 100 })]},
                }
            });

            return tour;
        },

THe page shows module as mentioned below
<script type="module" src="[https://cdn.jsdelivr.net/npm/@floating-ui/[email protected]/dist/floating-ui.core.umd.js](view-source:https://cdn.jsdelivr.net/npm/@floating-ui/[email protected]/dist/floating-ui.core.umd.js)"></script></head>

@LordRembo
Copy link

I'm having a similar issue to this. @mvksages did you ever find a workaround for the floatingUIOption offset not working?

@LordRembo
Copy link

LordRembo commented Mar 8, 2024

In the docs, I found the reference should be window.FloatingUIDOM, but that also doesn't work for my case.

@mvksages
Copy link
Author

mvksages commented Mar 8, 2024

Its not possible to have a workaround. Finally I had to try a different library like https://driverjs.com/

@RobbieTheWagner
Copy link
Member

Why not just import offset? You can do imports in <script type="module">

@lonix1
Copy link

lonix1 commented May 3, 2024

What about folks using the CDN option, how would we do it?

@RobbieTheWagner
Copy link
Member

@lonix1 you should still be able to do it with <script type="module">. Perhaps we should reexport it for ease of importing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants