-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Checkbox plugin #80
Checkbox plugin #80
Changes from all commits
f6736d6
0f78523
56ac691
d4d3298
85deadb
b72f62d
69b4737
e71a671
d494687
08dd84a
b2b347e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
{ | ||
"extends": "ta-webapp", | ||
"env": { | ||
"node": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import exampleContext from 'docs/app/utils/ExampleContext'; | |
*/ | ||
export default class ComponentExample extends Component { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
description: PropTypes.string, | ||
examplePath: PropTypes.string.isRequired, | ||
title: PropTypes.string, | ||
|
@@ -17,11 +18,21 @@ export default class ComponentExample extends Component { | |
state = {showCode: false}; | ||
fileContents = require(`!raw!docs/app/Examples/${this.props.examplePath}`); | ||
component = exampleContext(`./${this.props.examplePath}.js`); | ||
// 'elements/Button/Types/Button' => #Button-Types-Button | ||
anchor = this.props.examplePath.split('/').slice(1).join('-'); | ||
|
||
toggleShowCode = () => { | ||
this.setState({showCode: !this.state.showCode}); | ||
}; | ||
|
||
handleMouseEnter = () => { | ||
this.setState({showLink: true}); | ||
}; | ||
|
||
handleMouseLeave = () => { | ||
this.setState({showLink: false}); | ||
}; | ||
|
||
render() { | ||
const code = ( | ||
<Column> | ||
|
@@ -31,13 +42,28 @@ export default class ComponentExample extends Component { | |
</Column> | ||
); | ||
|
||
const linkIconStyle = { | ||
display: this.state.showLink ? 'inline-block' : 'none', | ||
marginLeft: '0.25em', | ||
}; | ||
|
||
const children = <Column>{this.props.children}</Column>; | ||
|
||
return ( | ||
<Grid className='one column' style={{marginBottom: '4em'}}> | ||
<Grid className='one column' style={{marginBottom: '4em'}} id={this.anchor}> | ||
<Column> | ||
<Grid> | ||
<Column width={12}> | ||
<h3 className='ui header' style={{marginBottom: 0}}> | ||
<h3 | ||
className='ui header' | ||
style={{marginBottom: 0}} | ||
onMouseEnter={this.handleMouseEnter} | ||
onMouseLeave={this.handleMouseLeave} | ||
> | ||
{this.props.title} | ||
<a href={`#${this.anchor}`}> | ||
<i className='linkify icon' style={linkIconStyle} /> | ||
</a> | ||
</h3> | ||
<p>{this.props.description}</p> | ||
</Column> | ||
|
@@ -49,7 +75,7 @@ export default class ComponentExample extends Component { | |
</Column> | ||
</Grid> | ||
</Column> | ||
|
||
{this.props.children && children} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now render children so we can add |
||
<Column> | ||
{createElement(this.component)} | ||
</Column> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, {Component} from 'react'; | ||
import {Button, Checkbox} from 'stardust'; | ||
|
||
export default class CheckboxRemoteControlExample extends Component { | ||
toggle = () => { | ||
this.refs.checkbox.plugin('toggle'); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we going to include these methods inside the stardust docs? Or just refer them to the semantic docs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup! |
||
|
||
render() { | ||
return ( | ||
<div> | ||
<Button onClick={this.toggle}>Toggle it</Button> | ||
<Checkbox label='Check this box' ref='checkbox' /> | ||
</div> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,8 @@ | ||
import React, {Component} from 'react'; | ||
import React from 'react'; | ||
import {Checkbox} from 'stardust'; | ||
|
||
export default class CheckboxCheckedExample extends Component { | ||
state = {isChecked: true}; | ||
|
||
handleChange = e => { | ||
this.setState({ | ||
isChecked: !this.state.isChecked | ||
}); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<Checkbox label='This checkbox comes prechecked' checked={this.state.isChecked} onChange={this.handleChange} /> | ||
); | ||
} | ||
} | ||
export default CheckboxCheckedExample => { | ||
return ( | ||
<Checkbox defaultChecked label='This checkbox comes prechecked' /> | ||
); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To check a checkbox, just set the React |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import React, {Component} from 'react'; | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'; | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'; | ||
import {Message} from 'stardust'; | ||
|
||
export default class CheckboxStatesExamples extends Component { | ||
render() { | ||
|
@@ -10,7 +11,17 @@ export default class CheckboxStatesExamples extends Component { | |
title='Checked' | ||
description='A checkbox can come pre-checked' | ||
examplePath='modules/Checkbox/States/Checked' | ||
/> | ||
> | ||
<Message> | ||
Use | ||
| ||
<a href='https://facebook.github.io/react/docs/forms.html#default-value' target='_blank'> | ||
<code>defaultChecked</code> | ||
</a> | ||
| ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous. |
||
as you normally would to set default form values. | ||
</Message> | ||
</ComponentExample> | ||
<ComponentExample | ||
title='Disabled' | ||
description='Checkboxes can be disabled' | ||
|
@@ -21,6 +32,11 @@ export default class CheckboxStatesExamples extends Component { | |
description='Make the checkbox unable to be edited by the user' | ||
examplePath='modules/Checkbox/States/ReadOnly' | ||
/> | ||
<ComponentExample | ||
title='Remote Control' | ||
description='You can trigger events remotely.' | ||
examplePath='modules/Checkbox/States/CheckboxRemoteControlExample' | ||
/> | ||
</ExampleSection> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,13 @@ export default class CheckboxFittedExample extends Component { | |
return ( | ||
<div> | ||
<Segment className='compact'> | ||
<Checkbox className='fitted' /> | ||
<Checkbox /> | ||
</Segment> | ||
<Segment className='compact'> | ||
<Checkbox className='fitted slider' /> | ||
<Checkbox className='slider' /> | ||
</Segment> | ||
<Segment className='compact'> | ||
<Checkbox className='fitted toggle' /> | ||
<Checkbox className='toggle' /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
</Segment> | ||
</div> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import React, {Component} from 'react'; | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'; | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'; | ||
import {Message} from 'stardust'; | ||
|
||
export default class CheckboxVariationsExamples extends Component { | ||
render() { | ||
|
@@ -10,7 +11,15 @@ export default class CheckboxVariationsExamples extends Component { | |
title='Fitted' | ||
description='A fitted checkbox does not leave padding for a label' | ||
examplePath='modules/Checkbox/Variations/Fitted' | ||
/> | ||
> | ||
<Message> | ||
The | ||
<a href='http://semantic-ui.com/modules/checkbox.html#fitted' target='_blank'> | ||
<code>fitted</code> | ||
</a> | ||
class is automatically applied if there is no <code>label</code> prop. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, React removes all whitespace regardless of how many blank lines (unlike html). So, there is no space between words/components without this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Crazy! Good to know |
||
</Message> | ||
</ComponentExample> | ||
</ExampleSection> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,9 @@ gulp.task('generate-docs-json', cb => { | |
paths.srcViews + '/**/*.js', | ||
'!' + paths.src + '/**/Style.js' | ||
]) | ||
.pipe(g.plumber(err => { | ||
// do not remove the function keyword | ||
// we need 'this' scope here | ||
.pipe(g.plumber(function(err) { | ||
g.util.log(err); | ||
this.emit('end'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was why watchers we dying on jsx parse error again. |
||
})) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import _ from 'lodash'; | ||
import META from 'src/utils/Meta'; | ||
import getUnhandledProps from 'src/utils/getUnhandledProps'; | ||
import React, {Component, PropTypes} from 'react'; | ||
import classNames from 'classnames'; | ||
import $ from 'jquery'; | ||
|
@@ -10,14 +11,8 @@ export default class Checkbox extends Component { | |
beforeDeterminate: PropTypes.func, | ||
beforeIndeterminate: PropTypes.func, | ||
beforeUnchecked: PropTypes.func, | ||
className: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.array, | ||
PropTypes.object, | ||
]), | ||
defaultChecked: PropTypes.bool, | ||
className: PropTypes.string, | ||
label: PropTypes.string, | ||
name: PropTypes.string, | ||
onChange: PropTypes.func, | ||
onChecked: PropTypes.func, | ||
onDeterminate: PropTypes.func, | ||
|
@@ -28,11 +23,13 @@ export default class Checkbox extends Component { | |
type: PropTypes.string, | ||
}; | ||
|
||
componentDidMount() { | ||
this.container = $(this.refs.container); | ||
this.input = $(this.refs.input); | ||
static defaultProps = { | ||
type: 'checkbox' | ||
}; | ||
|
||
this.container.checkbox({ | ||
componentDidMount() { | ||
this.element = $(this.refs.element); | ||
this.element.checkbox({ | ||
onChange: this.props.onChange, | ||
onChecked: this.props.onChecked, | ||
onIndeterminate: this.props.onIndeterminate, | ||
|
@@ -48,7 +45,7 @@ export default class Checkbox extends Component { | |
} | ||
|
||
componentWillUnmount() { | ||
this.container.off(); | ||
this.element.off(); | ||
} | ||
|
||
static _meta = { | ||
|
@@ -57,16 +54,15 @@ export default class Checkbox extends Component { | |
type: META.type.module, | ||
}; | ||
|
||
plugin() { | ||
return this.element.checkbox(...arguments); | ||
} | ||
|
||
render() { | ||
let type = this.props.type; | ||
|
||
if (!type) { | ||
type = 'checkbox'; | ||
if (_.includes(this.props.className, 'radio')) { | ||
type = 'radio'; | ||
} | ||
if (_.includes(this.props.className, 'radio')) { | ||
type = 'radio'; | ||
} | ||
|
||
const classes = classNames( | ||
'sd-checkbox', | ||
'ui', | ||
|
@@ -76,12 +72,10 @@ export default class Checkbox extends Component { | |
{fitted: !this.props.label}, | ||
'checkbox' | ||
); | ||
|
||
const checkboxProps = _.clone(this.props); | ||
delete checkboxProps.className; | ||
const props = getUnhandledProps(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hadn't seen this utility before! NEATO! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a newer util. Gets all props not defined in propTypes nor defaultProps. |
||
return ( | ||
<div className={classes} ref='container'> | ||
<input {...checkboxProps} type={type} ref='checkbox' /> | ||
<div className={classes} ref='element'> | ||
<input {...props} type={type} /> | ||
<label>{this.props.label}</label> | ||
</div> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specific examples now have links on hover: