-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[material_ui] Migrate M3 ActionChip template to use new gen_defaults
#12219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
elliette
wants to merge
6
commits into
flutter:m3e_migration
Choose a base branch
from
elliette:action-chip-migration
base: m3e_migration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
41fc2a2
Move action_chip_template
elliette 5c868e1
Move action_chip_defaults_m3.g.dart
elliette e664fd2
Finish migration
elliette 1316713
Delete unused fields
elliette 8e1924b
Use part file
elliette 130a623
Add test case
elliette File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,27 +2,29 @@ | |||||
| // Use of this source code is governed by a BSD-style license that can be | ||||||
| // found in the LICENSE file. | ||||||
|
|
||||||
| import '../data/assist_chip.dart'; | ||||||
| import 'template.dart'; | ||||||
|
|
||||||
| class ActionChipTemplate extends TokenTemplate { | ||||||
| const ActionChipTemplate( | ||||||
| super.blockName, | ||||||
| super.fileName, | ||||||
| super.tokens, { | ||||||
| super.colorSchemePrefix = '_colors.', | ||||||
| super.textThemePrefix = '_textTheme.', | ||||||
| class ActionChipTemplateM3 extends TokenTemplateM3 { | ||||||
| const ActionChipTemplateM3({ | ||||||
| this.colorSchemePrefix = '_colors', | ||||||
| }); | ||||||
|
|
||||||
| static const String tokenGroup = 'md.comp.assist-chip'; | ||||||
| static const String flatVariant = '.flat'; | ||||||
| static const String elevatedVariant = '.elevated'; | ||||||
| final String colorSchemePrefix; | ||||||
|
|
||||||
| @override | ||||||
| String generate() => ''' | ||||||
| class _${blockName}DefaultsM3 extends ChipThemeData { | ||||||
| _${blockName}DefaultsM3(this.context, this.isEnabled, this._chipVariant) | ||||||
| String get name => 'Action Chip'; | ||||||
|
|
||||||
| @override | ||||||
| String get parentFilePath => 'action_chip.dart'; | ||||||
|
|
||||||
| @override | ||||||
| String generateContents(String className) => | ||||||
| ''' | ||||||
| class $className extends ChipThemeData { | ||||||
| $className(this.context, this.isEnabled, this._chipVariant) | ||||||
| : super( | ||||||
| shape: ${shape("$tokenGroup.container")}, | ||||||
| shape: ${shape(TokenAssistChip.containerShape)}, | ||||||
| showCheckmark: true, | ||||||
| ); | ||||||
|
|
||||||
|
|
@@ -34,39 +36,39 @@ class _${blockName}DefaultsM3 extends ChipThemeData { | |||||
|
|
||||||
| @override | ||||||
| double? get elevation => _chipVariant == _ChipVariant.flat | ||||||
| ? ${elevation("$tokenGroup$flatVariant.container")} | ||||||
| : isEnabled ? ${elevation("$tokenGroup$elevatedVariant.container")} : ${elevation("$tokenGroup$elevatedVariant.disabled.container")}; | ||||||
| ? ${TokenAssistChip.flatContainerElevation} | ||||||
| : isEnabled ? ${TokenAssistChip.elevatedContainerElevation} : ${TokenAssistChip.elevatedDisabledContainerElevation}; | ||||||
|
|
||||||
| @override | ||||||
| double? get pressElevation => ${elevation("$tokenGroup$elevatedVariant.pressed.container")}; | ||||||
| double? get pressElevation => ${TokenAssistChip.elevatedPressedContainerElevation}; | ||||||
|
|
||||||
| @override | ||||||
| TextStyle? get labelStyle => ${textStyle("$tokenGroup.label-text")}?.copyWith( | ||||||
| TextStyle? get labelStyle => _textTheme.labelLarge?.copyWith( | ||||||
| color: isEnabled | ||||||
| ? ${color("$tokenGroup.label-text.color")} | ||||||
| : ${color("$tokenGroup.disabled.label-text.color")}, | ||||||
| ? ${color(TokenAssistChip.labelTextColor, colorSchemePrefix)} | ||||||
| : ${color(TokenAssistChip.disabledLabelTextColor, colorSchemePrefix)}, | ||||||
| ); | ||||||
|
|
||||||
| @override | ||||||
| WidgetStateProperty<Color?>? get color => | ||||||
| WidgetStateProperty.resolveWith((Set<WidgetState> states) { | ||||||
| if (states.contains(WidgetState.disabled)) { | ||||||
| return _chipVariant == _ChipVariant.flat | ||||||
| ? ${componentColor("$tokenGroup$flatVariant.disabled.container")} | ||||||
| : ${componentColor("$tokenGroup$elevatedVariant.disabled.container")}; | ||||||
| ? null | ||||||
| : ${colorWithOpacity(TokenAssistChip.elevatedDisabledContainerColor, TokenAssistChip.elevatedDisabledContainerOpacity, colorSchemePrefix)}; | ||||||
| } | ||||||
| return _chipVariant == _ChipVariant.flat | ||||||
| ? ${componentColor("$tokenGroup$flatVariant.container")} | ||||||
| : ${componentColor("$tokenGroup$elevatedVariant.container")}; | ||||||
| ? null | ||||||
| : ${color(TokenAssistChip.elevatedContainerColor, colorSchemePrefix)}; | ||||||
| }); | ||||||
|
|
||||||
| @override | ||||||
| Color? get shadowColor => _chipVariant == _ChipVariant.flat | ||||||
| ? ${colorOrTransparent("$tokenGroup$flatVariant.container.shadow-color")} | ||||||
| : ${colorOrTransparent("$tokenGroup$elevatedVariant.container.shadow-color")}; | ||||||
| ? Colors.transparent | ||||||
| : ${color(TokenAssistChip.elevatedContainerShadowColor, colorSchemePrefix)}; | ||||||
|
|
||||||
| @override | ||||||
| Color? get surfaceTintColor => ${colorOrTransparent("$tokenGroup.container.surface-tint-layer.color")}; | ||||||
| Color? get surfaceTintColor => Colors.transparent; | ||||||
|
|
||||||
| @override | ||||||
| Color? get checkmarkColor => null; | ||||||
|
|
@@ -77,16 +79,16 @@ class _${blockName}DefaultsM3 extends ChipThemeData { | |||||
| @override | ||||||
| BorderSide? get side => _chipVariant == _ChipVariant.flat | ||||||
| ? isEnabled | ||||||
| ? ${border('$tokenGroup$flatVariant.outline')} | ||||||
| : ${border('$tokenGroup$flatVariant.disabled.outline')} | ||||||
| ? ${border(color(TokenAssistChip.flatOutlineColor, colorSchemePrefix), width: TokenAssistChip.flatOutlineWidth)} | ||||||
| : ${border(colorWithOpacity(TokenAssistChip.flatDisabledOutlineColor, TokenAssistChip.flatDisabledOutlineOpacity, colorSchemePrefix))} | ||||||
| : const BorderSide(color: Colors.transparent); | ||||||
|
|
||||||
| @override | ||||||
| IconThemeData? get iconTheme => IconThemeData( | ||||||
| color: isEnabled | ||||||
| ? ${color("$tokenGroup.with-icon.icon.color")} | ||||||
| : ${color("$tokenGroup.with-icon.disabled.icon.color")}, | ||||||
| size: ${getToken("$tokenGroup.with-icon.icon.size")}, | ||||||
| ? ${color(TokenAssistChip.withIconIconColor, colorSchemePrefix)} | ||||||
| : ${color(TokenAssistChip.withIconDisabledIconColor, colorSchemePrefix)}, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The disabled icon color is missing its opacity. According to the token data in
Suggested change
|
||||||
| size: ${TokenAssistChip.withIconIconSize}, | ||||||
| ); | ||||||
|
|
||||||
| @override | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The disabled label color is missing its opacity. According to the token data in
assist_chip.dart,disabledLabelTextOpacityshould be applied to the color for the disabled state.