CamoButton
Concept
1. Why
The button is the component most often rebuilt per project ("our primary button is a pill with a gradient"). It's also the first real test of the whole architecture:
- the appearance (solid, soft, raised, outline, ghost, link);
- the tone (default, or a status color such as a red destructive action);
- interaction states and press feedback from the skin;
- the ambient icon style that makes a plain
AppIcon.save()look right inside it.
When CamoButton looks right on MinimalSkin (the v1 skin) and changes look with only a theme change, M3 ("Hello skin") is done. Appearance and tone are Camouflage's own vocabulary (Design Language).
2. Shape
Hovered, Focused and Pressed can overlap (focused and pressed). That's why they are three booleans in InteractionState, not one enum. Disabled overrides everything: no feedback and no focus.
What the renderer does with the inputs
- Picks the container, content and border colors from the appearance (visual weight) and the tone (color family).
- Draws
textitself, in the button's text style with the content color (underlined forLink). - Sets the ambient icon style (size 18, content color) and places
prefixIconbefore the text andsuffixIconafter it.
Appearance → colors (f = the tone's family; for Default, strong = primary and container = secondaryContainer, see Theme §3.2):
| Appearance | Container | Content | Border | Depth | Material 3 |
|---|---|---|---|---|---|
Solid (default) | f.strong | f.onStrong | – | – | Filled |
Soft | f.container | f.onContainer | – | – | Filled tonal |
Raised | surfaceContainerLow | f.strong | – | level1 (level2 on hover) | Elevated |
Outline | transparent | f.strong | outline (f.strong for status tones) | – | Outlined |
Ghost | transparent | f.strong | – | – | Text |
Link | transparent, no container padding | f.strong, underlined | – | – | (Material has no link button; drawn as underlined text) |
Every appearance works with every tone: Solid + Error is the red destructive confirm, and Outline + Warning is an amber outlined button. Full Material details: Material Skin.
3. API
Contract
fun CamoButton(
text: String,
onClick: () -> Unit,
appearance: Appearance? = null, // null → ButtonTheme.defaultAppearance (skin default: Solid)
tone: Tone = Default, // Error for destructive actions; Success / Warning / Info
enabled: Boolean = true,
loading: Boolean = false, // shows a progress circle, ignores clicks, keeps its width
prefixIcon: Widget? = null, // usually an app icon widget, e.g. AppIcon.save()
suffixIcon: Widget? = null, // e.g. AppIcon.chevronRight()
)
| Parameter | What it's for |
|---|---|
text | the label. It's a value: the renderer draws it with the skin's label style. |
onClick | fired once per completed press (release inside bounds), or on keyboard Enter/Space |
appearance | the visual weight. The usual mapping from action rank: main action → Solid, supporting → Soft or Outline, low-key → Ghost, inline navigation → Link. |
tone | the color family. Error is the destructive action ("Delete account"); a future Cupertino skin maps it to iOS's destructive role. |
enabled | false blocks clicks and focus, and shows the disabled look |
loading | true shows a small CamoProgressCircle in place of the text (the width stays the same), ignores clicks, stays focusable, and is announced as busy. The colors don't change to the disabled look. |
prefixIcon, suffixIcon | icon widgets before and after the text (the sides swap in RTL). They take size and color from the ambient icon style the renderer sets. |
Widget means the platform's UI unit: a Flutter Widget, or a @Composable () -> Unit lambda in Compose.
State → renderer: ButtonState(text, enabled, loading, appearance, tone, interaction: InteractionState). Slots: ButtonSlots(prefixIcon?, suffixIcon?).
Tokens used
| Token | Use |
|---|---|
the tone's family: strong, onStrong, container, onContainer | containers and content per appearance |
colors.surfaceContainerLow, outline | Raised container, Outline border |
colors.onSurface at the skin's disabled alphas | disabled container and content |
elevation.level1 / level2 | Raised depth |
shapes.full | container shape (skin may choose another role) |
typography.labelLarge | the text |
spacing.xl horizontal (spacing.l on a side with an icon), spacing.s gap between icon and text | padding (Link: none beyond the touch target) |
motion.durationShort | state-layer transitions |
| icon size 18 | the ambient IconStyle for prefix and suffix |
Component theme
theme.components.button: ButtonTheme?. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.
| Field | Type | Material default | What it's for |
|---|---|---|---|
defaultAppearance | Appearance | Solid | the appearance used when a call passes none (ADR-28: a brand's default variant) |
height | Dp | 40 | container height (it grows with text at large font scale) |
minWidth | Dp | 64 | keeps short labels ("OK") from making tiny buttons |
shape | Shape | shapes.full | corner radius |
padding | Padding | horizontal 24 | inner padding without icons |
paddingWithIcon | Padding | 24 on the text side, 16 on the icon side | inner padding when a prefix or suffix icon is present |
textStyle | CamoTextStyle | typography.labelLarge | the text |
iconSize | Dp | 18 | the ambient icon size for prefix and suffix icons |
iconGap | Dp | spacing.s (8) | space between an icon and the text |
borderWidth | Dp | 1 | the Outline border |
raisedElevation | ElevationLevel | Level1 (hover Level2) | the Raised depth |
solidColors / softColors / raisedColors / outlineColors / ghostColors / linkColors | ButtonColors(container, content, border?) | per the table in §2 | colors per appearance for tone = Default. Status tones always use their global family. |
disabledContainerAlpha / disabledContentAlpha | Float | 0.12 / 0.38 (of onSurface) | disabled look |
Example: a Figma design with 48-tall buttons, radius 12, and semi-bold text:
components = CamoComponentThemes(button = ButtonTheme(
height = 48, shape = RoundedCorner(12),
textStyle = BrandType.labelLarge.copy(fontWeight = SemiBold), iconSize = 20))
Accessibility
- Role button, focusable, activated by Enter/Space.
Linkis still a button semantically (it performs an action). For navigation to a URL, use aCamoTextlink span instead. - Minimum touch target 48 × 48, set by the component. A visually smaller button (40 tall, or a Link) gets an invisible touch margin.
- Accessible name =
text. Prefix and suffix icons are decorative (their labels are ignored). - Disabled buttons are announced as disabled, not hidden.
- A loading button keeps focus and is announced as busy ("Save, button, busy"). Screen readers get a polite announcement when loading ends only if the app shows a result.
- Visible focus indicator, drawn by the skin's feedback (WCAG 2.4.7).
GhostandLinkrely on text color alone to look interactive. Their content color must meet 4.5:1 against the surface (checked byvalidate()through the tone's strong color).
4. Build steps
- Core:
- track interaction (pressed/hovered/focused);
- build
ButtonState/ButtonSlots; - wrap it in a clickable with role, name, min size and the enabled gate;
- call
skin.button.render.
DebugSkinbutton renderer: a box with the text and appearance name, icons placed before and after with a debug icon style, a border when focused, and darker when pressed.- Sample:
- the six appearances × enabled/disabled;
Solid + ErrorandGhost + Error;- one with
prefixIcon = AppIcon.save(), and one withsuffixIcon = AppIcon.chevronRight(); - a full-width submit button (the parent sets the width) that shows
loadingwhile a fake request runs.
- Tests:
onClickfires once per tap, and not when disabled or loading;loading = truekeeps the button's width, shows the progress circle, keeps focus, and exposes busy semantics;- keyboard Enter activates it;
- the semantics are role button with name =
text; - the touch target is at least 48, including for
Link; interaction.pressedbecomes true during the press;- a prefix
AppIconwith no parameters gets the icon style the renderer set.
- Once the Minimal skin exists (M3), a screenshot for each appearance × tone in light and dark.
Done when
- The six appearances are visually distinct on
MinimalSkin, in light and dark. - Changing the theme's
primaryrecolors the Solid button and its icons with no call-site change. - All tests pass, including the 48dp target, keyboard activation and icon-style inheritance.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Long text at 200% font scale | The button grows in height and the text wraps to at most 2 lines, then ellipsizes. The width is never fixed by the renderer. Icons stay 18 and are centered vertically. |
| RTL | prefixIcon is at the start (the right in RTL) and suffixIcon at the end. Directional icons need autoMirror. |
| Icon only, no text | Use CamoIconButton, which requires a label. text is required and non-empty here. |
| Custom content (a badge, two lines of different styles) | Not supported by the value API, on purpose. Use a renderer override (MinimalSkin.copy(button = …)) or an app widget. This keeps every button on the design system. |
| Double tap / rapid taps | onClick fires for each completed press. Debouncing is app logic. |
| Loading state (settled 2026-09-27) | loading = true: the renderer measures the button as if it showed the text, then draws a small CamoProgressCircle (indeterminate, the content color, the icon size) centered in its place, so the width never jumps. Clicks are ignored (no double submit), focus stays, and the semantics say busy. It passes ADR-23 (Material progress in a button, Carbon inline loading, Fluent spinner, Cupertino activity indicator). |
loading and enabled = false together | Disabled wins: the disabled look, no spinner. |
| Full width (settled 2026-09-27) | No parameter. The parent sets the width (Compose Modifier.fillMaxWidth(), Flutter SizedBox(width: double.infinity, child: …)). The renderer honors the incoming width, centers text and icons in it, and falls back to minWidth when unconstrained. |
A Link inside a sentence | Not what Link is for (it's a standalone button with link styling). Inline links in text use CamoText spans. |
| Destructive action (red button) | tone = Error. Usually Solid + Error for the confirm in a delete dialog, and Ghost + Error for a low-key "Remove" in a list. |
| Disabled with a status tone | Disabled looks the same for every tone (onSurface alphas), so a disabled red button doesn't look like an error. |
Implementation
1. Why
CamoButton is the reference implementation of the component skeleton (Components — Overview). This note adds the pieces specific to buttons:
- the appearance × tone color lookup;
- the
ButtonTheme/ButtonStylepair; - keyboard activation;
- the text-wrapping rule at large font scale.
2. Shape
3. API
The full signature is in the Overview skeleton. The public types in com.srctool.camouflage.core.button:
// in core/skin (shared vocabulary, base/01 - Foundations/01 - Design Language)
public enum class Appearance { Solid, Soft, Raised, Outline, Ghost, Link }
// in core/button
@Immutable public data class ButtonColors(val container: Color, val content: Color, val border: Color? = null)
@Immutable public data class ButtonTheme(/* nullable overrides, base table */)
@Immutable public data class ButtonStyle(/* resolved */) {
public fun merge(overrides: ButtonTheme?): ButtonStyle
public fun colorsFor(appearance: Appearance, tone: Tone, theme: CamoTheme): ButtonColors {
if (tone == Tone.Default) return when (appearance) {
Appearance.Solid -> solidColors; Appearance.Soft -> softColors
Appearance.Raised -> raisedColors; Appearance.Outline -> outlineColors
Appearance.Ghost -> ghostColors; Appearance.Link -> linkColors
}
val f = theme.colors.family(tone)
return when (appearance) {
Appearance.Solid -> ButtonColors(f.strong, f.onStrong)
Appearance.Soft -> ButtonColors(f.container, f.onContainer)
Appearance.Raised -> ButtonColors(theme.colors.surfaceContainerLow, f.strong)
Appearance.Outline -> ButtonColors(Color.Transparent, f.strong, border = f.strong)
Appearance.Ghost, Appearance.Link -> ButtonColors(Color.Transparent, f.strong)
}
}
}
@Immutable public data class ButtonState(
val text: String, val enabled: Boolean, val loading: Boolean, val appearance: Appearance, val tone: Tone,
val interaction: InteractionState, val interactionSource: InteractionSource,
)
@Stable public class ButtonSlots(public val prefixIcon: (@Composable () -> Unit)?, public val suffixIcon: (@Composable () -> Unit)?)
Keyboard: Modifier.clickable already handles Enter, Space and the numpad Enter on desktop and web, and Android hardware keyboards and D-pad center. No extra code is needed.
Disabled look: the renderer uses style.disabledContainerAlpha / disabledContentAlpha on theme.colors.onSurface for every tone. clickable(enabled = false) removes focusability and click.
Link: the renderer drops the container padding and draws the text with TextDecoration.Underline. minimumTouchTarget() still guarantees 48 × 48. Raised: Modifier.shadow with style.raisedElevation, animated to level2 on hover. Outline: Modifier.border(style.borderWidth, colors.border, style.shape).
Text: BasicText(state.text, style = style.textStyle.copy(color = colors.content), maxLines = 2, overflow = TextOverflow.Ellipsis). The container uses heightIn(min = style.height), never a fixed height, so 200% font scale grows it.
4. Build steps
- The types above in
core/button/. CamoButtonfollowing the skeleton.DebugSkin.button(the reference renderer in Skin Contract §3.5).commonTest(runComposeUiTest):onClickcount equals taps;- disabled: no click, and
assertIsNotEnabled(); onNodeWithText("Save").assert(hasRole(Role.Button));- touch bounds ≥ 48 dp even with a 32 dp tall style;
- a prefix
AppIconmeasuresstyle.iconSizewithout parameters; - with
fontScale = 2f(aLocalDensityoverride), height >style.height; ButtonStyle.merge(ButtonTheme(height = 56.dp)).height == 56.dp;colorsFor(Outline, Error, theme).border == theme.colors.error.
- Desktop: the keyboard Tab focus ring is visible, and Enter activates.
Done when
- All tests pass on jvm + iOS simulator.
- The sample button gallery (appearances × tones × enabled) renders on all four platforms with DebugSkin, and (at M3) with MinimalSkin.
5. Edge cases
| Case | Decided behavior |
|---|---|
Hoisted interactionSource | Supported (the Compose convention), so apps can observe presses or share one source between two elements. |
| Rapid double taps | Each completed tap fires. Debouncing is app logic. |
text is blank | Debug builds fail; release builds render it and log once (server text or a missing translation mustn't crash production). KMP has no debug flag of its own, so core exposes DebugChecks.enabled (on by default); a release build turns it off at startup. An icon-only button must be CamoIconButton. |
| Long text in RTL | Row follows LocalLayoutDirection, so the prefix goes on the right automatically. |
| Loading state | loading = true (base settled). The renderer keeps the text in layout with Modifier.alpha(0f) and draws CamoProgressCircle in a Box on top, so the width is the text's. The component sets clickable(onClick = {}, …) no-op while loading and semantics { stateDescription = "Busy" } (plus progressBarRangeInfo = Indeterminate on the circle). |
| Full width | CamoButton(…, modifier = Modifier.fillMaxWidth()). The renderer centers its row content. |