2.0.0 • Published 2 months ago

@nikxda/react-xray v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

react-xray

Accessible image component that reveals images on user interaction

Installation

npm install @nikxda/react-xray

Try it online

The storybook is available here: https://react-xray.vercel.app/

Preview

React XRay

Features

  • :gear:  Fully customizable
  • :tophat:  TypeScript support built in
  • :sparkles:  Custom feColorMatrix effects
  • :computer:  Responsive out of the box
  • :iphone:  Touch support
  • :eyeglasses:  Basic accessibility built-in
  • :tada:  Custom transitions
  • :mag:  Zoom mode
  • :100:  3KB minified and gzip-ed

Usage

import XRay from '@nikxda/react-xray';

const ExampleComponent = () => (
 <div>
  <h1>An Example Image</h1>
  <XRay href="http://picsum.photos/1920/1080" alt="Lorem Picsum" />
 </div>
)

Component Props

The following properties are available:

Prop NameTypeDefault ValueDescriptionRequired
hrefstring-The image URL.Yes
altstring-A description of the image.Yes
blurnumber15The amount of blur.No
radiusScalenumber1The factor by which to scale the default responsive radius.No
fixedRadiusnumbernullIf no responsive radius is desired, a fixed radius can be applied.No
onClickfunction()=>{}An onClick handler.No
effectsstring[][]Effects to be applied globally, see Effects.No
imageLayerEffectsstring[][]Effects to be applied to the image layer, see Effects.No
blurLayerEffectsstring[][]Effects to be applied to the blur layer, see Effects.No
circleInTransitionstring"elastic.out(1, 0.3)"The GSAP transition which will be used to transition the circle in.No
circleInDurationnumber0.5The duration of the circleInTransitionNo
circleOutTransitionstring"expo.out"The GSAP transition which will be used to transition the circle out.No
circleOutDurationnumber0.2The duration of the circleOutTransitionNo
canRevealbooleantrueWhether the revealed state can be toggled using the keyboard on focus.No
autoRevealbooleanfalseWhether the image should automatically reveal itself upon focus.No
persistRevealbooleanfalseWhether the image should stay visible after it has been revealed for the first time.No
zoomnumber1The amount of zoom.No

Effects

XRay supports custom effects on three layers:

  • The global layer effects are applied to the whole component, therefore affecting all visuals. The corresponding property is effects.
  • The image layer effects are applied only to the revealed image, therefore to what is visible in the circular cutout. The corresponding property is imageLayerEffects.
  • The blur layer effects are applied only to the blurred section of the image. The corresponding property is blurLayerEffects.

Each of the three proprties take a string[] with each entry of the array being an effect matrix as per the MDN specification found here. For example, to darken the blurry part of the image, one may supply the value [".3 0 0 0 0 0 .3 0 0 0 0 0 .3 0 0 0 0 0 1 0"] for blurLayerEffects.

Accessibility & Responsiveness

React XRay provides basic accessibility out of the box. It features touch support for mobile devices and will allow the image to be revealed when the element has the focus and the mouse is not currently over the image. In this case, the component will display a message saying that the image can be revealed by pressing space. The responsiveness comes from the fact that a single radius given in pixels will likely not be suitable for all screen sizes. XRay therefore calculates a "responsive" radius by tracking the wrapper dimensions. The default diameter of the circular cutout is half the length of the shorter side. If this choice is not suitable, the responsive radius can be scaled using radiusScale or set to a fixed value using fixedRadius.

License

MIT

1.1.0

2 months ago

2.0.0

2 months ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.0

3 years ago