- Home
- /
- Design
- /
- DMBBootstrapBuilder
- /
- Button
Button
Html.Button(IActionItem) renders any action — URL, route, JavaScript, modal, clipboard, toggle or dropdown.
ActionItem types
ActionItemFactory provides a factory method for each button behaviour — the button renders differently depending on the type passed.
ActionItem types
Demo modal
Modal opened from a button.
@using DMBBootstrapBuilder
@using DMBPageBuilder
@using (Html.ModalBuilder().Id("ex-btn-demo-modal").WithTitle("Demo modal", TitleLevel.Three, IconStruct.Bootstrap("bi-window")).Begin())
{
@using (Html.PB_P().AsMuted().Begin())
{
@:Modal opened from a button.
}
@using (Html.FooterBuilder().Begin())
{
@Html.Button(ActionItemFactory.DismissModal("Close").SetVariant(VariantStyle.Secondary).SetOutlined())
}
}
@using (Html.FlexBlockBuilder().WithGap(Old_Gap.Gap2).Begin())
{
@Html.Button(ActionItemFactory.Url("Url", "#", IconStruct.Bootstrap("bi-link-45deg")).SetVariant(VariantStyle.Primary)).Render()
@Html.Button(ActionItemFactory.JavaScript("JavaScript", "console.log('js')", IconStruct.Bootstrap("bi-terminal")).SetVariant(VariantStyle.Info)).Render()
@Html.Button(ActionItemFactory.Modal("Modal", "ex-btn-demo-modal", IconStruct.Bootstrap("bi-window")).SetVariant(VariantStyle.Warning)).Render()
@Html.Button(ActionItemFactory.ClipboardButton("Hello world", "Copy", "Copied", IconStruct.Bootstrap("bi-clipboard")).SetVariant(VariantStyle.Success)).Render()
@Html.Button(ActionItemFactory.Toggle("Toggle", true, IconStruct.Bootstrap("bi-toggle-on")).SetVariant(VariantStyle.Danger)).Render()
}Variants & Outlined
SetVariant(VariantStyle) fills the button. SetOutlined() switches to the outline style. Both accept the same set of Bootstrap variants.
Variants & outlined
@using DMBBootstrapBuilder
@using DMBPageBuilder
@using (Html.FlexBlockBuilder().SetFlexColumn().SetAlignItemsStart().WithGap(Old_Gap.Gap2).Begin())
{
@using (Html.FlexBlockBuilder().WithGap(Old_Gap.Gap2).Begin())
{
@Html.Button(ActionItemFactory.Url("Primary", "#").SetVariant(VariantStyle.Primary)).Render()
@Html.Button(ActionItemFactory.Url("Success", "#").SetVariant(VariantStyle.Success)).Render()
@Html.Button(ActionItemFactory.Url("Danger", "#").SetVariant(VariantStyle.Danger)).Render()
}
@using (Html.FlexBlockBuilder().WithGap(Old_Gap.Gap2).Begin())
{
@Html.Button(ActionItemFactory.Url("Primary", "#").SetVariant(VariantStyle.Primary).SetOutlined()).Render()
@Html.Button(ActionItemFactory.Url("Success", "#").SetVariant(VariantStyle.Success).SetOutlined()).Render()
@Html.Button(ActionItemFactory.Url("Danger", "#").SetVariant(VariantStyle.Danger).SetOutlined()).Render()
}
}Sizes, Icon & Badge
SetSize(BoostrapButtonSize) adjusts padding. IconStruct.Bootstrap adds a leading icon. SetBadge(string) appends a count chip. SetDisabled() greys the button out.
Sizes, icon & badge
@using DMBBootstrapBuilder
@using DMBPageBuilder
@using (Html.RowBuilder().Begin())
{
@using (Html.ColBuilder().SetCol(ColSize.Col12).SetCol(ColSize.Col6, ResponsiveBreakpoint.Md).Begin())
{
@using (Html.BlockBuilder().AsSectionSubLabel().Begin())
{
@Html.TitleBuilder().SetTitle("Sizes", TitleLevel.Six).AsSubSectionTitle().Render()
}
@using (Html.FlexBlockBuilder().SetAlignItemsCenter().WithGap(Old_Gap.Gap2).Begin())
{
@Html.Button(ActionItemFactory.Url("Small", "#").SetVariant(VariantStyle.Primary).SetSize(BoostrapButtonSize.Small)).Render()
@Html.Button(ActionItemFactory.Url("Medium", "#").SetVariant(VariantStyle.Primary).SetSize(BoostrapButtonSize.Medium)).Render()
@Html.Button(ActionItemFactory.Url("Large", "#").SetVariant(VariantStyle.Primary).SetSize(BoostrapButtonSize.Large)).Render()
}
}
@using (Html.ColBuilder().SetCol(ColSize.Col12).SetCol(ColSize.Col6, ResponsiveBreakpoint.Md).Begin())
{
@using (Html.BlockBuilder().AsSectionSubLabel().Begin())
{
@Html.TitleBuilder().SetTitle("Icon · Badge · Disabled", TitleLevel.Six).AsSubSectionTitle().Render()
}
@using (Html.FlexBlockBuilder().WithGap(Old_Gap.Gap2).Begin())
{
@Html.Button(ActionItemFactory.Url("Download", "#", IconStruct.Bootstrap("bi-download")).SetVariant(VariantStyle.Primary)).Render()
@Html.Button(ActionItemFactory.Url("Inbox", "#", IconStruct.Bootstrap("bi-inbox")).SetVariant(VariantStyle.Secondary).SetBadge("5")).Render()
@Html.Button(ActionItemFactory.Url("Disabled", "#").SetVariant(VariantStyle.Normal).SetDisabled()).Render()
}
}
}Dropdown
GroupActionItem renders a dropdown menu. Items of any type can be nested, including sub-groups and dividers.
Dropdown
@using DMBBootstrapBuilder
@using DMBPageBuilder
@{
var dropdown = ActionItemFactory.Group("Actions", IconStruct.Bootstrap("bi-list"))
.AddItems(
ActionItemFactory.Url("Open docs", "#", IconStruct.Bootstrap("bi-book")),
ActionItemFactory.JavaScript("Log to console", "console.log('hello')", IconStruct.Bootstrap("bi-terminal")),
ActionItemFactory.ClipboardButton("Copy token", "Copy", "Copied"),
ActionItemFactory.Divider()
);
var subGroup = ActionItemFactory.Group("More", IconStruct.Bootstrap("bi-folder"));
subGroup.AddItems(
ActionItemFactory.Url("Settings", "#", IconStruct.Bootstrap("bi-gear")),
ActionItemFactory.Url("Danger zone", "#", IconStruct.Bootstrap("bi-exclamation-triangle")).SetVariant(VariantStyle.Danger)
);
dropdown.AddItem(subGroup);
}
@using (Html.FlexBlockBuilder().WithGap(Old_Gap.Gap2).Begin())
{
@Html.Button(dropdown.SetVariant(VariantStyle.Primary)).Render()
@Html.Button(ActionItemFactory.Group("Outlined", IconStruct.Bootstrap("bi-list")).SetVariant(VariantStyle.Secondary).SetOutlined()
.AddItems(
ActionItemFactory.Url("Item A", "#"),
ActionItemFactory.Url("Item B", "#")
)).Render()
}Split button
ActionItemFactory.Split(main, dropdown) renders a two-part button — the left side triggers the primary action, the right arrow opens the dropdown.
Split button
@using DMBBootstrapBuilder
@using DMBPageBuilder
@using (Html.FlexBlockBuilder().WithGap(Old_Gap.Gap2).Begin())
{
@Html.Button(ActionItemFactory.Split(
ActionItemFactory.Url("Save", "#", IconStruct.Bootstrap("bi-floppy")),
ActionItemFactory.Url("Save as draft", "#"),
ActionItemFactory.Url("Save and publish", "#")
).WithVariant(VariantStyle.Primary)).Render()
@Html.Button(ActionItemFactory.Split(
ActionItemFactory.Url("Export", "#", IconStruct.Bootstrap("bi-box-arrow-up")),
ActionItemFactory.Url("Export as PDF", "#"),
ActionItemFactory.Url("Export as CSV", "#")
).WithVariant(VariantStyle.Secondary).Outlined()).Render()
}