项目作者: arabsight

项目描述 :
Material Design Lite plugin for Aurelia.
高级语言: JavaScript
项目地址: git://github.com/arabsight/aurelia-mdl-plugin.git
创建时间: 2016-06-19T21:33:49Z
项目社区:https://github.com/arabsight/aurelia-mdl-plugin

开源协议:MIT License

下载


Material Design Lite plugin for Aurelia. CLI DEMO

NPM

Usage

With jspm:

  1. jspm install material-design-lite
  2. jspm install aurelia-mdl-plugin
  • Register the plugin:
  1. import 'material-design-lite/material';
  2. export function configure(aurelia) {
  3. ...
  4. aurelia.use.plugin('aurelia-mdl-plugin');
  5. ...
  6. }
  • Load mdl CSS:
  1. <template>
  2. <require from="material-design-lite/material.css"></require>
  3. ...
  4. <!-- give it a try -->
  5. <button
  6. class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect"
  7. >
  8. Button
  9. </button>
  10. </template>

With Aurelia CLI:

  • Install:
  1. npm i material-design-lite aurelia-mdl-plugin
  • Configure aurelia.json:

add mdl & plugin to one of your bundle’s dependencies.

  1. ({
  2. "name": "material-design-lite",
  3. "path": "../node_modules/material-design-lite/dist",
  4. "main": "material",
  5. "resources": ["material.css"]
  6. },
  7. {
  8. "name": "aurelia-mdl-plugin",
  9. "path": "../node_modules/aurelia-mdl-plugin/dist/amd",
  10. "main": "index"
  11. })
  • Register the plugin:
  1. import 'material-design-lite';
  2. export function configure(aurelia) {
  3. ...
  4. aurelia.use.plugin('aurelia-mdl-plugin');
  5. ...
  6. }
  • require css file the same way.
  • if you want to use another color theme:

change the resources key:

  1. "resources": [
  2. "material.deep_orange-blue.min.css"
  3. ]

import the css:

  1. <require
  2. from="material-design-lite/material.deep_orange-blue.min.css"
  3. ></require>

Configure the plugin

  • manual upgrade:

the plugin looks for specific mdl components and adds a custom attribute for each one automatically.
If for some reason you don’t want to auto upgrade you can change that when registering the plugin:

  1. aurelia.use.plugin("aurelia-mdl-plugin", (m) => m.autoUpgrade(false));

this way you need to add ‘mdl-target’ custom attribute manually to every component that needs upgrading.

  • upgrading other components:

if you want to upgrade other components like custom mdl components you can register them like this:

  1. aurelia.use.plugin("aurelia-mdl-plugin", (m) =>
  2. m.addClasses("mdl-custom-one", "two")
  3. );
  • example: using mdl-selectfield with aurelia cli:

aurelia.json:

  1. ({
  2. "name": "material-design-lite",
  3. "path": "../node_modules/material-design-lite/dist",
  4. "main": "material",
  5. "resources": ["material.css"]
  6. },
  7. {
  8. "name": "mdl-selectfield",
  9. "path": "../node_modules/mdl-selectfield/dist",
  10. "main": "mdl-selectfield",
  11. "resources": ["mdl-selectfield.css"]
  12. },
  13. {
  14. "name": "aurelia-mdl-plugin",
  15. "path": "../node_modules/aurelia-mdl-plugin/dist/amd",
  16. "main": "index"
  17. })

config:

  1. import 'material-design-lite';
  2. import 'mdl-selectfield';
  3. export function configure(aurelia) {
  4. ...
  5. aurelia.use.
  6. plugin('aurelia-mdl-plugin', mdl => {
  7. mdl.addClasses('mdl-js-selectfield');
  8. });
  9. ...
  10. }

require css in html:

  1. <require from="material-design-lite/material.css"></require>
  2. <require from="mdl-selectfield/mdl-selectfield.css"></require>
  3. <div class="mdl-selectfield mdl-js-selectfield">
  4. <select id="gender" class="mdl-selectfield__select">
  5. <option value=""></option>
  6. <option value="option1">option 1</option>
  7. <option value="option2">option 2</option>
  8. </select>
  9. <label class="mdl-selectfield__label" for="gender">User gender</label>
  10. <span class="mdl-selectfield__error">Select a value</span>
  11. </div>