Small library to accomplish common tasks in Svelte/SvelteKit

Overview

svelte-utilities

svelte-utilities is a small utilities library for Svelte/SvelteKit that provides features I use in almost every project, such as:

  • Lazy loading images
  • Outclick event handling
  • Intersection observers
  • Entry animations
  • Copy text onClick

Installation

npm i @benten28/svelte-utilities

Usage

//npm
import { animateIn, intersectionObserver, lazyLoad, outClick, copyOnClick } from '@benten28/svelte-utilities'

// animate in (margin refers to bottom margin)
<div use:animateIn={{delay: 250, duration: 500, margin: '100px'}}>Hello World!</div>

// intersection observer
<div 
use:intersectionObserver={{marginTop: '100px', marginBottom: '100px', threshold: 0}}
on:inView={()=>console.log('entering viewport')}
on:outView={()=>console.log('exiting viewport')}>
Hello World!
</div>

// lazyLoad
//(src is optional in image tag, can use css background or something else as a placeholder)
// set transition-opacity CSS property to animate image load
<img use:lazyLoad={'/image.jpg'} src='/placeholder.jpg'>

// out click 
<div use:outClick on:outClick={()=>console.log('clicked outside!')}>Hello World!</div>

//copy on click
<div use:copyOnClick>This text will be copied when the user clicks the div</div>
//or
<div bind:this={content}>Text to be copied</div>
<button use:copyOnClick={content}>Copy Text</div>

Contributing

If you have a utility you'd like to add feel free to make a pull request. Please open an issue first to discuss what you would like to add and how you'd implement it.

License

MIT

You might also like...

Vite Svelte plugin to remove console logs in prod.

vite-plugin-svelte-console-remover A Vite plugin that removes all console statements (log, group, dir, error, etc) from Svelte, JS, and TS files durin

Oct 13, 2022

A small utility for managing an undo stack

svelte-undo A small utility for managing an undo stack, that you can subscribe to in your Svelte applications (or indeed anywhere else). Demo here. Us

Dec 21, 2022

🌊 A flexible and fun JavaScript file upload library

🌊 A flexible and fun JavaScript file upload library

A JavaScript library that can upload anything you throw at it, optimizes images for faster uploads, and offers a great, accessible, silky smooth user

Jan 7, 2023

🎉 A Vue.js 3.0 UI Library made by Element team

🎉 A Vue.js 3.0 UI Library made by Element team

Element Plus - A Vue.js 3.0 UI library đŸ’Ē Vue 3.0 Composition API đŸ”Ĩ Written in TypeScript Status: Beta This project is still under heavy development.

Jan 9, 2023

A lightweight Vue.js UI library with a simple API, inspired by Google's Material Design.

Keen UI Keen UI is a Vue.js UI library with a simple API, inspired by Google's Material Design. Keen UI is not a CSS framework. Therefore, it doesn't

Jan 2, 2023

JavaScript Survey and Form Library

JavaScript Survey and Form Library

SurveyJS is a JavaScript Survey and Form Library. SurveyJS is a modern way to add surveys and forms to your website. It has versions for Angular, jQue

Jan 5, 2023

The first truly composable CSS animation library. Built for Vue, React, SCSS, and CSS, AnimXYZ will bring your website to life.

AnimXYZ animxyz.com AnimXYZ helps you create, customize, and compose animations for your website. Powered by CSS variables to allow a nearly limitless

Jan 2, 2023

Jenesius vue modal is simple library for Vue 3 only

Jenesius Vue Modal Jenesius vue modal is simple library for Vue 3 only . Site Documentation Installation npm i jenesius-vue-modal For add modals in yo

Dec 30, 2022

Mosha-vue-toastify - A light weight and fun Vue 3 toast or notification or snack bar or however you wanna call it library.

Mosha-vue-toastify - A light weight and fun Vue 3 toast or notification or snack bar or however you wanna call it library.

Mosha Vue Toastify A lightweight and fun Vue 3 toast or notification or snack bar or however you wanna call it library. English | įŽ€äŊ“中文 Talk is cheap,

Jan 2, 2023
Owner
null
Automatically configure Vitest from your SvelteKit configuration.

vitest-svelte-kit Automatically configure Vitest from your SvelteKit configuration. Getting Started Installing In an existing SvelteKit project, run t

Nick Breaton 44 Dec 30, 2022
Adapter for SvelteKit apps that prerenders your site as a collection of static files for GitHub Pages

svelte-adapter-github Adapter for SvelteKit apps that prerenders your site as a collection of static files for GitHub Pages. Usage Install with npm i

null 36 Sep 20, 2022
📓 The UI component explorer. Develop, document, & test React, Vue, Angular, Web Components, Ember, Svelte & more!

Build bulletproof UI components faster Storybook is a development environment for UI components. It allows you to browse a component library, view the

Storybook 75.9k Jan 9, 2023
NativeScript empowers you to access native api's from JavaScript directly. Angular, Vue, Svelte, React and you name it compatible.

NativeScript empowers you to access native APIs from JavaScript directly. The framework currently provides iOS and Android runtimes for rich mobile de

NativeScript 22k Jan 4, 2023
Matteo Bruni 4.7k Jan 4, 2023
A template to use GoLang Lorca package to make desktop applications using webview and Svelte for the frontend,

Svelte Lorca Template A starter project for building modern cross-platform desktop apps in Go, HTML, and Svelte. This project is a fork of lorca-ts-re

Ben Winchester 16 Jun 19, 2022
bare bones demo of svelte-three

create-svelte Everything you need to build a Svelte project, powered by create-svelte; Creating a project If you're seeing this, you've probably alrea

Rich Harris 39 Jul 30, 2022
A svelte action for creating tippy.js tooltips with full typescript support

Tippy.js for svelte A svelte action for creating tippy.js tooltips. Getting started # Pnpm pnpm add svelte-tippy tippy.js # Yarn yarn add svelte-tipp

Brett Mandler 11 Jul 19, 2022
Time-traveling debugger for Svelte applications

DeLorean The first time-travelling debugger for Svelte applciations DeLorean is a debugging tool for Svelte developers. It records snapshots when a ta

OSLabs Beta 60 Oct 8, 2022
Add Routify to your Svelte project

?? Add (work in progress) Routify to Svelte This is an adder for svelte-add; you should read its README before continuing here. ➕ Adding (work in prog

Svelte Add 5 Aug 3, 2022