Skip to content

Commit b018a91

Browse files
committed
more iteration
1 parent 1cddf6d commit b018a91

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed

docs/content/Link.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ In special cases where you'd like a `<button>` styled like a `Link`, use `<Link
3131
/>
3232
<PropsTable.Row name="underline" type="boolean" defaultValue="false" description="Adds underline to the Link" />
3333
<PropsTable.Row name="hoverColor" type="string" description="Color used when hovering over link" />
34-
<PropsTable.AsRow defaultValue='"a"' />
35-
<PropsTable.SxRow />
34+
<PropsTable.CommonPropRows elementType="a" isPolymorphic />
3635
</PropsTable>

docs/content/TextInput.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ Native `<input>` attributes are forwarded to the underlying React `input` compon
5858
description="An Octicon react component. To be used inside of input. Positioned on the left edge."
5959
/>
6060
<PropsTable.SxRow />
61+
<PropsTable.RefRow
62+
elementType="input"
63+
description="A ref to the input element rendered by this component. Note: this is not the outermost element rendered by TextInput. There is also a divElement wrapper for which a ref is not accepted."
64+
/>
6165
</PropsTable>

docs/src/props-table.js

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react'
22
import {Box, Link, Label} from '@primer/components'
33
import Table from '@primer/gatsby-theme-doctocat/src/components/table'
4+
import InlineCode from '@primer/gatsby-theme-doctocat/src/components/inline-code'
5+
import {element} from 'prop-types'
46

57
function PropsTable({children}) {
68
return (
@@ -29,7 +31,7 @@ function PropsTable({children}) {
2931
function Row({name, type, defaultValue, description, required}) {
3032
return (
3133
<tr>
32-
<Box as="td" fontFamily="mono" fontSize={1} fontWeight="bold" sx={{whiteSpace: 'nowrap'}}>
34+
<Box as="td" fontFamily="mono" fontSize={1} sx={{whiteSpace: 'nowrap'}} verticalAlign="top">
3335
{typeof name === 'function' ? name() : name}
3436
{required ? (
3537
<>
@@ -38,24 +40,86 @@ function Row({name, type, defaultValue, description, required}) {
3840
</>
3941
) : null}
4042
</Box>
41-
<Box as="td" fontFamily="mono" fontSize={1}>
43+
<Box as="td" fontFamily="mono" fontSize={1} verticalAlign="top">
4244
{typeof type === 'function' ? type() : type}
4345
</Box>
44-
<Box as="td" fontFamily="mono" fontSize={1}>
46+
<Box as="td" fontFamily="mono" fontSize={1} verticalAlign="top">
4547
{typeof defaultValue === 'function' ? defaultValue() : defaultValue}
4648
</Box>
47-
<td>{typeof description === 'function' ? description() : description}</td>
49+
<Box as="td" verticalAlign="top">
50+
{typeof description === 'function' ? description() : description}
51+
</Box>
52+
</tr>
53+
)
54+
}
55+
56+
function CommonPropRows({elementType, isPolymorphic}) {
57+
return (
58+
<>
59+
<SxRow />
60+
{isPolymorphic && <AsRow defaultElementType={elementType} />}
61+
<RefRow elementType={elementType} isPolymorphic={isPolymorphic} />
62+
<DOMPropsRow elementName={elementType} isPolymorphic={isPolymorphic} />
63+
</>
64+
)
65+
}
66+
67+
function DOMPropsRow({elementName, isPolymorphic}) {
68+
return (
69+
<tr>
70+
<Box as="td" colSpan={3}>
71+
<i>
72+
(various DOM props. See{' '}
73+
<Link href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L2023">
74+
the React HTML attribute types
75+
</Link>
76+
)
77+
</i>
78+
</Box>
79+
<td>
80+
This component will also accept all the props of its underlying element (<InlineCode>{elementName}</InlineCode>)
81+
{isPolymorphic && (
82+
<>
83+
Or, if an <InlineCode>as</InlineCode> prop is passed, the properties of that element are passed through.
84+
</>
85+
)}
86+
.
87+
</td>
4888
</tr>
4989
)
5090
}
5191

52-
function AsRow({defaultValue}) {
92+
function AsRow({defaultElementType}) {
5393
return (
5494
<Row
5595
name="as"
56-
defaultValue={defaultValue}
57-
type="ReactElement"
58-
description="The underlying element to render — either a DOM element or a React component."
96+
defaultValue={`"${defaultElementType}"`}
97+
type={() => (
98+
<Link href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L73">
99+
React.ElementType
100+
</Link>
101+
)}
102+
description="The underlying element to render — either a DOM element name or a React component."
103+
/>
104+
)
105+
}
106+
107+
function RefRow({elementType, isPolymorphic}) {
108+
return (
109+
<Row
110+
name="ref"
111+
type={() => <>{'React.RefObject<HTMLElement>'}</>}
112+
description={() => (
113+
<>
114+
A ref to the element rendered by this component.
115+
{isPolymorphic && (
116+
<>
117+
Because this component is isPolymorphic, the type will vary based on the value of the{' '}
118+
<InlineCode>as</InlineCode> prop.
119+
</>
120+
)}
121+
</>
122+
)}
59123
/>
60124
)
61125
}
@@ -64,7 +128,6 @@ function SxRow() {
64128
return (
65129
<Row
66130
name="sx"
67-
defaultValue="{}"
68131
type={() => (
69132
<Link href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/styled-system__css/index.d.ts#L407">
70133
SystemStyleObject
@@ -79,6 +142,6 @@ function SxRow() {
79142
)
80143
}
81144

82-
Object.assign(PropsTable, {Row, AsRow, SxRow})
145+
Object.assign(PropsTable, {Row, CommonPropRows, AsRow, RefRow, DOMPropsRow, SxRow})
83146

84147
export {PropsTable}

0 commit comments

Comments
 (0)