The BottomSheet component is a sleek, interactive UI element for mobile-first and desktop applications. It provides a smooth and customizable sliding sheet that can be triggered from the bottom of the screen. Whether you're building a mobile app or a responsive web app, the BottomSheet component offers an intuitive and engaging way to display additional content or options.
onopen
and onclose
to track user interactions.You can use the BottomSheet component in any SvelteKit project.
Install the Component
If you're starting from scratch, create a SvelteKit project:
npx sv create my-app
cd my-app
NPM Install the Bottom Sheet
npm i svelte-bottom-sheet
Import the component
<script lang="ts">
import BottomSheet from 'svelte-bottom-sheet';
let isOpen = $state(false);
</script>
<button onclick={() => (isOpen = true)}>Open Bottom Sheet</button>
<BottomSheet bind:isOpen={isOpen} settings={{maxHeight: '70%'}}>
<BottomSheet.Overlay>
<BottomSheet.Sheet>
<BottomSheet.Content>
<h3>Content inside the bottom sheet</h3>
<p>Here you can put any content you need.</p>
</BottomSheet.Content>
</BottomSheet.Sheet>
</BottomSheet.Overlay>
</BottomSheet>
Property | Type | Default | Description |
---|---|---|---|
isOpen |
boolean |
false |
Determines whether the bottom sheet is visible. BINDABLE (bind:isOpen) |
settings |
BottomSheetSettings |
default |
Settings for the BottomSheet. |
Name | Type | Description | Default Value |
---|---|---|---|
maxHeight |
string |
Sets the maximum height of the Bottom Sheet. The value should be in percentage (90% ). |
70% |
snapPoints |
number[] |
An array of snap points for the Bottom Sheet. Each value represents a height at which the sheet can stop during the transition. Values in percentage points. ([25, 50, 75] ) |
[] |
closePercentage |
number |
The percentage of the Bottom Sheet's height that the user must drag for it to close, measured in percentage points. | 10 |
Event | Description |
---|---|
onopen() |
Fires when the Bottom Sheet opens. |
onclose() |
Fires when the Bottom Sheet closes. |
There is a lot of stuff you can use inside BottomSheet
which will be explained after the example usage.
<script lang="ts">
let isSheetOpen = $state(false);
<script>
<BottomSheet bind:isOpen={isSheetOpen}>
<BottomSheet.Trigger>
<p>Click to open the sheet.</p>
</BottomSheet.Trigger>
<BottomSheet.Overlay>
<BottomSheet.Sheet>
<BottomSheet.Content>
<h3>Bottom Sheet Title</h3>
<p>Text</p>
</BottomSheet.Content>
</BottomSheet.Sheet>
</BottomSheet.Overlay>
</BottomSheet>
Binding the isOpen
Property:
The isOpen
property is bound to a variable (here, isEventsSheetOpen
) to track whether the bottom sheet is open or closed. You can control the sheet’s state programmatically by modifying the bound variable.
Example:
let isEventsSheetOpen = $state(false);
Trigger Area:
The BottomSheet.Trigger
component defines the area that opens / closes the bottom sheet when clicked. You can style it and use any content inside the trigger.
Example:
<BottomSheet.Trigger>Trigger</BottomSheet.Trigger>
Handling Open/Close Events:
You can listen to onopen
and onclose
events to trigger custom logic when the sheet is opened or closed. This is useful for tracking interactions or performing other actions.
Example:
<BottomSheet
onopen={() => logEvent('Bottom Sheet opened.')}
onclose={() => logEvent('Bottom Sheet closed.')}
>
...
</BottomSheet>
Overlay & Content:
If you want to add a Overlay, you can do that by wrapping the BottomSheet.Sheet
with BottomSheet.Overlay
. You can style the overlay using the style
property.
You can use BottomSheet.Content
inside BottomSheet.Sheet
to display content. It's optional, but you are able to style it.
Customizing the Sheet:
The content inside the BottomSheet.Sheet
component is fully customizable. You can add everything (really everything).
Notes on Trigger and isOpen
:
You can both use the Trigger Area
and the isOpen State
for opening and closing the sheet. Depends on your preferences.
Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request on the GitHub repository.
This project is licensed under the MIT License. See the LICENSE file for more details.