1.0.0 • Published 4 years ago

@tomoeed/j-dialog v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 years ago

j-dialog

A dialog component for Vue

安装

npm install @tomoeed/j-dialog --save

使用

安装插件

import Vue from 'vue';
import JDialog from '@tomoeed/j-dialog';

Vue.use(JDialog, {names: {}, hooks: {}});

组件使用

对话框打开后元素聚焦规则: 1. 第一个拥有 autofocus 属性的元素 2. 对话框按钮组件 e.g j-dialog-button 3. 对话框自身

<template>
    <div>
        <button @click="visible = true" type="button">Open</button>

        <j-dialog :visible="visible"
                  :before-close="beforeClose"
                  title="Title"
                  title-id="dialog_title"
                  describe="'Describe'"
                  describe-id="dialog_describe"
                  @open="onOpen"
                  @opened="onOpened"
                  @closed="onClosed">
            <j-dialog-content>
                Content
            </j-dialog-content>

            <j-dialog-footer>
                <j-dialog-button :priority="1" :is-dismisser="true">Close</j-dialog-button>
            </j-dialog-footer>
        </j-dialog>
    </div>
</template>

<script>
    export default {
        name: 'YourComponent',
        data() {
            return { visible: false };
        },
        methods: {
            beforeClose() {
                // do something...
                return true; // or false
            },
            onOpen() { /* do something... */ },
            onOpened() { /* do something... */ },
            onClosed() { /* do something... */ }
        }
    };
</script>

插件可选的选项对象

  • names 组件名称
Vue.use(JDialog, {names: {
    dialog: 'j-dialog',
    content: 'j-dialog-content',
    footer: 'j-dialog-footer',
    button: 'j-dialog-button'
}});
  • hooks 全局钩子
Vue.use(JDialog, {hooks: {
    open: () => {},
    opened: () => {},
    closed: () => {}
}});

组件 Props

j-dialog

PropRequiredTypeDefaultDescription
visiblefalseBooleanfalse对话框显示状态
modalfalseBooleantrue是否为模态对话框
keyboardDismissfalseBooleantrueEscape按键是否可以关闭对话框
backdropDismissfalseBooleanfalse点击遮罩层是否可以关闭对话框
lockScrollfalseBooleantrue对话框打开后是否禁止屏幕滚顶
beforeClosefalseFunction() => true对话框关闭前的回调函数, 会暂停对话框的关闭. 如果函数返回 false, 对话框将不会关闭
xClassfalseString|Array|Object''对话框class
xStylefalseString|Array|Object''对话框style
draggablefalseBooleantrue对话框是否可拖动
resetPositionfalseBooleantrue对话框关闭后重置定位
titlefalseString''对话框标题
titleIdfalseStringundefined对话框标题id
describefalseString''对话框描述
describeIdfalseStringundefined对话框描述id
dismissablefalseBooleantrue是否显示关闭按钮

j-dialog-content

PropRequiredTypeDefaultDescription
tagfalseStringdiv渲染标签

j-dialog-footer

j-dialog-button

PropRequiredTypeDefaultDescription
priorityfalseNumber0对话框打开后聚焦优先级(对话框内没有具有autofocus属性的元素使生效)
isDismisserfalseBooleanfalse该按钮是否可以关闭对话框

组件插槽

NameDescription
title对话框标题
describe对话框描述

License

Apache-2.0