Giter Site home page Giter Site logo

vmodal's People

Contributors

cretueusebiu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vmodal's Issues

Bootstrap 5

<template>
  <div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document" :class="sizeClass">
      <div class="modal-content">
        <slot name="content">
          <form @submit.prevent="$emit('submit', $event)" @keydown="onKeydown">
            <div class="modal-header">
              <slot name="header">
                <div class="modal-title">
                  <slot name="title" />
                </div>
                <button v-if="close" type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" />
              </slot>
            </div>
            <div class="modal-body">
              <slot name="body" />
            </div>
            <div v-if="$slots.footer" class="modal-footer">
              <slot name="footer" />
            </div>
          </form>
        </slot>
      </div>
    </div>
  </div>
</template>

<script>
import Modal from 'bootstrap/js/dist/modal'

export default {
  name: 'Modal',

  props: {
    backdrop: {
      type: [Boolean, String],
      default: true
    },

    close: {
      type: Boolean,
      default: true
    },

    focus: {
      type: Boolean,
      default: true
    },

    keyboard: {
      type: Boolean,
      default: true
    },

    size: {
      type: String,
      default: null
    },

    small: Boolean,
    large: Boolean,

    form: {
      type: Object,
      default: null
    },

    submit: {
      type: Function,
      default: null
    }
  },

  computed: {
    options () {
      return {
        focus: this.focus,
        backdrop: this.backdrop,
        keyboard: this.keyboard
      }
    },

    sizeClass () {
      if (this.small) { return 'modal-sm' }

      if (this.large) { return 'modal-lg' }

      return this.size ? `modal-${this.size}` : null
    }
  },

  mounted () {
    this.$modal = new Modal(this.$el, this.options)

    this.registerEvents()
  },

  beforeDestroy () {
    this.hide()
  },

  methods: {
    show () {
      this.updateOptions()

      this.$modal.show()

      return this
    },

    hide () {
      this.$modal.hide()

      return this
    },

    toggle () {
      this.$modal.toggle()

      return this
    },

    updateOptions () {
      Object.keys(this.options).forEach((key) => {
        this.$modal._config[key] = this.options[key]
      })
    },

    registerEvents () {
      ['show', 'shown', 'hide', 'hidden'].forEach((name) => {
        this.$el.addEventListener(`${name}.bs.modal`, e => this.$emit(name, e))
      })
    },

    onKeydown (e) {
      if (this.form) {
        this.form.errors.clear(e.target.name)
      }
    }
  }
}
</script>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.