Code Components - Brand Kit
Brand Kit fonts and colors can be managed from a local codebase with the Canvas CLI. This lets you keep the fonts and colors used by Canvas in source control alongside Code Components and pages.
canvas pull and canvas push include the Brand Kit by default. Use
--no-include-brand-kit, or set CANVAS_INCLUDE_BRAND_KIT=false, to skip it
for a run.
npx canvas pullnpx canvas pushnpx canvas push --no-include-brand-kitTo copy the Brand Kit into a headless frontend app, see Headless - Brand Kit.
Pull the Brand Kit
Section titled “Pull the Brand Kit”canvas pull writes the Brand Kit fonts and colors to canvas.brand-kit.json
and downloads font files into a local fonts/ directory.
Push the Brand Kit
Section titled “Push the Brand Kit”canvas push reads canvas.brand-kit.json and updates the global Brand Kit.
For fonts, the command resolves configured font families, uploads font files, and replaces the remote Brand Kit font set.
For colors, the command creates and updates colors on the site. Colors that are
on the site but not in the file are kept unless you pass --prune-colors.
Colors in use by a component instance or template can’t be deleted.
Configure fonts
Section titled “Configure fonts”Create canvas.brand-kit.json in the project root.
{ "fonts": { "defaults": { "weights": ["400"], "styles": ["normal"], "subsets": ["latin"] }, "families": [ { "name": "Inter", "provider": "google", "weights": ["400", "700"], "styles": ["normal", "italic"] }, { "name": "My Font", "src": "fonts/MyFont-Regular.woff2", "weights": ["400"], "styles": ["normal"] } ] }}Font families can use a provider or a local font file. Local src values are
relative to the project root.
Supported providers include google, bunny, fontshare, fontsource,
npm, and adobe.
For the full CLI schema and advanced font and color options, see the
@drupal-canvas/cli README.
Configure colors
Section titled “Configure colors”Add a colors map to canvas.brand-kit.json. Each key becomes a CSS variable
name: brand-red becomes --brand-red. Values are CSS color strings, or an
object when the color needs a display name other than the key in title case.
{ "colors": { "brand-red": "#cc0000", "overlay": "hsla(220, 60%, 50%, 0.5)", "deep-sea": { "value": "#003366", "name": "Ocean Deep" } }}Supported color formats are #rrggbb, #rrggbbaa, rgb(), rgba(), hsl(),
and hsla(). Color names must be unique. Color folders are managed in the
Canvas UI.
Use fonts in Code Components
Section titled “Use fonts in Code Components”Do not import font packages from Code Component JavaScript or TypeScript files.
// Do not use this.import '@fontsource/inter';Use Brand Kit fonts for fonts that should be available in Canvas. Put component styles in the component CSS file, and put shared global styles in the project global CSS file.
Color props
Section titled “Color props”The Brand Kit is the site’s palette. A color prop is an input on a single component, where an editor picks a color for that instance: one from the palette, or any other color.
When an editor picks a Brand Kit color, Canvas stores a reference to that color, not its value. Drupal resolves the reference when it renders the component, and the component receives an object:
{ "cssColorValue": "rgb(204, 0, 0)", "cssVariable": "--brand-red", "colorName": "Brand Red"}It also has a value key holding the color as a design token object, with
colorSpace, components, alpha, and hex, not as a CSS color string.
A component can use either of the first two keys:
cssColorValueis the color’s current value in the Brand Kit. If a site builder changes the color, the component gets the new value.cssVariableis the name of the CSS variable.var(--brand-red)uses the value that the page’s CSS defines. On a headless app, that’s the value you copied into the app’s CSS, as described in Headless - Brand Kit.
For a color that isn’t from the Brand Kit, cssVariable and colorName are
null, so use cssColorValue.