• Stars
    star
    201
  • Rank 194,491 (Top 4 %)
  • Language
    JavaScript
  • Created over 6 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create responsive components with ResizeObserver

vue-responsive-components

Create responsive components with ResizeObserver.

Idea

Check out my post on ITNEXT

Installation

npm install vue-responsive-components

(Optional) Add plugin globally

import Vue from "vue"
import { VueResponsiveComponents } from "vue-responsive-components"

Vue.use(VueResponsiveComponents)

It will add Responsive component and v-responsive directive

Usage

Responsive component with scoped slot

<template>
  <Responsive :breakpoints="{
    small: el => el.width <= 500
  }">
    <div slot-scope="el" :class="['post__item', { small: el.is.small }]">
      <img class="post__image" :src="post.image" />
      <div class="post__text">{{post.text}}</div>
    </div>
  </Responsive>
</template>

<script>
import { Responsive } from "vue-responsive-components"

export default {
  props: ["post"],
  components: { Responsive }
}
</script>

<style>
.post__item {
  display: flex;
}

.post__image {
  flex: 0 0 200px;
  height: 200px;
}

.post__item.small {
  flex-direction: column;
}

.post__item.small .post__image {
  flex: 0 auto;
  height: auto;
}
</style>

v-responsive directive

Thanks to this guy for idea

<template>
  <!-- Will add/remove .small if the width is less / greater -->
  <div class="post__item" v-responsive="{ small: el => el.width <= 500 }">
    <img class="post__image" :src="post.image" />
    <div class="post__text">{{post.text}}</div>
  </div>
</template>

<script>
import { ResponsiveDirective } from "vue-responsive-components"

export default {
  props: ["post"],
  directives: {
    responsive: ResponsiveDirective
  }
}
</script>

Mixin

<template>
  <div :class="['post__item', { small: el.is.small }]">
    <img class="post__image" :src="post.image" />
    <div class="post__text">{{post.text}}</div>
  </div>
</template>

<script>
import { ResponsiveMixin } from "vue-responsive-components"

export default {
  props: ["post"],
  mixins: [ResponsiveMixin],
  breakpoints: {
    small: el => el.width <= 500
  }
}
</script>

License

MIT

More Repositories

1

vue-timers

Mixin to manage your intervals in Vue.js
JavaScript
232
star
2

nanoclone

Tiny util to deep clone JavaScript objects
JavaScript
73
star
3

vuelidate-forms

Use one schema to create a data and Vuelidate validations object
JavaScript
57
star
4

effector-factorio

The simplest way to write re-usable features with React + Effector
TypeScript
48
star
5

effector-hotkey

Hotkeys with Effector made easy
TypeScript
35
star
6

nanoutils

Tiniest JavaScript utils library
JavaScript
27
star
7

nanotween

Extremely small tweening library
JavaScript
27
star
8

react-render-time

React hook to check how much doest it take to render component
JavaScript
26
star
9

effector-history

Utility library that implements undo/redo feature for you
TypeScript
24
star
10

composable-forms

Flexible and composable forms on top of Effector!
TypeScript
14
star
11

effector-routing

Simple abstact router on top of Effector. Also has React bindings and DOM adapter
JavaScript
12
star
12

fixgpt

AI-based CLI tool for code generation and mass refactoring
JavaScript
10
star
13

effector-utils

Effector utilities library
JavaScript
8
star
14

Tree.php

Simple class to work with multidimensional Arrays in PHP
PHP
6
star
15

astroverse

State-management based on structures
JavaScript
4
star
16

kelin2025tv-client

Client for kelin2025.tv
TypeScript
4
star
17

vue-data-stash

Save component data for rainy day
JavaScript
4
star
18

ws-json-client

Simple WS JSON client
JavaScript
3
star
19

effector-pagination

TypeScript
3
star
20

vue-sync-props

Sync your Vue props and data with just a single flag
JavaScript
2
star
21

delightful-bus

JavaScript
2
star
22

react-effector-feature-slices-template

Template for React + Effector + Feature Slices structure
TypeScript
2
star
23

morphling

Morphing animations with ease
TypeScript
2
star
24

slax

Stop creating files/folders in your projects manually
JavaScript
2
star
25

async-nocatch

No need to use try/catch to handle your async/await functions
JavaScript
2
star
26

publish-cleaner

Cleanup your npm package for publish
JavaScript
2
star
27

x-lines

Crop your text to fit it into X lines
JavaScript
1
star
28

vue-bus-park

Create and work with a park of event buses
JavaScript
1
star
29

dom-effects

TypeScript
1
star
30

kelin2025-me

TypeScript
1
star
31

schematic-fluent

Easily create fluent interfaces
JavaScript
1
star