Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(gatsby-theme-docz): add new Props component
- Loading branch information
1 parent
a4770ab
commit 8eb780d
Showing
13 changed files
with
251 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** @jsx jsx */ | ||
import { useState } from 'react' | ||
import { jsx } from 'theme-ui' | ||
|
||
import { ChevronDown, ChevronUp } from '../Icons' | ||
import * as styles from './styles' | ||
|
||
export const Prop = ({ propName, prop, getPropType }) => { | ||
const [showing, setShowing] = useState(false) | ||
if (!prop.type && !prop.flowType) return null | ||
|
||
const toggle = () => setShowing(s => !s) | ||
|
||
return ( | ||
<div sx={styles.line}> | ||
<div sx={styles.content}> | ||
<div sx={styles.propName}>{propName}</div> | ||
<div sx={styles.propType}>{getPropType(prop)}</div> | ||
{prop.defaultValue && ( | ||
<div sx={styles.defaultValue}> | ||
{prop.defaultValue.value === "''" ? ( | ||
<em>[Empty String]</em> | ||
) : ( | ||
<em>{prop.defaultValue.value.replace(/\'/g, '"')}</em> | ||
)} | ||
</div> | ||
)} | ||
<div sx={styles.right}> | ||
{prop.required && ( | ||
<div sx={styles.propRequired}> | ||
<strong>required</strong> | ||
</div> | ||
)} | ||
{prop.description && ( | ||
<button sx={styles.openDescBtn} onClick={toggle}> | ||
{showing ? <ChevronUp size={20} /> : <ChevronDown size={20} />} | ||
</button> | ||
)} | ||
</div> | ||
</div> | ||
{showing && prop.description && ( | ||
<div sx={styles.description}>{prop.description}</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export const Props = ({ props, getPropType }) => { | ||
const entries = Object.entries(props) | ||
|
||
return ( | ||
<div sx={styles.container}> | ||
{entries.map(([key, prop]) => ( | ||
<Prop key={key} propName={key} prop={prop} getPropType={getPropType} /> | ||
))} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { breakpoints } from '~theme/breakpoints' | ||
import * as mixins from '~utils/mixins' | ||
|
||
export const container = { | ||
my: 4, | ||
border: '1px solid #000', | ||
borderColor: 'border', | ||
borderRadius: 'radius', | ||
overflow: 'hidden', | ||
bg: 'props.bg', | ||
color: 'props.text', | ||
fontSize: 3, | ||
} | ||
|
||
export const content = { | ||
position: 'relative', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
[`@media (min-width: ${breakpoints.tablet}px)`]: { | ||
flexWrap: 'nowrap', | ||
flexDirection: 'row', | ||
}, | ||
} | ||
|
||
export const line = { | ||
pt: 2, | ||
'& + &': { | ||
borderTop: '1px solid #000', | ||
borderColor: 'border', | ||
}, | ||
} | ||
|
||
export const column = { | ||
minWidth: 0, | ||
pb: 2, | ||
px: 3, | ||
wordWrap: 'break-word', | ||
'& ~ &': { | ||
bg: 'red', | ||
}, | ||
} | ||
|
||
export const propName = { | ||
...column, | ||
color: 'props.highlight', | ||
} | ||
|
||
export const propType = { | ||
...column, | ||
colors: 'props.text', | ||
} | ||
|
||
export const defaultValue = { | ||
...column, | ||
color: 'props.defaultValue', | ||
} | ||
|
||
export const right = { | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'flex-end', | ||
px: 3, | ||
flex: 1, | ||
[`@media (max-width: ${breakpoints.tablet}px)`]: { | ||
position: 'absolute', | ||
top: 0, | ||
right: 0, | ||
}, | ||
} | ||
|
||
export const propRequired = { | ||
color: 'props.text', | ||
fontSize: 1, | ||
opacity: 0.5, | ||
} | ||
|
||
export const openDescBtn = { | ||
...mixins.ghostButton, | ||
mt: -2, | ||
ml: 3, | ||
color: 'props.defaultValue', | ||
} | ||
|
||
export const description = { | ||
fontSize: 2, | ||
m: 0, | ||
py: 2, | ||
px: 3, | ||
borderTop: '1px solid #000', | ||
borderColor: 'border', | ||
color: 'props.descriptionText', | ||
bg: 'props.descriptionBg', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import * as headings from './Headings' | ||
|
||
import { Layout } from './Layout' | ||
import { Props } from './Props' | ||
|
||
export const componentsMap = { | ||
...headings, | ||
layout: Layout, | ||
props: Props, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.