-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Çağatay Çivici
authored and
Çağatay Çivici
committed
Jun 26, 2018
1 parent
3e0e3bd
commit 460de95
Showing
3 changed files
with
92 additions
and
58 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 |
---|---|---|
@@ -1,39 +1,35 @@ | ||
/** TabMenu **/ | ||
.ui-tabmenu { | ||
|
||
} | ||
|
||
.ui-tabmenu .ui-tabmenu-nav { | ||
.ui-tabmenu .ui-tabmenu-nav { | ||
margin: 0; | ||
padding: .25em .5em 0 .25em; | ||
padding: .25em .5em 0 .25em; | ||
} | ||
|
||
.ui-tabmenu .ui-tabmenu-nav .ui-tabmenuitem { | ||
list-style: none; | ||
float: left; | ||
position: relative; | ||
margin: 0 .2em 1px 0; | ||
padding: 0; | ||
.ui-tabmenu .ui-tabmenu-nav .ui-tabmenuitem { | ||
list-style: none; | ||
float: left; | ||
position: relative; | ||
margin: 0 .2em 1px 0; | ||
padding: 0; | ||
white-space: nowrap; | ||
display: block; | ||
border-bottom: 0; | ||
top: 1px; | ||
top: 1px; | ||
} | ||
|
||
.ui-tabmenu .ui-tabmenu-nav .ui-tabmenuitem a { | ||
float: left; | ||
.ui-tabmenu .ui-tabmenu-nav .ui-tabmenuitem a { | ||
float: left; | ||
padding: 0.5em 1em; | ||
text-decoration: none; | ||
text-decoration: none; | ||
} | ||
|
||
.ui-tabmenu .ui-tabmenu-nav a { | ||
.ui-tabmenu .ui-tabmenu-nav a { | ||
padding: 0.5em 1em; | ||
} | ||
|
||
.ui-tabmenu .ui-tabmenu-nav .ui-tabmenuitem .ui-icon { | ||
float: left; | ||
.ui-tabmenu .ui-menuitem-icon { | ||
margin-right: .25em; | ||
} | ||
|
||
.ui-tabmenu .ui-tabmenu-nav .ui-tabmenuitem.ui-state-disabled a { | ||
cursor: default; | ||
cursor: default; | ||
} |
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,70 +1,107 @@ | ||
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import {MenuItem} from '../menu/MenuItem' | ||
|
||
export class TabMenu extends Component { | ||
|
||
static defaultProps = { | ||
id: null, | ||
model:null, | ||
activeItem:null, | ||
style:null, | ||
className:null, | ||
model: null, | ||
activeItem: null, | ||
style: null, | ||
className: null | ||
}; | ||
|
||
static propTypes = { | ||
id: PropTypes.string, | ||
model:PropTypes.array, | ||
activeItem:PropTypes.any, | ||
style:PropTypes.any, | ||
className:PropTypes.string, | ||
model: PropTypes.array, | ||
activeItem: PropTypes.any, | ||
style: PropTypes.any, | ||
className: PropTypes.string | ||
}; | ||
|
||
|
||
constructor(props) { | ||
super(props); | ||
this.state ={activeItem:this.props.activeItem || this.props.model[0]}; | ||
this.state = { | ||
activeItem: props.activeItem || props.model ? props.model[0] : null | ||
}; | ||
} | ||
|
||
static getDerivedStateFromProps(nextProps, prevState) { | ||
if(nextProps.activeItem && nextProps.activeItem !== prevState.activeItem) { | ||
return { | ||
activeItem: nextProps.activeItem | ||
}; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
itemClick(event, item) { | ||
if(item.disabled) { | ||
if (item.disabled) { | ||
event.preventDefault(); | ||
return; | ||
} | ||
|
||
if(!item.url) { | ||
if (!item.url) { | ||
event.preventDefault(); | ||
} | ||
|
||
if(item.command) { | ||
if (item.command) { | ||
item.command({ | ||
originalEvent: event, | ||
item: item | ||
}); | ||
} | ||
|
||
this.setState({activeItem:item}); | ||
if(this.props.onChange) { | ||
this.props.onChange({ | ||
originalEvent: event, | ||
value: item | ||
}); | ||
} | ||
|
||
this.setState({activeItem: item}); | ||
} | ||
|
||
render() { | ||
var tabMenuClass=classNames('ui-tabmenu ui-widget ui-widget-content ui-corner-all',this.props.className); | ||
renderMenuItem(item, index) { | ||
const className = classNames('ui-tabmenuitem ui-state-default ui-corner-top', {'ui-state-active': this.state.activeItem === item}); | ||
const iconClassName = classNames(item.icon, 'ui-menuitem-icon'); | ||
const icon = item.icon ? <span className={iconClassName}></span>: null; | ||
|
||
var item=this.props.model && this.props.model.map((item,index)=>{ | ||
var listClass=classNames('ui-tabmenuitem ui-state-default ui-corner-top',{'ui-state-disabled':item.disabled}, | ||
{'ui-tabmenuitem-hasicon':item.icon},{'ui-state-active':this.state.activeItem===item}) | ||
var list=<li className={listClass} key={'tabmenuItem_' + index}> | ||
<MenuItem index={index} items={item} onItemClick={event=>this.itemClick(event,item)}/> | ||
return ( | ||
<li key={item.label + '_' + index} className={className}> | ||
<a href={item.url||'#'} className="ui-menuitem-link ui-corner-all" target={item.target} onClick={(event) => this.itemClick(event, item)}> | ||
{icon} | ||
<span className="ui-menuitem-text">{item.label}</span> | ||
</a> | ||
</li> | ||
return list; | ||
}) | ||
); | ||
} | ||
|
||
renderItems() { | ||
return ( | ||
<div id={this.props.id} className={tabMenuClass} style={this.props.style} ref={el=>this.container=el}> | ||
<ul className="ui-tabmenu-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" role="tablist"> | ||
{item} | ||
</ul> | ||
</div> | ||
this.props.model.map((item, index) => { | ||
return this.renderMenuItem(item, index); | ||
}) | ||
); | ||
} | ||
|
||
render() { | ||
if (this.props.model) { | ||
const className = classNames('ui-tabmenu ui-widget ui-widget-content ui-corner-all', this.props.className); | ||
const items = this.renderItems(); | ||
|
||
return ( | ||
<div id={this.props.id} className={className} style={this.props.style}> | ||
<ul className="ui-tabmenu-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" role="tablist"> | ||
{items} | ||
</ul> | ||
</div> | ||
); | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
} |
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