Skip to content

Instantly share code, notes, and snippets.

@MarceloAlves
Created July 9, 2021 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarceloAlves/7c49bc3a5cf578baa3f5ee51ecade639 to your computer and use it in GitHub Desktop.
Save MarceloAlves/7c49bc3a5cf578baa3f5ee51ecade639 to your computer and use it in GitHub Desktop.
interface Props {
text: string
}
export default function FitText({ text }: Props) {
return (
<div style={{ paddingLeft: 10 }}>
<svg
viewBox={`0 0 ${text.length * 16.5} 30`}
preserveAspectRatio='xMidYMin meet'
xmlns='http://www.w3.org/2000/svg'
xmlnsXlink='http://www.w3.org/1999/xlink'
width='600px'
height='150px'
overflow='visible'
>
<defs>
<linearGradient id='gradient' x1='20.791%' x2='0%' y1='97.815%' y2='0%'>
<stop offset='0%' stopColor='rgb(255,109,0)' stopOpacity='1' />
<stop offset='53%' stopColor='rgb(255,182,0)' stopOpacity='1' />
<stop offset='100%' stopColor='rgb(255,255,0)' stopOpacity='1' />
</linearGradient>
</defs>
<text
x='50%'
y='50%'
fontFamily='BadaBoom BB'
fontSize={34}
textAnchor='middle'
strokeWidth='1px'
stroke='black'
fill='url(#gradient)'
letterSpacing='2px'
dominantBaseline='middle'
>
{text}
</text>
</svg>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment