A Svelte library that provides an animated card component that expands to fill a target container when clicked, revealing additional details with a smooth transition.
npm install svelte-expanding-card
<script>
import { Card, ExpandedCardTarget } from 'svelte-expanding-card';
</script>
<ExpandedCardTarget>
<Card jsStyle={{ height: "300px", borderRadius: "1vh" }}>
<div slot="card">
<!-- Your card content here -->
</div>
<div slot="details">
<!-- Your expanded details content here -->
</div>
</Card>
</ExpandedCardTarget>
The main card component that handles the expansion animation and content display.
jsStyle
(object):height
(string, optional): Card heightborderRadius
(string, default: "1vh"): Border radius of the cardeasing
(string, default: "quintOut"): Svelte easing function namecard
: Content displayed in the collapsed card viewdetails
: Content displayed in the expanded viewContainer component that defines the expansion target area and handles layout management.
classes
(string, default: ""): Additional CSS classesstyle
(string, default: ""): Inline styles for the container<script>
import { Card, ExpandedCardTarget } from 'svelte-expanding-card';
</script>
<ExpandedCardTarget style="display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem;">
<Card jsStyle={{ height: "300px" }}>
<div slot="card">
<h3>Card Title</h3>
<p>Preview content</p>
</div>
<div slot="details">
<h2>Detailed View</h2>
<p>Extended content that appears when expanded</p>
</div>
</Card>
<!-- Add more cards as needed -->
</ExpandedCardTarget>
The ExpandedCardTarget
component automatically handles flex layouts, ensuring:
The expansion animation can be customized through the jsStyle
prop:
<Card jsStyle={{
height: "300px",
borderRadius: "2vh",
easing: "elasticOut"
}}>
Available easing functions include all standard Svelte easing functions (linear, quad, cubic, etc.).
The component automatically recalculates positions and sizes when:
The component provides several CSS classes for customization (they must be targeted with the :global keyword) in your .svelte
file:
<style>
/* Card styles */
:global(.expanding-card) {
/* Your custom styles */
}
/* Expanded view styles */
:global(.expanding-card .details) {
/* Your custom styles */
}
/* Close button styles */
:glboal(.expanding-card) {
/* Your custom styles */
}
</style>
MIT