import { CSSResultGroup, PropertyValues } from "lit"; import { SigveloElement } from "@mcp-b/wc-support/base/sigvelo-element"; import { TransitionAnimation } from "@mcp-b/wc-support/utilities/animate"; //#region src/components/transition-group/transition-group.d.ts /** * * * @summary Improves the user's experience by adding subtle animations as items are added, removed, and reordered in the * @tag sigvelo-transition-group * group. * @documentation https://design-system.sigvelo.com/docs/components/transition-group * @status stable * @since 1.0 * * @slot - One or more elements to transition when adding, removing, and reordering the DOM. * * @event sigvelo-content-changed - Emitted when content changes and before the transition animation begins. * @event sigvelo-transition-end - Emitted when transition animations end. * * @cssstate transitioning - Applied when a transition is active. * * @cssproperty [--duration=0.25s] - The duration of each individual step (not the total transition time). * * @example Default * Wrap a collection of elements in a transition group and use normal DOM APIs to add, remove, and reorder them. The transition group will automatically apply the appropriate animations as elements enter and exit the group. * * ```html *
* * *
1
*
2
*
3
*
4
*
5
*
6
*
7
*
8
*
* *
* Add random * Remove random * Shuffle * Disable transitions *
*
* * * * * * ``` * * This example includes logic and styles for the demo, but the minimal markup you need for a transition group is shown below. Note that only _direct children_ of the transition group will be animated. * * ```html * *
...
*
...
*
...
*
* ``` * * For best results, avoid applying transitions, animations, and inline styles to transition group items, as they may interfere with the component's animations. Also avoid modifying the DOM _during_ a transition to prevent interruptions. * * **Note:** Transition groups honor the user's [`prefers-reduced-motion`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion) setting. If you're not seeing animations, this might be why. To override this behavior, which is generally not recommended, use the `ignore-reduced-motion` attribute. * * @example Working with elements * Use standard DOM APIs to add, remove, and reorder elements and the transition group will automatically animate your changes. This example demonstrates how adding, removing, and reordering list items will be handled by the transition group. * * ```html *
* * * * * * * *
* * * * Shuffle *
*
* * * * * ``` * * **Note:** As elements are added, removed, and reordered, their positions in the DOM change instantly. The elements are then animated from their old positions to their new positions, meaning CSS selectors such as `:first-child`, `:last-child`, `:nth-child()`, et al will apply as soon as the transition starts, which may not always be desirable. To avoid this, use IDs and classes in lieu of position-based selectors. * * @example Awaiting transitions * Avoid making DOM changes while a transition is running. The `transitionComplete` property holds a promise that resolves when the current or next transition ends. You can await it to be sure all animations are complete before proceeding with further DOM changes. * * ```html *
* *
*
*
* *
* Swap *
*
* * * * * ``` * * @example Changing the layout * Transition groups use a columnar flex layout, by default. To change the layout, apply `flex-direction: row` to the transition group. You can add spacing between items by setting the `gap` property. * * ```css * sigvelo-transition-group { * flex-direction: row; * gap: 2rem; * } * ``` * * For best results, avoid using complex layouts within transition groups. * * @example Changing the duration * To change the animation speed, set the `--duration` custom property on the transition group. Each transition is made up of one or more steps (e.g. add, remove, reposition) and the duration applies to each individual step, not the total transition time. * * ```html * *
*
*
*
*
* * * * * ``` * * @example Changing the animation * Transition groups use the Web Animations API to move elements around. To customize the enter and exit animations, pass a `TransitionAnimation` object to the transition group's `transitionAnimation` property. The object includes keyframes and easings for entering and exiting: * * ```ts * import type { TransitionAnimation } from '@mcp-b/wc-support/utilities/animate'; * * const elevator: TransitionAnimation = { * enter: { * keyframes: [ * { opacity: 0, translate: '0 100%' }, * { opacity: 1, translate: '0 0' } * ], * easing: 'cubic-bezier(0.33, 1, 0.68, 1)' * }, * exit: { * keyframes: [ * { opacity: 1, translate: '0 0' }, * { opacity: 0, translate: '0 -100%' } * ], * easing: 'cubic-bezier(0.33, 1, 0.68, 1)' * } * }; * * const transitionGroup = document.querySelector('sigvelo-transition-group'); * transitionGroup.transitionAnimation = elevator; * ``` * * @example Disabling transitions * Add the `disable-transitions` attribute to disable transition animations. Note that the DOM will still be modified when this option is enabled. * * ```html *
* *
*
*
*
* * *
* * * * * ``` */ declare class SigveloTransitionGroup extends SigveloElement { static styles: CSSResultGroup; private cachedContainerPosition; private cachedElementPositions; private cachedScrollPosition; private currentTransition; private isObserving; private mutationObserver; private resizeObserver; /** Determines if the transition group is currently animating. (Property only) */ isTransitioning: boolean; /** * A custom enter/exit animation conforming to the `TransitionAnimation` interface. * (Property only) */ transitionAnimation?: TransitionAnimation; /** * By default, the transition group observes and animates its own children. In some cases, you may want it to control * another element's children. This is useful in cases where you can't directly wrap child elements with the * `` element. * * For example, if you embed a transition group in a component's shadow root but need it to control slotted (light * DOM) elements, you can't simply wrap the slot because the mutation observer can't see projected (slotted) elements. * In this case, point this property to the target element and the transition group will hide itself and observe the * target container's children instead. (Property only) */ transitionContainer: HTMLElement; /** * Disables transition animations. However, the `sigvelo-content-changed` and `sigvelo-transition-end` events will still * be dispatched. */ disableTransitions: boolean; /** * By default, no animation will occur when the user indicates a preference for reduced motion. Use this attribute to * override this behavior when necessary. */ ignoreReducedMotion: boolean; connectedCallback(): void; disconnectedCallback(): void; firstUpdated(): void; updated(changedProperties: PropertyValues): void; /** * Gets a custom animation based on the users preference. If a custom animation isn't found, the default is returned. */ private getAnimation; /** * The children this group animates. * * `children` is a collection of plain `Element`s, and everything the group does to one — hiding it, clearing an * inline opacity, animating a laid-out box — is `HTMLElement` vocabulary. Anything else in the container is left * where it is rather than quietly mistyped. */ private get animatableChildren(); private handleMutations; private handleResizes; private handleVisibilityChange; private startObservers; private stopObservers; /** * Returns a promise that resolves when the current transition ends. If no transition is running, it resolves * immediately This is a great way to ensure transitions have stopped before doing something else, such as adding or * removing new elements to the transition group. */ transitionComplete(): Promise; /** * Updates the cached coordinates of all child elements in the transition group. In most cases, you shouldn't have to * call this method. However, if you're resizing or animating elements imperatively, you may need to call this * immediately before appending or removing elements to ensure a smooth transition. */ updateElementPositions(): void; render(): import("lit-html").TemplateResult<1>; } declare global { interface HTMLElementTagNameMap { "sigvelo-transition-group": SigveloTransitionGroup; } } //#endregion export { SigveloTransitionGroup as t };