Git Product home page Git Product logo

render-smooth-image-react's Introduction

render-smooth-image-react

NPM npm (custom registry) npm Open Source Love

A React component to render images smoothly.

In Action

The left side one is default rendering of an image in DOM, The right one uses render-smooth-image-react.

RenderSmoothImageDemo

Install

Using npm

npm i render-smooth-image-react

or Using yarn

yarn add render-smooth-image-react

Usage

import React from 'react';
import RenderSmoothImage from 'render-smooth-image-react';
import 'render-smooth-image-react/build/style.css';

const Image = () => (
  <div style={{ width: 300, height: 300 }}>
    <RenderSmoothImage src={'your-image-source'} alt="alternate-text" />
  </div>
);

export default Image;

Note

RenderSmoothImage will occupy full width and height of its parent component.

So, To control width/height set a parent div with desired dimensions.

Props

Property Description Default
src (*required) Image source link or path to image ย 
alt Alternate text to display when src failed. not found
objectFit Sets the object-fit property in css (helps determining how the content should be resized to fit its container). Valid options contain, fill, cover, none, scale-down. Learn more contain
onLoad Callback for onLoad event on image. () => null
onError Callback for onError event on image.. () => null
wrapperProps Any additional props to be added on root div. {}
imageProps Any additional props to be added on img element. {}

Classes

ClassName Description
smooth-image-wrapper Class added to root element.
smooth-image Class added to img tag.
image-hidden, image-visible For img tag, Class image-hidden is added while image is being downloaded and will be replaced with image-visible once image is ready to render.
smooth-no-image Class added for element rendering alt text. (img tag is replaced with a div with alt text for invalid src or when image is not found at given src).

HTML structure

For Valid Image Source.

<div class="smooth-image-wrapper">
  <img src="your-image-source" class="smooth-image image-visible" />
</div>

For Invalid Image Source, rendering alternate text.

<div class="smooth-image-wrapper">
  <div class="smooth-no-image">"Your alternate text."</div>
</div>

For Loader

<div class="smooth-image-wrapper">
  <div className="smooth-preloader">
    <span className="loader" />
  </div>
</div>

Request / Bug Report

If you have any issues or have any suggestions, Please feel free to open an issue here.

render-smooth-image-react's People

Contributors

a-saran avatar dependabot-preview[bot] avatar dependabot[bot] avatar krrish96 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

render-smooth-image-react's Issues

[BUG]:update devDependencies

Can you update devDependencies please?) I got a dependency conflict in the project. The package render-smooth-image-react has a peer dependency on react@^17.0.1, but new projects has [email protected]

[BUG]: Global CSS cannot be imported from within node_modules.

Describe the bug
I have just installed on nextjs and received this error.

./node_modules/render-smooth-image-react/build/style.css
Global CSS cannot be imported from within node_modules.
Read more: https://err.sh/next.js/css-npm
Location: node_modules/render-smooth-image-react/build/index.js

To Reproduce
Steps to reproduce the behaviour:

  1. Set up nextjs project
  2. Add this package
  3. Insert code to smooth load image.

[BUG]: Image not show after reload

Describe the bug
I have following the instruction, but the images is always loading.

To Reproduce
Steps to reproduce the behavior:

  1. nextjs project

Expected behavior
after reload the image will show

Screenshots
Screen Shot 2020-06-06 at 18 57 55

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.