Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
improve: 给表单组件加静态setValue方法
Browse files Browse the repository at this point in the history
  • Loading branch information
shenlq committed Oct 11, 2016
1 parent 9674765 commit ca3525a
Show file tree
Hide file tree
Showing 19 changed files with 189 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-impression",
"version": "0.4.17",
"version": "0.5.0",
"author": "peter.shenlq",
"description": "An enterprise-class UI design language and React-based implementation.",
"main": "./lib/index.js",
Expand Down
11 changes: 10 additions & 1 deletion site/src/scripts/components/impression/components/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class Checkbox extends PureComponent {
}
}

// 获取checkbox是否选中
// getValue
Checkbox.getValue = ref => {
let { value } = ref.props,
{ main } = ref.refs;
Expand All @@ -72,3 +72,12 @@ Checkbox.getValue = ref => {

return value;
};

// setValue
Checkbox.setValue = (ref, checked) => {
let { main } = ref.refs;

if(ref) {
main.checked = !!checked;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default class CheckboxGroup extends PureComponent {
}
}

// 获取选中值
// getValue
CheckboxGroup.getValue = ref => {
if(!ref) {
return undefined;
Expand All @@ -114,3 +114,12 @@ CheckboxGroup.getValue = ref => {

return ref.state.value;
};

// setValue
CheckboxGroup.setValue = (ref, value) => {
if(ref && !ref.isPuppet) {
ref.setState({
value,
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default class InlineSelect extends PureComponent {
}
}

// 获取值
// getValue
InlineSelect.getValue = ref => {
if(!ref) {
return undefined;
Expand All @@ -91,4 +91,13 @@ InlineSelect.getValue = ref => {
return ref.state.value;
};

// setValue
InlineSelect.setValue = (ref, value) => {
if(ref && !ref.isPuppet) {
ref.setState({
value,
});
}
};

InlineSelect.Option = InlineSelectOption;
19 changes: 18 additions & 1 deletion site/src/scripts/components/impression/components/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default class Input extends PureComponent {
}
}

// 获取Input内容
// getValue
Input.getValue = ref => {
let { type } = ref.props;

Expand All @@ -270,3 +270,20 @@ Input.getValue = ref => {
return ref.refs.main.value;
}
};

// setValue
Input.setValue = (ref, value) => {
let { type } = ref.props;

if(!ref) {
return;
}

switch(type) {
case 'file':
ref.refs.main.refs.main.files[0] = value;
break;
default:
ref.refs.main.value = value;
}
};
11 changes: 10 additions & 1 deletion site/src/scripts/components/impression/components/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class Radio extends PureComponent {
}
}

// 获取checkbox是否选中
// getValue
Radio.getValue = ref => {
let { value } = ref.props,
{ main } = ref.refs;
Expand All @@ -79,3 +79,12 @@ Radio.getValue = ref => {

return value;
};

// setValue
Radio.setValue = (ref, checked) => {
let { main } = ref.refs;

if(ref) {
main.checked = !!checked;
}
};
11 changes: 10 additions & 1 deletion site/src/scripts/components/impression/components/RadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class RadioGroup extends PureComponent {
}
}

// 获取选中值
// getValue
RadioGroup.getValue = ref => {
if(!ref) {
return undefined;
Expand All @@ -108,3 +108,12 @@ RadioGroup.getValue = ref => {

return ref.state.value;
};

// setValue
RadioGroup.setValue = (ref, value) => {
if(ref && !ref.isPuppet) {
ref.setState({
value,
});
}
};
11 changes: 10 additions & 1 deletion site/src/scripts/components/impression/components/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class Select extends PureComponent {
}
}

// 获取vule函数
// getValue
Select.getValue = ref => {
if(!ref) {
return undefined;
Expand All @@ -151,4 +151,13 @@ Select.getValue = ref => {
return ref.state.value;
};

// setValue
Select.setValue = (ref, value) => {
if(ref && !ref.isPuppet) {
ref.setState({
value,
});
}
};

Select.Option = SelectOption;
11 changes: 10 additions & 1 deletion site/src/scripts/components/impression/components/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class Switch extends PureComponent {
}
}

// 获取Swtich是否选中
// getValue
Switch.getValue = ref => {
let { value } = ref.props,
{ main } = ref.refs;
Expand All @@ -67,3 +67,12 @@ Switch.getValue = ref => {

return value;
};

// setValue
Switch.setValue = (ref, checked) => {
let { main } = ref.refs;

if(ref) {
main.checked = !!checked;
}
};
7 changes: 6 additions & 1 deletion site/src/scripts/components/impression/components/Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ export default class Upload extends PureComponent {
}
}

// 获取上传文件
// getValue
Upload.getValue = ref => {
return ref ? ref.refs.main.files[0] : undefined;
};

// setValue
Upload.setValue = (ref, value) => {
return ref && (ref.refs.main.files[0] = value);
};
11 changes: 10 additions & 1 deletion src/scripts/components/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class Checkbox extends PureComponent {
}
}

// 获取checkbox是否选中
// getValue
Checkbox.getValue = ref => {
let { value } = ref.props,
{ main } = ref.refs;
Expand All @@ -72,3 +72,12 @@ Checkbox.getValue = ref => {

return value;
};

// setValue
Checkbox.setValue = (ref, checked) => {
let { main } = ref.refs;

if(ref) {
main.checked = !!checked;
}
};
11 changes: 10 additions & 1 deletion src/scripts/components/CheckboxGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default class CheckboxGroup extends PureComponent {
}
}

// 获取选中值
// getValue
CheckboxGroup.getValue = ref => {
if(!ref) {
return undefined;
Expand All @@ -114,3 +114,12 @@ CheckboxGroup.getValue = ref => {

return ref.state.value;
};

// setValue
CheckboxGroup.setValue = (ref, value) => {
if(ref && !ref.isPuppet) {
ref.setState({
value,
});
}
};
11 changes: 10 additions & 1 deletion src/scripts/components/InlineSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default class InlineSelect extends PureComponent {
}
}

// 获取值
// getValue
InlineSelect.getValue = ref => {
if(!ref) {
return undefined;
Expand All @@ -91,4 +91,13 @@ InlineSelect.getValue = ref => {
return ref.state.value;
};

// setValue
InlineSelect.setValue = (ref, value) => {
if(ref && !ref.isPuppet) {
ref.setState({
value,
});
}
};

InlineSelect.Option = InlineSelectOption;
19 changes: 18 additions & 1 deletion src/scripts/components/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default class Input extends PureComponent {
}
}

// 获取Input内容
// getValue
Input.getValue = ref => {
let { type } = ref.props;

Expand All @@ -270,3 +270,20 @@ Input.getValue = ref => {
return ref.refs.main.value;
}
};

// setValue
Input.setValue = (ref, value) => {
let { type } = ref.props;

if(!ref) {
return;
}

switch(type) {
case 'file':
ref.refs.main.refs.main.files[0] = value;
break;
default:
ref.refs.main.value = value;
}
};
11 changes: 10 additions & 1 deletion src/scripts/components/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class Radio extends PureComponent {
}
}

// 获取checkbox是否选中
// getValue
Radio.getValue = ref => {
let { value } = ref.props,
{ main } = ref.refs;
Expand All @@ -79,3 +79,12 @@ Radio.getValue = ref => {

return value;
};

// setValue
Radio.setValue = (ref, checked) => {
let { main } = ref.refs;

if(ref) {
main.checked = !!checked;
}
};
11 changes: 10 additions & 1 deletion src/scripts/components/RadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class RadioGroup extends PureComponent {
}
}

// 获取选中值
// getValue
RadioGroup.getValue = ref => {
if(!ref) {
return undefined;
Expand All @@ -108,3 +108,12 @@ RadioGroup.getValue = ref => {

return ref.state.value;
};

// setValue
RadioGroup.setValue = (ref, value) => {
if(ref && !ref.isPuppet) {
ref.setState({
value,
});
}
};
11 changes: 10 additions & 1 deletion src/scripts/components/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class Select extends PureComponent {
}
}

// 获取vule函数
// getValue
Select.getValue = ref => {
if(!ref) {
return undefined;
Expand All @@ -151,4 +151,13 @@ Select.getValue = ref => {
return ref.state.value;
};

// setValue
Select.setValue = (ref, value) => {
if(ref && !ref.isPuppet) {
ref.setState({
value,
});
}
};

Select.Option = SelectOption;
11 changes: 10 additions & 1 deletion src/scripts/components/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class Switch extends PureComponent {
}
}

// 获取Swtich是否选中
// getValue
Switch.getValue = ref => {
let { value } = ref.props,
{ main } = ref.refs;
Expand All @@ -67,3 +67,12 @@ Switch.getValue = ref => {

return value;
};

// setValue
Switch.setValue = (ref, checked) => {
let { main } = ref.refs;

if(ref) {
main.checked = !!checked;
}
};
Loading

0 comments on commit ca3525a

Please sign in to comment.