diff --git a/docs/examples/button-menu/index.njk b/docs/examples/button-menu/index.njk index e2f7f702..1119c792 100644 --- a/docs/examples/button-menu/index.njk +++ b/docs/examples/button-menu/index.njk @@ -6,8 +6,56 @@ figma_link: https://www.figma.com/file/N2xqOFkyehXwcD9DxU1gEq/MoJ-Figma-Kit?type --- {%- from "moj/components/button-menu/macro.njk" import mojButtonMenu -%} +{%- from "govuk/components/button/macro.njk" import govukButton %} + +

Single button

+{{ mojButtonMenu({ + items: [{ + text: "Primary action", + href: "#" + }] +}) }} + +

Default

+{{ mojButtonMenu({ + items: [{ + text: "Primary action", + href: "#" + }, { + text: "Second action", + href: "#" + }, { + text: "Third action", + href: "#" + }] +}) }} + +

Secondary button

+{{ mojButtonMenu({ + button: { + text: "Print options", + classes: "govuk-button--secondary" + }, + items: [{ + text: "Primary action", + href: "#" + }, { + text: "Second action", + href: "#" + }, { + text: "Third action", + href: "#" + }] +}) }} + +

Right aligned

{{ mojButtonMenu({ + button: { + text: "Print options", + classes: "govuk-button--secondary" + }, + alignMenu: "right", items: [{ text: "Primary action", href: "#" @@ -19,3 +67,27 @@ figma_link: https://www.figma.com/file/N2xqOFkyehXwcD9DxU1gEq/MoJ-Figma-Kit?type href: "#" }] }) }} + + +

Button group

+
+ {{ govukButton({ + text: "Primary action" + })}} + {{ mojButtonMenu({ + button: { + text: "Print options", + classes: "govuk-button--secondary" + }, + items: [{ + text: "Action", + href: "#" + }, { + text: "Second action", + href: "#" + }, { + text: "Third action", + href: "#" + }] +}) }} +
diff --git a/src/moj/components/button-menu/_button-menu.scss b/src/moj/components/button-menu/_button-menu.scss index 7f991ce6..722a0a47 100644 --- a/src/moj/components/button-menu/_button-menu.scss +++ b/src/moj/components/button-menu/_button-menu.scss @@ -84,6 +84,27 @@ } } +.govuk-button-group { + $horizontal-gap: govuk-spacing(3); + $vertical-gap: govuk-spacing(3); + $button-shadow-size: $govuk-border-width-form-element; + + .moj-button-menu { + margin-bottom: $vertical-gap + $button-shadow-size; + } + + .moj-button-menu .moj-button-menu__toggle-button { + margin-bottom: 0; + margin-right: 0; + vertical-align: baseline + } + + @include govuk-media-query($from: tablet) { + .moj-button-menu { + margin-right: $horizontal-gap; + } + } +} diff --git a/src/moj/components/button-menu/button-menu.js b/src/moj/components/button-menu/button-menu.js index 5c5d7976..917bab8a 100644 --- a/src/moj/components/button-menu/button-menu.js +++ b/src/moj/components/button-menu/button-menu.js @@ -13,7 +13,8 @@ MOJFrontend.ButtonMenu = function($module, config) { const defaults = { buttonText: "Actions", - alignMenu: "left" + alignMenu: "left", + buttonClasses: "" } // data attributes override JS config, which overrides defaults @@ -27,10 +28,12 @@ MOJFrontend.ButtonMenu = function($module, config) { } MOJFrontend.ButtonMenu.prototype.init = function() { - if (this.$module.childNodes.length == 1) { - + if (this.$module.children.length == 1) { + if(this.config.buttonClasses) { + this.$module.children[0].classList.add(...this.config.buttonClasses.split(" ")) + } } - if (this.$module.childNodes.length > 1) { + if (this.$module.children.length > 1) { this.initMenu() } } diff --git a/src/moj/components/button-menu/template.njk b/src/moj/components/button-menu/template.njk index 972c9486..4ca250b3 100644 --- a/src/moj/components/button-menu/template.njk +++ b/src/moj/components/button-menu/template.njk @@ -3,6 +3,7 @@ {#- Set classes for this component #} {%- set classNames = "moj-button-menu" -%} +{%- set itemClassNames = "moj-button-menu__item govuk-button--secondary" %} {%- if params.classes %} {% set classNames = classNames + " " + params.classes %} @@ -24,9 +25,12 @@
{%- for item in params.items %} - {{ govukButton({ + {%- if item.classes %} + {% set itemClassNames = fitemClassNames + " " + item.classes %} + {% endif %} + {{ govukButton({ element: item.element, - classes: 'moj-button-menu__item ' + (item.classes if item.classes), + classes: itemClassNames, text: item.text, html: item.html, name: item.name,