Skip to content

Commit 4763798

Browse files
ffff
authored andcommitted
docs: 优化Switch文档
1 parent dbbc600 commit 4763798

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

packages/core/src/Switch/README.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,59 @@ Switch 开关
66
> 自带组件 Switch 已过时,将很快删除。
77
<!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
88
9-
![](https://user-images.githubusercontent.com/57083007/146733820-dbdfdf2d-80f6-4cd7-b130-2528fcd0d682.gif)<!--rehype:style=zoom: 33%;float: right; margin-left: 15px;-->
9+
10+
### 禁用
11+
12+
```jsx mdx:preview
13+
import { Switch } from '@uiw/react-native';
14+
import React from 'react';
15+
16+
function Demo() {
17+
return (
18+
<Switch disabled />
19+
);
20+
}
21+
export default Demo
22+
```
1023

1124
### 基础示例
1225

13-
```jsx
26+
```jsx mdx:preview
1427
import { Switch } from '@uiw/react-native';
28+
import React from 'react';
1529

1630
function Demo() {
1731
return (
1832
<Switch />
1933
);
2034
}
35+
export default Demo
36+
```
37+
38+
### 自定义颜色
39+
40+
```jsx mdx:preview
41+
import { Switch } from '@uiw/react-native';
42+
import React from 'react';
43+
44+
function Demo() {
45+
return (
46+
<Switch
47+
color="red"
48+
thumbStyle={{backgroundColor: 'skyblue'}}
49+
trackStyle={{backgroundColor: 'pink'}}
50+
/>
51+
);
52+
}
53+
export default Demo
2154
```
2255

2356
### 尺寸大小
2457

25-
这是一个受控组件,需要一个 `onValueChange` 回调来更新值属性,以使该组件反映用户操作。
2658

27-
```jsx
59+
```jsx mdx:preview
2860
import { Spacing, Flex, Switch } from '@uiw/react-native';
61+
import React from 'react';
2962

3063
function Demo() {
3164
return (
@@ -38,14 +71,16 @@ function Demo() {
3871
</Flex>
3972
);
4073
}
74+
75+
export default Demo
4176
```
4277

4378
### 受控组件
4479

4580
这是一个受控组件,需要一个 `onValueChange` 回调来更新值属性,以使该组件反映用户操作。
4681

47-
```jsx
48-
import { useState } from 'react';
82+
```jsx mdx:preview
83+
import React, { useState } from 'react';
4984
import { Switch } from '@uiw/react-native';
5085

5186
function Demo() {
@@ -54,14 +89,16 @@ function Demo() {
5489
<Switch checked={checked} onValueChange={() => setChecked(!checked)} />
5590
);
5691
}
92+
93+
export default Demo
5794
```
5895

5996
### props
6097

6198
| 参数 | 说明 | 类型 | 默认值|
6299
|------|------|-----|------|
63100
| `checked` | 是否被选中 | Boolean | `false` |
64-
| `color` | 设置 | Boolean | `false` |
101+
| `color` | 颜色 | String | - |
65102
| `size` | 尺寸大小 | `small`, `default`, `large` | `default` |
66103
| `disabled` | 如果为`true`,则用户将无法切换开关。 | Boolean | `false` |
67104
| `trackStyle` | 设置背景样式。 | ViewStyle | - |

packages/core/src/Switch/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,14 @@ export default class Switch extends React.Component<SwitchProps, SwitchState> {
182182
<Animated.View
183183
style={[
184184
styles.grip,
185-
thumbStyle,
185+
186186
disabled ? styles.shadowDisable : styles.shadow,
187187
{
188188
backgroundColor: thumbColor,
189189
width: containerSize.width,
190190
height: containerSize.height,
191191
},
192+
thumbStyle,
192193
{
193194
transform: [{ translateX: this.state.translateXValue }],
194195
},

0 commit comments

Comments
 (0)