Coder Social home page Coder Social logo

nimo9367 / svelte-copy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ghostdevv/svelte-copy

0.0 0.0 0.0 268 KB

A svelte action to copy text on click!

Home Page: svelte-copy.vercel.app

License: Other

JavaScript 12.02% TypeScript 57.82% HTML 7.19% Svelte 22.97%

svelte-copy's Introduction

Svelte Copy

Ever wanted to copy something to clipboard? Say hello to Svelte Copy โœจ

Demo

Installing

npm install svelte-copy -D

Using

Let's make a button that when you click it copies Hello World to the clipboard:

<script>
    import { copy } from 'svelte-copy';
</script>

<button use:copy={'Hello World'}>
    Click me!
</button>

Events

There are some custom events you can use on elements that have the copy action:

  • on:svelte-copy This will fire when text is copied, you have access to the copied text if needed with event.detail:

    <button
        use:copy={'Hello from alert'}
        on:svelte-copy={(event) => alert(event.detail)}>
        Click to cause alert on copy
    </button>
  • on:svelte-copy:error This event will fire if there is an error in copying to clipboard, you have access to the error with event.detail:

    <button
        use:copy={'Some text'}
        on:svelte-copy:error="{(event) =>
            alert(`There was an error: ${event.detail.message}`)}">
        Click to cause alert on copy
    </button>

Custom Triggers

By default, copy action is fired on click event. You can change this behavior by passing an object with the name or names of the events that you want to trigger the copy action.

<button
    use:copy={{ text: 'Hello' , events: ['touchstart', 'mouseenter']}}
    on:svelte-copy={(event) => alert(event.detail)}>
    Move cursor over button or touch button to cause alert on copy
</button>

Support

svelte-copy's People

Contributors

dependabot[bot] avatar ghostdevv avatar kilicbaran avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.