-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2597 from getAlby/refactor-passwordview
refactor: refactor password view into separate component
- Loading branch information
Showing
14 changed files
with
167 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { | ||
HiddenIcon, | ||
VisibleIcon, | ||
} from "@bitcoin-design/bitcoin-icons-react/outline"; | ||
import { useEffect, useState } from "react"; | ||
|
||
type Props = { | ||
onChange: (viewingPassword: boolean) => void; | ||
isRevealed?: boolean; | ||
}; | ||
|
||
export default function PasswordViewAdornment({ onChange, isRevealed }: Props) { | ||
const [_isRevealed, setRevealed] = useState(false); | ||
|
||
// toggle the button if password view is handled by component itself | ||
useEffect(() => { | ||
if (typeof isRevealed !== "undefined") { | ||
setRevealed(isRevealed); | ||
} | ||
}, [isRevealed]); | ||
|
||
return ( | ||
<button | ||
type="button" | ||
tabIndex={-1} | ||
className="flex justify-center items-center w-10 h-8" | ||
onClick={() => { | ||
setRevealed(!_isRevealed); | ||
onChange(!_isRevealed); | ||
}} | ||
> | ||
{_isRevealed ? ( | ||
<VisibleIcon className="h-6 w-6" /> | ||
) : ( | ||
<HiddenIcon className="h-6 w-6" /> | ||
)} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.