diff options
author | muhamedsalih-tw <104364298+muhamedsalih-tw@users.noreply.github.com> | 2022-10-31 05:20:17 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-30 23:50:17 +0000 |
commit | 011e73f24f8ae15091d41781c93c313d0167d887 (patch) | |
tree | 3e012f97a9c3ecf98e348690f82dae0d58ec0155 /src/components/ui/Input.js | |
parent | 6.2.1-nightly.33 [skip ci] (diff) | |
download | ferdium-app-011e73f24f8ae15091d41781c93c313d0167d887.tar.gz ferdium-app-011e73f24f8ae15091d41781c93c313d0167d887.tar.zst ferdium-app-011e73f24f8ae15091d41781c93c313d0167d887.zip |
Convert LoginScreen component tree to typescript (#721)
Diffstat (limited to 'src/components/ui/Input.js')
-rw-r--r-- | src/components/ui/Input.js | 156 |
1 files changed, 0 insertions, 156 deletions
diff --git a/src/components/ui/Input.js b/src/components/ui/Input.js deleted file mode 100644 index ae14493ca..000000000 --- a/src/components/ui/Input.js +++ /dev/null | |||
@@ -1,156 +0,0 @@ | |||
1 | import { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { observer } from 'mobx-react'; | ||
4 | import { Field } from 'mobx-react-form'; | ||
5 | import classnames from 'classnames'; | ||
6 | import { defineMessages, injectIntl } from 'react-intl'; | ||
7 | |||
8 | import { mdiEye, mdiEyeOff } from '@mdi/js'; | ||
9 | import { scorePassword as scorePasswordFunc } from '../../helpers/password-helpers'; | ||
10 | import Icon from './icon'; | ||
11 | |||
12 | const messages = defineMessages({ | ||
13 | passwordToggle: { | ||
14 | id: 'settings.app.form.passwordToggle', | ||
15 | defaultMessage: 'Password toggle', | ||
16 | }, | ||
17 | }); | ||
18 | |||
19 | // Can this file be merged into the './input/index.tsx' file? | ||
20 | class Input extends Component { | ||
21 | static propTypes = { | ||
22 | field: PropTypes.instanceOf(Field).isRequired, | ||
23 | className: PropTypes.string, | ||
24 | focus: PropTypes.bool, | ||
25 | showPasswordToggle: PropTypes.bool, | ||
26 | showLabel: PropTypes.bool, | ||
27 | scorePassword: PropTypes.bool, | ||
28 | prefix: PropTypes.string, | ||
29 | suffix: PropTypes.string, | ||
30 | }; | ||
31 | |||
32 | static defaultProps = { | ||
33 | className: null, | ||
34 | focus: false, | ||
35 | showPasswordToggle: false, | ||
36 | showLabel: true, | ||
37 | scorePassword: false, | ||
38 | prefix: '', | ||
39 | suffix: '', | ||
40 | }; | ||
41 | |||
42 | state = { | ||
43 | showPassword: false, | ||
44 | passwordScore: 0, | ||
45 | }; | ||
46 | |||
47 | inputElement; | ||
48 | |||
49 | componentDidMount() { | ||
50 | if (this.props.focus) { | ||
51 | this.focus(); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | onChange(e) { | ||
56 | const { field, scorePassword } = this.props; | ||
57 | |||
58 | field.onChange(e); | ||
59 | |||
60 | if (scorePassword) { | ||
61 | this.setState({ passwordScore: scorePasswordFunc(field.value) }); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | focus() { | ||
66 | this.inputElement.focus(); | ||
67 | } | ||
68 | |||
69 | render() { | ||
70 | const { | ||
71 | field, | ||
72 | className, | ||
73 | showPasswordToggle, | ||
74 | showLabel, | ||
75 | scorePassword, | ||
76 | prefix, | ||
77 | suffix, | ||
78 | } = this.props; | ||
79 | |||
80 | const { passwordScore } = this.state; | ||
81 | |||
82 | const { intl } = this.props; | ||
83 | |||
84 | let { type } = field; | ||
85 | if (type === 'password' && this.state.showPassword) { | ||
86 | type = 'text'; | ||
87 | } | ||
88 | |||
89 | return ( | ||
90 | <div | ||
91 | className={classnames({ | ||
92 | 'franz-form__field': true, | ||
93 | 'has-error': field.error, | ||
94 | [`${className}`]: className, | ||
95 | })} | ||
96 | > | ||
97 | <div className="franz-form__input-wrapper"> | ||
98 | {prefix && <span className="franz-form__input-prefix">{prefix}</span>} | ||
99 | <input | ||
100 | id={field.id} | ||
101 | type={type} | ||
102 | className="franz-form__input" | ||
103 | name={field.name} | ||
104 | value={field.value} | ||
105 | placeholder={field.placeholder} | ||
106 | onChange={e => this.onChange(e)} | ||
107 | onBlur={field.onBlur} | ||
108 | onFocus={field.onFocus} | ||
109 | ref={element => { | ||
110 | this.inputElement = element; | ||
111 | }} | ||
112 | disabled={field.disabled} | ||
113 | /> | ||
114 | {suffix && <span className="franz-form__input-suffix">{suffix}</span>} | ||
115 | {showPasswordToggle && ( | ||
116 | <button | ||
117 | type="button" | ||
118 | className={classnames({ | ||
119 | 'franz-form__input-modifier': true, | ||
120 | })} | ||
121 | onClick={() => | ||
122 | this.setState(prevState => ({ | ||
123 | showPassword: !prevState.showPassword, | ||
124 | })) | ||
125 | } | ||
126 | tabIndex={-1} | ||
127 | aria-label={intl.formatMessage(messages.passwordToggle)} | ||
128 | > | ||
129 | <Icon icon={this.state.showPassword ? mdiEye : mdiEyeOff} /> | ||
130 | </button> | ||
131 | )} | ||
132 | {scorePassword && ( | ||
133 | <div className="franz-form__password-score"> | ||
134 | {/* <progress value={this.state.passwordScore} max="100" /> */} | ||
135 | <meter | ||
136 | value={passwordScore < 5 ? 5 : passwordScore} | ||
137 | low={30} | ||
138 | high={75} | ||
139 | optimum={100} | ||
140 | max={100} | ||
141 | /> | ||
142 | </div> | ||
143 | )} | ||
144 | </div> | ||
145 | {field.label && showLabel && ( | ||
146 | <label className="franz-form__label" htmlFor={field.name}> | ||
147 | {field.label} | ||
148 | </label> | ||
149 | )} | ||
150 | {field.error && <div className="franz-form__error">{field.error}</div>} | ||
151 | </div> | ||
152 | ); | ||
153 | } | ||
154 | } | ||
155 | |||
156 | export default injectIntl(observer(Input)); | ||