diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-09-14 19:58:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 19:58:52 +0200 |
commit | 95df3522a15631abc51a4295cae0ea401a8d4e1e (patch) | |
tree | e5eb0f368c947683f01458e912f21756fb0d99cb /packages/forms | |
parent | docs: add sad270 as a contributor for bug, userTesting [skip ci] (#1941) (diff) | |
download | ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.tar.gz ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.tar.zst ferdium-app-95df3522a15631abc51a4295cae0ea401a8d4e1e.zip |
feat: add eslint-plugin-unicorn (#1936)
Diffstat (limited to 'packages/forms')
-rw-r--r-- | packages/forms/src/button/index.tsx | 70 | ||||
-rw-r--r-- | packages/forms/src/input/scorePassword.ts | 10 | ||||
-rw-r--r-- | packages/forms/src/select/index.tsx | 7 |
3 files changed, 40 insertions, 47 deletions
diff --git a/packages/forms/src/button/index.tsx b/packages/forms/src/button/index.tsx index 48fb61635..c9ae47d55 100644 --- a/packages/forms/src/button/index.tsx +++ b/packages/forms/src/button/index.tsx | |||
@@ -227,44 +227,38 @@ class ButtonComponent extends Component<IProps> { | |||
227 | </> | 227 | </> |
228 | ); | 228 | ); |
229 | 229 | ||
230 | let wrapperComponent: JSX.Element; | 230 | const wrapperComponent = !href ? ( |
231 | 231 | <button | |
232 | if (!href) { | 232 | id={id} |
233 | wrapperComponent = ( | 233 | type={type} |
234 | <button | 234 | onClick={onClick} |
235 | id={id} | 235 | className={classnames({ |
236 | type={type} | 236 | [`${classes.button}`]: true, |
237 | onClick={onClick} | 237 | [`${classes[buttonType as ButtonType]}`]: true, |
238 | className={classnames({ | 238 | [`${classes.disabled}`]: disabled, |
239 | [`${classes.button}`]: true, | 239 | [`${className}`]: className, |
240 | [`${classes[buttonType as ButtonType]}`]: true, | 240 | })} |
241 | [`${classes.disabled}`]: disabled, | 241 | disabled={disabled} |
242 | [`${className}`]: className, | 242 | data-type="franz-button" |
243 | })} | 243 | > |
244 | disabled={disabled} | 244 | {content} |
245 | data-type="franz-button" | 245 | </button> |
246 | > | 246 | ) : ( |
247 | {content} | 247 | <a |
248 | </button> | 248 | href={href} |
249 | ); | 249 | target={target} |
250 | } else { | 250 | onClick={onClick} |
251 | wrapperComponent = ( | 251 | className={classnames({ |
252 | <a | 252 | [`${classes.button}`]: true, |
253 | href={href} | 253 | [`${classes[buttonType as ButtonType]}`]: true, |
254 | target={target} | 254 | [`${className}`]: className, |
255 | onClick={onClick} | 255 | })} |
256 | className={classnames({ | 256 | rel={target === '_blank' ? 'noopener' : ''} |
257 | [`${classes.button}`]: true, | 257 | data-type="franz-button" |
258 | [`${classes[buttonType as ButtonType]}`]: true, | 258 | > |
259 | [`${className}`]: className, | 259 | {content} |
260 | })} | 260 | </a> |
261 | rel={target === '_blank' ? 'noopener' : ''} | 261 | ); |
262 | data-type="franz-button" | ||
263 | > | ||
264 | {content} | ||
265 | </a> | ||
266 | ); | ||
267 | } | ||
268 | 262 | ||
269 | return wrapperComponent; | 263 | return wrapperComponent; |
270 | } | 264 | } |
diff --git a/packages/forms/src/input/scorePassword.ts b/packages/forms/src/input/scorePassword.ts index bc30de4b8..59502e2b0 100644 --- a/packages/forms/src/input/scorePassword.ts +++ b/packages/forms/src/input/scorePassword.ts | |||
@@ -18,9 +18,9 @@ export function scorePasswordFunc(password: string): number { | |||
18 | 18 | ||
19 | // award every unique letter until 5 repetitions | 19 | // award every unique letter until 5 repetitions |
20 | const letters: ILetters = {}; | 20 | const letters: ILetters = {}; |
21 | for (let i = 0; i < password.length; i += 1) { | 21 | for (const element of password) { |
22 | letters[password[i]] = (letters[password[i]] || 0) + 1; | 22 | letters[element] = (letters[element] || 0) + 1; |
23 | score += 5.0 / letters[password[i]]; | 23 | score += 5 / letters[element]; |
24 | } | 24 | } |
25 | 25 | ||
26 | // bonus points for mixing it up | 26 | // bonus points for mixing it up |
@@ -32,9 +32,9 @@ export function scorePasswordFunc(password: string): number { | |||
32 | }; | 32 | }; |
33 | 33 | ||
34 | let variationCount = 0; | 34 | let variationCount = 0; |
35 | Object.keys(variations).forEach(key => { | 35 | for (const key of Object.keys(variations)) { |
36 | variationCount += variations[key] === true ? 1 : 0; | 36 | variationCount += variations[key] === true ? 1 : 0; |
37 | }); | 37 | } |
38 | 38 | ||
39 | score += (variationCount - 1) * 10; | 39 | score += (variationCount - 1) * 10; |
40 | 40 | ||
diff --git a/packages/forms/src/select/index.tsx b/packages/forms/src/select/index.tsx index d7479f63e..7806baa2a 100644 --- a/packages/forms/src/select/index.tsx +++ b/packages/forms/src/select/index.tsx | |||
@@ -187,10 +187,8 @@ class SelectComponent extends Component<IProps> { | |||
187 | componentDidUpdate() { | 187 | componentDidUpdate() { |
188 | const { open } = this.state; | 188 | const { open } = this.state; |
189 | 189 | ||
190 | if (this.searchInputRef && this.searchInputRef.current) { | 190 | if (this.searchInputRef && this.searchInputRef.current && open) { |
191 | if (open) { | 191 | this.searchInputRef.current.focus(); |
192 | this.searchInputRef.current.focus(); | ||
193 | } | ||
194 | } | 192 | } |
195 | } | 193 | } |
196 | 194 | ||
@@ -228,6 +226,7 @@ class SelectComponent extends Component<IProps> { | |||
228 | } | 226 | } |
229 | 227 | ||
230 | componentWillUnmount() { | 228 | componentWillUnmount() { |
229 | // eslint-disable-next-line unicorn/no-invalid-remove-event-listener | ||
231 | window.removeEventListener('keydown', this.arrowKeysHandler.bind(this)); | 230 | window.removeEventListener('keydown', this.arrowKeysHandler.bind(this)); |
232 | } | 231 | } |
233 | 232 | ||