@@ -2,10 +2,9 @@ import React, {Component} from 'react';
22import PropTypes from 'prop-types' ;
33import _ from 'lodash' ;
44import Link from 'gatsby-link' ;
5+ import Layout from '../components/layout' ;
56
67import './components.scss' ;
7- import Layout from '../components/layout' ;
8- import Navbar from '../components/navbar' ;
98
109const IMAGE_TYPES = {
1110 GIF : 'GIF' ,
@@ -14,22 +13,23 @@ const IMAGE_TYPES = {
1413
1514export default class ComponentTemplate extends Component {
1615 static propTypes = {
17- pathContext : PropTypes . object
16+ pageContext : PropTypes . object
1817 }
1918
2019 extractComponentsInfo ( component ) {
21- const statementPattern = / @ \w * \: / //eslint-disable-line
20+ const splitPattern = / ( [ \s \S ] * ? ) : ( [ \s \S ] * ) / //eslint-disable-line
2221
2322 const info = {
2423 description : _ . get ( component , 'description.text' )
2524 } ;
2625
2726 if ( component . docblock ) {
28- const infoRaw = _ . split ( component . docblock , '\n ' ) ;
27+ const infoRaw = _ . split ( component . docblock , '@ ' ) ;
2928 _ . forEach ( infoRaw , statement => {
30- if ( statement && statementPattern . test ( statement ) ) {
31- const key = statement . match ( statementPattern ) [ 0 ] . slice ( 1 , - 1 ) ;
32- info [ key ] = statement . split ( statementPattern ) [ 1 ] . trim ( ) ;
29+ const match = splitPattern . exec ( statement ) ;
30+ if ( statement && match ) {
31+ const key = match [ 1 ] ;
32+ info [ key ] = match [ 2 ] ;
3333 }
3434 } ) ;
3535 }
@@ -38,8 +38,8 @@ export default class ComponentTemplate extends Component {
3838 }
3939
4040 renderLink ( componentInfo ) {
41- const { pathContext } = this . props ;
42- const allComponents = pathContext . components ;
41+ const { pageContext } = this . props ;
42+ const allComponents = pageContext . components ;
4343
4444 const extendedComponents = _ . chain ( componentInfo . extends )
4545 . replace ( / / g, '' )
@@ -49,7 +49,7 @@ export default class ComponentTemplate extends Component {
4949 return _ . map ( extendedComponents , ( component , index ) => {
5050 const isLast = index === _ . size ( extendedComponents ) - 1 ;
5151 const text = < b > { `${ component } ${ ! isLast ? ', ' : '' } ` } </ b > ;
52- const extendedComponent = _ . find ( allComponents , c => c . node . displayName === component ) ;
52+ const extendedComponent = _ . find ( allComponents , c => c . node . displayName . trim ( ) === component . trim ( ) ) ;
5353 const path = ! extendedComponent && componentInfo . extendsLink ? componentInfo . extendsLink : `/docs/${ component } ` ;
5454
5555 return (
@@ -111,10 +111,10 @@ export default class ComponentTemplate extends Component {
111111 }
112112
113113 renderComponentPage ( ) {
114- const { pathContext } = this . props ;
115- const selectedComponent = pathContext . componentNode ;
114+ const { pageContext } = this . props ;
115+ const selectedComponent = pageContext . componentNode ;
116116 const componentInfo = this . extractComponentsInfo ( selectedComponent ) ;
117- const componentProps = _ . get ( selectedComponent , 'props' ) ;
117+ const componentProps = _ . orderBy ( _ . get ( selectedComponent , 'props' ) , prop => prop . name . toLowerCase ( ) ) ;
118118 const gifs = componentInfo . gif ? componentInfo . gif . split ( ',' ) : undefined ;
119119 const imgs = componentInfo . image ? componentInfo . image . split ( ',' ) : undefined ;
120120 const notes = componentInfo . notes ? componentInfo . notes . split ( ';' ) : undefined ;
@@ -126,7 +126,7 @@ export default class ComponentTemplate extends Component {
126126 { componentInfo . example && (
127127 < span className = "code-example" >
128128 (
129- < a className = "inline" target = "_blank" href = { componentInfo . example } >
129+ < a className = "inline" target = "_blank" rel = "noopener noreferrer" href = { componentInfo . example } >
130130 code example
131131 </ a >
132132 )
@@ -145,7 +145,11 @@ export default class ComponentTemplate extends Component {
145145 < p >
146146 Supported modifiers: < b > { componentInfo . modifiers } </ b > . < br />
147147 Read more about modifiers{ ' ' }
148- < a target = "_blank" href = { 'https://github.com/wix/react-native-ui-lib/wiki/MODIFIERS' } >
148+ < a
149+ target = "_blank"
150+ rel = "noopener noreferrer"
151+ href = { 'https://github.com/wix/react-native-ui-lib/wiki/MODIFIERS' }
152+ >
149153 { ' ' }
150154 here
151155 </ a >
@@ -191,9 +195,20 @@ export default class ComponentTemplate extends Component {
191195 }
192196
193197 render ( ) {
198+ const isIntro = ! _ . get ( this . props , 'pageContext.componentNode' ) ;
194199 return (
195- < Layout { ...this . props } navbar = { < Navbar /> } >
196- { this . renderComponentPage ( ) }
200+ < Layout { ...this . props } showSidebar >
201+ < div >
202+ { isIntro && (
203+ < div className = "docs-page" >
204+ < div className = "docs-page__content" >
205+ < div > Select a component from the left sidebar</ div >
206+ </ div >
207+ </ div >
208+ ) }
209+
210+ { ! isIntro && this . renderComponentPage ( ) }
211+ </ div >
197212 </ Layout >
198213 ) ;
199214 }
0 commit comments