mdc_web 0.4.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 75

mdc_web

Dart wrapper for the material-components-web javascript library.

Usage

In your index.html, include the script just before the main.dart.js script.

<!--
  This exposes the `mdc` global variable required by this package.
  For debugging purposes you can replace the ".min.js" extension with ".js".
-->
<script defer src="packages/mdc_web/material-components-web.min.js"></script>
<script defer src="main.dart.js"></script>

Now in your dart application you can use all of the MDC* classes as described by the Material Design Web component reference.

Documentation

Each class and notable members are documented. Class documentation includes links to corresponding (if available):

Limitations

Only the components themselves were mirrored. Their foundation and adapter classes are currently beyond the scope of this package as they are for deep customization within other web frameworks. However, the base MDCFoundation and MDCComponent classes are included. This limitation should not affect most implementations, but if it does affect you, please let me know.

[0.4.0] - November 4, 2018

  • Improve exposed APIs on the base MDCComponent.

[0.3.2] - November 4, 2018

  • Expose underlying JavaScript class through js getter.
  • Clean up and organize code.

[0.3.1] - October 26, 2018

  • Fix function signatures
  • Upgrade to material-components-web 0.40.1

[0.3.0] - October 11, 2018

  • Revert to MDC* class names (no need to import as 'mdc').
  • Wrap all component classes. The basic form of the API is hopefully settled.

[0.2.0] - October 11, 2018

  • Shorten class names and recommend import as mdc.
  • Add helper classes to organize helper functions and event names.
  • Improve documentation.

[0.1.1] - October 10, 2018

  • Fix improper use of @JS

[0.1.0+1] - October 7, 2018

  • Add content to the example.
  • Run dartfmt.

[0.1.0] - October 7, 2018

  • First release. Mirrors material-components-web v0.40.0.

example/example.dart

// See the full example at https://github.com/jifalops/mdc_web/tree/master/example/simple.

/// ./simple/web/main.dart
import 'dart:html';
import 'package:mdc_web/mdc_web.dart';

void main() {
  /// Automatically creates MDC-Web components from html elements that have a
  /// `data-mdc-auto-init="<class>"` attribute.
  autoInit();

  /// Programmatically add a ripple to all elements with a class that includes
  /// "mdc-button".
  querySelectorAll('.mdc-button').forEach(MDCRipple.attachTo);
}

/// ./simple/web/index.html
const indexHtml = '''
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="scaffolded-by" content="https://github.com/google/stagehand">
  <title>mdc_web Example</title>
  <link rel="stylesheet" href="styles.css">
  <link rel="icon" href="favicon.ico">
  <!--
    This exposes the `mdc` global variable required by this package.
    For debugging purposes you can replace the ".min.js" extension with ".js".
  -->
  <script defer src="packages/mdc_web/material-components-web.min.js"></script>
  <script defer src="main.dart.js"></script>
</head>

<body>
  <h2>mdc_web Example</h2>

  <button class="mdc-button mdc-button--raised" data-mdc-auto-init="MDCRipple">Auto Init!</button>
  <button class="mdc-button primary">Primary Button</button>
  <button class="mdc-button secondary">Secondary Button</button>
  <button class="mdc-button tertiary mdc-button--outlined mdc-button--dense">Tertiary Button</button>

  <button class="mdc-icon-button" aria-label="Add to favorites" aria-pressed="false" data-mdc-auto-init="MDCIconButtonToggle">
    <i class="material-icons mdc-icon-button__icon mdc-icon-button__icon--on">favorite</i>
    <i class="material-icons mdc-icon-button__icon">favorite_border</i>
  </button>
</body>

</html>
''';

/// ./simple/web/styles.scss
const stylesScss = r'''
@import url(https://fonts.googleapis.com/css?family=Roboto);
@import url(https://fonts.googleapis.com/css?family=Material+Icons);

$mdc-theme-primary: #fcb8ab;
$mdc-theme-secondary: rgb(66, 189, 189);
$mdc-theme-on-primary: #442b2d;
$mdc-theme-on-secondary: #212121;

@import "material-components-web/material-components-web";

.mdc-button.primary {
  @include mdc-elevation(2.0);
  @include mdc-button-container-fill-color(secondary);
  @include mdc-button-ink-color(on-secondary);
  @include mdc-states;
  // Add ripple via scss mixins.
  // @include mdc-ripple-surface;
  // @include mdc-ripple-radius-bounded;
  // @include mdc-states-base-color(black);
  // @include mdc-states-hover-opacity(.1);
  // @include mdc-states-focus-opacity(.3);
  // @include mdc-states-press-opacity(.4);

}
.mdc-button.secondary {
  @include mdc-button-container-fill-color(primary);
  @include mdc-button-ink-color(on-primary);
  @include mdc-states;
}
.mdc-button.tertiary {
  @include mdc-button-outline-color(gray);
  @include mdc-button-ink-color(black);
  @include mdc-states;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: 'Roboto', sans-serif;
  font-size: 16px;
}
''';

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  mdc_web: ^0.4.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:mdc_web/mdc_web.dart';
  
Version Uploaded Documentation Archive
0.4.0 Nov 4, 2018 Go to the documentation of mdc_web 0.4.0 Download mdc_web 0.4.0 archive
0.3.2 Nov 4, 2018 Go to the documentation of mdc_web 0.3.2 Download mdc_web 0.3.2 archive
0.3.1+1 Oct 26, 2018 Go to the documentation of mdc_web 0.3.1+1 Download mdc_web 0.3.1+1 archive
0.3.1 Oct 26, 2018 Go to the documentation of mdc_web 0.3.1 Download mdc_web 0.3.1 archive
0.3.0 Oct 12, 2018 Go to the documentation of mdc_web 0.3.0 Download mdc_web 0.3.0 archive
0.2.0 Oct 11, 2018 Go to the documentation of mdc_web 0.2.0 Download mdc_web 0.2.0 archive
0.1.1 Oct 10, 2018 Go to the documentation of mdc_web 0.1.1 Download mdc_web 0.1.1 archive
0.1.0+1 Oct 8, 2018 Go to the documentation of mdc_web 0.1.0+1 Download mdc_web 0.1.0+1 archive
0.1.0 Oct 7, 2018 Go to the documentation of mdc_web 0.1.0 Download mdc_web 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
50
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
75
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: web

Primary library: package:mdc_web/mdc_web.dart with components: html, js.

Health suggestions

Fix lib/src/mdc_web/selection_control.dart. (-0.50 points)

Analysis of lib/src/mdc_web/selection_control.dart reported 1 hint:

line 4 col 8: Unused import: 'dart:html'.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
js ^0.6.0 0.6.1+1
meta ^1.0.0 1.1.6
Dev dependencies
test ^1.0.0