0.0.5 • Published 5 years ago

aurelia-content-loader v0.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Aurelia Content Loader

Npm Version HitCount Contributions welcome

TravisCI CircleCI

Donate to this project using Patreon

SVG-Powered component to easily create placeholder loadings (like Facebook's cards loading).

Index

Getting Started

npm i aurelia-content-loader --save

or

yarn add aurelia-content-loader

Usage

In your aurelia main.js add:

aurelia.use.plugin(PLATFORM.moduleName('aurelia-content-loader'));

Options

OptionTypeDefaultDescription
animateBooleanfalseOptional. Activate animations with true, 1, any.
animate-durationString1sOptional. Change to any time value. i.e. 10s.
css-classStringOptional. Additional CSS classes to add on the main container of the component.
css-class-innerStringOptional. Additional CSS classes to add on the inner container of the component.
heightNumber110Optional. Represents the max height of the <svg />.
image-radiusNumber30Optional. Radius of the main image (see Facebook or Instagram components) - does not matter if the image is a square. If square, image width/height will be the diameter (2 * radius).
image-as-circleBooleanfalseOptional. Activate circle image with true, 1, any.
line-heightNumber7Optional. Used for components like (Facebook, List and Code), represents the height of the lines representing texts. Can be changed to any number.
line-max-numberNumber5Optional. Used for components like (Facebook, List and Code), represents the maximum number of rendered text lines. If given a very large number, the text lines will fill all the available space according to svg height.
line-paddingNumber5Optional. Used for components like (Facebook, List and Code), represents the top/bottom padding of the lines representing texts. Can be changed to any number.
line-width-randomizeBooleanfalseOptional. Used for components like (Facebook, List), allows 'text' lines to have random widths.
widthNumber320Optional. Represents the max width of the <svg />.
svg-directionNumberltrOptional. Defines the orientation of the <svg />. Can be changed to rtl.
svg-preserve-aspect-ratioStringnoneOptional. Defaults to none. Read more in the preserveAspectRatio attribute documentation.

Examples

Facebook Component

<svg-facebook-loader
  animate="1"
  corner-radius="3"
  image-as-circle="1"
></svg-facebook-loader>

Instagram Component

<svg-instagram-loader
  animate="1"
  height="220"
  corner-radius="3"
  image-as-circle="1"
></svg-instagram-loader>

Code Component

<svg-code-loader
  animate="1"
></svg-code-loader>

Additional Options

OptionTypeDefaultDescription
max-code-cuhnksNumber5Optional. Number of chunks in a line.

List Component

<svg-list-loader
  animate="1"
  corner-radius="3"
></svg-list-loader>

Additional Options

OptionTypeDefaultDescription
bulletsBooleanfalseOptional. Activate bullets with true, 1, any.
bullets-as-squaresBooleanfalseOptional. Activate rendering bullets as squares with true, 1, any.
bullet-radiusNumber5Optional. Set the radius of the list's bullets.

Bullet list Style

<svg-list-loader
  animate="1"
  bullets="1"
  bullets-as-squares="1"
></svg-list-loader>

Custom Component

<svg-content-loader
  animate="1"
>
  <rect x="0" y="0" rx="3" ry="3" width="60" height="60"></rect>

  <rect x="70" y="15" rx="3" ry="3" width="250" height="7"></rect>
  <rect x="70" y="37" rx="3" ry="3" width="200" height="7"></rect>

  <rect x="0" y="75" rx="3" ry="3" width="320" height="7"></rect>
  <rect x="0" y="92" rx="3" ry="3" width="320" height="7"></rect>
</svg-content-loader>

Extending component

Javascript Class

Let's say ./resources/elements/custom-loader.js.

import { bindable, containerless, customElement, inlineView } from 'aurelia-templating';

import { SvgContentLoader } from 'aurelia-content-loader/content-loader';
import { template } from 'aurelia-content-loader/template';

/** @var {String} */
const divTemplate = '';

/** @var {String} */
const svgTemplate = `<rect x="0" y="0" rx="3" ry="3" width="60" height="60"></rect>

<rect x="70" y="15" rx="3" ry="3" width="250" height="7"></rect>
<rect x="70" y="37" rx="3" ry="3" width="200" height="7"></rect>

<rect x="0" y="75" rx="3" ry="3" width="320" height="7"></rect>
<rect x="0" y="92" rx="3" ry="3" width="320" height="7"></rect>`;

/**
 * 
 */
@containerless
@customElement('svg-custom-loader')
@inlineView(template(divTemplate, svgTemplate))
export class SvgCustomLoader extends SvgContentLoader { }

Importing new component

Add to ./resources/index.js.

import { PLATFORM } from 'aurelia-pal';

export function configure(aurelia) {
  aurelia.globalResources(PLATFORM.moduleName('resources/elements/custom-loader'));
}

Using within HTML Templates

<svg-custom-loader
  animate="1"
></svg-custom-loader>

Similar packages

Development

Fork the repo then clone it

$ git clone git@github.com:dragoscirjan/aurelia-content-loader-dev.git && cd aurelia-content-loader

yarn global add gulp-cli (or $ npm install --global gulp-cli): Install Gulp cli tool.

$ yarn (or $ npm i): Install the dependencies;

$ yarn build (or $ npm run build): Build to production;

$ yarn dev: Run the docz to see your changes;

Momentarely I do not use the testing environment. I'm using this project to develop. You're all invited to help with the unit tests, if you wish to.

$ yarn test: Run all tests: type checking and unit tests;

$ yarn test:watch: Watch unit tests;

$ yarn tsc: Typescript checking;

$ yarn tsc:watch: Typescript checking with watching;

License

MIT