Loading...
Loading...
Style Canvas components with Tailwind CSS 4 theme tokens and approved utility patterns. Use when (1) Creating a new component, (2) Adding colors or styling to components, (3) Working with Tailwind theme tokens, (4) Adding or updating design tokens in global.css, (5) Creating color/style props, (6) Any change where component props are added/removed/renamed/retyped and can affect rendered styles. Covers @theme variables, CVA variants, and cn() utility.
npx skill4agent add drupal-canvas/skills canvas-styling-conventions| Technology | Purpose |
|---|---|
| Tailwind CSS 4.1+ | Styling |
| class-variance-authority (CVA) | Component variants |
| Class name merging |
primary-*gray-*global.csscn()clsxtailwind-mergeimport { cn } from '@/lib/utils';
// or
import { cn } from 'drupal-canvas';const Button = ({ variant, className, children }) => (
<button
className={cn(
'rounded px-4 py-2',
variant === 'primary' && 'bg-primary-600 text-white',
variant === 'secondary' && 'bg-gray-200 text-gray-800',
className,
)}
>
{children}
</button>
);classNamecn()const Card = ({ colorScheme, className, children }) => (
<div className={cn(cardVariants({ colorScheme }), className)}>{children}</div>
);classNameclassNamecomponent.yml@themeglobal.css@theme { }global.css@theme@themeCSS Variable in | Generated Utility Classes |
|---|---|
| |
| |
| |
| |
--{namespace}-{name}{utility}-{name}global.css@theme {
--color-primary-600: #1899cb;
--color-primary-700: #1487b4;
}// Correct
<button className="bg-primary-600 hover:bg-primary-700 text-white">
Click me
</button>
// Wrong
<button className="bg-[#1899cb] text-white hover:bg-[#1487b4]">Click me</button>bg-[#xxx]@theme@theme {
--color-primary-700: #1487b4;
--color-primary-dark: var(--color-primary-700);
}bg-primary-700bg-primary-darkprimary-dark@themeglobal.css--color-accent@theme {
/* Existing tokens */
--color-primary-600: #1899cb;
/* New token for a success state */
--color-success: #22c55e;
--color-success-dark: #16a34a;
}bg-successtext-success-darkglobal.cssprimary-100primary-900primary-darkglobal.cssglobal.cssprimary-*gray-*# Wrong
props:
properties:
backgroundColor:
title: Background Color
type: string
examples:
- '#3b82f6'// Wrong
const Card = ({ backgroundColor }) => (
<div style={{ backgroundColor }}>{/* ... */}</div>
);# Correct
props:
properties:
colorScheme:
title: Color Scheme
type: string
enum:
- default
- primary
- muted
- dark
meta:enum:
default: Default (White)
primary: Primary (Blue)
muted: Muted (Light Gray)
dark: Dark
examples:
- default// Correct
import { cva } from 'class-variance-authority';
const cardVariants = cva('rounded-lg p-6', {
variants: {
colorScheme: {
default: 'bg-white text-black',
primary: 'bg-primary-600 text-white',
muted: 'bg-gray-100 text-gray-700',
dark: 'bg-gray-900 text-white',
},
},
defaultVariants: {
colorScheme: 'default',
},
});
const Card = ({ colorScheme, children }) => (
<div className={cardVariants({ colorScheme })}>{children}</div>
);global.css