Skip to content

Commit

Permalink
feat(tabs): Implementation (#138)
Browse files Browse the repository at this point in the history
* feat(tabs): Initial commit

* feat(tabs): Implemented {{nucleus-tabs}}

Basic functionality working

Refractoring some code

* refactor(tabs): calling component attributes through get call

* fix(tabs): Background variant border radius issue

* refractor(tabs): current selected name change

* fix(tabs): no focus on disabled button

* fix(tabs): no focus on disabled button & safari text rendering issue

* feat(tabs): 'beforeChange' handler implementation

* feat(tabs): Adding customClasses prop to tabs

* refractor(tabs): class names changed to follow existing conventions

* refractor(tabs): Added missing empty lines at the end of files

* fix(tabs): documentation issues

* fix(tabs): safari font color on active element

* refractor(tabs): Removed sending attributes in single props object

* feat(tabs): select prop optional

* feat(tabs): disabled as boolean or string

* fix(tabs): focus styling not appearing on click

* fix(tabs): removed vendor prefixes

* fix(tabs): pressed and active hover state styling

* refactor(tabs): Combined attribute bindings, class bindings. Single line if statements wrapped

* refactor(tabs): changeFocusTab function

Co-authored-by: Shibu Lijack <[email protected]>
  • Loading branch information
Vignesh-Manogar-E3433 and shibulijack-fd authored Mar 19, 2020
1 parent 46c07ba commit 598e3e6
Show file tree
Hide file tree
Showing 62 changed files with 1,769 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@nucleus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@freshworks/inline-banner": "^0.5.4",
"@freshworks/modal": "^0.5.4",
"@freshworks/toast-message": "^0.6.4",
"@freshworks/tabs": "^0.1.0",
"ember-cli-autoprefixer": "^0.8.1",
"ember-cli-babel": "^7.11.1",
"ember-cli-htmlbars": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// BEGIN-SNIPPET nucleus-tabs-2.js
import Component from '@ember/component';
import { inject } from '@ember/service';
import { get } from '@ember/object';

export default Component.extend({
flashMessages: inject(),
actions: {
onChange(changedTo) { // changedTo, ChangedFrom, event params accepted
const flashMessages = get(this, 'flashMessages');
flashMessages.info(`Custom action invoked. '${changedTo}' tab selected!`, {
timeout: 1500
});
}
}
});
// END-SNIPPET
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// BEGIN-SNIPPET nucleus-tabs-3.js
import Component from '@ember/component';
import { inject } from '@ember/service';
import RSVP from 'rsvp';
import { get } from '@ember/object';

export default Component.extend({
flashMessages: inject(),
actions: {
beforeChange() { // changedTo, changedFrom, event params accepted
const flashMessages = get(this, 'flashMessages');
flashMessages.info(`Performing asyncronous operation..`, {
timeout: 1500
});
return new RSVP.Promise(function(resolve) {
setTimeout(function () {
resolve();
}, 2000);
});
},
onChange() { // changedTo, ChangedFrom, event params accepted
const flashMessages = get(this, 'flashMessages');
flashMessages.info(`Tab changed.`, {
timeout: 1500
});
}
}
});
// END-SNIPPET
1 change: 1 addition & 0 deletions packages/@nucleus/tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Router.map(function() {
this.route("nucleus-modal");
this.route("nucleus-toast-message");
this.route("nucleus-banner");
this.route("nucleus-tabs");
});

this.route('not-found', { path: '/*path' });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{#docs-demo as |demo|}}
{{#demo.example name="nucleus-tabs-2.hbs" }}
{{#nucleus-tabs
description="site-navigation"
onChange=(action "onChange") as |tabs| }}
{{#tabs.panel name="I want apples" }}
<div>This is apples section</div>
{{/tabs.panel}}
{{#tabs.panel name="I want oranges" }}
<div>This is oranges section</div>
{{/tabs.panel}}
{{#tabs.panel name="I want grapes" }}
<div>This is grapes section</div>
{{/tabs.panel}}
{{/nucleus-tabs}}
{{/demo.example}}

{{demo.snippet "nucleus-tabs-2.hbs"}}
{{demo.snippet "nucleus-tabs-2.js" label="component.js"}}
{{/docs-demo}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{#docs-demo as |demo|}}
{{#demo.example name="nucleus-tabs-3.hbs" }}
{{#nucleus-tabs
description="site-navigation"
select="I want apples"
beforeChange=(action "beforeChange")
onChange=(action "onChange") as |tabs| }}
{{#tabs.panel name="I want apples" }}
<div>This is apples section</div>
{{/tabs.panel}}
{{#tabs.panel name="I want oranges" }}
<div>This is oranges section</div>
{{/tabs.panel}}
{{#tabs.panel name="I want grapes" }}
<div>This is grapes section</div>
{{/tabs.panel}}
{{/nucleus-tabs}}
{{/demo.example}}

{{demo.snippet "nucleus-tabs-3.hbs"}}
{{demo.snippet "nucleus-tabs-3.js" label="component.js"}}
{{/docs-demo}}
1 change: 1 addition & 0 deletions packages/@nucleus/tests/dummy/app/templates/docs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{{nav.item "Inline Banner" "docs.components.nucleus-inline-banner"}}
{{nav.item "Modal" "docs.components.nucleus-modal"}}
{{nav.item "Toast message" "docs.components.nucleus-toast-message"}}
{{nav.item "Tabs" "docs.components.nucleus-tabs"}}
{{/viewer.nav}}

{{#viewer.main}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Tabs

```sh
yarn add @freshworks/tabs
```

Tabs are used to organise content under each section. Tabs are most helpful when there is a lot of content to show in a page. Tabs can help in showing content which are under the same level of hierarchy, under each section inside the same page.

## Usage

#### 1. Categorisation

It's easy for the user to quickly distinguish which tab belongs to which content.

{{#docs-demo as |demo|}}
{{#demo.example name="nucleus-tabs.hbs"}}
{{#nucleus-tabs
customClasses="sample-tab sample-tab-simple"
description="site-navigation"
select="I want apples"
variant="line" as |tabs| }}
{{#tabs.panel name="I want apples" }}
<div>This is apples section</div>
{{/tabs.panel}}
{{#tabs.panel name="I want oranges" }}
<div>This is oranges section</div>
{{/tabs.panel}}
{{#tabs.panel name="I want grapes" }}
<div>This is grapes section</div>
{{/tabs.panel}}
{{/nucleus-tabs}}
{{/demo.example}}
{{demo.snippet 'nucleus-tabs.hbs'}}
{{/docs-demo}}

#### 2. Custom action 'on' changing tab

{{nucleus-tabs/demo-1}}

#### 3. Custom action 'before' changing tab

{{nucleus-tabs/demo-2}}

#### 4. Disabled tab

{{#docs-demo as |demo|}}
{{#demo.example name="nucleus-tabs-4.hbs"}}
{{#nucleus-tabs
description="site-navigation"
variant="line" as |tabs| }}
{{#tabs.panel name="I want apples" }}
<div>This is apples section</div>
{{/tabs.panel}}
{{#tabs.panel name="I want oranges" }}
<div>This is oranges section</div>
{{/tabs.panel}}
{{#tabs.panel name="I want grapes" disabled=true }}
<div>This is grapes section</div>
{{/tabs.panel}}
{{/nucleus-tabs}}
{{/demo.example}}
{{demo.snippet 'nucleus-tabs-4.hbs'}}
{{/docs-demo}}

## Styles

#### 1. Default

{{#docs-demo as |demo|}}
{{#demo.example name="nucleus-tabs-variant1.hbs"}}
{{#nucleus-tabs
description="site-navigation"
select="I want apples"
variant="line" as |tabs| }}
{{#tabs.panel name="I want apples" }}
<div>This is apples section</div>
{{/tabs.panel}}
{{#tabs.panel name="I want oranges" }}
<div>This is oranges section</div>
{{/tabs.panel}}
{{#tabs.panel name="I want grapes" }}
<div>This is grapes section</div>
{{/tabs.panel}}
{{/nucleus-tabs}}
{{/demo.example}}
{{demo.snippet 'nucleus-tabs-variant1.hbs'}}
{{/docs-demo}}



#### 2. With Background
Pass 'variant' property as 'background'.

{{#docs-demo as |demo|}}
{{#demo.example name="nucleus-tabs-variant2.hbs"}}
{{#nucleus-tabs
description="site-navigation"
select="I want apples"
variant="background" as |tabs| }}
{{#tabs.panel name="I want apples" }}
<div>This is apples section</div>
{{/tabs.panel}}
{{#tabs.panel name="I want oranges" }}
<div>This is oranges section</div>
{{/tabs.panel}}
{{#tabs.panel name="I want grapes" }}
<div>This is grapes section</div>
{{/tabs.panel}}
{{/nucleus-tabs}}
{{/demo.example}}
{{demo.snippet 'nucleus-tabs-variant2.hbs'}}
{{/docs-demo}}


## Guidelines

**Do's**

1. Tabs should be placed in a single row over the content

2. Include all interactive states for the tabs


🚫 **Dont's**

1. Dont use tabs for sequential content. Users can navigate to any tab at any time and cannot be expected to do it sequentially.

2. Dont use tabs for content in different levels of hierarchy.

## Accessibility

__role=tablist__

Indicates that the element serves as a container for a set of tabs.

__aria-label=Entertainment__

Provides a label that describes the purpose of the set of tabs.


__role=tab__

Indicates the element serves as a tab control.

__aria-select=true__

Indicates the tab control is activated and its associated panel is displayed.

__aria-select=false__

Indicates the tab control is not active and its associated panel is NOT displayed.

__aria-controls=IDREF__

Refers to the tabpanel element associated with the tab.


__role=tabpanel__

Indicates the element serves as a container for tab panel content.

__aria-labelledby=IDREF__

Refers to the tab element that controls the panel.

{{docs-note}}
8 changes: 8 additions & 0 deletions packages/tabs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.1.0] - 2019-03-06
### Added
- {{nucleus-tabs}} Initial imlpementation.
9 changes: 9 additions & 0 deletions packages/tabs/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2019

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 changes: 22 additions & 0 deletions packages/tabs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@freshworks/tabs
==============================================================================

```
yarn add @freshworks/tabs
```

Tabs are used to organise content under each section.

Scenario
------------------------------------------------------------------------------
Tabs are most helpful when there is a lot of content to show in a page. Tabs can help in showing content which are under the same level of hierarchy, under each section inside the same page.

Guidelines
------------------------------------------------------------------------------
**Do's**
1. Tabs should be placed in a single row over the content
2. Include all interactive states for the tabs


**Dont's**
1. Dont use tabs for sequential content. Users can navigate to any tab at any time and cannot be expected to do it sequentially.
Loading

0 comments on commit 598e3e6

Please sign in to comment.