Comments (4)
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.
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.
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.
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)
- Alert toast component from README doesn't have the transition effect HOT 3
- Radio button cards HOT 2
- Open a modal inside a dropdown HOT 9
- Permit use Turbo frame on tabs click -Possible solution- HOT 3
- Multiple modals HOT 1
- How to utlize `cb`?
- https://registry.yarnpkg.com/tailwindcss-stimulus-components~: Not found HOT 1
- - delete this is just an error
- Tabs not working with the select / dropdown HOT 1
- Navigable Tabs with Keyboard HOT 1
- New release? HOT 4
- Active tabs styling is broken in version 4 HOT 2
- Modal forced to the hidden state when added to the DOM HOT 4
- Specify prefix for tailwind classes HOT 2
- Issue when using `data-tabs-update-anchor-value="true"` and linking to a specific anchor from another page HOT 1
- Dropdown improvements HOT 4
- Google Chrome Autofill Result Select Causes Modal Close HOT 3
- Multiple modals on a page -- components not properly behind background HOT 1
- Uncaught (in promise) DOMException: The user aborted a request. HOT 1
- CDN Minified version does not appear to respect `data-toggle-class` for toggle HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tailwindcss-stimulus-components.