1.0.9 • Published 2 years ago

react-loader-ts v1.0.9

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

React Loader TS

https://www.npmjs.com/package/react-loader-ts

react-loader-ts is a TypeScript/React library that offers a customizable Loader component, a LoaderContext to manage the loader state for the entire application, and other useful components.

Installation

Using yarn

yarn add react-loader-ts

Using npm

npm install --save react-loader-ts

ezgif com-gif-maker (1)

Uasage

To enable the library, wrap your application with the LoaderProvider.

Here's a quick example:

app.tsx

...otherImports;
import { TestLoading } from "./TestLoading";
import { LoaderProvider } from "react-loader-ts";

import "react-loader-ts/lib/esm/styles/global.css";

export default function Application() {
  return (
    <LoaderProvider>
      <TestLoading />
    </LoaderProvider>
  );
}

Remember to import the styles from react-loader-ts/lib/esm/styles/global.css.

TestLoading.tsx

import { useLoader, Loader } from "react-loader-ts";

export function TestLoading() {
  const { isLoading, setLoading } = useLoader();

  return (
    <>
      <button onClick={() => setLoading(!isLoading)}>Toggle loading</button>
      {isLoading ? <Loader /> : null}
    </>
  );
}

Components

Loader

PropertyTypeOptionalDefaultDescription
variantVarianttrueVariant.DotsChange the loader variant (CircleDots or Dots).
inlinebooleantruefalseMake the loader inline.
containerClassNamestringtrueundefinedAdd a custom class to the loader container.
containerStyleCSSPropertiestrueundefinedAdd custom styles to the loader container.
loaderClassNamestringtrueundefinedAdd a custom class to the loader.
loaderStylestringtrueundefinedAdd custom styles to the loader.

Example:

import { Loader, Variant } from "react-loader-ts";

<Loader
  variant={Variant.Dots}
  containerClassName="custom-container-class"
  containerStyle={{ backgroundColor: "red" }}
  loaderClassName="custom-loader-class"
  loaderStyle={{ width: "50px" }}
 />

WithLoader

This component automatically renders the loader when it's loading and it renders the children when it isn't.

By default the component uses the values from LoaderContext but you can override that behavior using the isLoading prop.

PropertyTypeOptionalDefaultDescription
isLoadingbooleantrueundefinedOverride the default logic and don't use the LoaderContext values.
loaderReactNodetrueundefinedOverride the default Loader component and provide a custom one.
variantVarianttrueVariant.DotsChange the loader variant (CircleDots or Dots).
inlinebooleantruefalseMake the loader inline.
containerClassNamestringtrueundefinedAdd a custom class to the loader container.
containerStyleCSSPropertiestrueundefinedAdd custom styles to the loader container.
loaderClassNamestringtrueundefinedAdd a custom class to the loader.
loaderStylestringtrueundefinedAdd custom styles to the loader.

Example:

import { WithLoader } from "react-loader-ts";

// It uses the default isLoading value from LoaderContext
<WithLoader>children</WithLoader>

// It uses the provided isLoading value
<WithLoader isLoading>children</WithLoader>

// It uses the provided loader component
<WithLoader loader={<>custom loader component</>}>children</WithLoader>
1.0.9

2 years ago

1.0.8

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

0.4.0

4 years ago

0.3.9

4 years ago

0.3.12

4 years ago

0.3.11

4 years ago

0.3.10

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.2.6

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.2.8

4 years ago

0.3.2

4 years ago

0.2.3

4 years ago

0.3.1

4 years ago

0.2.2

4 years ago

0.3.4

4 years ago

0.2.5

4 years ago

0.3.3

4 years ago

0.2.4

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago