Files
clide/lib/builtin/theme_picker/src/theme_families.dart
T
jpmschweitzerandClaude Opus 4.8 5fcc42bd8c tidy the theme switcher popover (T-237)
Per demo feedback on the T-234 status-bar popover: collapse the -hc
theme rows into a single 'High contrast' toggle at the top (applies the
chosen base theme's -hc sibling live, falling back to the base when none
exists); list base themes only, sorted by display name; widen 240->280
and ellipsize rows so 'Catppuccin Mocha' no longer wraps; swap the swatch
dot for the Phosphor palette icon; lowercase the bar label to match the
all-lowercase status bar (proper case kept in the a11y label).

New pure theme_families helpers (base/sibling/resolve), unit-tested.
Modal picker_view consistency + the status-bar right-alignment remain on
T-237.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 22:46:17 +02:00

30 lines
1.6 KiB
Dart

/// Theme-family helpers for the picker surfaces (T-237).
///
/// Bundled themes ship as a base + a high-contrast (`-hc`) / colour-blind
/// (`-cb`) sibling (D-69). The pickers don't list the siblings as separate
/// rows — they show base themes only and expose the variant as a "High
/// contrast" toggle. These pure helpers do the base/sibling bookkeeping so
/// the popover and the modal share one source of truth.
library;
import 'package:clide/kernel/kernel.dart' show ThemeDefinition;
bool isHcName(String name) => name.endsWith('-hc');
bool isCbName(String name) => name.endsWith('-cb');
/// The base theme name for any theme (strips a `-hc`/`-cb` suffix).
String baseThemeName(String name) => (isHcName(name) || isCbName(name)) ? name.substring(0, name.length - 3) : name;
/// Base themes only (no `-hc`/`-cb`), sorted by display name so the list is
/// stable and not "randomly" ordered.
List<ThemeDefinition> baseThemes(List<ThemeDefinition> available) =>
available.where((t) => !isHcName(t.name) && !isCbName(t.name)).toList()..sort((a, b) => a.displayName.toLowerCase().compareTo(b.displayName.toLowerCase()));
/// Whether [base] has a high-contrast sibling among [available].
bool hasHcSibling(List<ThemeDefinition> available, String base) => available.any((t) => t.name == '$base-hc');
/// The theme name to actually apply for a chosen [base] given the high-contrast
/// toggle: the `-hc` sibling when requested and present, else the base itself.
String resolveThemeName(List<ThemeDefinition> available, String base, {required bool highContrast}) =>
(highContrast && hasHcSibling(available, base)) ? '$base-hc' : base;