Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svelte-movable

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-movable

Action to move node on mousedown

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Svelte Action - use:movable

npm.badge bundlephobia.badge github.release.badge semantic-release.badge MIT

github.actions.release.badge

Table of Contents

Show / hide

Changelog

Usage

Example: show / hide

While mousedown of the trigger button element

  • mousemove will trigger div to move accordingly; a CustomEvent movablestartis dispatched,
  • movement will be limited to the border of the containerNode, plus and minus 20% of the width & height of the div that the action is being used on,
  • mouseup will stop the movement; a CustomEvent movableend is dispatched.
<script lang="ts">
  import arrows from 'svelte-awesome/icons/arrows';
  import Icon from 'svelte-awesome/components/Icon.svelte';

  let modal = false;
  let triggerNode: HTMLElement;
</script>

<container>
  <!-- ... some other content ... -->

  {#if modal}
    <div
      transition:fade={{ duration: 200 }}
      class="absolute top-1/2 left-1/2 -translate-y-1/2 -translate-x-1/2 w-full max-w-sm"
      use:movable={{
        limit: {
          delta: '20%',
          parent: containerNode,
        },
        trigger: triggerNode,
      }}
      on:movablestart={(node) => console.log('movable:start', node)}
      on:movableend={(node) => console.log('movable:end', node)}
    >
      <button
        bind:this={triggerNode}
        class="c-btn-icon absolute top-2 right-10 hover:cursor-move"
      >
        <Icon data={arrows} />
      </button>

      <!-- ... some other modal content ... -->
    </div>
{/if}

</container>

Documentation

Typescript support

app.d.ts: show / hide
/// <reference types="@sveltejs/kit" />
/// <reference types="svelte" />

// Typescript support in svelte-kit, see
// https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-using-an-attributeevent-on-a-dom-element-and-it-throws-a-type-error

declare namespace svelte.JSX {
  interface HTMLAttributes<T> {
    // on:movablestart
    onmovablestart?: (event: CustomEvent<HTMLElement>) => void;
    // on:movableend
    onmovableend?: (event: CustomEvent<HTMLElement>) => void;
  }
}

For detailed documentation, see the extracted API.

Quick access to the parameter interface accepted by the action: MovableParameters.

Note: action accepts Partial<MovableParameters>. By default you don't need to provide any option.

Contributing

Read Contribution Guide

Todos

  • separate helper methods & implement unit tests

  • add field test for svelte kit (integration)

  • CI workflow (github action)

buy vnphanquang a coffee

Keywords

FAQs

Package last updated on 08 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc