0.0.2 • Published 6 months ago

@svelte-bin/clickoutside v0.0.2

Weekly downloads
-
License
-
Repository
-
Last release
6 months ago

@svelte-bin/clickoutside

With the clickoutside action, a callback function will be fired whenever the user clicks outside of the DOM node the action is applied to.

Installation

npm  i @svelte-bin/clickoutside

Usage

<script>
	import { clickoutside } from '@svelte-bin/clickoutside';
	let enabled = false;
</script>

<div
	use:clickoutside={{
		enabled,
		callback: () => {
			alert('outside clicked');
		}
	}}
>
	<button type="button" on:click={() => (enabled = !enabled)}>
		Click Outside: {enabled ? 'on' : 'off'}
	</button>
	<div>Click outside</div>
</div>

Params

ParamDescription
enabledSets the action to an enabled state if true, if false, action will not trigger
callbackThe callback to be fired once the user clicks outside of the DOM node

Definition

import type { Action } from 'svelte/action';

export interface ClickOutSideConfig {
	enabled: boolean;
	callback: (any) => unknown;
}

export interface ClickOutSideAttribute {}
export type clickoutsideAction = Action<HTMLElement, ClickOutSideConfig, ClickOutSideAttribute>;
0.0.2

6 months ago

0.0.1

6 months ago