Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ComponentExample): title, desc, and icon alignments #549

Merged
merged 1 commit into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 48 additions & 43 deletions docs/app/Components/ComponentDoc/ComponentExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ import Editor from 'docs/app/Components/Editor/Editor'
import { getUnhandledProps } from 'src/lib'
import { Grid, Header, Icon, Divider } from 'stardust'

const showCodeStyle = {
position: 'absolute',
textAlign: 'right',
top: '1rem',
right: '1rem',
}

const descriptionStyle = {
marginRight: '5em',
}

const codeIconStyle = {
fontWeight: 'bold',
}

const titleStyle = {
marginBottom: 0,
}

/**
* Renders a `component` and the raw `code` that produced it.
* Allows toggling the the raw `code` code block.
Expand All @@ -22,7 +41,7 @@ export default class ComponentExample extends Component {

constructor(props, context) {
super(props, context)
this.state = { showCode: false }
this.state = { showCode: false, showHTML: false }
this.fileContents = props.exampleSrc || require(`!raw!docs/app/Examples/${props.examplePath}`)
this.component = exampleContext(`./${props.examplePath}.js`).default
}
Expand Down Expand Up @@ -83,48 +102,34 @@ export default class ComponentExample extends Component {
}

return (
<Grid style={style} divided={active}>
<Grid.Row columns={1}>
<Grid.Column>
<Grid>
<Grid.Column width={12}>
{title && <Header as='h3' style={{ marginBottom: 0 }}>{title}</Header>}
{description ? <p>{description}</p> : children}
</Grid.Column>
<Grid.Column width={4} textAlign='right'>
<Icon
link
bordered
name='code'
color={showCode ? 'green' : 'grey'}
onClick={this.toggleShowCode}
style={{ fontWeight: 'bold' }}
/>
<Icon
link
bordered
name='html5'
color={showHTML ? 'green' : 'grey'}
onClick={this.toggleShowHTML}
/>
</Grid.Column>
</Grid>
</Grid.Column>
{description && children && (
<Grid.Column>{children}</Grid.Column>
)}
</Grid.Row>
<Grid.Row>
<Grid.Column className={`rendered-example ${this.getKebabExamplePath()}`}>
{createElement(this.component, rest)}
</Grid.Column>
</Grid.Row>
{active && (
<Grid.Row columns='1'>
{this.renderCode()}
{this.renderHTML()}
</Grid.Row>
)}
<Grid style={style} divided={active} columns='1'>
<Grid.Column>
<div style={showCodeStyle}>
<Icon
link
bordered
name='code'
color={showCode ? 'green' : 'grey'}
onClick={this.toggleShowCode}
style={codeIconStyle}
/>
<Icon
link
bordered
name='html5'
color={showHTML ? 'green' : 'grey'}
onClick={this.toggleShowHTML}
/>
</div>
{title && <Header as='h3' style={titleStyle}>{title}</Header>}
{description && <p style={descriptionStyle}>{description}</p>}
{children}
</Grid.Column>
<Grid.Column className={`rendered-example ${this.getKebabExamplePath()}`}>
{createElement(this.component, rest)}
</Grid.Column>
{showCode && this.renderCode()}
{showHTML && this.renderHTML()}
</Grid>
)
}
Expand Down
18 changes: 9 additions & 9 deletions docs/app/Examples/collections/Form/Shorthand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,29 @@ const FormTypesExamples = () => (
<ExampleSection title='Shorthand'>
<ComponentExample
title='Form Sub Components'
description={[
'Render a Field containing a label and form control.',
'All form control components are available.',
].join(' ')}
examplePath='collections/Form/Shorthand/FormSubComponentControlExample'
>
<p>
Render a Field containing a label and form control.
All form control components are available.
</p>
<Compare { ...subComponentComparison } />
</ComponentExample>
<ComponentExample
title='Field with Custom Control'
description={[
'Render a Field containing a label and custom form control.',
'Use any component form any library, or your own.',
].join(' ')}
examplePath='collections/Form/Shorthand/FormFieldControlExample'
>
<p>
Render a Field containing a label and custom form control.
Use any component form any library, or your own.
</p>
<Compare { ...componentPropComparison } />
</ComponentExample>
<ComponentExample
title='Field with HTML Control'
description='The Field control prop also works with HTML tags'
examplePath='collections/Form/Shorthand/FormFieldControlHTMLExample'
>
<p>The Field control prop also works with HTML tags</p>
<Compare { ...htmlComparison } />
</ComponentExample>
</ExampleSection>
Expand Down