Skip to content

Commit 73a4168

Browse files
committed
fix(TreeSelect):组件样式调整
1 parent 4a19704 commit 73a4168

File tree

3 files changed

+77
-22
lines changed

3 files changed

+77
-22
lines changed

example/examples/src/routes/TreeSelect/index.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from 'react';
2-
import {TreeSelect} from '@uiw/react-native';
3-
import {View} from 'react-native';
2+
import {TreeSelect, DragDrawer, Icon} from '@uiw/react-native';
43
import {ComProps} from '../../routes';
54
import Layout, {Container} from '../../Layout';
6-
const {Header, Body, Footer} = Layout;
5+
const {Header} = Layout;
76

87
export interface TreeSelectViewProps extends ComProps {}
98

@@ -95,22 +94,23 @@ export default class TreeSelectDemo extends React.Component<TreeSelectViewProps>
9594
},
9695
];
9796
return (
98-
<Container>
99-
<Layout>
100-
<Header title={title} description={description} />
101-
<Body>
102-
<TreeSelect
103-
defaultValue={['01', '01-1']}
104-
activeColor="#fd8a00"
105-
options={option}
106-
onChange={(value: any, nodes: any) => {
107-
console.log(value, nodes);
108-
}}
109-
/>
110-
</Body>
111-
<Footer />
112-
</Layout>
113-
</Container>
97+
<React.Fragment>
98+
<DragDrawer drawerHeight={500}>
99+
<TreeSelect
100+
defaultValue={['01', '01-1']}
101+
activeColor="#fd8a00"
102+
options={option}
103+
onChange={(value: any, nodes: any) => {
104+
console.log(value, nodes);
105+
}}
106+
/>
107+
</DragDrawer>
108+
<Container>
109+
<Layout>
110+
<Header title={title} description={description} />
111+
</Layout>
112+
</Container>
113+
</React.Fragment>
114114
);
115115
}
116116
}

packages/core/src/TreeSelect/styles.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,25 @@ export const style = StyleSheet.create({
77
alignItems: 'center',
88
justifyContent: 'center',
99
},
10+
active_first_item: {
11+
backgroundColor: '#fff',
12+
},
13+
not_active_first_item: {
14+
backgroundColor: '#f6f7f9',
15+
},
16+
active_nth_item: {
17+
backgroundColor: '#fef4f3',
18+
borderWidth: 1,
19+
borderRadius: 5,
20+
marginLeft: 10,
21+
marginBottom: 10,
22+
},
23+
not_active_nth_item: {
24+
backgroundColor: '#f6f7f9',
25+
borderColor: '#fff',
26+
borderWidth: 1,
27+
borderRadius: 5,
28+
marginLeft: 10,
29+
marginBottom: 10,
30+
},
1031
});

packages/core/src/TreeSelect/tree-select.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,41 @@ export const TreeSelect: FC<TreeSelectProps> = (p) => {
7070
});
7171
};
7272

73+
// item样式
74+
const activeStyles = (index: number, isActive: boolean) => {
75+
let styles;
76+
// 选中第一排
77+
if (isActive && index === 0) {
78+
styles = {
79+
...style.active_first_item,
80+
};
81+
}
82+
// 未选中第一排
83+
if (!isActive && index === 0) {
84+
styles = {
85+
...style.not_active_first_item,
86+
};
87+
}
88+
// 选中后排
89+
if (isActive && index !== 0) {
90+
styles = {
91+
...style.active_nth_item,
92+
borderColor: props.activeColor,
93+
};
94+
}
95+
// 未选中后排
96+
if (!isActive && index !== 0) {
97+
styles = {
98+
...style.not_active_nth_item,
99+
};
100+
}
101+
return styles;
102+
};
103+
73104
const renderItems = (columnOptions: TreeSelectOption[] = [], index: number) => {
74105
return columnOptions.map((item) => {
75106
const isActive = item[valueName] === value[index];
107+
const active_font_color = index === 0 ? '#333' : props.activeColor;
76108
return (
77109
<TouchableOpacity
78110
key={item[valueName]}
@@ -81,9 +113,11 @@ export const TreeSelect: FC<TreeSelectProps> = (p) => {
81113
onItemSelect(item);
82114
}
83115
}}
84-
style={[style.item, isActive ? { backgroundColor: '#fff' } : {}]}
116+
style={[style.item, { ...activeStyles(index, isActive) }]}
85117
>
86-
<Text style={isActive ? { color: props.activeColor, fontWeight: 'bold' } : {}}>{item[labelName]}</Text>
118+
<Text style={isActive ? { color: active_font_color, fontWeight: 'bold' } : { color: '#666' }}>
119+
{item[labelName]}
120+
</Text>
87121
</TouchableOpacity>
88122
);
89123
});
@@ -102,7 +136,7 @@ export const TreeSelect: FC<TreeSelectProps> = (p) => {
102136
width = `66.67%`;
103137
}
104138
const column = (
105-
<ScrollView key={i} style={{ width, flex: 1, backgroundColor: '#fff' }}>
139+
<ScrollView key={i} style={{ width, flex: 1, backgroundColor: i === 0 ? '#f6f7f9' : '#fff' }}>
106140
{renderItems(i === 0 ? props.options : optionsMap.get(value[i - 1])?.[childrenName], i)}
107141
</ScrollView>
108142
);

0 commit comments

Comments
 (0)