Langage
Components and views
A component is a typed contract (properties, variants, states, slots, events) plus a view tree of nodes.
The contract
component "Button" {
description = "Primary or secondary action with a calculated minimum size."
property "label" {
type = "string"
description = "Visible text. Also the accessible name."
}
property "disabled" {
type = "boolean"
default = false
}
variant "appearance" {
values = ["primary", "secondary"]
default = "secondary"
}
# Interaction-derived states are read-only and may be true simultaneously.
state "hovered" {
source = "hover"
}
state "focus_visible" {
source = "focus_visible"
}
slot "leading" {
cardinality = "optional"
accepts = ["icon"]
}
event "activate" {}
# accessibility, view, overrides and behavior follow
}
| Declaration | Purpose |
|---|---|
property |
An input with a type and an optional default. binding = "controlled" means the host owns the value. |
variant |
A finite choice (values, default), read as variant.appearance. |
state |
Read-only, with a source: hover, press, focus or focus_visible. Or local, with a type and a default. |
slot |
A placeholder the parent fills. cardinality is optional, required or many; accepts lists node kinds or components. |
event |
An output, with an optional typed payload. |
The view
A view has exactly one root node (DSF-C008). Node names are unique in the whole view
(DSF-C004) and give stable IDs such as calculated-button:node:Button/label.
view {
stack "root" {
direction = "horizontal"
gap = token.unit.base / 2
min_width = token.unit.base * 9
min_height = token.unit.base * 3
padding = insets(token.unit.base / 2, token.unit.base)
main_alignment = "center"
cross_alignment = "center"
background = token.color.surface
foreground = token.color.on-surface
slot "leading" {}
text "label" {
value = prop.label
typography = token.type.label
max_lines = 1
truncation = "end"
}
}
}
| Node | Use |
|---|---|
stack |
Horizontal or vertical layout with gap, padding, alignment, background, border, outline, radius. |
overlay |
Children drawn on top of each other. |
shape |
Rectangle, ellipse, capsule, line or path. |
text, icon, image |
Content. foreground set on a container colors descendant text and template icons. |
text_input |
The platform’s native text field (one line) or text editor (several): it shows a value the host owns and delivers text_change and submit. One per component. |
slot |
Places the component’s own slot. |
instance |
Uses another component, with props, variants, fill "<slot>" and on "<event>". |
repeat, switch, scroll |
Keyed repetition, first-match branches, scrolling content. |
Every node accepts when (presence), sizing (width, min_width…, "content" or "fill"),
opacity, transform, transitions, provide and accessibility.
Composition
instance "confirm" {
component = component.Button
props = {
label = prop.confirm_label
}
variants = {
appearance = "primary"
}
fill "leading" {
icon "arrow" {
source = icon.arrow-forward
size = token.unit.base
decorative = true
}
}
on "activate" {
emit = event.confirm
}
}
Instances are type-checked: a missing required property is DSF-C001, an unknown one
DSF-C002, slot content that the slot does not accept DSF-C003. A component that
instantiates itself, directly or through other components, is DSF-C009.
Imported packages
A package can build on another one in the same workspace (the directory that contains it):
import "base" {
path = "../import-base"
version = "0.2.0"
}
component "ProfileCard" {
slot "extra" {
cardinality = "optional"
accepts = [base.component.Badge]
}
view {
stack "root" {
text "name" {
value = prop.name
typography = base.token.type.label
}
instance "status" {
component = base.component.Badge
props = {
label = prop.status
}
}
slot "extra" {}
}
}
}
The alias is a root for the imported package’s tokens, components, icons, images and fonts,
checked like local ones. The imported package is checked too, and must have the pinned
version (DSF-P006); a package that imports itself through others is DSF-P005, and a path
outside the workspace DSF-P003. Its declarations keep their own stable IDs
(import-base:component:Badge) and are generated with the importing package, under names
that start with the package (DSImportBaseBadge, ds-import-base-badge).