element-action-menu.html 3.03 KB
<link rel="import" href="../../bower_components/iron-icons/iron-icons.html">

<link rel="import" href="../catalog-element/catalog-element.html">

<dom-module id="element-action-menu">
  <template>
    <style>
      :host {
        @apply(--layout);
        @apply(--layout-center);
        @apply(--layout-center-justified);
        position: absolute;
        text-align: center;
        padding-top: 15px;
        margin-right: 5px;
        opacity: 1;
        transition: opacity 0.2s;
        -webkit-transition: opacity 0.2s;
      }

      :host(.cards) {
        background-color: rgba(255, 255, 255, 0.9);
        margin-right: 0px;
      }

      :host(.hidden) {
        pointer-events: none;
        opacity: 0;
      }

      a, iron-icon {
        font-size: 12px;
        color: #666;
        outline: none;
      }

      a {
        margin: 0 5px;
        cursor: pointer;
      }

      span {
        width: 40px;
        display: block;
      }

      a:hover,
      a:hover iron-icon {
        color: black;
      }

      iron-icon {
        --iron-icon-width: 18px;
        --iron-icon-height: 18px;
      }

      cart-item-icon {
        --cart-item-icon-label: { 
          display: block;
          width: 40px;
        };
      }

    </style>
    <catalog-element name="[[element]]" data="{{_element}}"></catalog-element>

    <a tabindex="0" role="button" on-tap="cartAdd">
      <cart-item-icon id="cartItemIcon" element="[[element]]" present-label="Remove" absent-label="Add" no-label="[[iconsOnly]]"></cart-item-icon>
    </a>

    <a tabindex="0" role="button" on-click="navToDocs" aria-label="View Docs">
      <iron-icon icon="description" title="View Docs"></iron-icon>
      <span hidden$="[[iconsOnly]]">Docs</span>
    </a>

    <a tabindex="0" role="button" href="[[githubLink(_element.source)]]" target="_blank" title="View Source on GitHub" aria-label="View Source on GitHub">
      <iron-icon icon="code"></iron-icon>
      <span hidden$="[[iconsOnly]]">Source</span>
    </a>

    <a tabindex="0" role="button" on-click="navToDemo" hidden$="[[!_element.demo]]" aria-label="View Demo">
      <iron-icon icon="visibility" title="View Demo"></iron-icon>
      <span hidden$="[[iconsOnly]]">Demo</span>
    </a>
  </template>
</dom-module>

<script>
Polymer({
  is: 'element-action-menu',
  properties: {
    element: String,
    _element: Object,
    iconsOnly: {type: Boolean, value: false, reflectToAttribute: true}
  },
  githubLink: function(source) {
    return "https://github.com/" + source;
  },
  cartAdd: function(e) {
    e.stopPropagation();
    e.preventDefault();
    this.$.cartItemIcon.toggle();
  },
  navToDocs: function(e) {
    e.stopPropagation();
    e.preventDefault();
    this.fire('nav', {url: '/elements/' + this.element + '?view=docs'});
  },
  navToDemo: function(e) {
    e.stopPropagation();
    e.preventDefault();
    if (e.currentTarget.hasAttribute('disabled')) return false;
    this.fire('nav', {url: '/elements/' + this.element + '?active=' + this._element.active + "&view=demo:" + this._element.demo.path});
  }
});
</script>