All Projects â†’ ktsn â†’ vue-size-provider

ktsn / vue-size-provider

Licence: MIT license
Declarative element size observer and provider

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects

Projects that are alternatives of or similar to vue-size-provider

Iconhandler
Tint you Icons, change the size, apply alpha color and set a position easily. 👓
Stars: ✭ 59 (+7.27%)
Mutual labels:  resize, size
Use Resize Observer
A React hook that allows you to use a ResizeObserver to measure an element's size.
Stars: ✭ 305 (+454.55%)
Mutual labels:  resize, size
dclareForMPS
Adding declarative, reactive and incremental rules to MPS
Stars: ✭ 21 (-61.82%)
Mutual labels:  declarative
zerocode-hello-world
Zerocode YAML and JSON based declarative steps hello world rest api testing example - soap, database
Stars: ✭ 18 (-67.27%)
Mutual labels:  declarative
react-nonav
Experimental React Native declarative navigation
Stars: ✭ 58 (+5.45%)
Mutual labels:  declarative
react-mops
🐶 Modify Orientation Position Size
Stars: ✭ 40 (-27.27%)
Mutual labels:  size
sugar
Declarative HTTP client for Golang
Stars: ✭ 25 (-54.55%)
Mutual labels:  declarative
react-is-scrolling
Simply detect if users are scrolling in your components in a declarative API
Stars: ✭ 17 (-69.09%)
Mutual labels:  declarative
swift-declarative-configuration
Declarative configuration for your objects
Stars: ✭ 46 (-16.36%)
Mutual labels:  declarative
vuo
A realtime visual programming language for interactive media.
Stars: ✭ 103 (+87.27%)
Mutual labels:  declarative
FeedbackTree
Unidirectional data flow architecture for Android
Stars: ✭ 14 (-74.55%)
Mutual labels:  declarative
ipx
High performance, secure and easy to use image proxy based on Sharp and libvips.
Stars: ✭ 683 (+1141.82%)
Mutual labels:  resize
Core
The contents of this repository have been integrated into https://github.com/SixLabors/ImageSharp
Stars: ✭ 26 (-52.73%)
Mutual labels:  size
bem-react-boilerplate
DEPRECATED! A bare minimum frontend boilerplate based on create-react-app and bem-react-core.
Stars: ✭ 32 (-41.82%)
Mutual labels:  declarative
node-disk-utility
Quickly calculate the size of a folder or disk on macOS and Linux
Stars: ✭ 28 (-49.09%)
Mutual labels:  size
pdf-thumbnail
npm package to create the preview of a pdf file
Stars: ✭ 23 (-58.18%)
Mutual labels:  resize
angular-inviewport
A simple lightweight library for Angular with no other dependencies that detects when an element is within the browser viewport and adds a "sn-viewport-in" or "sn-viewport-out" class to the element
Stars: ✭ 72 (+30.91%)
Mutual labels:  resize
MoleculeJS
A library for creating fast and reactive Custom Elements
Stars: ✭ 39 (-29.09%)
Mutual labels:  declarative
jsx-compress-loader
⚛JSX optimisation loader to reduce size of React application
Stars: ✭ 40 (-27.27%)
Mutual labels:  size
ObservableComputations
Cross-platform .NET library for computations whose arguments and results are objects that implement INotifyPropertyChanged and INotifyCollectionChanged (ObservableCollection) interfaces.
Stars: ✭ 94 (+70.91%)
Mutual labels:  declarative

vue-size-provider

Declarative element size observer and provider.

Motivation

Sometimes you may want to animate an element height when its content is changed. In that case, you need to directly read height value from DOM because Virtual DOM cannot acquire element size. Since it is low-level manipulation, the code would become messier.

vue-size-provider solves this problem by hiding low-level code with abstract helper components - <SizeProvider> and <SizeObserver>. The following gif is an example to show how vue-size-provider works:

Simple demo of vue-size-provider

Install

Install it via npm:

$ npm install vue-size-provider

Then, notify Vue to use it:

import Vue from 'vue'
import VueSizeProvider from 'vue-size-provider'

Vue.use(VueSizeProvider)

Or you can directly use the components:

<script>
import { SizeProvider, SizeObserver } from 'vue-size-provider'

export default {
  components: {
    SizeProvider,
    SizeObserver
  }
}
</script>

Usage

First, wrap elements that you would like to observe their size by <SizeObserver>.

<template>
  <!-- observe content size -->
  <SizeObserver>

    <!-- arbitrary contents that you want to observe their size -->

  </SizeObserver>
</template>

<script>
import { SizeProvider, SizeObserver } from 'vue-size-provider'

export default {
  components: {
    SizeProvider,
    SizeObserver
  }
}
</script>

Then, wrap them by <SizeProvider> and any element that you want to animate its size when the contents size is changed.

<template>
  <!-- provide observed content size via scoped slot -->
  <SizeProvider v-slot="{ width, height }">
    <div class="wrapper" :style="{ height: height + 'px' }">

      <!-- observe content size -->
      <SizeObserver>

        <!-- arbitrary contents that you want to observe their size -->

      </SizeObserver>

    </div>
  </SizeProvider>
</template>

<script>
import { SizeProvider, SizeObserver } from 'vue-size-provider'

export default {
  components: {
    SizeProvider,
    SizeObserver
  }
}
</script>

Finally, you need to write some animation code. In this example, we simply use CSS transition:

<template>
  <!-- provide observed content size via scoped slot -->
  <SizeProvider v-slot="{ width, height }">
    <div class="wrapper" :style="{ height: height + 'px' }">

      <!-- observe content size -->
      <SizeObserver>

        <!-- arbitrary contents that you want to observe their size -->

      </SizeObserver>

    </div>
  </SizeProvider>
</template>

<script>
import { SizeProvider, SizeObserver } from 'vue-size-provider'

export default {
  components: {
    SizeProvider,
    SizeObserver
  }
}
</script>

<style scoped>
.wrapper {
  box-sizing: content-box;
  border: 1px solid #000;
  
  /* animate content height smoothly */
  transition: height 300ms ease-out;
}
</style>

Note that you may want to specify box-sizing: content-box; to the animating element because the provided width and height are content size of the observed element. i.e. They do not include padding and border size.

License

MIT

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].