Lesson 52 of 56 · Design system
Design systems
Turn on a design system and a page written with the standard elements looks finished. Buttons, inputs, tables, dialogs and the rest are drawn by a design system, today shadcn/ui, and every example in the next lessons is a live page that sets it. This lesson explains the settings; the following lessons show each component with all its variants.
Turning the design on
Nothing is applied unless you ask. Write design = "shadcn" as the first line of the page block and a plain button is a styled button, and variant and size pick another one with a single word. A page without the setting has no design: the components keep their behaviour with a minimal look.
The design in use is chosen in this order: the design setting of the page, then the project default from design.toml or salam.toml (see below), and when neither exists, none. The page always wins over the project file.
The behaviour The behaviour (open and close, keyboard, focus, ARIA) is generated for you in the same way, with or without a design, so a dialog opens and a tabs element answers the arrow keys without a line of script.
page:
design = "shadcn"
title = "Default design"
padding = 16
box:
layout = "row"
gap = 8
button:
content = "Save"
end
button:
variant = "outline"
content = "Cancel"
end
end
endPage settings
Four settings in the page block control the design for the whole page. Write enum values in quotes.
| Setting | Values | Default |
|---|---|---|
design طراحی | "shadcn" "none" | "none" |
theme پوسته | "auto" "light" "dark" | "auto" |
palette پالت | "neutral" "zinc" "stone" "slate" "gray" "mauve" "olive" "mist" "taupe" or your own | "neutral" |
design tokens توکن های طراحی | text such as "primary: #2563eb; radius: 1rem" | none |
auto follows the system setting of the visitor, light and dark force one. The example below is dark with the zinc palette.
page:
title = "Settings"
design = "shadcn"
theme = "dark"
palette = "zinc"
padding = 16
gap = 12
box:
layout = "row"
gap = 8
button:
content = "Primary"
end
button:
variant = "secondary"
content = "Secondary"
end
badge:
content = "zinc, dark"
end
end
input:
placeholder = "Email"
end
endTheme toggle
The theme toggle element is a button with a sun and a moon that flips light and dark and remembers the choice of the visitor in the browser. It is a button, so it takes variant and size as well.
page:
design = "shadcn"
title = "Theme"
padding = 16
box:
layout = "row"
gap = 8
theme toggle:
end
button:
variant = "ghost"
content = "Follows the theme"
end
end
endTokens: change everything from one place
The whole look is a set of named values, the shadcn variables: background, foreground, card, popover, primary, secondary, muted, accent, destructive, border, input, ring, radius, chart-1 to chart-5 and the sidebar group, plus font-sans and font-mono. Components never use a fixed colour; they read these values, so changing one token restyles every component that uses it.
List the ones you want to change in design tokens, separated by semicolons. A bare name sets both themes; light name and dark name set one side only. Fonts go through the same place: font-sans: "Inter", sans-serif.
page:
design = "shadcn"
title = "Tokens"
padding = 16
design tokens = "primary: #2563eb; dark primary: #60a5fa; radius: 1rem"
box:
layout = "row"
gap = 8
button:
content = "Blue"
end
button:
variant = "outline"
content = "Outline"
end
badge:
content = "Round"
end
end
endLight and dark on any element
theme works on every element, not only on the page. A box, a card or any other element with theme = "dark" gets the dark colours for itself and everything inside it, even on a light page.
page:
design = "shadcn"
title = "Scope"
theme = "light"
padding = 16
card:
padding = 16
paragraph:
content = "This card follows the page: light."
end
box:
theme = "dark"
padding = 16
radius = 8
gap = 8
paragraph:
content = "This box is dark, and so is everything inside it."
end
button:
content = "Dark button"
end
end
end
endThe design on one element
design works on every element too. design = "none" on a box (or a card, a button, any element) removes the design look from that element and everything inside it, so they look like the bare elements with only what you set yourself. A descendant that sets its own design, such as design = "shadcn", turns the look back on for itself and what it holds. It also works the other way round: with design = "none" on the page, one element with design = "shadcn" is styled and the rest stays bare. Behaviour is kept in every case. The order is the element, then its ancestors, then the page, then the project file, then none. theme follows the same rule, and on the page it is the default for the whole page. palette and design tokens stay settings of the page and the project file.
No flash with the saved theme
With theme = "auto" a page that has a theme toggle also reads the saved choice (the browser key salam-theme) in the head, before anything is drawn, so a visitor who picked dark never sees a light page first. Pages without a toggle get no script.
Fonts from one place
Set the families with font-sans and font-mono, then say where the files come from. font-url is a stylesheet address such as a Google Fonts link; font-face lists your own files as Family url weight, separated by commas (write + for a space in the family, add italic for an italic file). The page gets the link and @font-face rules for you.
design tokens = "font-sans: Inter, sans-serif; font-face: Inter /fonts/inter.woff2 400 700"Inside design tokens a semicolon ends a token and an ampersand cannot be used, so write %3B and %26 in a URL there, or put the font settings in the project file below.
One file for the whole project
Put the defaults, including which design every page uses, in design.toml next to your project, or in a [design] table of salam.toml. The compiler looks in the folder you build from and in the folders above it. Whatever the page sets itself wins over the file, and a project with neither has no design.
[design]
design = "shadcn"
palette = "brand"
theme = "auto"
font-sans = "Inter, sans-serif"
font-url = "https://fonts.googleapis.com/css2?family=Inter:wght@400;700"
[design.tokens]
radius = "0.5rem"
dark-ring = "oklch(0.7 0.15 260)"
[design.palette.brand]
base = "zinc"
primary = "oklch(0.6 0.2 260)"
dark-primary = "oklch(0.7 0.15 260)"In design.toml the same keys are written without the design. prefix ([tokens], [palette.brand]). A [design.palette.NAME] table is your own palette: base is the built in palette it starts from, and every other key is a token, with dark- or light- in front for one side only. Then palette = "brand" in the file or on a page uses it.
Mistakes are reported
A token name that does not exist (primry) or a palette that is not defined is not silently ignored: the page carries a salam-design-warning meta tag and prints the same message to the browser console. To set your own CSS variable, start the name with two dashes, as in --brand-x: #123.
Variants and sizes
A component with several looks has a variant attribute, and one with several sizes has a size attribute. Each takes a single word, and the list of words is in the lesson of the component.
Your own styles win
Every rule of the design has the lowest possible weight, so anything you write on an element, such as background = "red" or padding = 4, overrides it without a fight. You never need to undo the design first.
Without a design
This is the default, and you can also write it: design = "none" on a page overrides a project file that turns shadcn on. The components have no design styling but keep their behaviour: the tabs below still switch, a dialog still opens, a menu still closes on Escape. This is also how you start your own look from nothing.
page:
title = "No design"
design = "none"
padding = 16
tabs:
default value = "a"
tab list:
tab trigger:
value = "a"
content = "One"
end
tab trigger:
value = "b"
content = "Two"
end
end
tab content:
value = "a"
paragraph:
content = "Works without a design"
end
end
tab content:
value = "b"
paragraph:
content = "Second panel"
end
end
end
endWhere it applies
The design is drawn on the web build today. The native, Android and iOS builds accept design and theme and ignore them: they keep their own drawing. More design systems will be added behind the same design setting, and each component page in the next lessons will say which ones it supports.
A new design is a new name in the design list plus its own styles, one set per component (the files ds_<design>_*.salam in layoutgen). The markup, the keyboard handling and the events stay the same, only the styles change. A component that the chosen design does not style yet falls back to the shadcn version, so a page never loses a component when you switch designs.
The component lessons
Form components: button, input, checkbox, switch, select and the rest.
Display components: card, badge, alert, table, avatar and more.
Overlays and navigation: tabs, dialog, menus, tooltip.
More components: toast, command, calendar, carousel, sidebar and charts.