Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 2 additions & 84 deletions packages/material_ui/lib/src/chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import 'theme.dart';
import 'theme_data.dart';
import 'tooltip.dart';

part 'generated/chip_defaults_m3.g.dart';

// Some design constants
const double _kChipHeight = 32.0;

Expand Down Expand Up @@ -2516,87 +2518,3 @@ class _RenderEnsureMinSemanticsSize extends RenderProxyBox {
);
}
}

// BEGIN GENERATED TOKEN PROPERTIES - Chip

// Do not edit by hand. The code between the "BEGIN GENERATED" and
// "END GENERATED" comments are generated from data in the Material
// Design token database by the script:
// dev/tools/gen_defaults/bin/gen_defaults.dart.

// dart format off
class _ChipDefaultsM3 extends ChipThemeData {
_ChipDefaultsM3(this.context, this.isEnabled)
: super(
elevation: 0.0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))),
showCheckmark: true,
);

final BuildContext context;
final bool isEnabled;
late final ColorScheme _colors = Theme.of(context).colorScheme;
late final TextTheme _textTheme = Theme.of(context).textTheme;

@override
TextStyle? get labelStyle => _textTheme.labelLarge?.copyWith(
color: isEnabled
? _colors.onSurfaceVariant
: _colors.onSurface,
);

@override
WidgetStateProperty<Color?>? get color => null; // Subclasses override this getter

@override
Color? get shadowColor => Colors.transparent;

@override
Color? get surfaceTintColor => Colors.transparent;

@override
Color? get checkmarkColor => null;

@override
Color? get deleteIconColor => isEnabled
? _colors.onSurfaceVariant
: _colors.onSurface;

@override
BorderSide? get side => isEnabled
? BorderSide(color: _colors.outlineVariant)
: BorderSide(color: _colors.onSurface.withOpacity(0.12));

@override
IconThemeData? get iconTheme => IconThemeData(
color: isEnabled
? _colors.primary
: _colors.onSurface,
size: 18.0,
);

@override
EdgeInsetsGeometry? get padding => const EdgeInsets.all(8.0);

/// The label padding of the chip scales with the font size specified in the
/// [labelStyle], and the system font size settings that scale font sizes
/// globally.
///
/// The chip at effective font size 14.0 starts with 8px on each side and as
/// the font size scales up to closer to 28.0, the label padding is linearly
/// interpolated from 8px to 4px. Once the label has a font size of 2 or
/// higher, label padding remains 4px.
@override
EdgeInsetsGeometry? get labelPadding {
final double fontSize = labelStyle?.fontSize ?? 14.0;
final double fontSizeRatio = MediaQuery.textScalerOf(context).scale(fontSize) / 14.0;
return EdgeInsets.lerp(
const EdgeInsets.symmetric(horizontal: 8.0),
const EdgeInsets.symmetric(horizontal: 4.0),
clampDouble(fontSizeRatio - 1.0, 0.0, 1.0),
)!;
}
}
// dart format on

// END GENERATED TOKEN PROPERTIES - Chip
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Do not edit by hand. The code is generated from data in the Material
// Design token database by the script:
// packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart.
part of '../chip.dart';

class _ChipDefaultsM3 extends ChipThemeData {
_ChipDefaultsM3(this.context, this.isEnabled)
: super(
Expand Down
4 changes: 2 additions & 2 deletions packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import '../templates/banner_template.dart';
import '../templates/bottom_sheet_template.dart';
import '../templates/button_template.dart';
import '../templates/card_template.dart';
import '../templates/chip_template.dart';

// import '../templates/checkbox_template.dart';
// import '../templates/chip_template.dart';
// import '../templates/color_scheme_template.dart';
// import '../templates/date_picker_template.dart';
// import '../templates/dialog_template.dart';
Expand Down Expand Up @@ -79,7 +79,7 @@ Future<void> main(List<String> args) async {
const CardTemplateM3('Filled Card').generateFile(verbose: verbose);
const CardTemplateM3('Outlined Card').generateFile(verbose: verbose);
// const CheckboxTemplateM3().generateFile(verbose: verbose);
// const ChipTemplateM3().generateFile(verbose: verbose);
const ChipTemplateM3().generateFile(verbose: verbose);
// const ColorSchemeTemplateM3().generateFile(verbose: verbose);
// const DatePickerTemplateM3().generateFile(verbose: verbose);
// const DialogTemplateM3().generateFile(verbose: verbose);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import '../data/filter_chip.dart';
import 'template.dart';

class ChipTemplate extends TokenTemplate {
const ChipTemplate(
super.blockName,
super.fileName,
super.tokens, {
super.colorSchemePrefix = '_colors.',
super.textThemePrefix = '_textTheme.',
});
class ChipTemplateM3 extends TokenTemplateM3 {
const ChipTemplateM3();

static const String tokenGroup = 'md.comp.filter-chip';
static const String variant = '.flat';
@override
String get name => 'Chip';

@override
String get parentFilePath => 'chip.dart';

@override
String generate() =>
String generateContents(String className) =>
'''
class _${blockName}DefaultsM3 extends ChipThemeData {
_${blockName}DefaultsM3(this.context, this.isEnabled)
class $className extends ChipThemeData {
$className(this.context, this.isEnabled)
: super(
elevation: ${elevation("$tokenGroup$variant.container")},
shape: ${shape("$tokenGroup.container")},
elevation: ${number(TokenFilterChip.flatContainerElevation)},
shape: ${shape(TokenFilterChip.containerShape)},
showCheckmark: true,
);

Expand All @@ -33,40 +31,40 @@ class _${blockName}DefaultsM3 extends ChipThemeData {
late final TextTheme _textTheme = Theme.of(context).textTheme;

@override
TextStyle? get labelStyle => ${textStyle("$tokenGroup.label-text")}?.copyWith(
TextStyle? get labelStyle => ${textStyle(TokenFilterChip.labelTextType, '_textTheme')}?.copyWith(
color: isEnabled
? ${color("$tokenGroup.unselected.label-text.color")}
: ${color("$tokenGroup.disabled.label-text.color")},
? ${color(TokenFilterChip.unselectedLabelTextColor, '_colors')}
: ${color(TokenFilterChip.disabledLabelTextColor, '_colors')},
);

@override
WidgetStateProperty<Color?>? get color => null; // Subclasses override this getter

@override
Color? get shadowColor => ${colorOrTransparent("$tokenGroup.container.shadow-color")};
Color? get shadowColor => Colors.transparent;

@override
Color? get surfaceTintColor => ${colorOrTransparent("$tokenGroup.container.surface-tint-layer.color")};
Color? get surfaceTintColor => Colors.transparent;

@override
Color? get checkmarkColor => null;

@override
Color? get deleteIconColor => isEnabled
? ${color("$tokenGroup.with-trailing-icon.unselected.trailing-icon.color")}
: ${color("$tokenGroup.with-trailing-icon.disabled.trailing-icon.color")};
? ${color(TokenFilterChip.withTrailingIconUnselectedTrailingIconColor, '_colors')}
: ${color(TokenFilterChip.withTrailingIconDisabledTrailingIconColor, '_colors')};

@override
BorderSide? get side => isEnabled
? ${border('$tokenGroup$variant.unselected.outline')}
: ${border('$tokenGroup$variant.disabled.unselected.outline')};
? ${border(color(TokenFilterChip.flatUnselectedOutlineColor, '_colors'), width: TokenFilterChip.flatUnselectedOutlineWidth)}
: ${border(colorWithOpacity(TokenFilterChip.flatDisabledUnselectedOutlineColor, TokenFilterChip.flatDisabledUnselectedOutlineOpacity, '_colors'))};

@override
IconThemeData? get iconTheme => IconThemeData(
color: isEnabled
? ${color("$tokenGroup.with-leading-icon.unselected.leading-icon.color")}
: ${color("$tokenGroup.with-leading-icon.disabled.leading-icon.color")},
size: ${getToken("$tokenGroup.with-icon.icon.size")},
? ${color(TokenFilterChip.withLeadingIconUnselectedLeadingIconColor, '_colors')}
: ${color(TokenFilterChip.withLeadingIconDisabledLeadingIconColor, '_colors')},
size: ${number(TokenFilterChip.withIconIconSize)},
);

@override
Expand Down
17 changes: 14 additions & 3 deletions packages/material_ui/tool/gen_defaults/test/gen_defaults_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import '../templates/bottom_sheet_template.dart';
import '../templates/button_template.dart';
import '../templates/card_template.dart';
// import '../templates/checkbox_template.dart';
// import '../templates/chip_template.dart';
import '../templates/chip_template.dart';
// import '../templates/color_scheme_template.dart';
// import '../templates/date_picker_template.dart';
// import '../templates/dialog_template.dart';
Expand Down Expand Up @@ -475,8 +475,19 @@ void main() {
});

test('ChipTemplateM3 emits M3 Chip defaults from tokens', () {
// Intentionally empty, will be implemented during migration. See:
// https://github.com/flutter/flutter/issues/187899
final String contents = const ChipTemplateM3().generateContents('_ChipDefaultsM3');
expect(contents, contains('class _ChipDefaultsM3 extends ChipThemeData'));
expect(contents, contains('elevation: 0.0'));
expect(
contents,
contains(
'shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0)))',
),
);
expect(contents, contains('Color? get shadowColor => Colors.transparent'));
expect(contents, contains('Color? get surfaceTintColor => Colors.transparent'));
expect(contents, contains('BorderSide(color: _colors.onSurface.withOpacity(0.12))'));
expect(contents, contains('size: 18.0'));
});

test('ColorSchemeTemplateM3 emits M3 ColorScheme defaults from tokens', () {
Expand Down
Loading