0.1.2 • Published 1 year ago

svelte-collapse v0.1.2

Weekly downloads
75
License
MIT
Repository
github
Last release
1 year ago

Svelte Collapse

A Svelte Action that is applied to an element to transition its height between open and closed states.

Usage

npm install svelte-collapse
<script>
    import collapse from 'svelte-collapse'
    let open = true
</script>

<div use:collapse={{open}}>
    <p>Lorem ipsum</p>
    <p>Lorem ipsum</p>
</div>

<button on:click={() => open = !open}>
    Toggle
</button>

Additional parameters that can be used to modify the transition properties, the defaults are shown below.

<div use:collapse={{ open: true, duration: 0.2, easing: 'ease' }}>

Motivation

Transitioning the height of an element using CSS alone is generally not sufficient. We need to use some Javascript to keep the height variable, so that it responds naturally to added content or a screen resize. This action relies on CSS to handle the transitions smoothly, and Javascript to manage the styles.

By wrapping the logic of this approach in an Action, the elements can be easily styled. Additionally, by maintaining the open state outside of the action, the user has complete control over the open/close mechanism.

The transitions are reversible, so that an open or close transition can be safely interrupted.

0.1.2

1 year ago

0.1.0

2 years ago

0.1.1

2 years ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago