All Projects โ†’ privatenumber โ†’ vue-pseudo-window

privatenumber / vue-pseudo-window

Licence: MIT License
๐Ÿ–ผ Declaratively interface window/document/body in your Vue template

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vue-pseudo-window

easydoc
EasyDoc, Easy to generate Documents. ๐ŸŒฑ EasyDoc๏ผŒ็ฎ€ๅ•ใ€ๅฟซ้€Ÿ็”Ÿๆˆๆ–‡ๆกฃ็š„ๅทฅๅ…ทใ€‚
Stars: โœญ 69 (+146.43%)
Mutual labels:  document
WinReform
A simple tool to help resize and relocate stubborn windows.
Stars: โœญ 20 (-28.57%)
Mutual labels:  window
dynamic-utils
Utility functions to perform dynamic operations on Android.
Stars: โœญ 86 (+207.14%)
Mutual labels:  window
incache
Powerful key/value in-memory storage or on disk to persist data
Stars: โœญ 16 (-42.86%)
Mutual labels:  window
recycler-adapter
RecyclerView-driven declarative UIs
Stars: โœญ 124 (+342.86%)
Mutual labels:  declarative
ReStory
A static site generator with MDX for React documentation.
Stars: โœญ 24 (-14.29%)
Mutual labels:  document
Helm
A graph-based SwiftUI router
Stars: โœญ 64 (+128.57%)
Mutual labels:  declarative
rugl
Declarative Stateless OpenGL in Rust
Stars: โœญ 39 (+39.29%)
Mutual labels:  declarative
phive
Generic business document validation engine
Stars: โœญ 17 (-39.29%)
Mutual labels:  document
FTerm.nvim
๐Ÿ”ฅ No-nonsense floating terminal plugin for neovim ๐Ÿ”ฅ
Stars: โœญ 353 (+1160.71%)
Mutual labels:  window
metagraf
metaGraf is a opinionated specification for describing a software component and what its requirements are from the runtime environment. The mg command, turns metaGraf specifications into Kubernetes resources, supporting CI, CD and GitOps software delivery.
Stars: โœญ 15 (-46.43%)
Mutual labels:  declarative
edd
Erlang Declarative Debugger
Stars: โœญ 20 (-28.57%)
Mutual labels:  declarative
semantic-document-relations
Implementation, trained models and result data for the paper "Pairwise Multi-Class Document Classification for Semantic Relations between Wikipedia Articles"
Stars: โœญ 21 (-25%)
Mutual labels:  document
craft-text-detector
Packaged, Pytorch-based, easy to use, cross-platform version of the CRAFT text detector
Stars: โœญ 151 (+439.29%)
Mutual labels:  document
scanbot-sdk-example-ionic
Scanbot scanner SDK example app for Ionic with Cordova.
Stars: โœญ 24 (-14.29%)
Mutual labels:  document
window-manager
A javascript-only Window Manager
Stars: โœญ 54 (+92.86%)
Mutual labels:  window
window-scroll-position
React hook for Window scroll position
Stars: โœญ 81 (+189.29%)
Mutual labels:  window
Tana
Bringing the Picture-in-Picture experience to the desktop.
Stars: โœญ 109 (+289.29%)
Mutual labels:  window
recurse
re<urse is a declarative language for generating musical patterns
Stars: โœญ 32 (+14.29%)
Mutual labels:  declarative
core
Declarative database schema definition
Stars: โœญ 31 (+10.71%)
Mutual labels:  declarative

๐Ÿ–ผ Pseudo Window

Vue component to bind event-handlers or classes to window/document/body!

Insert pseudo-window anywhere in your template:

<pseudo-window @resize.passive="handleResize" />

๐Ÿ‘‰ Try out a demo in this CodePen!

๐Ÿš€ Install

npm i vue-pseudo-window

๐Ÿ™‹โ€โ™‚๏ธ Why?

  • โœจ Cleaner code No longer pollute your component with .addEventListener() & .removeEventListener()
  • โ™ป๏ธ Template API Use Vue's @event syntax to bind listeners to the window as like you would to any other element
  • ๐Ÿ’ช Robust Supports all event modifiers capture, passive, and once. SSR friendly.
  • ๐Ÿฅ Tiny 819 B Gzipped!

Before

<template>
  ...
</template>

<script>
export default {

	// Your component would be polluted with event binding logic
	mounted() {
		window.addEventListener('resize', this.handleResize, { passive: true })
	},

	beforeDestroy() {
		window.removeEventListener('resize', this.handleResize)
	},

	methods: {
		handleResize() {
			...
		}
	}
}
</script>

After โœจ

<template>
	<div>
		...

		<!-- Insert pseudo-window anywhere in your template -->
		<pseudo-window @resize.passive="handleResize" />
	</div>
</template>

<script>
export default {

	// Much cleaner!
	methods: {
		handleResize() {
			...
		}
	}
}
</script>

๐Ÿ‘จโ€๐Ÿซ Demos JSFiddle Demo

Adding listeners to window
<template>
	<div>
		<div>
			Window width: {{ winWidth }}
		</div>

		<pseudo-window
			<!-- Handle window resize with "passive" option -->
			@resize.passive="onResize"
		/>
	</div>
</template>

<script>
import PseudoWindow from 'vue-pseudo-window';

export default {
	components: {
		PseudoWindow
	},
	
	data() {
		return {
			winWidth: 0
		}
	},

	methods: {
		onResize() {
			this.winWidth = window.innerWidth;
		}
	}
}
</script>
Adding class & listeners to document <html>
<template>
	<div>
		<pseudo-window
			document

			<!-- Add a class to <html> -->
			:class="$style.lockScroll"

			<!-- Handle document click -->
			@click="onClick"
		/>
	</div>
</template>

<script>
import PseudoWindow from 'vue-pseudo-window';

export default {
	components: {
		PseudoWindow
	},

	methods: {
		onClick() {
			console.log('Document click!')
		}
	}
}
</script>

<style module>
.lockScroll {
	overflow: hidden;
}
</style>
Adding class & listeners to body <body>
<template>
	<div>
		<pseudo-window
			body

			<!-- Add a class to <body> -->
			:class="$style.lockScroll"

			<!-- Handle body click -->
			@click="onClick"
		/>
	</div>
</template>

<script>
import PseudoWindow from 'vue-pseudo-window';

export default {
	components: {
		PseudoWindow
	},

	methods: {
		onClick() {
			console.log('Body click!')
		}
	}
}
</script>

<style module>
.lockScroll {
	overflow: hidden;
}
</style>
Only want one root element?

PseudoWindow is a functional component that returns exactly what's passed into it. By using it as the root component, its contents will pass-through.

<template>
	<pseudo-window
		@blur="pause"
		@focus="resume"
	>
		<video>
			<source
				src="/media/examples/flower.webm"
				type="video/webm"
			>
		</video>
	</div>
</template>

<script>
import PseudoWindow from 'vue-pseudo-window';

export default {
	components: {
		PseudoWindow
	},

	methods: {
		resume() {
			this.$el.play()
		},
		pause() {
			this.$el.pause()
		}
	}
}
</script>

๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Related

  • vue-subslot - ๐Ÿ’ Pick 'n choose what you want from a slot passed into your Vue component
  • vue-proxi - ๐Ÿ’  Tiny proxy component for Vue.js
  • vue-vnode-syringe - ๐ŸงฌMutate your vNodes with vNode Syringe ๐Ÿ’‰
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].