Giter Club home page Giter Club logo

Comments (4)

philipithomas avatar philipithomas commented on June 19, 2024 1

I took a shortcut of having the overlay slide in with the sidebar, without a separate animation. It looks decent enough @gjones.

from tailwindcss-stimulus-components.

gjones avatar gjones commented on June 19, 2024

I've been looking into this too, did you manage to find a workaround? Ideally the slideover would slide in and out rather than fading.

from tailwindcss-stimulus-components.

sethaddison avatar sethaddison commented on June 19, 2024

I was just working on this same thing yesterday. @philipithomas can you share code on how you achieved the slideover for entering?

from tailwindcss-stimulus-components.

coder17934 avatar coder17934 commented on June 19, 2024

I have found a suboptimal solution, I created my own DropdownController and SlideoverController. I had to change both as I could not get the entering transitions to work otherwise.

The code for getting the transitions to work came from https://github.com/mmccall10/el-transition.

This is what I ended up with:

// transition_helper.js

export async function transition(target, transitionClassList, startClassList, endClassList) {
    transitionClassList.forEach(klass => target.classList.add(klass))
    startClassList.forEach(klass => target.classList.add(klass))
    await nextFrame();
    startClassList.forEach(klass => target.classList.remove(klass))
    endClassList.forEach(klass => target.classList.add(klass))
    await afterTransition(target)
    endClassList.forEach(klass => target.classList.remove(klass))
    transitionClassList.forEach(klass => target.classList.remove(klass))
}

function nextFrame() {
    return new Promise(resolve => {
        requestAnimationFrame(() => {
            requestAnimationFrame(resolve)
        });
    });
}

function afterTransition(element) {
    return new Promise(resolve => {
        // safari return string with comma separate values
        const computedDuration = getComputedStyle(element).transitionDuration.split(",")[0]
        const duration = Number(computedDuration.replace('s', '')) * 1000;
        setTimeout(() => {
            resolve()
        }, duration)
    });
}
// custom_dropdown_controller.js
// other than the two methods below the code is the same as dropdown_controller.js

async _show(cb) {
        this.menuTarget.classList.remove(this.toggleClass)
        this.element.setAttribute("aria-expanded", "true")

        await transition(
            this.menuTarget,
            this._enteringClassList[0],
            this._invisibleClassList[0],
            this._visibleClassList[0]);

        if (typeof cb == 'function') {
            await cb()
        }
}

async _hide(cb) {
        await transition(
            this.menuTarget,
            this._leavingClassList[0],
            this._visibleClassList[0],
            this._invisibleClassList[0]);

        if (typeof cb == 'function') {
            await cb()
        }

        this.element.setAttribute("aria-expanded", "false")
        this.menuTarget.classList.add(this.toggleClass)
}
// custom_slideover_controller.js
// inheriting from custom_dropdown_controller.js

// added another target to solve the original issue in this thread
static targets = ['menu', 'overlay', 'sidebar']

async _show() {
        this.sidebarTarget.classList.remove(this.toggleClass)
        this.overlayTarget.classList.remove(this.toggleClass)

         const parent_show_promise = super._show()
         const transition_promise = transition(
                 this.overlayTarget,
                 this._enteringClassList[1],
                 this._invisibleClassList[1],
                 this._visibleClassList[1]);
         await Promise.all([parent_show_promise, transition_promise])
}

async _hide() {
        const parent_show_promise = super._hide()
        const transition_promise = await transition(
            this.overlayTarget,
            this._leavingClassList[1],
            this._visibleClassList[1],
            this._invisibleClassList[1]);

        await Promise.all([parent_show_promise, transition_promise]);

        this.overlayTarget.classList.add(this.toggleClass)
        this.sidebarTarget.classList.add(this.toggleClass)
}

from tailwindcss-stimulus-components.

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.