Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from ministryofjustice/component-badge
Add badge component
- Loading branch information
Showing
8 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
{% extends "layouts/base.html" %} | ||
|
||
{% block body %} | ||
|
||
<div class="govuk-grid-row"> | ||
|
||
<div class="govuk-grid-column-full"> | ||
|
||
{{ govukBackLink({ | ||
text: "Back", | ||
href: "../" | ||
}) }} | ||
|
||
<h1 class="govuk-heading-xl"> | ||
<span class="govuk-caption-xl">Components</span> Badge | ||
</h1> | ||
|
||
{%- set colours = [{ | ||
name: 'purple', | ||
hex: '#2e358b', | ||
contrast: '10.51' | ||
}, { | ||
name: 'bright-purple', | ||
hex: '#912b88', | ||
contrast: '7.23' | ||
}, { | ||
name: 'red', | ||
hex: '#b10e1e', | ||
contrast: '7.12' | ||
}, { | ||
name: 'bright-red', | ||
hex: '#df3034', | ||
contrast: '4.56' | ||
}, { | ||
name: 'green', | ||
hex: '#006435', | ||
contrast: '7.31' | ||
}, { | ||
name: 'blue', | ||
hex: '#005ea5', | ||
contrast: '6.68' | ||
}, { | ||
name: 'black', | ||
hex: '#0b0c0c', | ||
contrast: '19.59' | ||
}, { | ||
name: 'grey', | ||
hex: '#6f777b', | ||
contrast: '4.56' | ||
}] -%} | ||
|
||
|
||
<table class="govuk-table"> | ||
<thead class="govuk-table__head"> | ||
<tr class="govuk-table__row"> | ||
<th class="govuk-table__header" scope="col">Class</th> | ||
<th class="govuk-table__header" scope="col">Badge</th> | ||
<th class="govuk-table__header" scope="col">Class (with size modifier)</th> | ||
<th class="govuk-table__header" scope="col">Badge</th> | ||
</tr> | ||
</thead> | ||
<tbody class="govuk-table__body"> | ||
{%- for colour in colours %} | ||
{% set classColour = "moj-badge--" + colour.name %} | ||
{% set classSize = "moj-badge--small" %} | ||
<tr class="govuk-table__row"> | ||
<td class="govuk-table__cell"> | ||
<code>{{ classColour }}</code> | ||
</td> | ||
<td class="govuk-table__cell"> | ||
{{ mojBadge({ | ||
text: "Lorem ipsum " + loop.index, | ||
classes: classColour | ||
}) }} | ||
</td> | ||
<td class="govuk-table__cell"> | ||
<code>{{ classColour }} {{ classSize }}</code> | ||
</td> | ||
<td class="govuk-table__cell"> | ||
{{ mojBadge({ | ||
text: "Lorem ipsum " + loop.index, | ||
classes: classColour + " " + classSize | ||
}) }} | ||
</td> | ||
</tr> | ||
{% endfor -%} | ||
</tbody> | ||
</table> | ||
|
||
<h2 class="govuk-heading-m"> | ||
Other badges | ||
</h2> | ||
|
||
<table class="govuk-table"> | ||
<thead class="govuk-table__head"> | ||
<tr class="govuk-table__row"> | ||
<th class="govuk-table__header" scope="col">Class</th> | ||
<th class="govuk-table__header" scope="col">Badge</th> | ||
<th class="govuk-table__header" scope="col">Class (with size modifier)</th> | ||
<th class="govuk-table__header" scope="col">Badge</th> | ||
</tr> | ||
</thead> | ||
<tbody class="govuk-table__body"> | ||
{%- for status in ["error","warning","success","information"] %} | ||
{% set classColour = "moj-badge--" + status %} | ||
{% set classSize = "moj-badge--small" %} | ||
<tr class="govuk-table__row"> | ||
<td class="govuk-table__cell"> | ||
<code>{{ classColour }}</code> | ||
</td> | ||
<td class="govuk-table__cell"> | ||
{{ mojBadge({ | ||
text: status, | ||
classes: classColour | ||
}) }} | ||
</td> | ||
<td class="govuk-table__cell"> | ||
<code>{{ classColour }} {{ classSize }}</code> | ||
</td> | ||
<td class="govuk-table__cell"> | ||
{{ mojBadge({ | ||
text: status, | ||
classes: classColour + " " + classSize | ||
}) }} | ||
</td> | ||
</tr> | ||
{% endfor -%} | ||
</tbody> | ||
</table> | ||
|
||
</div> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Badge | ||
|
||
- [Guidance](https://mojdt-design-system.herokuapp.com/components/badge) | ||
- [Preview](https://mojdt-frontend.herokuapp.com/components/badge) | ||
|
||
## Example | ||
|
||
``` | ||
{{ mojBadge({ | ||
text: "Status text", | ||
classes: "moj-badge--blue" | ||
}) }} | ||
``` | ||
|
||
## Arguments | ||
|
||
This component accepts the following arguments. | ||
|
||
|Name|Type|Required|Description| | ||
|---|---|---|---| | ||
|text|string|Yes|If `html` is set, this is not required. Text to use within the span. If `html` is provided, the `text` argument will be ignored.| | ||
|html|string|Yes|If `text` is set, this is not required. HTML to use within the span. If `html` is provided, the `text` argument will be ignored.| | ||
|classes|string|Yes|Classes to add to the `span` container. See available [classes](#classes).| | ||
|label|string|No|The `aria-label` to add to the `span` container.| | ||
|attributes|object|No|HTML attributes (for example data attributes) to add to the `span` container.| | ||
|
||
### Classes | ||
|
||
|Name|Colour code|Colour contrast| | ||
|---|---|---| | ||
|moj-badge--purple|#2e358b|Pass| | ||
|moj-badge--light-purple|#6f72af|Fail| | ||
|moj-badge--bright-purple|#912b88|Pass| | ||
|moj-badge--pink|#d53880|Fail| | ||
|moj-badge--light-pink|#f499be|Fail| | ||
|moj-badge--red|#b10e1e|Pass| | ||
|moj-badge--bright-red|#df3034|Pass| | ||
|moj-badge--orange|#f47738|Fail| | ||
|moj-badge--brown|#b58840|Fail| | ||
|moj-badge--yellow|#ffbf47|Fail| | ||
|moj-badge--light-green|#85994b|Fail| | ||
|moj-badge--green|#006435|Pass| | ||
|moj-badge--turquoise|#28a197|Fail| | ||
|moj-badge--light-blue|#2b8cc4|Fail| | ||
|moj-badge--blue|#005ea5|Pass| | ||
|moj-badge--black|#0b0c0c|Pass| | ||
|moj-badge--grey-1|#6f777b|Pass| | ||
|moj-badge--grey-2|#bfc1c3|Fail| | ||
|moj-badge--grey-3|#dee0e2|Fail| | ||
|moj-badge--grey-4|#f8f8f8|Fail| | ||
|moj-badge--white|#ffffff|Fail| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* ========================================================================== | ||
#BADGE | ||
========================================================================== */ | ||
|
||
.moj-badge { | ||
@include govuk-font($size: 16, $weight: "bold"); | ||
display: inline-block; | ||
border: 2px solid govuk-colour("blue"); | ||
color: govuk-colour("blue"); | ||
text-transform: uppercase; | ||
vertical-align: middle; | ||
padding: 4px 8px; | ||
padding-bottom: 1px; | ||
outline: 2px solid transparent; | ||
outline-offset: -2px; | ||
|
||
&--purple { | ||
border-color: govuk-colour("purple"); | ||
color: govuk-colour("purple"); | ||
} | ||
|
||
&--bright-purple { | ||
border-color: govuk-colour("bright-purple"); | ||
color: govuk-colour("bright-purple"); | ||
} | ||
|
||
&--red, | ||
&--error { | ||
border-color: govuk-colour("red"); | ||
color: govuk-colour("red"); | ||
} | ||
|
||
&--bright-red, | ||
&--warning { | ||
border-color: govuk-colour("bright-red"); | ||
color: govuk-colour("bright-red"); | ||
} | ||
|
||
&--green, | ||
&--success { | ||
border-color: govuk-colour("green"); | ||
color: govuk-colour("green"); | ||
} | ||
|
||
&--blue, | ||
&--information { | ||
border-color: govuk-colour("blue"); | ||
color: govuk-colour("blue"); | ||
} | ||
|
||
&--black { | ||
border-color: govuk-colour("black"); | ||
color: govuk-colour("black"); | ||
} | ||
|
||
&--grey { | ||
border-color: govuk-colour("grey-1"); | ||
color: govuk-colour("grey-1"); | ||
} | ||
|
||
&--small { | ||
@include govuk-font($size: 14, $weight: "bold"); | ||
padding: 2px 4px 1px 4px; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% macro mojBadge(params) %} | ||
{%- include "./template.njk" -%} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<span class="moj-badge {{- ' ' + params.classes if params.classes }}" {%- if (params.label) %} aria-label=""{% endif -%} {%- for attribute, value in params.attributes -%} {{ attribute }}="{{ value }}"{% endfor %}> | ||
{{- params.html | safe if params.html else params.text -}} | ||
</span> |