1- import React from 'react'
1+ import React , { Component } from 'react'
2+ import PropTypes from 'prop-types'
23import { observer , inject } from 'mobx-react'
34import config from 'config'
45import icons from 'file-icons-js'
56
7+ class BreadcrumbsContainer extends Component {
8+ componentDidUpdate ( ) {
9+ this . refs . breadcrumbs . scrollLeft = this . refs . breadcrumbs . offsetWidth // 滑动条默认保持靠右
10+ }
11+
12+ render ( ) {
13+ const { crumbs } = this . props
14+ return (
15+ < div className = 'breadcrumbs' ref = 'breadcrumbs' >
16+ { crumbs . map ( crumb => (
17+ < Crumb node = { crumb } key = { crumb . path } />
18+ ) ) }
19+ </ div >
20+ )
21+ }
22+ }
23+
24+ BreadcrumbsContainer . propTypes = {
25+ crumbs : PropTypes . array
26+ }
27+
628let Breadcrumbs = observer ( ( { fileNode } ) => {
729 const pathComps = fileNode . path . split ( '/' )
830 let rootName = config . workspaceName || config . projectName || 'Home'
931 if ( config . isDefault ) {
1032 rootName = 'Home'
1133 }
12- const rootCrumb = { path : '/' , name : rootName , isDir : true }
13- const crumbs = pathComps . map ( ( pathComp , idx , pathComps ) => {
34+ const rootCrumb = { path : '/' , name : rootName , isDir : true }
35+ const crumbs = pathComps . map ( ( pathComp , idx , pathComps ) => {
1436 if ( pathComp === '' ) return rootCrumb
1537 return {
1638 name : pathComp ,
17- path : pathComps . slice ( 0 , idx + 1 ) . join ( '/' ) ,
39+ path : pathComps . slice ( 0 , idx + 1 ) . join ( '/' ) ,
1840 gitStatus : fileNode . gitStatus ,
19- isDir : ( idx !== pathComps . length - 1 ) // last pathComp isDir === false
41+ isDir : idx !== pathComps . length - 1 // last pathComp isDir === false
2042 }
2143 } , [ ] )
2244
23- return (
24- < div className = 'breadcrumbs' >
25- { crumbs . map ( crumb => < Crumb node = { crumb } key = { crumb . path } /> ) }
26- </ div >
27- )
45+ return < BreadcrumbsContainer crumbs = { crumbs } />
2846} )
2947
30- Breadcrumbs = inject ( state => {
48+ Breadcrumbs = inject ( ( state ) => {
3149 const activeTab = state . EditorTabState . activeTab
3250 const currentPath = activeTab && activeTab . file ? activeTab . file . path : ''
3351 let fileNode = state . FileTreeState . entities . get ( currentPath )
@@ -36,15 +54,24 @@ Breadcrumbs = inject(state => {
3654} ) ( Breadcrumbs )
3755
3856const SHOW_ICON = true
39- const Crumb = ( { node} ) => {
57+ const Crumb = ( { node } ) => {
4058 const props = { name : node . name }
4159 let fileClassName = 'crumb-node-name'
4260 if ( ! node . isDir ) {
4361 fileClassName = `crumb-node-name git-${ node . gitStatus ? node . gitStatus . toLowerCase ( ) : 'none' } `
4462 }
4563 return (
4664 < div className = 'crumb' >
47- { SHOW_ICON ? < i className = { node . isDir ? 'fa fa-folder-o' : ( icons . getClassWithColor ( node . name ) || 'fa fa-file-text-o' ) } style = { { marginRight :'5px' } } > </ i > :null }
65+ { SHOW_ICON ? (
66+ < i
67+ className = {
68+ node . isDir
69+ ? 'fa fa-folder-o'
70+ : icons . getClassWithColor ( node . name ) || 'fa fa-file-text-o'
71+ }
72+ style = { { marginRight : '5px' } }
73+ />
74+ ) : null }
4875 < div className = { fileClassName } > { node . name } </ div >
4976 < div className = 'crumb-node-name' > { extension `siderBar${ props } ` } </ div >
5077 </ div >
0 commit comments