@@ -16,7 +16,7 @@ import _ from 'lodash';
1616import React from 'react' ;
1717import { PropTypes } from 'prop-types' ;
1818
19- import { TextFieldWrapper , Button } from '../wrappers' ;
19+ import { TextFieldWrapper } from '../wrappers' ;
2020import TextareaAutosize from 'react-textarea-autosize' ;
2121
2222export class Textarea extends TextareaAutosize {
@@ -45,6 +45,7 @@ export class BaseTextField extends React.Component {
4545 spec : PropTypes . object ,
4646 value : PropTypes . any ,
4747 disabled : PropTypes . bool ,
48+ visible : PropTypes . bool ,
4849 onChange : PropTypes . func ,
4950 'data-test' : PropTypes . string ,
5051 }
@@ -54,6 +55,7 @@ export class BaseTextField extends React.Component {
5455
5556 this . state = {
5657 value : this . toStateValue ( this . props . value ) ,
58+ visible : false ,
5759 } ;
5860 }
5961
@@ -75,10 +77,6 @@ export class BaseTextField extends React.Component {
7577 throw new Error ( 'not implemented' ) ;
7678 }
7779
78- toggleVisibility ( ) {
79- this . setState ( { visible : ! this . state . visible } ) ;
80- }
81-
8280 validate ( v , spec = { } ) {
8381 if ( ( v === '' || v === undefined ) && spec . required ) {
8482 return 'parameter is required' ;
@@ -109,33 +107,34 @@ export class BaseTextField extends React.Component {
109107 }
110108 }
111109
110+ visibilityToggle ( ) {
111+ this . setState ( { visible : ! this . state . visible } )
112+ }
113+
112114 emitChange ( ) {
113115 return this . props . onChange ( this . fromStateValue ( this . state . value ) ) ;
114116 }
115117
116118 render ( ) {
117119 const { icon } = this . constructor ;
118- const { invalid, visible } = this . state ;
120+ const { invalid } = this . state ;
119121 const { spec= { } } = this . props ;
120- const wrapperProps = Object . assign ( { } , this . props ) ;
122+ const wrapperProps = Object . assign ( { } , this . props , {
123+ visibilityToggle : ( ) => this . visibilityToggle ( ) ,
124+ visible : this . state . visible ,
125+ } ) ;
121126
122127 if ( invalid ) {
123128 wrapperProps . invalid = invalid ;
124129 }
125130
126- const buttonProps = {
127- icon : visible ? 'view2' : 'view' ,
128- title : visible ? 'hide value' : 'see value' ,
129- onClick : ( ) => this . toggleVisibility ( ) ,
130- } ;
131-
132131 const inputProps = {
133- className : spec . secret && ! visible ? 'st2-auto-form__field--secret' : 'st2-auto-form__field' ,
132+ className : spec . secret && ! this . state . visible ? 'st2-auto-form__field--secret' : 'st2-auto-form__field' ,
134133 type : 'text' ,
135134 placeholder :this . toStateValue ( spec . default ) ,
136135 disabled : this . props . disabled ,
137136 value : this . state . value ,
138- spellCheck : spec . secret && ! visible ? false : true ,
137+ spellCheck : spec . secret && ! this . state . visible ? false : true ,
139138 onChange : ( e ) => this . handleChange ( e , e . target . value ) ,
140139 'data-test' : this . props [ 'data-test' ] ,
141140 } ;
@@ -146,10 +145,7 @@ export class BaseTextField extends React.Component {
146145
147146 return (
148147 < TextFieldWrapper icon = { icon } { ...wrapperProps } >
149- < div >
150- { ! this . props . disabled && spec . secret && < Button { ...buttonProps } /> }
151148 < input { ...inputProps } />
152- </ div >
153149 </ TextFieldWrapper >
154150 ) ;
155151 }
@@ -158,31 +154,24 @@ export class BaseTextField extends React.Component {
158154export class BaseTextareaField extends BaseTextField {
159155 render ( ) {
160156 const { icon } = this . constructor ;
161- const { invalid, visible } = this . state ;
157+ const { invalid } = this . state ;
162158 const { spec = { } } = this . props ;
163159
164- const wrapperProps = Object . assign ( { } , this . props ) ;
160+ const wrapperProps = Object . assign ( { } , this . props , {
161+ visibilityToggle : ( ) => this . visibilityToggle ( ) ,
162+ visible : this . state . visible ,
163+ } ) ;
165164
166165 if ( invalid ) {
167166 wrapperProps . invalid = invalid ;
168167 }
169168
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-
180169 const inputProps = {
181- className : spec . secret && ! visible ? 'st2-auto-form__field--secret' : 'st2-auto-form__field' ,
170+ className : spec . secret && ! this . state . visible ? 'st2-auto-form__field--secret' : 'st2-auto-form__field' ,
182171 placeholder : this . toStateValue ( spec . default ) ,
183172 disabled : this . props . disabled ,
184173 value : this . state . value ,
185- spellCheck : spec . secret && ! visible ? false : true ,
174+ spellCheck : spec . secret && ! this . state . visible ? false : true ,
186175 onChange : ( e ) => this . handleChange ( e , e . target . value ) ,
187176 minRows : 1 ,
188177 maxRows : 10 ,
@@ -195,10 +184,7 @@ export class BaseTextareaField extends BaseTextField {
195184
196185 return (
197186 < TextFieldWrapper icon = { icon } { ...wrapperProps } >
198- < div { ...wrapperBlockProps } >
199- { ! this . props . disabled && spec . secret && < Button { ...buttonProps } /> }
200187 < Textarea { ...inputProps } />
201- </ div >
202188 </ TextFieldWrapper >
203189 ) ;
204190 }
0 commit comments