一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
50 行
1.4 KiB
TypeScript
50 行
1.4 KiB
TypeScript
import * as React from 'react';
|
|
import { useState, useCallback } from 'react';
|
|
import StyledInput from '../style/StyledInput';
|
|
import { _ } from '@joplin/lib/locale';
|
|
import { ChangeEventHandler } from './types';
|
|
|
|
interface Props {
|
|
value: string;
|
|
inputId: string;
|
|
onChange: ChangeEventHandler;
|
|
onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
|
|
inputRef?: React.Ref<HTMLInputElement>;
|
|
|
|
'aria-invalid'?: boolean;
|
|
'aria-errormessage'?: string;
|
|
}
|
|
|
|
const PasswordInput = (props: Props) => {
|
|
const [showPassword, setShowPassword] = useState(false);
|
|
|
|
const inputType = showPassword ? 'text' : 'password';
|
|
const icon = showPassword ? 'far fa-eye-slash' : 'far fa-eye';
|
|
const title = showPassword ? _('Hide password') : _('Show password');
|
|
|
|
const onShowPassword = useCallback(() => {
|
|
setShowPassword(current => !current);
|
|
}, []);
|
|
|
|
return (
|
|
<div className="password-input">
|
|
<StyledInput
|
|
id={props.inputId}
|
|
aria-errormessage={props['aria-errormessage']}
|
|
aria-invalid={props['aria-invalid']}
|
|
className="field"
|
|
type={inputType}
|
|
value={props.value}
|
|
onChange={props.onChange}
|
|
onKeyDown={props.onKeyDown}
|
|
ref={props.inputRef}
|
|
/>
|
|
<button type="button" onClick={onShowPassword} className="showpasswordbutton">
|
|
<i className={icon} role='img' aria-label={title} title={title}></i>
|
|
</button>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default PasswordInput;
|