Collapse focus/hover/normal ternaries into Style.controlFill helpers

TextField, NumberField, Dropdown, SearchableDropdown, and Toggle all
painted their background, border color, and border width with the same
three-line ternary ladder (`_focused ? focusFill : _hot ? hoverFill :
normalFill`). Five components × three properties × three branches is a
lot of room for one of them to drift from the others when a new state
ever gets added.

Add controlFill / controlBorder / controlBorderWidth on Style and rewrite
each call site as a single binding. No visual change.
This commit is contained in:
David Heinemeier Hansson
2026-05-20 20:37:04 +02:00
parent 8ed6e302b0
commit b54d8e04ae
6 changed files with 37 additions and 65 deletions
+3 -13
View File
@@ -49,19 +49,9 @@ TextField {
bottomPadding: verticalPadding
background: Rectangle {
color: root._focused
? Style.focusFillFor(root.foreground, root.accent)
: (root._hot
? Style.hoverFillFor(root.foreground, root.accent)
: Style.normalFillFor(root.foreground, root.accent))
border.color: root._focused
? Style.focusBorderFor(root.foreground, root.accent)
: (root._hot
? Style.hoverBorderFor(root.foreground, root.accent)
: Style.normalBorderFor(root.foreground, root.accent))
border.width: root._focused
? Style.focusBorderWidth
: (root._hot ? Style.hoverBorderWidth : Style.normalBorderWidth)
color: Style.controlFill(root._focused, root._hot, root.foreground, root.accent)
border.color: Style.controlBorder(root._focused, root._hot, root.foreground, root.accent)
border.width: Style.controlBorderWidth(root._focused, root._hot)
radius: Style.cornerRadius
}
}