Files
pipelines/app/lib/ui/theme/app_design_tokens.dart
T
alan 7d2c3412a1 Paper design: warm paper, serif reading text and a typeset transcript
Adds the Paper design and generalises design tokens (transcript, composer,
selected-row styles, reading type, panel fill, chat colour saturation).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 18:00:07 +00:00

167 lines
5.4 KiB
Dart

import 'package:flutter/material.dart';
import 'app_design.dart';
import 'app_design_styles.dart';
export 'app_design_styles.dart';
/// The muted ANSI-style accents a design names for status and roles. The
/// Default design leaves them to its colour scheme; Terminal sets them, and
/// Paper sets ink-toned ones.
@immutable
class AnsiAccents {
const AnsiAccents({
required this.green,
required this.cyan,
required this.yellow,
required this.red,
required this.magenta,
required this.blue,
});
final Color green;
final Color cyan;
final Color yellow;
final Color red;
final Color magenta;
final Color blue;
}
/// The design-specific facts widgets read instead of hard-coding one look:
/// corner shapes, whether surfaces are flat, frame colour, how the chat
/// transcript, the composer and the open list row are drawn, and the reading
/// typography. Every theme an [AppDesign] builds carries one; a theme without
/// one (a test's bare `ThemeData`) reads as [standard].
///
/// Adding a design: every field has a default that keeps the Default look,
/// so a new design sets only what it changes. Widgets branch on the named
/// styles ([transcript], [composer], [selectedRow]) rather than on [design],
/// so two designs can share a behaviour.
@immutable
class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
const AppDesignTokens({
required this.design,
this.radius,
this.flat = false,
this.frame,
this.panel,
this.ansi,
this.promptGlyph = '>',
this.transcript = TranscriptStyle.bubbles,
this.composer = ComposerStyle.pill,
this.selectedRow = SelectedRowStyle.tonal,
this.reading = const ReadingType(),
this.chatColorSaturation = 1,
});
/// The Default design: every widget keeps its own shapes.
static const AppDesignTokens standard = AppDesignTokens(
design: AppDesign.standard,
);
final AppDesign design;
/// The corner radius of framed surfaces (cards, pills, the composer,
/// bubbles, thumbnails, badges); null keeps each widget's own shape.
final double? radius;
/// Whether surfaces are flat: no frosted glass, blur, highlight or shadow.
final bool flat;
/// The 1px frame colour around flat surfaces; null keeps each widget's own.
final Color? frame;
/// The fill of a flat design's own panels (settings groups, floating bars,
/// cards a widget draws itself); null keeps `surfaceContainerLow`.
final Color? panel;
/// The design's ANSI-style accents; null for a design that uses its colour
/// scheme's roles.
final AnsiAccents? ansi;
/// The glyph before the operator's prompt line and the composer's field.
final String promptGlyph;
/// How the chat transcript draws the operator's and the agent's turns.
final TranscriptStyle transcript;
/// How the chat composer frames its writing area.
final ComposerStyle composer;
/// How a list marks its open row.
final SelectedRowStyle selectedRow;
/// The face, line height and measure of reading text (chat, documents).
final ReadingType reading;
/// How much of a chat colour's saturation the transcript keeps: 1 for the
/// palette as is, lower to quieten it towards ink.
final double chatColorSaturation;
/// Whether the transcript draws prompt and tool lines rather than bubbles.
bool get terminal => transcript == TranscriptStyle.prompt;
/// The tokens of the theme at [context]; [standard] when it has none.
static AppDesignTokens of(BuildContext context) =>
Theme.of(context).extension<AppDesignTokens>() ?? standard;
/// [designed] as this design draws it: the widget's own shape, or a
/// rectangle with [radius] corners.
OutlinedBorder shape(OutlinedBorder designed) {
final r = radius;
if (r == null) return designed;
return RoundedRectangleBorder(borderRadius: BorderRadius.circular(r));
}
/// [designed] corners, or [radius] corners under a design that sets it.
BorderRadius corners(BorderRadius designed) {
final r = radius;
return r == null ? designed : BorderRadius.circular(r);
}
/// [designed] (a widget's own fill) or, under a flat design, its [panel].
Color panelFill(ColorScheme scheme, Color designed) =>
flat ? panel ?? scheme.surfaceContainerLow : designed;
/// The hairline a flat design frames its panels with; null keeps none.
BorderSide? get frameSide {
final color = frame;
return color == null ? null : BorderSide(color: color);
}
@override
AppDesignTokens copyWith({
AppDesign? design,
double? radius,
bool? flat,
Color? frame,
Color? panel,
AnsiAccents? ansi,
String? promptGlyph,
TranscriptStyle? transcript,
ComposerStyle? composer,
SelectedRowStyle? selectedRow,
ReadingType? reading,
double? chatColorSaturation,
}) => AppDesignTokens(
design: design ?? this.design,
radius: radius ?? this.radius,
flat: flat ?? this.flat,
frame: frame ?? this.frame,
panel: panel ?? this.panel,
ansi: ansi ?? this.ansi,
promptGlyph: promptGlyph ?? this.promptGlyph,
transcript: transcript ?? this.transcript,
composer: composer ?? this.composer,
selectedRow: selectedRow ?? this.selectedRow,
reading: reading ?? this.reading,
chatColorSaturation: chatColorSaturation ?? this.chatColorSaturation,
);
/// Designs switch whole: a theme animation snaps halfway rather than
/// blending two designs' shapes.
@override
AppDesignTokens lerp(AppDesignTokens? other, double t) =>
other == null || t < 0.5 ? this : other;
}