Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-51: <bootstrap-split-button> Vue component #42

Merged
merged 13 commits into from
Apr 21, 2022
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<template>
<div class="btn-group bootstrapSplitButton">
<button type="button"
:class="`bootstrapSplitButton__main btn btn-${type} ${buttonClasses}`"
:disabled="options.length === 0"
@click="mainAction">
{{ text ? text : options[0].text }}
</button>
<button type="button"
class="dropdown-toggle dropdown-toggle-split bootstrapSplitButton__dropdownButton btn"
:class="`btn-${type} ${toggleClasses}`"
:disabled="options.length === 0"
:aria-expanded="open.toString()"
@click="open = !open">
<span class="visually-hidden">[[ Toggle Dropdown ]]</span>
</button>
<div v-if="open" class="w-100 h-100 fixed-bottom" style="z-index: auto" @click="open = false"></div>
<ul class="bootstrapSplitButton__dropdownMenu dropdown-menu"
:class="`${dropdownClasses} ${open ? 'show' : ''}`"
:style="`margin-top: ${marginTop}px`">
<li v-for="option in options" :key="option.text" class="bootstrapSplitButton__dropdownMenuItem">
<a v-if="option.text && option.text.trim && option.text.trim().startsWith('---')">
<hr class="dropdown-divider">
</a>
<a v-else :href="option.url" class="dropdown-item">
{{ option.text }}
</a>
</li>
</ul>
</div>
</template>

<script>
export default {
props: {
type: { type: String, default: 'primary' },
text: { default: () => null },
options: { type: Array, required: true }, // { text: String, href: String }[]
buttonClasses: { type: String, default: '' },
toggleClasses: { type: String, default: '' },
dropdownClasses: { type: String, default: '' },
},
data: () => ({
open: false,
marginTop: 0,
}),
methods: {
mainAction() {
window.location.href = this.options[0].url;
},
},
watch: {
open(value) {
if (!value) return;
const shadowOffset = this.type === 'transparent' ? 0 : 8;
this.marginTop =
shadowOffset + this.$el.querySelector('.dropdown-toggle-split').offsetHeight;
},
},
};
</script>
1 change: 1 addition & 0 deletions Lombiq.VueJs/Constants/ResourceNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public static class Components
public const string ContentItemDisplay = "content-item-display";
public const string DateTime = "date-time";
public const string ListFetcher = "list-fetcher";
public const string BootstrapSplitButton = "bootstrap-split-button";
}
}
11 changes: 11 additions & 0 deletions Lombiq.VueJs/Models/UrlAndText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Lombiq.VueJs.Models;

[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class UrlAndText
{
public string Url { get; set; }
public string Text { get; set; }
}