Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tab): introduce fixed variant #4431

Merged
merged 6 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
}
}

.component-example__live,
.demo--container {
.bx--tabs--fixed + div {
width: 100%;
height: 320px;
background-color: $ui-01;
}
}

.page-header + div > .bx--tabs {
background-color: $field-01;

Expand Down
99 changes: 99 additions & 0 deletions packages/components/src/components/tabs/_tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@
outline: none;
}

.#{$prefix}--tabs--fixed {
@include carbon--breakpoint(md) {
// Draws the border without affecting the inner-content
box-shadow: inset 0 -1px 0 0 $ui-04;
}
}

.#{$prefix}--tabs__nav {
@include layer('overlay');
margin: 0;
Expand Down Expand Up @@ -153,6 +160,28 @@
}
}

.#{$prefix}--tabs--fixed .#{$prefix}--tabs__nav-item {
@include carbon--breakpoint(md) {
background-color: $ui-03;

& + .#{$prefix}--tabs__nav-item {
margin-left: 0;
border-left: solid $ui-04 1px;
}
}
}

.#{$prefix}--tabs--fixed .#{$prefix}--tabs__nav-item,
.#{$prefix}--tabs--fixed
.#{$prefix}--tabs__nav-item:hover:not(.#{$prefix}--tabs__nav-item--selected) {
@include carbon--breakpoint(md) {
// Reveals the border of `<div class="bx--tabs bx--tabs--fixed">` with transparent border
border-bottom: solid transparent 1px;
// Prevents background color from affecting the transparent border
background-clip: content-box;
}
}

.#{$prefix}--tabs__nav-item .#{$prefix}--tabs__nav-link {
transition: color $duration--fast-01 motion(standard, productive),
border-bottom-color $duration--fast-01 motion(standard, productive),
Expand All @@ -178,6 +207,13 @@
}
}

.#{$prefix}--tabs--fixed
.#{$prefix}--tabs__nav-item:hover:not(.#{$prefix}--tabs__nav-item--disabled) {
@include carbon--breakpoint(md) {
background-color: $hover-ui;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is the token the spec has, but for some reason the color it's receiving is #e5e5e5 instead of #cacaca, so the hover color is lighter and it should be darker. Not sure why the color doesn't match the token though. Is this the right token? @aagonzales
Screen Shot 2019-10-23 at 11 31 41 AM

Copy link
Member

@aagonzales aagonzales Oct 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, it will need to use a different token. Use$hover-selected-ui (even though its not "selected" it gets it the correct color) 🤷‍♀

}
}

//---------------------------------------------
// Item Disabled
//---------------------------------------------
Expand All @@ -191,6 +227,23 @@
pointer-events: none;
}

.#{$prefix}--tabs--fixed
.#{$prefix}--tabs__nav-item.#{$prefix}--tabs__nav-item--disabled,
.#{$prefix}--tabs--fixed
.#{$prefix}--tabs__nav-item.#{$prefix}--tabs__nav-item--disabled:hover {
@include carbon--breakpoint(md) {
background-color: $disabled-02;
}
}

.#{$prefix}--tabs--fixed
.#{$prefix}--tabs__nav-item--disabled
.#{$prefix}--tabs__nav-link {
@include carbon--breakpoint(md) {
color: $disabled-03;
}
}

//-----------------------------
// Item Selected
//-----------------------------
Expand All @@ -215,6 +268,26 @@
}
}

.#{$prefix}--tabs--fixed
.#{$prefix}--tabs__nav-item--selected:not(.#{$prefix}--tabs__nav-item--disabled),
.#{$prefix}--tabs--fixed
.#{$prefix}--tabs__nav-item--selected:hover:not(.#{$prefix}--tabs__nav-item--disabled) {
@include carbon--breakpoint(md) {
background-color: $ui-01;

.#{$prefix}--tabs__nav-link {
// Draws the border without affecting the inner-content
box-shadow: inset 0 3px 0 0 $interactive-04;
border-bottom: none;
}

.#{$prefix}--tabs__nav-link:focus,
.#{$prefix}--tabs__nav-link:active {
box-shadow: none;
}
}
}

//-----------------------------
// Link
//-----------------------------
Expand Down Expand Up @@ -260,6 +333,16 @@
}
}

.#{$prefix}--tabs--fixed a.#{$prefix}--tabs__nav-link {
@include carbon--breakpoint(md) {
display: flex;
align-items: center;
// Prevents this elements from interfering the bottom border of `<div class="bx--tabs bx--tabs--fixed">`
margin-bottom: -1px;
border-bottom: none;
}
}

//-----------------------------
// Link Hover
//-----------------------------
Expand All @@ -272,6 +355,14 @@
}
}

.#{$prefix}--tabs--fixed
.#{$prefix}--tabs__nav-item:hover:not(.#{$prefix}--tabs__nav-item--selected):not(.#{$prefix}--tabs__nav-item--disabled)
.#{$prefix}--tabs__nav-link {
@include carbon--breakpoint(md) {
border-bottom: none;
}
}

//-----------------------------
// Link Disabled
//-----------------------------
Expand All @@ -291,6 +382,14 @@
border-bottom: $tab-underline-disabled;
}

.#{$prefix}--tabs--fixed
.#{$prefix}--tabs__nav-item--disabled
.#{$prefix}--tabs__nav-link {
@include carbon--breakpoint(md) {
border-bottom: none;
}
}

//-----------------------------
// Link Focus
//-----------------------------
Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/components/tabs/tabs.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,13 @@ module.exports = {
items,
},
},
{
name: 'fixed',
label: 'Tabs (fixed)',
context: {
fixed: true,
items,
},
},
],
};
2 changes: 1 addition & 1 deletion packages/components/src/components/tabs/tabs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
LICENSE file in the root directory of this source tree.
-->

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may need unique IDs for the examples otherwise the tabs will control the content for all examples

<div data-tabs class="{{@root.prefix}}--tabs">
<div data-tabs class="{{@root.prefix}}--tabs{{#if fixed}} {{@root.prefix}}--tabs--fixed{{/if}}">
<div class="{{@root.prefix}}--tabs-trigger" tabindex="0">
<a href="javascript:void(0)" class="{{@root.prefix}}--tabs-trigger-text" tabindex="-1"></a>
{{ carbon-icon 'ChevronDownGlyph' }}
Expand Down
14 changes: 13 additions & 1 deletion packages/react/src/components/Tabs/Tabs-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@ import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';

import { withKnobs, boolean, number, text } from '@storybook/addon-knobs';
import {
withKnobs,
boolean,
number,
select,
text,
} from '@storybook/addon-knobs';
import Tabs from '../Tabs';
import Tab from '../Tab';
import TabsSkeleton from '../Tabs/Tabs.Skeleton';

const types = {
'Default (default)': 'default',
'Fixed (fixed)': 'fixed',
};

const props = {
tabs: () => ({
className: 'some-class',
Expand All @@ -23,6 +34,7 @@ const props = {
'#'
),
role: text('ARIA role (role in <Tabs>)', 'navigation'),
type: select('Tabs type (type)', types, 'default'),
iconDescription: text(
'The description of the trigger icon for narrow mode (iconDescription in <Tabs>)',
'show menu options'
Expand Down
14 changes: 14 additions & 0 deletions packages/react/src/components/Tabs/Tabs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ describe('Tabs', () => {
.hasClass(`${prefix}--tabs`)
).toBe(true);
});

it('supports fixed variant', () => {
expect(
shallow(
<Tabs className="extra-class" type="fixed">
<Tab label="firstTab">content1</Tab>
<Tab label="lastTab">content2</Tab>
</Tabs>
)
.find('div')
.first()
.hasClass(`${prefix}--tabs--fixed`)
).toBe(true);
});
});

describe('Trigger (<div>)', () => {
Expand Down
11 changes: 10 additions & 1 deletion packages/react/src/components/Tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export default class Tabs extends React.Component {
*/
role: PropTypes.string.isRequired,

/**
* Provide the type of Tab
*/
type: PropTypes.oneOf(['default', 'fixed']),

/**
* Optionally provide an `onClick` handler that is invoked when a <Tab> is
* clicked
Expand Down Expand Up @@ -87,6 +92,7 @@ export default class Tabs extends React.Component {
static defaultProps = {
iconDescription: 'show menu options',
role: 'navigation',
type: 'default',
triggerHref: '#',
selected: 0,
ariaLabel: 'listbox',
Expand Down Expand Up @@ -191,6 +197,7 @@ export default class Tabs extends React.Component {
className,
triggerHref,
role,
type,
onSelectionChange,
tabContentClassName,
...other
Expand Down Expand Up @@ -241,7 +248,9 @@ export default class Tabs extends React.Component {
});

const classes = {
tabs: classNames(`${prefix}--tabs`, className),
tabs: classNames(`${prefix}--tabs`, className, {
[`${prefix}--tabs--fixed`]: type === 'fixed',
}),
tablist: classNames(`${prefix}--tabs__nav`, {
[`${prefix}--tabs__nav--hidden`]: this.state.dropdownHidden,
}),
Expand Down