1
1
import React from "react"
2
2
import PropTypes from "prop-types"
3
3
import ImPropTypes from "react-immutable-proptypes"
4
+ import cx from "classnames"
5
+ import randomBytes from "randombytes"
4
6
5
7
export default class ModelExample extends React . Component {
6
8
static propTypes = {
@@ -31,11 +33,11 @@ export default class ModelExample extends React.Component {
31
33
}
32
34
33
35
this . state = {
34
- activeTab : activeTab
36
+ activeTab,
35
37
}
36
38
}
37
39
38
- activeTab = ( e ) => {
40
+ activeTab = ( e ) => {
39
41
let { target : { dataset : { name } } } = e
40
42
41
43
this . setState ( {
@@ -58,42 +60,83 @@ export default class ModelExample extends React.Component {
58
60
let { defaultModelExpandDepth } = getConfigs ( )
59
61
const ModelWrapper = getComponent ( "ModelWrapper" )
60
62
const HighlightCode = getComponent ( "highlightCode" )
63
+ const exampleTabId = randomBytes ( 5 ) . toString ( "base64" )
64
+ const examplePanelId = randomBytes ( 5 ) . toString ( "base64" )
65
+ const modelTabId = randomBytes ( 5 ) . toString ( "base64" )
66
+ const modelPanelId = randomBytes ( 5 ) . toString ( "base64" )
61
67
62
68
let isOAS3 = specSelectors . isOAS3 ( )
63
69
64
- return < div className = "model-example" >
65
- < ul className = "tab" >
66
- < li className = { "tabitem" + ( this . state . activeTab === "example" ? " active" : "" ) } >
67
- < a className = "tablinks" data-name = "example" onClick = { this . activeTab } > { isExecute ? "Edit Value" : "Example Value" } </ a >
68
- </ li >
69
- { schema ? < li className = { "tabitem" + ( this . state . activeTab === "model" ? " active" : "" ) } >
70
- < a className = { "tablinks" + ( isExecute ? " inactive" : "" ) } data-name = "model" onClick = { this . activeTab } >
71
- { isOAS3 ? "Schema" : "Model" }
72
- </ a >
73
- </ li > : null }
74
- </ ul >
75
- < div >
76
- {
77
- this . state . activeTab === "example" ? (
78
- example ? example : (
70
+ return (
71
+ < div className = "model-example" >
72
+ < ul className = "tab" role = "tablist" >
73
+ < li className = { cx ( "tabitem" , { active : this . state . activeTab === "example" } ) } role = "presentation" >
74
+ < button
75
+ aria-controls = { examplePanelId }
76
+ aria-selected = { this . state . activeTab === "example" }
77
+ className = "tablinks"
78
+ data-name = "example"
79
+ id = { exampleTabId }
80
+ onClick = { this . activeTab }
81
+ role = "tab"
82
+ >
83
+ { isExecute ? "Edit Value" : "Example Value" }
84
+ </ button >
85
+ </ li >
86
+ { schema && (
87
+ < li className = { cx ( "tabitem" , { active : this . state . activeTab === "model" } ) } role = "presentation" >
88
+ < button
89
+ aria-controls = { modelPanelId }
90
+ aria-selected = { this . state . activeTab === "model" }
91
+ className = { cx ( "tablinks" , { inactive : isExecute } ) }
92
+ data-name = "model"
93
+ id = { modelTabId }
94
+ onClick = { this . activeTab }
95
+ role = "tab"
96
+ >
97
+ { isOAS3 ? "Schema" : "Model" }
98
+ </ button >
99
+ </ li >
100
+ ) }
101
+ </ ul >
102
+ { this . state . activeTab === "example" && (
103
+ < div
104
+ aria-hidden = { this . state . activeTab !== "example" }
105
+ aria-labelledby = { exampleTabId }
106
+ data-name = "examplePanel"
107
+ id = { examplePanelId }
108
+ role = "tabpanel"
109
+ tabIndex = "0"
110
+ >
111
+ { example ? example : (
79
112
< HighlightCode value = "(no example available)" getConfigs = { getConfigs } />
80
- )
81
- ) : null
82
- }
83
- {
84
- this . state . activeTab === "model" && < ModelWrapper schema = { schema }
85
- getComponent = { getComponent }
86
- getConfigs = { getConfigs }
87
- specSelectors = { specSelectors }
88
- expandDepth = { defaultModelExpandDepth }
89
- specPath = { specPath }
90
- includeReadOnly = { includeReadOnly }
91
- includeWriteOnly = { includeWriteOnly } />
113
+ ) }
114
+ </ div >
115
+ ) }
92
116
93
-
94
- }
117
+ { this . state . activeTab === "model" && (
118
+ < div
119
+ aria-hidden = { this . state . activeTab === "example" }
120
+ aria-labelledby = { modelTabId }
121
+ data-name = "modelPanel"
122
+ id = { modelPanelId }
123
+ role = "tabpanel"
124
+ tabIndex = "0"
125
+ >
126
+ < ModelWrapper
127
+ schema = { schema }
128
+ getComponent = { getComponent }
129
+ getConfigs = { getConfigs }
130
+ specSelectors = { specSelectors }
131
+ expandDepth = { defaultModelExpandDepth }
132
+ specPath = { specPath }
133
+ includeReadOnly = { includeReadOnly }
134
+ includeWriteOnly = { includeWriteOnly }
135
+ />
136
+ </ div >
137
+ ) }
95
138
</ div >
96
- </ div >
139
+ )
97
140
}
98
141
99
142
}
0 commit comments