@@ -9,6 +9,7 @@ import exampleContext from 'docs/app/utils/ExampleContext';
99 */
1010export default class ComponentExample extends Component {
1111 static propTypes = {
12+ children : PropTypes . node ,
1213 description : PropTypes . string ,
1314 examplePath : PropTypes . string . isRequired ,
1415 title : PropTypes . string ,
@@ -17,11 +18,21 @@ export default class ComponentExample extends Component {
1718 state = { showCode : false } ;
1819 fileContents = require ( `!raw!docs/app/Examples/${ this . props . examplePath } ` ) ;
1920 component = exampleContext ( `./${ this . props . examplePath } .js` ) ;
21+ // 'elements/Button/Types/Button' => #Button-Types-Button
22+ anchor = this . props . examplePath . split ( '/' ) . slice ( 1 ) . join ( '-' ) ;
2023
2124 toggleShowCode = ( ) => {
2225 this . setState ( { showCode : ! this . state . showCode } ) ;
2326 } ;
2427
28+ handleMouseEnter = ( ) => {
29+ this . setState ( { showLink : true } ) ;
30+ } ;
31+
32+ handleMouseLeave = ( ) => {
33+ this . setState ( { showLink : false } ) ;
34+ } ;
35+
2536 render ( ) {
2637 const code = (
2738 < Column >
@@ -31,13 +42,28 @@ export default class ComponentExample extends Component {
3142 </ Column >
3243 ) ;
3344
45+ const linkIconStyle = {
46+ display : this . state . showLink ? 'inline-block' : 'none' ,
47+ marginLeft : '0.25em' ,
48+ } ;
49+
50+ const children = < Column > { this . props . children } </ Column > ;
51+
3452 return (
35- < Grid className = 'one column' style = { { marginBottom : '4em' } } >
53+ < Grid className = 'one column' style = { { marginBottom : '4em' } } id = { this . anchor } >
3654 < Column >
3755 < Grid >
3856 < Column width = { 12 } >
39- < h3 className = 'ui header' style = { { marginBottom : 0 } } >
57+ < h3
58+ className = 'ui header'
59+ style = { { marginBottom : 0 } }
60+ onMouseEnter = { this . handleMouseEnter }
61+ onMouseLeave = { this . handleMouseLeave }
62+ >
4063 { this . props . title }
64+ < a href = { `#${ this . anchor } ` } >
65+ < i className = 'linkify icon' style = { linkIconStyle } />
66+ </ a >
4167 </ h3 >
4268 < p > { this . props . description } </ p >
4369 </ Column >
@@ -49,7 +75,7 @@ export default class ComponentExample extends Component {
4975 </ Column >
5076 </ Grid >
5177 </ Column >
52-
78+ { this . props . children && children }
5379 < Column >
5480 { createElement ( this . component ) }
5581 </ Column >
0 commit comments