Skip to content

Commit

Permalink
Initial commit of tab html css and js
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Elliott committed Dec 17, 2019
1 parent a00eabe commit cd90238
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 26 deletions.
28 changes: 25 additions & 3 deletions dist/components/tab-navigation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>NSW Digital Design System - Tab navigation [INCOMPLETE]</title>
<title>NSW Digital Design System - Tab navigation</title>
<meta name="robots" content="noindex" />
<meta name="description" content="">
<meta name="keywords" content="">
Expand All @@ -28,9 +28,31 @@
</head>

<body>
<div class="nsw-wysiwyg-content nsw-container">
<h1>Tab navigation</h1>
<div class="nsw-container">
<div class="nsw-tabs js-tabs">
<ul class="nsw-tabs__list">
<li class="nsw-tabs__list-item">
<a href="#section1" class="nsw-tabs__link">New and existing homes</a>
</li>
<li class="nsw-tabs__list-item">
<a href="#section2" class="nsw-tabs__link">Vacant land</a>
</li>
<li class="nsw-tabs__list-item">
<a href="#section3" class="nsw-tabs__link">Knockdown rebuild</a>
</li>
</ul>
<section id="section1" class="nsw-tabs__content nsw-wysiwyg-content">
<h2>New and existing homes</h2><p>As a first home buyer, you may be eligible for a <a href='https://www.revenue.nsw.gov.au/taxes-duties-levies-royalties/transfer-duty'>transfer duty</a> concession or exemption.</p><ul><li>If your home is valued at less than $650,000, you can apply for a full exemption so that you don’t have to pay transfer duty.</li><li>If the value of your home is between $650,000 and $800,000, you can apply for a concessional rate of transfer duty. The amount you’ll have to pay will be based on the value of your home.</li></ul>
</section>
<section id="section2" class="nsw-tabs__content nsw-wysiwyg-content">
<h2>Vacant land</h2> <p>The FHBAS applies to vacant land on which you plan to build your home.</p><ul> <li>You won’t pay any <a href='https://www.revenue.nsw.gov.au/taxes-duties-levies-royalties/transfer-duty'>transfer duty</a> if your land is valued at less than $350,000.</li><li>For land valued between $350,000 and $450,000, you’ll receive a concessional rate.</li></ul>
</section>
<section id="section3" class="nsw-tabs__content nsw-wysiwyg-content">
<h2>Knockdown rebuild</h2> <p>If you’re like many Sydney homeowners, you wish you had a more spacious and luxurious home. The problem is, you don’t want to give up your prized location!<br/>KnockDown Rebuild by Metricon gives you the best of both worlds.</p><p>You can have a gorgeous, modern home with plenty of space for your family – without giving up the location you love. All you have to do is demolish your existing dwelling and replace it with your dream Metricon home.</p>
</section>
</div>
</div>

<script src="/js/main.js"></script>
<script>window.NSW.initSite()</script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions dist/css/main.css

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,37 @@
<h1>Styleguide</h1>
<h2>Components</h2>
<ul>
<li><a class="navigation-nav-item" href="components/main-navigation/index.html" target="_blank">Main Navigation</a></li>
<li><a class="navigation-nav-item" href="components/in-page-navigation/index.html" target="_blank">In-page Navigation [INCOMPLETE]</a></li>
<li><a class="navigation-nav-item" href="components/accordion/index.html" target="_blank">Accordion</a></li>
<li><a class="navigation-nav-item" href="components/blockquote/index.html" target="_blank">Blockquote</a></li>
<li><a class="navigation-nav-item" href="components/breadcrumbs/index.html" target="_blank">Breadcrumbs</a></li>
<li><a class="navigation-nav-item" href="components/direction-links/index.html" target="_blank">Direction Links</a></li>
<li><a class="navigation-nav-item" href="components/button/index.html" target="_blank">Buttons</a></li>
<li><a class="navigation-nav-item" href="components/hero-banner/index.html" target="_blank">Hero Banner</a></li>
<li><a class="navigation-nav-item" href="components/callout/index.html" target="_blank">Callout</a></li>
<li><a class="navigation-nav-item" href="components/card/index.html" target="_blank">Card</a></li>
<li><a class="navigation-nav-item" href="components/in-page-navigation/index.html" target="_blank">In-page Navigation [INCOMPLETE]</a></li>
<li><a class="navigation-nav-item" href="components/accordion/index.html" target="_blank">Accordion</a></li>
<li><a class="navigation-nav-item" href="components/button/index.html" target="_blank">Buttons</a></li>
<li><a class="navigation-nav-item" href="components/hero-banner/index.html" target="_blank">Hero Banner</a></li>
<li><a class="navigation-nav-item" href="components/direction-links/index.html" target="_blank">Direction Links</a></li>
<li><a class="navigation-nav-item" href="components/main-navigation/index.html" target="_blank">Main Navigation</a></li>
<li><a class="navigation-nav-item" href="components/breadcrumbs/index.html" target="_blank">Breadcrumbs</a></li>
<li><a class="navigation-nav-item" href="components/link-list/index.html" target="_blank">Link list</a></li>
<li><a class="navigation-nav-item" href="components/notification/index.html" target="_blank">Notification</a></li>
<li><a class="navigation-nav-item" href="components/pagination/index.html" target="_blank">Pagination</a></li>
<li><a class="navigation-nav-item" href="components/site-wide-message/index.html" target="_blank">Site wide message [INCOMPLETE]</a></li>
<li><a class="navigation-nav-item" href="components/social-bar/index.html" target="_blank">Social bar</a></li>
<li><a class="navigation-nav-item" href="components/notification/index.html" target="_blank">Notification</a></li>
<li><a class="navigation-nav-item" href="components/side-navigation/index.html" target="_blank">Side navigation [INCOMPLETE]</a></li>
<li><a class="navigation-nav-item" href="components/tab-navigation/index.html" target="_blank">Tab navigation [INCOMPLETE]</a></li>
<li><a class="navigation-nav-item" href="components/social-bar/index.html" target="_blank">Social bar</a></li>
<li><a class="navigation-nav-item" href="components/site-wide-message/index.html" target="_blank">Site wide message [INCOMPLETE]</a></li>
<li><a class="navigation-nav-item" href="components/tab-navigation/index.html" target="_blank">Tab navigation</a></li>
<li><a class="navigation-nav-item" href="components/tags/index.html" target="_blank">Tags</a></li>
</ul>
<h2>Patterns</h2>
<ul>
<li><a class="navigation-nav-item" href="patterns/header/index.html" target="_blank">Global Header</a></li>
<li><a class="navigation-nav-item" href="patterns/footer/index.html" target="_blank">Global Footer</a></li>
<li><a class="navigation-nav-item" href="patterns/header/index.html" target="_blank">Global Header</a></li>
</ul>
<h2>Styles</h2>
<ul>
<li><a class="navigation-nav-item" href="styles/iconography/index.html" target="_blank">Iconography</a></li>
<li><a class="navigation-nav-item" href="styles/forms/index.html" target="_blank">Forms [INCOMPLETE]</a></li>
<li><a class="navigation-nav-item" href="styles/tables/index.html" target="_blank">Tables</a></li>
<li><a class="navigation-nav-item" href="styles/typography/index.html" target="_blank">Typography</a></li>
<li><a class="navigation-nav-item" href="styles/grid/index.html" target="_blank">Grid</a></li>
<li><a class="navigation-nav-item" href="styles/typography/index.html" target="_blank">Typography</a></li>
<li><a class="navigation-nav-item" href="styles/iconography/index.html" target="_blank">Iconography</a></li>
<li><a class="navigation-nav-item" href="styles/tables/index.html" target="_blank">Tables</a></li>
</ul>
<h2>Pages</h2>
<ul>
Expand Down
59 changes: 59 additions & 0 deletions dist/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,60 @@
popupWindow(this.href, 600, 600);
};

function Tabs(element) {
var _this = this;

this.tab = element;
this.tabList = element.querySelector('ul');
this.tabItems = this.tabList.querySelectorAll('li');
this.tabContents = [];
this.selectedTab = null;

this.showHideEvent = function (e) {
return _this.showHide(e);
};
}

Tabs.prototype.init = function init() {
this.setUpDom(); // this.controls()
};

Tabs.prototype.setUpDom = function setUpDom() {
var _this2 = this;

this.tab.classList.add('is-ready');
this.tabList.setAttribute('role', 'tablist');
this.tabItems.forEach(function (item, index) {
var itemElem = item;
var itemLink = item.querySelector('a');

var content = _this2.tab.querySelector(itemLink.hash);

var uID = uniqueId('accordion');
item.classList.toggle('is-selected', index === 0);
itemElem.setAttribute('role', 'presentation');
itemLink.setAttribute('role', 'tab');
itemLink.setAttribute('id', uID);
itemLink.setAttribute('tabindex', '-1');
itemLink.setAttribute('aria-selected', index === 0);
if (index === 0) _this2.selectedTab = itemLink;
content.setAttribute('role', 'tabpanel');
content.setAttribute('role', 'tabpanel');
content.setAttribute('aria-labelledBy', uID);
content.setAttribute('tabindex', '-1');
content.hidden = index !== 0;
});
};

Tabs.prototype.changeTabs = function changeTabs(e) {
var clickedTab = e.currentTarget;
clickedTab.focus();
clickedTab.removeAttrubute('tabindex');
clickedTab.setAttribute('aria-selected', true);
this.selectedTab.removeAttrubute('aria-selected');
this.selectedTab.setAttribute('tabindex', '-1');
};

if (window.NodeList && !NodeList.prototype.forEach) {
NodeList.prototype.forEach = Array.prototype.forEach;
}
Expand Down Expand Up @@ -543,6 +597,7 @@
var closeSearchButton = document.querySelectorAll('.js-close-search');
var responsiveTables = document.querySelectorAll('.js-responsive-table');
var accordions = document.querySelectorAll('.js-accordion');
var tabs = document.querySelectorAll('.js-tabs');
openSearchButton.forEach(function (element) {
new SiteSearch(element).init();
});
Expand All @@ -557,13 +612,17 @@
accordions.forEach(function (element) {
new Accordion(element).init();
});
tabs.forEach(function (element) {
new Tabs(element).init();
});
new ShareThis().init();
}

exports.Accordion = Accordion;
exports.Navigation = Navigation;
exports.ResponsiveTables = ResponsiveTables;
exports.SiteSearch = SiteSearch;
exports.Tabs = Tabs;
exports.initSite = initSite;

Object.defineProperty(exports, '__esModule', { value: true });
Expand Down
17 changes: 14 additions & 3 deletions src/components/tab-navigation/_tab-navigation.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<div class="nsw-wysiwyg-content nsw-container">
<h1>Tab navigation</h1>
</div>
<div class="nsw-tabs js-tabs">
<ul class="nsw-tabs__list">
{{#each tabitems}}
<li class="nsw-tabs__list-item">
<a href="#{{urlHash}}" class="nsw-tabs__link">{{title}}</a>
</li>
{{/each}}
</ul>
{{#each tabitems}}
<section id="{{urlHash}}" class="nsw-tabs__content nsw-wysiwyg-content">
{{{content}}}
</section>
{{/each}}
</div>
63 changes: 63 additions & 0 deletions src/components/tab-navigation/_tab-navigation.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.nsw-tabs{
@include nsw-spacing(margin-top, md);

&__list{
margin: 0;
padding: 0;
list-style: none;
display: flex;
position: relative;

&::after{
content: '';
width: 100%;
height: 2px;
position: absolute;
left: 0;
bottom: 0;
background-color: $light20;
z-index: 0;
}
}

// &__list-item{

// }

&__link{
@include nsw-spacing(padding, sm md);
@include font-stack;
display: block;
position: relative;
text-decoration: none;
color: $dark80;
z-index: 2;

&:hover{
@include nsw-hover;
}

&:focus{
@include nsw-focus;
}

.is-selected &{
@include font-stack('heading');

&::after{
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 4px;
background-color: $nsw-primary-blue;
}
}
}

&__content{
@include nsw-spacing(padding, lg md);
border-bottom: solid 1px $light20;
}
}
7 changes: 5 additions & 2 deletions src/components/tab-navigation/index.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
title: Tab navigation [INCOMPLETE]
title: Tab navigation
model: tab-navigation.json
---
{{>_tab-navigation}}
<div class="nsw-container">
{{>_tab-navigation model}}
</div>
50 changes: 50 additions & 0 deletions src/components/tab-navigation/tab-navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { uniqueId } from '../../global/scripts/helpers/utilities'

function Tabs(element) {
this.tab = element
this.tabList = element.querySelector('ul')
this.tabItems = this.tabList.querySelectorAll('li')
this.tabContents = []
this.selectedTab = null
this.showHideEvent = (e) => this.showHide(e)
}

Tabs.prototype.init = function init() {
this.setUpDom()
// this.controls()
}

Tabs.prototype.setUpDom = function setUpDom() {
this.tab.classList.add('is-ready')
this.tabList.setAttribute('role', 'tablist')
this.tabItems.forEach((item, index) => {
const itemElem = item
const itemLink = item.querySelector('a')
const content = this.tab.querySelector(itemLink.hash)
const uID = uniqueId('accordion')
item.classList.toggle('is-selected', index === 0)
itemElem.setAttribute('role', 'presentation')
itemLink.setAttribute('role', 'tab')
itemLink.setAttribute('id', uID)
itemLink.setAttribute('tabindex', '-1')
itemLink.setAttribute('aria-selected', index === 0)
if (index === 0) this.selectedTab = itemLink
content.setAttribute('role', 'tabpanel')
content.setAttribute('role', 'tabpanel')
content.setAttribute('aria-labelledBy', uID)
content.setAttribute('tabindex', '-1')
content.hidden = index !== 0
})
}

Tabs.prototype.changeTabs = function changeTabs(e) {
const clickedTab = e.currentTarget
clickedTab.focus()
clickedTab.removeAttrubute('tabindex')
clickedTab.setAttribute('aria-selected', true)
this.selectedTab.removeAttrubute('aria-selected')
this.selectedTab.setAttribute('tabindex', '-1')
}


export default Tabs
19 changes: 19 additions & 0 deletions src/components/tab-navigation/tab-navigation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"tabitems": [
{
"title": "New and existing homes",
"urlHash": "section1",
"content": "<h2>New and existing homes</h2><p>As a first home buyer, you may be eligible for a <a href='https://www.revenue.nsw.gov.au/taxes-duties-levies-royalties/transfer-duty'>transfer duty</a> concession or exemption.</p><ul><li>If your home is valued at less than $650,000, you can apply for a full exemption so that you don’t have to pay transfer duty.</li><li>If the value of your home is between $650,000 and $800,000, you can apply for a concessional rate of transfer duty. The amount you’ll have to pay will be based on the value of your home.</li></ul>"
},
{
"title": "Vacant land",
"urlHash": "section2",
"content": "<h2>Vacant land</h2> <p>The FHBAS applies to vacant land on which you plan to build your home.</p><ul> <li>You won’t pay any <a href='https://www.revenue.nsw.gov.au/taxes-duties-levies-royalties/transfer-duty'>transfer duty</a> if your land is valued at less than $350,000.</li><li>For land valued between $350,000 and $450,000, you’ll receive a concessional rate.</li></ul>"
},
{
"title": "Knockdown rebuild",
"urlHash": "section3",
"content": " <h2>Knockdown rebuild</h2> <p>If you’re like many Sydney homeowners, you wish you had a more spacious and luxurious home. The problem is, you don’t want to give up your prized location!<br/>KnockDown Rebuild by Metricon gives you the best of both worlds.</p><p>You can have a gorgeous, modern home with plenty of space for your family – without giving up the location you love. All you have to do is demolish your existing dwelling and replace it with your dream Metricon home.</p>"
}
]
}
8 changes: 7 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Navigation from './components/main-navigation/main-navigation'
import ResponsiveTables from './styles/tables/tables'
import Accordion from './components/accordion/accordion'
import ShareThis from './components/social-bar/social-bar'
import Tabs from './components/tab-navigation/tab-navigation'

if (window.NodeList && !NodeList.prototype.forEach) {
NodeList.prototype.forEach = Array.prototype.forEach
Expand Down Expand Up @@ -30,6 +31,7 @@ function initSite() {
const closeSearchButton = document.querySelectorAll('.js-close-search')
const responsiveTables = document.querySelectorAll('.js-responsive-table')
const accordions = document.querySelectorAll('.js-accordion')
const tabs = document.querySelectorAll('.js-tabs')

openSearchButton.forEach((element) => {
new SiteSearch(element).init()
Expand All @@ -51,9 +53,13 @@ function initSite() {
new Accordion(element).init()
})

tabs.forEach((element) => {
new Tabs(element).init()
})

new ShareThis().init()
}

export {
initSite, SiteSearch, Navigation, ResponsiveTables, Accordion,
initSite, SiteSearch, Navigation, ResponsiveTables, Accordion, Tabs,
}

0 comments on commit cd90238

Please sign in to comment.