Skin Contract
Concept
1. Why
A Skin is the design language: how each component is built, how it reacts to touch, and what its surfaces are made of. Core defines the contract a skin must fulfil: one renderer interface per component, plus two reusable parts (surface treatment and interaction feedback). A skin that implements the whole contract can draw every Camo* component, so an app changes design language by changing one value. This note is also the spec an AI agent follows to generate a new skin, so it must be precise.
2. Shape
Responsibilities of a skin
- Draw every component from
(state, slots, theme). - Map semantic inputs (
Appearance,Tone,SurfaceLevel,ElevationLevel,ShapeRole: Camouflage's vocabulary, see Design Language) to its own visual language. - Choose structure: where slots go, what shape a dialog has, whether a switch shows icons.
- Provide one surface treatment and one feedback style, which all its renderers share for consistency.
Not the skin's job (the component owns these, see Architecture):
- callbacks;
- semantics role and label;
- the enabled gate;
- the minimum touch target;
- focus traversal order;
- holding state.
2.1 State vs Slots
Every renderer receives two separate objects:
| State | Slots | |
|---|---|---|
| Is | plain data, including text values (text, label, title) | widgets the caller provides: icon widgets, nested components (dialog buttons), layout content (card body) |
| Example (button) | text = "Save", enabled = true, appearance = Solid, interaction = Pressed | prefixIcon = AppIcon.save(), suffixIcon = null |
| Renderer may | branch on it (when (appearance)), draw text values in its own styles | place it, wrap it, give it a content color and icon style, or not show it |
| Renderer may not | mutate it | inspect what's inside it |
Keeping them apart means a renderer can't depend on what the caller put in a slot. It only decides where the slot goes, and what content color and icon style it gets.
The API rule behind this split: text is a value, icons and nested components are widgets, and layout content is a slot. See ADR-12 in Decisions.
Content color and icon style. Before invoking a slot, the renderer sets the local content color and the ambient icon style (IconStyle(size, color)) (e.g. onPrimary inside a Solid button). CamoText and CamoIcon read that color by default, so a caller's CamoText("Save") automatically gets the right color on every skin.
3. API
3.1 CamoSkin
data class CamoSkin(
val name: String, // "minimal", for debugging and tests
val surfaceTreatment: SurfaceTreatment,
val feedback: InteractionFeedback,
val text: TextRenderer,
val icon: IconRenderer,
val surface: SurfaceRenderer,
val card: CardRenderer,
val button: ButtonRenderer,
val iconButton: IconButtonRenderer,
val textField: TextFieldRenderer,
val checkbox: CheckboxRenderer,
val switch: SwitchRenderer,
val topBar: TopBarRenderer,
val dialog: DialogRenderer,
val bottomSheet: BottomSheetRenderer,
// added with the full v1 set (ADR-21)
val divider: DividerRenderer,
val radio: RadioRenderer,
val segmentedControl: SegmentedControlRenderer,
val slider: SliderRenderer,
val searchField: SearchFieldRenderer,
val listItem: ListItemRenderer,
val listSection: ListSectionRenderer,
val pagedList: PagedListRenderer,
val datePicker: DatePickerRenderer, val timePicker: TimePickerRenderer,
val stepper: StepperRenderer, val accordion: AccordionRenderer,
val skeleton: SkeletonRenderer,
val menu: MenuRenderer,
val tooltip: TooltipRenderer,
val chip: ChipRenderer,
val badge: BadgeRenderer,
val avatar: AvatarRenderer,
val progressBar: ProgressBarRenderer,
val progressCircle: ProgressCircleRenderer,
val snackbar: SnackbarRenderer,
val banner: BannerRenderer,
val tabs: TabsRenderer,
val navigationBar: NavigationBarRenderer,
val navigationRail: NavigationRailRenderer,
val navigationDrawer: NavigationDrawerRenderer,
val fab: FabRenderer,
) {
fun copy(...): CamoSkin // replace any subset, keep the rest
}
All fields are required, with no defaults. A skin that forgets a renderer is a compile error.
Component defaults travel with the renderer. Each renderer declares defaults(theme), which returns a complete XTheme (every field set). It's a function because defaults usually reference global tokens (container = theme.colors.primary, shape = theme.shapes.full), so changing primary still recolors buttons. Before calling render, core resolves style = renderer.defaults(theme).merge(theme.components.x), so the renderer draws from style (component values) and theme (global tokens), never from nulls. Because defaults belong to the renderer, MaterialSkin.copy(button = X) brings X's own proportions with it. Components with no component theme (text, surface) take style = Unit. See Theme §3.10.
3.2 Renderer interfaces
Every renderer has the same shape:
interface XRenderer {
fun defaults(theme: CamoTheme): XTheme // complete component theme; may reference global tokens
fun render(state: XState, slots: XSlots, theme: CamoTheme, style: XTheme) // style = resolved, no nulls
}
| Renderer | State (data) | Slots (content) |
|---|---|---|
TextRenderer | content: String or List<CamoSpan>, style: CamoTextStyle, resolved color, maxLines, overflow, textAlign | none |
IconRenderer | source: IconSource, resolved size, resolved color, contentDescription? | none |
SurfaceRenderer | level: SurfaceLevel, shape: ShapeRole, elevation: ElevationLevel, border: Boolean | content |
CardRenderer | appearance: Appearance, tone: Tone, clickable, enabled, selected?, interaction | content |
ButtonRenderer | text, enabled, loading, appearance: Appearance, tone: Tone, interaction | prefixIcon?, suffixIcon? |
IconButtonRenderer | enabled, checked?, loading, appearance: Appearance, tone: Tone, interaction | icon |
TextFieldRenderer | value, label?, placeholder?, supportingText?, error?, prefixText?, suffixText?, enabled, focused, singleLine, secure, isEmpty | prefixIcon?, suffixIcon?, input (the editable text itself, provided by core) |
CheckboxRenderer | checked, label? (String or spans), description?, error?, enabled, interaction | none |
SwitchRenderer | checked, label? (String or spans), description?, error?, enabled, interaction | none |
TopBarRenderer | title, scrollOffset: Dp | navigation?, actions, titleContent? |
DialogRenderer | title?, message, dismissible, onDismissRequest (opening and closing belong to the navigator and the dialog frame) | confirm, dismiss?, content? |
BottomSheetRenderer | title?, dragProgress, dismissible, onDismissRequest | content |
the 27 added renderers (incl. PagedListRenderer, SkeletonRenderer, DatePickerRenderer, TimePickerRenderer, StepperRenderer, AccordionRenderer) | see each component note (§3, State → renderer) | see each component note |
Overlay dismissal in state. dismissible and onDismissRequest come from the overlay frame (passed down the tree), not from the app. A skin that draws a close affordance (DialogTheme.showCloseButton / BottomSheetTheme.showCloseButton, or a Cupertino "Done") shows it only when dismissible is true, and calls onDismissRequest, which goes through the same path as back/Esc, so vetoes (PopScope / OnDismissRequest) still apply. Skins without a close affordance ignore both.
CamoSelect has no renderer of its own: it reuses the text-field, menu, bottom-sheet and list-item renderers.
Shared types (in core):
data class InteractionState(val pressed: Boolean, val focused: Boolean, val hovered: Boolean, val dragged: Boolean) // dragged: slider handle, switch thumb
enum class Appearance { Solid, Soft, Raised, Outline, Ghost, Link } // visual weight; per-component subsets + fallbacks (Design Language §3.3)
enum class Tone { Default, Error, Success, Warning, Info } // color family; see Theme §3.2
enum class SurfaceLevel { Surface, Lowest, Low, Container, High, Highest } // → surface, surfaceContainer*
enum class ElevationLevel { Level0, Level1, Level2, Level3, Level4, Level5 }
enum class ShapeRole { None, ExtraSmall, Small, Medium, Large, ExtraLarge, Full }
data class CamoSpan(text, style?, fontWeight?, italic?, color?, underline?, link?) // rich text, see CamoText
Exact fields for each component are in its note under Components — Overview.
3.3 SurfaceTreatment
interface SurfaceTreatment {
// decorates a region: background, shadow/blur, clip to shape
fun paint(color: Color, shape: ShapeRole, elevation: ElevationLevel, theme: CamoTheme)
}
| Implementation | Where | How it expresses elevation |
|---|---|---|
Flat | Minimal skin (v1) | no shadow: a hairline border from Level1, and a one-step surface-level shift from Level3 |
Paper | Material skin (Later) | shadow + tonal tint of primary blended into the surface |
Glass | Later | background blur + refraction, stronger with level |
Acrylic | Later | frosted blur + noise, stronger with level |
Every renderer that draws a container (surface, card, button, dialog, top bar) calls theme-aware surfaceTreatment.paint(...) instead of painting a background itself. That is what lets Fluent reuse Material renderers with a different surface.
3.4 InteractionFeedback
interface InteractionFeedback {
// draws the visual response to press / hover / focus on top of a region
fun indicate(interaction: InteractionState, contentColor: Color, theme: CamoTheme)
}
| Implementation | Look |
|---|---|
Fade (v1, Minimal) | content-color overlay 4% hover, 8% pressed, no ripple, no scale |
Ripple (Material, Later) | Material ink ripple from the touch point, plus a state layer (8% hover, 10% focus, 10% press) |
Opacity | content fades to about 40% while pressed (iOS style) |
Scale | shrinks to about 96% while pressed |
The focus indicator (keyboard focus ring) is also drawn by indicate when focused. A skin must always make keyboard focus visible (WCAG 2.4.7).
3.5 Partial override
val brandSkin = MinimalSkin.copy(button = PillGradientButtonRenderer)
This replaces one renderer and keeps everything else. It's the common case for "our Figma button is special, everything else is Minimal".
Borrowing a renderer from another skin (ADR-28). Product feedback is often "make the tabs behave like Apple's" or "like that app's": the brand look stays, but one component takes another dialect's structure and behavior.
val brandSkin = MinimalSkin.copy(tabs = CupertinoSkin.tabs, switch = CupertinoSkin.switch)
// only one screen: CamouflageProvider(skin = Camouflage.skin.copy(tabs = CupertinoSkin.tabs)) { … }
| Rule | Why |
|---|---|
The borrowed renderer keeps its structure, behavior and defaults(theme) (a segmented control for tabs, the iOS switch proportions). | That's what was asked for. |
It reads the host skin's surfaceTreatment and feedback (always Camouflage.skin.…, never its own skin object). | The component still feels part of the app (flat surfaces, fade feedback under Minimal). To borrow the feel too, copy those as well: .copy(feedback = CupertinoSkin.feedback) on a nested provider. |
| It reads the app's theme (colors, typography, component-theme overrides). | The brand's colors and fonts stay. |
Every skin module exposes its renderers individually (CupertinoSkin.tabs), not only the whole skin. | Borrowing needs no fork. It works once that skin module exists (the Later skins). |
3.6 Rules every renderer follows
- Pure. Its output depends only on
(state, slots, theme), plus internal animation state (e.g. the ripple position). No network, no global singletons, no reading other providers. - Tokens only. It reads colors, sizes and durations only from
style(the resolved component theme) andthemeroles. Every size a designer might change (height, radius, padding, icon size) must come fromstyle, and never be a literal in the renderer. No hard-coded colors, not even for "Material's default grey". Fixed alphas for states (hover 8%) are allowed; they are part of the skin's language. - Sets content color and icon style before invoking a slot (§2.1), and draws text values with theme typography.
- Respects layout direction. It uses start/end, never left/right, so RTL mirrors automatically.
- Never shrinks the touch area below what the component set (48dp minimum).
- Honors reduced motion implicitly, by using
theme.motiondurations (see Theme §5).
3.7 Checklist: writing a new skin (for you or an AI agent)
- Pick the design language and write down its surface metaphor and press feedback.
- Implement
SurfaceTreatmentandInteractionFeedbackfirst. Test them on a bare box. - Write the skin's dialect alignment table: how it renders every Appearance, Tone and Level (Design Language §3.4). Then, for each renderer, write its complete
defaultscomponent theme (this dialect's proportions and color references). Put the tables in the skin's own doc. - Implement the renderers in this order:
text→icon→surface→button→iconButton→card→checkbox→switch→textField→topBar→dialog→bottomSheet, then the rest in milestone order (M3 divider; M5 radio, segmentedControl, slider, searchField; M6 listItem, listSection, menu, tooltip; M7 chip, badge, avatar, progress, snackbar, banner; M8 tabs, navigation bar/rail/drawer, fab). The simplest come first, and later ones reuse the earlier ones. - Check each renderer against the rules in §3.6.
- Run the shared screenshot matrix (skin × light/dark × font scale 100/200% × LTR/RTL). See the platform Testing notes (Testing, Testing).
- Package it as its own module,
camouflage-skin-<name>, depending only oncamouflage-core.
4. Build steps
- Add the shared enums and
InteractionStateto core. - Add
SurfaceTreatmentandInteractionFeedbackinterfaces. - Add
CamoSkinwithname,surfaceTreatment,feedbackandcopy. - In
sample, make aDebugSkinwhose surface and feedback are no-ops. This proves the contract end to end before any real skin exists, and is useful for tests. - Write tests:
copyreplaces one field and keeps the others identical; a skin that leaves out a field doesn't compile (a comment in the test file documents this, since compile errors can't be asserted at runtime). - With each component (M3 to M8, ADR-39): its
XState/XSlotsdata classes, itsXRendererinterface withdefaults(theme)(fields from §3.2), the merge step that resolvesstyle, its requiredCamoSkinfield, and aDebugSkinrenderer that draws a labelled grey box ("Button: High").
Done when
- Core compiles with the contract mechanism, and
DebugSkinimplements it with no warnings (M2). -
copyreplaces one field and keeps the others identical (===). - By M8,
CamoSkinhas all 39 renderers andDebugSkinimplements every one.
5. Edge cases
| Case | Decided behavior |
|---|---|
Overriding one renderer (MinimalSkin.copy(button = X)) | Only button changes. Other renderers that use a button internally (the dialog's confirm action) get the caller's widget. When the caller passes a CamoButton (the recommended way), it uses X, so the override applies consistently inside dialogs too. |
| A renderer ignores a token (hard-codes a color) | A contract violation. The screenshot matrix catches it: the rendering doesn't change between two themes. The skin checklist item 5 is the manual gate. |
| A skin needs an extra parameter (a look only this dialect draws, like Material's wavy progress) | Put it in the skin's own constructor or options object (MaterialSkin(expressiveProgress = true)). Values the skin reads from the brand go in a custom token set (ADR-32). If a brand could want it on any skin (switch thumb icons), it's a component-theme field instead (ADR-28). Never add it to a core component's API, because the core API stays skin-neutral. |
| A skin wants to restructure a component (an iOS alert stacks buttons vertically) | Allowed. That's what a renderer is for. Values and slots stay the same; only placement changes. |
| A renderer needs state the contract lacks (e.g. a switch that shows its thumb while dragging) | Add the field to XState in core (a core minor version plus an ADR). Other skins may ignore it. |
| Two skins in one screen | Supported through nested providers; see Provider and Scoping. Each renderer reads only the skin it was invoked from. |
Implementation
1. Why
This note turns the skin contract into Compose interfaces: one renderer per component, plus surface treatment and interaction feedback, bundled in a CamoSkin data class. The Compose-specific questions it settles:
- how the component's behavior modifiers (click, semantics, touch target) reach the renderer's root;
- how press feedback plugs into Compose's
Indicationsystem; - how a renderer sets the content color and icon style for its slots.
2. Shape
The one rule that makes the split work in Compose: the component builds a behavior Modifier (click handling, semantics, min touch target, focus), and passes it to Render. The renderer must apply it to its outermost layout node, before its own visual modifiers. Then the whole visual box is clickable and focusable, and the ripple bounds match the shape.
3. API
3.1 Renderer interfaces
@Stable
public interface ButtonRenderer {
public fun defaults(theme: CamoTheme): ButtonStyle
@Composable
public fun Render(state: ButtonState, slots: ButtonSlots, theme: CamoTheme, style: ButtonStyle, modifier: Modifier)
}
Every renderer follows this shape (XRenderer, XState, XSlots, XStyle). Renderers without a component theme (TextRenderer, SurfaceRenderer) drop defaults and style.
States and slots (Kotlin additions in bold):
| Class | Fields |
|---|---|
ButtonState | text, enabled, appearance, tone, interaction: InteractionState, interactionSource: InteractionSource |
ButtonSlots | prefixIcon: (@Composable () -> Unit)?, suffixIcon: (@Composable () -> Unit)? |
IconButtonState / Slots | enabled, appearance, tone, interaction, interactionSource / icon: @Composable () -> Unit |
TextFieldState | the base fields, plus interactionSource |
TextFieldSlots | prefixIcon?, suffixIcon?, input: @Composable () -> Unit (the BasicTextField from core) |
CardState / CheckboxState / SwitchState | the base fields, plus interactionSource |
TopBarSlots | navigation?, actions: @Composable RowScope.() -> Unit, titleContent: (@Composable () -> Unit)? |
DialogState | the base fields, including dismissible and onDismissRequest: () -> Unit (read from the frame's LocalCamoOverlayFrame) |
DialogSlots | confirm, dismiss?, content? |
BottomSheetState / Slots | title?, dragProgress, dismissible, onDismissRequest / content: @Composable ColumnScope.() -> Unit |
SurfaceSlots / CardSlots | content: @Composable () -> Unit |
| the 23 renderers added after the first twelve | the base fields from each component note, plus interactionSource wherever the base state has interaction; slot lambdas use Compose receivers where natural (RowScope for actions, LazyItemScope for list items) |
InteractionState stays the base's four booleans (the component derives them with collectIsPressedAsState(), collectIsHoveredAsState(), collectIsFocusedAsState() and collectIsDraggedAsState()). interactionSource is added because Compose's Indication (ripple) needs the source itself, not just booleans.
@Immutable public data class InteractionState(val pressed: Boolean, val focused: Boolean, val hovered: Boolean, val dragged: Boolean = false)
The name clash with Compose's own TextFieldState is resolved by packaging: Camouflage's is com.srctool.camouflage.core.textfield.TextFieldState. Inside core, Compose's is imported under an alias (import androidx.compose.foundation.text.input.TextFieldState as InputBuffer).
3.2 SurfaceTreatment and InteractionFeedback
@Stable
public interface SurfaceTreatment {
/** Background, depth and clip for a container. Applied after the behavior modifier. */
public fun modifier(color: Color, shape: Shape, elevation: Dp, theme: CamoTheme): Modifier
}
@Stable
public interface InteractionFeedback {
/** Compose Indication drawing press / hover / focus feedback in the given content color. */
public fun indication(contentColor: Color, shape: Shape, theme: CamoTheme): Indication // shape: overlays stay inside it, focus rings follow it (as Flutter's wrap)
}
- Flat (skin-minimal, v1):
Modifier.background(color, shape).clip(shape), plusModifier.border(1.dp, outlineVariant, shape)fromLevel1. No shadow. - Fade (skin-minimal, v1): an
IndicationNodeFactorythat draws a content-color overlay (4% hover, 8% pressed) and a 2 dp focus ring. Nomaterial-rippleneeded. - Paper (skin-material, Later):
Modifier.shadow(elevation, shape, clip = false).background(color, shape).clip(shape). - Ripple (skin-material, Later): an
IndicationNodeFactorybuilt onmaterial-ripple'screateRippleModifierNode(the public low-level API), plus a state-layer node for hover and focus and a focus ring. Details are in Material Skin. - Opacity / Scale (future skins): custom
IndicationNodeFactorys that animate alpha or scale from theInteractionSource.
3.3 CamoSkin
@Immutable
public data class CamoSkin(
val name: String,
val surfaceTreatment: SurfaceTreatment,
val feedback: InteractionFeedback,
// 39 renderers, grouped as in base
val text: TextRenderer, val icon: IconRenderer, val surface: SurfaceRenderer, val divider: DividerRenderer,
val button: ButtonRenderer, val iconButton: IconButtonRenderer, val fab: FabRenderer,
val textField: TextFieldRenderer, val checkbox: CheckboxRenderer, val switch: SwitchRenderer, val radio: RadioRenderer,
val segmentedControl: SegmentedControlRenderer, val slider: SliderRenderer, val searchField: SearchFieldRenderer,
val datePicker: DatePickerRenderer, val timePicker: TimePickerRenderer, val stepper: StepperRenderer,
val card: CardRenderer, val listItem: ListItemRenderer, val listSection: ListSectionRenderer, val pagedList: PagedListRenderer, val accordion: AccordionRenderer,
val chip: ChipRenderer, val badge: BadgeRenderer, val avatar: AvatarRenderer,
val progressBar: ProgressBarRenderer, val progressCircle: ProgressCircleRenderer, val snackbar: SnackbarRenderer,
val banner: BannerRenderer, val skeleton: SkeletonRenderer,
val dialog: DialogRenderer, val bottomSheet: BottomSheetRenderer, val menu: MenuRenderer, val tooltip: TooltipRenderer,
val topBar: TopBarRenderer, val tabs: TabsRenderer, val navigationBar: NavigationBarRenderer,
val navigationRail: NavigationRailRenderer, val navigationDrawer: NavigationDrawerRenderer,
)
It has no default values. copy(button = BrandButtonRenderer) is the partial override.
3.4 Helpers for skin authors (public, in core)
/** Sets the content color + icon style for slots drawn inside a renderer. */
@Composable public fun ProvideContentStyle(color: Color, iconStyle: IconStyle, content: @Composable () -> Unit)
/** The current skin's feedback as an Indication, for use with Modifier.indication. */
@Composable public fun rememberSkinIndication(contentColor: Color, shape: Shape): Indication
/** Applies the disabled alphas uniformly. */
public fun Color.disabled(alpha: Float): Color
A renderer reads Camouflage.skin.surfaceTreatment and .feedback at render time, not fixed references to Paper/Ripple. That way MinimalSkin.copy(feedback = Opacity) changes the feedback of every Material renderer.
3.5 Reference: a complete renderer (DebugSkin button)
internal object DebugButtonRenderer : ButtonRenderer {
override fun defaults(theme: CamoTheme) = ButtonStyle(
height = 40.dp, minWidth = 64.dp, shape = theme.shapes.small,
padding = PaddingValues(horizontal = theme.spacing.l), paddingWithIcon = PaddingValues(horizontal = theme.spacing.m),
textStyle = theme.typography.labelLarge, iconSize = 18.dp, iconGap = theme.spacing.s,
borderWidth = 1.dp, raisedElevation = ElevationLevel.Level1,
solidColors = ButtonColors(Color.LightGray, Color.Black), /* soft, raised, outline, ghost, link … */
disabledContainerAlpha = 0.12f, disabledContentAlpha = 0.38f,
)
@Composable
override fun Render(state: ButtonState, slots: ButtonSlots, theme: CamoTheme, style: ButtonStyle, modifier: Modifier) {
val colors = style.colorsFor(state.appearance, state.tone, theme)
Row(
modifier = modifier // 1. behavior first
.then(Camouflage.skin.surfaceTreatment.modifier(colors.container, style.shape, 0.dp, theme))
.indication(state.interactionSource, rememberSkinIndication(colors.content, style.shape))
.border(if (state.interaction.focused) 2.dp else 0.dp, Color.Magenta, style.shape)
.heightIn(min = style.height).widthIn(min = style.minWidth)
.padding(if (slots.prefixIcon != null || slots.suffixIcon != null) style.paddingWithIcon else style.padding),
horizontalArrangement = Arrangement.spacedBy(style.iconGap),
verticalAlignment = Alignment.CenterVertically,
) {
ProvideContentStyle(colors.content, IconStyle(style.iconSize, colors.content)) {
slots.prefixIcon?.invoke()
BasicText("[${state.appearance}] ${state.text}", style = style.textStyle.copy(color = colors.content))
slots.suffixIcon?.invoke()
}
}
}
}
4. Build steps
InteractionState(@Immutable) and the shared enums.SurfaceTreatmentandInteractionFeedback.CamoSkin(name, surfaceTreatment, feedback).ProvideContentStyle,rememberSkinIndication,Color.disabled.DebugSkinin:sample:shared, withNoTreatmentandNoFeedback.commonTest:copy(feedback = X)keeps the other fields referentially equal;- a renderer applying
modifiermakes the whole box clickable (runComposeUiTestwith a test-only renderer: a click on the box's corner firesonClick).
- With each component (M3–M8, ADR-39): its
XState(@Immutable) /XSlots(@Stable), itsXRendererinterface, itsCamoSkinfield, and aDebugSkinrenderer drawing a labelled box (like §3.5).
Done when
-
DebugSkincompiles for all targets (M2), and implements every renderer that exists at each later milestone. - A click anywhere on a renderer's box fires; from M3, the focus border on a DebugSkin button appears with keyboard Tab (desktop).
5. Edge cases
| Case | Decided behavior |
|---|---|
A renderer forgets to apply modifier | Clicks and semantics silently vanish, which is the worst kind of bug. Guard: assertRendererAppliesBehavior(renderer) from the published test-only artifact camouflage-skin-testing, which every skin's test suite (Camouflage's own, brands', generated ones) runs for each clickable renderer. |
A renderer applies modifier after padding | The touch area shrinks to the inner box. The rule is "outermost". The same test utility checks a click at the corner. |
interactionSource added to states (not in base) | A platform addition, needed by Compose's Indication. The base booleans are still present for renderers that only branch on state. |
Name clash with Compose TextFieldState | Solved by package plus an import alias inside core. Apps rarely import both. |
| Skin-specific options | Constructor parameters of the skin's factory function, only for looks tied to that dialect (materialSkin(expressiveProgress = true)), never core parameters. Anything a brand could want on any skin is a component-theme field (ADR-28), e.g. SwitchStyle.showThumbIcons. |
| Performance: renderers are interfaces called every recomposition | Renderers are objects or stable instances inside an @Immutable skin, so Compose can skip them when inputs don't change. Avoid allocating lambdas in Render without remember. |
Web (planned)
1. Why
This note turns the skin contract into TypeScript: one renderer per component, plus a surface treatment and interaction feedback, bundled in a CamoSkin object. The web-specific questions it settles:
- A component is a custom element that owns state, behavior and accessibility. It does not draw itself. It asks the nearest provider for the skin and calls the skin's renderer.
- A renderer is a pure function that returns a Lit template. That is what makes server rendering possible (SSR and Hydration).
- Skins are separate packages, so an app bundles only the skins it uses.
- Slots map to native
<slot>elements, which fits the rule that a renderer decides where a slot goes but never inspects what is inside it.
2. Shape
| Layer | Lives in | Owns |
|---|---|---|
| Component element | core | attributes and properties (state), events, accessibility semantics, form participation |
| Behavior | core | focus management, roving tabindex, keyboard, popover and dialog wiring |
| Renderer | a skin package | the template, the styles, the defaults for the component theme |
| Surface and feedback | a skin package | materials and press, hover and focus responses |
The rule from the base note stays: a renderer can't change what a component does. If a skin needs different behavior (a segmented control for tabs), the behavior layer already provides the behavior, and the renderer decides how to show it.
3. API
3.1 Types
import type { TemplateResult, CSSResultGroup } from "lit";
export interface Renderer<State, Slots extends string, Style> {
/** A complete component theme (every field set); may reference global tokens. */
defaults(theme: CamoTheme): Style;
/** Pure: the output depends only on the arguments. No browser or network access. */
render(args: { state: State; slots: SlotNames<Slots>; theme: CamoTheme; style: Style }): TemplateResult;
/** Styles for this renderer's shadow DOM, shared as constructable stylesheets. */
readonly styles?: CSSResultGroup;
}
/** The names of the native <slot> elements the renderer may place. */
export type SlotNames<S extends string> = { readonly [K in S]: string };
export interface CamoSkin {
readonly name: string; // "minimal", for debugging and tests
readonly surfaceTreatment: SurfaceTreatment;
readonly feedback: InteractionFeedback;
readonly text: Renderer<TextState, never, TextTheme>;
readonly icon: Renderer<IconState, never, IconTheme>;
readonly button: Renderer<ButtonState, "prefix-icon" | "suffix-icon", ButtonTheme>;
readonly dialog: Renderer<DialogState, "confirm" | "dismiss" | "content", DialogTheme>;
// ...one required field per component, as in Kotlin and Dart
}
All fields are required, with no defaults. A skin that misses a renderer fails type-checking. A skin file ends with satisfies CamoSkin so the compiler reports the missing field by name.
3.2 State and slots
| State | Slots | |
|---|---|---|
| Is | plain data: text, enabled, appearance, tone, the interaction state | names of <slot> elements; the caller's nodes go in them (<camo-icon slot="prefix-icon">) |
| Renderer may | branch on it, draw text values in its own styles | place a <slot>, wrap it, give it a content color and icon style, or leave it out |
| Renderer may not | mutate it | look at the slotted nodes |
Content color and icon style: before a slot, the renderer's wrapper sets --camo-content-color and --camo-icon-size (CSS custom properties). camo-text and camo-icon read them by default, so <camo-text>Save</camo-text> inside a Solid button is automatically onPrimary, as in Kotlin and Dart.
3.3 Surface treatment and feedback
export interface SurfaceTreatment {
/** CSS for a region: background, border or shadow, blur, clip to shape. Pure. */
paint(args: { color: string; shape: ShapeRole; elevation: ElevationLevel; theme: CamoTheme; capabilities: CamoCapabilities }): CSSResult;
}
export interface InteractionFeedback {
/** The visual response to hover, press and focus, as styles over a region. */
indicate(args: { contentColor: string; theme: CamoTheme }): CSSResult;
/** Optional: a directive for feedback that needs the element, such as a ripple's origin. */
readonly attach?: (el: HTMLElement) => () => void;
}
- Feedback uses CSS states (
:hover,:active,:focus-visible) wherever it can, which is also what server rendering can emit. - A material (Liquid Glass, Acrylic) reads
capabilitiesfrom the provider (backdropBlur,reduceTransparency, and so on) and follows the chain of ADR-42: refraction (an SVG filter, Chromium only) then blur plus specular edge, then an opaque fill. Mica falls back to Solid. See Theme §3.3. - Keyboard focus is always visible (WCAG 2.4.7), drawn by the feedback.
3.4 Skins as packages
// packages/skin-cupertino/src/index.ts
export const cupertinoSkin = {
name: "cupertino",
surfaceTreatment: classic,
feedback: opacity,
button: cupertinoButton,
dialog: cupertinoDialog,
// ...
} satisfies CamoSkin;
export function cupertinoSkinWith(options: { surface: "classic" | "liquid-glass" }): CamoSkin { /* ... */ }
export { cupertinoButton, cupertinoTabs /* every renderer is exported on its own */ };
// packages/skin-cupertino/src/register.ts (a separate, side-effect entry)
import { registerSkin } from "@srctool/camouflage-core";
import { cupertinoSkin } from "./index";
registerSkin(cupertinoSkin);
- The main entry has no side effects, so bundlers can drop unused renderers (
"sideEffects": false). registeris opt-in and lets theskin="cupertino"attribute work in plain HTML and on the server. In TypeScript, set the typed property instead (provider.skin = cupertinoSkin).- Every skin exports each renderer on its own, so another skin can borrow it.
3.5 Partial override and borrowing
import { minimalSkin } from "@srctool/camouflage-skin-minimal";
import { cupertinoTabs } from "@srctool/camouflage-skin-cupertino";
export const brandSkin = { ...minimalSkin, name: "brand", tabs: cupertinoTabs } satisfies CamoSkin;
A plain object spread replaces any subset and keeps the rest. A borrowed renderer keeps its structure, behavior and defaults(theme), reads the host skin's surface treatment and feedback, and reads the app's theme (ADR-28). On the web, borrowing a renderer means also importing its styles, which the renderer carries with it.
3.6 Rules every renderer follows
- Pure. No
window,document, timers or fetch insiderender. Server rendering depends on it. - Tokens only. Colors, sizes and durations come from
styleand--camo-*variables, never literals. A lint rule and a test check this, as the Kotlin and Dart no-literals tests do. - Sets content color and icon style before a slot.
- Logical properties.
margin-inline-start, neverleft, so right-to-left mirrors by itself. - Touch area of at least 48 px, even if the visual is smaller.
- Reduced motion by reading the motion tokens, which the provider zeroes under
prefers-reduced-motion. - No light DOM leaks. All styles live in the shadow root; only
::part()hooks named in the component note are public.
3.7 Checklist: writing a new skin
Same as the base note, with two web items: export every renderer individually, and provide a register entry.
4. Build steps
- The types of §3.1 and the registry (
registerSkin,resolveSkin(name)). - The behavior layer for the spike components (button, dialog), then the rest per milestone.
skin-minimalrenderers for the components in each milestone, withsatisfies CamoSkinkept compiling at the end of each milestone (a milestone adds a renderer to every skin that exists).skin-cupertinostarted during W1 to W2, to test the contract against structural differences.- A conformance test per renderer: purity (renders the same twice, and on the server), tokens only, logical properties, 48 px target, axe.
Done when
- A skin with a missing renderer fails
tscwith the renderer's name. -
<camo-button>renders under Minimal and Cupertino with no change to the element. - A dialog's actions stack under Cupertino and sit side by side under Minimal from the same markup.
- Every renderer renders on the server and hydrates.
5. Edge cases
| Case | Decided behavior |
|---|---|
| A skin is chosen by attribute but not registered | The provider logs a clear error in development and uses the fallback skin (see the Provider note). |
| Two skins loaded on one page (nested providers) | Each provider holds its own skin; styles are scoped by shadow roots, so they never collide. |
| A renderer needs the element (ripple origin) | Through feedback.attach, never by reading the DOM inside render. |
| A renderer's styles are large | Styles are constructable stylesheets shared by every instance; per-skin packages keep unused skins out of the bundle. |
| A brand overrides a renderer with different slots | The type of slots is per component, so the compiler flags a mismatch. |
6. What W1 settled (srctool/camouflage-web#11)
| Finding | Decision |
|---|---|
| Growing contract | SkinComponents has one renderer per component built so far, and CamoSkin requires all of them. A milestone adds its components' lines, and every skin must follow (Kotlin and Dart list all 54 at once). The web lists 60 since W9: the split pane and the scrollbar joined, and it counts the drawn parts of a component (a segment, a menu item, a tab) as renderers of their own. |
| Incomplete skins | defineSkin({ ...minimalSkin, name: "brand" }) fails to compile, and throws, naming the missing renderer. InProgressSkin compiles while a skin is half built but cannot be registered. registerSkin checks at run time (a JavaScript skin has no compiler). pnpm skins checks every skin package in CI: complete, and a register entry. |
| Shared treatments | Flat, Classic, Fade and Opacity live in core and the skins re-export them. |
| Press feedback | Feedback reacts to :active and to [data-camo-pressed], which PressController sets for pointer and key, so Space and Enter feel like a click. |
| Behavior layer | PressController; focus helpers (tabbables, initialFocusTarget, rememberFocus, hasVisibleFocus); RovingTabindexController (arrow keys, Home, End, wrap, skips disabled, mirrors in right-to-left); setCustomState and reportFormState for ElementInternals; contentVariables for the two variables a container sets. |
| Conformance | Pure (no window, same output twice, same page on the server twice), tokens only, logical properties only, axe, and a 48 px touch area, checked for every scenario variant with no per-component code. The touch-area check found a link button with a 24 px inline target, now fixed. |