PluralKit/docs/content/.vuepress/components/Cmd.vue

90 lines
2.5 KiB
Vue
Raw Normal View History

2020-06-10 18:11:28 +02:00
<template>
2020-06-12 15:18:51 +02:00
<div v-bind:class="{ cmd: true, 'cmd-block': inline === undefined, 'cmd-inline': inline !== undefined }">
<div class="comment" v-if="comment">// {{ comment }}</div>
<span class="prefix">pk;</span><slot v-if="usage === undefined"/><span v-if="usage !== undefined">
2020-06-12 12:47:44 +02:00
<span v-for="part in parse(usage)">
<span v-if="part.type === 'str'">{{ part.str }}</span>
<span v-else-if="part.type === 'arg'"><Arg>{{ part.arg }}</Arg></span>
</span>
</span>
2020-06-12 15:18:51 +02:00
</div>
2020-06-10 18:11:28 +02:00
</template>
<style lang="stylus">
2020-06-12 15:18:51 +02:00
.cmd {
// Universal command styles (text)
line-height: 1.7;
color: $cmdColor;
.comment {
font-weight: bold;
color: $accentColor;
}
.prefix {
font-weight: bold;
color: $accentColor;
}
}
.cmd-block {
// Base block command styles (also see CmdGroup)
background-color: $cmdBgBlock;
2020-06-10 18:11:28 +02:00
border-radius: 6px;
2020-06-12 15:18:51 +02:00
margin: 0.5rem 0;
2020-06-10 18:11:28 +02:00
padding: 0.75rem 1.25rem;
2020-06-11 00:48:43 +02:00
}
2020-06-12 15:18:51 +02:00
.details > .cmd-block {
margin-top: 1rem;
2020-06-10 18:11:28 +02:00
}
2020-06-12 15:18:51 +02:00
.cmd-group .cmd-block {
// Disable most parameters above for grouped commands
// (they'll get added back by CmdGroup below)
background-color: transparent;
padding: 0.1rem 1.25rem;
2020-06-10 18:11:28 +02:00
}
2020-06-12 15:18:51 +02:00
.cmd-inline {
display: inline-block;
color: $textColor;
background-color: $cmdBgInline;
border-radius: 3px;
padding: 0 0.7rem;
margin: 0 0.1rem;
}
.tip .cmd-inline {
background-color: $cmdBgInlineTip;
}
</style>
<script>
export default {
2020-06-12 15:18:51 +02:00
props: ["usage", "comment", "inline"],
2020-06-12 12:47:44 +02:00
methods: {
parse(usage) {
const parts = [];
let lastMatch = 0;
2020-06-12 15:32:30 +02:00
// matchAll isn't common yet, using exec :(
const re = /`([^`]+)`/g;
let match;
while (match = re.exec(usage)) {
2020-06-12 12:47:44 +02:00
if (match.index > 0)
parts.push({type: "str", str: usage.substring(lastMatch, match.index)});
parts.push({type: "arg", arg: match[1]});
lastMatch = match.index + match[0].length;
}
if (lastMatch < usage.length)
parts.push({type: "str", str: usage.substring(lastMatch)});
return parts;
}
}
}
</script>