@jswork/antd-components 1.0.78 → 1.0.80
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 +1 -56
- package/dist/main.cjs.js +77 -0
- package/dist/main.cjs.js.map +1 -0
- package/dist/main.d.mts +1062 -0
- package/dist/main.d.ts +1062 -34
- package/dist/main.esm.js +77 -0
- package/dist/main.esm.js.map +1 -0
- package/dist/style.css +2 -267
- package/dist/style.css.map +1 -0
- package/package.json +30 -75
- package/src/lib/_abstract-upload.tsx +131 -0
- package/src/lib/alert.tsx +53 -0
- package/src/lib/breadcrumb.tsx +40 -0
- package/src/lib/checkable-dropdown.tsx +170 -0
- package/src/lib/checkable-tag-list.tsx +122 -0
- package/src/lib/checkable-tag.tsx +101 -0
- package/src/lib/checkbox-group.tsx +72 -0
- package/src/lib/checkbox.tsx +59 -0
- package/src/lib/codeflask.tsx +17 -0
- package/src/lib/confirm-button.tsx +87 -0
- package/src/lib/date-picker.tsx +60 -0
- package/src/lib/editable-tag-group.tsx +234 -0
- package/src/lib/input-hidden.tsx +13 -0
- package/src/lib/input-number.tsx +52 -0
- package/src/lib/input-tags.tsx +140 -0
- package/src/lib/input-token.tsx +102 -0
- package/src/lib/input.tsx +58 -0
- package/src/lib/interactive-list.tsx +173 -0
- package/src/lib/pre-select.tsx +128 -0
- package/src/lib/radio-group.tsx +67 -0
- package/src/lib/range-picker.tsx +59 -0
- package/src/lib/rate.tsx +38 -0
- package/src/lib/search.tsx +49 -0
- package/src/lib/select.tsx +86 -0
- package/src/lib/slider-range.tsx +40 -0
- package/src/lib/slider.tsx +37 -0
- package/src/lib/switch.tsx +52 -0
- package/src/lib/textarea.tsx +29 -0
- package/src/lib/time-picker.tsx +66 -0
- package/src/lib/transfer.tsx +70 -0
- package/src/lib/tree-select.tsx +64 -0
- package/src/lib/tree.tsx +60 -0
- package/src/lib/upload-dragger.tsx +60 -0
- package/src/lib/upload-picture-card.tsx +56 -0
- package/src/lib/upload-picture.tsx +47 -0
- package/src/lib/upload.tsx +55 -0
- package/src/main.ts +34 -0
- package/src/style.scss +191 -0
- package/LICENSE.txt +0 -21
- package/dist/index.esm.js +0 -10
- package/dist/index.js +0 -10
- package/dist/lib/_abstract-upload.d.ts +0 -40
- package/dist/lib/alert.d.ts +0 -14
- package/dist/lib/breadcrumb.d.ts +0 -29
- package/dist/lib/checkable-dropdown.d.ts +0 -52
- package/dist/lib/checkable-tag-list.d.ts +0 -51
- package/dist/lib/checkable-tag.d.ts +0 -43
- package/dist/lib/checkbox-group.d.ts +0 -38
- package/dist/lib/checkbox.d.ts +0 -27
- package/dist/lib/codeflask.d.ts +0 -9
- package/dist/lib/confirm-button.d.ts +0 -23
- package/dist/lib/date-picker.d.ts +0 -26
- package/dist/lib/editable-tag-group.d.ts +0 -92
- package/dist/lib/input-hidden.d.ts +0 -7
- package/dist/lib/input-number.d.ts +0 -27
- package/dist/lib/input-tags.d.ts +0 -37
- package/dist/lib/input-token.d.ts +0 -39
- package/dist/lib/input.d.ts +0 -29
- package/dist/lib/interactive-list.d.ts +0 -56
- package/dist/lib/pre-select.d.ts +0 -57
- package/dist/lib/radio-group.d.ts +0 -42
- package/dist/lib/range-picker.d.ts +0 -27
- package/dist/lib/rate.d.ts +0 -23
- package/dist/lib/search.d.ts +0 -29
- package/dist/lib/select.d.ts +0 -43
- package/dist/lib/slider-range.d.ts +0 -23
- package/dist/lib/slider.d.ts +0 -22
- package/dist/lib/switch.d.ts +0 -27
- package/dist/lib/textarea.d.ts +0 -22
- package/dist/lib/time-picker.d.ts +0 -29
- package/dist/lib/transfer.d.ts +0 -37
- package/dist/lib/tree-select.d.ts +0 -32
- package/dist/lib/tree.d.ts +0 -31
- package/dist/lib/upload-dragger.d.ts +0 -28
- package/dist/lib/upload-picture-card.d.ts +0 -14
- package/dist/lib/upload-picture.d.ts +0 -14
- package/dist/lib/upload.d.ts +0 -28
- /package/{dist → src}/styles/input-tags.scss +0 -0
- /package/{dist → src}/styles/override.scss +0 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import noop from '@jswork/noop';
|
|
2
|
+
import ReactList from '@jswork/react-list';
|
|
3
|
+
import cx from 'classnames';
|
|
4
|
+
import React, { Component, HTMLAttributes } from 'react';
|
|
5
|
+
import deepEqual from 'fast-deep-equal';
|
|
6
|
+
|
|
7
|
+
const CLASS_NAME = 'ac-interactive-list';
|
|
8
|
+
|
|
9
|
+
type StdEventTarget = { target: { value: any } };
|
|
10
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
11
|
+
type TemplateCallback = (
|
|
12
|
+
item: { item: any; index: number; items: any[] },
|
|
13
|
+
cb: any
|
|
14
|
+
) => React.ReactNode;
|
|
15
|
+
|
|
16
|
+
export type ReactInteractiveListProps = {
|
|
17
|
+
/**
|
|
18
|
+
* The extended className for component.
|
|
19
|
+
*/
|
|
20
|
+
className?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The minimum size.
|
|
23
|
+
*/
|
|
24
|
+
min: number;
|
|
25
|
+
/**
|
|
26
|
+
* The max size.
|
|
27
|
+
*/
|
|
28
|
+
max: number;
|
|
29
|
+
/**
|
|
30
|
+
* The data source.
|
|
31
|
+
*/
|
|
32
|
+
items: any[];
|
|
33
|
+
/**
|
|
34
|
+
* The data item template.
|
|
35
|
+
*/
|
|
36
|
+
template: TemplateCallback;
|
|
37
|
+
/**
|
|
38
|
+
* The action of `create` component.
|
|
39
|
+
*/
|
|
40
|
+
templateCreate: (...args) => React.ReactNode;
|
|
41
|
+
/**
|
|
42
|
+
* The empty create template.
|
|
43
|
+
*/
|
|
44
|
+
templateDefault: () => React.ReactNode;
|
|
45
|
+
/**
|
|
46
|
+
* The change handler.
|
|
47
|
+
*/
|
|
48
|
+
onChange: StdCallback;
|
|
49
|
+
/**
|
|
50
|
+
* When trigger max/min boundary.
|
|
51
|
+
*/
|
|
52
|
+
onError: StdCallback;
|
|
53
|
+
/**
|
|
54
|
+
* Forwards a ref to the underlying div element.
|
|
55
|
+
*/
|
|
56
|
+
forwardedRef: any;
|
|
57
|
+
} & HTMLAttributes<any>;
|
|
58
|
+
|
|
59
|
+
interface ReactInteractiveListState {
|
|
60
|
+
value: any[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
class ReactInteractiveList extends Component<ReactInteractiveListProps, ReactInteractiveListState> {
|
|
64
|
+
static displayName = CLASS_NAME;
|
|
65
|
+
static defaultProps = {
|
|
66
|
+
min: 0,
|
|
67
|
+
max: 10,
|
|
68
|
+
items: [],
|
|
69
|
+
template: noop,
|
|
70
|
+
templateCreate: noop,
|
|
71
|
+
templateDefault: noop,
|
|
72
|
+
onChange: noop,
|
|
73
|
+
onError: noop
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
get length() {
|
|
77
|
+
const { value } = this.state;
|
|
78
|
+
return value.length;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get isLteMin() {
|
|
82
|
+
const { min } = this.props;
|
|
83
|
+
return this.length <= min;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get isGteMax() {
|
|
87
|
+
const { max } = this.props;
|
|
88
|
+
return this.length >= max;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get listView() {
|
|
92
|
+
const { value } = this.state;
|
|
93
|
+
return <ReactList items={value} template={this.template} />;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get createView() {
|
|
97
|
+
const { value } = this.state;
|
|
98
|
+
const { templateCreate, templateDefault } = this.props;
|
|
99
|
+
const cb = () => {
|
|
100
|
+
if (this.isGteMax) return;
|
|
101
|
+
value.push(templateDefault());
|
|
102
|
+
this.handleChange(value);
|
|
103
|
+
};
|
|
104
|
+
return templateCreate({ items: value }, cb);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
constructor(inProps) {
|
|
108
|
+
super(inProps);
|
|
109
|
+
const { items } = inProps;
|
|
110
|
+
this.state = { value: [...items] };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
shouldComponentUpdate(inProps) {
|
|
114
|
+
const { items } = inProps;
|
|
115
|
+
const isEqual = deepEqual(this.state.value, items);
|
|
116
|
+
if (!isEqual) {
|
|
117
|
+
this.setState({ value: [...items] });
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
template = ({ item, index }) => {
|
|
123
|
+
const { template } = this.props;
|
|
124
|
+
const { value } = this.state;
|
|
125
|
+
const cb = () => {
|
|
126
|
+
if (this.isLteMin) return;
|
|
127
|
+
value.splice(index, 1);
|
|
128
|
+
this.handleChange(value);
|
|
129
|
+
};
|
|
130
|
+
return template({ item, index, items: value }, cb);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
handleChange = (inValue) => {
|
|
134
|
+
const { onChange, onError, min, max } = this.props;
|
|
135
|
+
const target = { value: inValue };
|
|
136
|
+
this.setState(target, () => {
|
|
137
|
+
onChange({ target });
|
|
138
|
+
this.length < min && onError({ target: { value: 'EQ_MIN' } });
|
|
139
|
+
this.length > max && onError({ target: { value: 'EQ_MAX' } });
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
notify = (inValue) => {
|
|
144
|
+
this.handleChange(inValue);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
render() {
|
|
148
|
+
const {
|
|
149
|
+
className,
|
|
150
|
+
forwardedRef,
|
|
151
|
+
min,
|
|
152
|
+
max,
|
|
153
|
+
items,
|
|
154
|
+
template,
|
|
155
|
+
templateCreate,
|
|
156
|
+
templateDefault,
|
|
157
|
+
onChange,
|
|
158
|
+
onError,
|
|
159
|
+
...props
|
|
160
|
+
} = this.props;
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<div className={cx(CLASS_NAME, className)} ref={forwardedRef} {...props}>
|
|
164
|
+
{this.listView}
|
|
165
|
+
{this.createView}
|
|
166
|
+
</div>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export const AcInteractiveList = React.forwardRef((props: any, ref) => {
|
|
172
|
+
return <ReactInteractiveList {...props} ref={ref} />;
|
|
173
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import noop from '@jswork/noop';
|
|
2
|
+
import cx from 'classnames';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { AcInput } from './input';
|
|
5
|
+
import { AcSelect } from './select';
|
|
6
|
+
import { AcSearch } from './search';
|
|
7
|
+
|
|
8
|
+
const CLASS_NAME = 'ac-pre-select';
|
|
9
|
+
const DEFAULT_VALUE = { option: null, keyword: '' };
|
|
10
|
+
|
|
11
|
+
export interface Value {
|
|
12
|
+
option: string;
|
|
13
|
+
keyword: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type AcPreSelectProps = {
|
|
17
|
+
/**
|
|
18
|
+
* The extended className for component.
|
|
19
|
+
*/
|
|
20
|
+
className?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Default value.
|
|
23
|
+
*/
|
|
24
|
+
value?: Value;
|
|
25
|
+
/**
|
|
26
|
+
* Select options.
|
|
27
|
+
*/
|
|
28
|
+
items?: any[];
|
|
29
|
+
/**
|
|
30
|
+
* The change handler.
|
|
31
|
+
*/
|
|
32
|
+
onChange?: Function;
|
|
33
|
+
/**
|
|
34
|
+
* The handler for search.
|
|
35
|
+
*/
|
|
36
|
+
onSearch?: Function;
|
|
37
|
+
/**
|
|
38
|
+
* If use search input.
|
|
39
|
+
*/
|
|
40
|
+
searchable?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The prefix select options.
|
|
43
|
+
*/
|
|
44
|
+
selectOptions?: any;
|
|
45
|
+
/**
|
|
46
|
+
* The suffix input options.
|
|
47
|
+
*/
|
|
48
|
+
inputOptions?: any;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export class AcPreSelect extends React.Component<AcPreSelectProps> {
|
|
52
|
+
static displayName = CLASS_NAME;
|
|
53
|
+
static formSchema = CLASS_NAME;
|
|
54
|
+
static version = '__VERSION__';
|
|
55
|
+
static defaultProps = {
|
|
56
|
+
onChange: noop,
|
|
57
|
+
onSearch: noop,
|
|
58
|
+
searchable: false
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
state = { value: this.props.value };
|
|
62
|
+
|
|
63
|
+
get addonView() {
|
|
64
|
+
const { items, selectOptions } = this.props;
|
|
65
|
+
const { value } = this.state;
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<AcSelect
|
|
69
|
+
value={value?.option}
|
|
70
|
+
items={items}
|
|
71
|
+
onChange={this.handleChange.bind(this, 'option')}
|
|
72
|
+
{...selectOptions}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
handleFiledAction = (inField, inEvent, inCallback) => {
|
|
78
|
+
const { value } = this.state;
|
|
79
|
+
const _value = value || DEFAULT_VALUE;
|
|
80
|
+
_value![inField] = inEvent.target.value;
|
|
81
|
+
const target = { value: _value };
|
|
82
|
+
this.setState(target);
|
|
83
|
+
inCallback!({ target });
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
handleChange = (inField, inEvent) => {
|
|
87
|
+
this.handleFiledAction(inField, inEvent, this.props.onChange);
|
|
88
|
+
if (inField === 'option') {
|
|
89
|
+
this.handleFiledAction(inField, inEvent, this.props.onSearch);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
handleSearch = (inField, inEvent) => {
|
|
94
|
+
this.handleFiledAction(inField, inEvent, this.props.onSearch);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
render() {
|
|
98
|
+
const {
|
|
99
|
+
className,
|
|
100
|
+
value,
|
|
101
|
+
onChange,
|
|
102
|
+
onSearch,
|
|
103
|
+
searchable,
|
|
104
|
+
selectOptions,
|
|
105
|
+
inputOptions,
|
|
106
|
+
...props
|
|
107
|
+
} = this.props;
|
|
108
|
+
|
|
109
|
+
const AsTag = searchable ? AcSearch : AcInput;
|
|
110
|
+
const _value = this.state.value;
|
|
111
|
+
const computedProps = searchable
|
|
112
|
+
? { onSearch: this.handleSearch.bind(this, 'keyword') }
|
|
113
|
+
: null;
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<AsTag
|
|
117
|
+
data-component={CLASS_NAME}
|
|
118
|
+
className={cx(CLASS_NAME, className)}
|
|
119
|
+
addonBefore={this.addonView}
|
|
120
|
+
value={_value?.keyword}
|
|
121
|
+
onChange={this.handleChange.bind(this, 'keyword')}
|
|
122
|
+
{...computedProps}
|
|
123
|
+
{...props}
|
|
124
|
+
{...inputOptions}
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React, { HTMLAttributes } from 'react';
|
|
2
|
+
import ReactList from '@jswork/react-list';
|
|
3
|
+
import noop from '@jswork/noop';
|
|
4
|
+
import { Radio } from 'antd';
|
|
5
|
+
import cx from 'classnames';
|
|
6
|
+
import { radioKv } from '@jswork/antd-tpls/dist/esm';
|
|
7
|
+
|
|
8
|
+
const CLASS_NAME = 'ac-radio-group';
|
|
9
|
+
type StdEventTarget = { target: { value: any } };
|
|
10
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
11
|
+
type TemplateCallback = (item: { item: any; index: number }, opts?: any) => React.ReactNode;
|
|
12
|
+
|
|
13
|
+
type Props = {
|
|
14
|
+
className?: string;
|
|
15
|
+
value?: any;
|
|
16
|
+
defaultValue?: any;
|
|
17
|
+
items?: any[];
|
|
18
|
+
onChange?: StdCallback;
|
|
19
|
+
onSearch?: StdCallback;
|
|
20
|
+
template?: TemplateCallback;
|
|
21
|
+
templateOptions?: any;
|
|
22
|
+
buttonStyle?: 'solid' | 'outline';
|
|
23
|
+
} & HTMLAttributes<any>;
|
|
24
|
+
|
|
25
|
+
export class AcRadioGroup extends React.Component<Props> {
|
|
26
|
+
static displayName = CLASS_NAME;
|
|
27
|
+
static formSchema = CLASS_NAME;
|
|
28
|
+
static defaultProps = {
|
|
29
|
+
items: [],
|
|
30
|
+
template: radioKv,
|
|
31
|
+
onChange: noop,
|
|
32
|
+
onSearch: noop
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
get templateCallback() {
|
|
36
|
+
const { template, templateOptions } = this.props;
|
|
37
|
+
return (item) => template!(item, templateOptions);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
state = { value: this.props.value };
|
|
41
|
+
|
|
42
|
+
static getDerivedStateFromProps(inProps: Readonly<Props>, inState: any) {
|
|
43
|
+
const { value } = inProps;
|
|
44
|
+
if (value !== inState.value) return { value };
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
handleChange = (inEvent) => {
|
|
49
|
+
const { onChange, onSearch } = this.props;
|
|
50
|
+
const { value } = inEvent.target;
|
|
51
|
+
const target = { value };
|
|
52
|
+
this.setState(target);
|
|
53
|
+
onChange!({ target });
|
|
54
|
+
onSearch!({ target });
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
render() {
|
|
58
|
+
const { className, items, template, templateOptions, onChange, onSearch, ...props } =
|
|
59
|
+
this.props;
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Radio.Group className={cx(CLASS_NAME, className)} onChange={this.handleChange} {...props}>
|
|
63
|
+
<ReactList items={items} template={this.templateCallback} />
|
|
64
|
+
</Radio.Group>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { DatePicker } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
import moment from 'dayjs';
|
|
6
|
+
import { RangePickerProps } from 'antd/es/date-picker';
|
|
7
|
+
|
|
8
|
+
const CLASS_NAME = 'ac-range-picker';
|
|
9
|
+
const STD_FORMAT = 'YYYY-MM-DD HH:mm:ss';
|
|
10
|
+
const { RangePicker } = DatePicker;
|
|
11
|
+
|
|
12
|
+
type StdEventTarget = { target: { value: any } };
|
|
13
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
14
|
+
|
|
15
|
+
type Props = {
|
|
16
|
+
className?: string;
|
|
17
|
+
value?: any;
|
|
18
|
+
defaultValue?: any;
|
|
19
|
+
onChange?: StdCallback;
|
|
20
|
+
} & RangePickerProps;
|
|
21
|
+
|
|
22
|
+
export class AcRangePicker extends React.Component<Props> {
|
|
23
|
+
static displayName = CLASS_NAME;
|
|
24
|
+
static formSchema = CLASS_NAME;
|
|
25
|
+
static defaultProps = {
|
|
26
|
+
onChange: noop,
|
|
27
|
+
format: STD_FORMAT
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
handleChange = (inEvent) => {
|
|
31
|
+
const { onChange } = this.props;
|
|
32
|
+
onChange!({ target: { value: this.stringify(inEvent) } });
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
parse = (inValue) => {
|
|
36
|
+
const { format } = this.props;
|
|
37
|
+
return inValue.map((item) => moment(item, format as string));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
stringify = (inValue) => {
|
|
41
|
+
if (!inValue) return [];
|
|
42
|
+
const { format } = this.props;
|
|
43
|
+
return inValue.map((item) => item.format(format as string));
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
render() {
|
|
47
|
+
const { className, defaultValue, value, onChange, ...props } = this.props;
|
|
48
|
+
if (defaultValue) props['defaultValue'] = this.parse(defaultValue);
|
|
49
|
+
if (value) props['value'] = this.parse(value);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<RangePicker
|
|
53
|
+
className={cx(CLASS_NAME, className)}
|
|
54
|
+
onChange={this.handleChange}
|
|
55
|
+
{...props}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/lib/rate.tsx
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { Rate, RateProps } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
|
|
6
|
+
const CLASS_NAME = 'ac-rate';
|
|
7
|
+
type StdEventTarget = { target: { value: any } };
|
|
8
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
className?: string;
|
|
12
|
+
value?: number;
|
|
13
|
+
onChange?: StdCallback;
|
|
14
|
+
} & RateProps;
|
|
15
|
+
|
|
16
|
+
export class AcRate extends React.Component<Props> {
|
|
17
|
+
static displayName = CLASS_NAME;
|
|
18
|
+
static formSchema = CLASS_NAME;
|
|
19
|
+
static defaultProps = {
|
|
20
|
+
onChange: noop
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
handleChange = (inEvent) => {
|
|
24
|
+
const { onChange } = this.props;
|
|
25
|
+
onChange!({ target: { value: inEvent } });
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
render() {
|
|
29
|
+
const { className, value, onChange, ...props } = this.props;
|
|
30
|
+
return (
|
|
31
|
+
<Rate
|
|
32
|
+
className={cx(CLASS_NAME, className)}
|
|
33
|
+
onChange={this.handleChange}
|
|
34
|
+
{...props}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { Input } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
import { SearchProps } from 'antd/es/input';
|
|
6
|
+
|
|
7
|
+
const CLASS_NAME = 'ac-search';
|
|
8
|
+
type StdEventTarget = { target: { value: any } };
|
|
9
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
12
|
+
className?: string;
|
|
13
|
+
value?: boolean;
|
|
14
|
+
onChange?: StdCallback;
|
|
15
|
+
onSearch?: StdCallback;
|
|
16
|
+
autoComplete?: boolean;
|
|
17
|
+
} & SearchProps;
|
|
18
|
+
|
|
19
|
+
export class AcSearch extends React.Component<Props> {
|
|
20
|
+
static displayName = CLASS_NAME;
|
|
21
|
+
static formSchema = CLASS_NAME;
|
|
22
|
+
static defaultProps = {
|
|
23
|
+
onChange: noop,
|
|
24
|
+
onSearch: noop,
|
|
25
|
+
autoComplete: false,
|
|
26
|
+
placeholder: '输入关键字搜索'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
get complete() {
|
|
30
|
+
return this.props.autoComplete ? 'on' : 'off';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
handleSearch = (inEvent) => {
|
|
34
|
+
const { onSearch } = this.props;
|
|
35
|
+
onSearch!({ target: { value: inEvent } });
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
render() {
|
|
39
|
+
const { className, value, autoComplete, onSearch, ...props } = this.props;
|
|
40
|
+
return (
|
|
41
|
+
<Input.Search
|
|
42
|
+
className={cx(CLASS_NAME, className)}
|
|
43
|
+
autoComplete={this.complete}
|
|
44
|
+
onSearch={this.handleSearch}
|
|
45
|
+
{...props}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactList from '@jswork/react-list';
|
|
3
|
+
import noop from '@jswork/noop';
|
|
4
|
+
import { Select, SelectProps } from 'antd';
|
|
5
|
+
import cx from 'classnames';
|
|
6
|
+
import { selectKv, kv as KvTmpl } from '@jswork/antd-tpls';
|
|
7
|
+
|
|
8
|
+
const CLASS_NAME = 'ac-select';
|
|
9
|
+
const DEFAULT_KV = {
|
|
10
|
+
label: 'label',
|
|
11
|
+
value: 'value'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type StdEventTarget = { target: { value: any } };
|
|
15
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
16
|
+
type TemplateCallback = (item: { item: any; index: number }) => React.ReactNode;
|
|
17
|
+
|
|
18
|
+
type Props = {
|
|
19
|
+
className?: string;
|
|
20
|
+
items?: any[];
|
|
21
|
+
kv?: Record<string, string>;
|
|
22
|
+
onChange?: StdCallback;
|
|
23
|
+
onSearch?: StdCallback;
|
|
24
|
+
template?: TemplateCallback;
|
|
25
|
+
} & Omit<SelectProps, 'options'>;
|
|
26
|
+
|
|
27
|
+
export class AcSelect extends React.Component<Props> {
|
|
28
|
+
static displayName = CLASS_NAME;
|
|
29
|
+
static formSchema = CLASS_NAME;
|
|
30
|
+
static defaultProps = {
|
|
31
|
+
placeholder: '请选择',
|
|
32
|
+
items: [],
|
|
33
|
+
kv: DEFAULT_KV,
|
|
34
|
+
template: selectKv,
|
|
35
|
+
onChange: noop,
|
|
36
|
+
onSearch: noop
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
state = {
|
|
40
|
+
value: this.props.value
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
shouldComponentUpdate(nextProps: Readonly<Props>): boolean {
|
|
44
|
+
const { value } = nextProps;
|
|
45
|
+
const isNewValue = this.props.value !== value;
|
|
46
|
+
if (isNewValue && value !== this.state.value) {
|
|
47
|
+
this.setState({ value });
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
handleChange = (inValue) => {
|
|
53
|
+
const { onChange, onSearch } = this.props;
|
|
54
|
+
const target = { value: inValue };
|
|
55
|
+
const stdEvent: StdEventTarget = { target: { value: inValue } };
|
|
56
|
+
this.setState(target, () => {
|
|
57
|
+
onChange!(stdEvent);
|
|
58
|
+
onSearch!(stdEvent);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
template = (args) => {
|
|
63
|
+
const { template, kv } = this.props;
|
|
64
|
+
if (kv === DEFAULT_KV) return template!(args);
|
|
65
|
+
return KvTmpl(args, {
|
|
66
|
+
component: Select.Option,
|
|
67
|
+
...kv
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
render() {
|
|
72
|
+
const { className, onChange, onSearch, value, template, ...props } = this.props;
|
|
73
|
+
const { value: _value } = this.state;
|
|
74
|
+
return (
|
|
75
|
+
<ReactList
|
|
76
|
+
allowEmpty
|
|
77
|
+
as={Select}
|
|
78
|
+
onChange={this.handleChange}
|
|
79
|
+
className={cx(CLASS_NAME, className)}
|
|
80
|
+
value={_value}
|
|
81
|
+
template={this.template}
|
|
82
|
+
{...props}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { Slider } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
import { SliderRangeProps } from 'antd/es/slider';
|
|
6
|
+
|
|
7
|
+
const CLASS_NAME = 'ac-slider-range';
|
|
8
|
+
type StdEventTarget = { target: { value: any } };
|
|
9
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
12
|
+
className?: string;
|
|
13
|
+
range?: true;
|
|
14
|
+
onChange?: StdCallback;
|
|
15
|
+
} & Omit<SliderRangeProps, 'range'>;
|
|
16
|
+
|
|
17
|
+
export class AcSliderRange extends React.Component<Props> {
|
|
18
|
+
static displayName = CLASS_NAME;
|
|
19
|
+
static formSchema = CLASS_NAME;
|
|
20
|
+
static defaultProps = {
|
|
21
|
+
onChange: noop
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
handleChange = (inEvent) => {
|
|
25
|
+
const { onChange } = this.props;
|
|
26
|
+
onChange!({ target: { value: inEvent } });
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
render() {
|
|
30
|
+
const { className, range, onChange, ...props } = this.props;
|
|
31
|
+
return (
|
|
32
|
+
<Slider
|
|
33
|
+
range={true}
|
|
34
|
+
className={cx(CLASS_NAME, className)}
|
|
35
|
+
onChange={this.handleChange}
|
|
36
|
+
{...props}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { Slider, SliderSingleProps } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
|
|
6
|
+
const CLASS_NAME = 'ac-slider';
|
|
7
|
+
type StdEventTarget = { target: { value: any } };
|
|
8
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
className?: string;
|
|
12
|
+
onChange?: StdCallback;
|
|
13
|
+
} & SliderSingleProps;
|
|
14
|
+
|
|
15
|
+
export class AcSlider extends React.Component<Props> {
|
|
16
|
+
static displayName = CLASS_NAME;
|
|
17
|
+
static formSchema = CLASS_NAME;
|
|
18
|
+
static defaultProps = {
|
|
19
|
+
onChange: noop
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
handleChange = (inEvent) => {
|
|
23
|
+
const { onChange } = this.props;
|
|
24
|
+
onChange!({ target: { value: inEvent } });
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
render() {
|
|
28
|
+
const { className, value, onChange, ...props } = this.props;
|
|
29
|
+
return (
|
|
30
|
+
<Slider
|
|
31
|
+
className={cx(CLASS_NAME, className)}
|
|
32
|
+
onChange={this.handleChange}
|
|
33
|
+
{...props}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|