Files
pipelines/app/lib/ui/theme/notebook_theme.dart
T
alan 113063b040 Notebook design: numbered In/Out cells, tool sub-cells and an input-cell composer
Adds the Notebook design (TranscriptStyle.cells, ComposerStyle.cell), a
white/charcoal IDE theme with light grey cells, hairlines and 5px corners.

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

209 lines
7.6 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'app_design.dart';
import 'app_design_tokens.dart';
import 'app_theme.dart';
import 'notebook_controls.dart';
import 'notebook_palette.dart';
/// Notebook's corner radius: cells, cards, fields, menus, dialogs, chips and
/// buttons all take it, a notebook IDE's small soft corner.
const double notebookRadius = 5;
/// Notebook's reading type: the interface sans a step under the body size on
/// an airy line, as a notebook sets its markdown cells.
const ReadingType notebookReading = ReadingType(height: 1.5, scale: 15 / 16);
/// Notebook's surfaces: a white page, light grey cells, hairline borders and
/// a faint shadow only under the pieces that float (menus, dialogs, sheets,
/// snack bars), as an IDE draws its popups.
class NotebookSurfaces {
NotebookSurfaces(this.scheme);
final ColorScheme scheme;
static const BorderRadius corners = BorderRadius.all(
Radius.circular(notebookRadius),
);
/// A floating piece's elevation: just enough shadow to lift it.
static const double floatElevation = 2;
Color get shadow => scheme.shadow.withValues(
alpha: scheme.brightness == Brightness.dark ? 0.55 : 0.18,
);
BorderSide get hairline => BorderSide(color: scheme.outlineVariant);
/// The page white (or the dark page's raised grey) a floating piece takes.
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 Notebook design's theme: a clean light page (a charcoal one in dark)
/// with light grey cells, hairline borders, [notebookRadius] corners, the
/// device's interface sans for chrome and the bundled monospace for code
/// and the cells' gutter labels; the chat is drawn as numbered In/Out cells
/// ([TranscriptStyle.cells]) with an input cell for the composer.
ThemeData notebookTheme(Brightness brightness, {String? fontFamily}) {
final scheme = notebookColorScheme(brightness);
final surfaces = NotebookSurfaces(scheme);
final dark = brightness == Brightness.dark;
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.notebook,
radius: notebookRadius,
flat: true,
frame: scheme.outlineVariant,
panel: dark
? scheme.surfaceContainerLow
: scheme.surfaceContainerLowest,
ansi: dark ? notebookDarkAccents : notebookLightAccents,
transcript: TranscriptStyle.cells,
composer: ComposerStyle.cell,
selectedRow: SelectedRowStyle.washed,
reading: notebookReading,
chatColorSaturation: 0.7,
),
],
);
final text = notebookTextTheme(base.textTheme);
final floatingShape = surfaces.framed;
return notebookControls(
base.copyWith(
textTheme: text,
primaryTextTheme: notebookTextTheme(base.primaryTextTheme),
// A toolbar: the page colour, a hairline beneath and a compact title.
appBarTheme: AppBarTheme(
backgroundColor: scheme.surface,
foregroundColor: scheme.onSurface,
surfaceTintColor: const Color(0x00000000),
elevation: 0,
scrolledUnderElevation: 0,
titleTextStyle: text.titleMedium?.copyWith(color: scheme.onSurface),
shape: Border(bottom: surfaces.hairline),
),
cardTheme: CardThemeData(
elevation: 0,
shadowColor: const Color(0x00000000),
surfaceTintColor: const Color(0x00000000),
shape: surfaces.framed,
),
dialogTheme: DialogThemeData(
backgroundColor: surfaces.floating,
surfaceTintColor: const Color(0x00000000),
elevation: NotebookSurfaces.floatElevation,
shadowColor: surfaces.shadow,
shape: floatingShape,
titleTextStyle: text.titleMedium?.copyWith(color: scheme.onSurface),
),
bottomSheetTheme: BottomSheetThemeData(
backgroundColor: surfaces.floating,
modalBackgroundColor: surfaces.floating,
surfaceTintColor: const Color(0x00000000),
elevation: NotebookSurfaces.floatElevation,
modalElevation: NotebookSurfaces.floatElevation,
shadowColor: surfaces.shadow,
shape: RoundedRectangleBorder(
borderRadius: const BorderRadius.vertical(
top: Radius.circular(notebookRadius),
),
side: surfaces.hairline,
),
dragHandleColor: scheme.outline,
),
popupMenuTheme: PopupMenuThemeData(
color: surfaces.floating,
surfaceTintColor: const Color(0x00000000),
elevation: NotebookSurfaces.floatElevation,
shadowColor: surfaces.shadow,
shape: floatingShape,
menuPadding: const EdgeInsets.symmetric(vertical: 4),
),
snackBarTheme: SnackBarThemeData(
backgroundColor: scheme.inverseSurface,
contentTextStyle: text.bodyMedium?.copyWith(
color: scheme.onInverseSurface,
),
actionTextColor: scheme.inversePrimary,
elevation: NotebookSurfaces.floatElevation,
shape: NotebookSurfaces.rounded,
),
tooltipTheme: TooltipThemeData(
decoration: BoxDecoration(
color: scheme.inverseSurface,
borderRadius: const BorderRadius.all(Radius.circular(4)),
),
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
textStyle: text.bodySmall?.copyWith(color: scheme.onInverseSurface),
),
dividerTheme: DividerThemeData(
color: scheme.outlineVariant,
thickness: 1,
space: 1,
),
navigationRailTheme: NavigationRailThemeData(
backgroundColor: scheme.surface,
elevation: 0,
indicatorColor: scheme.primaryContainer,
indicatorShape: NotebookSurfaces.rounded,
),
navigationBarTheme: NavigationBarThemeData(
backgroundColor: scheme.surface,
elevation: 0,
indicatorColor: scheme.primaryContainer,
indicatorShape: NotebookSurfaces.rounded,
surfaceTintColor: const Color(0x00000000),
),
drawerTheme: DrawerThemeData(
backgroundColor: scheme.surface,
surfaceTintColor: const Color(0x00000000),
elevation: NotebookSurfaces.floatElevation,
shadowColor: surfaces.shadow,
shape: const RoundedRectangleBorder(),
),
textSelectionTheme: TextSelectionThemeData(
cursorColor: scheme.primary,
selectionColor: scheme.primary.withValues(alpha: dark ? 0.32 : 0.2),
selectionHandleColor: scheme.primary,
),
),
surfaces,
);
}
/// [base] for Notebook: the interface sans throughout with titles a little
/// tighter and semibold, as an IDE heads its panes, and no added tracking on
/// labels.
TextTheme notebookTextTheme(TextTheme base) {
TextStyle? title(TextStyle? style, double size) => style?.copyWith(
fontSize: size,
fontWeight: FontWeight.w600,
letterSpacing: 0,
);
return base.copyWith(
headlineSmall: title(base.headlineSmall, 22),
titleLarge: title(base.titleLarge, 19),
titleMedium: title(base.titleMedium, 15),
titleSmall: base.titleSmall?.copyWith(fontWeight: FontWeight.w600),
);
}