Skip to content

Commit 2c2ff8d

Browse files
committed
Add SVG icon Vue component
1 parent db2bcf0 commit 2c2ff8d

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

web_src/js/components/ContextPopup.vue

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div v-if="loading" class="ui active centered inline loader"/>
44
<div v-if="!loading && issue !== null">
55
<p><small>{{ issue.repository.full_name }} on {{ createdAt }}</small></p>
6-
<p><span :class="color" v-html="icon" /> <strong>{{ issue.title }}</strong> #{{ issue.number }}</p>
6+
<p><svg-icon :name="icon" :class="[color]" /> <strong>{{ issue.title }}</strong> #{{ issue.number }}</p>
77
<p>{{ body }}</p>
88
<div>
99
<div
@@ -20,12 +20,17 @@
2020
</template>
2121

2222
<script>
23-
import {svg} from '../svg.js';
23+
import {SvgIcon} from '../svg.js';
24+
2425
const {AppSubUrl} = window.config;
2526
2627
export default {
2728
name: 'ContextPopup',
2829
30+
components: {
31+
SvgIcon,
32+
},
33+
2934
data: () => ({
3035
loading: false,
3136
issue: null
@@ -49,15 +54,15 @@ export default {
4954
icon() {
5055
if (this.issue.pull_request !== null) {
5156
if (this.issue.state === 'open') {
52-
return svg('octicon-git-pull-request'); // Open PR
57+
return 'octicon-git-pull-request'; // Open PR
5358
} else if (this.issue.pull_request.merged === true) {
54-
return svg('octicon-git-merge'); // Merged PR
59+
return 'octicon-git-merge'; // Merged PR
5560
}
56-
return svg('octicon-git-pull-request'); // Closed PR
61+
return 'octicon-git-pull-request'; // Closed PR
5762
} else if (this.issue.state === 'open') {
58-
return svg('octicon-issue-opened'); // Open Issue
63+
return 'octicon-issue-opened'; // Open Issue
5964
}
60-
return svg('octicon-issue-closed'); // Closed Issue
65+
return 'octicon-issue-closed'; // Closed Issue
6166
},
6267
6368
color() {

web_src/js/svg.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import octiconRepo from '../../public/img/svg/octicon-repo.svg';
1414
import octiconRepoForked from '../../public/img/svg/octicon-repo-forked.svg';
1515
import octiconRepoTemplate from '../../public/img/svg/octicon-repo-template.svg';
1616

17+
import Vue from 'vue';
18+
1719
export const svgs = {
1820
'octicon-chevron-down': octiconChevronDown,
1921
'octicon-chevron-right': octiconChevronRight,
@@ -47,3 +49,19 @@ export function svg(name, size = 16, className = '') {
4749
if (className) svgNode.classList.add(...className.split(/\s+/));
4850
return serializer.serializeToString(svgNode);
4951
}
52+
53+
export const SvgIcon = Vue.component('SvgIcon', {
54+
props: {
55+
name: {type: String, required: true},
56+
size: {type: Number, default: 16},
57+
className: {type: String, default: ''},
58+
},
59+
60+
computed: {
61+
svg() {
62+
return svg(this.name, this.size, this.className);
63+
},
64+
},
65+
66+
template: `<span v-html="svg" />`
67+
});

0 commit comments

Comments
 (0)