react-icons/ai#AiFillEyeInvisible TypeScript Examples
The following examples show how to use
react-icons/ai#AiFillEyeInvisible.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerPasswordField.tsx From bluebubbles-server with Apache License 2.0 | 5 votes |
ServerPasswordField = ({ helpText }: ServerPasswordFieldProps): JSX.Element => {
const dispatch = useAppDispatch();
const password: string = (useAppSelector(state => state.config.password) ?? '');
const [showPassword, setShowPassword] = useBoolean();
const [newPassword, setNewPassword] = useState(password);
const [passwordError, setPasswordError] = useState('');
const hasPasswordError: boolean = (passwordError?? '').length > 0;
useEffect(() => { setNewPassword(password); }, [password]);
/**
* A handler & validator for saving a new password.
*
* @param theNewPassword - The new password to save
*/
const savePassword = (theNewPassword: string): void => {
// Validate the port
if (theNewPassword.length < 8) {
setPasswordError('Your password must be at least 8 characters!');
return;
} else if (theNewPassword === password) {
setPasswordError('You have not changed the password since your last save!');
return;
}
dispatch(setConfig({ name: 'password', value: theNewPassword }));
if (hasPasswordError) setPasswordError('');
showSuccessToast({
id: 'settings',
description: 'Successfully saved new password!'
});
};
return (
<FormControl isInvalid={hasPasswordError}>
<FormLabel htmlFor='password'>Server Password</FormLabel>
<Input
id='password'
type={showPassword ? 'text' : 'password'}
maxWidth="20em"
value={newPassword}
onChange={(e) => {
if (hasPasswordError) setPasswordError('');
setNewPassword(e.target.value);
}}
/>
<IconButton
ml={3}
verticalAlign='top'
aria-label='View password'
icon={showPassword ? <AiFillEye /> : <AiFillEyeInvisible />}
onClick={() => setShowPassword.toggle()}
/>
<IconButton
ml={3}
verticalAlign='top'
aria-label='Save password'
icon={<AiOutlineSave />}
onClick={() => savePassword(newPassword)}
/>
{!hasPasswordError ? (
<FormHelperText>
{helpText ?? 'Enter a password to use for clients to authenticate with the server'}
</FormHelperText>
) : (
<FormErrorMessage>{passwordError}</FormErrorMessage>
)}
</FormControl>
);
}
Example #2
Source File: NgrokAuthTokenField.tsx From bluebubbles-server with Apache License 2.0 | 4 votes |
NgrokAuthTokenField = ({ helpText }: NgrokAuthTokenFieldProps): JSX.Element => {
const dispatch = useAppDispatch();
const ngrokToken: string = (useAppSelector(state => state.config.ngrok_key) ?? '');
const [showNgrokToken, setShowNgrokToken] = useBoolean();
const [newNgrokToken, setNewNgrokToken] = useState(ngrokToken);
const [ngrokTokenError, setNgrokTokenError] = useState('');
const hasNgrokTokenError: boolean = (ngrokTokenError ?? '').length > 0;
useEffect(() => { setNewNgrokToken(ngrokToken); }, [ngrokToken]);
/**
* A handler & validator for saving a new Ngrok auth token.
*
* @param theNewNgrokToken - The new auth token to save
*/
const saveNgrokToken = (theNewNgrokToken: string): void => {
theNewNgrokToken = theNewNgrokToken.trim();
// Validate the port
if (theNewNgrokToken === ngrokToken) {
setNgrokTokenError('You have not changed the token since your last save!');
return;
} else if (theNewNgrokToken.includes(' ')) {
setNgrokTokenError('Invalid Ngrok Auth Token! Please check that you have copied it correctly.');
return;
}
dispatch(setConfig({ name: 'ngrok_key', value: theNewNgrokToken }));
setNgrokTokenError('');
showSuccessToast({
id: 'settings',
duration: 4000,
description: 'Successfully saved new Ngrok Auth Token! Restarting Proxy service...'
});
};
return (
<FormControl isInvalid={hasNgrokTokenError}>
<FormLabel htmlFor='ngrok_key'>Ngrok Auth Token (Optional)</FormLabel>
<Input
id='password'
type={showNgrokToken ? 'text' : 'password'}
maxWidth="20em"
value={newNgrokToken}
onChange={(e) => {
if (hasNgrokTokenError) setNgrokTokenError('');
setNewNgrokToken(e.target.value);
}}
/>
<IconButton
ml={3}
verticalAlign='top'
aria-label='View Ngrok token'
icon={showNgrokToken ? <AiFillEye /> : <AiFillEyeInvisible />}
onClick={() => setShowNgrokToken.toggle()}
/>
<IconButton
ml={3}
verticalAlign='top'
aria-label='Save Ngrok token'
icon={<AiOutlineSave />}
onClick={() => saveNgrokToken(newNgrokToken)}
/>
{!hasNgrokTokenError ? (
<FormHelperText>
{helpText ?? (
<Text>
Using an Auth Token will allow you to use the benefits of the upgraded Ngrok
service. This can improve connection stability and reliability. If you do not have
an Ngrok Account, sign up for free here:
<Box as='span' color={baseTheme.colors.brand.primary}>
<Link href='https://dashboard.ngrok.com/get-started/your-authtoken' target='_blank'>ngrok.com</Link>
</Box>
</Text>
)}
</FormHelperText>
) : (
<FormErrorMessage>{ngrokTokenError}</FormErrorMessage>
)}
</FormControl>
);
}