import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { NgIf, Icon, EventEmitter, EventReceiver } from './';
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
import './breadcrumb.scss';
export class BreadCrumb extends React.Component {
constructor(props){
super(props);
this.state = {
path: this._formatPath(props.path)
};
}
componentWillReceiveProps(props){
this.setState({path: this._formatPath(props.path)});
}
_formatPath(full_path){
let paths = full_path.split("/");
if(paths.slice(-1)[0] === ''){
paths.pop();
}
paths = paths.map((path, index) => {
let sub_path = paths.slice(0, index+1).join('/'),
label = path === ''? 'Nuage' : path;
if(index === paths.length - 1){
return {full: null, label: label};
}else{
return {full: sub_path+'/', label: label};
}
});
return paths;
}
render(Element) {
const Path = Element? Element : PathElement;
return (
{
this.state.path.map((path, index) => {
return (
);
})
}
);
}
}
BreadCrumb.propTypes = {
path: PropTypes.string.isRequired,
needSaving: PropTypes.bool
}
const BreadCrumbContainer = (props) => {
return (
);
}
const Logout = (props) => {
return (
);
}
const Saving = (props) => {
return (
*
);
}
const Separator = (props) => {
return (
);
}
@EventEmitter
export class PathElementWrapper extends React.Component {
constructor(props){
super(props);
}
limitSize(str){
if(str.length > 30){
return str.substring(0,23)+'...';
}
return str;
}
render(){
let className = "component_path-element-wrapper";
if(this.props.highlight) { className += " highlight";}
return (
{this.limitSize(this.props.path.label)}
{this.limitSize(this.props.path.label)}
);
}
}
// just a hack to make it play nicely with react-dnd as it refuses to use our custom component if it's not wrap by something it knows ...
export class PathElement extends PathElementWrapper {
constructor(props){
super(props);
}
render(highlight = false){
let className = "component_path-element";
if(this.props.isLast){
className += " is-last";
}
return (
);
}
}