1.2.1 • Published 4 years ago

react-image-designer v1.2.1

Weekly downloads
23
License
MIT
Repository
github
Last release
4 years ago

React Image Designer

Build Status

Known Vulnerabilities

Features

- Can be background-image, or src. Just specify they base element tag in props.
- Loads only if visible in window.
- Support for srcset and sizes.
- Placeholder present until src image is loaded (blank by default)
- Can set custom timeout to delay src image load

background

this project is influenced heavily by react-progressive-image. However, it appears they are no longer making updates to it (at least not new features), and I needed something similar that had options to generate background-images, use dynamic base element types, and handle children. I also prefer a simplified syntax.

Install

yarn

$ yarn add react-image-designer

npm

$ npm install react-image-designer

The UMD build is also available on unpkg:

<script src="https://unpkg.com/react-image-designer/umd/react-image-designer.min.js"></script>

If you use the UMD build you can find the library on window.__RID.

Props

NameTypeRequiredDescriptionDefault
srcstringtruesource of main imagerequired - no default
placeholderstringfalsesource of placeholder images""
styleobjfalseinline styles for component{}
classNamestringfalseclass for the base element""
idstringfalseid for the base element""
containbooleanfalseif background-size is 'contain' (else 'cover')false
repeatbooleanfalseif image repeats (background images only)false
positionstringfalsebackground-position style stringbrowser default
childrenReact Childrenfalseany string, html, or react element to embed""
altstringfalsestring for alt attribute if img tagsrc
tagstringfalsehtml element type for img (e.g. - img, div, figure etc.)"img"
srcsetstringfalsesrcset""
sizesstringfalsesizes for srcset""
noImagebooleanfalseif true, no image is used (for text only)false
timeoutnumberfalsedelay in milliseconds before src is loaded0
lazybooleanfalseif img should be lazy-loadedtrue

Simple

<ImageDesigner
  src={img.src}
  placeholder={img.placeholder}
  style={{
    height: "auto",
    margin: "auto"
  }}
/>

With Caption (as background-image)

<ImageDesigner
  src={img.src}
  srcset={img.srcset}
  sizes={img.sizes}
  placeholder={img.placeholder}
  id={["img", i].join("-")}
  className={imgClass}
  tag="div"
>
  <div
    className={captionClass}
    dangerouslySetInnerHTML={{
      __html: tryDecode(img.caption)
    }}
  />
</ImageDesigner>

Try Things Live

to test the options, git clone this repo, put some images in the 'imgs' directory, and set-up your configuration somewhere in the 'src' directory. Then run yarn start ./relative/path/from/src/to/configuration or npm run start ./relative/path/from/src/to/configuration. There is an example provided. To run it locally, execute yarn start ./dev-scripts/example or npm run start ./dev-scripts/example.

Contributing

clone, install, tinker, submit. Thanks!

1.2.0

4 years ago

1.2.1

4 years ago

1.1.18

5 years ago

1.1.17

5 years ago

1.1.16

5 years ago

1.1.15

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago