1.0.0 • Published 4 years ago

react-image-attribution v1.0.0

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

react-image-attribution

Easily add attribution info to your images

NPM JavaScript Style Guide

This package allows to add attibution info to the images and easily display them in different ways.

You can use it as a normal <img /> element or pass a custom component as child.

How to correctly attribute images

Best practices for attribution

Install

npm install --save react-image-attribution

Usage

You can use this component as the standard HTML immg tag.

import React, { Component } from 'react'

import ImageAttribution from 'react-image-attribution'

class Example extends Component {
  render() {
    return <ImageAttribution
                src="https://www.pixsy.com/wp-content/uploads/2018/03/Winter-in-town-David-J-CC-BY-2.0.jpg"
                title="Winter in town"
                author="David J"
                license="CC BY 2.0"
                mode="overlay"
            />
  }
}

You can use a custom image component:

import React, { Component } from 'react'

import ImageAttribution from 'react-image-attribution'
import CustomImage from './CustomImage'

class Example extends Component {
  render() {
    return <ImageAttribution
                title="Winter in town"
                author="David J"
                license="CC BY 2.0"
                mode="overlay"
            >
              <CustomImage
                imageLink="https://www.pixsy.com/wp-content/ uploads/2018/03/Winter-in-town-David-J-CC-BY-2.0.jpg"
              />
            </ImageAttribution>
  }
}

Props

By default the image is shown using an img HTML element. All unlinsted props will be passed to the img element.

NameTypeDeafultDescription
attributionTextstring,nullReplace the attribution text with a custom text
attributionTextClassNamestringnullClass assigned to the attribution text element
attributionTextComponentcomponent/element"figcaption"Custom component or html element used for the attribution text
attributionTextStyleanynullStyle assigned to the attribution text element
authorstring,nullPicture's author name
authorLinkstring,nullLink assigned to the author text
containerClassNamestringnullClass of the img container, not used with mode: hidden
containerComponentcomponent/element"figure"Component/element of the img container, not used with mode: hidden
containerStyleanynullStyle of the img container, not used with mode: hidden
dataAttributesbooleantrueIf true add picture informations as data-* attributes to the img element
hoverboolfalseIf true, show attribution text only when the mouse is hover the image
licensestringnullLicense applied to the picture
licenseLinkstringnullLink assigned to the license text
mode"hidden"/"outside"/"overlay""overlay"Mode to display the attribution text
onContainerMouseEnterfuncnullonMouseEnter listener of the img container, not used with mode: hidden
onContainerMouseLeavefuncnullonMouseLeave listener of the img container, not used with mode: hidden
position"topleft"/"topcenter"/"topright"/"bottomleft"/"bottomcenter"/"bottomright""bottomright"Position of the attribution text
sourcestringnullSource of the picture
sourceLinkstringnullLink assigned to the source text
titlestringnullTitle of the picture
titleLinkstringnullLink assigned to the title text

License

MIT © scailbc