1.0.7 • Published 9 days ago

@chan_alston/image v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
9 days ago

React Image Component

A simple, easy to use image component for React. (Compatible with NextJs)

Installation

npm install @chan_alston/image@latest --save

Image usage

import styles from "./image.module.css";

import React from "react";
import Image from "@chan_alston/image";

import myImg from "../public/myImg.jpg";
import myImgSmall from "../public/myImgSmall.jpg";
import myImgMedium from "../public/myImgMedium.jpg";
import myImgBig from "../public/myImgBig.jpg";

const ImageComponent = ({ image }) => (
  <figure>
    <Image
      src={myImg} 
      alt="my image"
      w="100px"  // w stands for width
      h="100px" // h stands for height
      className={`${styles.myImage} ${styles.imgContainer} img`}
      srcSet={`${myImgSmall} 500w,
              ${myImgMedium} 900w,
              ${qmyImgBig} 1400w`}
      sizes="(min-width: 66em) 33vw,
            (min-width: 44em) 50vw,
            100vw"
      responsive  // default to true
      priority={false} // default to false
      placeholder="https://via.placeholder.com/512"
    />
    <figcaption>This is my image</figcaption>
  </figure>
);

export default ImageComponent;

Properties of Image

PropertiesTypeRequiredDefault Value
srcString or StaticImageDatatrue
altStringtrue
wString or Numberfalse
hString or Numberfalse
classNameStringfalse
srcSetStringfalse
sizesStringfalse
responsiveBooleanfalsetrue
priorityBooleanfalsefalse
imgRefReact.MutableRefObjectfalsenull
styleCSSPropertiesfalse{}
placeholderString or StaticImageDatafalse

Notes

  • When w(width) and/or h(height) is set, responsive is set to false by default, unless explicitly specify with responsive.
1.0.7

9 days ago

1.0.5

5 months ago

1.0.4

6 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.3

12 months ago

1.0.0

1 year ago

0.0.8

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.1

2 years ago

0.0.0

2 years ago