npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-pressure

v0.1.7

Published

Wrapper of https://pressurejs.com/ as HOC

Downloads

11

Readme

If you want to implement 3D touch on your react component this is the module for you

Installation & Usage

npm i --save react-pressure

How to

The project wrapps al the functionalities from Pressure.js into a React High Order component, any component enchanced by this will have force and pressing in its props . The HOC allows you to pass some config options.

Debug

By default is false, if true then the component will print warnings/logs.

Polyfill Support

Using the "polyfill" keyword, you can disable polyfill support for the element. The polyfill is enabled by default and is useful if the device or browser does not support pressure, it will fall back to using time. For example instead of force from 0 to 1, it counts up from 0 to 1 over the course of one second, as long as you are holding the element. Try some of the examples on the main page on a devices that does not support pressure and see for yourself how it works.

Polyfill Speed Up

If you are using the polyfill, you can use the "polyfillSpeedUp" speed to determine how fast the polyfill takes to go from 0 to 1. The value is an integer in milliseconds and the default is 1000 (1 second). These great products are built on Semantic UI React. Add yours [here][22].

Polyfill Speed Down

If you are using the polyfill, you can use the "polyfillSpeedDown" speed to determine how fast the polyfill takes to go from 1 to 0 when the elemnt is released. The value is an integer in milliseconds and the default is 0 (aka off).

Device Detection

With Pressure, the third paramater is an optional object of options that can be passed in. The first option is device targeting. Using the "only" keyword, you can define if you want pressure to respond to ONLY touch, ONLY Mouse, or ONLY Pointer events.

touch: Iphones with 3D touch (6s,7)
mouse: Mac with Force Touch (Macbook Pro 2016/2017)
pointer: Wacom Tablets or devices that support Pointer Events

Prevent Select

Both Mac and iPhones have system wide features that they default to when force clicking on something (ex. defining a word on Mac or "peeking and popping" an image on iOS). Pressure prevents those actions from happening, however if you still want those actions to be possible on "Pressure" elements, you can pass in "preventSelect" as an option.

Example

If you want to implement 3D touch on your component you can do something like this:

import React, { Component } from 'react';
import Pressure from 'react-pressure';

class MyGreatComponent extends Component {
  render() {
    const message = this.props.pressing?"Stop please":"Touch me";
    return (
      <div>
        <h1>This is an awesome component</h1>
		<p>{message}</p>
        <p>The whole component has 3D touch detection</p>
        <p>You are using {this.props.force} force</p>
      </div>
    );
  }
}
//This is the important part
export default Pressure(MyGreatComponent);

By default all components have the configuration:

{
  polyfill: true,
  polyfillSpeedUp: 1000,
  polyfillSpeedDown: 1000,
  preventSelect: true,
  only: null
}

If you want to add some configurations you can modify the last part from the previous code and write something like this:(You can override some,none or all of the configurations)

//Now this changed
const configs = {
  polyfill: false, //Only people with 3D touch
  only: "touch"    //Only Iphones 
}
export default Pressure(MyGreatComponent,configs) ;

If you are using react-redux you can do something like:

export default connect(mapStateToProps,mapDispatchToProps)( Pressure(MyGreatComponent) );

If you have any doubt/recommendation you can write me or any trouble you can create a new thread on the issues area of the repository #ISSUES: 0.1.2 The latest realese of pressure.js has a weird bug in some Android devices, this new realese of react-pressure has a hotfix while the core code is upgraded, if you don't pass a configuration object then the HOC will try to guess if you are using a mobile phone, if it is de case then it uses the only:"touch", else it continues with the default configurations. 09/12/2017

#LIVE EXAMPLE:

Pressure Cubes: React & Three.js videogame that implements 3D touch to avoid cubes