diff --git a/app/soapbox/components/showable_password.js b/app/soapbox/components/showable_password.js new file mode 100644 index 000000000..a6dbdad24 --- /dev/null +++ b/app/soapbox/components/showable_password.js @@ -0,0 +1,64 @@ +import React from 'react'; +import ImmutablePureComponent from 'react-immutable-pure-component'; +import { defineMessages, injectIntl } from 'react-intl'; +import PropTypes from 'prop-types'; +import classNames from 'classnames'; +import IconButton from 'soapbox/components/icon_button'; +import { FormPropTypes, InputContainer, LabelInputContainer } from 'soapbox/features/forms'; + +const messages = defineMessages({ + showPassword: { id: 'forms.show_password', defaultMessage: 'Show password' }, + hidePassword: { id: 'forms.hide_password', defaultMessage: 'Hide password' }, +}); + +export default @injectIntl +class ShowablePassword extends ImmutablePureComponent { + + static propTypes = { + intl: PropTypes.object.isRequired, + label: FormPropTypes.label, + className: PropTypes.string, + hint: PropTypes.node, + error: PropTypes.bool, + } + + state = { + revealed: false, + } + + toggleReveal = () => { + if (this.props.onToggleVisibility) { + this.props.onToggleVisibility(); + } else { + this.setState({ revealed: !this.state.revealed }); + } + } + + render() { + const { intl, hint, error, label, className, ...props } = this.props; + const { revealed } = this.state; + + const revealButton = ( + + ); + + return ( + + {label ? ( + + + {revealButton} + + ) : (<> + + {revealButton} + )} + + ); + } + +} \ No newline at end of file diff --git a/app/soapbox/features/auth_login/components/login_form.js b/app/soapbox/features/auth_login/components/login_form.js index 842e38832..fbfe4afb3 100644 --- a/app/soapbox/features/auth_login/components/login_form.js +++ b/app/soapbox/features/auth_login/components/login_form.js @@ -5,6 +5,7 @@ import { Link } from 'react-router-dom'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { getFeatures } from 'soapbox/utils/features'; import { getBaseURL } from 'soapbox/utils/state'; +import ShowablePassword from 'soapbox/components/showable_password'; const messages = defineMessages({ username: { id: 'login.fields.username_placeholder', defaultMessage: 'Username' }, @@ -45,19 +46,21 @@ class LoginForm extends ImmutablePureComponent { required /> -
+ + {/*
-
+
*/}

{hasResetPasswordAPI ? ( diff --git a/app/soapbox/features/auth_login/components/registration_form.js b/app/soapbox/features/auth_login/components/registration_form.js index a4c52ef62..ff8c987ae 100644 --- a/app/soapbox/features/auth_login/components/registration_form.js +++ b/app/soapbox/features/auth_login/components/registration_form.js @@ -5,6 +5,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import { connect } from 'react-redux'; import { injectIntl, FormattedMessage, defineMessages } from 'react-intl'; import { Link } from 'react-router-dom'; +import ShowablePassword from 'soapbox/components/showable_password'; import { SimpleForm, SimpleInput, @@ -231,7 +232,7 @@ class RegistrationForm extends ImmutablePureComponent { )} - - - {intl.formatMessage(messages.passwordHeader)}

- - -
-
-
-