Design: forms and buttons
Every Salam page gets the shadcn look by default. This lesson shows every form control of that design: its name, what it is for, example code, and each variant and size with a live example. The examples really work in the preview.
Buttons
A page is a page block and gets this look unless you write design = "none", which drops the look and keeps the behaviour. Variants and sizes are one word attributes, and their values are written in quotes.
button (Persian: دکمه)
A button runs code or sends a form. The variant attribute picks its look and size its size. Quote the value, as in variant = "outline". A button with disabled = true is dimmed and ignores clicks.
page:
title = "Button variants"
margin = 1.5rem
box:
layout = "row"
gap = 8
wrap = true
button:
content = "Default"
end
button:
variant = "destructive"
content = "Destructive"
end
button:
variant = "outline"
content = "Outline"
end
button:
variant = "secondary"
content = "Secondary"
end
button:
variant = "ghost"
content = "Ghost"
end
button:
variant = "link"
content = "Link"
end
button:
disabled = true
content = "Disabled"
end
end
end| Variant | Persian | Use for |
|---|---|---|
default | پیش فرض | The main action. |
destructive | خطرناک | Deleting or other actions that cannot be undone. |
outline | خط دور | A quieter action with a border. |
secondary | ثانویه | A second choice next to the main one. |
ghost | شفاف | Toolbars and menus, no background until hover. |
link | پیوند | An action that looks like a link. |
button sizes (Persian: اندازههای دکمه)
The sizes are xs, sm, the default, and lg. The icon sizes icon xs, icon sm, icon and icon lg make a square button for one symbol.
page:
title = "Button sizes"
margin = 1.5rem
box:
layout = "row"
gap = 8
wrap = true
align = "center"
button:
size = "xs"
content = "Extra small"
end
button:
size = "sm"
content = "Small"
end
button:
content = "Default"
end
button:
size = "lg"
content = "Large"
end
end
box:
layout = "row"
gap = 8
wrap = true
align = "center"
margin top = 12
button:
variant = "outline"
size = "icon xs"
content = "+"
end
button:
variant = "outline"
size = "icon sm"
content = "+"
end
button:
variant = "outline"
size = "icon"
content = "+"
end
button:
variant = "outline"
size = "icon lg"
content = "+"
end
end
endtheme toggle (Persian: تغییر پوسته)
A button that flips the page between light and dark and remembers the choice. It takes the same variant and size as a button. Press it in the preview to see the page change.
page:
title = "Theme toggle"
margin = 1.5rem
box:
layout = "row"
gap = 8
theme toggle:
end
theme toggle:
variant = "outline"
end
theme toggle:
variant = "ghost"
end
end
endText and choices
input (Persian: ورودی)
A one line box. The type decides the keyboard and the checks, and the shadcn look is the same for all of them: text, email, password, number, search, date and the rest. placeholder is the grey hint, disabled dims the box, and the focus ring appears on keyboard focus. Checkbox, radio and range have their own looks, shown below.
page:
title = "Input types"
margin = 1.5rem
box:
gap = 8
input:
type = "text"
placeholder = "Text"
end
input:
type = "email"
placeholder = "name@example.com"
end
input:
type = "password"
placeholder = "Password"
end
input:
type = "number"
placeholder = "Number"
end
input:
type = "search"
placeholder = "Search"
end
input:
type = "date"
end
input:
type = "text"
value = "Disabled"
disabled = true
end
end
endtext area (Persian: ناحیه متن)
A multi line box, written as an input with type = "textarea". rows sets the starting height and the box grows with its content. The old element text area still works but warns (W297) and will be removed, so write the input form shown here.
page:
title = "Text area"
margin = 1.5rem
input:
type = "textarea"
rows = 3
placeholder = "Write a message"
end
endlabel (Persian: برچسب)
The text that names a control. Give the control an id and write it in the for of the label: a click on the label then focuses the control. A label next to a disabled control is dimmed too.
page:
title = "Label"
margin = 1.5rem
box:
gap = 8
label:
for = "email"
content = "Email"
end
input:
id = "email"
type = "email"
placeholder = "name@example.com"
end
end
endcheckbox (Persian: تیک)
An input with type = "checkbox". checked = true starts it ticked and disabled dims it. indeterminate = true shows the in-between dash for a "select all" box; the first click on it clears the state, and a page script can set or remove the data-indeterminate attribute to change it later. The box also gets aria-checked="mixed" for screen readers.
page:
title = "Checkbox"
margin = 1.5rem
box:
gap = 12
box:
layout = "row"
gap = 8
align = "center"
input:
id = "terms"
type = "checkbox"
end
label:
for = "terms"
content = "Accept the terms"
end
end
box:
layout = "row"
gap = 8
align = "center"
input:
id = "news"
type = "checkbox"
checked = true
end
label:
for = "news"
content = "Send me the newsletter"
end
end
box:
layout = "row"
gap = 8
align = "center"
input:
id = "off"
type = "checkbox"
disabled = true
end
label:
for = "off"
content = "Disabled"
end
end
end
endpage:
title = "Indeterminate"
margin = 1.5rem
box:
gap = 10
box:
layout = "row"
gap = 8
align = "center"
input:
id = "all"
type = "checkbox"
indeterminate = true
end
label:
for = "all"
content = "Select all (some chosen)"
end
end
box:
layout = "row"
gap = 8
align = "center"
input:
type = "checkbox"
checked = true
end
label:
content = "First"
end
end
box:
layout = "row"
gap = 8
align = "center"
input:
type = "checkbox"
end
label:
content = "Second"
end
end
end
endradio group (Persian: گروه رادیویی)
Several input elements with type = "radio" and the same name, held in a radio group. The group gives them even spacing and the radiogroup role for screen readers. Only one of them can be chosen.
page:
title = "Radio group"
margin = 1.5rem
radio group:
box:
layout = "row"
gap = 8
align = "center"
input:
id = "r1"
type = "radio"
name = "plan"
checked = true
end
label:
for = "r1"
content = "Free"
end
end
box:
layout = "row"
gap = 8
align = "center"
input:
id = "r2"
type = "radio"
name = "plan"
end
label:
for = "r2"
content = "Pro"
end
end
box:
layout = "row"
gap = 8
align = "center"
input:
id = "r3"
type = "radio"
name = "plan"
end
label:
for = "r3"
content = "Team"
end
end
end
endselect (Persian: انتخاب)
The native select with option children, drawn with a border and a chevron. Because it is the real control, the picker, the keyboard and the form value all work as in any browser. control size = "sm" makes it 32 pixels high instead of 36. (size is already the row count of an HTML select, so the look has its own name.)
page:
title = "Select"
margin = 1.5rem
select:
name = "fruit"
option:
value = "apple"
content = "Apple"
end
option:
value = "pear"
content = "Pear"
end
option:
value = "plum"
content = "Plum"
end
end
endpage:
title = "Select sizes"
margin = 1.5rem
box:
gap = 12
select:
name = "a"
option:
content = "Default size"
end
option:
content = "Second"
end
end
select:
name = "b"
control size = "sm"
option:
content = "Small size"
end
option:
content = "Second"
end
end
end
endaria invalid (Persian: نامعتبر دسترسیپذیری)
Set aria invalid = "true" on an input, text area, select, checkbox or radio to mark its value as wrong. Screen readers announce it and the control gets the red border and soft red ring. Drive it from your own checks; leave it out when the value is fine.
page:
title = "Invalid state"
margin = 1.5rem
box:
gap = 12
input:
type = "email"
value = "not an email"
aria invalid = "true"
end
input:
type = "textarea"
rows = 2
aria invalid = "true"
placeholder = "A message is required"
end
select:
aria invalid = "true"
option:
content = "Pick a plan"
end
end
box:
layout = "row"
gap = 8
align = "center"
input:
id = "agree"
type = "checkbox"
aria invalid = "true"
end
label:
for = "agree"
content = "I accept the terms"
end
end
end
endFields and groups
field (Persian: فیلد)
A label, a control, a description and an error laid out as one unit. field set and legend group fields, field group stacks them, and inside a field you can use field label, field content, field title, field description, field error and field separator.
page:
title = "Field"
margin = 1.5rem
form:
field set:
legend:
variant = "label"
content = "Account"
end
field group:
field:
field label:
for = "fname"
content = "Name"
end
input:
id = "fname"
type = "text"
end
field description:
content = "Shown on your profile."
end
end
field:
error = true
field label:
for = "fmail"
content = "Email"
end
input:
id = "fmail"
type = "email"
end
field error:
content = "Enter a valid address."
end
end
field:
orientation = "horizontal"
input:
id = "fnews"
type = "checkbox"
end
field label:
for = "fnews"
content = "Subscribe"
end
end
field separator:
content = "or"
end
field:
orientation = "horizontal"
field content:
field title:
content = "Two step sign in"
end
field description:
content = "Ask for a code at every sign in."
end
end
input:
id = "ftwo"
type = "checkbox"
end
end
end
end
end
end| Element | Attribute | Values |
|---|---|---|
field | orientation | vertical, horizontal, responsive |
field | error, disabled | true or false. The error state turns the text red. |
legend | variant | legend or label |
field label | for | The id of the control. |
input group (Persian: گروه ورودی)
An input fused with text or buttons at its edges. Children are the input, input group addon and input group text, and a button. The align attribute of the addon picks its side.
page:
title = "Input group"
margin = 1.5rem
box:
gap = 12
input group:
input group addon:
input group text:
content = "https://"
end
end
input:
type = "text"
placeholder = "example.com"
end
end
input group:
input:
type = "text"
placeholder = "Amount"
end
input group addon:
align = "inline-end"
input group text:
content = "USD"
end
end
end
input group:
input:
type = "search"
placeholder = "Search"
end
input group addon:
align = "inline-end"
button:
size = "xs"
content = "Go"
end
end
end
end
end| align | Persian | Where the addon goes |
|---|---|---|
inline-start | ابتدای خط | Before the text, the default. |
inline-end | انتهای خط | After the text. |
block-start | ابتدای بلوک | Above the input. |
block-end | انتهای بلوک | Below the input. |
button group (Persian: گروه دکمه)
Buttons joined into one bar with shared borders. orientation is horizontal (default) or vertical. Inside you can also use button group text and button group separator.
page:
title = "Button group"
margin = 1.5rem
box:
gap = 12
button group:
button:
variant = "outline"
content = "Day"
end
button:
variant = "outline"
content = "Week"
end
button:
variant = "outline"
content = "Month"
end
end
button group:
orientation = "vertical"
button:
variant = "outline"
content = "Top"
end
button:
variant = "outline"
content = "Middle"
end
button:
variant = "outline"
content = "Bottom"
end
end
button group:
button group text:
content = "https://"
end
input:
placeholder = "domain"
end
button group separator:
end
button:
variant = "outline"
content = "Go"
end
end
end
endToggles and small controls
switch (Persian: کلید)
An on and off control. It sends its value under its name when on, and fires the change event on every flip. Attributes: checked, name, value, disabled and size (default or sm).
page:
title = "Switch"
margin = 1.5rem
box:
layout = "row"
gap = 16
align = "center"
switch:
name = "wifi"
end
switch:
name = "mail"
checked = true
end
switch:
size = "sm"
checked = true
end
switch:
disabled = true
end
end
endslider (Persian: لغزنده)
An input with type = "range", with min, max and value. The filled part of the track follows the value as you drag. orientation = "vertical" stands it up, with the smallest value at the bottom.
page:
title = "Slider"
margin = 1.5rem
box:
gap = 16
input:
type = "range"
min = "0"
max = "100"
value = "30"
end
input:
type = "range"
min = "0"
max = "100"
value = "75"
end
end
endrange slider (Persian: لغزنده بازه)
A slider with two thumbs for a lower and an upper value. min, max and step set the scale, low and high the starting values, and orientation is horizontal or vertical. The thumbs cannot cross. The element carries data-low, data-high and data-value (as "20,70"), fires ds-change with detail.low and detail.high, and with a name sends two form values, name-min and name-max.
page:
title = "Range slider"
margin = 1.5rem
box:
gap = 16
range slider:
id = "price"
low = 20
high = 70
end
paragraph:
id = "shown"
content = "20 to 70"
end
box:
layout = "row"
gap = 32
input:
type = "range"
orientation = "vertical"
value = "40"
end
range slider:
orientation = "vertical"
low = 10
high = 60
end
end
end
script:
content = "document.getElementById('price').addEventListener('ds-change', function (e) { document.getElementById('shown').textContent = e.detail.low + ' to ' + e.detail.high; });"
end
endtoggle (Persian: تغییر وضعیت)
A button that stays pressed. pressed = true starts it on, variant is default or outline, size is default, sm or lg. It sets aria-pressed and fires change.
page:
title = "Toggle"
margin = 1.5rem
box:
layout = "row"
gap = 8
wrap = true
align = "center"
toggle:
content = "Bold"
end
toggle:
pressed = true
content = "Italic"
end
toggle:
variant = "outline"
content = "Outline"
end
toggle:
size = "sm"
content = "Small"
end
toggle:
size = "lg"
content = "Large"
end
toggle:
disabled = true
content = "Disabled"
end
end
endtoggle group (Persian: گروه تغییر وضعیت)
Several toggles that work together. With type = "single" (default) one can be on, with "multiple" any number. variant and size pass down to the toggles, spacing from 0 to 4 separates them, and the arrow keys, Home and End move between them. The first group below is single and outlined, the second is multiple.
page:
title = "Toggle group"
margin = 1.5rem
box:
gap = 12
toggle group:
type = "single"
variant = "outline"
toggle:
pressed = true
content = "Left"
end
toggle:
content = "Center"
end
toggle:
content = "Right"
end
end
toggle group:
type = "multiple"
variant = "outline"
toggle:
pressed = true
font weight = 700
content = "Bold"
end
toggle:
italic = true
content = "Italic"
end
toggle:
pressed = true
decoration = underline
content = "Underline"
end
end
end
endkeyboard (Persian: صفحه کلید)
A key cap, for showing a shortcut. keyboard group puts several caps side by side.
page:
title = "Keyboard"
margin = 1.5rem
box:
layout = "row"
gap = 12
align = "center"
wrap = true
keyboard:
content = "Esc"
end
keyboard group:
keyboard:
content = "Ctrl"
end
keyboard:
content = "K"
end
end
keyboard group:
keyboard:
content = "Shift"
end
keyboard:
content = "Enter"
end
end
end
endinput otp (Persian: کد یکبار مصرف)
A row of boxes for a one time code. length is the number of digits (6 by default) and group size the digits per group, with a dash between groups; 0 means no groups. Typing moves forward, backspace moves back and a paste fills all the boxes. It fires change on each digit and complete when all are filled, and name carries the whole code in a form.
page:
title = "One time code"
margin = 1.5rem
box:
gap = 16
input otp:
length = 6
group size = 3
name = "code"
end
input otp:
length = 4
group size = 0
end
end
end