Skip to content

Commit

Permalink
checkbox add prop id
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeLin committed Aug 16, 2017
1 parent 4149c01 commit b7135ad
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
10 changes: 7 additions & 3 deletions components/Checkbox/Checkbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Checkbox extends PureComponent {
}

render() {
const { prefixCls, className, theme, type, value, block, disabled, children } = this.props;
const { prefixCls, className, theme, type, value, block, disabled, id, children } = this.props;
const { checked } = this.state;

const cls = classnames({
Expand Down Expand Up @@ -67,8 +67,12 @@ class Checkbox extends PureComponent {
<div className={cls}>
<div className={`${prefixCls}-wrapper`}>
<span className={`${prefixCls}-inner`} />
<span className={`${prefixCls}-text`}>{children}</span>
<input type="checkbox" className={`${prefixCls}-input`} disabled={disabled} checked={checked} onChange={this.onValueChange} />
{
children
? <span className={`${prefixCls}-text`}>{children}</span>
: null
}
<input id={id} type="checkbox" className={`${prefixCls}-input`} disabled={disabled} checked={checked} onChange={this.onValueChange} />
</div>
</div>
);
Expand Down
11 changes: 8 additions & 3 deletions docs/zh-cn/components/Checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ import { Checkbox } from 'zarm';

```jsx
<Checkbox.Group
value={this.state.checkbox}
onChange={value => console.log(`checkbox to ${value}`)}>
value={this.state.value}
onChange={value => {
this.setState({
value,
})
}}>
<Checkbox value="0">选项一</Checkbox>
<Checkbox value="1">选项二</Checkbox>
<Checkbox value="2">选项三</Checkbox>
Expand Down Expand Up @@ -139,10 +143,11 @@ import { Checkbox } from 'zarm';
| className | string || | 追加类名 |
| theme | string | primary | 'default', 'primary', 'info', 'success', 'warning', 'error' | 主题 |
| type | string || 'button', 'cell' | 显示类型 |
| value | array | [] | | 选中值 |
| shape | string || 'radius', 'round' | 形状 |
| block | bool | false | | 是否为块级元素 |
| disabled | bool | false | | 是否禁用 |
| onChange | func | noop | \(value: string, number\) | 值变化时触发的回调函数 |
| onChange | func | noop | \(value: array\) | 值变化时触发的回调函数 |



4 changes: 3 additions & 1 deletion examples/pages/CheckboxPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class Page extends PureComponent {
<Panel.Title>基本用法</Panel.Title>
</Panel.Header>
<Panel.Body>
<Cell><Checkbox onChange={checked => console.log(`checkbox to ${checked}`)}>单独使用</Checkbox></Cell>
<Cell>
<Checkbox onChange={checked => console.log(`checkbox to ${checked}`)}>单独使用</Checkbox>
</Cell>

<Cell
description={
Expand Down
22 changes: 16 additions & 6 deletions styles/components/Checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ $prefixCls: za-checkbox;
}

&-text {
color: #333;
}

&-inner + &-text {
margin-left: r(5);
}

Expand Down Expand Up @@ -122,13 +126,19 @@ $prefixCls: za-checkbox;

/* 禁用状态 */
&.disabled {
.#{$prefixCls}-inner {
border-color: #d9d9d9;
background-color: #f3f3f3;
cursor: not-allowed;
.#{$prefixCls} {
&-inner {
border-color: #d9d9d9;
background-color: #f3f3f3;
cursor: not-allowed;

&:before {
border-color: #ccc;
}
}

&:before {
border-color: #ccc;
&-text {
opacity: 0.5;
}
}
}
Expand Down

0 comments on commit b7135ad

Please sign in to comment.