Skip to content

Conditional

Use HTML conditional comments effortlessly

Install

Install the component from your command line

console
pnpm install email-craft
pnpm install email-craft
console
bun install email-craft
bun install email-craft
console
npm install email-craft
npm install email-craft
console
yarn install email-craft
yarn install email-craft

Usage

Add the component to your email template. Include styles where needed.

jsx
import { Conditional, Head } from 'email-craft';

const Email = () => {
  return (
    <Head>
      <Conditional mso={true}>
        <meta content="batman" />
      </Conditional>
    </Head>
  );
};
import { Conditional, Head } from 'email-craft';

const Email = () => {
  return (
    <Head>
      <Conditional mso={true}>
        <meta content="batman" />
      </Conditional>
    </Head>
  );
};

Component Props

ts
interface ConditionalProps {
  children?: React.ReactNode;
  expression?: string;
  mso?: boolean;
}
interface ConditionalProps {
  children?: React.ReactNode;
  expression?: string;
  mso?: boolean;
}

INFO

The expression prop or the mso prop must be defined, but not both.

Props

ts
expression?: string;
expression?: string;

If provided, the string will be used as the conditional expression within the HTML comment. e.g. a value of lt ie 10 would result in a conditional comment block starting with <!--[if lt ie 10]>.

ts
mso?: boolean;
mso?: boolean;

If true, the conditional comment begins with <!--[if mso]>. If false, the conditional comment block uses a common hack and appears as <!--[if !mso]><!--> ... <!--<![endif]-->.