Skip to content

Instantly share code, notes, and snippets.

@valtism
Last active May 3, 2022 01:57
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 valtism/76589d26505517444f6a2afe7704f24d to your computer and use it in GitHub Desktop.
Save valtism/76589d26505517444f6a2afe7704f24d to your computer and use it in GitHub Desktop.
Comparing EmotionCSS to TailwindCSS
// Emotion
const Label = styled.div<Pick<BreadcrumbProps, "isActive">>(
({ theme, isActive }) => [
{
...theme.typography.DetailLargeM,
...theme.typography.noWrap,
color: theme.colors.contentTertiary,
},
isActive && {
color: theme.colors.contentPrimary,
"&:hover": {
textDecoration: "underline",
},
},
],
);
export const Breadcrumb: React.VFC<BreadcrumbProps> = ({
label,
isActive,
}) => {
return (
<Label isActive={isActive}>
{label}
</Label>
);
};
// ---
// Tailwind
function Label({ isActive, children }) {
return (
<div
className={clsx(
"text-detail-large-m whitespace-nowrap text-content-tertiary",
isActive && "text-content-primary hover:underline",
)}
>
{children}
</div>
);
}
export const Breadcrumb: React.VFC<BreadcrumbProps> = ({
label,
isActive,
}) => {
return (
<Label isActive={isActive}>
{label}
</Label>
);
};
@valtism
Copy link
Author

valtism commented May 3, 2022

A nice thing here is that you don't have to import anything like styled. We are importing clsx however for the conditional formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment