Git Product home page Git Product logo

react-shimmer's Introduction

Logo

A powerful, customisable, Suspense-like <img> component that (optionally) simulates a shimmer effect while loading. (with zero dependencies!).

NPM JavaScript Style Guide Github Actions CI Status Maintainability

Header

Install

npm i react-shimmer

or

yarn add react-shimmer

Usage

import React from 'react'
import { Image, Shimmer } from 'react-shimmer'

function App() {
  return (
    <div>
      <Image
        src='https://source.unsplash.com/random/800x600'
        fallback={<Shimmer width={800} height={600} />}
      />
    </div>
  )
}
import React from 'react'
import { Image, Breathing } from 'react-shimmer'

function App() {
  return (
    <div>
      <Image
        src='https://source.unsplash.com/random/800x600'
        fallback={<Breathing width={800} height={600} />}
      />
    </div>
  )
}

or you can use your custom React component as a fallback:

import React from 'react'
import { Image } from 'react-shimmer'

import Spinner from './Spinner'

function App(props) {
  return (
    <div>
      <Image
        src="https://example.com/test.jpg"
        fallback={<Spinner />}
      />
    </div>
  )
}

Properties

Property Type Required Default value Description
src string yes
fallback ReactNode yes
errorFallback func no
onLoad func no
delay number no Delay in milliseconds before showing the fallback
fadeIn bool no false Use built-in fade animation on img
NativeImgProps React.ImgHTMLAttributes no

Contributing


Feel free to send PRs.

License

MIT ยฉ gokcan

react-shimmer's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar endocrimes avatar gokcan 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

react-shimmer's Issues

Problem with module build?

Version: 3.1.1

package.json has the line:

"module": "dist/index.module.js",

...but that file doesn't seem to exist in the built dist folder though (e.g. node_modules/react-shimmer/dist/index.module.js)

I'm encountering errors related to this while trying to build with Parcel.

@parcel/resolver-default: Could not load './dist/index.module.js' from module 'react-shimmer' found in package.json#module
/Users/username/git/project/node_modules/react-shimmer/package.json:22:13
  21 |   "main": "dist/index.js",
> 22 |   "module": "dist/index.module.js",
>    |             ^^^^^^^^^^^^^^^^^^^^^^ './dist/index.module.js' does not exist, did you mean './dist/index.d.ts'?'
  23 |   "source": "src/index.ts",
  24 |   "typings": "dist/index.d.ts",

Typescript support?

image
I wanna try but got this problem.
'Image' cannot be used as a JSX component. Its instance type 'SuspenseImage' is not a valid JSX element. The types returned by 'render()' are incompatible between these types. Type '{} | null | undefined' is not assignable to type 'ReactNode'. Type '{}' is not assignable to type 'ReactNode'.

I am using latest react with nextjs.

Getting Image failed to load error.

I implemented it using the following code:

 <div className="thumbnail">
            <Image
              src={post.image}
              fallback={<Shimmer width={100} height={100} />}
            />
            </div>

but I'm getting this error in the browser:

image

This is what I found when I inspected using dev tools:
<span role="button" aria-label="Image failed to load">โŒ</span>

How to apply custom css classes to <img>?

I want to add custom css into <img, there's no props to handle that

Edit--
I'm already tried add css into className props didn't work

<Image
   src={item.image}
  width={512}
  height={512}
  alt="Berita1"
  className="rounded-xl"
   fadeIn={true}
   delay={2}
  fallback={<Shimmer width={512} height={512} />}
/>

Screen Shot 2023-04-05 at 14 37 27

borderRadius does not work

i tried on round image which is styled by border-radius, but the default shimmer effect remain square

Make Css Utilities Classes Scoped

Most Of The Classes Define Create Conflicts when combine with css libraries like tailwinds, since this package as same classes with those other classes.

Display placeholder for server-side rendering

Right now the behavior seems to be not to display anything.

I think it would be best to display the placeholder default color, using the space based on the styles provided.

I can try myself submitting a PR if it sounds like a good idea.

How to add `classname` to <Image> component

i've try to add className in <Image> component, but it doesn't work. here my code
<Image
src={this.props.imageUrl}
fallback={<Shimmer width={800} height={600} />}
className={this.props.className}
/>

[Question/Help] React Dependency Conflict

While Adding this project as a dependency , I am getting a react version conflict as shown below:


PS D:\React\my-app> npm i react-shimmer
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"^17.0.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.13.1" from [email protected]
npm ERR! node_modules/react-shimmer
npm ERR!   react-shimmer@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Ability to render not only images when the loading is completed

First, thanks for this lib.

I know, there's some ways to reach something like this by using the onLoad prop to set a state or context and conditional rendering to the target, but It would be awesome if you add a feature to render not only images when the loading is completed, but anything else like a post by using render props or react children technique. Maybe providing a component to do it from react-shimmer?

Support for rem, vw and percentage dimensions

I am unable to provide the .rem dimensions to the Shimmer component since it's taking the height and width as number.

Is there any workaround to pass the responsive css paramters.

Thanks for this wonderful module.

Can't perform a React state update on an unmounted component.

Hi, I'm conditionally rendering a component, a modal mini-cart of sorts, and I'm getting a
Can't perform a React state update on an unmounted component ... error
if I close the cart before the image has been loaded.
As you can see on the screenshot, the issue is inside Image component that you're exporting.
Is this fixable? Cheers!

Screenshot_7

unit tests broke

When I use react-shimmer and test a component with that, my tests broke.

Console error

has anyone had this problem? found it in version 17 of React

Failed to compile after installing react-shimmer on a CRA typescript app

TypeScript error in /node_modules/react-shimmer/dist/index.d.ts(2,1):
Declaration or statement expected.  TS1128

    1 | export { default } from './Image';
  > 2 | export type { ImageProps } from './Image';
      | ^
    3 | export * from './loaders';
    4 | export type { ShimmerProps } from './loaders/shimmer/Shimmer';
    5 | export type { BreathingProps } from './loaders/breathing/Breathing';

I used it like:

import Image, { Shimmer } from 'react-shimmer'

function App() {
  return (
    <div>
      <Image
        src='https://source.unsplash.com/random/800x600'
        fallback={<Shimmer width={800} height={600} />}
      />
    </div>
  )
}

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.