@@ -16,7 +16,7 @@ import _ from 'lodash';
1616import React from 'react' ;
1717import { PropTypes } from 'prop-types' ;
1818
19- import { TextFieldWrapper } from '../wrappers' ;
19+ import { TextFieldWrapper , Button } from '../wrappers' ;
2020import TextareaAutosize from 'react-textarea-autosize' ;
2121
2222export class Textarea extends TextareaAutosize {
@@ -75,6 +75,10 @@ export class BaseTextField extends React.Component {
7575 throw new Error ( 'not implemented' ) ;
7676 }
7777
78+ toggleVisibility ( ) {
79+ this . setState ( { visible : ! this . state . visible } ) ;
80+ }
81+
7882 validate ( v , spec = { } ) {
7983 if ( ( v === '' || v === undefined ) && spec . required ) {
8084 return 'parameter is required' ;
@@ -111,20 +115,27 @@ export class BaseTextField extends React.Component {
111115
112116 render ( ) {
113117 const { icon } = this . constructor ;
114- const { invalid } = this . state ;
118+ const { invalid, visible } = this . state ;
115119 const { spec= { } } = this . props ;
116120 const wrapperProps = Object . assign ( { } , this . props ) ;
117121
118122 if ( invalid ) {
119123 wrapperProps . invalid = invalid ;
120124 }
121125
126+ const buttonProps = {
127+ icon : visible ? 'view2' : 'view' ,
128+ title : visible ? 'hide value' : 'see value' ,
129+ onClick : ( ) => this . toggleVisibility ( ) ,
130+ } ;
131+
122132 const inputProps = {
123- className : 'st2-auto-form__field' ,
124- type : spec . secret ? 'password' : 'text' ,
133+ className : spec . secret && ! visible ? 'st2-auto-form__field--secret' : 'st2-auto-form__field' ,
134+ type : 'text' ,
125135 placeholder :this . toStateValue ( spec . default ) ,
126136 disabled : this . props . disabled ,
127137 value : this . state . value ,
138+ spellCheck : spec . secret && ! visible ? false : true ,
128139 onChange : ( e ) => this . handleChange ( e , e . target . value ) ,
129140 'data-test' : this . props [ 'data-test' ] ,
130141 } ;
@@ -135,7 +146,10 @@ export class BaseTextField extends React.Component {
135146
136147 return (
137148 < TextFieldWrapper icon = { icon } { ...wrapperProps } >
138- < input { ...inputProps } />
149+ < div >
150+ { ! this . props . disabled && spec . secret && < Button { ...buttonProps } /> }
151+ < input { ...inputProps } />
152+ </ div >
139153 </ TextFieldWrapper >
140154 ) ;
141155 }
@@ -144,20 +158,31 @@ export class BaseTextField extends React.Component {
144158export class BaseTextareaField extends BaseTextField {
145159 render ( ) {
146160 const { icon } = this . constructor ;
147- const { invalid } = this . state ;
148- const { spec= { } } = this . props ;
161+ const { invalid, visible } = this . state ;
162+ const { spec = { } } = this . props ;
149163
150164 const wrapperProps = Object . assign ( { } , this . props ) ;
151165
152166 if ( invalid ) {
153167 wrapperProps . invalid = invalid ;
154168 }
155169
170+ const buttonProps = {
171+ icon : visible ? 'view2' : 'view' ,
172+ title : visible ? 'hide value' : 'see value' ,
173+ onClick : ( ) => this . toggleVisibility ( ) ,
174+ } ;
175+
176+ const wrapperBlockProps = {
177+ className : 'st2-auto-form__wrapper-block' ,
178+ } ;
179+
156180 const inputProps = {
157- className : 'st2-auto-form__field' ,
181+ className : spec . secret && ! visible ? 'st2-auto-form__field--secret' : 'st2-auto-form__field' ,
158182 placeholder : this . toStateValue ( spec . default ) ,
159183 disabled : this . props . disabled ,
160184 value : this . state . value ,
185+ spellCheck : spec . secret && ! visible ? false : true ,
161186 onChange : ( e ) => this . handleChange ( e , e . target . value ) ,
162187 minRows : 1 ,
163188 maxRows : 10 ,
@@ -170,7 +195,10 @@ export class BaseTextareaField extends BaseTextField {
170195
171196 return (
172197 < TextFieldWrapper icon = { icon } { ...wrapperProps } >
173- < Textarea { ...inputProps } />
198+ < div { ...wrapperBlockProps } >
199+ { ! this . props . disabled && spec . secret && < Button { ...buttonProps } /> }
200+ < Textarea { ...inputProps } />
201+ </ div >
174202 </ TextFieldWrapper >
175203 ) ;
176204 }
0 commit comments