@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,170 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { Checkbox, Dropdown, Button, MenuProps } from 'antd';
|
|
4
|
+
import { DownOutlined } from '@ant-design/icons';
|
|
5
|
+
import nx from '@jswork/next';
|
|
6
|
+
import '@jswork/next-dom-event';
|
|
7
|
+
import { SizeType } from 'antd/es/config-provider/SizeContext';
|
|
8
|
+
|
|
9
|
+
const CLASS_NAME = 'ac-checkable-dropdown';
|
|
10
|
+
const locales = { 'zh-CN': { selectAll: '全部' }, 'en-US': { selectAll: 'All' } };
|
|
11
|
+
type StdEventTarget = { target: { value: any } };
|
|
12
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
className?: string;
|
|
16
|
+
lang?: string;
|
|
17
|
+
items?: any[];
|
|
18
|
+
value?: any[];
|
|
19
|
+
width?: number;
|
|
20
|
+
size?: SizeType;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
onChange?: StdCallback;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export class AcCheckableDropdown extends React.Component<Props> {
|
|
26
|
+
static displayName = CLASS_NAME;
|
|
27
|
+
static formSchema = CLASS_NAME;
|
|
28
|
+
static id = 1;
|
|
29
|
+
static defaultProps = {
|
|
30
|
+
lang: 'zh-CN',
|
|
31
|
+
onChange: noop,
|
|
32
|
+
items: [],
|
|
33
|
+
value: [],
|
|
34
|
+
width: 140
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
private readonly overlayClass = `${CLASS_NAME}-overlay--${AcCheckableDropdown.id++}`;
|
|
38
|
+
|
|
39
|
+
state = {
|
|
40
|
+
visible: false,
|
|
41
|
+
value: this.props.value
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
private overlayRes: any;
|
|
45
|
+
private winBlankRes: any;
|
|
46
|
+
|
|
47
|
+
get indeterminate() {
|
|
48
|
+
const { value } = this.state;
|
|
49
|
+
return !!value?.length && value?.length < this.props.items!.length;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get label() {
|
|
53
|
+
const { value } = this.state;
|
|
54
|
+
const { items } = this.props;
|
|
55
|
+
const labels = value?.map((val) => items?.find((item) => item.value === val).label);
|
|
56
|
+
const isAll = value?.length === 0 || value?.length === items?.length;
|
|
57
|
+
return isAll ? this.t('selectAll') : labels?.join(',');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get menuItems() {
|
|
61
|
+
const { items } = this.props;
|
|
62
|
+
const _value = this.state.value;
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
key: 'select_all',
|
|
66
|
+
label: (
|
|
67
|
+
<Checkbox
|
|
68
|
+
indeterminate={this.indeterminate}
|
|
69
|
+
checked={_value?.length === items?.length}
|
|
70
|
+
onChange={(e) => {
|
|
71
|
+
const checked = e.target.checked;
|
|
72
|
+
const val = checked ? items?.map((item) => item.value) : [];
|
|
73
|
+
this.doChange(val);
|
|
74
|
+
}}>
|
|
75
|
+
{this.t('selectAll')}
|
|
76
|
+
</Checkbox>
|
|
77
|
+
)
|
|
78
|
+
},
|
|
79
|
+
{ type: 'divider' },
|
|
80
|
+
...items!.map((opt) => {
|
|
81
|
+
const shouldChecked = _value?.includes(opt.value);
|
|
82
|
+
return {
|
|
83
|
+
key: opt.value,
|
|
84
|
+
label: (
|
|
85
|
+
<Checkbox
|
|
86
|
+
onChange={(e) => {
|
|
87
|
+
const { checked } = e.target;
|
|
88
|
+
const filtered = this.state.value?.filter((item) => item !== opt.value);
|
|
89
|
+
const val = checked ? [...filtered!, opt.value] : filtered;
|
|
90
|
+
this.doChange(val);
|
|
91
|
+
}}
|
|
92
|
+
checked={shouldChecked}>
|
|
93
|
+
{opt.label}
|
|
94
|
+
</Checkbox>
|
|
95
|
+
)
|
|
96
|
+
};
|
|
97
|
+
})
|
|
98
|
+
] as MenuProps['items'];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
t = (inKey: string) => {
|
|
102
|
+
const { lang } = this.props;
|
|
103
|
+
return locales[lang!][inKey] || inKey;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
doChange = (inValue) => {
|
|
107
|
+
const { onChange } = this.props;
|
|
108
|
+
const target = { value: inValue };
|
|
109
|
+
this.setState(target);
|
|
110
|
+
onChange!({ target });
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
componentDidMount() {
|
|
114
|
+
// click blank, close overlay
|
|
115
|
+
this.winBlankRes = nx.DomEvent.on(window as any, 'click', (e) => {
|
|
116
|
+
const target = e.target as HTMLElement;
|
|
117
|
+
const overlay = document.querySelector(`.${this.overlayClass}`) as HTMLDivElement;
|
|
118
|
+
if (overlay && !overlay.contains(target)) {
|
|
119
|
+
this.setState({ visible: false });
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
componentDidUpdate() {
|
|
125
|
+
const { visible } = this.state;
|
|
126
|
+
if (visible) {
|
|
127
|
+
const overlay = document.querySelector(`.${this.overlayClass}`) as HTMLDivElement;
|
|
128
|
+
if (overlay) {
|
|
129
|
+
this.overlayRes = nx.DomEvent.on(overlay, 'mouseleave', () => {
|
|
130
|
+
this.setState({ visible: false });
|
|
131
|
+
this.overlayRes?.destroy();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
componentWillUnmount() {
|
|
138
|
+
this.winBlankRes?.destroy();
|
|
139
|
+
this.overlayRes?.destroy();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* todo: 有朝一日,找出原因
|
|
144
|
+
* 这里的 button disabled 不能生效,除非在 dropdown 内层套一个 Fragment。
|
|
145
|
+
*/
|
|
146
|
+
render() {
|
|
147
|
+
const { width, disabled, size } = this.props;
|
|
148
|
+
const { visible } = this.state;
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<Dropdown
|
|
152
|
+
disabled={disabled}
|
|
153
|
+
overlayClassName={this.overlayClass}
|
|
154
|
+
open={visible}
|
|
155
|
+
menu={{ items: this.menuItems }}>
|
|
156
|
+
<>
|
|
157
|
+
<Button
|
|
158
|
+
className={`${CLASS_NAME}__btn`}
|
|
159
|
+
style={{ width }}
|
|
160
|
+
size={size}
|
|
161
|
+
disabled={disabled}
|
|
162
|
+
onMouseEnter={() => this.setState({ visible: true })}>
|
|
163
|
+
<span className="is-label">{this.label}</span>
|
|
164
|
+
<DownOutlined />
|
|
165
|
+
</Button>
|
|
166
|
+
</>
|
|
167
|
+
</Dropdown>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import cx from 'classnames';
|
|
4
|
+
import ReactList from '@jswork/react-list';
|
|
5
|
+
import { Space, Button } from 'antd';
|
|
6
|
+
import { AcCheckableTag } from './checkable-tag';
|
|
7
|
+
|
|
8
|
+
const CLASS_NAME = 'ac-checkable-tag-list';
|
|
9
|
+
const locales = {
|
|
10
|
+
'zh-CN': { selectAll: '全部' },
|
|
11
|
+
'en-US': { selectAll: 'All' }
|
|
12
|
+
};
|
|
13
|
+
type StdEventTarget = { target: { value: any } };
|
|
14
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
15
|
+
type Props = {
|
|
16
|
+
/**
|
|
17
|
+
* Main className.
|
|
18
|
+
*/
|
|
19
|
+
className?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The language key.
|
|
22
|
+
*/
|
|
23
|
+
lang?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The component data soruce.
|
|
26
|
+
*/
|
|
27
|
+
items?: any[];
|
|
28
|
+
/**
|
|
29
|
+
* Runtime value.
|
|
30
|
+
*/
|
|
31
|
+
value?: any[];
|
|
32
|
+
/**
|
|
33
|
+
* The event handler for `change`.
|
|
34
|
+
*/
|
|
35
|
+
onChange?: StdCallback;
|
|
36
|
+
/**
|
|
37
|
+
* The disabled state.
|
|
38
|
+
*/
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export class AcCheckableTagList extends React.Component<Props> {
|
|
43
|
+
static displayName = CLASS_NAME;
|
|
44
|
+
static formSchema = CLASS_NAME;
|
|
45
|
+
static defaultProps = {
|
|
46
|
+
lang: 'zh-CN',
|
|
47
|
+
value: [],
|
|
48
|
+
onChange: noop
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
state = {
|
|
52
|
+
value: this.props.value
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
t = (inKey: string) => {
|
|
56
|
+
const { lang } = this.props;
|
|
57
|
+
return locales[lang!][inKey] || inKey;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
shouldComponentUpdate(nextProps: Readonly<Props>): boolean {
|
|
61
|
+
const { value } = nextProps;
|
|
62
|
+
if (value !== this.props.value) this.setState({ value });
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
handleChange = (inEvent) => {
|
|
67
|
+
const { onChange } = this.props;
|
|
68
|
+
const target = { value: inEvent };
|
|
69
|
+
this.setState(target, () => {
|
|
70
|
+
onChange!({ target });
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
handleClearAll = () => {
|
|
75
|
+
this.handleChange([]);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
render() {
|
|
79
|
+
const { className, items, value, onChange, disabled, ...props } = this.props;
|
|
80
|
+
const label = this.t('selectAll');
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<Space direction="horizontal" className={cx(CLASS_NAME, className)}>
|
|
84
|
+
<Button
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
size="small"
|
|
87
|
+
onClick={this.handleClearAll}
|
|
88
|
+
className="ac-is-aside">
|
|
89
|
+
{label}
|
|
90
|
+
</Button>
|
|
91
|
+
<ReactList
|
|
92
|
+
items={items}
|
|
93
|
+
template={({ item, index }) => {
|
|
94
|
+
const _value = this.state.value as any[];
|
|
95
|
+
const isChecked = _value?.includes(item.value);
|
|
96
|
+
return (
|
|
97
|
+
<AcCheckableTag
|
|
98
|
+
className="ac-is-item"
|
|
99
|
+
toggleable
|
|
100
|
+
closeable
|
|
101
|
+
propagation
|
|
102
|
+
disabled={disabled}
|
|
103
|
+
value={isChecked}
|
|
104
|
+
onChange={(inEvent) => {
|
|
105
|
+
const checked = inEvent.target.value;
|
|
106
|
+
const curSet = new Set([..._value]);
|
|
107
|
+
const method = checked ? 'add' : 'delete';
|
|
108
|
+
curSet[method](item.value);
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
this.handleChange([...curSet]);
|
|
111
|
+
}}
|
|
112
|
+
key={index}>
|
|
113
|
+
{item.label}
|
|
114
|
+
</AcCheckableTag>
|
|
115
|
+
);
|
|
116
|
+
}}
|
|
117
|
+
{...props}
|
|
118
|
+
/>
|
|
119
|
+
</Space>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { Tag } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
import { CheckableTagProps } from 'antd/es/tag';
|
|
6
|
+
import { CloseOutlined } from '@ant-design/icons';
|
|
7
|
+
|
|
8
|
+
const CLASS_NAME = 'ac-checkable-tag';
|
|
9
|
+
const { CheckableTag } = Tag;
|
|
10
|
+
type StdEventTarget = { target: { value: any } };
|
|
11
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @see https://ant.design/components/tag-cn/#Tag.CheckableTag
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
type Props = {
|
|
18
|
+
className?: string;
|
|
19
|
+
value?: boolean;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
closeable?: boolean;
|
|
22
|
+
toggleable?: boolean;
|
|
23
|
+
propagation?: boolean;
|
|
24
|
+
onChange?: StdCallback;
|
|
25
|
+
onCloseClick?: StdCallback;
|
|
26
|
+
} & Omit<CheckableTagProps, 'checked'>;
|
|
27
|
+
|
|
28
|
+
export class AcCheckableTag extends React.Component<Props> {
|
|
29
|
+
static displayName = CLASS_NAME;
|
|
30
|
+
static formSchema = CLASS_NAME;
|
|
31
|
+
static defaultProps = {
|
|
32
|
+
value: false,
|
|
33
|
+
closeable: false,
|
|
34
|
+
disabled: false,
|
|
35
|
+
toggleable: false,
|
|
36
|
+
propagation: false,
|
|
37
|
+
onChange: noop,
|
|
38
|
+
onCloseClick: noop
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
state = {
|
|
42
|
+
value: Boolean(this.props.value)
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
get closeIcon() {
|
|
46
|
+
const { closeable, toggleable } = this.props;
|
|
47
|
+
const { value } = this.state;
|
|
48
|
+
let view: ReactNode = null;
|
|
49
|
+
if (closeable) view = <CloseOutlined onClick={this.handleCloseClick} />;
|
|
50
|
+
if (toggleable) view = value ? view : null;
|
|
51
|
+
return view;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
shouldComponentUpdate(nextProps: Readonly<Props>): boolean {
|
|
55
|
+
const { value } = nextProps;
|
|
56
|
+
if (value !== this.state.value) {
|
|
57
|
+
this.setState({ value });
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
handleChange = (inEvent) => {
|
|
63
|
+
const { onChange } = this.props;
|
|
64
|
+
const target = { value: inEvent };
|
|
65
|
+
this.setState(target, () => {
|
|
66
|
+
onChange!({ target });
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
handleCloseClick = (inEvent) => {
|
|
71
|
+
const { propagation, onCloseClick } = this.props;
|
|
72
|
+
!propagation && inEvent.stopPropagation();
|
|
73
|
+
onCloseClick!(inEvent);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
render() {
|
|
77
|
+
const {
|
|
78
|
+
className,
|
|
79
|
+
value,
|
|
80
|
+
onChange,
|
|
81
|
+
onCloseClick,
|
|
82
|
+
children,
|
|
83
|
+
closeable,
|
|
84
|
+
toggleable,
|
|
85
|
+
propagation,
|
|
86
|
+
...props
|
|
87
|
+
} = this.props;
|
|
88
|
+
const _value = this.state.value;
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<CheckableTag
|
|
92
|
+
className={cx(CLASS_NAME, className)}
|
|
93
|
+
onChange={this.handleChange}
|
|
94
|
+
checked={_value}
|
|
95
|
+
{...props}>
|
|
96
|
+
{children}
|
|
97
|
+
{this.closeIcon}
|
|
98
|
+
</CheckableTag>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactList from '@jswork/react-list';
|
|
3
|
+
import noop from '@jswork/noop';
|
|
4
|
+
import { Checkbox } from 'antd';
|
|
5
|
+
import cx from 'classnames';
|
|
6
|
+
import { checkboxKv } from '@jswork/antd-tpls';
|
|
7
|
+
import { CheckboxGroupProps } from 'antd/es/checkbox';
|
|
8
|
+
|
|
9
|
+
const CLASS_NAME = 'ac-checkbox-group';
|
|
10
|
+
type StdEventTarget = { target: { value: any } };
|
|
11
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
12
|
+
type TemplateCallback = (item: { item: any; index: number }) => React.ReactNode;
|
|
13
|
+
|
|
14
|
+
export type AcCheckboxGroupProps = {
|
|
15
|
+
className?: string;
|
|
16
|
+
value?: any[];
|
|
17
|
+
items?: any[];
|
|
18
|
+
onChange?: StdCallback;
|
|
19
|
+
onSearch?: StdCallback;
|
|
20
|
+
template?: TemplateCallback;
|
|
21
|
+
} & CheckboxGroupProps;
|
|
22
|
+
|
|
23
|
+
export class AcCheckboxGroup extends React.Component<AcCheckboxGroupProps> {
|
|
24
|
+
static displayName = CLASS_NAME;
|
|
25
|
+
static formSchema = CLASS_NAME;
|
|
26
|
+
static defaultProps = {
|
|
27
|
+
items: [],
|
|
28
|
+
value: [],
|
|
29
|
+
template: checkboxKv,
|
|
30
|
+
onChange: noop,
|
|
31
|
+
onSearch: noop
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
state = {
|
|
35
|
+
value: this.props.value
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
shouldComponentUpdate(nextProps: Readonly<AcCheckboxGroupProps>): boolean {
|
|
39
|
+
const { value } = nextProps;
|
|
40
|
+
const isNewValue = nextProps.value !== this.props.value;
|
|
41
|
+
if (isNewValue && this.state.value !== value) {
|
|
42
|
+
this.setState({ value });
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
handleChange = (inEvent) => {
|
|
48
|
+
const { onChange, onSearch } = this.props;
|
|
49
|
+
const target = { value: inEvent };
|
|
50
|
+
const stdEvent = { target };
|
|
51
|
+
this.setState(target, () => {
|
|
52
|
+
onChange!(stdEvent);
|
|
53
|
+
onSearch!(stdEvent);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
render() {
|
|
58
|
+
const { className, items, template, onChange, onSearch, children, value, ...props } =
|
|
59
|
+
this.props;
|
|
60
|
+
const { value: stateValue } = this.state;
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<Checkbox.Group
|
|
64
|
+
className={cx(CLASS_NAME, className)}
|
|
65
|
+
value={stateValue}
|
|
66
|
+
onChange={this.handleChange}
|
|
67
|
+
{...props}>
|
|
68
|
+
<ReactList items={items} template={template} />
|
|
69
|
+
</Checkbox.Group>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React, { HTMLAttributes } from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { Checkbox, CheckboxProps } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
|
|
6
|
+
const CLASS_NAME = 'ac-checkbox';
|
|
7
|
+
type StdEventTarget = { target: { value: any } };
|
|
8
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
className?: string;
|
|
12
|
+
value?: boolean;
|
|
13
|
+
onChange?: StdCallback;
|
|
14
|
+
} & CheckboxProps &
|
|
15
|
+
HTMLAttributes<any>;
|
|
16
|
+
|
|
17
|
+
export class AcCheckbox extends React.Component<Props> {
|
|
18
|
+
static displayName = CLASS_NAME;
|
|
19
|
+
static formSchema = CLASS_NAME;
|
|
20
|
+
static defaultProps = {
|
|
21
|
+
onChange: noop
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
state = {
|
|
25
|
+
value: this.props.value
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
shouldComponentUpdate(nextProps: Readonly<Props>): boolean {
|
|
29
|
+
const { value } = nextProps;
|
|
30
|
+
if (value !== this.state.value) {
|
|
31
|
+
this.setState({ value });
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
handleChange = (inEvent) => {
|
|
37
|
+
const { checked } = inEvent.target;
|
|
38
|
+
const { onChange } = this.props;
|
|
39
|
+
const target = { value: checked };
|
|
40
|
+
|
|
41
|
+
this.setState(target, () => {
|
|
42
|
+
onChange!({ target });
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
render() {
|
|
47
|
+
const { className, onChange, value, defaultValue, ...props } = this.props;
|
|
48
|
+
const _value = this.state.value;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Checkbox
|
|
52
|
+
className={cx(CLASS_NAME, className)}
|
|
53
|
+
checked={_value}
|
|
54
|
+
onChange={this.handleChange}
|
|
55
|
+
{...props}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import ReactCodeflask from '@jswork/react-codeflask';
|
|
4
|
+
|
|
5
|
+
const CLASS_NAME = 'ac-codeflask';
|
|
6
|
+
|
|
7
|
+
export class AcCodeFlask extends React.Component {
|
|
8
|
+
static displayName = CLASS_NAME;
|
|
9
|
+
static formSchema = CLASS_NAME;
|
|
10
|
+
static defaultProps = {
|
|
11
|
+
onChange: noop
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
render() {
|
|
15
|
+
return <ReactCodeflask {...this.props} />;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import cx from 'classnames';
|
|
2
|
+
import React, { Component } from 'react';
|
|
3
|
+
import { Popconfirm, Button, message } from 'antd';
|
|
4
|
+
import type { PopconfirmProps, ButtonProps } from 'antd';
|
|
5
|
+
|
|
6
|
+
const CLASS_NAME = 'ac-confirm-button';
|
|
7
|
+
const locals = {
|
|
8
|
+
'zh-CN': {
|
|
9
|
+
title: '确认执行这个操作?',
|
|
10
|
+
msgCancel: '您取消了操作~'
|
|
11
|
+
},
|
|
12
|
+
'en-US': {
|
|
13
|
+
title: 'Are you sure to do this?',
|
|
14
|
+
msgCancel: 'You canceled the operation~'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export interface AcConfirmButtonProps extends Omit<PopconfirmProps, 'title'> {
|
|
19
|
+
className?: string;
|
|
20
|
+
lang?: string;
|
|
21
|
+
title?: string;
|
|
22
|
+
type?: ButtonProps['type'] | 'raw' | 'anchor';
|
|
23
|
+
childProps?: ButtonProps;
|
|
24
|
+
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class AcConfirmButton extends Component<AcConfirmButtonProps> {
|
|
28
|
+
static displayName = CLASS_NAME;
|
|
29
|
+
static formSchema = CLASS_NAME;
|
|
30
|
+
|
|
31
|
+
static defaultProps = {
|
|
32
|
+
lang: 'zh-CN',
|
|
33
|
+
type: 'link',
|
|
34
|
+
childProps: {}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
get computedChildren() {
|
|
38
|
+
const { type, children, childProps } = this.props;
|
|
39
|
+
switch (type) {
|
|
40
|
+
case 'raw':
|
|
41
|
+
return children;
|
|
42
|
+
case 'anchor':
|
|
43
|
+
return <a {...childProps}>{children}</a>;
|
|
44
|
+
default:
|
|
45
|
+
return (
|
|
46
|
+
<Button type={type} size="small" {...childProps}>
|
|
47
|
+
{children}
|
|
48
|
+
</Button>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
handleCancel = () => {
|
|
54
|
+
message.info(this.t('msgCancel'));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
t = (inKey) => {
|
|
58
|
+
const { lang } = this.props;
|
|
59
|
+
return nx.get(locals, `${lang}.${inKey}`, inKey);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
render() {
|
|
63
|
+
const {
|
|
64
|
+
className,
|
|
65
|
+
onClick,
|
|
66
|
+
type,
|
|
67
|
+
children,
|
|
68
|
+
childProps,
|
|
69
|
+
lang,
|
|
70
|
+
title: _title,
|
|
71
|
+
...props
|
|
72
|
+
} = this.props;
|
|
73
|
+
|
|
74
|
+
const title = _title || locals[lang!].title;
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Popconfirm
|
|
78
|
+
title={title}
|
|
79
|
+
onConfirm={(e) => onClick?.(e as any)}
|
|
80
|
+
onCancel={this.handleCancel}
|
|
81
|
+
className={cx(CLASS_NAME, className)}
|
|
82
|
+
{...props}>
|
|
83
|
+
{this.computedChildren}
|
|
84
|
+
</Popconfirm>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import noop from '@jswork/noop';
|
|
3
|
+
import { DatePicker, DatePickerProps } from 'antd';
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
|
|
6
|
+
const CLASS_NAME = 'ac-date-picker';
|
|
7
|
+
const STD_FORMAT = 'YYYY-MM-DD HH:mm:ss';
|
|
8
|
+
|
|
9
|
+
type StdEventTarget = { target: { value: any } };
|
|
10
|
+
type StdCallback = (inEvent: StdEventTarget) => void;
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
className?: string;
|
|
14
|
+
value?: any;
|
|
15
|
+
dayjs?: any;
|
|
16
|
+
defaultValue?: any;
|
|
17
|
+
onChange?: StdCallback;
|
|
18
|
+
} & DatePickerProps;
|
|
19
|
+
|
|
20
|
+
export class AcDatePicker extends React.Component<Props> {
|
|
21
|
+
static displayName = CLASS_NAME;
|
|
22
|
+
static formSchema = CLASS_NAME;
|
|
23
|
+
static defaultProps: Props = {
|
|
24
|
+
onChange: noop,
|
|
25
|
+
format: STD_FORMAT
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
get values() {
|
|
29
|
+
const { value, defaultValue } = this.props;
|
|
30
|
+
let props = {};
|
|
31
|
+
if (value) props['value'] = this.parse(value);
|
|
32
|
+
if (defaultValue) props['defaultValue'] = this.parse(defaultValue);
|
|
33
|
+
return props;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
handleChange = (inEvent) => {
|
|
37
|
+
const { onChange } = this.props;
|
|
38
|
+
onChange!({ target: { value: this.stringify(inEvent) } });
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
parse = (inValue) => {
|
|
42
|
+
const { format, dayjs } = this.props;
|
|
43
|
+
return dayjs(inValue, format as string);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
stringify = (inValue) => {
|
|
47
|
+
if (!inValue) return null;
|
|
48
|
+
const { format } = this.props;
|
|
49
|
+
return inValue.format(format as string);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
render() {
|
|
53
|
+
const { className, defaultValue, value, onChange, ...props } = this.props;
|
|
54
|
+
const rest = { ...props, ...this.values };
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<DatePicker className={cx(CLASS_NAME, className)} onChange={this.handleChange} {...rest} />
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|