Socket
Socket
Sign inDemoInstall

react-tridi

Package Overview
Dependencies
12
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-tridi

360-degree product viewer


Version published
Weekly downloads
805
increased by42.48%
Maintainers
1
Install size
1.44 MB
Created
Weekly downloads
 

Changelog

Source

[2.1.1] - 2022-01-24

Updated

  • Updated version of dependencies in package.json

Readme

Source

react-tridi

React Tridi is a light-weight react component for 360-degree product viewer

NPM JavaScript Style Guide

Inspired by the Tridi javascript library for 360-degree 3D product visualizations based on series of images. Special thanks to Łukasz Wójcik

Install


npm install --save react-tridi

Usage

Simple

Here is the simplest case of using React Tridi. You just need to specify an images' location, its format, and total of the images.

Sample code:

import React from 'react';
import Tridi from 'react-tridi';
import 'react-tridi/dist/index.css';

const Example = () => (
    <div style={{ width: '500px' }}>
        <Tridi location="./images" format="jpg" count="36" />
    </div>
);
With Pins

In this mode, you can load some pin points on top of the product images. There is an onClick event on each pin with the pin's information returned, so you can show the product information on that event if needed.

The pins data structure looks like this:

const pins = [
  { "id": "kcyvybbrjkr8lz7w1j", "frameId": 0, "x": "0.664000", "y": "0.570922", "recordingSessionId": "klbp4jr3r7vyy5nnmkg" },
  { "id": "kcyvybrdbqwmi3z1ig", "frameId": 1, "x": "0.340000", "y": "0.500000", "recordingSessionId": "klbp4jr3r7vyy5nnmkg" },
]

You can record pins' coordinates via the recoding mode of the React Tridi with the following steps:

  1. Enable the prop showControlBar to show functionality buttons.
  2. Click the target icon to start recoding the coordinates.
  3. Click on the image view area to create a pin. Double click the pin to remove it. You can click the Next & Prev button to move to other frames, and create other pins on them.
  4. On each start and stop recording event, an array of pins' information like above will be returned.

You can also render a custom pin point if needed by using the renderPin prop.

Sample code:

import React from 'react';
import Tridi from 'react-tridi';
import 'react-tridi/dist/index.css';

const Example = () => (
    <div style={{ width: '500px' }}>
      <Tridi
        location="./images"
        format="jpg"
        count="36"
        autoplaySpeed={70}
        onRecordStart={recordStartHandler}
        onRecordStop={recordStopHandler}
        onPinClick={pinClickHandler}
        renderPin={(pin) => (<span>A</span>)}
        inverse
        showControlBar
      />
    </div>
);
With Customized Control Buttons

If you do not like the default control buttons, React Tridi gives you a ref accessing to all the button actions.

Sample code:

import React, { useState, useRef } from 'react';
import Tridi from 'react-tridi';
import 'react-tridi/dist/index.css';

const Example = () => {
    const [isAutoPlayRunning, setIsAutoPlayRunning] = useState(false);
  const tridiRef = useRef(null);
  
  return (
    <div style={{ width: '500px' }}>
      <Tridi
        ref={tridiRef}
        location="./images"
        format="jpg"
        count="36"
      />
      <button onClick={() => tridiRef.current.prev()}>Prev</button>
      <button onClick={() => tridiRef.current.next()}>Next</button>
      <button onClick={() => tridiRef.current.toggleAutoplay(!isAutoPlayRunning)}>
        {isAutoPlayRunning ? 'Pause' : 'Autoplay'}
      </button>
    </div>
  );
};

Props

Prop NameProp TypeDefault ValueRequired?Description
classNamestringundefinednoAdd class name for the component
styleobjectundefinednoAdd style for the component
imagesarrays"numbered"noSource of images to be used by Tridi
pinsarraysundefinednoPin coordinates to show on the product
formatstringundefinedyes*Image extension (e.g. "jpg"). Required if images = "numbered"
locationstringundefinedyes*Path to images folder. Required if images = "numbered"
countnumberundefinedyes*Number of images in the series. Required if images = "numbered"
draggablebooleantruenoEnable/disable mouse drag event
hintOnStartUpbooleanfalsenoEnable/disable hint on start up
hintTextstringundefinednoEnable/disable hint text
autoplaybooleanfalsenoEnable/disable autoplay
autoplaySpeednumber50noAdjust autoplay speed
stopAutoplayOnClickbooleanfalsenoStop autoplay if user clicks on container
stopAutoplayOnMouseEnterbooleanfalsenoStop autoplay if user hovers over container
resumeAutoplayOnMouseLeavebooleanfalsenoResume autoplay if user moves mouse cursor away from container
touchbooleantruenoEnable/disable touch support
mousewheelbooleanfalsenoEnable/disable mousewheel support
inversebooleanfalsenoSwap image rotation direction. Affects mouse drag, mousewheel and touch
dragIntervalnumber1noAdjust rotation speed for mouse drag events
touchDragIntervalnumber2noAdjust rotation speed for touch events
mouseleaveDetectbooleanfalsenoIf true, active drag event will stop whenever mouse cursor leaves Tridi container
showControlBarbooleanfalsenoshow a control bar with record, play, pause, next, prev functions
showStatusBarbooleanfalsenoshow a status bar on recording
hideRecordbooleanfalsenohide record button in the control bar
zoomnumber1nodefault zoom value
minZoomnumber1nominimum zoom value
maxZoomnumber3nomaximum zoom value
renderPinfuncundefinednorender a customized pin point
setPinsfuncundefinednofunction to set pin's state
renderHintfuncundefinednorender a customized hint message

Prop Events

Prop NameParams TypeDescription
onHintHidenullHint is hidden
onAutoplayStartnullAutoplay is started
onAutoplayStopnullAutoplay is stopped
onNextMovenullNext image is loaded (obeying inverse option)
onPrevMovenullPrevious image is loaded (obeying inverse option)
onNextFramenullNext image is loaded following the order in the image source (indifferent to inverse option)
onPrevFramenullPrevious image is loaded according to the order in the image source (indifferent to inverse option)
onDragStartnullImage rotation sequence (dragging) starts
onDragEndnullImage rotation sequence (dragging) ends
onFrameChangenumberNext image is loaded, sending out the current image index
onRecordStartnullget current sessionId on start recording
onRecordStopnullget current sessionId on stop recording
onPinClicknullget a pin info on click in normal mode
onZoomnullget the current zoom scale value
onLoadChangeload_success, percentageload_success: get whether all images have been loaded, percentage: current load percentage

Ref Functions

Function NameParams TypeDescription
prev()nulltrigger prev move
next()nulltrigger next move
toggleAutoPlay(true/false)booleantoogle autoplay
toggleRecording(true/false)booleantoggle recording pins' coordinates
toggleMoving(true/false)booleantoogle moving photo while zooming

License

MIT © nevestuan

Keywords

FAQs

Last updated on 24 Jan 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc