We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hey, I am using NextJS + styled-components template. I want help in making a gradient of random color to black
SomeThing Like This
const Container = tw`from-[randomColor] to-black bg-gradient-to-b`
I am getting error
Below is my code ⬇️⬇️⬇️
const Component= () => { const [randomColor, setRandomColor] = useState(null); const getRandomColor = () => `hsl(${360 * Math.random()}, ${25 + 70 * Math.random()}%, ${ 75 + 10 * Math.random() }%)`; useEffect(() => { setColor(`from-[${getRandomColor ()}]`); }, []); return <div css={`${ tw` from-[${randomColor}] to-black bg-gradient-to-b ` }`} > Something... </div> }
The text was updated successfully, but these errors were encountered:
Hey there
Unfortunately, twin can't translate random values - you'll have to use plain old css for that 😭
Something like this:
const Component = () => { const [randomColor, setRandomColor] = useState(null) const getRandomColor = () => `hsl(${360 * Math.random()}, ${25 + 70 * Math.random()}%, ${ 75 + 10 * Math.random() }%)` useEffect(() => { setRandomColor(getRandomColor()) }, []) const styles = [ tw`to-black bg-gradient-to-b`, { '--tw-gradient-from': randomColor, '--tw-gradient-stops': `var(--tw-gradient-from), var(--tw-gradient-to, ${randomColor})`, }, ] return <div css={styles}>Something...</div> }
Sorry, something went wrong.
Thanks, @ben-rogerson and team. Twin.macro is fantastic 💖
No branches or pull requests
Hey, I am using NextJS + styled-components template.
I want help in making a gradient of random color to black
SomeThing Like This
I am getting error
Below is my code ⬇️⬇️⬇️
The text was updated successfully, but these errors were encountered: