Files
pipelines/app/lib/ui/theme/paper_theme.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

194 lines
6.7 KiB
Dart

import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'app_design.dart';
import 'app_design_tokens.dart';
import 'app_theme.dart';
import 'paper_controls.dart';
import 'paper_fonts.dart';
import 'paper_palette.dart';
import 'paper_typography.dart';
/// Paper's corner radius: every card, field, menu, dialog, chip, button and
/// thumbnail takes it, so the page has one soft corner throughout.
const double paperRadius = 8;
/// Paper's surfaces: hairline rules on the page rather than filled panels,
/// and no elevation except a whisper of shadow under the pieces that float
/// over the page (menus, dialogs, sheets, snack bars).
class PaperSurfaces {
PaperSurfaces(this.scheme);
final ColorScheme scheme;
static const BorderRadius corners = BorderRadius.all(
Radius.circular(paperRadius),
);
/// The whisper: a low elevation in the page's warm shadow at low alpha.
static const double floatElevation = 3;
Color get shadow => scheme.shadow.withValues(
alpha: scheme.brightness == Brightness.dark ? 0.5 : 0.22,
);
BorderSide get hairline => BorderSide(color: scheme.outlineVariant);
/// A floating piece's fill: the brightest paper, so it lifts off the page
/// by tone and hairline rather than by shadow.
Color get floating => scheme.brightness == Brightness.dark
? scheme.surfaceContainerHigh
: scheme.surfaceContainerLowest;
RoundedRectangleBorder get framed =>
RoundedRectangleBorder(borderRadius: corners, side: hairline);
static const RoundedRectangleBorder rounded = RoundedRectangleBorder(
borderRadius: corners,
);
}
/// The Paper design's theme: a warm paper page (or night paper in dark), ink
/// text with a muted secondary ink and one deep-blue accent, titles and
/// reading text in a bundled serif with the interface font for chrome, soft
/// [paperRadius] corners, hairline rules and almost no elevation. Building it
/// starts loading the serif ([ensurePaperFonts]).
ThemeData paperTheme(Brightness brightness, {String? fontFamily}) {
unawaited(ensurePaperFonts());
final scheme = paperColorScheme(brightness);
final surfaces = PaperSurfaces(scheme);
final base = ThemeData(
platform: kIsWeb ? TargetPlatform.android : null,
colorScheme: scheme,
fontFamily: fontFamily,
scaffoldBackgroundColor: scheme.surface,
canvasColor: scheme.surface,
pageTransitionsTheme: appPageTransitions,
dividerColor: scheme.outlineVariant,
shadowColor: surfaces.shadow,
extensions: [
AppDesignTokens(
design: AppDesign.paper,
radius: paperRadius,
flat: true,
frame: scheme.outlineVariant,
panel: scheme.surface,
ansi: brightness == Brightness.dark
? paperDarkAccents
: paperLightAccents,
transcript: TranscriptStyle.manuscript,
composer: ComposerStyle.underline,
selectedRow: SelectedRowStyle.washed,
reading: paperReading,
chatColorSaturation: 0.45,
),
],
);
final floating = surfaces.floating;
final floatingShape = RoundedRectangleBorder(
borderRadius: PaperSurfaces.corners,
side: surfaces.hairline,
);
return paperControls(
base.copyWith(
textTheme: paperTextTheme(base.textTheme),
primaryTextTheme: paperTextTheme(base.primaryTextTheme),
appBarTheme: AppBarTheme(
backgroundColor: scheme.surface,
foregroundColor: scheme.onSurface,
surfaceTintColor: const Color(0x00000000),
elevation: 0,
scrolledUnderElevation: 0,
shape: Border(bottom: surfaces.hairline),
),
// Only the hairline and the corners: each card variant keeps its own
// fill, so a selected graph node still reads apart.
cardTheme: CardThemeData(
elevation: 0,
shadowColor: const Color(0x00000000),
surfaceTintColor: const Color(0x00000000),
shape: surfaces.framed,
),
dialogTheme: DialogThemeData(
backgroundColor: floating,
surfaceTintColor: const Color(0x00000000),
elevation: PaperSurfaces.floatElevation,
shadowColor: surfaces.shadow,
shape: floatingShape,
),
bottomSheetTheme: BottomSheetThemeData(
backgroundColor: floating,
modalBackgroundColor: floating,
surfaceTintColor: const Color(0x00000000),
elevation: PaperSurfaces.floatElevation,
modalElevation: PaperSurfaces.floatElevation,
shadowColor: surfaces.shadow,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(paperRadius),
),
),
dragHandleColor: scheme.outline,
),
popupMenuTheme: PopupMenuThemeData(
color: floating,
surfaceTintColor: const Color(0x00000000),
elevation: PaperSurfaces.floatElevation,
shadowColor: surfaces.shadow,
shape: floatingShape,
),
snackBarTheme: SnackBarThemeData(
backgroundColor: scheme.inverseSurface,
contentTextStyle: base.textTheme.bodyMedium?.copyWith(
color: scheme.onInverseSurface,
),
actionTextColor: scheme.inversePrimary,
elevation: PaperSurfaces.floatElevation,
shape: PaperSurfaces.rounded,
),
tooltipTheme: TooltipThemeData(
decoration: BoxDecoration(
color: scheme.inverseSurface.withValues(alpha: 0.94),
borderRadius: const BorderRadius.all(Radius.circular(4)),
),
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
textStyle: base.textTheme.bodySmall?.copyWith(
color: scheme.onInverseSurface,
),
),
dividerTheme: DividerThemeData(
color: scheme.outlineVariant,
thickness: 1,
space: 1,
),
navigationRailTheme: NavigationRailThemeData(
backgroundColor: scheme.surface,
elevation: 0,
indicatorColor: scheme.secondaryContainer,
indicatorShape: PaperSurfaces.rounded,
),
navigationBarTheme: NavigationBarThemeData(
backgroundColor: scheme.surface,
elevation: 0,
indicatorColor: scheme.secondaryContainer,
indicatorShape: PaperSurfaces.rounded,
surfaceTintColor: const Color(0x00000000),
),
drawerTheme: DrawerThemeData(
backgroundColor: scheme.surface,
surfaceTintColor: const Color(0x00000000),
elevation: PaperSurfaces.floatElevation,
shadowColor: surfaces.shadow,
),
textSelectionTheme: TextSelectionThemeData(
cursorColor: scheme.primary,
selectionColor: scheme.primary.withValues(alpha: 0.22),
selectionHandleColor: scheme.primary,
),
),
surfaces,
);
}