Skip to content

Commit 1387829

Browse files
committed
added shared components
1 parent 759c074 commit 1387829

File tree

3 files changed

+256
-0
lines changed

3 files changed

+256
-0
lines changed

resources/js/Shared/Confirm.vue

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<template>
2+
<v-dialog v-model="dialog" width="500">
3+
<v-card>
4+
<v-card-title class="headline error" dark>
5+
<span class="white--text">{{ title }}</span>
6+
</v-card-title>
7+
8+
<v-card-text>{{ message }}</v-card-text>
9+
10+
<v-divider />
11+
12+
<v-card-actions>
13+
<v-btn text color="secondary" @click="dialog = false">
14+
<v-icon left>arrow_left</v-icon>Back
15+
</v-btn>
16+
<v-spacer />
17+
<v-btn color="primary" text @click="confirm()">{{ action }}</v-btn>
18+
</v-card-actions>
19+
</v-card>
20+
</v-dialog>
21+
</template>
22+
23+
<script>
24+
export default {
25+
props: {
26+
callback: {
27+
type: Function,
28+
required: true,
29+
},
30+
message: {
31+
type: String,
32+
default: function() {
33+
return "Halt! This Action is Destructive and Irreversible Only Proceed If You Think Deleting This Record has No Side effects To Other Record.";
34+
},
35+
},
36+
title: {
37+
type: String,
38+
default: function() {
39+
return "Are You Sure You Want To Delete This?";
40+
},
41+
},
42+
action: {
43+
type: String,
44+
default: function() {
45+
return "Yes , I Understand";
46+
},
47+
},
48+
},
49+
data: () => ({
50+
dialog: false,
51+
params: null,
52+
}),
53+
mounted() {
54+
// eslint-disable-next-line no-undef
55+
Bus.$on("open-confirmation", params => {
56+
this.dialog = true;
57+
this.params = params;
58+
});
59+
},
60+
methods: {
61+
closeDialog() {
62+
this.dialog = false;
63+
},
64+
confirm() {
65+
if (this.callback) {
66+
if (this.params != undefined) {
67+
this.dialog = false;
68+
69+
this.callback(this.params);
70+
} else {
71+
this.dialog = false;
72+
73+
this.callback();
74+
}
75+
}
76+
},
77+
},
78+
};
79+
</script>
80+
81+
<style>
82+
</style>

resources/js/Shared/VHyperlink.vue

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<template>
2+
<inertia-link
3+
class="inertia-link"
4+
:href="route(`${href}`)"
5+
>
6+
<slot />
7+
</inertia-link>
8+
</template>
9+
10+
11+
<script>
12+
export default {
13+
props: {
14+
href: {
15+
type: String,
16+
default: "home",
17+
},
18+
},
19+
};
20+
</script>
21+
22+
23+
24+
<style scoped>
25+
.btn {
26+
text-decoration: none;
27+
}
28+
.inertia-link {
29+
text-decoration: none;
30+
}
31+
</style>
32+
33+

resources/js/Shared/Vlink.vue

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<template>
2+
<v-list-item :class="[{ styleAvatar: avatarOn }]" @click.native="navigate(href)">
3+
<v-list-item-action v-if="iconOn && !avatarOn">
4+
<v-icon
5+
:style="{color: isActive(href) ? activeColor : iconColor, cursor: href ? 'pointer' : ''}"
6+
>{{ icon }}</v-icon>
7+
</v-list-item-action>
8+
<v-list-item-avatar v-if="iconOn && avatarOn">
9+
<v-img :src="avatar" />
10+
</v-list-item-avatar>
11+
<v-list-item-content>
12+
<v-list-item-title :style="{color: isActive(href) ? activeColor : linkColor}">
13+
<span :style="{cursor: href ? 'pointer' : ''}">{{ title }}</span>
14+
</v-list-item-title>
15+
</v-list-item-content>
16+
<v-list-item-action v-if="iconOn && avatarOn">
17+
<v-icon
18+
:style="{color: isActive(href) ? activeColor : iconColor, cursor: href ? 'pointer' : ''}"
19+
>{{ icon }}</v-icon>
20+
</v-list-item-action>
21+
</v-list-item>
22+
</template>
23+
24+
<script>
25+
export default {
26+
props: {
27+
dark: {
28+
type: Boolean,
29+
default() {
30+
return false;
31+
}
32+
},
33+
href: {
34+
type: String,
35+
required: true
36+
},
37+
title: {
38+
type: String,
39+
required: true
40+
},
41+
avatar: {
42+
type: String,
43+
default() {
44+
return "";
45+
}
46+
},
47+
icon: {
48+
type: String,
49+
default() {
50+
return "";
51+
}
52+
},
53+
iconColor: {
54+
type: String,
55+
default() {
56+
return this.dark ? "#fafafa" : "#78909C"; // white or blue-grey lighten-1
57+
}
58+
},
59+
linkColor: {
60+
type: String,
61+
default() {
62+
return this.dark ? "#fafafa" : "#e3b500"; // white or blue-grey lighten-1
63+
}
64+
},
65+
activeColor: {
66+
type: String,
67+
default() {
68+
return "#f5c300"; // teal lighten 2
69+
}
70+
}
71+
},
72+
computed: {
73+
isDark() {
74+
return this.dark === true;
75+
},
76+
avatarOn() {
77+
return !!this.avatar;
78+
},
79+
iconOn() {
80+
return !!this.icon;
81+
}
82+
},
83+
methods: {
84+
isActive() {
85+
return this.route().current(this.href);
86+
},
87+
navigate(href) {
88+
let self = this;
89+
/* if valid url */
90+
if (self.isURL(href)) {
91+
// check if link belongs to same domain
92+
if (self.getHostName(href) == window.location.hostname) {
93+
this.$inertia.replace(href);
94+
} else {
95+
window.open(href);
96+
}
97+
} else if (this.routeExists(href)) {
98+
/* when using vue router path */
99+
100+
this.$inertia.visit(this.route(href).url());
101+
} else {
102+
this.$inertia.visit(href);
103+
}
104+
},
105+
routeExists(name) {
106+
try {
107+
route(name);
108+
return true;
109+
} catch (Err) {
110+
return false;
111+
}
112+
},
113+
getHostName(url) {
114+
var match = url.match(/:\/\/(www[0-9]?\.)?(.[^/:]+)/i);
115+
if (
116+
match != null &&
117+
match.length > 2 &&
118+
typeof match[2] === "string" &&
119+
match[2].length > 0
120+
) {
121+
return match[2];
122+
} else {
123+
return null;
124+
}
125+
},
126+
isURL(str) {
127+
var urlRegex =
128+
"^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$";
129+
var url = new RegExp(urlRegex, "i");
130+
return str.length < 2083 && url.test(str);
131+
}
132+
}
133+
};
134+
</script>
135+
136+
<style lang="scss" scoped>
137+
.styleAvatar {
138+
position: relative;
139+
margin-left: -55px;
140+
}
141+
</style>

0 commit comments

Comments
 (0)