Langage
Overrides
Conditional values for view nodes, ordered by layer and priority, with conflicts found at compile time.
An override assigns new values to named nodes when its condition holds. The view gives the default; overrides refine it.
override "primary" {
layer = "variant"
when = variant.appearance == "primary"
node "root" {
background = token.color.action
foreground = token.color.on-action
}
}
override "disabled" {
layer = "state"
priority = 30
when = prop.disabled
node "root" {
background = token.color.disabled
foreground = token.color.on-disabled
}
}
Precedence
When several overrides set the same property of the same node, the winner is decided by:
- Layer, in this order:
base<context<variant<state<instance. - Priority within a layer: the higher
prioritywins (default0).
Declaration order never breaks a tie. In the button above, a disabled primary button is
gray: disabled (layer state) beats primary (layer variant).
Conflicts are compile errors
Two overrides in the same layer with the same priority may both apply only if they agree. The compiler decides this exactly for booleans, enums, variants and enum context axes:
# Same layer and priority, but `appearance` is an enum:
# the conditions are mutually exclusive, so this compiles.
override "hover-primary" {
layer = "state"
priority = 10
when = state.hovered && variant.appearance == "primary"
node "root" {
background = token.color.action-hover
}
}
override "hover-secondary" {
layer = "state"
priority = 10
when = state.hovered && variant.appearance == "secondary"
node "root" {
background = token.color.surface-hover
}
}
If both could apply with different values, dsfc check reports DSF-O001. When the
compiler cannot decide (comparisons of magnitudes), it warns with DSF-O002. Assigning a
property the node kind does not have is DSF-O003; targeting an unknown node is DSF-C005.
Context overrides
Overrides can depend on context axes, such as the pointer or the user’s motion preference:
override "coarse-pointer" {
layer = "context"
when = context.pointer == "coarse"
node "root" {
min_height = token.size.row-coarse
padding = insets(token.space.inset-coarse, token.space.inset)
}
}
Generators apply overrides in the same precedence order on every target, and the reference
evaluator used by dsfc test does too.