-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add base accessible tabs structure including jquery, modernizr, plugi…
…n architecture
- Loading branch information
1 parent
b86d53c
commit 64ab43f
Showing
13 changed files
with
228 additions
and
16 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,9 @@ | ||
module.exports = { | ||
dist: { | ||
dest: "./dist/javascripts/modernizr-custom.js", | ||
options: [ | ||
"setClasses" | ||
], | ||
uglify: true | ||
} | ||
}; |
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,21 @@ | ||
import $ from "jquery"; | ||
|
||
// Load all modules from this directory automatically, see http://stackoverflow.com/a/31770875/486434 | ||
var req = require.context("./", true, /^(.*\.(js$))[^.]*$/igm); | ||
req.keys().forEach(function(key){ | ||
req(key); | ||
}); | ||
|
||
/// Auto plugin loader. | ||
/// Useful for JIT loading of plugins | ||
export default { | ||
findPlugins: function($context) { | ||
// Load any plugins automatically | ||
$("[data-nice-plugin]", $context || $(document)).each((i, el) => { | ||
let $el = $(el), | ||
pluginName = $el.data("nicePlugin"); | ||
// TODO: Convert plugin data-attributes into options object | ||
$el[pluginName](); | ||
}); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,7 +1,63 @@ | ||
/*eslint-env browser */ | ||
import $ from "jquery"; | ||
|
||
const NAME = "tabs"; | ||
|
||
const ClassName = { | ||
Tabs: ".tabs", | ||
Tab: "tabs__tab", | ||
TabActive: "tabs__tab--active", | ||
TabPane: "tabs__pane", | ||
TabPaneActive: "tabs__pane--active" | ||
}; | ||
|
||
class Tab { | ||
|
||
constructor(element: HTMLElement) { | ||
this._element = element; | ||
this._bindEvents(); | ||
this.activate(0); | ||
} | ||
|
||
/// Activates a tab with the given index | ||
/// @param {number} index The index of the tab to activate | ||
activate(index: number) { | ||
// TODO: Look with the closest Tabs collection | ||
$(`.${ClassName.Tab}`) | ||
.removeClass(ClassName.TabActive) | ||
.find("a") | ||
.attr("aria-expanded", false) | ||
.end() | ||
.eq(index) | ||
.addClass(ClassName.TabActive) | ||
.find("a") | ||
.attr("aria-expanded", true); | ||
|
||
$(`.${ClassName.TabPane}`) | ||
.removeClass(ClassName.TabPaneActive) | ||
.eq(index) | ||
.addClass(ClassName.TabPaneActive); | ||
} | ||
|
||
// PRIVATE | ||
|
||
_bindEvents() { | ||
$(this._element).on("click", `.${ClassName.Tab} a`, e => { | ||
var index = $(e.currentTarget).parent().index(); | ||
this.activate(index); | ||
e.preventDefault(); | ||
}); | ||
} | ||
|
||
static _jQueryInterface(config: mixed) { | ||
return this.each(() => new Tab(this[0])); | ||
} | ||
} | ||
|
||
$.fn[NAME] = Tab._jQueryInterface; | ||
|
||
/** | ||
* @module A test module | ||
* Tabs | ||
*/ | ||
module.exports = (): void => { | ||
return "This is from the tabs module"; | ||
}; | ||
export default Tab; |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
//// | ||
/// @group components | ||
//// | ||
|
||
.breadcrumbs { | ||
list-style: none; | ||
padding: scut-em(12 0); | ||
|
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//// | ||
/// @group components | ||
//// | ||
|
||
.btn { | ||
@include remove-mz-focus-inner; | ||
|
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,56 @@ | ||
//// | ||
/// @group components | ||
//// | ||
|
||
/// Tabbed navigational structure | ||
.tabs { | ||
|
||
/// The list of tabs | ||
&__list { | ||
list-style: none; | ||
margin: 0; | ||
overflow: hidden; | ||
padding: 0; | ||
} | ||
|
||
/// | ||
&__tab { | ||
float: left; | ||
|
||
a { | ||
display: block; | ||
line-height: 4rem; | ||
margin: 0; | ||
padding: 0 1rem; | ||
} | ||
|
||
&--active { | ||
background: get-colour(grey, light); | ||
} | ||
|
||
a { | ||
&:hover { | ||
background: get-colour(grey); | ||
} | ||
} | ||
} | ||
|
||
/// The tab content containing the tab panels | ||
&__content { | ||
background: get-colour(grey, light); | ||
padding: 1rem; | ||
} | ||
|
||
/// An individual tab content pane | ||
&__pane { | ||
|
||
// Assume tabs will stack if no JS is available | ||
.js & { | ||
display: none; | ||
|
||
&--active { | ||
display: block; | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
import test from "departments"; | ||
import tabs from "tabs"; | ||
//import tab from "tabs"; | ||
import $ from "jquery"; | ||
import pluginAutoLoader from "plugin-autoloader"; | ||
|
||
console.log("tabs", tabs); | ||
$().ready(function() { | ||
|
||
console.log("test", test); | ||
|
||
function sum(a: number, b: number): number { | ||
return a + b; | ||
} | ||
|
||
sum(1, 2); | ||
// Load any plugins automatically | ||
pluginAutoLoader.findPlugins(); | ||
}); |
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,56 @@ | ||
{% extends "./_style-guide-layout.njk" %} | ||
{% set title = "Tabs" %} | ||
|
||
{% block main %} | ||
|
||
<h1>Tabs</h1> | ||
|
||
<nav> | ||
<ul> | ||
<li><a href="#basics">Basics</a></li> | ||
</ul> | ||
</nav> | ||
|
||
<section id="basics"> | ||
<h2>Basics</h2> | ||
|
||
{% example -%} | ||
<div class="tabs" data-nice-plugin="tabs"> | ||
<nav> | ||
<ul class="tabs__list" role="tablist"> | ||
<li class="tabs__tab tabs__tab--active" role="presentation"> | ||
<a id="tab-1" href="#tab-1-content" role="tab" aria-controls="tab-1-content" aria-expanded="false"> | ||
Tab 1 | ||
</a> | ||
</li> | ||
<li class="tabs__tab" role="presentation"> | ||
<a id="tab-2" href="#tab-2-content" role="tab" aria-controls="tab-2-content" aria-expanded="false"> | ||
Tab 2 | ||
</a> | ||
</li> | ||
<li class="tabs__tab" role="presentation"> | ||
<a id="tab-3" href="#tab-3-content" role="tab" aria-controls="tab-3-content" aria-expanded="false"> | ||
Tab 3 | ||
</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
<div class="tabs__content"> | ||
<div id="tab-1-content" class="tabs__pane tabs__pane--active" role="tabpanel" aria-labelledby="tab1"> | ||
<h2>First tab</h2> | ||
<p>This is the content for tab 1</p> | ||
</div> | ||
<div id="tab-2-content" class="tabs__pane" role="tabpanel" aria-labelledby="tab2"> | ||
<h2>Second tab</h2> | ||
<p>This is the content for tab 2</p> | ||
</div> | ||
<div id="tab-3-content" class="tabs__pane" role="tabpanel" aria-labelledby="tab3"> | ||
<h2>Third tab</h2> | ||
<p>This is the content for tab 3</p> | ||
</div> | ||
</div> | ||
</div> | ||
{%- endexample %} | ||
</section> | ||
|
||
{% endblock %} |