Skip to content

Instantly share code, notes, and snippets.

@GGrassiant
Created December 30, 2021 20:40
Show Gist options
  • Save GGrassiant/d32e815407334abfb75ad8dd47a8b3a6 to your computer and use it in GitHub Desktop.
Save GGrassiant/d32e815407334abfb75ad8dd47a8b3a6 to your computer and use it in GitHub Desktop.
Animated Cursor

Animated Cursor with Styled Components

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