bits-ui
Version:
The headless components for Svelte.
25 lines (24 loc) • 732 B
JavaScript
import { watch } from "runed";
import { AnimationsComplete } from "./animations-complete.js";
export class OpenChangeComplete {
#opts;
#enabled;
#afterAnimations;
constructor(opts) {
this.#opts = opts;
this.#enabled = opts.enabled ?? true;
this.#afterAnimations = new AnimationsComplete({
ref: this.#opts.ref,
afterTick: this.#opts.open,
});
watch([() => this.#opts.open.current], ([open]) => {
if (!this.#enabled)
return;
this.#afterAnimations.run(() => {
if (open === this.#opts.open.current) {
this.#opts.onComplete();
}
});
});
}
}