Skip to content

Commit 805b47d

Browse files
authored
Merge pull request #790 from ShuyunFF2E/feat-imageText-mly
feat: 新增 Format、ImageText、LightText 组件;配置保存时格式化
2 parents 3ffad2d + 73915d9 commit 805b47d

52 files changed

Lines changed: 2093 additions & 140 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
"semi": ["error", "always"],
4848
"spaced-comment": ["error", "always"],
4949
"no-multi-spaces": "error",
50-
"no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true }],
50+
"no-unused-expressions": [
51+
"error",
52+
{ "allowShortCircuit": true, "allowTernary": true }
53+
],
5154
"no-return-assign": "error",
5255
"max-len": ["error", { "code": 200, "comments": 200 }],
5356
"quote-props": ["error", "as-needed"],
@@ -58,20 +61,27 @@
5861
"object-curly-spacing": ["error", "always", { "arraysInObjects": true }],
5962
"comma-spacing": ["error", { "before": false, "after": true }],
6063
"arrow-spacing": ["error", { "before": true, "after": true }],
61-
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
62-
"template-curly-spacing": ["error", "never"],
63-
"space-infix-ops": ["error"],
64-
"arrow-body-style": "off",
65-
"no-undef": "error",
66-
"no-multi-assign": "error",
67-
"no-nested-ternary": "error",
68-
"no-lonely-if": "error",
69-
"no-unneeded-ternary": "error",
70-
"no-case-declarations": "error",
71-
"object-curly-newline": "off",
72-
"array-bracket-spacing": "off",
73-
"space-before-function-paren": "error",
74-
"space-before-blocks": ["error", { "functions": "always", "keywords": "always", "classes": "always" }],
64+
"lines-between-class-members": [
65+
"error",
66+
"always",
67+
{ "exceptAfterSingleLine": true }
68+
],
69+
"template-curly-spacing": ["error", "never"],
70+
"space-infix-ops": ["error"],
71+
"arrow-body-style": "off",
72+
"no-undef": "error",
73+
"no-multi-assign": "error",
74+
"no-nested-ternary": "error",
75+
"no-lonely-if": "error",
76+
"no-unneeded-ternary": "error",
77+
"no-case-declarations": "error",
78+
"object-curly-newline": "off",
79+
"array-bracket-spacing": "off",
80+
"space-before-function-paren": "error",
81+
"space-before-blocks": [
82+
"error",
83+
{ "functions": "always", "keywords": "always", "classes": "always" }
84+
],
7585
"no-underscore-dangle": "off",
7686
"global-require": "off",
7787
"jsx-a11y/no-static-element-interactions": "off",
@@ -86,14 +96,17 @@
8696
"import/extensions": "off",
8797

8898
// react (eslint-plugin-react required)
89-
"react/jsx-filename-extension": ["error", { "extensions": [".js", ".jsx"] }],
99+
"react/jsx-filename-extension": [
100+
"error",
101+
{ "extensions": [".js", ".jsx"] }
102+
],
90103
"react/jsx-no-duplicate-props": ["error"],
91104
"react/jsx-indent-props": "off",
92105
"react/jsx-indent": "off",
93106
"no-promise-executor-return": "off",
94107
"no-param-reassign": "off",
95108
"class-methods-use-this": "off",
96-
"react/jsx-first-prop-new-line": [ "error", "multiline" ],
109+
"react/jsx-first-prop-new-line": ["error", "multiline"],
97110
"react/prop-types": "off",
98111
"react/no-children-prop": "off",
99112

@@ -123,7 +136,11 @@
123136
"react/function-component-definition": [
124137
"warn",
125138
{
126-
"namedComponents": ["function-declaration", "arrow-function", "function-expression"],
139+
"namedComponents": [
140+
"function-declaration",
141+
"arrow-function",
142+
"function-expression"
143+
],
127144
"unnamedComponents": ["arrow-function", "function-expression"]
128145
}
129146
],

.umirc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export default defineConfig({
9292
.__dumi-default-layout-hero img { margin-top: -50px }
9393
.__dumi-default-layout-hero h1 { color: white !important }
9494
.__dumi-default-layout-hero .markdown { color: white !important }
95+
.markdown .icon.icon-link { display: none }
9596
`,
9697
],
9798
});

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-picker/demos/date-picker.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ desc: 基本用法,日期选择器。
1212
import React from "react";
1313
import moment from "moment";
1414
import { CPicker as DatePicker, Form, Field, Toggle } from "cloud-react";
15-
1615
const { TimePicker } = DatePicker;
1716

1817
const presets = [
@@ -47,6 +46,7 @@ class DatePickerDemo extends React.Component {
4746
state = {
4847
value: moment("2021/12/01 16:05:33", "yyyy/MM/DD HH:mm:ss").toDate(),
4948
time: "17:58:58",
49+
value1: moment("2021/12/01 16:05", "yyyy/MM/DD HH:mm").toDate(),
5050
};
5151

5252
onChange = (value) => {
@@ -60,7 +60,7 @@ class DatePickerDemo extends React.Component {
6060
};
6161

6262
render() {
63-
const { value, time, disabled } = this.state;
63+
const { value, value1, time, disabled } = this.state;
6464
const { init } = this.field;
6565
return (
6666
<Form
@@ -118,6 +118,20 @@ class DatePickerDemo extends React.Component {
118118
presets={presets}
119119
/>
120120
</Form.Item>
121+
<Form.Item label="日期选择器(不显示秒)">
122+
<DatePicker
123+
value={value}
124+
onChange={this.onChange}
125+
showToday
126+
showTimePicker={{
127+
showSecond: false,
128+
format: "HH:mm",
129+
}}
130+
format="YYYY-MM-DD HH:mm"
131+
disabled={disabled}
132+
presets={presets}
133+
/>
134+
</Form.Item>
121135
<Form.Item label="时间选择器">
122136
<TimePicker
123137
value={time}

src/components/c-table/columnTpl/link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function LinkTpl({ value, row, linkKey, link, onClick, line = 1,
1717
setTooltipContent(value);
1818
}
1919
}
20-
}, [tooltipValue]);
20+
}, [value, tooltipValue]);
2121

2222
if (isVoid(value)) {
2323
return '-';

src/components/c-table/columnTpl/number.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useEffect, useState, useCallback } from 'react';
12
import PropTypes from 'prop-types';
23
import { formatThousands, isVoid } from '../util';
34

@@ -8,17 +9,27 @@ export default function NumberTpl({
89
prefix = '',
910
suffix = '',
1011
}) {
11-
let number = value;
12-
if (isVoid(number)) {
13-
return '-';
14-
}
15-
if (precision > 0) {
16-
number = Number(number).toFixed(precision);
17-
}
18-
if (isThousands) {
19-
number = formatThousands(number);
20-
}
21-
return `${prefix || ''}${number}${suffix || ''}`;
12+
const [resolvedValue, setResolvedValue] = useState(value);
13+
14+
const getNumberVal = useCallback(() => {
15+
let number = value;
16+
if (isVoid(number)) {
17+
return '';
18+
}
19+
if (precision > 0) {
20+
number = Number(number).toFixed(precision);
21+
}
22+
if (isThousands) {
23+
number = formatThousands(number);
24+
}
25+
return `${prefix || ''}${number}${suffix || ''}`;
26+
}, [value, precision, isThousands, prefix, suffix]);
27+
28+
useEffect(() => {
29+
setResolvedValue(getNumberVal());
30+
}, [getNumberVal]);
31+
32+
return resolvedValue || '-';
2233
}
2334

2435
NumberTpl.propTypes = {

src/components/c-table/columnTpl/text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function TextTpl({ value, line = 1, tooltipValue }) {
1717
setTooltipContent(value);
1818
}
1919
}
20-
}, [tooltipValue]);
20+
}, [value, tooltipValue]);
2121

2222
if (isVoid(value)) {
2323
return '-';

src/components/c-table/columnTpl/time.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1+
import { useEffect, useState } from 'react';
12
import PropTypes from 'prop-types';
23
import moment from 'moment';
34
import { isVoid } from '../util';
45

56
export default function TimeTpl({ value, format }) {
6-
if (isVoid(value)) {
7-
return '-';
8-
}
9-
if (format) {
10-
return moment(value).format(format);
11-
}
12-
return `${value}`.replaceAll('/', '-');
7+
const [time, setTime] = useState(value);
8+
9+
useEffect(() => {
10+
if (isVoid(value)) {
11+
setTime('');
12+
} else if (format) {
13+
setTime(moment(value).format(format));
14+
} else {
15+
setTime(`${value}`.replaceAll('/', '-'));
16+
}
17+
}, [value, format]);
18+
19+
return time || '-';
1320
}
1421

1522
TimeTpl.propTypes = {

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`);

src/components/checkbox/index.js

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,37 @@ function Group(props) {
1414

1515
let checkedValue = value ? [ ...value ] : value;
1616

17-
const group = Children.map(children, (child) => cloneElement(child, {
18-
disabled: disabled === undefined ? child.props.disabled : disabled,
19-
20-
checked:
21-
checkedValue === undefined
22-
? undefined
23-
: checkedValue.indexOf(child.props.value) > -1,
24-
25-
onChange(checked, val) {
26-
if (checkedValue === undefined) {
27-
checkedValue = [];
28-
}
29-
30-
const index = checkedValue.indexOf(val);
31-
32-
if (index > -1 && !checked) {
33-
checkedValue.splice(index, 1);
34-
}
35-
36-
if (index === -1 && checked) {
37-
checkedValue.push(val);
38-
}
39-
40-
onChange(checkedValue);
41-
},
42-
}));
17+
const group = Children.map(children, (child) => {
18+
if (child && child.type && [ 'Checkbox', 'ComplexCheckbox' ].includes(child.type.displayName)) {
19+
return cloneElement(child, {
20+
disabled: disabled === undefined ? child.props.disabled : disabled,
21+
22+
checked:
23+
checkedValue === undefined
24+
? undefined
25+
: checkedValue.indexOf(child.props.value) > -1,
26+
27+
onChange(checked, val) {
28+
if (checkedValue === undefined) {
29+
checkedValue = [];
30+
}
31+
32+
const index = checkedValue.indexOf(val);
33+
34+
if (index > -1 && !checked) {
35+
checkedValue.splice(index, 1);
36+
}
37+
38+
if (index === -1 && checked) {
39+
checkedValue.push(val);
40+
}
41+
42+
onChange(checkedValue);
43+
},
44+
});
45+
}
46+
return child;
47+
});
4348

4449
const classes = classNames(`${classSelector}-group`, {
4550
vertical: layout === 'v',
@@ -159,4 +164,6 @@ class Checkbox extends React.Component {
159164
}
160165
}
161166

167+
Checkbox.displayName = 'Checkbox';
168+
162169
export default Checkbox;

0 commit comments

Comments
 (0)