Skip to content

Commit d494687

Browse files
committed
expose module settings as props, add example, update guidelines
1 parent e71a671 commit d494687

7 files changed

Lines changed: 83 additions & 60 deletions

File tree

docs/app/Component Guidelines.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,38 @@ They ensure consistency and optimal development experience for Stardust users.
1717

1818
### Modules
1919

20-
Semantic UI [Modules](http://semantic-ui.com/introduction/glossary.html) are components that include a jQuery plugin.
20+
Semantic UI [Modules](http://semantic-ui.com/introduction/glossary.html) are components that define appearance and behavior.
2121
These are things that have state, like a [Dropdown](http://semantic-ui.com/modules/dropdown.html).
22+
They usually require a Semantic UI jQuery plugin.
2223

23-
**Element**
24-
Stardust components expose the jQuery element on the component as `element`:
24+
All the appropriate lifecycle work is handled. You can just use the module.
25+
26+
**Settings**
27+
Semantic UI's jQuery plugin settings are exposed as props:
2528

2629
```jsx
27-
let checkbox = <Checkbox />;
28-
checkbox.element; // the jQuery element
30+
<Checkbox onChange={this.handleChange} />; // the Semantic UI change callback
2931
```
32+
>Settings are applied on componentDidMount.
3033
3134
**Plugin**
32-
The Semantic UI jQuery plugin can be accessed using `element`:
33-
34-
```jsx
35-
let checkbox = <Checkbox />;
36-
checkbox.element.checkbox(); // the Semantic UI Checkbox plugin
37-
```
38-
You can also trigger behaviors with the plugin:
35+
Stardust exposes the Semantic UI jQuery plugin as `plugin`. Use it to trigger behaviors:
3936

4037
```jsx
41-
let checkbox = <Checkbox />;
42-
checkbox.element.checkbox('toggle'); // toggles the checkbox
38+
<Checkbox ref='checkbox' />;
39+
// ...
40+
this.refs.checkbox.plugin('toggle'); // toggles the checkbox
41+
this.refs.checkbox.plugin('is checked'); // get the state
4342
```
4443

45-
**Settings**
46-
Module jQuery plugins can be configured via the `settings` prop:
44+
**Element**
45+
Stardust components expose the jQuery element as `element`:
4746

4847
```jsx
49-
let settings = {allowAdditions: true};
50-
let dropdown = <Dropdown settings={settings}/>;
48+
<Checkbox ref='checkbox' ref='checkbox' />;
49+
// then
50+
this.refs.checkbox.element; // the jQuery element
5151
```
52-
>Settings are applied on componentDidMount.
5352

5453
## Classes
5554

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React, {Component} from 'react';
2+
import {Button, Checkbox} from 'stardust';
3+
4+
export default class CheckboxRemoteControlExample extends Component {
5+
state = {checked: false};
6+
7+
toggle = () => {
8+
this.refs.checkbox.plugin('toggle');
9+
};
10+
11+
handleChange = () => {
12+
this.setState({
13+
checked: this.refs.checkbox.plugin('is checked')
14+
});
15+
};
16+
17+
render() {
18+
return (
19+
<div>
20+
<Button onClick={this.toggle}>Toggle it</Button>
21+
<Checkbox label='Check this box' onChange={this.handleChange} ref='checkbox' />
22+
<p>It is {!this.state.checked && 'not '}checked.</p>
23+
</div>
24+
);
25+
}
26+
}

docs/app/Examples/modules/Checkbox/States/States.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class CheckboxStatesExamples extends Component {
1212
description='A checkbox can come pre-checked'
1313
examplePath='modules/Checkbox/States/Checked'
1414
>
15-
<Message className='info'>
15+
<Message>
1616
Use
1717
&nbsp;
1818
<a href='https://facebook.github.io/react/docs/forms.html#default-value' target='_blank'>
@@ -32,6 +32,11 @@ export default class CheckboxStatesExamples extends Component {
3232
description='Make the checkbox unable to be edited by the user'
3333
examplePath='modules/Checkbox/States/ReadOnly'
3434
/>
35+
<ComponentExample
36+
title='Remote Control'
37+
description='You can trigger events remotely.'
38+
examplePath='modules/Checkbox/States/CheckboxRemoteControlExample'
39+
/>
3540
</ExampleSection>
3641
);
3742
}
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
import React, {Component} from 'react';
2-
import {Button, Checkbox} from 'stardust';
2+
import {Checkbox} from 'stardust';
33

44
export default class CheckboxCheckboxExample extends Component {
5-
toggle = () => {
6-
this.refs.checkbox.plugin('toggle');
7-
};
8-
9-
handleChange(e) {
10-
console.log('it change');
11-
console.log(e);
12-
}
13-
145
render() {
156
return (
16-
<div>
17-
<Button onClick={this.toggle}>Toggle it!</Button>
18-
<Checkbox label='Make my profile visible' ref='checkbox' onChange={this.handleChange}/>
19-
</div>
7+
<Checkbox label='Make my profile visible' />
208
);
219
}
2210
}

docs/app/Examples/modules/Checkbox/Variations/Variations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class CheckboxVariationsExamples extends Component {
1515
<Message>
1616
The&nbsp;
1717
<a href='http://semantic-ui.com/modules/checkbox.html#fitted' target='_blank'>
18-
fitted
18+
<code>fitted</code>
1919
</a>
2020
&nbsp;class is automatically applied if there is no <code>label</code> prop.
2121
</Message>

src/modules/Checkbox/Checkbox.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,41 @@ import $ from 'jquery';
77

88
export default class Checkbox extends Component {
99
static propTypes = {
10+
beforeChecked: PropTypes.func,
11+
beforeDeterminate: PropTypes.func,
12+
beforeIndeterminate: PropTypes.func,
13+
beforeUnchecked: PropTypes.func,
1014
className: PropTypes.string,
1115
label: PropTypes.string,
12-
name: PropTypes.string,
13-
settings: PropTypes.object,
16+
onChange: PropTypes.func,
17+
onChecked: PropTypes.func,
18+
onDeterminate: PropTypes.func,
19+
onDisable: PropTypes.func,
20+
onEnable: PropTypes.func,
21+
onIndeterminate: PropTypes.func,
22+
onUnchecked: PropTypes.func,
1423
type: PropTypes.string,
1524
};
1625

17-
state = {checked: false};
26+
static defaultProps = {
27+
type: 'checkbox'
28+
};
1829

1930
componentDidMount() {
2031
this.element = $(this.refs.element);
21-
// this.element.checkbox(this.props.settings);
32+
this.element.checkbox({
33+
onChange: this.props.onChange,
34+
onChecked: this.props.onChecked,
35+
onIndeterminate: this.props.onIndeterminate,
36+
onDeterminate: this.props.onDeterminate,
37+
onUnchecked: this.props.onUnchecked,
38+
beforeChecked: this.props.beforeChecked,
39+
beforeIndeterminate: this.props.beforeIndeterminate,
40+
beforeDeterminate: this.props.beforeDeterminate,
41+
beforeUnchecked: this.props.beforeUnchecked,
42+
onEnable: this.props.onEnable,
43+
onDisable: this.props.onDisable,
44+
});
2245
}
2346

2447
componentWillUnmount() {
@@ -32,16 +55,13 @@ export default class Checkbox extends Component {
3255
};
3356

3457
plugin() {
35-
this.element.checkbox(...arguments);
58+
return this.element.checkbox(...arguments);
3659
}
3760

3861
render() {
3962
let type = this.props.type;
40-
if (!type) {
41-
type = 'checkbox';
42-
if (_.includes(this.props.className, 'radio')) {
43-
type = 'radio';
44-
}
63+
if (_.includes(this.props.className, 'radio')) {
64+
type = 'radio';
4565
}
4666
const classes = classNames(
4767
'sd-checkbox',

test/specs/Conformance-test.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,6 @@ describe('Conformance', () => {
126126
.indexOf(sdClass).should.equal(0);
127127
});
128128
}
129-
130-
if (META.isModule(SDComponent) && !META.isChild(SDComponent)) {
131-
describe('settings', () => {
132-
it('is defined in propTypes', () => {
133-
SDComponent.propTypes.settings.should.be.a('function');
134-
});
135-
it('is not spread', () => {
136-
const props = {settings: {}};
137-
render(<SDComponent {...props} />)
138-
.children()
139-
.some(element => _.has(element.props, 'settings'))
140-
.should.equal(false);
141-
});
142-
});
143-
}
144129
});
145130
});
146131
});

0 commit comments

Comments
 (0)