Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit f717dbc

Browse files
authored
docs(FTZ): use PropsTable (#1268)
* remove HOCs, remove `active` on `ComponentButton`, remove unused props * rename to ComponentPropsTable, add useComponentProps hook * add FTZ components to docgen, to propsTable * fix links, update docgen to filter interfaces * fix ignore * revert link() changes * invert condition * update error contents * restore link stuff
1 parent 88cc96c commit f717dbc

30 files changed

+139
-468
lines changed

build/gulp/plugins/gulp-component-menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default () => {
3939
const jsonInfo = fs.readFileSync(infoFilePath)
4040
componentInfo = JSON.parse(jsonInfo.toString())
4141
} else {
42-
componentInfo = getComponentInfo(file.path)
42+
componentInfo = getComponentInfo(file.path, [])
4343
}
4444

4545
if (componentInfo.isParent) {

build/gulp/plugins/gulp-react-docgen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getComponentInfo } from './util'
77

88
const pluginName = 'gulp-react-docgen'
99

10-
export default () =>
10+
export default (ignoredInterfaces: string[] = []) =>
1111
through2.obj(function bufferContents(file, enc, cb) {
1212
if (file.isNull()) {
1313
cb(null, file)
@@ -21,7 +21,7 @@ export default () =>
2121

2222
try {
2323
const infoFilename = file.basename.replace(/\.tsx$/, '.info.json')
24-
const contents = getComponentInfo(file.path)
24+
const contents = getComponentInfo(file.path, ignoredInterfaces)
2525

2626
const infoFile = new Vinyl({
2727
path: `./${infoFilename}`,

build/gulp/plugins/util/getComponentInfo.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface BehaviorInfo {
1212
category: string
1313
}
1414

15-
const getComponentInfo = (filepath: string) => {
15+
const getComponentInfo = (filepath: string, ignoredParentInterfaces: string[]) => {
1616
const absPath = path.resolve(process.cwd(), filepath)
1717

1818
const dir = path.dirname(absPath)
@@ -99,14 +99,21 @@ const getComponentInfo = (filepath: string) => {
9999
const { description, tags } = parseDocblock(propDef.description)
100100
const { name, value } = parseType(propName, propDef)
101101

102-
info.props[propName] = {
103-
...propDef,
104-
description,
105-
tags,
106-
value,
107-
defaultValue: parseDefaultValue(propDef),
108-
name: propName,
109-
type: name,
102+
const parentInterface = _.get(propDef, 'parent.name')
103+
const visibleInDefinition = !_.includes(ignoredParentInterfaces, parentInterface)
104+
105+
if (visibleInDefinition) {
106+
info.props[propName] = {
107+
...propDef,
108+
description,
109+
tags,
110+
value,
111+
defaultValue: parseDefaultValue(propDef),
112+
name: propName,
113+
type: name,
114+
}
115+
} else {
116+
delete info.props[propName]
110117
}
111118
})
112119

build/gulp/tasks/docs.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ task(
6868
),
6969
)
7070

71-
// ----------------------------------------s
71+
// ----------------------------------------
7272
// Build
7373
// ----------------------------------------
7474

75-
const componentsSrc = [`${paths.posix.packageSrc('react')}/components/*/[A-Z]*.tsx`]
75+
const componentsSrc = [
76+
`${paths.posix.packageSrc('react')}/components/*/[A-Z]*.tsx`,
77+
`${paths.posix.packageSrc('react')}/lib/accessibility/FocusZone/[A-Z]!(*.types).tsx`,
78+
]
7679
const behaviorSrc = [`${paths.posix.packageSrc('react')}/lib/accessibility/Behaviors/*/[a-z]*.ts`]
7780
const examplesIndexSrc = `${paths.posix.docsSrc()}/examples/*/*/*/index.tsx`
7881
const examplesSrc = `${paths.posix.docsSrc()}/examples/*/*/*/!(*index|.knobs).tsx`
@@ -88,7 +91,7 @@ const markdownSrc = [
8891
task('build:docs:component-info', () =>
8992
src(componentsSrc, { since: lastRun('build:docs:component-info') })
9093
.pipe(
91-
cache(gulpReactDocgen(), {
94+
cache(gulpReactDocgen(['DOMAttributes', 'HTMLAttributes']), {
9295
name: 'componentInfo',
9396
}),
9497
)

docs/src/components/ComponentDoc/ComponentControls/ComponentButton.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import * as React from 'react'
44
interface LabelledButtonProps {
55
iconName: string
66
label: string
7-
active: boolean
87
onClick?: (event: React.SyntheticEvent) => void
98
}
109

11-
const LabelledButton = createComponent<LabelledButtonProps>({
12-
displayName: 'LabelledButton',
10+
const ComponentButton = createComponent<LabelledButtonProps>({
11+
displayName: 'ComponentButton',
1312
render: ({ stardust, ...props }) => {
1413
const { iconName, label, onClick } = props
1514
return (
@@ -20,4 +19,4 @@ const LabelledButton = createComponent<LabelledButtonProps>({
2019
)
2120
},
2221
})
23-
export default LabelledButton
22+
export default ComponentButton

docs/src/components/ComponentDoc/ComponentControls/ComponentControls.tsx

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as _ from 'lodash'
99
import * as React from 'react'
1010
import { NavLink } from 'react-router-dom'
1111

12-
import { updateForKeys } from 'docs/src/hoc'
1312
import ComponentButton from './ComponentButton'
1413
import { ComponentSourceManagerLanguage } from 'docs/src/components/ComponentDoc/ComponentSourceManager'
1514
import ComponentControlsCodeSandbox from './ComponentControlsCodeSandbox/ComponentControlsCodeSandbox'
@@ -25,10 +24,7 @@ type ComponentControlsProps = {
2524
onShowRtl: (e: React.SyntheticEvent) => void
2625
onShowTransparent: (e: React.SyntheticEvent) => void
2726
onShowVariables: (e: React.SyntheticEvent) => void
28-
showCode: boolean
2927
showRtl: boolean
30-
showTransparent: boolean
31-
showVariables: boolean
3228
}
3329

3430
const controlsTheme: ThemeInput = {
@@ -58,10 +54,7 @@ const ComponentControls: React.FC<ComponentControlsProps> = props => {
5854
exampleCode,
5955
exampleLanguage,
6056
examplePath,
61-
showCode,
6257
showRtl,
63-
showTransparent,
64-
showVariables,
6558
onCopyLink,
6659
onShowCode,
6760
onShowRtl,
@@ -83,7 +76,7 @@ const ComponentControls: React.FC<ComponentControlsProps> = props => {
8376
items={[
8477
{
8578
key: 'show-code',
86-
content: <ComponentButton iconName="code" label="Try it" active={showCode} />,
79+
content: <ComponentButton iconName="code" label="Try it" />,
8780
onClick: onShowCode,
8881
accessibility: toolbarButtonBehavior,
8982
},
@@ -100,31 +93,25 @@ const ComponentControls: React.FC<ComponentControlsProps> = props => {
10093
},
10194
{
10295
key: 'show-variables',
103-
content: (
104-
<ComponentButton iconName="paint brush" label="Theme it" active={showVariables} />
105-
),
96+
content: <ComponentButton iconName="paint brush" label="Theme it" />,
10697
onClick: onShowVariables,
10798
accessibility: toolbarButtonBehavior,
10899
},
109100
{
110101
key: 'show-transparent',
111-
content: (
112-
<ComponentButton iconName="adjust" label="Transparent" active={showTransparent} />
113-
),
102+
content: <ComponentButton iconName="adjust" label="Transparent" />,
114103
onClick: onShowTransparent,
115104
accessibility: toolbarButtonBehavior,
116105
},
117106
{
118107
key: 'show-rtl',
119-
content: <ComponentButton iconName="align right" label="RTL" active={showRtl} />,
108+
content: <ComponentButton iconName="align right" label="RTL" />,
120109
onClick: onShowRtl,
121110
accessibility: toolbarButtonBehavior,
122111
},
123112
{
124113
key: 'maximize',
125-
content: (
126-
<ComponentButton iconName="external alternate" label="Popout" active={false} />
127-
),
114+
content: <ComponentButton iconName="external alternate" label="Popout" />,
128115
as: NavLink,
129116
to: `/maximize/${_.kebabCase(
130117
examplePath
@@ -144,7 +131,6 @@ const ComponentControls: React.FC<ComponentControlsProps> = props => {
144131
<ComponentButton
145132
iconName="linkify"
146133
label={active ? 'Copied!' : 'Permalink'}
147-
active={active}
148134
onClick={onClick}
149135
/>
150136
)}
@@ -160,11 +146,4 @@ const ComponentControls: React.FC<ComponentControlsProps> = props => {
160146
)
161147
}
162148

163-
export default updateForKeys([
164-
'exampleCode',
165-
'examplePath',
166-
'showRtl',
167-
'showCode',
168-
'showTransparent',
169-
'showVariables',
170-
])(ComponentControls, ComponentButton)
149+
export default React.memo(ComponentControls)

docs/src/components/ComponentDoc/ComponentControls/ComponentControlsCodeSandbox/ComponentControlsCodeSandbox.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ import * as React from 'react'
22
import CodeSandboxer from 'react-codesandboxer'
33

44
import { ComponentSourceManagerLanguage } from 'docs/src/components/ComponentDoc/ComponentSourceManager'
5-
import { updateForKeys } from 'docs/src/hoc'
65
import { appTemplateJs, appTemplateTs } from './indexTemplates'
7-
import LabelledButton from '../ComponentButton'
6+
import ComponentButton from '../ComponentButton'
87
import createPackageJson from './createPackageJson'
98

109
type ComponentControlsCodeSandboxProps = {
1110
exampleCode: string
1211
exampleLanguage: ComponentSourceManagerLanguage
1312
exampleName: string
14-
active: boolean
1513
}
1614

1715
type ComponentControlsCodeSandboxState = {
@@ -20,7 +18,7 @@ type ComponentControlsCodeSandboxState = {
2018
sandboxUrl: string
2119
}
2220

23-
class ComponentControlsShowCode extends React.Component<
21+
class ComponentControlsCodeSandbox extends React.PureComponent<
2422
ComponentControlsCodeSandboxProps,
2523
ComponentControlsCodeSandboxState
2624
> {
@@ -55,7 +53,7 @@ class ComponentControlsShowCode extends React.Component<
5553
}
5654

5755
render() {
58-
const { active, exampleLanguage, exampleCode, exampleName } = this.props
56+
const { exampleLanguage, exampleCode, exampleName } = this.props
5957
const { examplePath, sandboxUrl } = this.state
6058

6159
const main = exampleLanguage === 'ts' ? 'index.tsx' : 'index.js'
@@ -64,12 +62,7 @@ class ComponentControlsShowCode extends React.Component<
6462

6563
if (sandboxUrl) {
6664
return (
67-
<LabelledButton
68-
label="Click to open"
69-
onClick={this.handleClick}
70-
iconName="checkmark"
71-
active={active}
72-
/>
65+
<ComponentButton label="Click to open" onClick={this.handleClick} iconName="checkmark" />
7366
)
7467
}
7568

@@ -86,13 +79,12 @@ class ComponentControlsShowCode extends React.Component<
8679
skipRedirect
8780
template={template}
8881
>
89-
{({ isLoading, isDeploying, active }) => {
82+
{({ isLoading, isDeploying }) => {
9083
const loading = isLoading || isDeploying
9184
return (
92-
<LabelledButton
85+
<ComponentButton
9386
iconName={loading ? 'spinner' : 'connectdevelop'}
9487
label={loading ? 'Exporting...' : 'CodeSandbox'}
95-
active={active}
9688
/>
9789
)
9890
}}
@@ -101,4 +93,4 @@ class ComponentControlsShowCode extends React.Component<
10193
}
10294
}
10395

104-
export default updateForKeys(['exampleCode', 'active'])(ComponentControlsShowCode)
96+
export default ComponentControlsCodeSandbox

docs/src/components/ComponentDoc/ComponentControls/ComponentControlsCopyLink.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react'
2-
import LabelledButton from './ComponentButton'
2+
import ComponentButton from './ComponentButton'
33
import * as _ from 'lodash'
44

55
export default class ComponentControlsCopyLink extends React.Component<any, any> {
@@ -24,10 +24,9 @@ export default class ComponentControlsCopyLink extends React.Component<any, any>
2424
const { active } = this.state
2525

2626
return (
27-
<LabelledButton
27+
<ComponentButton
2828
iconName="linkify"
2929
label={active ? 'Copied!' : this.btnLabel}
30-
active={active}
3130
onClick={this.handleClick}
3231
/>
3332
)

docs/src/components/ComponentDoc/ComponentExample/ComponentExample.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ class ComponentExample extends React.Component<ComponentExampleProps, ComponentE
511511
description,
512512
title,
513513
} = this.props
514-
const { showCode, showRtl, showTransparent, showVariables } = this.state
514+
const { showCode, showRtl, showTransparent } = this.state
515515

516516
return (
517517
<Flex column>
@@ -535,10 +535,7 @@ class ComponentExample extends React.Component<ComponentExampleProps, ComponentE
535535
onShowRtl={this.handleShowRtlClick}
536536
onShowVariables={this.handleShowVariablesClick}
537537
onShowTransparent={this.handleShowTransparentClick}
538-
showCode={showCode}
539538
showRtl={showRtl}
540-
showTransparent={showTransparent}
541-
showVariables={showVariables}
542539
/>
543540
</Flex.Item>
544541
</Flex>

docs/src/components/ComponentDoc/ComponentProp/ComponentPropEnum.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as _ from 'lodash'
22
import * as PropTypes from 'prop-types'
33
import * as React from 'react'
44

5-
import { updateForKeys } from 'docs/src/hoc'
65
import ComponentPropExtra from './ComponentPropExtra'
76
import ComponentPropToggle from './ComponentPropEnumToggle'
87
import ComponentPropValue from './ComponentPropEnumValue'
@@ -39,4 +38,9 @@ ComponentPropEnum.propTypes = {
3938
values: PropTypes.array,
4039
}
4140

42-
export default updateForKeys(['showAll', 'type', 'values'])(ComponentPropEnum)
41+
const arePropsEqual = (prevProps, nextProps) =>
42+
prevProps.showAll === nextProps.showAll &&
43+
prevProps.type === nextProps.type &&
44+
prevProps.values === nextProps.values
45+
46+
export default React.memo(ComponentPropEnum, arePropsEqual)

docs/src/components/ComponentDoc/ComponentProp/ComponentPropEnumToggle.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as PropTypes from 'prop-types'
22
import * as React from 'react'
33

4-
import { updateForKeys } from 'docs/src/hoc'
5-
64
const toggleStyle = {
75
cursor: 'pointer',
86
}
@@ -19,4 +17,6 @@ ComponentPropEnumToggle.propTypes = {
1917
total: PropTypes.number,
2018
}
2119

22-
export default updateForKeys(['showAll'])(ComponentPropEnumToggle)
20+
const areEqualProps = (prevProps, nextProps) => prevProps.showAll === nextProps.showAll
21+
22+
export default React.memo(ComponentPropEnumToggle, areEqualProps)

docs/src/components/ComponentDoc/ComponentProp/ComponentPropEnumValue.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as PropTypes from 'prop-types'
22
import * as React from 'react'
33

4-
import { neverUpdate } from 'docs/src/hoc'
5-
64
const spanStyle = {
75
display: 'inline-block',
86
paddingRight: '0.2em',
@@ -18,4 +16,6 @@ ComponentPropEnumValue.propTypes = {
1816
children: PropTypes.node,
1917
}
2018

21-
export default neverUpdate(ComponentPropEnumValue)
19+
const arePropsEqual = () => true
20+
21+
export default React.memo(ComponentPropEnumValue, arePropsEqual)

docs/src/components/ComponentDoc/ComponentProp/ComponentPropFunctionSignature.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as _ from 'lodash'
22
import * as PropTypes from 'prop-types'
33
import * as React from 'react'
44

5-
import { neverUpdate } from 'docs/src/hoc'
65
import ComponentPropExtra, { ComponentPropExtraProps } from './ComponentPropExtra'
76

87
interface ComponentPropFunctionProps extends ComponentPropExtraProps {
@@ -75,4 +74,6 @@ ComponentPropFunctionSignature.propTypes = {
7574
tags: PropTypes.array,
7675
}
7776

78-
export default neverUpdate(ComponentPropFunctionSignature)
77+
const arePropsEqual = () => true
78+
79+
export default React.memo(ComponentPropFunctionSignature, arePropsEqual)

0 commit comments

Comments
 (0)