Animated Cursor with Styled Components
Created
December 30, 2021 20:40
-
-
Save GGrassiant/d32e815407334abfb75ad8dd47a8b3a6 to your computer and use it in GitHub Desktop.
Animated Cursor
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
const fadeIn = (length: number): Keyframes => keyframes` | |
from { | |
width: 0 | |
} | |
to { | |
width: ${length}ch; | |
} | |
`; | |
const blink = keyframes` | |
50% { | |
border-color: transparent | |
} | |
`; | |
const DynamicParagraph = styled.p<DynamicParagraphProps>` | |
width: ${({ length }) => length + 'ch'}; | |
white-space: nowrap; | |
overflow: hidden; | |
box-sizing: revert; | |
border-right: ${({ showCursor }) => (showCursor ? '3px solid' : 'none')}; | |
animation: ${(props) => | |
props.length | |
? css` | |
${fadeIn( | |
props.length, | |
)} 2s steps(${props.length}) 800ms both, ${blink} .5s step-end infinite alternate | |
` | |
: ''}; | |
color: ${({ theme }) => theme.main.fontColor.outputColor}; | |
`; | |
DynamicParagraph.displayName = 'DynamicParagraph'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment