File tree Expand file tree Collapse file tree 5 files changed +58
-26
lines changed
Expand file tree Collapse file tree 5 files changed +58
-26
lines changed Original file line number Diff line number Diff line change 1+ import React , { Component } from 'react' ;
2+
3+ class HoldClickBehaviour extends Component {
4+ timer = null ;
5+
6+ handleButtonPress = ( ) => {
7+ const { delay = 250 , onHoldStart } = this . props ;
8+
9+ this . timer = setTimeout ( onHoldStart , delay ) ;
10+ } ;
11+
12+ handleButtonRelease = ( ) => {
13+ const { onHoldEnd } = this . props ;
14+
15+ clearTimeout ( this . timer ) ;
16+
17+ onHoldEnd ( ) ;
18+ } ;
19+
20+ render ( ) {
21+ const { onHoldStart, onHoldEnd, ...props } = this . props ;
22+
23+ return (
24+ < div
25+ { ...props }
26+ role = "presentation"
27+ onTouchStart = { this . handleButtonPress }
28+ onTouchEnd = { this . handleButtonRelease }
29+ onMouseDown = { this . handleButtonPress }
30+ onMouseUp = { this . handleButtonRelease }
31+ onMouseLeave = { this . handleButtonRelease }
32+ />
33+ ) ;
34+ }
35+ }
36+
37+ export default HoldClickBehaviour ;
Original file line number Diff line number Diff line change 1+ export { default as HoldClickBehaviour } from './HoldClickBehaviour' ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import React, { PureComponent } from 'react';
22import styled from 'styled-components' ;
33import Input from './Input' ;
44import { Icon } from '../Icon' ;
5+ import { HoldClickBehaviour } from '../HoldClickBehaviour' ;
56
67const StyledIcon = styled ( Icon ) `
78 cursor: pointer;
@@ -12,10 +13,10 @@ class PasswordInput extends PureComponent {
1213 visible : false ,
1314 } ;
1415
15- handleChangeVisible = ( ) => {
16- this . setState ( prevState => ( {
17- visible : ! prevState . visible ,
18- } ) ) ;
16+ handleToggleVisible = visible => ( ) => {
17+ this . setState ( {
18+ visible,
19+ } ) ;
1920 } ;
2021
2122 render ( ) {
@@ -32,12 +33,12 @@ class PasswordInput extends PureComponent {
3233 type = { type }
3334 postfix = {
3435 value && (
35- < StyledIcon
36- name = { iconName }
37- width = { 18 }
38- height = { 18 }
39- onClick = { this . handleChangeVisible }
40- / >
36+ < HoldClickBehaviour
37+ onHoldStart = { this . handleToggleVisible ( true ) }
38+ onHoldEnd = { this . handleToggleVisible ( false ) }
39+ >
40+ < StyledIcon name = { iconName } width = { 18 } height = { 18 } />
41+ </ HoldClickBehaviour >
4142 )
4243 }
4344 />
Original file line number Diff line number Diff line change 11import React , { Component } from 'react' ;
22import styled from 'styled-components' ;
33import copy from 'copy-text-to-clipboard' ;
4- import { Icon , Label } from 'components' ;
4+ import { Icon , Label , HoldClickBehaviour } from 'components' ;
55import {
66 Wrapper ,
77 Row ,
@@ -47,7 +47,7 @@ class Credentials extends Component {
4747 isPasswordVisible : false ,
4848 } ;
4949
50- handleTogglePasswordVisibility = visible => {
50+ handleToggleVisibility = visible => ( ) => {
5151 this . setState ( ( ) => ( {
5252 isPasswordVisible : visible ,
5353 } ) ) ;
@@ -124,20 +124,12 @@ class Credentials extends Component {
124124 < FieldValue >
125125 < FixedSizeField > { pwd } </ FixedSizeField >
126126 < Row >
127- < StyledEyeIcon
128- name = { eyeIconName }
129- width = { 20 }
130- height = { 20 }
131- onMouseDown = { ( ) => {
132- return this . handleTogglePasswordVisibility ( true ) ;
133- } }
134- onMouseUp = { ( ) => {
135- return this . handleTogglePasswordVisibility ( false ) ;
136- } }
137- onMouseOver = { ( ) => {
138- return this . handleTogglePasswordVisibility ( false ) ;
139- } }
140- />
127+ < HoldClickBehaviour
128+ onHoldStart = { this . handleToggleVisibility ( true ) }
129+ onHoldEnd = { this . handleToggleVisibility ( false ) }
130+ >
131+ < StyledEyeIcon name = { eyeIconName } width = { 20 } height = { 20 } />
132+ </ HoldClickBehaviour >
141133 < StyledIcon
142134 name = "copy"
143135 width = { 19 }
Original file line number Diff line number Diff line change @@ -70,3 +70,4 @@ export { Toggle } from './Toggle';
7070export { RangeInput } from './RangeInput' ;
7171export { PasswordIndicator } from './PasswordIndicator' ;
7272export { TagsInput } from './TagsInput' ;
73+ export { HoldClickBehaviour } from './HoldClickBehaviour' ;
You can’t perform that action at this time.
0 commit comments