Skip to content

Commit 28b52f6

Browse files
committed
Merge branch 'feat-select-tips' of github.com:ShuyunFF2E/cloud-react into feat-imageText-mly
2 parents e8f78fe + 702d37b commit 28b52f6

14 files changed

Lines changed: 443 additions & 94 deletions

File tree

src/components/c-cascader/demos/basic.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ desc: 默认样式
66

77
```jsx
88
import React, { useState, useEffect } from "react";
9-
import { CCascader } from "cloud-react";
9+
import { CCascader, Tooltip, Icon } from "cloud-react";
1010
const addressOptions = [
1111
{
1212
value: "zhejiang",
1313
label: "Zhejiang",
14+
info: "说明",
1415

1516
children: [
1617
{
1718
value: "hangzhou",
1819
label: "Hangzhou",
20+
info: "说明",
1921
children: [
2022
{
2123
value: "xihu",
@@ -128,6 +130,23 @@ export default function Demo() {
128130
onChange={onChange}
129131
placeholder="Please select"
130132
style={{ width: 328 }}
133+
optionRender={(option) => {
134+
return (
135+
<label title={option.title} style={{ display: "flex", gap: 4 }}>
136+
{option.label}
137+
{option.info && (
138+
<Tooltip
139+
content={option.info}
140+
theme="light"
141+
placement="right"
142+
overlayStyle={{ zIndex: 10000 }}
143+
>
144+
<Icon type="question-circle" />
145+
</Tooltip>
146+
)}
147+
</label>
148+
);
149+
}}
131150
/>
132151
<div style={{ marginBottom: 24, marginTop: 40 }}>任意选项支持选择</div>
133152
<CCascader

src/components/c-table/js/rowTooltip.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class RowTooltip extends Component {
6060
tooltipEle,
6161
checkboxEle || radioEle,
6262
'top-left',
63+
undefined,
64+
'top',
6365
);
6466

6567
const isInModal = document.querySelector(`.${prefixCls}-modal-mask`);
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
order: 2
3+
title: 基本使用
4+
desc: 基本使用
5+
---
6+
7+
```jsx
8+
/**
9+
* title: 下拉选项释义
10+
* desc: 下拉选项释义
11+
*/
12+
import React, { useState } from 'react';
13+
import { Select } from 'cloud-react';
14+
15+
const Option = Select.Option;
16+
17+
const dataList = [
18+
{
19+
label: 'JQuery',
20+
value: '1',
21+
selectInfo: 'JQueryJQueryJQueryJQueryJQueryJQueryJQueryJQueryJQuery'
22+
},
23+
{
24+
label: 'Vue',
25+
value: '2'
26+
},
27+
{
28+
label: 'React',
29+
value: '3',
30+
selectInfo: 'ReactReactReactReactReactReactReactReactReact'
31+
},
32+
{
33+
label: 'Angular',
34+
value: '4',
35+
selectInfo: '11212122'
36+
},
37+
{
38+
label: 'Angular1',
39+
value: '41',
40+
selectInfo: '11212122'
41+
},
42+
{
43+
label: 'Angular2',
44+
value: '42',
45+
selectInfo: '11212122'
46+
},
47+
{
48+
label: 'Angular3',
49+
value: '43',
50+
selectInfo: '11212122'
51+
},
52+
{
53+
label: 'Angular4',
54+
value: '44',
55+
selectInfo: '11212122'
56+
},
57+
{
58+
label: 'Angular5',
59+
value: '45',
60+
selectInfo: '11212122'
61+
},
62+
{
63+
label: 'Angular6',
64+
value: '46',
65+
selectInfo: '11212122'
66+
},
67+
{
68+
label: 'Angular7',
69+
value: '47',
70+
selectInfo: '11212122'
71+
},
72+
];
73+
74+
export default function SelectDemo() {
75+
const handleChange = (value, prevValue) => {
76+
console.log('select --- ' + value);
77+
console.log('prevSelect --- ' + prevValue);
78+
};
79+
80+
return (
81+
<div className="demo">
82+
<div style={{ display: 'flex', gap: 30, flexWrap: 'wrap' }}>
83+
<div>
84+
<h5>单选</h5>
85+
<Select
86+
style={{ width: 328 }}
87+
dropdownConfig={{
88+
width: 328,
89+
leftWidth: 128,
90+
rightWidth: 200
91+
}}
92+
allowClear
93+
onChange={handleChange}
94+
dataSource={dataList}
95+
// selectInfoKey="info"
96+
/>
97+
</div>
98+
<div>
99+
<h5>多选</h5>
100+
<Select
101+
style={{ width: 328 }}
102+
dropdownConfig={{
103+
width: 328,
104+
leftWidth: 148,
105+
rightWidth: 180
106+
}}
107+
multiple
108+
allowClear
109+
onChange={handleChange}
110+
dataSource={dataList}
111+
// selectInfoKey="info"
112+
/>
113+
</div>
114+
</div>
115+
</div>
116+
);
117+
}
118+
```

src/components/select/index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class Select extends Component {
9595
style: {},
9696
searchValue: '',
9797
isSearch: false,
98+
hoveredOption: null,
9899
};
99100
this.node = React.createRef();
100101
this.optionsNode = React.createRef();
@@ -506,6 +507,10 @@ class Select extends Component {
506507
this.setState({ searchValue: v });
507508
};
508509

510+
onHoverChange = (item) => {
511+
this.setState({ hoveredOption: item });
512+
};
513+
509514
renderOptions() {
510515
const { multiple, confirmTemplate, dataSource } = this.props;
511516
const { value } = this.state;
@@ -523,6 +528,8 @@ class Select extends Component {
523528
onSearchValueChange={this.onSearchValueChange}
524529
handleSelect={this.handleSelect}
525530
searchValue={this.state.searchValue}
531+
onHoverChange={this.onHoverChange}
532+
open={this.state.open}
526533
/>
527534
);
528535
}
@@ -548,6 +555,8 @@ class Select extends Component {
548555
onChange={this.onSimpleOptionChange}
549556
searchValue={this.state.searchValue}
550557
onSearchValueChange={this.onSearchValueChange}
558+
onHoverChange={this.onHoverChange}
559+
open={this.state.open}
551560
/>
552561
);
553562
}
@@ -567,9 +576,10 @@ class Select extends Component {
567576
supportUnlimited,
568577
formSize,
569578
dataSource,
579+
dropdownConfig,
570580
...otherProps
571581
} = this.props;
572-
const { selected, open, style: popupStyle } = this.state;
582+
const { selected, open, style: popupStyle, hoveredOption } = this.state;
573583
const { width } = this.selectedContainerStyle;
574584
const classNames = classnames(
575585
`${selector}`,
@@ -581,7 +591,13 @@ class Select extends Component {
581591
<div
582592
className={`${selector}-option-container ${dropdownClassName}`}
583593
ref={this.optionsNode}
584-
style={{ ...popupStyle, width: `${width}px`, ...dropdownStyle }}
594+
style={{
595+
...popupStyle,
596+
width: hoveredOption?.[this.props.selectInfoKey]
597+
? dropdownConfig?.width
598+
: dropdownConfig?.leftWidth || dropdownStyle?.width || `${width}px`,
599+
...dropdownStyle,
600+
}}
585601
>
586602
{this.renderOptions()}
587603
</div>
@@ -676,6 +692,8 @@ Select.propTypes = {
676692
selectAllText: PropTypes.string,
677693
borderRadiusSize: PropTypes.oneOf(['default', 'medium', 'large']),
678694
checkboxStyle: PropTypes.object,
695+
dropdownConfig: PropTypes.object,
696+
selectInfoKey: PropTypes.string,
679697
};
680698

681699
Select.defaultProps = {
@@ -726,6 +744,7 @@ Select.defaultProps = {
726744
selectAllText: '全选',
727745
borderRadiusSize: 'default',
728746
checkboxStyle: {},
747+
selectInfoKey: 'selectInfo',
729748
};
730749

731750
export default Select;

src/components/select/index.less

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,3 +627,33 @@
627627
font-size: 12px;
628628
}
629629
}
630+
631+
632+
.@{select-prefix-cls}-select-panel-container {
633+
display: flex;
634+
position: relative;
635+
636+
.@{select-prefix-cls}-info-panel {
637+
position: relative;
638+
left: -2px;
639+
padding: 0 12px 14px 12px;
640+
color: #222;
641+
font-size: 14px;
642+
line-height: 22px;
643+
z-index: 10;
644+
border-left: 1px solid #E8E8E8;
645+
646+
&-title {
647+
font-weight: 600;
648+
font-size: 16px;
649+
margin-bottom: 8px;
650+
word-break: break-all;
651+
}
652+
653+
&-content {
654+
color: #666;
655+
white-space: pre-line;
656+
word-break: break-all;
657+
}
658+
}
659+
}

0 commit comments

Comments
 (0)