react-email icon indicating copy to clipboard operation
react-email copied to clipboard

TailwindCSS with CSS Variables

Open andrecasal opened this issue 3 years ago • 9 comments

Describe the Bug

I have a tailwind.config.ts file that uses CSS Variables:

{
	theme: {
		extend: {
			colors: {
				background: 'hsl(var(--color-background) / <alpha-value>)',
			// ...
			},
		},
	},
}

declared in a tailwind.css file:

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
	:root {
		--color-background: 0 0% 100%; /* white */
		// ...
	}
}

When using the <Tailwind config={tailwindConfig}> component, how does one load the tailwind.css file too so we can use custom Tailwind classnames?

The following does not work:

import { Container, Head, Html, Link, Tailwind, Text, Body } from '@react-email/components'
import tailwindConfig from '../../../../tailwind.config.ts'
import tailwindStylesheetUrl from '../../../styles/tailwind.css'

export function SomeEmail() {
	return (
		<Tailwind config={tailwindConfig}>
			<Html lang="en" dir="ltr">
				<Head>
					<meta charSet="utf-8" />
					<title>Welcome to André Casal!</title>
					<style type="text/css">{tailwindStylesheetUrl}</style>
				</Head>
				<Body className="bg-background">
					<Container>
						<h1>
							<Text>Welcome to André Casal!</Text>
						</h1>
					</Container>
				</Body>
			</Html>
		</Tailwind>
	)
}

Which package is affected (leave empty if unsure)

No response

Link to the code that reproduces this issue

NA

To Reproduce

NA

Expected Behavior

NA

What's your node version? (if relevant)

No response

andrecasal avatar Jun 27 '23 14:06 andrecasal

assign this issue to me.

Bharathi-Senthil avatar Jun 28 '23 13:06 Bharathi-Senthil

assign this issue to me.

Thanks @BHARATHI-GIT-HUB

bukinoshita avatar Jun 29 '23 00:06 bukinoshita

Iam not able to host locally in my device is their any pre-requirement like docker. Screenshot 2023-06-29 at 12 02 15 PM

Bharathi-Senthil avatar Jun 29 '23 06:06 Bharathi-Senthil

@BHARATHI-GIT-HUB I am running into the same issue. Is there any update for how to use CSS variables with react-email and <Tailwind />? Thanks!

LeathanTeal avatar Aug 11 '23 22:08 LeathanTeal

@andrecasal @LeathanTeal

I figured out a way to use variables directly in your <Tailwind/> component.

You can use the plugin @mertasan/tailwindcss-variables NPM: @mertasan/tailwindcss-variables

I made a gist containing a demo, you can find it here

Let me know if you have any issues

lordelogos avatar Aug 15 '23 16:08 lordelogos

Iam not able to host locally in my device is their any pre-requirement like docker. Screenshot 2023-06-29 at 12 02 15 PM

Hi @BHARATHI-GIT-HUB, Have you resolved your setup issue?

There are no pre-requirements You just need to cd into any of the projects and run the dev command. e.g

cd web
npm run dev

lordelogos avatar Aug 15 '23 16:08 lordelogos

@lordelogos Its working with mertasan plugin....

Bharathi-Senthil avatar Aug 15 '23 17:08 Bharathi-Senthil

may i know what to do further??.....

Bharathi-Senthil avatar Aug 15 '23 17:08 Bharathi-Senthil

may i know what to do further??.....

after selecting your project and setting it up locally you can now proceed to make your contribution You should also read the Contributing guidelines

lordelogos avatar Aug 15 '23 18:08 lordelogos