-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Makes the code example an exported component
Also changed the design to match the one used by the GOV.UK Design System website, so no longer dependent upon the Tabs component.
- Loading branch information
1 parent
0a8af6d
commit 49bb4c5
Showing
22 changed files
with
661 additions
and
134 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,72 @@ | ||
--- | ||
layout: sub-navigation | ||
order: 3 | ||
title: Code example | ||
description: Show users how to use your components | ||
--- | ||
{% from "example/macro.njk" import xGovukExample %} | ||
|
||
{{ xGovukExample({ | ||
idPrefix: "code-example", | ||
previewPath: "/examples/code-example", | ||
codeSamples: [ | ||
{ | ||
label: { | ||
text: "HTML" | ||
}, | ||
content: { | ||
html: getHtmlCode("code-example") | ||
} | ||
}, | ||
{ | ||
label: { | ||
text: "Nunjucks" | ||
}, | ||
content: { | ||
html: getNunjucksCode("code-example") | ||
} | ||
} | ||
] | ||
}) }} | ||
|
||
This component is used in documentation websites (like this one) to show examples and the code behind them. | ||
|
||
|
||
## Nunjucks macro options | ||
|
||
{% from "govuk/components/table/macro.njk" import govukTable %} | ||
{{ govukTable({ | ||
firstCellIsHeader: true, | ||
head: [ | ||
{ text: "Name" }, | ||
{ text: "Type" }, | ||
{ text: "Description" } | ||
], | ||
rows: [ | ||
[ | ||
{ text: "idPrefix" }, | ||
{ text: "string" }, | ||
{ text: "**Required**. A unique ID for the component on the page" } | ||
], | ||
[ | ||
{ text: "previewPath" }, | ||
{ text: "string" }, | ||
{ text: "URL path to a page where the example can be viewed" } | ||
], | ||
[ | ||
{ text: "codeSamples" }, | ||
{ text: "array" }, | ||
{ text: "A list of code samples in different languages" } | ||
], | ||
[ | ||
{ text: "codeSamples.label.text" }, | ||
{ text: "string" }, | ||
{ text: "The text label for the code sample, for example 'HTML'" } | ||
], | ||
[ | ||
{ text: "codeSamples.content.html" }, | ||
{ text: "string" }, | ||
{ text: "The code used in that sample. You may need to escape this, and may wany to apply code formatting styles." } | ||
] | ||
] | ||
}) }} |
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,6 @@ | ||
--- | ||
eleventyExcludeFromCollections: true | ||
layout: example-full-width.njk | ||
title: Code example | ||
--- | ||
<p>This is an <strong>example</strong>.</p> |
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,37 @@ | ||
--- | ||
eleventyExcludeFromCollections: true | ||
layout: example-full-width.njk | ||
title: Code example | ||
--- | ||
{% from "x-govuk/components/example/macro.njk" import xGovukExample %} | ||
|
||
{% set htmlCode %} | ||
<p>This is an <strong>example </strong>. </p> | ||
{% endset %} | ||
{% set nunjucksCode %} | ||
{% raw %}{{ paragraph({ html: "This is an <strong>example </strong>." }) }}{% endraw %} | ||
{% endset %} | ||
|
||
|
||
{{ xGovukExample({ | ||
idPrefix: "my-code", | ||
previewPath: "/examples/code-example-output", | ||
codeSamples: [ | ||
{ | ||
label: { | ||
text: "HTML" | ||
}, | ||
content: { | ||
html: htmlCode | ||
} | ||
}, | ||
{ | ||
label: { | ||
text: "Nunjucks" | ||
}, | ||
content: { | ||
html: nunjucksCode | ||
} | ||
} | ||
] | ||
}) }} |
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
Oops, something went wrong.