-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add length control and new visuals
- Loading branch information
1 parent
bd94dd9
commit e374b70
Showing
13 changed files
with
219 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { CSSProperties } from 'react' | ||
import { sample } from './utils/sample' | ||
import { getVerticalLinesStyle } from './styles/getVerticalLinesStyle' | ||
import { getSquareAndVerticalLinesStyle } from './styles/getSquareAndVerticalLinesStyle' | ||
import { getBigCircleDottedStyle } from './styles/getBigCircleDottedStyle' | ||
import { getBigDotsStyle } from './styles/getBigDotsStyle' | ||
import { isUpperCaseLetter } from './utils/is-upper-case-letter' | ||
import { isSymbol } from './utils/is-symbol' | ||
import { isNumber } from './utils/is-number' | ||
|
||
type ColorizedLetterStyles = { | ||
classNames: string | ||
style: CSSProperties | ||
} | ||
|
||
interface ColorizedLetterProps { | ||
letter: string | ||
} | ||
export function ColorizedLetter({ letter }: ColorizedLetterProps) { | ||
const { classNames, style } = getStyles(letter) | ||
return ( | ||
<span className={classNames} style={style}> | ||
{letter} | ||
</span> | ||
) | ||
} | ||
|
||
function getStyles(letter: string): ColorizedLetterStyles { | ||
let classNames = 'text-white' | ||
let style: CSSProperties = {} | ||
if (isNumber(letter)) { | ||
classNames = 'text-orange-600' | ||
style = getBigDotsStyle() | ||
} else if (isSymbol(letter)) { | ||
classNames = 'text-lime-600' | ||
style = getBigCircleDottedStyle() | ||
style.textShadow = 'rgb(116 255 77 / 60%) -1px -1px 6px, rgb(124 127 255 / 0%) 1px 1px 6px' | ||
} else if (isUpperCaseLetter(letter)) { | ||
classNames = 'text-white/50' | ||
style = getSquareAndVerticalLinesStyle() | ||
} else { | ||
classNames = 'text-white px-4' | ||
style = getVerticalLinesStyle() | ||
} | ||
|
||
const duration = sample(['duration-500', 'duration-700', 'duration-1000']) | ||
|
||
classNames = `${duration} hover:scale-150 inline-block ${classNames}` | ||
|
||
return { | ||
classNames, | ||
style | ||
} | ||
} |
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,14 @@ | ||
import { ColorizedLetter } from './colorized-letter' | ||
|
||
interface ColorizedPasswordProps { | ||
password: string | ||
} | ||
export function ColorizedPassword({ password }: ColorizedPasswordProps) { | ||
return ( | ||
<div className='font-mono font-black text-4xl min-h-min tracking-widest cursor-pointer'> | ||
{password.split('').map((letter, i) => ( | ||
<ColorizedLetter key={i} letter={letter} /> | ||
))} | ||
</div> | ||
) | ||
} |
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,7 @@ | ||
const LETTERS = 'abcdefghijklmnopqrstuvwxyz' | ||
export const NUMBERS = '0123456789' | ||
export const SYMBOLS = '\'\\¡!"·$%&()=€@[]{}^/+-*' | ||
export const UPPER_CASE_LETTERS_LIST = LETTERS.toUpperCase().split('') | ||
export const LOWER_CASE_LETTERS_LIST = LETTERS.toLowerCase().split('') | ||
export const NUMBERS_LIST = NUMBERS.split('') | ||
export const SYMBOLS_LIST = SYMBOLS.split('') |
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
16 changes: 16 additions & 0 deletions
16
src/components/javigaralva/styles/getBigCircleDottedStyle.tsx
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,16 @@ | ||
import { CSSProperties } from 'react' | ||
import { random } from '../utils/random' | ||
|
||
export function getBigCircleDottedStyle() { | ||
const style: CSSProperties = {} | ||
const width = 8 + random(-4, 2) | ||
const offset = 204 + random(-100, 100) | ||
const alpha = 6 + random(-2, 2) | ||
const color = 124 + random(-25, 75) | ||
style.outlineOffset = `${offset}px` | ||
style.outlineColor = `hsl(${color}deg 100% 50% / ${alpha}%)` | ||
style.outlineWidth = `${width}px` | ||
style.outlineStyle = 'dotted' | ||
style.borderRadius = '50%' | ||
return style | ||
} |
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,16 @@ | ||
import { CSSProperties } from 'react' | ||
import { random } from '../utils/random' | ||
|
||
export function getBigDotsStyle() { | ||
const style: CSSProperties = {} | ||
const width = 128 + random(-100, 100) | ||
const offset = 154 + random(-100, 100) | ||
const alpha = 2 + random(-1, 6) | ||
const color = 0 + random(-10, 40) | ||
style.outlineOffset = `${offset}px` | ||
style.outlineColor = `hsl(${color}deg 100% 50% / ${alpha}%)` | ||
style.outlineWidth = `${width}px` | ||
style.outlineStyle = 'dotted' | ||
style.borderRadius = '50%' | ||
return style | ||
} |
25 changes: 25 additions & 0 deletions
25
src/components/javigaralva/styles/getSquareAndVerticalLinesStyle.tsx
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,25 @@ | ||
import { CSSProperties } from 'react' | ||
import { random } from '../utils/random' | ||
|
||
export function getSquareAndVerticalLinesStyle() { | ||
const style: CSSProperties = {} | ||
{ | ||
const width = 28 + random(-10, 10) | ||
const alpha = 4 + random(-2, 2) | ||
const offset = 54 + random(-50, 50) | ||
const color = 0 + random(50, 100) | ||
style.outlineOffset = `${offset}px` | ||
style.outlineColor = `hsl(${color}deg 100% 50% / ${alpha}%)` | ||
style.outlineWidth = `${width}px` | ||
style.outlineStyle = 'dashed' | ||
} | ||
{ | ||
const thickness = 380 + random(-200, 100) | ||
const alpha = 4 + random(-2, 2) | ||
const color = 0 + random(100, 150) | ||
style.textDecorationLine = 'underline' | ||
style.textDecorationColor = `hsl(${color}deg 100% 50% / ${alpha}%)` | ||
style.textDecorationThickness = `${thickness}px` | ||
} | ||
return style | ||
} |
13 changes: 13 additions & 0 deletions
13
src/components/javigaralva/styles/getVerticalLinesStyle.tsx
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,13 @@ | ||
import { CSSProperties } from 'react' | ||
import { random } from '../utils/random' | ||
|
||
export function getVerticalLinesStyle() { | ||
const style: CSSProperties = {} | ||
const thickness = 380 + random(-200, 100) | ||
const alpha = 4 + random(-2, 2) | ||
style.textDecorationLine = 'overline' | ||
const color = 0 + random(50, 100) | ||
style.textDecorationColor = `hsl(${color}deg 100% 50% / ${alpha}%)` | ||
style.textDecorationThickness = `${thickness}px` | ||
return style | ||
} |
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,5 @@ | ||
import { NUMBERS } from '../constants' | ||
|
||
export function isNumber(letter: string) { | ||
return NUMBERS.includes(letter) | ||
} |
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,5 @@ | ||
import { SYMBOLS } from '../constants' | ||
|
||
export function isSymbol(letter: string) { | ||
return SYMBOLS.includes(letter) | ||
} |
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,5 @@ | ||
import { UPPER_CASE_LETTERS_LIST } from '../constants' | ||
|
||
export function isUpperCaseLetter(letter: string) { | ||
return UPPER_CASE_LETTERS_LIST.includes(letter) | ||
} |
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,3 @@ | ||
export function random(min: number, max: number) { | ||
return Math.floor(Math.random() * (max - min + 1) + min) | ||
} |
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,3 @@ | ||
export function sample<T>(arr: T[]) { | ||
return arr[Math.floor(Math.random() * arr.length)] | ||
} |