在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):leifoolsen/mdl-ext开源软件地址(OpenSource Url):https://github.com/leifoolsen/mdl-ext开源编程语言(OpenSource Language):HTML 39.3%开源软件介绍(OpenSource Introduction):mdl-extMaterial Design Lite Ext (MDLEXT). Components built with the Google Material Design Lite framework. MDLEXT provides the following components.
Live demoA Live demo of MDLEXT is available here
IntroductionThe MDLEXT component library is built with responsiveness in mind. The pre built CSS provided in the lib directory therefore comes
in two versions; one based on media queries and one based on element queries, using eq.js.
If you build the CSS from SASS, just import the correct sass file, Responsive breakpointsA common metod in responsive design is to use media queries to apply styles based on device
characteristics. The problem with media queries is that they relates to the viewport - so every time you
write a media query for Media queries are a hackSome developers claim that media queries are a hack, and I totally agree! Imagine a design with a sidebar and a content area. In a responsive, fluent design both the sidebar and the content has "unknown" widths. Trying to add e.g. a responsive grid into the content area which relies on media queries, where you have no knowledge of how much space your content occupies, is in my opinion almost an impossible task. Element queries to the rescueAn element query is similar to a media query in that, if a condition is met, some CSS will be applied.
Element query conditions (such as Some of the polyfrills available are: These are all good libraries, and they serve the purpose. After some evaluation I decided to go for eq.js. It is a small library with support for width based breakpoints. It works without requiring a server to run (no Ajax stuff). It does not break the existing CSS standard. I can use SASS for styling, and it works well in a Webpack workflow. InstallIf you haven't done so already, install Material Design Lite. $ npm install --save material-design-lite Install mdl-ext $ npm install --save mdl-ext Install eq.js if you choose to use the element query CSS/SASS version. $ npm install --save eq.js Getting startedUse it in your (static) page<!DOCTYPE html>
<html>
<head>
<title>Material Design Lite Extensions</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&lang=en">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="node_modules/material-design-lite/material.css" />
<link rel="stylesheet" href="node_modules/mdl-ext/lib/mdl-ext.min.css" />
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer">
<main class="mdl-layout__content">
</main>
</div>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
<script type="text/javascript" src="node_modules/material-design-lite/material.min.js" charset="utf-8"></script>
<script type="text/javascript" src="node_modules/mdl-ext/lib/mdl-ext.min.js" charset="utf-8"></script>
</body>
</html>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script> Use it with element queries in your (static) page<!DOCTYPE html>
<html>
<head>
<title>Material Design Lite Extensions</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&lang=en">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="node_modules/material-design-lite/material.css" />
<link rel="stylesheet" href="node_modules/mdl-ext/lib/mdl-ext-eqjs.min.css" />
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer">
<main class="mdl-layout__content">
</main>
</div>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
<script type="text/javascript" src="node_modules/material-design-lite/material.min.js" charset="utf-8"></script>
<script type="text/javascript" src="node_modules/mdl-ext/lib/mdl-ext.min.js" charset="utf-8"></script>
<script type="text/javascript" src="node_modules/eq.js/dist/eq.min.js" charset="utf-8"></script>
</body>
</html>
Use it in your (webpack) buildImport SASS files into your main SCSS file, e.g. @charset "UTF-8";
// 1. Configuration and helpers
// MDL image path
$image_path: '~material-design-lite/src/images';
// 2. Vendors
// Import MDL
@import '~material-design-icons/iconfont/material-icons.css';
@import '~roboto-fontface/css/roboto-fontface.css';
@import '~material-design-lite/src/material-design-lite';
// Import MDLEXT
@import '~mdl-ext/src/mdl-ext';
// ... or import mdl-ext-eqjs
//@import '~mdl-ext/src/mdl-ext-eqjs';
// 3. Your stuff
@import 'stylesheets/variables';
@import 'stylesheets/app/whatever'; Import material-design-lite, mdl-ext and styles.scss into your main JavaScript file, e.g. import 'material-design-lite/material';
import 'mdl-ext';
import './styles.scss'; If you choose to use element queries, import import eqjs from 'eq.js';
window.eqjs = eqjs; // Put in global scope - for use with script in page Use of specific components in your (webpack) buildIt is possible to use a selection of the provided MDLEXT components. Just import the specific MDLEXT SASS module and the corresponding ES2015 JavaScript component. The following example demonstrates a setup that uses only two of the MDLEXT components; menu-button and selectfield. Import SASS files into your main SCSS file, e.g. @charset "UTF-8";
// 1. Configuration and helpers
// MDL image path
$image_path: '~material-design-lite/src/images';
// Material Design Lite
@import '~material-design-lite/src/variables';
@import '~material-design-lite/src/mixins';
// mdl-ext
@import '~mdl-ext/src/variables';
@import '~mdl-ext/src/mixins';
@import '~mdl-ext/src/functions';
// 2. Vendors
// Import MDL
@import '~material-design-icons/iconfont/material-icons';
@import '~roboto-fontface/css/roboto/sass/roboto-fontface-light';
@import '~material-design-lite/src/material-design-lite';
// Import required MDLEXT SASS modules
@import '~mdl-ext/src/aria-expanded-toggle/aria-expanded-toggle';
@import '~mdl-ext/src/menu-button/menu-button';
@import '~mdl-ext/src/selectfield/selectfield';
// 3. Your stuff
@import 'stylesheets/variables';
@import 'stylesheets/app/whatever'; Import material-design-lite, mdl-ext components and styles.scss into your main JavaScript file, e.g. import 'material-design-lite/material';
// Import MDLEXT components from the es folder
import 'mdl-ext/es/menu-button/menu-button';
import 'mdl-ext/es/selectfield/selectfield';
import './styles.scss'; You can find a webpack project with this setup in the example-webpack folder. Clone this repo, cd
into the
ComponentsAccordionA WAI-ARIA friendly accordion component with vertcial or horizontal layout. Bordered fieldsThe Material Design Lite Ext (MDLEXT) bordered fields component demonstrates how you can create your own theme of MDL text fields. CarouselA responsive image carousel. Collapsible - Collapse All the ThingsCollapsed Expanded Accessible collapsible content regions. Color themesThe color-themes component demonstrates how you can create your own themes of material design colors. The formatfield component formats an input field using language sensitive number formatting. GridA responsive grid based on element queries in favour of media queries. LightboardA lightboard is a translucent surface illuminated from behind, used for situations where a shape laid upon the surface needs to be seen with high contrast. In the "old days" of photography photograpers used a lightboard to get a quick view of, sorting and organizing their slides. LightboxA lightbox displays an image filling the screen, and dimming out the rest of the web page.
It acts as a modal dialog using the Menu ButtonA menu button is a button that opens a menu. It has roles, attributes and behaviour as outlined in WAI-ARIA Authoring Practices, 2.20 Menu Button. SelectfieldThe Material Design Lite Ext (MDLEXT) select field component is an enhanced version
of the standard [HTML Sticky HeaderA sticky header makes site navigation easily accessible anywhere on the page and saves content space at the same. The header should auto-hide, i.e. hiding the header automatically when a user starts scrolling down the page and bringing the header back when a user might need it: they reach the bottom of the page or start scrolling up. Notes
Using Material Design Lite in a Single Page Application (SPA)If you use Material Design Lite in a dynamic page, e.g. a single page application, you must call
The following code snippet demonstrates how to properly clean up MDL components before removing them from DOM. // Call 'componentHandler.downgradeElements' to clean up
const content = document.querySelector('#content');
const components = content.querySelectorAll('.is-upgraded');
componentHandler.downgradeElements([...components]);
// Remove elements from DOM.
// See: http://jsperf.com/empty-an-element/16
const removeChildElements = (element, forceReflow = true) => {
while (element.lastChild) {
element.removeChild(element.lastChild);
}
if(forceReflow) {
// See: http://jsperf.com/force-reflow
const d = element.style.display;
element.style.display = 'none';
element.style.display = d;
}
}
removeChildElements(content); Licence© Leif Olsen, 2016. Licensed under an Apache-2 license. This software is built with the Google Material Design Lite framework, which is licenced under an Apache-2 licence. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论