Migrate Chips to Material 3 (#107166)
This commit is contained in:
@@ -20,6 +20,9 @@ import 'dart:io';
|
||||
import 'package:gen_defaults/app_bar_template.dart';
|
||||
import 'package:gen_defaults/button_template.dart';
|
||||
import 'package:gen_defaults/card_template.dart';
|
||||
import 'package:gen_defaults/chip_action_template.dart';
|
||||
import 'package:gen_defaults/chip_filter_template.dart';
|
||||
import 'package:gen_defaults/chip_input_template.dart';
|
||||
import 'package:gen_defaults/dialog_template.dart';
|
||||
import 'package:gen_defaults/fab_template.dart';
|
||||
import 'package:gen_defaults/icon_button_template.dart';
|
||||
@@ -101,6 +104,10 @@ Future<void> main(List<String> args) async {
|
||||
ButtonTemplate('md.comp.outlined-button', '$materialLib/outlined_button.dart', tokens).updateFile();
|
||||
ButtonTemplate('md.comp.text-button', '$materialLib/text_button.dart', tokens).updateFile();
|
||||
CardTemplate('$materialLib/card.dart', tokens).updateFile();
|
||||
ChipActionTemplate('$materialLib/chip_action.dart', tokens).updateFile();
|
||||
ChipFilterTemplate('$materialLib/chip_filter.dart', tokens).updateFile();
|
||||
ChipFilterTemplate('$materialLib/chip_choice.dart', tokens).updateFile();
|
||||
ChipInputTemplate('$materialLib/chip_input.dart', tokens).updateFile();
|
||||
DialogTemplate('$materialLib/dialog.dart', tokens).updateFile();
|
||||
FABTemplate('$materialLib/floating_action_button.dart', tokens).updateFile();
|
||||
IconButtonTemplate('$materialLib/icon_button.dart', tokens).updateFile();
|
||||
|
||||
80
dev/tools/gen_defaults/lib/chip_action_template.dart
Normal file
80
dev/tools/gen_defaults/lib/chip_action_template.dart
Normal file
@@ -0,0 +1,80 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'template.dart';
|
||||
|
||||
class ChipActionTemplate extends TokenTemplate {
|
||||
|
||||
const ChipActionTemplate(super.fileName, super.tokens);
|
||||
|
||||
static const String tokenGroup = 'md.comp.assist-chip';
|
||||
static const String variant = '.flat';
|
||||
|
||||
@override
|
||||
String generate() => '''
|
||||
// Generated version ${tokens["version"]}
|
||||
class _TokenDefaultsM3 extends ChipThemeData {
|
||||
const _TokenDefaultsM3(this.context, this.isEnabled)
|
||||
: super(
|
||||
elevation: ${elevation("$tokenGroup$variant.container")},
|
||||
shape: ${shape("$tokenGroup.container")},
|
||||
showCheckmark: true,
|
||||
);
|
||||
|
||||
final BuildContext context;
|
||||
final bool isEnabled;
|
||||
|
||||
@override
|
||||
TextStyle? get labelStyle => ${textStyle("$tokenGroup.label-text")};
|
||||
|
||||
@override
|
||||
Color? get backgroundColor => ${componentColor("$tokenGroup$variant.container")};
|
||||
|
||||
@override
|
||||
Color? get shadowColor => ${color("$tokenGroup.container.shadow-color")};
|
||||
|
||||
@override
|
||||
@override Color? get surfaceTintColor => ${color("$tokenGroup.container.surface-tint-layer.color")};
|
||||
|
||||
@override
|
||||
Color? get selectedColor => ${componentColor("$tokenGroup$variant.selected.container")};
|
||||
|
||||
@override
|
||||
Color? get checkmarkColor => ${color("$tokenGroup.with-icon.selected.icon.color")};
|
||||
|
||||
@override
|
||||
Color? get disabledColor => ${componentColor("$tokenGroup$variant.disabled.container")};
|
||||
|
||||
@override
|
||||
Color? get deleteIconColor => ${color("$tokenGroup.with-icon.selected.icon.color")};
|
||||
|
||||
@override
|
||||
BorderSide? get side => isEnabled
|
||||
? ${border('$tokenGroup$variant.outline')}
|
||||
: ${border('$tokenGroup$variant.disabled.outline')};
|
||||
|
||||
@override
|
||||
IconThemeData? get iconTheme => IconThemeData(
|
||||
color: isEnabled
|
||||
? ${color("$tokenGroup.with-icon.icon.color")}
|
||||
: ${color("$tokenGroup.with-icon.disabled.icon.color")},
|
||||
size: ${tokens["$tokenGroup.with-icon.icon.size"]},
|
||||
);
|
||||
|
||||
@override
|
||||
EdgeInsetsGeometry? get padding => const EdgeInsets.all(8.0);
|
||||
|
||||
/// The chip at text scale 1 starts with 8px on each side and as text scaling
|
||||
/// gets closer to 2 the label padding is linearly interpolated from 8px to 4px.
|
||||
/// Once the widget has a text scaling of 2 or higher than the label padding
|
||||
/// remains 4px.
|
||||
@override
|
||||
EdgeInsetsGeometry? get labelPadding => EdgeInsets.lerp(
|
||||
const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
const EdgeInsets.symmetric(horizontal: 4.0),
|
||||
clampDouble(MediaQuery.of(context).textScaleFactor - 1.0, 0.0, 1.0),
|
||||
)!;
|
||||
}
|
||||
''';
|
||||
}
|
||||
86
dev/tools/gen_defaults/lib/chip_filter_template.dart
Normal file
86
dev/tools/gen_defaults/lib/chip_filter_template.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'template.dart';
|
||||
|
||||
class ChipFilterTemplate extends TokenTemplate {
|
||||
const ChipFilterTemplate(super.fileName, super.tokens);
|
||||
|
||||
static const String tokenGroup = 'md.comp.filter-chip';
|
||||
static const String variant = '.flat';
|
||||
|
||||
@override
|
||||
String generate() => '''
|
||||
// Generated version ${tokens["version"]}
|
||||
class _TokenDefaultsM3 extends ChipThemeData {
|
||||
const _TokenDefaultsM3(this.context, this.isEnabled, this.isSelected)
|
||||
: super(
|
||||
elevation: ${elevation("$tokenGroup$variant.container")},
|
||||
shape: ${shape("$tokenGroup.container")},
|
||||
showCheckmark: true,
|
||||
);
|
||||
|
||||
final BuildContext context;
|
||||
final bool isEnabled;
|
||||
final bool isSelected;
|
||||
|
||||
@override
|
||||
TextStyle? get labelStyle => ${textStyle("$tokenGroup.label-text")};
|
||||
|
||||
@override
|
||||
Color? get backgroundColor => ${componentColor("$tokenGroup$variant.container")};
|
||||
|
||||
@override
|
||||
Color? get shadowColor => ${color("$tokenGroup.container.shadow-color")};
|
||||
|
||||
@override
|
||||
@override Color? get surfaceTintColor => ${color("$tokenGroup.container.surface-tint-layer.color")};
|
||||
|
||||
@override
|
||||
Color? get selectedColor => isEnabled
|
||||
? ${componentColor("$tokenGroup$variant.selected.container")}
|
||||
: ${componentColor("$tokenGroup$variant.disabled.selected.container")};
|
||||
|
||||
@override
|
||||
Color? get checkmarkColor => ${color("$tokenGroup.with-icon.selected.icon.color")};
|
||||
|
||||
@override
|
||||
Color? get disabledColor => isSelected
|
||||
? ${componentColor("$tokenGroup$variant.disabled.selected.container")}
|
||||
: ${componentColor("$tokenGroup$variant.disabled.unselected.container")};
|
||||
|
||||
@override
|
||||
Color? get deleteIconColor => ${color("$tokenGroup.with-icon.selected.icon.color")};
|
||||
|
||||
@override
|
||||
BorderSide? get side => !isSelected
|
||||
? isEnabled
|
||||
? ${border('$tokenGroup$variant.unselected.outline')}
|
||||
: ${border('$tokenGroup$variant.disabled.unselected.outline')}
|
||||
: null;
|
||||
|
||||
@override
|
||||
IconThemeData? get iconTheme => IconThemeData(
|
||||
color: isEnabled
|
||||
? ${color("$tokenGroup.with-icon.icon.color")}
|
||||
: ${color("$tokenGroup.with-icon.disabled.icon.color")},
|
||||
size: ${tokens["$tokenGroup.with-icon.icon.size"]},
|
||||
);
|
||||
|
||||
@override
|
||||
EdgeInsetsGeometry? get padding => const EdgeInsets.all(8.0);
|
||||
|
||||
/// The chip at text scale 1 starts with 8px on each side and as text scaling
|
||||
/// gets closer to 2 the label padding is linearly interpolated from 8px to 4px.
|
||||
/// Once the widget has a text scaling of 2 or higher than the label padding
|
||||
/// remains 4px.
|
||||
@override
|
||||
EdgeInsetsGeometry? get labelPadding => EdgeInsets.lerp(
|
||||
const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
const EdgeInsets.symmetric(horizontal: 4.0),
|
||||
clampDouble(MediaQuery.of(context).textScaleFactor - 1.0, 0.0, 1.0),
|
||||
)!;
|
||||
}
|
||||
''';
|
||||
}
|
||||
79
dev/tools/gen_defaults/lib/chip_input_template.dart
Normal file
79
dev/tools/gen_defaults/lib/chip_input_template.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'template.dart';
|
||||
|
||||
class ChipInputTemplate extends TokenTemplate {
|
||||
const ChipInputTemplate(super.fileName, super.tokens);
|
||||
|
||||
static const String tokenGroup = 'md.comp.input-chip';
|
||||
static const String variant = '';
|
||||
|
||||
@override
|
||||
String generate() => '''
|
||||
// Generated version ${tokens["version"]}
|
||||
class _TokenDefaultsM3 extends ChipThemeData {
|
||||
const _TokenDefaultsM3(this.context, this.isEnabled)
|
||||
: super(
|
||||
elevation: ${elevation("$tokenGroup$variant.container")},
|
||||
shape: ${shape("$tokenGroup.container")},
|
||||
showCheckmark: true,
|
||||
);
|
||||
|
||||
final BuildContext context;
|
||||
final bool isEnabled;
|
||||
|
||||
@override
|
||||
TextStyle? get labelStyle => ${textStyle("$tokenGroup.label-text")};
|
||||
|
||||
@override
|
||||
Color? get backgroundColor => ${componentColor("$tokenGroup$variant.container")};
|
||||
|
||||
@override
|
||||
Color? get shadowColor => ${color("$tokenGroup.container.shadow-color")};
|
||||
|
||||
@override
|
||||
@override Color? get surfaceTintColor => ${color("$tokenGroup.container.surface-tint-layer.color")};
|
||||
|
||||
@override
|
||||
Color? get selectedColor => ${componentColor("$tokenGroup$variant.selected.container")};
|
||||
|
||||
@override
|
||||
Color? get checkmarkColor => ${color("$tokenGroup.with-icon.selected.icon.color")};
|
||||
|
||||
@override
|
||||
Color? get disabledColor => ${componentColor("$tokenGroup$variant.disabled.container")};
|
||||
|
||||
@override
|
||||
Color? get deleteIconColor => ${color("$tokenGroup.with-trailing-icon.selected.trailing-icon.color")};
|
||||
|
||||
@override
|
||||
BorderSide? get side => isEnabled
|
||||
? ${border('$tokenGroup$variant.unselected.outline')}
|
||||
: ${border('$tokenGroup$variant.disabled.unselected.outline')};
|
||||
|
||||
@override
|
||||
IconThemeData? get iconTheme => IconThemeData(
|
||||
color: isEnabled
|
||||
? ${color("$tokenGroup.with-leading-icon.leading-icon.color")}
|
||||
: ${color("$tokenGroup.with-leading-icon.disabled.leading-icon.color")},
|
||||
size: ${tokens["$tokenGroup.with-leading-icon.leading-icon.size"]},
|
||||
);
|
||||
|
||||
@override
|
||||
EdgeInsetsGeometry? get padding => const EdgeInsets.all(8.0);
|
||||
|
||||
/// The chip at text scale 1 starts with 8px on each side and as text scaling
|
||||
/// gets closer to 2 the label padding is linearly interpolated from 8px to 4px.
|
||||
/// Once the widget has a text scaling of 2 or higher than the label padding
|
||||
/// remains 4px.
|
||||
@override
|
||||
EdgeInsetsGeometry? get labelPadding => EdgeInsets.lerp(
|
||||
const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
const EdgeInsets.symmetric(horizontal: 4.0),
|
||||
clampDouble(MediaQuery.of(context).textScaleFactor - 1.0, 0.0, 1.0),
|
||||
)!;
|
||||
}
|
||||
''';
|
||||
}
|
||||
Reference in New Issue
Block a user