Skip to content

Commit f0559cd

Browse files
committed
添加原生Modal
1 parent 6ec7536 commit f0559cd

File tree

29 files changed

+332
-100
lines changed

29 files changed

+332
-100
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<template>
2+
<div>
3+
<lai-button @click.native="originModal">原生 Modal</lai-button>
4+
<lai-button @click.native="value = !value">Vue Modal</lai-button>
5+
<lai-modal v-model="value">
6+
<h3>Vue Modal</h3>
7+
</lai-modal>
8+
</div>
9+
</template>
10+
<script>
11+
import LaiButton from './lai-button'
12+
import LaiModal from './modal'
13+
import './modal/Modal'
14+
export default {
15+
// name: 'globalModalDemo',
16+
data () {
17+
return {
18+
value: false
19+
}
20+
},
21+
components: { LaiModal, LaiButton },
22+
methods: {
23+
originModal () {
24+
this.modal = new window.Modal({
25+
content: '<h3>原生Modal</h3>'
26+
})
27+
this.modal.open()
28+
}
29+
}
30+
}
31+
</script>

docs/.vuepress/components/lai-button.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
</template>
44
<script>
55
export default {
6+
created () {
7+
console.log(process.env.NODE_ENV)
8+
},
69
props: {
710
size: {
811
validator: val => {

docs/.vuepress/components/modal-demo.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<lai-button @click.native="value = !vlaue">Toggle Modal</lai-button>
3+
<lai-button @click.native="value = !value">Toggle Modal</lai-button>
44
<lai-modal v-model="value"></lai-modal>
55
</div>
66
</template>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import "./Modal.less"
2+
;(function(window) {
3+
function extendDefaults(source, properties) {
4+
var property
5+
for (property in properties) {
6+
if (properties.hasOwnProperty(property)) {
7+
source[property] = properties[property]
8+
}
9+
}
10+
return source
11+
}
12+
13+
function getTransitionEnd() {
14+
var el = document.createElement("div")
15+
if (el.style.WebkitTransition) {
16+
return "webkitTransitionEnd"
17+
}
18+
return "transitionEnd"
19+
}
20+
21+
function buildOut() {
22+
var content, contetnHolder, docFrag
23+
if (typeof this.options.content === "string") {
24+
content = this.options.content
25+
} else {
26+
content = this.options.content.innerHTML
27+
}
28+
29+
docFrag = document.createDocumentFragment()
30+
31+
this.modal = document.createElement("div")
32+
this.modal.className = "modal " + this.options.className
33+
this.modal.style.minWidth = this.options.minWidth + "px"
34+
this.modal.style.minHeight = this.options.minHeight + "px"
35+
36+
if (this.options.closeButton) {
37+
this.closeButton = document.createElement("button")
38+
this.closeButton.className = "modal-close close-button"
39+
this.closeButton.innerHTML = "x"
40+
this.modal.appendChild(this.closeButton)
41+
}
42+
43+
if (this.options.overlay) {
44+
this.overlay = document.createElement("div")
45+
this.overlay.className = "modal-overlay " + this.options.className
46+
docFrag.appendChild(this.overlay)
47+
}
48+
49+
contetnHolder = document.createElement("div")
50+
contetnHolder.className = "modal-content"
51+
contetnHolder.innerHTML = content
52+
this.modal.appendChild(contetnHolder)
53+
54+
docFrag.appendChild(this.modal)
55+
56+
document.body.appendChild(docFrag)
57+
}
58+
59+
function initializeEvents() {
60+
if (this.closeButton) {
61+
this.closeButton.addEventListener("click", this.close.bind(this))
62+
}
63+
64+
if (this.overlay) {
65+
this.overlay.addEventListener("click", this.close.bind(this))
66+
}
67+
}
68+
window.Modal = function() {
69+
var defaults = {
70+
content: "",
71+
overlay: true,
72+
minWidth: 560,
73+
minHeight: 280,
74+
closeButton: true,
75+
className: "fade-and-drop"
76+
}
77+
78+
this.closeButton = null
79+
this.modal = null
80+
this.overlay = null
81+
if (arguments[0] && typeof arguments[0] === "object") {
82+
this.options = extendDefaults(defaults, arguments[0])
83+
}
84+
}
85+
86+
window.Modal.prototype.open = function() {
87+
buildOut.call(this)
88+
initializeEvents.call(this)
89+
90+
window.getComputedStyle(this.modal)
91+
92+
this.modal.className =
93+
this.modal.className +
94+
(this.modal.offsetHeight > window.innerHeight
95+
? " modal-open modal-anchored"
96+
: " modal-open")
97+
this.overlay.className = this.overlay.className + " modal-open"
98+
}
99+
100+
window.Modal.prototype.close = function() {
101+
var $this = this
102+
this.modal.className = this.modal.className.replace(" modal-open", "")
103+
this.overlay.className = this.overlay.className.replace(" modal-open", "")
104+
105+
this.modal.addEventListener("webkitTransitionEnd", function() {
106+
$this.modal.parentNode.removeChild($this.modal)
107+
})
108+
109+
this.overlay.addEventListener("webkitTransitionEnd", function() {
110+
$this.overlay.parentNode.removeChild($this.overlay)
111+
})
112+
}
113+
})(window)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
.modal-overlay {
2+
position: fixed;
3+
will-change: transform;
4+
z-index: 9999;
5+
top: 0;
6+
right: 0;
7+
bottom: 0;
8+
left: 0;
9+
opacity: 0;
10+
background-color: rgba(0, 0, 0, 0.65);
11+
transition: 1ms opacity ease;
12+
&.modal-open {
13+
opacity: 1;
14+
}
15+
}
16+
17+
.modal {
18+
position: absolute;
19+
z-index: 10000;
20+
top: 50%;
21+
left: 50%;
22+
transform: translate(-50%, -50%);
23+
max-width: 80vw;
24+
padding: 30px 20px;
25+
transition: 1ms opacity ease;
26+
opacity: 0;
27+
border-radius: 4px;
28+
background-color: #fff;
29+
&.modal-anchored {
30+
top: 2vh;
31+
transform: translate(-50%, 0);
32+
}
33+
&.modal-open {
34+
opacity: 1;
35+
}
36+
}
37+
.modal-close {
38+
font-family: Helvetica, Arial, sans-serif;
39+
font-size: 24px;
40+
font-weight: 700;
41+
line-height: 12px;
42+
position: absolute;
43+
top: 5px;
44+
right: 5px;
45+
padding: 5px 7px 7px;
46+
cursor: pointer;
47+
color: #fff;
48+
border: 0;
49+
outline: none;
50+
background: #e74c3c;
51+
&:hover {
52+
background: #c0392b;
53+
}
54+
}
55+
56+
// 默认动画效果
57+
.modal-overlay.fade-and-drop {
58+
display: block;
59+
opacity: 0;
60+
transition: 500ms opacity 500ms ease;
61+
&.modal-open {
62+
top: 0;
63+
transition: 500ms opacity ease;
64+
opacity: 1;
65+
}
66+
}
67+
.modal.fade-and-drop {
68+
top: -300vh;
69+
opacity: 1;
70+
display: block;
71+
transition: 500ms top ease;
72+
&.modal-open {
73+
top: 50%;
74+
transition: 500ms top 500ms ease;
75+
&.modal-anchored {
76+
transition: 500ms top 500ms ease;
77+
}
78+
}
79+
}

docs/.vuepress/config.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,51 @@
11
module.exports = {
2-
base: '/lai-ui/',
3-
title: 'Components Learning With Vue',
4-
head: [
5-
['link', { rel: 'icon', href: '/img/favicon.ico' }]
6-
],
2+
base: process.env.NODE_ENV === "production" ? "/lai-ui/" : "/",
3+
title: "Components Learning With Vue",
4+
head: [["link", { rel: "icon", href: "/img/favicon.ico" }]],
75
serviceWorker: false,
86
themeConfig: {
97
nav: [
10-
{ text: 'Home', link: '/' },
11-
{ text: 'documents', link: '/posts/' },
12-
{ text: 'github', link: 'https://github.com/zepang/lai-ui' },
8+
{ text: "Home", link: "/" },
9+
{ text: "documents", link: "/posts/" },
10+
{ text: "github", link: "https://github.com/zepang/lai-ui" }
1311
],
1412
sidebar: [
15-
'/posts/',
13+
"/posts/",
1614
{
17-
title: '组件实践',
15+
title: "组件实践",
1816
collapsable: false,
1917
children: [
20-
'/posts/tutorial/1',
18+
"/posts/tutorial/1",
2119
// '/posts/tutorial/prerequsites',
22-
'/posts/tutorial/2',
23-
'/posts/tutorial/3',
24-
'/posts/tutorial/4',
25-
'/posts/tutorial/5',
26-
'/posts/tutorial/6',
27-
'/posts/tutorial/7',
28-
'/posts/tutorial/8',
29-
'/posts/tutorial/9',
30-
'/posts/tutorial/10',
20+
"/posts/tutorial/2",
21+
"/posts/tutorial/3",
22+
"/posts/tutorial/4",
23+
"/posts/tutorial/5",
24+
"/posts/tutorial/6",
25+
"/posts/tutorial/7",
26+
"/posts/tutorial/8",
27+
"/posts/tutorial/9",
28+
"/posts/tutorial/10"
3129
]
3230
},
3331
{
34-
title: '组件案例',
32+
title: "组件案例",
3533
collapsable: false,
3634
children: [
37-
'/posts/components/button',
38-
'/posts/components/message',
39-
'/posts/components/modal',
40-
'/posts/components/checkbox',
41-
'/posts/components/tree',
42-
'/posts/components/date'
35+
"/posts/components/button",
36+
"/posts/components/message",
37+
"/posts/components/modal",
38+
"/posts/components/checkbox",
39+
"/posts/components/tree",
40+
"/posts/components/date"
4341
]
4442
}
4543
]
4644
},
4745
configureWebpack: (config, isServer) => {
4846
if (!isServer) {
49-
config.output.publicPath = '/lai-ui/'
47+
config.output.publicPath =
48+
process.env.NODE_ENV === "production" ? "/lai-ui/" : "/"
5049
}
5150
}
52-
}
51+
}

docs/.vuepress/dist/404.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<meta name="description" content="">
88
<link rel="icon" href="/lai-ui/img/favicon.ico">
99

10-
<link rel="preload" href="/lai-ui/assets/css/0.styles.00650b63.css" as="style"><link rel="preload" href="/lai-ui/assets/js/app.b69adbbf.js" as="script"><link rel="prefetch" href="/lai-ui/assets/js/1.e23d61a3.js"><link rel="prefetch" href="/lai-ui/assets/js/10.c5a89235.js"><link rel="prefetch" href="/lai-ui/assets/js/11.fc22c208.js"><link rel="prefetch" href="/lai-ui/assets/js/12.a7363272.js"><link rel="prefetch" href="/lai-ui/assets/js/13.1ea586cf.js"><link rel="prefetch" href="/lai-ui/assets/js/14.a0f36f98.js"><link rel="prefetch" href="/lai-ui/assets/js/15.73787a08.js"><link rel="prefetch" href="/lai-ui/assets/js/16.f10acf75.js"><link rel="prefetch" href="/lai-ui/assets/js/17.5b3297b2.js"><link rel="prefetch" href="/lai-ui/assets/js/18.c04768f3.js"><link rel="prefetch" href="/lai-ui/assets/js/19.fd01e87a.js"><link rel="prefetch" href="/lai-ui/assets/js/2.0290846d.js"><link rel="prefetch" href="/lai-ui/assets/js/20.29ba5d2a.js"><link rel="prefetch" href="/lai-ui/assets/js/21.0c4537c2.js"><link rel="prefetch" href="/lai-ui/assets/js/22.91388c64.js"><link rel="prefetch" href="/lai-ui/assets/js/23.499ca679.js"><link rel="prefetch" href="/lai-ui/assets/js/24.a5aee98c.js"><link rel="prefetch" href="/lai-ui/assets/js/25.a7864260.js"><link rel="prefetch" href="/lai-ui/assets/js/26.98a1d1b4.js"><link rel="prefetch" href="/lai-ui/assets/js/27.7110ff41.js"><link rel="prefetch" href="/lai-ui/assets/js/28.a021b427.js"><link rel="prefetch" href="/lai-ui/assets/js/29.0d3b7864.js"><link rel="prefetch" href="/lai-ui/assets/js/30.c50323f4.js"><link rel="prefetch" href="/lai-ui/assets/js/31.419834ff.js"><link rel="prefetch" href="/lai-ui/assets/js/32.1a62e87a.js"><link rel="prefetch" href="/lai-ui/assets/js/33.03f0a068.js"><link rel="prefetch" href="/lai-ui/assets/js/34.3b3dc970.js"><link rel="prefetch" href="/lai-ui/assets/js/35.93a8eb89.js"><link rel="prefetch" href="/lai-ui/assets/js/36.097df056.js"><link rel="prefetch" href="/lai-ui/assets/js/37.0986ff00.js"><link rel="prefetch" href="/lai-ui/assets/js/38.ee3d8843.js"><link rel="prefetch" href="/lai-ui/assets/js/39.23b75403.js"><link rel="prefetch" href="/lai-ui/assets/js/4.b3cbff8b.js"><link rel="prefetch" href="/lai-ui/assets/js/40.0dd3009d.js"><link rel="prefetch" href="/lai-ui/assets/js/41.94c2c506.js"><link rel="prefetch" href="/lai-ui/assets/js/42.06df845c.js"><link rel="prefetch" href="/lai-ui/assets/js/43.93b9b1e4.js"><link rel="prefetch" href="/lai-ui/assets/js/44.ebac3e47.js"><link rel="prefetch" href="/lai-ui/assets/js/45.edbd395b.js"><link rel="prefetch" href="/lai-ui/assets/js/46.f09ea619.js"><link rel="prefetch" href="/lai-ui/assets/js/47.1f48d3bc.js"><link rel="prefetch" href="/lai-ui/assets/js/48.8ab892bd.js"><link rel="prefetch" href="/lai-ui/assets/js/49.542698b3.js"><link rel="prefetch" href="/lai-ui/assets/js/5.f70937d1.js"><link rel="prefetch" href="/lai-ui/assets/js/50.0033db77.js"><link rel="prefetch" href="/lai-ui/assets/js/6.07661dea.js"><link rel="prefetch" href="/lai-ui/assets/js/7.ba8b369a.js"><link rel="prefetch" href="/lai-ui/assets/js/8.87b2f5ff.js"><link rel="prefetch" href="/lai-ui/assets/js/9.17aa6d21.js">
11-
<link rel="stylesheet" href="/lai-ui/assets/css/0.styles.00650b63.css">
10+
<link rel="preload" href="/lai-ui/assets/css/0.styles.85cfd723.css" as="style"><link rel="preload" href="/lai-ui/assets/js/app.a7d24472.js" as="script"><link rel="prefetch" href="/lai-ui/assets/js/1.835102cd.js"><link rel="prefetch" href="/lai-ui/assets/js/10.33386f85.js"><link rel="prefetch" href="/lai-ui/assets/js/11.01ceda88.js"><link rel="prefetch" href="/lai-ui/assets/js/12.9e24b8c2.js"><link rel="prefetch" href="/lai-ui/assets/js/13.8c56eed9.js"><link rel="prefetch" href="/lai-ui/assets/js/14.c874860e.js"><link rel="prefetch" href="/lai-ui/assets/js/15.3665fb15.js"><link rel="prefetch" href="/lai-ui/assets/js/16.c270df1f.js"><link rel="prefetch" href="/lai-ui/assets/js/17.037d68aa.js"><link rel="prefetch" href="/lai-ui/assets/js/18.01766f22.js"><link rel="prefetch" href="/lai-ui/assets/js/19.23789c40.js"><link rel="prefetch" href="/lai-ui/assets/js/2.84fed521.js"><link rel="prefetch" href="/lai-ui/assets/js/20.f0f33398.js"><link rel="prefetch" href="/lai-ui/assets/js/21.c2f414b1.js"><link rel="prefetch" href="/lai-ui/assets/js/22.7fed4a64.js"><link rel="prefetch" href="/lai-ui/assets/js/23.5450852d.js"><link rel="prefetch" href="/lai-ui/assets/js/24.472f7183.js"><link rel="prefetch" href="/lai-ui/assets/js/25.a7864260.js"><link rel="prefetch" href="/lai-ui/assets/js/26.2656af57.js"><link rel="prefetch" href="/lai-ui/assets/js/27.00e90597.js"><link rel="prefetch" href="/lai-ui/assets/js/28.267deba5.js"><link rel="prefetch" href="/lai-ui/assets/js/29.28e64496.js"><link rel="prefetch" href="/lai-ui/assets/js/30.6a29c9fc.js"><link rel="prefetch" href="/lai-ui/assets/js/31.ce778e5d.js"><link rel="prefetch" href="/lai-ui/assets/js/32.bf9bd9ba.js"><link rel="prefetch" href="/lai-ui/assets/js/33.15447277.js"><link rel="prefetch" href="/lai-ui/assets/js/34.14eec79e.js"><link rel="prefetch" href="/lai-ui/assets/js/35.3ede12c2.js"><link rel="prefetch" href="/lai-ui/assets/js/36.5ba9d882.js"><link rel="prefetch" href="/lai-ui/assets/js/37.26a533c2.js"><link rel="prefetch" href="/lai-ui/assets/js/38.f6901208.js"><link rel="prefetch" href="/lai-ui/assets/js/39.ca02e8f9.js"><link rel="prefetch" href="/lai-ui/assets/js/4.b3cbff8b.js"><link rel="prefetch" href="/lai-ui/assets/js/40.ed19be3b.js"><link rel="prefetch" href="/lai-ui/assets/js/41.aa054801.js"><link rel="prefetch" href="/lai-ui/assets/js/42.0be89855.js"><link rel="prefetch" href="/lai-ui/assets/js/43.ec99fb48.js"><link rel="prefetch" href="/lai-ui/assets/js/44.0830d8e2.js"><link rel="prefetch" href="/lai-ui/assets/js/45.fc312cf3.js"><link rel="prefetch" href="/lai-ui/assets/js/46.ada613f9.js"><link rel="prefetch" href="/lai-ui/assets/js/47.b1b6750e.js"><link rel="prefetch" href="/lai-ui/assets/js/48.adc9e622.js"><link rel="prefetch" href="/lai-ui/assets/js/49.4eee2588.js"><link rel="prefetch" href="/lai-ui/assets/js/5.172be422.js"><link rel="prefetch" href="/lai-ui/assets/js/50.0033db77.js"><link rel="prefetch" href="/lai-ui/assets/js/6.9f669274.js"><link rel="prefetch" href="/lai-ui/assets/js/7.fb1f6967.js"><link rel="prefetch" href="/lai-ui/assets/js/8.d5cdacc0.js"><link rel="prefetch" href="/lai-ui/assets/js/9.1b0e6a19.js">
11+
<link rel="stylesheet" href="/lai-ui/assets/css/0.styles.85cfd723.css">
1212
</head>
1313
<body>
14-
<div id="app" data-server-rendered="true"><div class="theme-container"><div class="content"><h1>404</h1> <blockquote>How did we get here?</blockquote> <a href="/lai-ui/" class="router-link-active">Take me home.</a></div></div></div>
15-
<script src="/lai-ui/assets/js/app.b69adbbf.js" defer></script>
14+
<div id="app" data-server-rendered="true"><div class="theme-container"><div class="content"><h1>404</h1> <blockquote>That's a Four-Oh-Four.</blockquote> <a href="/lai-ui/" class="router-link-active">Take me home.</a></div></div></div>
15+
<script src="/lai-ui/assets/js/app.a7d24472.js" defer></script>
1616
</body>
1717
</html>

0 commit comments

Comments
 (0)