amis 1.5.3 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/lib/components/Card.d.ts +96 -0
- package/lib/components/Card.js +85 -0
- package/lib/components/Card.js.map +13 -0
- package/lib/components/DatePicker.d.ts +85 -84
- package/lib/components/DatePicker.js.map +2 -2
- package/lib/components/DateRangePicker.d.ts +84 -84
- package/lib/components/MonthRangePicker.d.ts +84 -84
- package/lib/components/Picker.d.ts +503 -0
- package/lib/components/Picker.js +65 -0
- package/lib/components/Picker.js.map +13 -0
- package/lib/components/PickerColumn.d.ts +29 -459
- package/lib/components/PickerColumn.js +35 -44
- package/lib/components/PickerColumn.js.map +2 -2
- package/lib/components/Select.d.ts +238 -238
- package/lib/components/Select.js +9 -2
- package/lib/components/Select.js.map +2 -2
- package/lib/components/Selection.js +1 -4
- package/lib/components/Selection.js.map +2 -2
- package/lib/components/Switch.d.ts +6 -6
- package/lib/components/Switch.js.map +2 -2
- package/lib/components/calendar/Calendar.js +15 -0
- package/lib/components/calendar/Calendar.js.map +2 -2
- package/lib/components/calendar/DaysView.js +4 -4
- package/lib/components/calendar/DaysView.js.map +2 -2
- package/lib/components/calendar/TimeView.d.ts +10 -0
- package/lib/components/calendar/TimeView.js +55 -2
- package/lib/components/calendar/TimeView.js.map +2 -2
- package/lib/components/calendar/YearsView.d.ts +9 -0
- package/lib/components/calendar/YearsView.js +19 -0
- package/lib/components/calendar/YearsView.js.map +2 -2
- package/lib/index.js +1 -1
- package/lib/renderers/Card.d.ts +81 -13
- package/lib/renderers/Card.js +178 -81
- package/lib/renderers/Card.js.map +2 -2
- package/lib/renderers/Form/DiffEditor.d.ts +145 -37
- package/lib/renderers/Form/Editor.d.ts +144 -36
- package/lib/renderers/Form/Formula.js +5 -5
- package/lib/renderers/Form/Formula.js.map +2 -2
- package/lib/renderers/Form/InputCity.d.ts +84 -84
- package/lib/renderers/Form/InputFile.js +2 -2
- package/lib/renderers/Form/InputFile.js.map +2 -2
- package/lib/renderers/Form/index.js +10 -0
- package/lib/renderers/Form/index.js.map +2 -2
- package/lib/renderers/Form/wrapControl.js +3 -2
- package/lib/renderers/Form/wrapControl.js.map +2 -2
- package/lib/store/combo.d.ts +160 -40
- package/lib/store/form.d.ts +64 -16
- package/lib/store/formItem.d.ts +4 -2
- package/lib/store/formItem.js +11 -6
- package/lib/store/formItem.js.map +2 -2
- package/lib/store/table.d.ts +128 -32
- package/lib/themes/ang-ie11.css +177 -30
- package/lib/themes/ang.css +177 -30
- package/lib/themes/ang.css.map +1 -1
- package/lib/themes/antd-ie11.css +177 -30
- package/lib/themes/antd.css +177 -30
- package/lib/themes/antd.css.map +1 -1
- package/lib/themes/cxd-ie11.css +177 -30
- package/lib/themes/cxd.css +177 -30
- package/lib/themes/cxd.css.map +1 -1
- package/lib/themes/dark-ie11.css +177 -30
- package/lib/themes/dark.css +177 -30
- package/lib/themes/dark.css.map +1 -1
- package/lib/themes/default.css +177 -30
- package/lib/themes/default.css.map +1 -1
- package/lib/utils/helper.d.ts +7 -0
- package/lib/utils/helper.js +33 -1
- package/lib/utils/helper.js.map +2 -2
- package/package.json +2 -2
- package/schema.json +157 -13
- package/scss/_properties.scss +13 -2
- package/scss/components/_card.scss +155 -15
- package/scss/components/_nav.scss +1 -1
- package/scss/components/_picker-columns.scss +20 -14
- package/scss/components/form/_file.scss +2 -2
- package/scss/components/form/_selection.scss +4 -0
- package/scss/components/form/_switch.scss +6 -0
- package/sdk/ang-ie11.css +214 -40
- package/sdk/ang.css +216 -32
- package/sdk/antd-ie11.css +214 -40
- package/sdk/antd.css +216 -32
- package/sdk/charts.js +14 -14
- package/sdk/color-picker.js +65 -65
- package/sdk/cropperjs.js +2 -2
- package/sdk/cxd-ie11.css +206 -32
- package/sdk/cxd.css +216 -32
- package/sdk/dark-ie11.css +214 -40
- package/sdk/dark.css +216 -32
- package/sdk/exceljs.js +1 -1
- package/sdk/markdown.js +69 -69
- package/sdk/papaparse.js +1 -1
- package/sdk/renderers/Form/CityDB.js +1 -1
- package/sdk/rest.js +18 -18
- package/sdk/rich-text.js +62 -62
- package/sdk/sdk-ie11.css +206 -32
- package/sdk/sdk.css +216 -32
- package/sdk/sdk.js +1190 -1186
- package/sdk/thirds/hls.js/hls.js +1 -1
- package/sdk/thirds/mpegts.js/mpegts.js +1 -1
- package/sdk/tinymce.js +57 -57
- package/src/components/Card.tsx +203 -0
- package/src/components/DatePicker.tsx +3 -0
- package/src/components/Picker.tsx +145 -0
- package/src/components/PickerColumn.tsx +58 -95
- package/src/components/Select.tsx +17 -12
- package/src/components/Selection.tsx +1 -4
- package/src/components/Switch.tsx +7 -7
- package/src/components/calendar/Calendar.tsx +18 -0
- package/src/components/calendar/DaysView.tsx +6 -4
- package/src/components/calendar/TimeView.tsx +80 -5
- package/src/components/calendar/YearsView.tsx +44 -1
- package/src/renderers/Card.tsx +299 -191
- package/src/renderers/Form/Formula.tsx +7 -5
- package/src/renderers/Form/InputFile.tsx +6 -2
- package/src/renderers/Form/index.tsx +12 -0
- package/src/renderers/Form/wrapControl.tsx +5 -2
- package/src/store/formItem.ts +12 -6
- package/src/utils/helper.ts +34 -0
@@ -0,0 +1,203 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import {isClickOnInput} from '../utils/helper';
|
3
|
+
import {ClassNamesFn, themeable, ThemeProps} from '../theme';
|
4
|
+
export interface CardProps extends ThemeProps {
|
5
|
+
className?: string;
|
6
|
+
headerClassName?: string;
|
7
|
+
titleClassName?: string;
|
8
|
+
subTitleClassName?: string;
|
9
|
+
descriptionClassName?: string;
|
10
|
+
avatarTextStyle?: object;
|
11
|
+
avatarTextClassName?: string;
|
12
|
+
avatarClassName?: string;
|
13
|
+
secondaryClassName?: string;
|
14
|
+
imageClassName?: string;
|
15
|
+
bodyClassName?: string;
|
16
|
+
footerClassName?: string;
|
17
|
+
media?: React.ReactNode;
|
18
|
+
mediaPosition?: 'top' | 'left' | 'right' | 'bottom';
|
19
|
+
toolbar?: React.ReactNode;
|
20
|
+
children?: React.ReactNode;
|
21
|
+
actions?: React.ReactNode;
|
22
|
+
title?: string | JSX.Element;
|
23
|
+
subTitle?: string | JSX.Element;
|
24
|
+
subTitlePlaceholder?: string | JSX.Element;
|
25
|
+
description?: string | JSX.Element;
|
26
|
+
descriptionPlaceholder?: string | JSX.Element;
|
27
|
+
avatar?: string;
|
28
|
+
avatarText?: string | JSX.Element;
|
29
|
+
secondary?: string | JSX.Element;
|
30
|
+
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
|
31
|
+
classnames: ClassNamesFn;
|
32
|
+
}
|
33
|
+
|
34
|
+
export class Card extends React.Component<CardProps> {
|
35
|
+
static defaultProps: Partial<CardProps> = {
|
36
|
+
className: '',
|
37
|
+
avatarClassName: '',
|
38
|
+
headerClassName: '',
|
39
|
+
footerClassName: '',
|
40
|
+
secondaryClassName: '',
|
41
|
+
avatarTextClassName: '',
|
42
|
+
bodyClassName: '',
|
43
|
+
titleClassName: '',
|
44
|
+
subTitleClassName: '',
|
45
|
+
descriptionClassName: '',
|
46
|
+
imageClassName: '',
|
47
|
+
mediaPosition: 'left'
|
48
|
+
};
|
49
|
+
|
50
|
+
constructor(props: CardProps) {
|
51
|
+
super(props);
|
52
|
+
this.handleClick = this.handleClick.bind(this);
|
53
|
+
}
|
54
|
+
|
55
|
+
handleClick(e: React.MouseEvent<HTMLDivElement>) {
|
56
|
+
if (isClickOnInput(e)) {
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
|
60
|
+
this.props.onClick && this.props.onClick(e);
|
61
|
+
}
|
62
|
+
|
63
|
+
render() {
|
64
|
+
const {
|
65
|
+
classnames: cx,
|
66
|
+
className,
|
67
|
+
headerClassName,
|
68
|
+
bodyClassName,
|
69
|
+
titleClassName,
|
70
|
+
subTitleClassName,
|
71
|
+
descriptionClassName,
|
72
|
+
avatarClassName,
|
73
|
+
avatarTextStyle,
|
74
|
+
imageClassName,
|
75
|
+
avatarTextClassName,
|
76
|
+
secondaryClassName,
|
77
|
+
footerClassName,
|
78
|
+
media,
|
79
|
+
mediaPosition,
|
80
|
+
actions,
|
81
|
+
children,
|
82
|
+
onClick,
|
83
|
+
toolbar,
|
84
|
+
title,
|
85
|
+
subTitle,
|
86
|
+
subTitlePlaceholder,
|
87
|
+
description,
|
88
|
+
descriptionPlaceholder,
|
89
|
+
secondary,
|
90
|
+
avatar,
|
91
|
+
avatarText
|
92
|
+
} = this.props;
|
93
|
+
|
94
|
+
let heading = null;
|
95
|
+
const isShowHeading =
|
96
|
+
avatar ||
|
97
|
+
avatarText ||
|
98
|
+
title ||
|
99
|
+
subTitle ||
|
100
|
+
subTitlePlaceholder ||
|
101
|
+
description ||
|
102
|
+
descriptionPlaceholder ||
|
103
|
+
toolbar;
|
104
|
+
if (isShowHeading) {
|
105
|
+
heading = (
|
106
|
+
<div className={cx('Card-heading', headerClassName)}>
|
107
|
+
{avatar ? (
|
108
|
+
<span className={cx('Card-avtar', avatarClassName)}>
|
109
|
+
<img className={cx('Card-img', imageClassName)} src={avatar} />
|
110
|
+
</span>
|
111
|
+
) : avatarText ? (
|
112
|
+
<span
|
113
|
+
className={cx('Card-avtarText', avatarTextClassName)}
|
114
|
+
style={avatarTextStyle}
|
115
|
+
>
|
116
|
+
{avatarText}
|
117
|
+
</span>
|
118
|
+
) : null}
|
119
|
+
<div className={cx('Card-meta')}>
|
120
|
+
{title ? (
|
121
|
+
<div className={cx('Card-title', titleClassName)}>{title}</div>
|
122
|
+
) : null}
|
123
|
+
{subTitle || subTitlePlaceholder ? (
|
124
|
+
<div className={cx('Card-subTitle', subTitleClassName)}>
|
125
|
+
{subTitle
|
126
|
+
? subTitle
|
127
|
+
: subTitlePlaceholder
|
128
|
+
? subTitlePlaceholder
|
129
|
+
: null}
|
130
|
+
</div>
|
131
|
+
) : null}
|
132
|
+
{description || descriptionPlaceholder ? (
|
133
|
+
<div className={cx('Card-desc', descriptionClassName)}>
|
134
|
+
{description
|
135
|
+
? description
|
136
|
+
: descriptionPlaceholder
|
137
|
+
? descriptionPlaceholder
|
138
|
+
: null}
|
139
|
+
</div>
|
140
|
+
) : null}
|
141
|
+
</div>
|
142
|
+
{toolbar}
|
143
|
+
</div>
|
144
|
+
);
|
145
|
+
}
|
146
|
+
|
147
|
+
const body = children;
|
148
|
+
|
149
|
+
return (
|
150
|
+
<div
|
151
|
+
onClick={this.handleClick}
|
152
|
+
className={cx('Card', className, {
|
153
|
+
'Card--link': onClick
|
154
|
+
})}
|
155
|
+
>
|
156
|
+
{media ? (
|
157
|
+
<div className={cx(`Card-multiMedia--${mediaPosition}`)}>
|
158
|
+
{media}
|
159
|
+
<div className={cx('Card-multiMedia-flex')}>
|
160
|
+
{heading}
|
161
|
+
{body ? (
|
162
|
+
<div className={cx('Card-body', bodyClassName)}>{body}</div>
|
163
|
+
) : null}
|
164
|
+
{secondary || actions ? (
|
165
|
+
<div className={cx('Card-footer-wrapper', footerClassName)}>
|
166
|
+
{secondary ? (
|
167
|
+
<div className={cx('Card-secondary', secondaryClassName)}>
|
168
|
+
{secondary}
|
169
|
+
</div>
|
170
|
+
) : null}
|
171
|
+
{actions ? (
|
172
|
+
<div className={cx('Card-actions-wrapper')}>{actions}</div>
|
173
|
+
) : null}
|
174
|
+
</div>
|
175
|
+
) : null}
|
176
|
+
</div>
|
177
|
+
</div>
|
178
|
+
) : (
|
179
|
+
<div>
|
180
|
+
{heading}
|
181
|
+
{body ? (
|
182
|
+
<div className={cx('Card-body', bodyClassName)}>{body}</div>
|
183
|
+
) : null}
|
184
|
+
{secondary || actions ? (
|
185
|
+
<div className={cx('Card-footer-wrapper', footerClassName)}>
|
186
|
+
{secondary ? (
|
187
|
+
<div className={cx('Card-secondary', secondaryClassName)}>
|
188
|
+
{secondary}
|
189
|
+
</div>
|
190
|
+
) : null}
|
191
|
+
{actions ? (
|
192
|
+
<div className={cx('Card-actions-wrapper')}>{actions}</div>
|
193
|
+
) : null}
|
194
|
+
</div>
|
195
|
+
) : null}
|
196
|
+
</div>
|
197
|
+
)}
|
198
|
+
</div>
|
199
|
+
);
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
export default themeable(Card);
|
@@ -288,6 +288,8 @@ export interface DateProps extends LocaleProps, ThemeProps {
|
|
288
288
|
largeMode?: boolean;
|
289
289
|
onScheduleClick?: (scheduleData: any) => void;
|
290
290
|
|
291
|
+
useMobileUI?: boolean;
|
292
|
+
|
291
293
|
// 下面那个千万不要写,写了就会导致 keyof DateProps 得到的结果是 string | number;
|
292
294
|
// [propName: string]: any;
|
293
295
|
}
|
@@ -567,6 +569,7 @@ export class DatePicker extends React.Component<DateProps, DatePickerState> {
|
|
567
569
|
const isOpened = this.state.isOpened;
|
568
570
|
let date: moment.Moment | undefined = this.state.value;
|
569
571
|
|
572
|
+
|
570
573
|
if (embed) {
|
571
574
|
let schedulesData: DateProps['schedules'] = undefined;
|
572
575
|
if (schedules && Array.isArray(schedules)) {
|
@@ -0,0 +1,145 @@
|
|
1
|
+
/**
|
2
|
+
* @file Picker
|
3
|
+
* @description 移动端列滚动选择器
|
4
|
+
*/
|
5
|
+
import React, {
|
6
|
+
memo,
|
7
|
+
ReactNode,
|
8
|
+
useState
|
9
|
+
} from 'react';
|
10
|
+
import {uncontrollable} from 'uncontrollable';
|
11
|
+
|
12
|
+
import {themeable, ThemeProps} from '../theme';
|
13
|
+
import {localeable, LocaleProps} from '../locale';
|
14
|
+
|
15
|
+
import Button from './Button';
|
16
|
+
import {PickerColumnItem, default as Column} from './PickerColumn';
|
17
|
+
|
18
|
+
export type PickerValue = string | number;
|
19
|
+
|
20
|
+
export interface PickerProps extends ThemeProps, LocaleProps {
|
21
|
+
title?: String | ReactNode,
|
22
|
+
labelField?: string;
|
23
|
+
className?: string;
|
24
|
+
showToolbar?: boolean;
|
25
|
+
defaultValue?: PickerValue[];
|
26
|
+
value?: PickerValue[];
|
27
|
+
swipeDuration?: number;
|
28
|
+
visibleItemCount?: number;
|
29
|
+
itemHeight?: number;
|
30
|
+
columns: PickerColumnItem[] | PickerColumnItem;
|
31
|
+
onChange?: (
|
32
|
+
value?: PickerValue[],
|
33
|
+
index?: number,
|
34
|
+
confirm?: boolean
|
35
|
+
) => void;
|
36
|
+
onClose?: (
|
37
|
+
value?: PickerValue[]
|
38
|
+
) => void;
|
39
|
+
onConfirm?: (
|
40
|
+
value?: PickerValue[]
|
41
|
+
) => void;
|
42
|
+
}
|
43
|
+
|
44
|
+
function fixToArray(data: any) {
|
45
|
+
if (!Array.isArray(data)) {
|
46
|
+
return [data];
|
47
|
+
}
|
48
|
+
return data;
|
49
|
+
}
|
50
|
+
|
51
|
+
const Picker = memo<PickerProps>((props) => {
|
52
|
+
const {
|
53
|
+
labelField,
|
54
|
+
visibleItemCount = 5,
|
55
|
+
value = [],
|
56
|
+
swipeDuration = 1000,
|
57
|
+
columns = [],
|
58
|
+
itemHeight = 30,
|
59
|
+
showToolbar = true,
|
60
|
+
className='',
|
61
|
+
classnames: cx,
|
62
|
+
classPrefix: ns,
|
63
|
+
translate: __
|
64
|
+
} = props;
|
65
|
+
|
66
|
+
const _columns = fixToArray(columns);
|
67
|
+
const [innerValue, setInnerValue] = useState<PickerValue[]>(
|
68
|
+
fixToArray(props.value === undefined ? props.defaultValue || [] : value )
|
69
|
+
);
|
70
|
+
|
71
|
+
const close = () => {
|
72
|
+
if (props.onClose) {
|
73
|
+
props.onClose(innerValue);
|
74
|
+
}
|
75
|
+
};
|
76
|
+
|
77
|
+
const confirm = () => {
|
78
|
+
if (props.onConfirm) {
|
79
|
+
props.onConfirm(innerValue);
|
80
|
+
}
|
81
|
+
};
|
82
|
+
|
83
|
+
const onChange = (itemValue: PickerValue, columnIndex: number, confirm?: boolean) => {
|
84
|
+
const nextInnerValue = [...innerValue];
|
85
|
+
nextInnerValue[columnIndex] = itemValue;
|
86
|
+
setInnerValue(nextInnerValue);
|
87
|
+
if (props.onChange) {
|
88
|
+
props.onChange(nextInnerValue, columnIndex, confirm);
|
89
|
+
}
|
90
|
+
};
|
91
|
+
|
92
|
+
const renderColumnItem = (item: PickerColumnItem, index: number) => {
|
93
|
+
return (
|
94
|
+
<Column
|
95
|
+
{...item}
|
96
|
+
classnames={cx}
|
97
|
+
classPrefix={ns}
|
98
|
+
labelField={labelField}
|
99
|
+
itemHeight={itemHeight}
|
100
|
+
swipeDuration={swipeDuration}
|
101
|
+
visibleItemCount={visibleItemCount}
|
102
|
+
value={innerValue[index]}
|
103
|
+
onChange={(val: string | number, i, confirm) => {
|
104
|
+
onChange(val, index, confirm);
|
105
|
+
}}
|
106
|
+
/>)
|
107
|
+
};
|
108
|
+
|
109
|
+
const wrapHeight = itemHeight * +visibleItemCount;
|
110
|
+
const frameStyle = {height: `${itemHeight}px`};
|
111
|
+
const columnsStyle = {height: `${wrapHeight}px`};
|
112
|
+
const maskStyle = {
|
113
|
+
backgroundSize: `100% ${(wrapHeight - itemHeight) / 2}px`
|
114
|
+
};
|
115
|
+
|
116
|
+
return (
|
117
|
+
<div
|
118
|
+
className={cx(className, 'PickerColumns', 'PickerColumns-popOver')}
|
119
|
+
>
|
120
|
+
{showToolbar && <div className={cx('PickerColumns-toolbar')}>
|
121
|
+
<Button className="PickerColumns-cancel" level="default" onClick={close}>
|
122
|
+
{__('cancel')}
|
123
|
+
</Button>
|
124
|
+
<Button className="PickerColumns-confirm" level="primary" onClick={confirm}>
|
125
|
+
{__('confirm')}
|
126
|
+
</Button>
|
127
|
+
</div>}
|
128
|
+
<div className={cx('PickerColumns-columns')} style={columnsStyle}>
|
129
|
+
{
|
130
|
+
_columns.map((column: PickerColumnItem, index: number) => renderColumnItem(column, index))
|
131
|
+
}
|
132
|
+
<div className={cx('PickerColumns-mask')} style={maskStyle}></div>
|
133
|
+
<div className={cx('PickerColumns-frame')} style={frameStyle}></div>
|
134
|
+
</div>
|
135
|
+
</div>
|
136
|
+
);
|
137
|
+
});
|
138
|
+
|
139
|
+
export default themeable(
|
140
|
+
localeable(
|
141
|
+
uncontrollable(Picker, {
|
142
|
+
value: 'onChange'
|
143
|
+
})
|
144
|
+
)
|
145
|
+
);
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
2
|
* @file Picker
|
3
|
-
* @description
|
3
|
+
* @description 移动端列滚动选择器
|
4
4
|
*/
|
5
5
|
import React, {
|
6
6
|
useEffect,
|
@@ -8,8 +8,7 @@ import React, {
|
|
8
8
|
useRef,
|
9
9
|
useImperativeHandle,
|
10
10
|
useCallback,
|
11
|
-
forwardRef
|
12
|
-
CSSProperties
|
11
|
+
forwardRef
|
13
12
|
} from 'react';
|
14
13
|
import isObject from 'lodash/isObject';
|
15
14
|
import cloneDeep from 'lodash/cloneDeep';
|
@@ -18,37 +17,25 @@ import {uncontrollable} from 'uncontrollable';
|
|
18
17
|
import {useSetState, useUpdateEffect} from '../hooks';
|
19
18
|
import {range} from '../utils/helper';
|
20
19
|
import {themeable, ThemeProps} from '../theme';
|
21
|
-
import {localeable, LocaleProps} from '../locale';
|
22
20
|
import useTouch from '../hooks/use-touch';
|
23
|
-
import Button from './Button';
|
24
21
|
|
25
|
-
export interface
|
26
|
-
|
27
|
-
style?: CSSProperties;
|
28
|
-
index?: number;
|
29
|
-
labelField: string;
|
22
|
+
export interface PickerColumnItem {
|
23
|
+
labelField?: string;
|
30
24
|
readonly?: boolean;
|
31
|
-
value
|
32
|
-
swipeDuration?: number
|
33
|
-
visibleItemCount?: number
|
25
|
+
value?: PickerOption;
|
26
|
+
swipeDuration?: number;
|
27
|
+
visibleItemCount?: number;
|
28
|
+
itemHeight?: number;
|
34
29
|
options?: PickerOption[];
|
35
|
-
children?: any;
|
36
30
|
optionRender?: (option: string | object | PickerOption) => React.ReactNode;
|
37
31
|
onChange?: (
|
38
32
|
value?: PickerOption | string,
|
39
33
|
index?: number,
|
40
34
|
confirm?: boolean
|
41
35
|
) => void;
|
42
|
-
|
43
|
-
onConfirm?: () => void;
|
44
|
-
}
|
36
|
+
};
|
45
37
|
|
46
|
-
export interface
|
47
|
-
values?: string[];
|
48
|
-
className?: string;
|
49
|
-
children?: Column[];
|
50
|
-
disabled?: boolean;
|
51
|
-
}
|
38
|
+
export interface PickerColumnProps extends PickerColumnItem, ThemeProps {}
|
52
39
|
|
53
40
|
export type PickerOption = string | number | PickerObjectOption;
|
54
41
|
|
@@ -77,23 +64,17 @@ function getElementTranslateY(element: HTMLElement | null) {
|
|
77
64
|
function isOptionDisabled(option: PickerOption) {
|
78
65
|
return isObject(option) && option.disabled;
|
79
66
|
}
|
80
|
-
|
67
|
+
|
81
68
|
const PickerColumn = forwardRef<{}, PickerColumnProps>((props, ref) => {
|
82
69
|
const {
|
83
|
-
onClose,
|
84
|
-
onConfirm,
|
85
|
-
mobileClassName,
|
86
70
|
visibleItemCount = 5,
|
71
|
+
itemHeight = 30,
|
87
72
|
value,
|
88
73
|
swipeDuration = 1000,
|
89
|
-
labelField = '
|
90
|
-
translate: __,
|
74
|
+
labelField = 'text',
|
91
75
|
options = [],
|
92
76
|
classnames: cx
|
93
77
|
} = props;
|
94
|
-
let itemHeight = 24;
|
95
|
-
|
96
|
-
const defaultIndex = options.findIndex(item => item === value);
|
97
78
|
|
98
79
|
const root = useRef(null);
|
99
80
|
const menuItemRef = useRef(null);
|
@@ -105,21 +86,9 @@ const PickerColumn = forwardRef<{}, PickerColumnProps>((props, ref) => {
|
|
105
86
|
const touchStartTime = useRef(0);
|
106
87
|
const momentumOffset = useRef(0);
|
107
88
|
|
108
|
-
if (menuItemRef.current) {
|
109
|
-
//@ts-ignore
|
110
|
-
itemHeight = menuItemRef.current.getBoundingClientRect().height;
|
111
|
-
}
|
112
|
-
|
113
|
-
const [state, updateState] = useSetState({
|
114
|
-
index: defaultIndex,
|
115
|
-
offset: 0,
|
116
|
-
duration: 0,
|
117
|
-
options: cloneDeep(options)
|
118
|
-
});
|
119
|
-
|
120
89
|
const touch = useTouch();
|
121
|
-
|
122
|
-
const
|
90
|
+
const count = options.length;
|
91
|
+
const defaultIndex = options.findIndex(item => item === value);
|
123
92
|
|
124
93
|
const baseOffset = useMemo(() => {
|
125
94
|
// 默认转入第一个选项的位置
|
@@ -128,20 +97,27 @@ const PickerColumn = forwardRef<{}, PickerColumnProps>((props, ref) => {
|
|
128
97
|
|
129
98
|
const adjustIndex = (index: number) => {
|
130
99
|
index = range(index, 0, count);
|
131
|
-
if (!
|
100
|
+
if (!options) {
|
132
101
|
return;
|
133
102
|
}
|
134
103
|
|
135
104
|
for (let i = index; i < count; i += 1) {
|
136
|
-
if (!isOptionDisabled(
|
105
|
+
if (!isOptionDisabled(options[i])) return i;
|
137
106
|
}
|
138
107
|
for (let i = index - 1; i >= 0; i -= 1) {
|
139
|
-
if (!isOptionDisabled(
|
108
|
+
if (!isOptionDisabled(options[i])) return i;
|
140
109
|
}
|
141
110
|
|
142
111
|
return null;
|
143
112
|
};
|
144
113
|
|
114
|
+
const [state, updateState] = useSetState({
|
115
|
+
index: adjustIndex(defaultIndex) || 0,
|
116
|
+
offset: 0,
|
117
|
+
duration: 0,
|
118
|
+
options: cloneDeep(options)
|
119
|
+
});
|
120
|
+
|
145
121
|
/**
|
146
122
|
*
|
147
123
|
* @param index 索引
|
@@ -156,9 +132,14 @@ const PickerColumn = forwardRef<{}, PickerColumnProps>((props, ref) => {
|
|
156
132
|
updateState({index});
|
157
133
|
|
158
134
|
if (emitChange && props.onChange) {
|
159
|
-
|
160
|
-
|
161
|
-
|
135
|
+
requestAnimationFrame(
|
136
|
+
() => {
|
137
|
+
props.onChange?.(options[index], index, confirm);
|
138
|
+
}
|
139
|
+
);
|
140
|
+
// setTimeout(() => {
|
141
|
+
// props.onChange?.(options[index], index, confirm);
|
142
|
+
// }, 0);
|
162
143
|
}
|
163
144
|
};
|
164
145
|
|
@@ -175,7 +156,8 @@ const PickerColumn = forwardRef<{}, PickerColumnProps>((props, ref) => {
|
|
175
156
|
const setOptions = (options: Array<PickerOption>) => {
|
176
157
|
if (JSON.stringify(options) !== JSON.stringify(state.options)) {
|
177
158
|
updateState({options});
|
178
|
-
|
159
|
+
const index = options.findIndex(item => item === value) || 0;
|
160
|
+
setIndex(index, true, true);
|
179
161
|
}
|
180
162
|
};
|
181
163
|
|
@@ -189,7 +171,7 @@ const PickerColumn = forwardRef<{}, PickerColumnProps>((props, ref) => {
|
|
189
171
|
};
|
190
172
|
|
191
173
|
const getOptionText = (option: [] | PickerOption) => {
|
192
|
-
if (isObject(option) &&
|
174
|
+
if (isObject(option) && labelField in option) {
|
193
175
|
//@ts-ignore
|
194
176
|
return option[labelField];
|
195
177
|
}
|
@@ -298,6 +280,10 @@ const PickerColumn = forwardRef<{}, PickerColumnProps>((props, ref) => {
|
|
298
280
|
};
|
299
281
|
|
300
282
|
const renderOptions = () => {
|
283
|
+
const style = {
|
284
|
+
height: `${itemHeight}px`,
|
285
|
+
lineHeight: `${itemHeight}px`
|
286
|
+
};
|
301
287
|
return state.options.map((option, index: number) => {
|
302
288
|
const text: string | PickerOption = getOptionText(option);
|
303
289
|
const disabled = isOptionDisabled(option);
|
@@ -305,6 +291,7 @@ const PickerColumn = forwardRef<{}, PickerColumnProps>((props, ref) => {
|
|
305
291
|
const data = {
|
306
292
|
role: 'button',
|
307
293
|
key: index,
|
294
|
+
style,
|
308
295
|
tabIndex: disabled ? -1 : 0,
|
309
296
|
className: props.classnames(`PickerColumns-columnItem`, {
|
310
297
|
'is-disabled': disabled,
|
@@ -314,7 +301,7 @@ const PickerColumn = forwardRef<{}, PickerColumnProps>((props, ref) => {
|
|
314
301
|
onClickItem(index);
|
315
302
|
}
|
316
303
|
};
|
317
|
-
|
304
|
+
|
318
305
|
const childData = {
|
319
306
|
className: 'text-ellipsis',
|
320
307
|
children: text
|
@@ -335,7 +322,7 @@ const PickerColumn = forwardRef<{}, PickerColumnProps>((props, ref) => {
|
|
335
322
|
const setValue = (value: string) => {
|
336
323
|
const {options} = state;
|
337
324
|
for (let i = 0; i < options.length; i += 1) {
|
338
|
-
if (
|
325
|
+
if (options[i] === value) {
|
339
326
|
return setIndex(i);
|
340
327
|
}
|
341
328
|
}
|
@@ -348,7 +335,7 @@ const PickerColumn = forwardRef<{}, PickerColumnProps>((props, ref) => {
|
|
348
335
|
);
|
349
336
|
|
350
337
|
useEffect(() => {
|
351
|
-
setIndex(defaultIndex
|
338
|
+
setIndex(defaultIndex);
|
352
339
|
}, [defaultIndex]);
|
353
340
|
|
354
341
|
useUpdateEffect(() => {
|
@@ -369,61 +356,37 @@ const PickerColumn = forwardRef<{}, PickerColumnProps>((props, ref) => {
|
|
369
356
|
transitionDuration: `${state.duration}ms`,
|
370
357
|
transitionProperty: state.duration ? 'all' : 'none'
|
371
358
|
};
|
372
|
-
|
373
|
-
const wrapHeight = itemHeight * +visibleItemCount;
|
374
|
-
const frameStyle = {height: `${itemHeight}px`};
|
375
|
-
const columnsStyle = {height: `${wrapHeight}px`};
|
376
|
-
const maskStyle = {
|
377
|
-
backgroundSize: `100% ${(wrapHeight - itemHeight) / 2}px`
|
378
|
-
};
|
379
|
-
|
380
359
|
return (
|
381
|
-
|
382
|
-
className={cx(mobileClassName, 'PickerColumns', 'PickerColumns-popOver')}
|
383
|
-
>
|
384
|
-
<div className={cx('PickerColumns-toolbar')}>
|
385
|
-
<Button level="default" onClick={onClose}>
|
386
|
-
{__('cancel')}
|
387
|
-
</Button>
|
388
|
-
<Button level="primary" onClick={onConfirm}>
|
389
|
-
{__('confirm')}
|
390
|
-
</Button>
|
391
|
-
</div>
|
392
|
-
<div className={cx('PickerColumns-columns')} style={columnsStyle}>
|
393
|
-
<div
|
360
|
+
<div
|
394
361
|
ref={root}
|
395
|
-
className={props.classnames(props.className)}
|
362
|
+
className={props.classnames('PickerColumns', props.className)}
|
396
363
|
onTouchStart={onTouchStart}
|
397
364
|
onTouchMove={onTouchMove}
|
398
365
|
onTouchEnd={onTouchEnd}
|
399
366
|
onTouchCancel={onTouchEnd}
|
400
|
-
|
367
|
+
>
|
401
368
|
<ul
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
369
|
+
ref={wrapper}
|
370
|
+
style={wrapperStyle}
|
371
|
+
className={props.classnames('PickerColumns-columnWrapper')}
|
372
|
+
onTransitionEnd={stopMomentum}
|
406
373
|
>
|
407
|
-
|
374
|
+
{renderOptions()}
|
408
375
|
</ul>
|
409
|
-
</div>
|
410
|
-
<div className={cx('PickerColumns-mask')} style={maskStyle}></div>
|
411
|
-
<div className={cx('PickerColumns-frame')} style={frameStyle}></div>
|
412
376
|
</div>
|
413
|
-
</div>
|
414
377
|
);
|
415
378
|
});
|
416
379
|
|
417
380
|
PickerColumn.defaultProps = {
|
418
381
|
options: [],
|
419
382
|
visibleItemCount: 5,
|
420
|
-
swipeDuration: 1000
|
383
|
+
swipeDuration: 1000,
|
384
|
+
itemHeight: 30
|
421
385
|
};
|
422
386
|
|
423
387
|
export default themeable(
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
})
|
428
|
-
)
|
388
|
+
uncontrollable(PickerColumn, {
|
389
|
+
value: 'onChange'
|
390
|
+
})
|
429
391
|
);
|
392
|
+
|