@@ -2,10 +2,9 @@ import React, {Component} from 'react';
2
2
import PropTypes from 'prop-types' ;
3
3
import _ from 'lodash' ;
4
4
import Link from 'gatsby-link' ;
5
+ import Layout from '../components/layout' ;
5
6
6
7
import './components.scss' ;
7
- import Layout from '../components/layout' ;
8
- import Navbar from '../components/navbar' ;
9
8
10
9
const IMAGE_TYPES = {
11
10
GIF : 'GIF' ,
@@ -14,22 +13,23 @@ const IMAGE_TYPES = {
14
13
15
14
export default class ComponentTemplate extends Component {
16
15
static propTypes = {
17
- pathContext : PropTypes . object
16
+ pageContext : PropTypes . object
18
17
}
19
18
20
19
extractComponentsInfo ( component ) {
21
- const statementPattern = / @ \w * \: / //eslint-disable-line
20
+ const splitPattern = / ( [ \s \S ] * ? ) : ( [ \s \S ] * ) / //eslint-disable-line
22
21
23
22
const info = {
24
23
description : _ . get ( component , 'description.text' )
25
24
} ;
26
25
27
26
if ( component . docblock ) {
28
- const infoRaw = _ . split ( component . docblock , '\n ' ) ;
27
+ const infoRaw = _ . split ( component . docblock , '@ ' ) ;
29
28
_ . 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 ] ;
33
33
}
34
34
} ) ;
35
35
}
@@ -38,8 +38,8 @@ export default class ComponentTemplate extends Component {
38
38
}
39
39
40
40
renderLink ( componentInfo ) {
41
- const { pathContext } = this . props ;
42
- const allComponents = pathContext . components ;
41
+ const { pageContext } = this . props ;
42
+ const allComponents = pageContext . components ;
43
43
44
44
const extendedComponents = _ . chain ( componentInfo . extends )
45
45
. replace ( / / g, '' )
@@ -49,7 +49,7 @@ export default class ComponentTemplate extends Component {
49
49
return _ . map ( extendedComponents , ( component , index ) => {
50
50
const isLast = index === _ . size ( extendedComponents ) - 1 ;
51
51
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 ( ) ) ;
53
53
const path = ! extendedComponent && componentInfo . extendsLink ? componentInfo . extendsLink : `/docs/${ component } ` ;
54
54
55
55
return (
@@ -111,10 +111,10 @@ export default class ComponentTemplate extends Component {
111
111
}
112
112
113
113
renderComponentPage ( ) {
114
- const { pathContext } = this . props ;
115
- const selectedComponent = pathContext . componentNode ;
114
+ const { pageContext } = this . props ;
115
+ const selectedComponent = pageContext . componentNode ;
116
116
const componentInfo = this . extractComponentsInfo ( selectedComponent ) ;
117
- const componentProps = _ . get ( selectedComponent , 'props' ) ;
117
+ const componentProps = _ . orderBy ( _ . get ( selectedComponent , 'props' ) , prop => prop . name . toLowerCase ( ) ) ;
118
118
const gifs = componentInfo . gif ? componentInfo . gif . split ( ',' ) : undefined ;
119
119
const imgs = componentInfo . image ? componentInfo . image . split ( ',' ) : undefined ;
120
120
const notes = componentInfo . notes ? componentInfo . notes . split ( ';' ) : undefined ;
@@ -126,7 +126,7 @@ export default class ComponentTemplate extends Component {
126
126
{ componentInfo . example && (
127
127
< span className = "code-example" >
128
128
(
129
- < a className = "inline" target = "_blank" href = { componentInfo . example } >
129
+ < a className = "inline" target = "_blank" rel = "noopener noreferrer" href = { componentInfo . example } >
130
130
code example
131
131
</ a >
132
132
)
@@ -145,7 +145,11 @@ export default class ComponentTemplate extends Component {
145
145
< p >
146
146
Supported modifiers: < b > { componentInfo . modifiers } </ b > . < br />
147
147
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
+ >
149
153
{ ' ' }
150
154
here
151
155
</ a >
@@ -191,9 +195,20 @@ export default class ComponentTemplate extends Component {
191
195
}
192
196
193
197
render ( ) {
198
+ const isIntro = ! _ . get ( this . props , 'pageContext.componentNode' ) ;
194
199
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 >
197
212
</ Layout >
198
213
) ;
199
214
}
0 commit comments