<commit_before>require('../../stylus/components/_small-dialog.styl')

export default {
  name: 'v-edit-dialog',

  data () {
    return {
      isActive: false,
      isSaving: false
    }
  },

  props: {
    cancelText: {
      default: 'Cancel'
    },
    large: Boolean,
    lazy: Boolean,
    saveText: {
      default: 'Save'
    },
    transition: {
      type: String,
      default: 'slide-x-reverse-transition'
    }
  },

  watch: {
    isActive (val) {
      val &&
        this.$emit('open') &&
        setTimeout(this.focus, 50) // Give DOM time to paint

      if (!val) {
        !this.isSaving && this.$emit('cancel')
        this.isSaving && this.$emit('close')
        this.isSaving = false
      }
    }
  },

  methods: {
    cancel () {
      this.isActive = false
    },
    focus () {
      const input = this.$refs.content.querySelector('input')
      input && input.focus()
    },
    save () {
      this.isSaving = true
      this.isActive = false
      this.$emit('save')
    },
    genButton (fn, text) {
      return this.$createElement('v-btn', {
        props: {
          flat: true,
          primary: true,
          light: true
        },
        on: { click: fn }
      }, text)
    },
    genActions () {
      return this.$createElement('div', {
        'class': 'small-dialog__actions',
        directives: [{
          name: 'show',
          value: this.large
        }]
      }, [
        this.genButton(this.cancel, this.cancelText),
        this.genButton(this.save, this.saveText)
      ])
    },
    genContent () {
      return this.$createElement('div', {
        on: {
          keydown: e => {
            e.keyCode === 27 && this.cancel()
            e.keyCode === 13 && this.save()
          }
        },
        ref: 'content'
      }, [this.$slots.input])
    }
  },

  render (h) {
    return h('v-menu', {
      'class': 'small-dialog',
      props: {
        contentClass: 'small-dialog__content',
        transition: this.transition,
        origin: 'top right',
        right: true,
        value: this.isActive,
        closeOnContentClick: false,
        lazy: this.lazy
      },
      on: {
        input: val => (this.isActive = val)
      }
    }, [
      h('a', {
        domProps: { href: 'javascript:;' },
        slot: 'activator'
      }, this.$slots.default),
      this.genContent(),
      this.genActions()
    ])
  }
}<commit_msg>use 'color' prop instead of 'primary', do not generate actions if not large (#2039)<commit_after>require('../../stylus/components/_small-dialog.styl')

export default {
  name: 'v-edit-dialog',

  data () {
    return {
      isActive: false,
      isSaving: false
    }
  },

  props: {
    cancelText: {
      default: 'Cancel'
    },
    large: Boolean,
    lazy: Boolean,
    saveText: {
      default: 'Save'
    },
    transition: {
      type: String,
      default: 'slide-x-reverse-transition'
    }
  },

  watch: {
    isActive (val) {
      val &&
        this.$emit('open') &&
        setTimeout(this.focus, 50) // Give DOM time to paint

      if (!val) {
        !this.isSaving && this.$emit('cancel')
        this.isSaving && this.$emit('close')
        this.isSaving = false
      }
    }
  },

  methods: {
    cancel () {
      this.isActive = false
    },
    focus () {
      const input = this.$refs.content.querySelector('input')
      input && input.focus()
    },
    save () {
      this.isSaving = true
      this.isActive = false
      this.$emit('save')
    },
    genButton (fn, text) {
      return this.$createElement('v-btn', {
        props: {
          flat: true,
          color: 'primary',
          light: true
        },
        on: { click: fn }
      }, text)
    },
    genActions () {
      return this.$createElement('div', {
        'class': 'small-dialog__actions'
      }, [
        this.genButton(this.cancel, this.cancelText),
        this.genButton(this.save, this.saveText)
      ])
    },
    genContent () {
      return this.$createElement('div', {
        on: {
          keydown: e => {
            e.keyCode === 27 && this.cancel()
            e.keyCode === 13 && this.save()
          }
        },
        ref: 'content'
      }, [this.$slots.input])
    }
  },

  render (h) {
    return h('v-menu', {
      'class': 'small-dialog',
      props: {
        contentClass: 'small-dialog__content',
        transition: this.transition,
        origin: 'top right',
        right: true,
        value: this.isActive,
        closeOnContentClick: false,
        lazy: this.lazy
      },
      on: {
        input: val => (this.isActive = val)
      }
    }, [
      h('a', {
        domProps: { href: 'javascript:;' },
        slot: 'activator'
      }, this.$slots.default),
      this.genContent(),
      this.large ? this.genActions() : null
    ])
  }
}
{'fraction_non_alphanumeric': 0.1571843853820598, 'fraction_numerical': 0.0033222591362126247, 'mean_word_length': 1.6569222283507998, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4998927', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1516, 'n_words': 298}