Skip to content

Commit

Permalink
Cleaner dev structure
Browse files Browse the repository at this point in the history
  • Loading branch information
SenChung committed Sep 11, 2024
1 parent bf859b9 commit 38084b9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 64 deletions.
79 changes: 25 additions & 54 deletions src/breadcrumbs/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,31 @@
* Common js module to support DXP Component Service.
*/
module.exports = async function (input, info) {
const getBreadcrumbData = function () {
let breadcrumbHtml = "";
const navData = [
{
link: "#",
linktext: "Home",
},
{
link: "#",
linktext: "Topic 01",
},
{
link: "#",
linktext: "Topic 02",
},
{
link: "#",
linktext: "Topic 03",
},
{
link: "#",
linktext: "Current page",
},
];
const breadcrumbLength = Number(navData.length);

for (const navItems in navData) {
if (Number(navItems) + 1 < breadcrumbLength) {
breadcrumbHtml += `<li class="breadcrumb-item">
<a href="${navData[navItems].link}">
${navData[navItems].linktext}
</a>
</li>`;
} else {
breadcrumbHtml += `<li class="breadcrumb-item active" aria-current="page" data-href="${navData[navItems].link}">
${navData[navItems].linktext}
</li>`;
}
}

return breadcrumbHtml;
};
const itemLength = input.breadcrumbs.length;
const items = input.breadcrumbs
.map(
(item, i) => `
<li class="breadcrumb-item">
${i + 1 < itemLength ? `<a href="${item.link}">` : ""}
${item.linktext}
${i + 1 < itemLength ? `</a>` : ""}
</li>
`
)
.join("");
return `
<div class="container-fluid ${input.colour}">
<div class="container">
<div class="row">
<div class="container-xl">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
${getBreadcrumbData()}
</ol>
</nav>
</div>
</div>
<div class="container-fluid ${input.brandOverride ? input.brandOverride : ""}">
<div class="container">
<div class="row">
<div class="container-xl">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
${items}
</ol>
</nav>
</div>
</div>`;
</div>
</div>
</div>
`;
};
26 changes: 22 additions & 4 deletions src/breadcrumbs/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://localhost:3000/schemas/v1.json#",
"version": "1.0.1",
"version": "1.0.17",
"name": "breadcrumbs",
"displayName": "Breadcrumbs Component",
"description": "QGDS Bootstrap 5 - Breadcrumbs Component",
Expand All @@ -16,11 +16,29 @@
"input": {
"type": "object",
"properties": {
"colour": {
"type": "string"
"brandOverride": {
"title": "brand override",
"type": "string",
"enum": ["", "light", "dark", "alt", "dark-alt"]
},
"breadcrumbs": {
"title": "Breadchrumb items array",
"type": "array",
"items": {
"type": "object",
"properties": {
"link": {
"type": "string"
},
"linktext": {
"type": "string"
}
},
"required": ["link", "linktext"]
}
}
},
"required": []
"required": ["breadcrumbs"]
},
"output": {
"responseType": "html",
Expand Down
28 changes: 27 additions & 1 deletion src/breadcrumbs/previews/example.data.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
{
"colour": " alt"
"brandOverride": "alt",
"breadcrumbs": [
{
"link": "#",
"linktext": "For government"
},
{
"link": "#",
"linktext": "Information and communication technology"
},
{
"link": "#",
"linktext": "Communication and publishing"
},
{
"link": "#",
"linktext": "Website and digital publishing"
},
{
"link": "#",
"linktext": "Website standards, guidelines and templates"
},
{
"link": "#",
"linktext": "Single Website Experience"
}
]
}
5 changes: 0 additions & 5 deletions src/breadcrumbs/previews/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

<head>
[component://static-header]
<!-- <link rel="stylesheet"
href="https://www.forgov.qld.gov.au/__data/assets/git_bridge/0030/498603/assets/css/qld.bootstrap.css">
<link rel="stylesheet"
href="https://www.forgov.qld.gov.au/__data/assets/css_file_folder/0029/499142/QGDS-forgov-shim.css"> -->

</head>

<body>
Expand Down

0 comments on commit 38084b9

Please sign in to comment.