如何在Dart中使用不同的核心图标图标集



core-icons包含不同的图标集,如

    <
  • 图标/gh>
  • av-icons
  • communication-icons
  • device-icons
  • hardware-icons
  • image-icons
  • maps-icons
  • 通知图标
  • png-icons
  • 社会性图标

下面是paper-elements中包含的图标的概述http://polymer.github.io/core-icons/components/core-icons/demo.html

我创建了一个示例来演示如何使用它们。

<!DOCTYPE html>
<html>
  <head>
    <title>core-icons</title>
    <!-- <script src="packages/web_components/platform.js"></script>
         not necessary anymore with Polymer >= 0.14.0 -->
    <script src="packages/web_components/dart_support.js"></script>
    <link rel="import" href="packages/paper_elements/paper_icon_button.html">
    <!-- choose the name according to the set you want to load - "social-icons" -->
    <!-- this is now accessible with a simpler path
    <link rel="import" href="packages/core_elements/src/core-icons/iconsets/social-icons.html"> 
    <link rel="import" href="packages/core_elements/core_icons/iconsets/social_icons.html"> 
    this changed again with core-elements 0.2.0+1 -->
    <link rel="import" href="packages/core_elements/social_icons.html">
  </head>
  <body>
    <!-- use the icon by setting the `icon` attribute. The value consists of iconsset-id a colon followed by the icon name. -->
    <paper-icon-button id="bookmark-button" icon="social:plus-one" style="fill:steelblue;"></paper-icon-button>
    <script type="application/dart">export 'package:polymer/init.dart';</script>
  </body>
</html>

编辑

您可以从Dart代码中设置图标的样式,如

($['bookmark-button'] as dom.Element).querySelector('* /deep/ #icon').style
    ..setProperty('fill', 'red')
    ..setProperty('stroke', 'blue')
    ..setProperty('stroke-with', '3px');

这原来是相当棘手的,因为paper-icon-button有一个以上的shadowRoot(3实际上),当我在<g>元素上设置样式(在<core-icon>内部)时,它被应用,但由于未知的原因不久之后又恢复了。

我刚刚看到这在Firefox中不起作用。据我所知,querySelector()/deep/的填充正在进行中。也许当当前的Polymer版本被集成到Polymer. dart中时,它会更好地工作。

这在Dartium和Firefox中都有效:

($['bookmark-button'] as dom.Element).shadowRoot.olderShadowRoot.querySelector('#icon').style
    ..setProperty('fill', 'red')
    ..setProperty('stroke', 'blue')
    ..setProperty('stroke-with', '3px');

<paper-icon-button>的实现改变时,这个解决方案可能会中断,但希望在一段时间内第一次尝试将很快在所有浏览器中工作。

编辑

querySelector/deep/的Polyfill支持包含在Polymer.js 0.4.0中。希望是下一个聚合物。Dart更新也包含了它

最新更新