Giter Club home page Giter Club logo

vue-content-loader's Introduction

vue-content-loader

NPM version NPM downloads CircleCI

SVG component to create placeholder loading, like Facebook cards loading.

preview

Features

This is a Vue port for react-content-loader.

  • Completely customizable: you can change the colors, speed and sizes.
  • Create your own loading: use the online tool to create your custom loader easily.
  • You can use it right now: there are a lot of presets already.
  • Performance:
    • Tree-shakable and highly optimized bundle.
    • Pure SVG, so it's works without any javascript, canvas, etc.
    • Pure functional components.

Install

⚠️ The latest version is compatible with Vue 3 only. For Vue 2 & Nuxt 2, use vue-content-loader@^0.2 instead.

With npm:

npm i vue-content-loader

Or with yarn:

yarn add vue-content-loader

CDN: UNPKG | jsDelivr (available as window.contentLoaders)

Usage

👀👉 Demo: CodeSandbox

<template>
  <content-loader></content-loader>
</template>

<script>
import { ContentLoader } from 'vue-content-loader'

export default {
  components: {
    ContentLoader,
  },
}
</script>

Built-in loaders

import {
  ContentLoader,
  FacebookLoader,
  CodeLoader,
  BulletListLoader,
  InstagramLoader,
  ListLoader,
} from 'vue-content-loader'

ContentLoader is a meta loader while other loaders are just higher-order components of it. By default ContentLoader only displays a simple rectangle, here's how you can use it to create custom loaders:

<ContentLoader viewBox="0 0 250 110">
  <rect x="0" y="0" rx="3" ry="3" width="250" height="10" />
  <rect x="20" y="20" rx="3" ry="3" width="220" height="10" />
  <rect x="20" y="40" rx="3" ry="3" width="170" height="10" />
  <rect x="0" y="60" rx="3" ry="3" width="250" height="10" />
  <rect x="20" y="80" rx="3" ry="3" width="200" height="10" />
  <rect x="20" y="100" rx="3" ry="3" width="80" height="10" />
</ContentLoader>

This is also how ListLoader is created.

You can also use the online tool to create shapes for your custom loader.

API

Props

Prop Type Default Description
width number, string SVG width in pixels without unit
height number, string SVG height in pixels without unit
viewBox string '0 0 ${width ?? 400} ${height ?? 130}' See SVG viewBox attribute
preserveAspectRatio string 'xMidYMid meet' See SVG preserveAspectRatio attribute
speed number 2 Animation speed
primaryColor string '#f9f9f9' Background color
secondaryColor string '#ecebeb' Highlight color
uniqueKey string randomId() Unique ID, you need to make it consistent for SSR
animate boolean true
baseUrl string empty string Required if you're using <base url="/" /> in your <head />. Defaults to an empty string. This prop is common used as: <content-loader :base-url="$route.fullPath" /> which will fill the SVG attribute with the relative path. Related #14.
primaryOpacity number 1 Background opacity (0 = transparent, 1 = opaque) used to solve an issue in Safari
secondaryOpacity number 1 Background opacity (0 = transparent, 1 = opaque) used to solve an issue in Safari

Examples

Responsiveness

To create a responsive loader that will follow its parent container width, use only the viewBox attribute to set the ratio:

<ContentLoader viewBox="0 0 300 200">
  <!-- ... -->
</ContentLoader>

To create a loader with fixed dimensions, use width and height attributes:

<ContentLoader width="300" height="200">
  <!-- ... -->
</ContentLoader>

Note: the exact behavior might be different depending on the CSS you apply to SVG elements.

Credits

This is basically a Vue port for react-content-loader.

Thanks to @alidcastano for transferring the package name to me. 😘

License

MIT © EGOIST

vue-content-loader's People

Contributors

719media avatar dependabot-preview[bot] avatar dependabot[bot] avatar egoist avatar emilpriver avatar jacob-marshall avatar lafreefall avatar lebenleben avatar mldmoritz avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-content-loader's Issues

Is this project still alive

Hi,

I ask that painful question because pull requests are still pending, bugs from a few months have no reply...

Maybe you need some help maintaining this project or you don't use it anymore ?

BTW I don't see any active alternative in the Vue.js world so this project still seems to be the best choice 👍

Thanks for your efforts in creating this package, I hope you will reply to this ticket ;-)

"export 'createVNode, mergeProps, defineComponent' was not found in 'vue'

Getting these warnings on a project with Vue 2

 warning  in ./node_modules/vue-content-loader/dist/vue-content-loader.es.js

"export 'createVNode' was not found in 'vue'

 warning  in ./node_modules/vue-content-loader/dist/vue-content-loader.es.js

"export 'defineComponent' was not found in 'vue'

 warning  in ./node_modules/vue-content-loader/dist/vue-content-loader.es.js

"export 'mergeProps' was not found in 'vue'

They are just warnings not errors but still would be nice to not have them

Dynamically viewbox

When I want to dynamically change the value of the viewbox,

I find that the computedviewbox in the component contentloader maintains the original value,

resulting in failure to respond to the latest value

Component disappear during mount in nuxt

Hello,

thank you for the awesome work. I'm experiencing an issue using vue-content-loader with nuxt.
At the beginning server render the content, and then in mount it disappear.

If I trigger HMR component appear again.

Any ideas?

Thank you.

Nuxtjs Example

Hi,

Are you aware of any examples/demos for using vue-content-loader in a nuxt js project?

Best regards!

How to not responsive?

How to make loader not-responsive, and not follow to be big, when container get bigger

Custom paths can't be rendered

Hello,

I can't get this library to render custom paths with Vue 2.5. the clipPath is "undefined" in the HTML too, so I am not sure whats wrong.

Example used:

<content-loader
		:height="160"
		:width="400"
		:speed="2"
		primaryColor="#f3f3f3"
		secondaryColor="#ecebeb">
  <rect x="18.56" y="16.61" rx="0" ry="0" width="350.03" height="41" /> 
  <rect x="18.73" y="78.61" rx="0" ry="0" width="109.2" height="46" />
</content-loader>

if I inspect that, the clipPath is

<clipPath id="68y2z5o1l1d">undefined</clipPath>

Can you help?

Package name

Not sure whether @alidcastano 's vue-content-loader is in use or not.

Otherwise I'll move this package to @egoist/vue-content-loader when I get the npm handle (egoist).

The rect does not come out when using cdn

I try to use cdn ,but I found that it can't working at custom.
(rect just show first one , and primaryColor 、secondaryColor also not working)

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-content-loader.min.js"></script>

code:

<div id="app">
<template>
              <content-loader  primaryColor="#fff" secondaryColor="#000">
                <rect x="70" y="15" rx="4" ry="4" width="117" height="6.4" />
                <rect x="70" y="35" rx="3" ry="3" width="85" height="6.4" />
                <rect x="0" y="80" rx="3" ry="3" width="350" height="6.4" />
                <rect x="0" y="100" rx="3" ry="3" width="380" height="6.4" />
                <rect x="0" y="120" rx="3" ry="3" width="201" height="6.4" />
                <circle cx="30" cy="30" r="30" />
              </content-loader>
            </template>
</div>
<script>
  new Vue({
    el: '#app',
    data () {
      return {
        list: [],
        tags:[]
      }
    },
    components: { 
        'content-loader': window.contentLoaders.ContentLoader
      }
  })
</script>

but the result :
(rect just show first one , and primaryColor 、secondaryColor also not working)
螢幕快照 2020-10-24 下午8 32 19

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • @babel/core 7.18.5
  • @babel/preset-env 7.18.2
  • @types/poi 12.5.5
  • @vue/babel-plugin-jsx 1.1.1
  • @vue/compiler-sfc 3.2.37
  • @vue/test-utils 2.0.1
  • babel-jest 27.5.1
  • bili 5.0.5
  • jest 27.5.1
  • poi 12.10.3
  • prettier 2.7.1
  • regenerator-runtime 0.13.9
  • rollup-plugin-typescript2 0.32.1
  • typescript 4.7.4
  • vue 3.2.37
  • vue-loader 17.0.0
  • vue-router 4.0.16
  • vue ^3

  • Check this box to trigger a request for Renovate to run again on this repository

content-loader not displayed immediately when in production

before introducing content-loader I just had a loading spinner that would appear immediately upon arriving on a certain page

after replacing the loading spinner with content-loader, there is a lag for the content-loader to appear. are there known causes to this?

this problem appears only in production, but not when I am running my development server.

Responsive

Issuehunt badges

My content's width depend on the screen size, is it possible to create content loaders with a dynamic width for responsiveness purposes ?

The width and height properties seems to accept only numbers.


IssueHunt Summary

Backers (Total: $100.00)

Submitted pull Requests


Become a backer now!

Or submit a pull request to get the deposits!

Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Seems to show a black box instead on an iPhone6

Issuehunt badges

Hello, thank you for this beauty.
The content loader works exactly as expected across different devices on production but displays a black rectangular box on my iphone 6 instead, does anyone have such experience please?
file


IssueHunt Summary

mldmoritz mldmoritz has been rewarded.

Sponsors (Total: $100.00)

Tips

Render after mounted

Only render the component after mounted (so it only renders on client-side) will make it easier for SSR, my question is: do we need to render the component on server-side at all?

Uncaught TypeError: this.$slots.default is not a function

Hi, I cant run loader with this configuration with custom loaders in slot.

"@vue/compat": "^3.1.5",
"@vue/compiler-sfc": "^3.1.5",
"@vue/composition-api": "^1.4.7",
"vue-content-loader": "^2.0.1",
"vue": "^3.1.5",
<content-loader v-if="visible" :speed="speed" :width="width" :height="height" primaryColor="#ced4da">
    <rect rx="3" ry="3" height="199" width="123" y="0" x="0"></rect>
</content-loader>

This fails with error: Uncaught TypeError: this.$slots.default is not a function

Wrong height

The height of the rendered component is higher than the height set with :height="200"

Seems to show a black color an iPhone8 plus

<ContentLoader :height="960" :width="700" >
This is the code causing the problem.
But i fix it by
<ContentLoader :height="960" :width="701" >
Then,it looks like normal.
why?I think it is a bug.
tmp7cfe04ab

Add option to control roundness of square blocks

Some designs require square corners for loaders, but currently there is no way to do that with this component. Currently, ry and rx values in svg are hard-coded.

Could we have control over this value (either by two params or by one, controlling both values)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.