Skip to content

Commit d2e143e

Browse files
committed
fix(Tabs): 新增defaultColor api
1 parent 3fb26b2 commit d2e143e

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

packages/core/src/Tabs/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ function Demo() {
4545
export default Demo
4646
```
4747

48+
### 修改默认色
49+
50+
```jsx
51+
import React, { useState } from 'react';
52+
import { Tabs, Icon } from '@uiw/react-native';
53+
function Demo() {
54+
const [value,setValue]= useState(0)
55+
return (
56+
<Tabs onChange={(value)=>setValue(value)} value={value} defaultColor="red">
57+
<Tabs.Item title="喜欢" icon='heart-on' />
58+
<Tabs.Item title="关注" icon={<Icon name='star-on' color={value===1?'#035bb6':'red'} size={24} />} />
59+
<Tabs.Item title="信息" icon='mail' />
60+
</Tabs>
61+
);
62+
}
63+
export default Demo
64+
```
65+
4866
### 选中色更改
4967

5068
```jsx
@@ -72,6 +90,7 @@ export default Demo
7290
| `value` || `number` | - |
7391
| `onChange` | 点击tab栏变化 | `(value: number) => void` | - |
7492
| `activeColor` | 选中后颜色 | `string` | `#035bb6` |
93+
| `defaultColor` | 组件默认眼色 | `string` | `#035bb6` |
7594

7695
### Tabs.Item Props
7796

packages/core/src/Tabs/TabsItem.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,32 @@ export interface TabsItemProps {
3737
value?: number;
3838
onChange?: (value: number) => void;
3939
index?: number;
40+
defaultColor?: string;
4041
}
4142

4243
function TabsItem(props: TabsItemProps) {
43-
const { activeColor, icon, index, value, onChange } = props;
44-
console.log('value', value, 'index', index);
44+
const { activeColor, icon, index, value, onChange, defaultColor } = props;
4545
const style = useCallback(() => {
4646
const { style = {} } = props;
4747
const titleBoxStyle = {
4848
width: style.width ?? 100,
4949
};
5050
const titleStyle = {
5151
fontSize: style.titleSize ?? 20,
52-
color: index === value && activeColor ? activeColor : '#035bb6',
52+
color: index === value && activeColor ? activeColor : defaultColor,
5353
fontWeight: style.titleFontWeight ?? '600',
5454
};
5555
const iconBoxStyle = {
5656
width: style.width ?? 100,
5757
};
5858
const iconStyle = {
59-
color: index === value && activeColor ? activeColor : '#035bb6',
59+
color: index === value && activeColor ? activeColor : defaultColor,
6060
size: style.iconSize ?? 24,
6161
};
6262
const borderColor = {
6363
width: style.borderWidth ?? 40,
6464
borderBottomWidth: style.borderHeight ?? 4,
65-
borderBottomColor: index === value && activeColor ? activeColor : '#035bb6',
65+
borderBottomColor: index === value && activeColor ? activeColor : defaultColor,
6666
bottom: 0,
6767
};
6868
return {

packages/core/src/Tabs/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ export interface TabsProps extends ViewProps {
1212
style?: ViewStyle;
1313
value?: number;
1414
onChange?: (value: number) => void;
15+
defaultColor?: string;
1516
activeColor?: string;
1617
}
1718

1819
function Tabs(props: TabsProps) {
19-
const { style, children, onChange, activeColor, value } = props;
20+
const { style, children, onChange, activeColor, value, defaultColor = '#035bb6' } = props;
2021
if (!children) {
2122
return null;
2223
}
@@ -46,7 +47,13 @@ function Tabs(props: TabsProps) {
4647
}
4748
return React.cloneElement(child, {
4849
...child.props,
49-
...{ value: value, onChange: onChange, index: index, activeColor: activeColor },
50+
...{
51+
value: value,
52+
onChange: onChange,
53+
index: index,
54+
activeColor: activeColor,
55+
defaultColor: defaultColor,
56+
},
5057
});
5158
})}
5259
</ScrollView>

0 commit comments

Comments
 (0)