-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathComponentDoc.js
More file actions
129 lines (116 loc) · 4.41 KB
/
ComponentDoc.js
File metadata and controls
129 lines (116 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import _ from 'lodash'
import PropTypes from 'prop-types'
import React, { Component, createRef } from 'react'
import { withRouter, withRouteData } from 'react-static'
import { Grid, Header, Icon, Label, Popup } from 'semantic-ui-react'
import DocsLayout from 'docs/src/components/DocsLayout'
import { docTypes, examplePathToHash } from 'docs/src/utils'
import ComponentDocLinks from './ComponentDocLinks'
import ComponentDocSee from './ComponentDocSee'
import ComponentExamples from './ComponentExamples'
import ComponentProps from './ComponentProps'
import ComponentSidebar from './ComponentSidebar'
import ComponentDocContext from './ComponentDocContext'
const exampleEndStyle = {
textAlign: 'center',
opacity: 0.5,
paddingTop: '50vh',
}
class ComponentDoc extends Component {
state = {}
examplesRef = createRef()
static getDerivedStateFromProps(props, state) {
const resetOccurred = props.displayName !== state.displayName
return {
displayName: props.displayName,
exampleStates: resetOccurred ? {} : state.exampleStates,
}
}
handleExampleVisibility = (examplePath, visible) =>
this.setState((prevState) => ({
exampleStates: {
...prevState.exampleStates,
[examplePath]: visible,
},
}))
handleSidebarItemClick = (e, { examplePath }) => {
const { history, location } = this.props
history.replace(`${location.pathname}#${examplePathToHash(examplePath)}`)
}
render() {
const { componentsInfo, displayName, deprecated, seeTags, sidebarSections } = this.props
const activePath = _.findKey(this.state.exampleStates)
const componentInfo = componentsInfo[displayName]
const contextValue = { ...this.props, onVisibilityChange: this.handleExampleVisibility }
return (
/* TODO: use `title` from context */
<DocsLayout additionalTitle={displayName} sidebar title='Semantic UI React'>
<Grid padded>
<Grid.Row>
<Grid.Column>
<Header
as='h1'
content={
<>
<span>{displayName}</span>
{deprecated && (
<Popup trigger={<Label color='black'>Deprecated</Label>}>
This component is deprecated and will be removed in the next major release.
</Popup>
)}
</>
}
subheader={_.join(componentInfo.docblock.description, ' ')}
/>
<ComponentDocSee seeTags={seeTags} />
{componentInfo.repoPath && (
<ComponentDocLinks
displayName={displayName}
parentDisplayName={componentInfo.parentDisplayName}
repoPath={componentInfo.repoPath}
type={componentInfo.type}
/>
)}
<ComponentProps componentsInfo={componentsInfo} displayName={displayName} />
</Grid.Column>
</Grid.Row>
<Grid.Row columns='equal'>
<Grid.Column>
<div ref={this.examplesRef}>
<ComponentDocContext.Provider value={contextValue}>
<ComponentExamples
displayName={displayName}
examplesExist={componentInfo.examplesExist}
type={componentInfo.type}
/>
</ComponentDocContext.Provider>
</div>
<div style={exampleEndStyle}>
This is the bottom <Icon name='pointing down' />
</div>
</Grid.Column>
<Grid.Column computer={5} largeScreen={4} widescreen={4}>
<ComponentSidebar
activePath={activePath}
examplesRef={this.examplesRef}
onItemClick={this.handleSidebarItemClick}
sections={sidebarSections}
/>
</Grid.Column>
</Grid.Row>
</Grid>
</DocsLayout>
)
}
}
ComponentDoc.propTypes = {
componentsInfo: PropTypes.objectOf(docTypes.componentInfoShape).isRequired,
displayName: PropTypes.string.isRequired,
deprecated: PropTypes.bool.isRequired,
history: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
seeTags: docTypes.seeTags.isRequired,
sidebarSections: docTypes.sidebarSections.isRequired,
title: PropTypes.string.isRequired,
}
export default withRouteData(withRouter(ComponentDoc))