Giter VIP home page Giter VIP logo

react-preloaders's Introduction

React Preloaders

React Preloaders

npm npm bundle size Travis (.org) branch npm downloads NPM

Setup

Install it:

npm install react-preloaders --save

or

yarn add react-preloaders --save

Get Started

find full preloaders list here.

Simplest way

import React from 'react';
import { Lines } from 'react-preloaders';

function App() {
  return (
    <React.Fragment>
      <YourApp />
      <Lines />
    </React.Fragment>
  );
}

Your components as preloader

Here is example how you can use your components as prelaoder:

import React from 'react';
import { CustomPreloader } from 'react-preloaders';

function App() {
  return (
    <React.Fragment>
      <YourApp />
         <CustomPreloader>
                 YOUR CUSTOM PRELOADER COMPONENT
         </CustomPreloader>
    </React.Fragment>
  );
}

Properties (Props)

Prop type Default value
color String(hex, rgb,...) #2D2D2D
background String(blur, gradient...) #F7F7F7
time Number(Milliseconds) 1300ms
animation String(fade, slide...) fade
customLoading Boolean undefined

color (String)

Color (hex, rgb, rgba) defines preloaders main color.

import { Lines } from 'react-preloaders';

<Lines color={'#f7f7f7'} />;
<Lines color={'rgb(158, 38, 102)'} />;

background (String)

Background can be just color (hex, rgb), gradient or blured. For just colored background pass color(hex, rgb, rgba).

import { Lines } from 'react-preloaders';

<Lines background="#f7f7f7" />;

For gradient background pass your gradient.

You can generate gradients here.

import { Lines } from 'react-preloaders';

<Lines background="linear-gradient(180deg, #f95759 0%, #a62022 100%)" />;

For blured background just pass blur.(it's now in beta)

import { Lines } from 'react-preloaders';

<Lines background="blur" />;

time (Number)

Time defines how long you want show preloader after page loaded.

import { Lines } from 'react-preloaders';

<Lines time={1800} />;

If your are using customLoading and you don't want play preloader if your loading status false you need to pass time 0

import { Lines } from 'react-preloaders';

<Lines customLoading={loading} time={0} />;

animation (String)

Now you can choose preloader closing animation, in this version available just 2 animations fade and slide. By default preloader will close with fade animation.

For slide animation you can choose direction.

import { Lines } from 'react-preloaders';

<Lines animation="slide" />;
<Lines animation="slide-down" />;
<Lines animation="slide-right" />;
<Lines animation="slide-left" />;

customLoading (Boolean)

If in your app somthing loads async you can use preloaders too. For customLoading you need to pass your loading status.

import React, { Component } from 'react';
import { Lines } from 'react-preloaders';

class App {
  constructor() {
    state = {
      loading: true
    };
  }
  componentDidMount() {
    fetch('https://jsonplaceholder.typicode.com/todos/1')
      .then(response => response.json())
      .then(json => {
        setState({ loading: false });
      })
      .catch(err => {
        setState({ loading: false });
      });
  }
  render() {
    return (
      <React.Fragment>
        <YourApp />
        <Lines customLoading={loading} />
      </React.Fragment>
    );
  }
}

Example with hooks

import React, { useState, useEffect } from 'react';
import { Lines } from 'react-preloaders';

function App() {
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    fetch('https://jsonplaceholder.typicode.com/todos/1')
      .then(response => response.json())
      .then(json => {
        setLoading(false);
      })
      .catch(err => {
        setLoading(false);
      });
  }, []);

  return (
    <React.Fragment>
      <YourApp />
      <Lines customLoading={loading} />
    </React.Fragment>
  );
}

CSS loading (under v3.x.x) methods for old versions

Packages you need

style-loader css-loader

more if you want to extract css you need

Extract ( webpack 3.x )

extract-text-webpack-plugin

Extract ( webpack 4.x )

mini-css-extract-plugin

Add this to your webpack if you don't have css loader yet

{
  test: /\.css$/,
  use: [ 'style-loader', 'css-loader' ]
}

Extract ( webpack 3.x )

const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractCSS = new ExtractTextPlugin('style.[hash].css');

module.exports = {
  plugins: [extractCSS],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: extractCSS.extract(['css-loader', 'postcss-loader'])
      }
    ]
  }
};

Extract ( webpack 4.x )

const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
  plugins: [
    new MiniCssExtractPlugin({
      // Options similar to the same options in webpackOptions.output
      // both options are optional
      filename: '[name].css',
      chunkFilename: '[id].css'
    })
  ],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              // you can specify a publicPath here
              // by default it use publicPath in webpackOptions.output
              publicPath: '../'
            }
          },
          'css-loader'
        ]
      }
    ]
  }
};

react-preloaders's People

Contributors

dependabot[bot] avatar vamosgs 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

Watchers

 avatar  avatar  avatar

react-preloaders's Issues

Ability to pass custom component as loader

Is your feature request related to a problem? Please describe.
It is great that we have several preloader options provided with the package however certain apps require very custom loading screens to be displayed. Do you have plans to include them?

Also, do we have provision to custom style the loading components? say in planets, can we customise it to have additional planets and configure colour options to the same?

Stucked on Loader

Describe the bug
Stucked on loader for the first time after refresh it works fine

To Reproduce
Steps to reproduce the behavior:

  1. in react router when user log in preloader loads then main app
  2. it will remain stucked until we refresh the page
  3. then it will work fine on every refresh

Screenshots
If applicable, add screenshots to help explain your problem.

image

Error: Invalid hook call.

After install and set up app just reporting the following error:

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This >could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app
    See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.

image

This is my App.js as it recommends

import React from 'react';
import Routes from './routes';
import GlobalStyle from './Styles/global';
import { Lines } from 'react-preloaders';

function App() {
    return (
        <>
            <Routes />
            <GlobalStyle />
            <Lines />
        </>
    );
}

export default App;

Manually stop loading

The docs doesn't have any tips showing us on how to manually stop loading. For example, if we need to show the loading screen while some data from API is fetching and stop it after data is fetched, how to do this?

Currently its impossible to implement?

Thanks!

Can't set customLoading equal true again after get request api

Describe the bug
When i using customLoading to set status for pre-loading with request api, i can't set customLoading equals TRUE again with another request.

Expected behavior
Can setting customLoading and preloader is display again with each request

Code
In my render function
<h1>My app</h1>
<Lines customLoading={this.state.loading} />
<button onClick={() => this.setState({ loading: true })}>Another Request</button>
<h3>{this.state.loading ? 'true' : 'false' } </h3>
When i change state by click button "Another Request", state has change, but my preloader not reset customLoading and have no display preloader

Dependency issues with React 17

Describe the bug
Looks like this package has peer dependency [email protected], I'm using 17.0.2.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new project with npx create-react-app
  2. npm install react-preloaders
  3. npm run
  4. Import and add any preloader eg <Cube/> to your app's root
  5. Visit localhost:3000

Expected behavior
The app starts with the preloader visible.

Observed behaviour

1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app

Screenshots
image

Desktop (please complete the following information):
n/a

Smartphone (please complete the following information):
n/a

Additional context
Apologies if I'm missing something here.

3.0 Roadmap

3.0 Roadmap

  • Rewirte with react hooks.
  • Integrate testing system (Jest).
  • Integrate CI system (Travic CI).
  • Integrate prop-types.
  • Integrate styled-components.
  • Add custom preloaders possibility #4
  • Add manually stop loading functionalty #5
  • Create withPreloader function for extracting Preloaders with less code.
  • Add choice for closing transition (or custom transitions).
  • Add blur background.
  • Update library build.
  • Update (or rewrite) documentation.
  • Create examples
    • Simple
    • Manually stop loading
    • With custom loader component
  • Create repo card
  • Add new preloaders

Check 3.0 development progress in development branch.

TypeScript support?

Could you write *.d.ts files to support typescript features?
Looking forward to it.

Webpack 4 support?

Would I be able to use the mini css extract plugin that is recommended for webpack 4? If not can you build in support for webpack 4?

Impossible to implement

in render() should be only one element which contains anothers...
errors:
Module build failed: SyntaxError: D:.../src/App.jsx: Adjacent JSX elements must be wrapped in an enclosing tag
If I insert it inside another tag:
Error: Module parse failed: Unexpected token (18:12)
You may need an appropriate loader to handle this file type

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.