From 284b825384fabdcef57475a688df013477349eef Mon Sep 17 00:00:00 2001 From: silentcloud Date: Wed, 5 Jul 2017 17:04:29 +0800 Subject: [PATCH] feat(Switch): add color prop for switch, for tinyapp --- components/progress/index.web.tsx | 2 +- components/switch/PropsType.tsx | 1 + .../__tests__/__snapshots__/demo.test.js.snap | 113 ++++++++++++++++++ .../__snapshots__/demo.test.web.js.snap | 75 +++++++++++- .../__snapshots__/index.test.js.snap | 1 + components/switch/demo/basic.md | 22 +++- components/switch/demo/basic.tsx | 1 + components/switch/index.en-US.md | 1 + components/switch/index.tsx | 4 +- components/switch/index.web.tsx | 7 +- components/switch/index.zh-CN.md | 3 +- 11 files changed, 224 insertions(+), 6 deletions(-) diff --git a/components/progress/index.web.tsx b/components/progress/index.web.tsx index 71f3ac9e15..9d90ed9738 100644 --- a/components/progress/index.web.tsx +++ b/components/progress/index.web.tsx @@ -35,7 +35,7 @@ export default class Progress extends React.Component { [`${prefixCls}-fixed-outer`]: position === 'fixed', [`${prefixCls}-hide-outer`]: unfilled === 'hide', }); - // TODO 2.0 整理 style, api 变更 style, barStyle, remove wrapStyle(不添入文档, for tiny) + return (
void; + color?: string; /* web only */ prefixCls?: string; className?: string; diff --git a/components/switch/__tests__/__snapshots__/demo.test.js.snap b/components/switch/__tests__/__snapshots__/demo.test.js.snap index 1f5e06693e..dab093768c 100644 --- a/components/switch/__tests__/__snapshots__/demo.test.js.snap +++ b/components/switch/__tests__/__snapshots__/demo.test.js.snap @@ -110,6 +110,7 @@ exports[`renders ./components/switch/demo/basic.tsx correctly 1`] = ` onChange={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} + onTintColor="#4dd865" onValueChange={[Function]} style={ Array [ @@ -218,6 +219,7 @@ exports[`renders ./components/switch/demo/basic.tsx correctly 1`] = ` onChange={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} + onTintColor="#4dd865" onValueChange={[Function]} style={ Array [ @@ -344,6 +346,7 @@ exports[`renders ./components/switch/demo/basic.tsx correctly 1`] = ` onChange={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} + onTintColor="#4dd865" onValueChange={[Function]} style={ Array [ @@ -452,6 +455,7 @@ exports[`renders ./components/switch/demo/basic.tsx correctly 1`] = ` onChange={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} + onTintColor="#4dd865" onValueChange={[Function]} style={ Array [ @@ -467,6 +471,115 @@ exports[`renders ./components/switch/demo/basic.tsx correctly 1`] = ` + + + + + + color + + + + + + +
+
+
+ Color for Android +
+
+
+
@@ -221,6 +258,42 @@ exports[`renders ./components/switch/demo/basic.md correctly 1`] = ` style="display:none;" />
+
+
+
+ Color for iOS +
+
+
+
`; diff --git a/components/switch/__tests__/__snapshots__/index.test.js.snap b/components/switch/__tests__/__snapshots__/index.test.js.snap index 4c628f7a4f..d0a51bdd08 100644 --- a/components/switch/__tests__/__snapshots__/index.test.js.snap +++ b/components/switch/__tests__/__snapshots__/index.test.js.snap @@ -6,6 +6,7 @@ exports[`Switch renders correctly 1`] = ` onChange={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} + onTintColor="#4dd865" onValueChange={[Function]} style={ Array [ diff --git a/components/switch/demo/basic.md b/components/switch/demo/basic.md index bd7df9ca7d..cf16489ab7 100644 --- a/components/switch/demo/basic.md +++ b/components/switch/demo/basic.md @@ -58,7 +58,7 @@ let SwitchExample = (props) => { { initialValue: true, valuePropName: 'checked', })} + platform="android" + color="red" + />} + >Color for Android + } >Style for iOS + } + >Color for iOS ); }; diff --git a/components/switch/demo/basic.tsx b/components/switch/demo/basic.tsx index ac7066626f..85e5e4e2e4 100644 --- a/components/switch/demo/basic.tsx +++ b/components/switch/demo/basic.tsx @@ -23,6 +23,7 @@ export default class SwitchExample extends React.Component { onChange event, switch status: {this.state.checked ? 'open' : 'close'} }>disabled + }>color ); } diff --git a/components/switch/index.en-US.md b/components/switch/index.en-US.md index 6ffd6edaed..50937c25a3 100644 --- a/components/switch/index.en-US.md +++ b/components/switch/index.en-US.md @@ -21,6 +21,7 @@ Properties | Descrition | Type | Default -----------|------------|------|-------- | checked | Whether is checked by default | Boolean | false | | disabled | whether is disabled | Boolean | false | +| color | Background color when the switch is turned on. | String | #4dd865 | | onChange | The callback function that is triggered when the selected state changes. | (checked: bool): void | - | | name(`web only`) | name of `switch` | String | | | platform (`web only`) | set the special style depends on platform, Options `android`, `ios`, default to be `cross`, which means we will detect UA and change the component style | String | `'cross'`| diff --git a/components/switch/index.tsx b/components/switch/index.tsx index 84dccddbb8..caf049a1a4 100644 --- a/components/switch/index.tsx +++ b/components/switch/index.tsx @@ -8,6 +8,7 @@ export default class AntmSwitch extends React.Component { checked: false, disabled: false, onChange() {}, + color: '#4dd865', }; onChange(value) { @@ -17,7 +18,7 @@ export default class AntmSwitch extends React.Component { } render() { - let { style, disabled, checked } = this.props; + let { style, disabled, color, checked } = this.props; return ( { onValueChange={(value) => {this.onChange(value); }} value={checked} disabled={disabled} + onTintColor={color} /> ); } diff --git a/components/switch/index.web.tsx b/components/switch/index.web.tsx index 3a73eeb3de..dfc38edc82 100644 --- a/components/switch/index.web.tsx +++ b/components/switch/index.web.tsx @@ -33,7 +33,7 @@ export default class Switch extends React.Component { } render() { - let { prefixCls, style, name, checked, disabled, className, platform, ...restProps } = this.props; + let { prefixCls, name, checked, disabled, className, platform, color, ...restProps } = this.props; const isAndroid = platform === 'android' || (platform === 'cross' && typeof navigator !== 'undefined' && !!navigator.userAgent.match(/Android/i)); const wrapCls = classNames({ @@ -54,6 +54,11 @@ export default class Switch extends React.Component { return prev; }, {}); + const style: any = this.props.style || {}; + if (color && checked) { + style.backgroundColor = color; + } + return (