diff --git a/app/soapbox/components/showable_password.js b/app/soapbox/components/showable_password.js deleted file mode 100644 index a8ebb0786..000000000 --- a/app/soapbox/components/showable_password.js +++ /dev/null @@ -1,65 +0,0 @@ -import classNames from 'classnames'; -import PropTypes from 'prop-types'; -import React from 'react'; -import ImmutablePureComponent from 'react-immutable-pure-component'; -import { defineMessages, injectIntl } from 'react-intl'; - -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} - )} - - ); - } - -} diff --git a/app/soapbox/components/showable_password.tsx b/app/soapbox/components/showable_password.tsx new file mode 100644 index 000000000..40835decd --- /dev/null +++ b/app/soapbox/components/showable_password.tsx @@ -0,0 +1,58 @@ +import classNames from 'classnames'; +import React, { useState } from 'react'; +import { defineMessages, useIntl } from 'react-intl'; + +import IconButton from 'soapbox/components/icon_button'; +import { 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' }, +}); + +interface IShowablePassword { + label?: React.ReactNode, + className?: string, + hint?: React.ReactNode, + error?: boolean, + onToggleVisibility?: () => void, +} + +const ShowablePassword: React.FC = (props) => { + const intl = useIntl(); + const [revealed, setRevealed] = useState(false); + + const { hint, error, label, className, ...rest } = props; + + const toggleReveal = () => { + if (props.onToggleVisibility) { + props.onToggleVisibility(); + } else { + setRevealed(!revealed); + } + }; + + const revealButton = ( + + ); + + return ( + + {label ? ( + + + {revealButton} + + ) : (<> + + {revealButton} + )} + + ); +}; + +export default ShowablePassword; diff --git a/app/soapbox/features/forms/index.js b/app/soapbox/features/forms/index.js deleted file mode 100644 index 06bddefa9..000000000 --- a/app/soapbox/features/forms/index.js +++ /dev/null @@ -1,314 +0,0 @@ -import classNames from 'classnames'; -import PropTypes from 'prop-types'; -import React, { useState } from 'react'; -import ImmutablePureComponent from 'react-immutable-pure-component'; -import { FormattedMessage } from 'react-intl'; -import { v4 as uuidv4 } from 'uuid'; - -import { Text, Select } from '../../components/ui'; - -export const FormPropTypes = { - label: PropTypes.oneOfType([ - PropTypes.string, - PropTypes.object, - PropTypes.node, - ]), -}; - -export const InputContainer = (props) => { - const containerClass = classNames('input', { - 'with_label': props.label, - 'required': props.required, - 'boolean': props.type === 'checkbox', - 'field_with_errors': props.error, - }, props.extraClass); - - return ( -
- {props.children} - {props.hint && {props.hint}} -
- ); -}; - -InputContainer.propTypes = { - label: FormPropTypes.label, - hint: PropTypes.node, - required: PropTypes.bool, - type: PropTypes.string, - children: PropTypes.node, - extraClass: PropTypes.string, - error: PropTypes.bool, -}; - -export const LabelInputContainer = ({ label, hint, children, ...props }) => { - const [id] = useState(uuidv4()); - const childrenWithProps = React.Children.map(children, child => ( - React.cloneElement(child, { id: id, key: id }) - )); - - return ( -
- -
- {childrenWithProps} -
- {hint && {hint}} -
- ); -}; - -LabelInputContainer.propTypes = { - label: FormPropTypes.label.isRequired, - hint: PropTypes.node, - children: PropTypes.node, -}; - -export const LabelInput = ({ label, dispatch, ...props }) => ( - - - -); - -LabelInput.propTypes = { - label: FormPropTypes.label.isRequired, - dispatch: PropTypes.func, -}; - -export const LabelTextarea = ({ label, dispatch, ...props }) => ( - -