Skip to content

Commit

Permalink
Merge pull request #651 from primer/doc-fixes
Browse files Browse the repository at this point in the history
Some documentation fixes
  • Loading branch information
shawnbot authored Jan 18, 2019
2 parents d51305c + 946e3ad commit aeca890
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 24 deletions.
39 changes: 35 additions & 4 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"prop-types": "^15.6.2",
"react": "16.6.1",
"react-dom": "16.6.1",
"react-measure": "^2.2.2",
"refractor": "^2.6.2",
"remark-emoji": "^2.0.2",
"remark-images": "^0.16.1",
Expand Down
2 changes: 1 addition & 1 deletion docs/src/CodeExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function CodeExample(props) {
<Text
as={LiveError}
fontFamily="mono"
css={{
style={{
overflow: 'auto',
whiteSpace: 'pre'
}}
Expand Down
34 changes: 21 additions & 13 deletions docs/src/Frame.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom'
import Measure from 'react-measure'
import {BorderBox} from '@primer/components'
import {assetPrefix} from './utils'

Expand All @@ -19,14 +20,16 @@ export default class Frame extends React.Component {
}

componentDidMount() {
this.doc = this.node.contentDocument
this.doc = this.iframe.contentDocument
const files = JSON.parse(document.body.dataset.files || '[]')
// eslint-disable-next-line react/no-did-mount-set-state
this.setState({files})
this.node.addEventListener('load', () => this.setState({loaded: true}))
this.setState({loaded: false, files})
this.iframe.addEventListener('load', () => {
this.setState({loaded: true})
})
}

getCssLinks() {
getHead() {
const {files} = this.state
return files
? files
Expand All @@ -35,21 +38,26 @@ export default class Frame extends React.Component {
: null
}

getHeight() {
if (!this.node) return null
this.node.style.height = 'max-content'
const {body} = this.node.contentDocument
return body.offsetHeight > DEFAULT_IFRAME_HEIGHT ? body.offsetHeight : body.scrollHeight
getBody(children) {
return (
<Measure bounds onResize={rect => this.setHeight(rect.bounds.height)}>
{({measureRef}) => <div ref={measureRef}>{children}</div>}
</Measure>
)
}

setHeight(height) {
// console.warn('height:', height)
this.setState({height})
}

render() {
const {children, ...rest} = this.props
const height = this.getHeight()
const style = height ? {height} : null
const {height = 'auto'} = this.state
return (
<BorderBox as="iframe" style={style} {...rest} ref={node => (this.node = node)}>
<BorderBox as="iframe" style={{height}} {...rest} ref={node => (this.iframe = node)}>
{this.doc
? [ReactDOM.createPortal(this.getCssLinks(), this.doc.head), ReactDOM.createPortal(children, this.doc.body)]
? [ReactDOM.createPortal(this.getHead(), this.doc.head), ReactDOM.createPortal(this.getBody(children), this.doc.body)]
: null}
</BorderBox>
)
Expand Down
10 changes: 4 additions & 6 deletions docs/src/color-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,13 @@ FadeVariables.propTypes = {
function Swatch(props) {
const {name, value, textColor = overlayColor(value), ...rest} = props
return (
<Box bg={value} {...rest}>
<Box bg={value} color={textColor} {...rest}>
<Text as={Flex} fontSize={1} justifyContent="space-between">
<Box p={3}>
<Var color={textColor}>${name}</Var>
<Var>${name}</Var>
</Box>
<Box p={3}>
<Text color={textColor} fontFamily="mono">
{value}
</Text>
<Text fontFamily="mono">{value}</Text>
</Box>
</Text>
</Box>
Expand All @@ -163,7 +161,7 @@ Swatch.propTypes = {

function Var(props) {
// FIXME: fontStyle should be a prop, right?
return <Text as="var" fontWeight="bold" fontFamily="mono" css={{fontStyle: 'normal'}} {...props} />
return <Text as="var" fontWeight="bold" fontFamily="mono" style={{fontStyle: 'normal'}} {...props} />
}

function overlayColor(bg) {
Expand Down

0 comments on commit aeca890

Please sign in to comment.