<commit_before>/**
 * @license
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 */

CLASS({
  package: 'foam.u2.md',
  name: 'ActionButton',
  extends: 'foam.u2.View',

  requires: [
    'foam.ui.Color',
    'foam.ui.md.HaloView',
  ],
  imports: [ 'window' ],

  properties: [
    [ 'nodeName', 'ACTION-BUTTON' ],
    {
      type: 'Action',
      name: 'action',
    },
    {
      name: 'halo',
      lazyFactory: function() {
        return this.HaloView.create({
          className: 'halo',
          color$: this.color_$,
          recentering: false,
          pressedAlpha: 0.2,
          startAlpha: 0.2,
          finishAlpha: 0
        }, this.Y);
      },
    },
    {
      model_: 'foam.ui.ColorProperty',
      name: 'color',
      defaultValue: '#02A8F3',
    },
    {
      model_: 'FloatProperty',
      name: 'alpha',
      defaultValue: 1,
    },
    {
      model_: 'foam.ui.ColorProperty',
      name: 'color_',
      dynamicValue: function() {
        if ( ! (this.action && this.data &&
            this.action.isEnabled.call(this.data)) )
          return this.setColor('rgba(0,0,0,0.65)');
        else
          return this.setColor(this.color);
      },
    },
  ],

  methods: [
    function initE() {
      return this.cls('md-button').style({
        color: this.color_$,
        opacity: this.alpha$,
      })
        .on('click', this.onClick)
          // TODO(markdittmer): We need a better story for adapting CViews into
          // u2.
          .add(this.halo.toView_())
          .start('span').cls('md-button-label')
            .add(function() {
              return this.action ? this.action.label : '';
            }.bind(this).on$(this.X, this.action$))
          .end();
    },
    function setColor(c) {
      if ( ! this.Color.isInstance(c) ) {
        this.alpha = 1;
        return c;
      }
      this.alpha = c.alpha;
      c.alpha = 1;
      return c;
    },
  ],

  listeners: [
    function onClick(e) {
      e.preventDefault();
      e.stopPropagation();
      this.action.maybeCall(this.X, this.data);
    },
  ],

  templates: [
    function CSS() {/*
      action-button {
        display: inline-flex;
        align-items: baseline;
        justify-content: center;
        overflow: hidden;
        position: relative;
        border-radius: 2px;
        cursor: pointer;
        color: #02A8F3;
      }

      action-button .halo {
        position: absolute;
        left: 0;
        top: 0;
        z-index: 2;
        border-radius: inherit;
      }

      action-button.md-button .md-button-label {
        color: inherit;
      }
    */},
  ],
});<commit_msg>U2 MD ActionButton: Proper show/hide for .isAvailable().<commit_after>/**
 * @license
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 */

CLASS({
  package: 'foam.u2.md',
  name: 'ActionButton',
  extends: 'foam.u2.View',

  requires: [
    'foam.ui.Color',
    'foam.ui.md.HaloView',
  ],
  imports: [ 'window' ],

  properties: [
    [ 'nodeName', 'ACTION-BUTTON' ],
    {
      type: 'Action',
      name: 'action',
    },
    {
      name: 'halo',
      lazyFactory: function() {
        return this.HaloView.create({
          className: 'halo',
          color$: this.color_$,
          recentering: false,
          pressedAlpha: 0.2,
          startAlpha: 0.2,
          finishAlpha: 0
        }, this.Y);
      },
    },
    {
      model_: 'foam.ui.ColorProperty',
      name: 'color',
      defaultValue: '#02A8F3',
    },
    {
      model_: 'FloatProperty',
      name: 'alpha',
      defaultValue: 1,
    },
    {
      model_: 'foam.ui.ColorProperty',
      name: 'color_',
      dynamicValue: function() {
        if ( ! (this.action && this.data &&
            this.action.isEnabled.call(this.data)) )
          return this.setColor('rgba(0,0,0,0.65)');
        else
          return this.setColor(this.color);
      },
    },
  ],

  methods: [
    function initE() {
      return this.cls('md-button')
        .cls2(function() {
          return (this.action &&
              this.action.isAvailable.call(this.data, this.action)) ?
              'available' : '';
        }.bind(this)).style({
          color: this.color_$,
          opacity: this.alpha$,
        })
        .on('click', this.onClick)
          // TODO(markdittmer): We need a better story for adapting CViews into
          // u2.
          .add(this.halo.toView_())
          .start('span').cls('md-button-label')
            .add(function() {
              return this.action ? this.action.label : '';
            }.bind(this).on$(this.X, this.action$))
          .end();
    },
    function setColor(c) {
      if ( ! this.Color.isInstance(c) ) {
        this.alpha = 1;
        return c;
      }
      this.alpha = c.alpha;
      c.alpha = 1;
      return c;
    },
  ],

  listeners: [
    function onClick(e) {
      e.preventDefault();
      e.stopPropagation();
      this.action.maybeCall(this.X, this.data);
    },
  ],

  templates: [
    function CSS() {/*
      action-button {
        display: none;
        align-items: baseline;
        justify-content: center;
        overflow: hidden;
        position: relative;
        border-radius: 2px;
        cursor: pointer;
        color: #02A8F3;
      }

      action-button.available {
        display: inline-flex;
      }

      action-button .halo {
        position: absolute;
        left: 0;
        top: 0;
        z-index: 2;
        border-radius: inherit;
      }

      action-button.md-button .md-button-label {
        color: inherit;
      }
    */},
  ],
});
{'fraction_non_alphanumeric': 0.15027367722673743, 'fraction_numerical': 0.01260573892851219, 'mean_word_length': 1.7211191335740073, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '640320', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1931, 'n_words': 402}