11import React from 'react'
22import { Box , Link , Label } from '@primer/components'
33import 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
57function PropsTable ( { children} ) {
68 return (
@@ -29,7 +31,7 @@ function PropsTable({children}) {
2931function 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
84147export { PropsTable }
0 commit comments