项目作者: psirenny

项目描述 :
Material Design in JS
高级语言: JavaScript
项目地址: git://github.com/psirenny/md-in-js.git
创建时间: 2017-07-10T14:58:16Z
项目社区:https://github.com/psirenny/md-in-js

开源协议:

下载


md-in-js

Material Design constants (animation curves & durations, breakpoints, colors, shadows, etc…) all defined in JS.

CircleCI
codecov
Greenkeeper badge

What is it?

md-in-js is an assortment of js constants and values used in material design. It’s not a framework or a replacement for material components, material design lite, material-ui, et al.

Why?

The frameworks listed above are opionated. They mostly use sass but they ALL declare their constants in css. You won’t be able to access any of their values in your js components, your js animations, or in your css written in js (Styled Components, JSS, etc.)

The frameworks also try to simplify a broad and detailed specification. As a result, they end up omitting various parts of the spec. Good luck trying to use the dense and tall typographical styles outlined in the docs.

Moreover, md-in-js incorporates the Android Wearable specification which, you’d be hard pressed to find in any of the other frameworks.

Examples

css in js:

/css/typography.css.js

  1. import {
  2. colorBlackHsl,
  3. colorLightBlue500Hsl,
  4. colorWhiteHsl,
  5. fontFileRoboto400NormalLatin,
  6. fontUnicodeRangeLatin,
  7. typographyOpacityBody1Dark,
  8. typographyOpacityBody1Light,
  9. typographyLeadingEnLikeBody1Dark,
  10. typographyLeadingEnLikeBody1Light,
  11. typographySizeEnLikeBody1Desktop,
  12. typographySizeEnLikeBody1Device,
  13. } from 'md-in-js';
  14. export default {
  15. '@font-face': [{
  16. 'font-family': 'Roboto',
  17. 'src': `local('Roboto'), url(fontFileRoboto400NormalLatin)`,
  18. 'unicode-range': fontUnicodeRangeLatin,
  19. }],
  20. '.en': {
  21. 'font-family': 'Roboto',
  22. },
  23. '.en .text': {
  24. 'line-height': typographyLeadingEnLikeBody1,
  25. },
  26. '.en.desktop .text': {
  27. 'font-size': typographySizeEnLikeBody1Desktop,
  28. },
  29. '.en.mobile .text': {
  30. 'font-size': typographySizeEnLikeBody1Device,
  31. },
  32. '.dark .text': {
  33. 'color': `hsl(${colorWhiteHsl})`,
  34. 'opacity': typographyOpacityBody1Dark,
  35. },
  36. '.light .text': {
  37. 'color': `hsl(${colorBlackHsl})`,
  38. 'opacity': typographyOpacityBody1Light,
  39. },
  40. '.link': {
  41. 'color': `hsl(${colorLightBlue500Hsl})`,
  42. },
  43. };

React:

/components/TimeRangeEn.jsx

  1. import { createElement } from 'react';
  2. import {
  3. formatDateAliasHourMidnightEn as aliasMidnight,
  4. formatDateAliasHourNoonEn as aliasNoon,
  5. formatDateOptionsWeekdayHourMinShort as options,
  6. formatDateRangeString,
  7. } from 'md-in-js';
  8. // values [{ hour: 16 }, { hour: 0 }]
  9. // render <time>4 PM–Midnight</time>
  10. export default ({ values }) => {
  11. const locales = ['en'];
  12. const ltr = true;
  13. const aliases = [aliasNoon, aliasMidnight];
  14. return (
  15. <time>
  16. {{formatDateRangeString(
  17. options, locales, ltr, aliases, values[0], values[1]
  18. )}}
  19. </time>
  20. );
  21. };