-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(project): add password strength component
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/components/PasswordStrength/PasswordStrength.module.scss
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,48 @@ | ||
@use '../../styles/variables'; | ||
@use '../../styles/theme'; | ||
|
||
.passwordStrength { | ||
position: relative; | ||
margin: variables.$base-spacing 0; | ||
font-family: theme.$body-font-family; | ||
font-size: 14px; | ||
} | ||
|
||
.passwordStrengthBar { | ||
position: relative; | ||
width: 170px; | ||
height: 6px; | ||
margin: variables.$base-spacing 0; | ||
|
||
background: #ddd; | ||
border-radius: 5px; | ||
} | ||
|
||
.passwordStrengthFill { | ||
position: absolute; | ||
width: 0; | ||
height: inherit; | ||
background: transparent; | ||
border-radius: inherit; | ||
transition: width 0.5s ease-in-out, background 0.25s; | ||
} | ||
|
||
.passwordStrengthFill[data-strength='1'] { | ||
width: 25%; | ||
background: orangered; | ||
} | ||
|
||
.passwordStrengthFill[data-strength='2'] { | ||
width: 50%; | ||
background: orange; | ||
} | ||
|
||
.passwordStrengthFill[data-strength='3'] { | ||
width: 75%; | ||
background: yellowgreen; | ||
} | ||
|
||
.passwordStrengthFill[data-strength='4'] { | ||
width: 100%; | ||
background: green; | ||
} |
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,12 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import PasswordStrength from './PasswordStrength'; | ||
|
||
describe('<PasswordStrength>', () => { | ||
test('renders and matches snapshot', () => { | ||
const { container } = render(<PasswordStrength />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
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,20 @@ | ||
import React from 'react'; | ||
|
||
import styles from './PasswordStrength.module.scss'; | ||
|
||
type Props = { | ||
strength: number; | ||
}; | ||
|
||
const PasswordStrength: React.FC<Props> = ({ strength }: Props) => { | ||
return ( | ||
<div className={styles.passwordStrength}> | ||
<div className={styles.passwordStrengthBar}> | ||
<div className={styles.passwordStrengthFill} data-strength={strength}></div> | ||
</div> | ||
<span>Use a minimum of 6 characters (case sensitive) with at least one number or special character and one capital character</span> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PasswordStrength; |
20 changes: 20 additions & 0 deletions
20
src/components/PasswordStrength/__snapshots__/PasswordStrength.test.tsx.snap
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,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<PasswordStrength> renders and matches snapshot 1`] = ` | ||
<div> | ||
<div | ||
class="passwordStrength" | ||
> | ||
<div | ||
class="passwordStrengthBar" | ||
> | ||
<div | ||
class="passwordStrengthFill" | ||
/> | ||
</div> | ||
<span> | ||
Use a minimum of 6 characters (case sensitive) with at least one number or special character and one capital character | ||
</span> | ||
</div> | ||
</div> | ||
`; |