samuelweckstrom / react-ascii-text Goto Github PK
View Code? Open in Web Editor NEWASCII text art renderer
ASCII text art renderer
Cool project thanks for this!
Goal: I am wanting to get my ascii text to animate, but only once. So noting shows, then the animation shows, and once the animation finishes (for the first time), it stays on the screen; static.
The fadeIn
property doesn't seem to do anything for me. IDK what the originaly intent for fadeIn
was; but I noticed that fadeIn
wasn't documented in the read me. Maybe this was removed on purpose?
Here's a hacky work around I found: pass an array to text
and set isPaused
to a boolean state variable that you mutate in a useEffect
after the first string in the array has finished animating using setTimeout
.
export default function Banner() {
const [paused, setPaused] = useState(false)
useEffect(() => {
setTimeout(() => {
setPaused(true)
}, 1000)
}, [])
const asciiTextRef = useAsciiText({
animationCharacters: '▒ ░ █',
font: ansiShadow,
text: ['MY STRING', 'MT STRING'],
fadeIn: true,
animationDirection: 'down',
isPaused: paused,
})
return (
<div className='h-48'>
<h1 className='text-z-red text-2xl'>
<pre ref={asciiTextRef}></pre>
</h1>
</div>
)
}
When I do this, basic example:
export default function Banner() {
const asciiTextRef = useAsciiText({
animationCharacters: '▒ ░ █',
font: ansiShadow,
text: ['MY STRING', 'MY STRING'],
fadeIn: true,
animationDirection: 'down',
})
return (
<div className='h-48'>
<h1 className='text-z-red text-2xl'>
<pre ref={asciiTextRef}></pre>
</h1>
</div>
)
}
I get this type error:
Diagnostics:
1. Type 'MutableRefObject<HTMLPreElement | undefined>' is not assignable to type 'LegacyRef<HTMLPreElement> | undefined'.
Type 'MutableRefObject<HTMLPreElement | undefined>' is not assignable to type 'RefObject<HTMLPreElement>'.
Types of property 'current' are incompatible.
Type 'HTMLPreElement | undefined' is not assignable to type 'HTMLPreElement | null'.
Type 'undefined' is not assignable to type 'HTMLPreElement | null'. [2322]
Work around:
export default function Banner() {
const asciiTextRef = useAsciiText({
animationCharacters: '▒ ░ █',
font: ansiShadow,
text: ['MY STRING', 'MY STRING'],
fadeIn: true,
animationDirection: 'down',
})
// Using a ref callback to bridge the type mismatch.
const refCallback = (element: HTMLPreElement | null) => {
if (asciiTextRef) {
// Directly manipulate the `.current` property only if it's not `undefined`.
asciiTextRef.current = element ?? undefined // Convert `null` to `undefined`.
}
}
return (
<div className='h-48'>
<h1 className='text-z-red text-2xl'>
<pre ref={refCallback}></pre>
</h1>
</div>
)
}
This package is really cool! I love it!
Feature request: new hook useAsciiArt()
Instead of rendering text with the font, it will render the actual ASCII art we already have, taking care of the spaces and applying animations.
Thanks a lot for providing this react package. It works like a charm other than 1 scenario I'm currently facing:
However, the last instance seems to override the font of all the other instances.
I wonder if there's a workaround you could think of?
Many thanks
fred
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.