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

feat(Form): update to v1 API #400

Merged
merged 13 commits into from
Sep 1, 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
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,19 @@ Once you change the flag, you need to refresh your browser to see the changes in

## How Can I Help?

Our [CONTRIBUTING.md][1] is a step-by-step setup and development guide. It is meant to be read from top to bottom. Once you're up to speed, we have two areas of focus:
Our [CONTRIBUTING.md][1] is a step-by-step setup and development guide. It is meant to be read from top to bottom. Once you're up to speed, each issue here includes more information on how you can help:

### v1.0 Migrations
### [v1.0 Migrations][15]

Each issue includes more information on how you can help:
Have a look at the task list on the issue to see where you can jump in.

1. [Moving legacy component APIs to our v1 API][15]
1. [Removing jQuery and SUI JS][11]
### [Missing Components][17]

### New Components
We're seeking component parity with Semantic UI, plus some addons. There is an issue for every missing component, labeled [`enhancement` `help wanted`][17]. Just comment on the issue you'd like to take.

We're seeking component parity with Semantic UI, plus some addons. There is an issue for every missing component, labeled [`enhancement` `help wanted`][17].
### [Help Wanted Label][4]

Any other issue labeled [`help wanted`][4] is ready for a PR.

## Our Principles

Expand Down Expand Up @@ -167,7 +168,7 @@ Made with :heart: [@TechnologyAdvice][9], a ridiculous [place to work][16].
[1]: /~https://github.com/TechnologyAdvice/stardust/blob/master/CONTRIBUTING.md
[2]: https://technologyadvice.github.io/stardust/
[3]: https://facebook.github.io/react/
[4]: #
[4]: /~https://github.com/TechnologyAdvice/stardust/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted
[5]: http://semantic-ui.com/
[6]: /~https://github.com/TechnologyAdvice/stardust/milestone/1
[7]: /~https://github.com/webpack/webpack-dev-server/
Expand Down
11 changes: 7 additions & 4 deletions docs/app/Components/ComponentDoc/ComponentExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { getUnhandledProps } from 'src/lib'
import { Grid, Header, Icon } from 'stardust'

const codeIconStyle = {
position: 'absolute',
top: '0.6em',
right: '0.5em',
fontSize: '1.5em',
fontWeight: 'bold',
}
Expand All @@ -17,10 +20,10 @@ const codeIconStyle = {
export default class ComponentExample extends Component {
static propTypes = {
children: PropTypes.node,
description: PropTypes.string,
description: PropTypes.node,
examplePath: PropTypes.string.isRequired,
exampleSrc: PropTypes.node,
title: PropTypes.string,
title: PropTypes.node,
}

constructor(props, context) {
Expand Down Expand Up @@ -57,14 +60,14 @@ export default class ComponentExample extends Component {
<Grid>
<Grid.Column width={12}>
{title && <Header as='h3' style={{ marginBottom: 0 }}>{title}</Header>}
{description && <p>{description}</p>}
{description ? <p>{description}</p> : children}
</Grid.Column>
<Grid.Column width={4} textAlign='right'>
<Icon name='code link' color='grey' onClick={this.toggleShowCode} style={codeIconStyle} />
</Grid.Column>
</Grid>
</Grid.Column>
{children && <Grid.Column>{children}</Grid.Column>}
{description && children && <Grid.Column>{children}</Grid.Column>}
<Grid.Column className='rendered-example'>
{createElement(this.component, rest)}
</Grid.Column>
Expand Down
2 changes: 1 addition & 1 deletion docs/app/Components/ComponentDoc/ComponentExamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class ComponentExamples extends Component {
<Message.Content>
If there's no
<a href='/~https://github.com/TechnologyAdvice/stardust/pulls'> pull request </a>
open for <code>&lt;{name} /&gt;</code> examples, you should
open for <code>{`<${name} />`}</code> examples, you should
<a href='/~https://github.com/TechnologyAdvice/stardust/blob/master/CONTRIBUTING.md'> contribute</a>!
</Message.Content>
</Message>
Expand Down
9 changes: 7 additions & 2 deletions docs/app/Components/ComponentDoc/ComponentProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ export default class ComponentProps extends Component {
}
}
defaultValueRenderer = (item) => {
const defaultValue = _.get(item, 'defaultValue.value')
let defaultValue = _.get(item, 'defaultValue.value')

if (_.startsWith(defaultValue, 'function ')) {
defaultValue = defaultValue.match(/^function(.*)\{/)[1].trim()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to get the function name? If I'm reading it correctly, seems like you could also do:

if (typeof defaultValue === 'function') {
  defaultValue = defaultValue.name
}

I could be totally reading this wrong, so ignore if that's the case.

Copy link
Member Author

@levithomason levithomason Aug 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are half correct, this is to get the function name. However, the defaultValue here is a json representation of the function from react-docgen. The defaultValue is the actual function stringified.

See "value": "function formSerializer(formNode) {\n debug('formSerializer...:

"serializer": {
  "type": {
    "name": "func"
  },
  "required": false,
  "defaultValue": {
    "value": "function formSerializer(formNode) {\n  debug('formSerializer()')\n  const json = {}\n  // handle empty formNode ref\n  if (!formNode) return json\n\n  // ----------------------------------------\n  // Checkboxes\n  // Single: { name: value|bool        }\n  // Group:  { name: [value|bool, ...] }\n\n  _.each(formNode.querySelectorAll('input[type=\"checkbox\"]'), (node, index, arr) => {\n    const name = getNodeName(node)\n    const checkboxesByName = _.filter(arr, { name })\n\n    // single: (value|checked)\n    if (checkboxesByName.length === 1) {\n      json[name] = node.checked && node.value !== 'on' ? node.value : node.checked\n      debugSerializedResult(json, name, node)\n      return\n    }\n\n    // groups (checked): [value, ...]\n    if (!Array.isArray(json[name])) json[name] = []\n    if (node.checked) json[name].push(node.value)\n    debugSerializedResult(json, name, node)\n\n    // in dev, warn about multiple checkboxes with a default browser value of \"on\"\n    if (process.NODE_ENV !== 'production' && node.value === 'on') {\n      const errorMessage = [\n        \"Encountered a checkbox in a group with the default browser value 'on'.\",\n        'Each checkbox in a group should have a unique value.',\n        \"Otherwise, the checkbox value will serialize as ['on', ...].\",\n      ].join(' ')\n      console.error(errorMessage, node, formNode) // eslint-disable-line no-console\n    }\n  })\n\n  // ----------------------------------------\n  // Radios\n  // checked: { name: checked value }\n  // none:    { name: null }\n\n  _.each(formNode.querySelectorAll('input[type=\"radio\"]'), (node, index, arr) => {\n    const name = getNodeName(node)\n    const checkedRadio = _.find(arr, { name, checked: true })\n\n    if (checkedRadio) {\n      json[name] = checkedRadio.value\n    } else {\n      json[name] = null\n    }\n\n    debugSerializedResult(json, name, node)\n\n    // in dev, warn about radios with a default browser value of \"on\"\n    if (process.NODE_ENV !== 'production' && node.value === 'on') {\n      const errorMessage = [\n        \"Encountered a radio with the default browser value 'on'.\",\n        'Each radio should have a unique value.',\n        \"Otherwise, the radio value will serialize as { [name]: 'on' }.\",\n      ].join(' ')\n      console.error(errorMessage, node, formNode) // eslint-disable-line no-console\n    }\n  })\n\n  // ----------------------------------------\n  // Other inputs\n  // { name: value }\n\n  _.each(formNode.querySelectorAll('input:not([type=\"radio\"]):not([type=\"checkbox\"])'), (node) => {\n    const name = getNodeName(node)\n    json[name] = node.value\n    debugSerializedResult(json, name, node)\n  })\n\n  // ----------------------------------------\n  // Other inputs and text areas\n  // { name: value }\n\n  _.each(formNode.querySelectorAll('textarea'), (node) => {\n    const name = getNodeName(node)\n    json[name] = node.value\n    debugSerializedResult(json, name, node)\n  })\n\n  // ----------------------------------------\n  // Selects\n  // single:   { name: value }\n  // multiple: { name: [value, ...] }\n\n  _.each(formNode.querySelectorAll('select'), (node) => {\n    const name = getNodeName(node)\n\n    if (node.multiple) {\n      json[name] = _.map(_.filter(node.querySelectorAll('option'), 'selected'), 'value')\n    } else {\n      json[name] = node.value\n    }\n\n    debugSerializedResult(json, name, node)\n  })\n\n  return json\n}",
    "computed": false
  },
  "docBlock": {
    "description": "Called onSubmit with the form node that returns the serialized form object",
    "tags": []
  }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, makes sense. Thanks for the explanation. Comment resolved.

}

const defaultIsComputed = <span className='ui mini gray circular label'>computed</span>

return (
Expand Down Expand Up @@ -62,7 +67,7 @@ export default class ComponentProps extends Component {
return (
<div>
<Table data={content} className='very basic compact'>
<Table.Column dataKey='name' cellRenderer={this.nameRenderer} />
<Table.Column dataKey='Prop' cellRenderer={this.nameRenderer} />
<Table.Column cellRenderer={this.requiredRenderer} />
<Table.Column dataKey='type' />
<Table.Column dataKey='defaultValue' cellRenderer={this.defaultValueRenderer} />
Expand Down
2 changes: 1 addition & 1 deletion docs/app/Components/Sidebar/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MenuItem.defaultProps = {
activeClassName: 'active',
className: 'item',
}
const selectedItemLabel = <span style={{ color: '#4db', float: 'right' }}>Press Enter</span>
const selectedItemLabel = <span style={{ color: '#35bdb2', float: 'right' }}>Press Enter</span>

export default class Sidebar extends Component {
static contextTypes = {
Expand Down
4 changes: 2 additions & 2 deletions docs/app/Examples/addons/Radio/States/Disabled.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react'
import { Form, Radio, Field } from 'stardust'
import { Form, Radio } from 'stardust'

const RadioDisabledExample = () => (
<Form>
<Form.Field>
<Radio label='Disabled' disabled />
</Form.Field>
<Form.Field>
<Radio type='toggle' label='Disabled' disabled />
<Radio toggle label='Disabled' disabled />
</Form.Field>
</Form>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class RadioRemoteControlExample extends Component {
</Button>
<Radio
label='Check this radio'
onClick={this.toggle}
onChange={this.toggle}
checked={this.state.checked}
/>
</div>
Expand Down
6 changes: 3 additions & 3 deletions docs/app/Examples/addons/Radio/Types/RadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Form, Radio } from 'stardust'

export default class RadioGroupExample extends Component {
state = {}
handleClick = (e, { value }) => this.setState({ value })
handleChange = (e, { value }) => this.setState({ value })

render() {
return (
Expand All @@ -17,7 +17,7 @@ export default class RadioGroupExample extends Component {
name='radioGroup'
value='this'
checked={this.state.value === 'this'}
onClick={this.handleClick}
onChange={this.handleChange}
/>
</Form.Field>
<Form.Field>
Expand All @@ -26,7 +26,7 @@ export default class RadioGroupExample extends Component {
name='radioGroup'
value='that'
checked={this.state.value === 'that'}
onClick={this.handleClick}
onChange={this.handleChange}
/>
</Form.Field>
</Form>
Expand Down
2 changes: 1 addition & 1 deletion docs/app/Examples/addons/Radio/Types/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Radio } from 'stardust'

const RadioSliderExample = () => (
<Radio type='slider' />
<Radio slider />
)

export default RadioSliderExample
2 changes: 1 addition & 1 deletion docs/app/Examples/addons/Radio/Types/Toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Radio } from 'stardust'

const RadioToggleExample = () => (
<Radio type='toggle' />
<Radio toggle />
)

export default RadioToggleExample
11 changes: 10 additions & 1 deletion docs/app/Examples/addons/Radio/Types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react'
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'

import { Message } from 'src'

const RadioTypesExamples = () => (
<ExampleSection title='Types'>
<ComponentExample
Expand All @@ -23,7 +25,14 @@ const RadioTypesExamples = () => (
title='Radio Group'
description='Radios can be part of a group.'
examplePath='addons/Radio/Types/RadioGroup'
/>
>
<Message warning>
Radios in a group must be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&nbsp; should probably be after the be? Otherwise it doesn't achieve anything different than a {' ' }.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware of the differences between those, though the spaced string did give issues elsewhere.

Since space is removed between components that are separated by a new line, and the component's content should always be one space away from adjacent text, I've opted to include &nbsp; inside of components. This way, no matter where the components are moved the spacing is correct without having to add/remove spacing elements every time you move the component.

<a href='https://facebook.github.io/react/docs/forms.html#controlled-components' target='_blank'>
&nbsp;controlled components.
</a>
</Message>
</ComponentExample>
</ExampleSection>
)

Expand Down
4 changes: 2 additions & 2 deletions docs/app/Examples/addons/Radio/Variations/Fitted.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const RadioFittedExample = () => (
<Radio />
</Segment>
<Segment className='compact'>
<Radio type='slider' />
<Radio slider />
</Segment>
<Segment className='compact'>
<Radio type='toggle' />
<Radio toggle />
</Segment>
</div>
)
Expand Down
25 changes: 12 additions & 13 deletions docs/app/Examples/collections/Form/Content/FormFieldExample.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, { Component } from 'react'
import { Form, Input } from 'stardust'
import React from 'react'
import { Form } from 'stardust'

export default class FormFieldExample extends Component {
render() {
return (
<Form>
<Form.Field label='User Input'>
<Input placeholder='User Input' />
</Form.Field>
</Form>
)
}
}
const FormFieldExample = () => (
<Form>
<Form.Field>
<label>User Input</label>
<input />
</Form.Field>
</Form>
)

export default FormFieldExample
25 changes: 11 additions & 14 deletions docs/app/Examples/collections/Form/Content/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import React, { Component } from 'react'
import React from 'react'
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'

export default class FormTypesExamples extends Component {
render() {
return (
<ExampleSection title='Content'>
<ComponentExample
title='Field'
description='A field is a form element containing a label and an input.'
examplePath='collections/Form/Content/FormFieldExample'
/>
</ExampleSection>
)
}
}
const FormTypesExamples = () => (
<ExampleSection title='Content'>
<ComponentExample
title='Field'
description='A field is a form element containing a label and an input.'
examplePath='collections/Form/Content/FormFieldExample'
/>
</ExampleSection>
)
export default FormTypesExamples
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, { Component } from 'react'
import React from 'react'
import { Form, Input } from 'stardust'

export default class FormFieldInlineExample extends Component {
render() {
return (
<Form>
<Form.Field label='First name' className='inline'>
<Input placeholder='First name' />
</Form.Field>
</Form>
)
}
}
const FormFieldInlineExample = () => (
<Form>
<Form.Field inline>
<label>First name</label>
<Input placeholder='First name' />
</Form.Field>
</Form>
)

export default FormFieldInlineExample
26 changes: 12 additions & 14 deletions docs/app/Examples/collections/Form/FieldVariations/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React, { Component } from 'react'
import React from 'react'
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'

export default class FormFieldVariationsExamples extends Component {
render() {
return (
<ExampleSection title='Field Variations'>
<ComponentExample
title='Inline'
description='A field can have its label next to instead of above it.'
examplePath='collections/Form/FieldVariations/FormFieldInlineExample'
/>
</ExampleSection>
)
}
}
const FormFieldVariationsExamples = () => (
<ExampleSection title='Field Variations'>
<ComponentExample
title='Inline'
description='A field can have its label next to instead of above it.'
examplePath='collections/Form/FieldVariations/FormFieldInlineExample'
/>
</ExampleSection>
)

export default FormFieldVariationsExamples
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import React, { Component } from 'react'
import React from 'react'
import { Form, Input } from 'stardust'

export default class FormGroupEvenlyDividedExample extends Component {
render() {
return (
<Form>
<Form.Fields evenlyDivided>
<Form.Field label='First name'>
<Input placeholder='First name' />
</Form.Field>
<Form.Field label='Last name'>
<Input placeholder='Last name' />
</Form.Field>
</Form.Fields>
</Form>
)
}
}
const FormGroupEvenlyDividedExample = () => (
<Form>
<Form.Group widths='equal'>
<Form.Field>
<label>First name</label>
<Input placeholder='First name' />
</Form.Field>
<Form.Field>
<label>Last name</label>
<Input placeholder='Last name' />
</Form.Field>
</Form.Group>
</Form>
)

export default FormGroupEvenlyDividedExample
Loading