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
1 change: 1 addition & 0 deletions packages/material_ui/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ environment:

workspace:
- example
- tool/gen_defaults

dependencies:
collection: ^1.19.1
Expand Down
24 changes: 24 additions & 0 deletions packages/material_ui/tool/gen_defaults/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Token Defaults Generator

Script that generates component theme data defaults based on token data.

## Usage
Run this program from the root of the git repository:
```sh
dart packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart [-v]
```

This updates generated component theming files under
`packages/material_ui/lib/src/generated`.

## Templates

There is a template file for every component that needs defaults from the token
database. These templates are implemented as subclasses of either `M3TokenTemplate` or `M3ETokenTemplate`.

Templates need to override the `generateContents` method to provide the
generated code block as a string.

## Tokens

Tokens are stored in `data/`, and are sourced from an internal Google database.
4 changes: 4 additions & 0 deletions packages/material_ui/tool/gen_defaults/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: ../../../../analysis_options.yaml

formatter:
page_width: 100
28 changes: 28 additions & 0 deletions packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ## Usage
//
// Run from the root of flutter/packages:
//
// ```
// dart packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart [-v]
// ```

import 'package:args/args.dart';

// TODO(elliette): Import template files.
// import '../templates/x_template.dart';

Future<void> main(List<String> args) async {
// Parse arguments
final parser = ArgParser();
parser.addFlag('verbose', abbr: 'v', help: 'Enable verbose output', negatable: false);
final ArgResults argResults = parser.parse(args);
// TODO(elliette): Add token logger when verbose flag is used.
// ignore: unused_local_variable
final verbose = argResults['verbose'] as bool;
// TODO(elliette): Invoke template generators.
// const XTemplate().generateFile(verbose: verbose);
}
194 changes: 194 additions & 0 deletions packages/material_ui/tool/gen_defaults/data/app_bar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
// Copyright 2013 The Flutter Authors.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Version: 38.0.1

import 'color_role.dart';
import 'shape_struct.dart';

class TokenAppBar {
/// md.comp.app-bar.avatar.size
static const double avatarSize = 32.00;

/// md.comp.app-bar.container.elevation
static const double containerElevation = 0.00;

/// md.comp.app-bar.container.shape
static const ShapeStruct containerShape = ShapeStruct(
family: 'SHAPE_FAMILY_ROUNDED_CORNERS',
topLeft: 0.00,
topRight: 0.00,
bottomLeft: 0.00,
bottomRight: 0.00,
);

/// md.comp.app-bar.icon-button-space
static const double iconButtonSpace = 0.00;

/// md.comp.app-bar.icon.size
static const double iconSize = 24.00;

/// md.comp.app-bar.leading-space
static const double leadingSpace = 4.00;

/// md.comp.app-bar.on-scroll.container.elevation
static const double onScrollContainerElevation = 3.00;

/// md.comp.app-bar.search.leading-space
static const double searchLeadingSpace = 8.00;

/// md.comp.app-bar.search.trailing-space
static const double searchTrailingSpace = 8.00;

/// md.comp.app-bar.trailing-space
static const double trailingSpace = 4.00;
}

class TokenAppBarDark {
/// md.comp.app-bar.container.color
static const TokenColorRole containerColor = TokenColorRole.surface;

/// md.comp.app-bar.on-scroll.container.color
static const TokenColorRole onScrollContainerColor =
TokenColorRole.surfaceContainer;

/// md.comp.app-bar.search.container.color
static const TokenColorRole searchContainerColor =
TokenColorRole.surfaceContainer;

/// md.comp.app-bar.search.on-scroll.container.color
static const TokenColorRole searchOnScrollContainerColor =
TokenColorRole.surfaceContainerHighest;
}

class TokenAppBarDarkDefault {
/// md.comp.app-bar.leading-icon.color
static const TokenColorRole leadingIconColor = TokenColorRole.onSurface;

/// md.comp.app-bar.search.label.color
static const TokenColorRole searchLabelColor =
TokenColorRole.onSurfaceVariant;

/// md.comp.app-bar.subtitle.color
static const TokenColorRole subtitleColor = TokenColorRole.onSurfaceVariant;

/// md.comp.app-bar.title.color
static const TokenColorRole titleColor = TokenColorRole.onSurface;

/// md.comp.app-bar.trailing-icon.color
static const TokenColorRole trailingIconColor =
TokenColorRole.onSurfaceVariant;
}

class TokenAppBarDarkHighContrast {
/// md.comp.app-bar.leading-icon.color
static const TokenColorRole leadingIconColor = TokenColorRole.onSurface;

/// md.comp.app-bar.search.label.color
static const TokenColorRole searchLabelColor =
TokenColorRole.onSurfaceVariant;

/// md.comp.app-bar.subtitle.color
static const TokenColorRole subtitleColor = TokenColorRole.onSurfaceVariant;

/// md.comp.app-bar.title.color
static const TokenColorRole titleColor = TokenColorRole.onSurface;

/// md.comp.app-bar.trailing-icon.color
static const TokenColorRole trailingIconColor =
TokenColorRole.onSurfaceVariant;
}

class TokenAppBarDarkMediumContrast {
/// md.comp.app-bar.leading-icon.color
static const TokenColorRole leadingIconColor = TokenColorRole.onSurface;

/// md.comp.app-bar.search.label.color
static const TokenColorRole searchLabelColor =
TokenColorRole.onSurfaceVariant;

/// md.comp.app-bar.subtitle.color
static const TokenColorRole subtitleColor = TokenColorRole.onSurfaceVariant;

/// md.comp.app-bar.title.color
static const TokenColorRole titleColor = TokenColorRole.onSurface;

/// md.comp.app-bar.trailing-icon.color
static const TokenColorRole trailingIconColor =
TokenColorRole.onSurfaceVariant;
}

class TokenAppBarLight {
/// md.comp.app-bar.container.color
static const TokenColorRole containerColor = TokenColorRole.surface;

/// md.comp.app-bar.on-scroll.container.color
static const TokenColorRole onScrollContainerColor =
TokenColorRole.surfaceContainer;

/// md.comp.app-bar.search.container.color
static const TokenColorRole searchContainerColor =
TokenColorRole.surfaceContainer;

/// md.comp.app-bar.search.on-scroll.container.color
static const TokenColorRole searchOnScrollContainerColor =
TokenColorRole.surfaceContainerHighest;
}

class TokenAppBarLightDefault {
/// md.comp.app-bar.leading-icon.color
static const TokenColorRole leadingIconColor = TokenColorRole.onSurface;

/// md.comp.app-bar.search.label.color
static const TokenColorRole searchLabelColor =
TokenColorRole.onSurfaceVariant;

/// md.comp.app-bar.subtitle.color
static const TokenColorRole subtitleColor = TokenColorRole.onSurfaceVariant;

/// md.comp.app-bar.title.color
static const TokenColorRole titleColor = TokenColorRole.onSurface;

/// md.comp.app-bar.trailing-icon.color
static const TokenColorRole trailingIconColor =
TokenColorRole.onSurfaceVariant;
}

class TokenAppBarLightHighContrast {
/// md.comp.app-bar.leading-icon.color
static const TokenColorRole leadingIconColor = TokenColorRole.onSurface;

/// md.comp.app-bar.search.label.color
static const TokenColorRole searchLabelColor =
TokenColorRole.onSurfaceVariant;

/// md.comp.app-bar.subtitle.color
static const TokenColorRole subtitleColor = TokenColorRole.onSurfaceVariant;

/// md.comp.app-bar.title.color
static const TokenColorRole titleColor = TokenColorRole.onSurface;

/// md.comp.app-bar.trailing-icon.color
static const TokenColorRole trailingIconColor =
TokenColorRole.onSurfaceVariant;
}

class TokenAppBarLightMediumContrast {
/// md.comp.app-bar.leading-icon.color
static const TokenColorRole leadingIconColor = TokenColorRole.onSurface;

/// md.comp.app-bar.search.label.color
static const TokenColorRole searchLabelColor =
TokenColorRole.onSurfaceVariant;

/// md.comp.app-bar.subtitle.color
static const TokenColorRole subtitleColor = TokenColorRole.onSurfaceVariant;

/// md.comp.app-bar.title.color
static const TokenColorRole titleColor = TokenColorRole.onSurface;

/// md.comp.app-bar.trailing-icon.color
static const TokenColorRole trailingIconColor =
TokenColorRole.onSurfaceVariant;
}
16 changes: 16 additions & 0 deletions packages/material_ui/tool/gen_defaults/data/app_bar_large.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2013 The Flutter Authors.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Version: 38.0.1

import 'typescale.dart';
import 'typescale_struct.dart';

class TokenAppBarLarge {
/// md.comp.app-bar.large.container.height
static const double containerHeight = 152.00;

/// md.comp.app-bar.large.title.font
static const TypescaleStruct titleFont = TokenTypescale.headlineMedium;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2013 The Flutter Authors.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Version: 38.0.1

import 'typescale.dart';
import 'typescale_struct.dart';

class TokenAppBarLargeFlexible {
/// md.comp.app-bar.large-flexible.container.height
static const double containerHeight = 120.00;

/// md.comp.app-bar.large-flexible.subtitle.font
static const TypescaleStruct subtitleFont = TokenTypescale.titleMedium;

/// md.comp.app-bar.large-flexible.title.font
static const TypescaleStruct titleFont = TokenTypescale.displaySmall;

/// md.comp.app-bar.large-flexible.with-subtitle.container.height
static const double withSubtitleContainerHeight = 152.00;
}
16 changes: 16 additions & 0 deletions packages/material_ui/tool/gen_defaults/data/app_bar_medium.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2013 The Flutter Authors.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Version: 38.0.1

import 'typescale.dart';
import 'typescale_struct.dart';

class TokenAppBarMedium {
/// md.comp.app-bar.medium.container.height
static const double containerHeight = 112.00;

/// md.comp.app-bar.medium.title.font
static const TypescaleStruct titleFont = TokenTypescale.headlineSmall;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2013 The Flutter Authors.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Version: 38.0.1

import 'typescale.dart';
import 'typescale_struct.dart';

class TokenAppBarMediumFlexible {
/// md.comp.app-bar.medium-flexible.container.height
static const double containerHeight = 112.00;

/// md.comp.app-bar.medium-flexible.subtitle.font
static const TypescaleStruct subtitleFont = TokenTypescale.labelLarge;

/// md.comp.app-bar.medium-flexible.title.font
static const TypescaleStruct titleFont = TokenTypescale.headlineMedium;

/// md.comp.app-bar.medium-flexible.with-subtitle.container.height
static const double withSubtitleContainerHeight = 136.00;
}
35 changes: 35 additions & 0 deletions packages/material_ui/tool/gen_defaults/data/app_bar_small.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2013 The Flutter Authors.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Version: 38.0.1

import 'shape_struct.dart';
import 'typescale.dart';
import 'typescale_struct.dart';

class TokenAppBarSmall {
/// md.comp.app-bar.small.container.height
static const double containerHeight = 64.00;

/// md.comp.app-bar.small.search.container.height
static const double searchContainerHeight = 56.00;

/// md.comp.app-bar.small.search.container.shape
static const ShapeStruct searchContainerShape = ShapeStruct(
family: 'SHAPE_FAMILY_CIRCULAR',
topLeft: 0.00,
topRight: 0.00,
bottomLeft: 0.00,
bottomRight: 0.00,
);

/// md.comp.app-bar.small.search.label-text.font
static const TypescaleStruct searchLabelTextFont = TokenTypescale.bodyLarge;

/// md.comp.app-bar.small.subtitle.font
static const TypescaleStruct subtitleFont = TokenTypescale.labelMedium;

/// md.comp.app-bar.small.title.font
static const TypescaleStruct titleFont = TokenTypescale.titleLarge;
}
Loading