@king-design/intact 3.3.2 → 3.4.0-beta.0
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/components/button/demos/basic.md +5 -2
- package/components/button/demos/ghost.md +1 -0
- package/components/button/demos/group.md +7 -0
- package/components/button/group.ts +2 -0
- package/components/button/index.md +1 -0
- package/components/button/index.ts +2 -0
- package/components/button/index.vdt +12 -7
- package/components/button/styles.ts +31 -1
- package/components/dialog/alert.vdt +2 -3
- package/components/dialog/demos/static.md +18 -0
- package/components/switch/demos/beforeChange.md +52 -0
- package/components/switch/index.md +2 -0
- package/components/switch/index.spec.ts +11 -0
- package/components/switch/index.ts +28 -6
- package/components/switch/index.vdt +8 -2
- package/components/switch/styles.ts +15 -1
- package/components/table/cell.vdt +6 -1
- package/components/table/column.ts +2 -0
- package/components/table/column.vdt +2 -1
- package/components/table/demos/hidden.md +44 -0
- package/components/table/index.md +1 -0
- package/components/table/index.spec.ts +63 -0
- package/components/table/styles.ts +6 -3
- package/components/table/table.vdt +4 -2
- package/components/table/useChecked.ts +2 -1
- package/components/table/useColumns.ts +1 -1
- package/components/table/useDisableRow.ts +3 -1
- package/components/table/useMerge.ts +6 -1
- package/components/utils.ts +19 -0
- package/es/components/button/group.d.ts +1 -0
- package/es/components/button/group.js +2 -1
- package/es/components/button/index.d.ts +1 -0
- package/es/components/button/index.js +1 -0
- package/es/components/button/index.vdt.js +13 -6
- package/es/components/button/styles.d.ts +1 -1
- package/es/components/button/styles.js +3 -3
- package/es/components/dialog/alert.vdt.js +2 -2
- package/es/components/switch/index.d.ts +3 -1
- package/es/components/switch/index.js +65 -13
- package/es/components/switch/index.spec.js +21 -0
- package/es/components/switch/index.vdt.js +14 -4
- package/es/components/switch/styles.js +12 -7
- package/es/components/table/cell.vdt.js +3 -1
- package/es/components/table/column.d.ts +1 -0
- package/es/components/table/column.js +1 -0
- package/es/components/table/column.vdt.js +3 -2
- package/es/components/table/index.spec.js +313 -221
- package/es/components/table/styles.js +1 -1
- package/es/components/table/table.vdt.js +1 -1
- package/es/components/table/useChecked.js +3 -1
- package/es/components/table/useColumns.js +1 -1
- package/es/components/table/useDisableRow.js +3 -1
- package/es/components/table/useMerge.js +6 -1
- package/es/components/utils.js +17 -0
- package/es/i18n/en-US.js +6 -2
- package/es/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/es/site/data/components/button/demos/basic/react.js +7 -1
- package/es/site/data/components/button/demos/ghost/react.js +3 -0
- package/es/site/data/components/button/demos/group/react.js +17 -0
- package/es/site/data/components/dialog/demos/static/index.d.ts +1 -0
- package/es/site/data/components/dialog/demos/static/index.js +15 -0
- package/es/site/data/components/dialog/demos/static/react.d.ts +1 -0
- package/es/site/data/components/dialog/demos/static/react.js +18 -1
- package/es/site/data/components/popover/demos/tooltip/index.d.ts +7 -0
- package/es/site/data/components/popover/demos/tooltip/index.js +21 -0
- package/es/site/data/components/popover/demos/tooltip/react.d.ts +6 -0
- package/es/site/data/components/popover/demos/tooltip/react.js +30 -0
- package/es/site/data/components/switch/demos/beforeChange/index.d.ts +12 -0
- package/es/site/data/components/switch/demos/beforeChange/index.js +39 -0
- package/es/site/data/components/switch/demos/beforeChange/react.d.ts +11 -0
- package/es/site/data/components/switch/demos/beforeChange/react.js +62 -0
- package/es/site/data/components/table/demos/hidden/index.d.ts +14 -0
- package/es/site/data/components/table/demos/hidden/index.js +28 -0
- package/es/site/data/components/table/demos/hidden/react.d.ts +13 -0
- package/es/site/data/components/table/demos/hidden/react.js +63 -0
- package/i18n/en-US.ts +5 -2
- package/index.ts +2 -2
- package/package.json +2 -2
- package/components/menu/.DS_Store +0 -0
- package/components/menu/demos/.DS_Store +0 -0
|
@@ -15,6 +15,7 @@ import ScrollToRowDemo from '~/components/table/demos/scrollToRow';
|
|
|
15
15
|
import {mount, unmount, dispatchEvent, getElement, wait} from '../../test/utils';
|
|
16
16
|
import {Component} from 'intact';
|
|
17
17
|
import {Table, TableColumn} from './';
|
|
18
|
+
import { bind } from '../utils';
|
|
18
19
|
import DraggableTable from '~/components/table/demos/draggable';
|
|
19
20
|
import MergeCellDemo from '~/components/table/demos/mergeCell';
|
|
20
21
|
import {Dropdown, DropdownMenu, DropdownItem} from '../dropdown';
|
|
@@ -186,6 +187,68 @@ describe('Table', () => {
|
|
|
186
187
|
expect(table2.outerHTML).to.matchSnapshot();
|
|
187
188
|
});
|
|
188
189
|
|
|
190
|
+
it('append a row in merged table', async () => {
|
|
191
|
+
let uniqueId = 0;
|
|
192
|
+
class Demo extends Component<{data: any[]}> {
|
|
193
|
+
static template = `
|
|
194
|
+
const {Table, TableColumn} = this;
|
|
195
|
+
const { data } = this.get();
|
|
196
|
+
<Table data={data} merge={this.merge} rowKey={data => data.uniqueId} animation={false}>
|
|
197
|
+
<TableColumn title="名称" key="Name" />
|
|
198
|
+
<TableColumn title="头衔" key="Title" />
|
|
199
|
+
<TableColumn title="uniqueId" key="uniqueId" />
|
|
200
|
+
</Table>
|
|
201
|
+
`
|
|
202
|
+
|
|
203
|
+
private Table = Table;
|
|
204
|
+
private TableColumn = TableColumn;
|
|
205
|
+
|
|
206
|
+
static defaults() {
|
|
207
|
+
return {
|
|
208
|
+
data: [
|
|
209
|
+
{
|
|
210
|
+
Name: '刘备',
|
|
211
|
+
Title: '大哥',
|
|
212
|
+
uniqueId: 0,
|
|
213
|
+
},
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
@bind
|
|
219
|
+
merge(row: any, column: any, rowIndex: number, columnIndex: number) {
|
|
220
|
+
const { data } = this.get();
|
|
221
|
+
for (let i = 0; i < data.length; i++) {
|
|
222
|
+
const mergeIndex = data.findIndex((item: any, index: number) => {
|
|
223
|
+
return index > i && item.Name !== data[i]?.Name;
|
|
224
|
+
});
|
|
225
|
+
const allSame = data.every((item: any, index: number) => {
|
|
226
|
+
if (index > i) {
|
|
227
|
+
return item.Name === data[i].Name;
|
|
228
|
+
}
|
|
229
|
+
return true;
|
|
230
|
+
});
|
|
231
|
+
if ([0, 1, 2].includes(columnIndex) && rowIndex === i) {
|
|
232
|
+
if (mergeIndex === -1 && allSame) {
|
|
233
|
+
return { rowspan: data.length - i };
|
|
234
|
+
}
|
|
235
|
+
if (mergeIndex > -1) {
|
|
236
|
+
return { rowspan: mergeIndex - i };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const [instance, element] = mount(Demo);
|
|
244
|
+
|
|
245
|
+
const { data } = instance.get();
|
|
246
|
+
instance.set('data', [...data, { ...data[data.length - 1], uniqueId: ++uniqueId }]);
|
|
247
|
+
|
|
248
|
+
await wait();
|
|
249
|
+
expect(element.innerHTML).to.matchSnapshot();
|
|
250
|
+
});
|
|
251
|
+
|
|
189
252
|
it('sort', async () => {
|
|
190
253
|
const [instance, element] = mount(SortDemo);
|
|
191
254
|
|
|
@@ -313,10 +313,13 @@ export const makeStyles = cache(function makeStyles(k: string) {
|
|
|
313
313
|
background: ${table.selectedBgColor};
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
-
//
|
|
317
|
-
// tr.${k}-hidden {
|
|
318
|
-
|
|
316
|
+
// hidden cell
|
|
317
|
+
// col.${k}-hidden, tr > .${k}-hidden {
|
|
318
|
+
// display: none;
|
|
319
319
|
// }
|
|
320
|
+
.${k}-hidden {
|
|
321
|
+
display: none;
|
|
322
|
+
}
|
|
320
323
|
.${k}-table-arrow {
|
|
321
324
|
width: ${table.arrow.width} !important;
|
|
322
325
|
margin-right: ${table.arrow.gap};
|
|
@@ -57,7 +57,10 @@ const colgroup = (
|
|
|
57
57
|
<col v-for={cols}
|
|
58
58
|
width={$value.width}
|
|
59
59
|
style={{width: getWidth($value.key)}}
|
|
60
|
-
class={{
|
|
60
|
+
class={{
|
|
61
|
+
[`${k}-hidden`]: $value.hidden,
|
|
62
|
+
[$value.className]: $value.className
|
|
63
|
+
}}
|
|
61
64
|
/>
|
|
62
65
|
</colgroup>
|
|
63
66
|
);
|
|
@@ -176,7 +179,6 @@ const tbody = (
|
|
|
176
179
|
</Tooltip>
|
|
177
180
|
);
|
|
178
181
|
}
|
|
179
|
-
|
|
180
182
|
rows.push(row);
|
|
181
183
|
if ($blocks.expand) {
|
|
182
184
|
const expanded = isExpanded(key);
|
|
@@ -210,7 +210,8 @@ export function useChecked(
|
|
|
210
210
|
instance.trigger(isChecked ? 'checkRow' : 'uncheckRow', data.value![rowIndex], rowIndex, key);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
instance.on('$receive:children', updateAllCheckedStatus);
|
|
213
|
+
// instance.on('$receive:children', updateAllCheckedStatus);
|
|
214
|
+
useReceive(['children'], updateAllCheckedStatus);
|
|
214
215
|
instance.on('$change:checkedKeys', updateAllCheckedStatus);
|
|
215
216
|
// for draggable
|
|
216
217
|
watchState(data, updateAllCheckedStatus);
|
|
@@ -2,6 +2,7 @@ import {useInstance} from 'intact';
|
|
|
2
2
|
import type {Table, TableRowKey, TableCheckType} from './table';
|
|
3
3
|
import type {useTree} from './useTree';
|
|
4
4
|
import { State, watchState } from '../../hooks/useState';
|
|
5
|
+
import { useReceive } from '../../hooks/useReceive';
|
|
5
6
|
|
|
6
7
|
export function useDisableRow(
|
|
7
8
|
loopData: ReturnType<typeof useTree>['loopData'],
|
|
@@ -48,7 +49,8 @@ export function useDisableRow(
|
|
|
48
49
|
return allKeys;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
instance.on('$receive:children', setDisabledKeys);
|
|
52
|
+
// instance.on('$receive:children', setDisabledKeys);
|
|
53
|
+
useReceive(['children'], setDisabledKeys);
|
|
52
54
|
watchState(data, setDisabledKeys);
|
|
53
55
|
|
|
54
56
|
return {isDisabled, getEnableKeys, isDisabledKey, getAllKeys};
|
|
@@ -2,6 +2,7 @@ import {useInstance, Props} from 'intact';
|
|
|
2
2
|
import type {Table, TableRowKey, TableCheckType} from './table';
|
|
3
3
|
import type {TableColumnProps} from './column';
|
|
4
4
|
import { State, watchState } from '../../hooks/useState';
|
|
5
|
+
import { useReceive } from '../../hooks/useReceive';
|
|
5
6
|
|
|
6
7
|
export type TableMerge<T = any, CheckType = 'checkbox'> = (
|
|
7
8
|
row: T,
|
|
@@ -100,7 +101,11 @@ export function useMerge(
|
|
|
100
101
|
return grid;
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
|
|
104
|
+
/**
|
|
105
|
+
* https://github.com/ksc-fe/kpc/issues/1008
|
|
106
|
+
*/
|
|
107
|
+
// instance.on('$receive:children', handleSpans);
|
|
108
|
+
useReceive(['children'], handleSpans);
|
|
104
109
|
watchState(data, handleSpans);
|
|
105
110
|
|
|
106
111
|
return {getGrid};
|
package/components/utils.ts
CHANGED
|
@@ -293,9 +293,28 @@ export function strPad(str: number | string, length: number, pad: string = '0')
|
|
|
293
293
|
return str;
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
+
/**
|
|
297
|
+
* 在vue3.0中,数组会转成Proxy对象,需要获取原始数据比较
|
|
298
|
+
* https://github.com/ksc-fe/kpc/issues/985
|
|
299
|
+
* https://github.com/vuejs/core/blob/main/packages/reactivity/src/reactive.ts
|
|
300
|
+
*/
|
|
301
|
+
const RAW = '__v_raw';
|
|
302
|
+
function isProxy(value: any): boolean {
|
|
303
|
+
return value ? !!value[RAW] : false
|
|
304
|
+
}
|
|
305
|
+
function toRaw<T>(observed: T): T {
|
|
306
|
+
const raw = observed && (observed as any)[RAW]
|
|
307
|
+
return raw ? toRaw(raw) : observed
|
|
308
|
+
}
|
|
296
309
|
type EqualArrayValue = any | EqualArrayValue[]
|
|
297
310
|
export function isEqualArray(a: EqualArrayValue, b: EqualArrayValue): boolean {
|
|
298
311
|
if (a === b) return true;
|
|
312
|
+
|
|
313
|
+
// for vue3.0 Proxy object
|
|
314
|
+
if (isProxy(a)) a = toRaw(a);
|
|
315
|
+
if (isProxy(b)) b = toRaw(b);
|
|
316
|
+
if (a === b) return true;
|
|
317
|
+
|
|
299
318
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
300
319
|
if (a.length !== b.length) return false;
|
|
301
320
|
return a.every((value, index) => isEqualArray(value, b[index]));
|
|
@@ -5,6 +5,7 @@ export interface ButtonGroupProps {
|
|
|
5
5
|
checkType?: 'none' | 'radio' | 'checkbox';
|
|
6
6
|
fluid?: boolean;
|
|
7
7
|
seperate?: boolean;
|
|
8
|
+
btnWidth?: number | string;
|
|
8
9
|
}
|
|
9
10
|
export declare class ButtonGroup extends Component<ButtonGroupProps> {
|
|
10
11
|
static template: string | import("intact").Template<any>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
2
2
|
import { createUnknownComponentVNode as _$cc, className as _$cn, createElementVNode as _$ce } from 'intact';
|
|
3
|
-
import { getRestProps } from '../utils';
|
|
3
|
+
import { addStyle, getRestProps } from '../utils';
|
|
4
4
|
import { Icon } from '../icon';
|
|
5
5
|
import { makeButtonStyles } from './styles';
|
|
6
6
|
import { DynamicButton } from './dynamicButton';
|
|
7
7
|
import { Wave } from '../wave';
|
|
8
8
|
import { button as theme } from './styles';
|
|
9
9
|
export default function ($props, $blocks, $__proto__) {
|
|
10
|
-
var _classNameObj;
|
|
10
|
+
var _classNameObj, _buttonGroup$get;
|
|
11
11
|
$blocks || ($blocks = {});
|
|
12
12
|
$props || ($props = {});
|
|
13
13
|
var $this = this;
|
|
@@ -27,7 +27,9 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
27
27
|
loading = _this$get.loading,
|
|
28
28
|
disabled = _this$get.disabled,
|
|
29
29
|
name = _this$get.name,
|
|
30
|
-
ghost = _this$get.ghost
|
|
30
|
+
ghost = _this$get.ghost,
|
|
31
|
+
color = _this$get.color,
|
|
32
|
+
style = _this$get.style;
|
|
31
33
|
var _this$config = this.config,
|
|
32
34
|
cls = _this$config.cls,
|
|
33
35
|
k = _this$config.k;
|
|
@@ -53,7 +55,7 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
53
55
|
}
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
|
-
var classNameObj = (_classNameObj = {}, _classNameObj[cls('btn')] = true, _classNameObj[cls(size)] = size !== 'default', _classNameObj[cls(type)] =
|
|
58
|
+
var classNameObj = (_classNameObj = {}, _classNameObj[cls('btn')] = true, _classNameObj[cls(size)] = size !== 'default', _classNameObj[cls(type)] = !color, _classNameObj[cls("btn-icon")] = icon, _classNameObj[className] = className, _classNameObj[cls('circle')] = circle, _classNameObj[cls('loading')] = loading, _classNameObj[cls('fluid')] = fluid, _classNameObj[cls('active')] = checked, _classNameObj[cls('disabled')] = disabled || loading, _classNameObj[cls('ghost')] = ghost, _classNameObj[cls('custom')] = color, _classNameObj[makeButtonStyles(k, iconSide, color)] = true, _classNameObj);
|
|
57
59
|
var loadingIcon = _$cc(Icon, {
|
|
58
60
|
'className': _$cn("ion-load-c " + k + "-icon-loading"),
|
|
59
61
|
'size': size /*loadingSizeMap[size]*/,
|
|
@@ -61,10 +63,14 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
61
63
|
'rotate': true
|
|
62
64
|
}, 'k-loading');
|
|
63
65
|
var buttonGroup = this.buttonGroup;
|
|
64
|
-
var checkType = buttonGroup ? buttonGroup.get('checkType') : 'none';
|
|
66
|
+
var checkType = (_buttonGroup$get = buttonGroup == null ? void 0 : buttonGroup.get('checkType')) != null ? _buttonGroup$get : 'none';
|
|
67
|
+
var btnWidth = buttonGroup == null ? void 0 : buttonGroup.get('btnWidth');
|
|
68
|
+
var _style = {
|
|
69
|
+
width: typeof btnWidth === 'number' ? btnWidth + "px" : btnWidth
|
|
70
|
+
};
|
|
65
71
|
var isCheckType = checkType !== 'none';
|
|
66
72
|
var typeStyles = theme[type];
|
|
67
|
-
var waveColor = typeStyles && typeStyles.borderColor || theme.primary.borderColor;
|
|
73
|
+
var waveColor = typeStyles && typeStyles.borderColor || color || theme.primary.borderColor;
|
|
68
74
|
return _$cc(Wave, {
|
|
69
75
|
'disabled': loading || disabled || type === 'none' || type === 'link',
|
|
70
76
|
'inset': type === 'flat' ? '-1px' : '-2px',
|
|
@@ -73,6 +79,7 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
73
79
|
'className': _$cn(classNameObj),
|
|
74
80
|
'tagName': tagName
|
|
75
81
|
}, getRestProps(this), {
|
|
82
|
+
'style': btnWidth ? addStyle(style, _style) : style,
|
|
76
83
|
'ref': this.elementRef,
|
|
77
84
|
'tabindex': disabled || loading ? '-1' : tabindex,
|
|
78
85
|
'ev-click': this.onClick,
|
|
@@ -84,7 +84,7 @@ declare const defaults: {
|
|
|
84
84
|
declare let button: typeof defaults;
|
|
85
85
|
export { button };
|
|
86
86
|
export declare const makeButtonStyles: {
|
|
87
|
-
(k: string, iconSide?: string | undefined): string;
|
|
87
|
+
(k: string, iconSide?: string | undefined, color?: string | undefined): string;
|
|
88
88
|
clearCache(): {};
|
|
89
89
|
};
|
|
90
90
|
export declare const makeButtonGroupStyles: {
|
|
@@ -190,7 +190,7 @@ setDefault(function () {
|
|
|
190
190
|
makeButtonGroupStyles == null || makeButtonGroupStyles.clearCache();
|
|
191
191
|
});
|
|
192
192
|
export { button };
|
|
193
|
-
export var makeButtonStyles = cache(function makeButtonStyles(k, iconSide) {
|
|
193
|
+
export var makeButtonStyles = cache(function makeButtonStyles(k, iconSide, color) {
|
|
194
194
|
var _button = button,
|
|
195
195
|
secondary = _button.secondary,
|
|
196
196
|
link = _button.link;
|
|
@@ -200,7 +200,7 @@ export var makeButtonStyles = cache(function makeButtonStyles(k, iconSide) {
|
|
|
200
200
|
css("display:inline-flex;align-items:center;justify-content:center;cursor:pointer;height:", button.height, ";padding:", button.padding, ";outline:none;vertical-align:middle;color:", button.color, ";background:", button.bgColor, ";border-radius:", button.borderRadius, ";border:1px solid ", button.borderColor, ";font-size:", button.fontSize, ";white-space:nowrap;transition:all ", button.transition, ";line-height:", button.lineHeight, ";.", k, "-icon{color:inherit;}&.", k, "-default,&.", k, "-none,&.", k, "-flat{.", k, "-icon{color:", theme.color.lightBlack, ";}&:hover{.", k, "-icon{color:inherit;}}}&:hover,&:focus{border-color:", button.hoverBorderColor, ";color:", button.hoverColor, ";}&:active{background:", palette(theme.color.primary, -4), ";}.", k, "-button-input{position:absolute;opacity:0;width:0;height:0;}", _mapInstanceProperty(types).call(types, function (type) {
|
|
201
201
|
var typeStyles = button[type];
|
|
202
202
|
return /*#__PURE__*/css("&.", k, "-", type, "{background:", typeStyles.bgColor, ";color:", typeStyles.color, ";border-color:", typeStyles.borderColor, ";&:hover,&:focus{background:", palette(typeStyles.bgColor, -1), ";border-color:", typeStyles.hoverBorderColor, ";color:", typeStyles.color, ";}&:active{background:", palette(typeStyles.bgColor, 1), ";border-color:", palette(typeStyles.borderColor, 1), ";}}");
|
|
203
|
-
}), "&.", k, "-secondary{color:", secondary.color, ";border-color:", secondary.borderColor, ";&:hover,&:focus{background:", secondary.hoverBgColor, ";}&:active{background:", secondary.activeBgColor, ";}}&.", k, "-link{color:", link.color, ";&:hover{color:", link.hoverColor, ";background:", link.hoverBgColor, ";}}&.", k, "-none,&.", k, "-link,&.", k, "-flat{background:transparent;&,&:hover{border:none;}&.", k, "-active{color:", theme.color.primary, ";}}&.", k, "-none:hover{background:", button.none.hoverBgColor, ";}&.", k, "-flat{background:", button.none.hoverBgColor, ";}&.", k, "-disabled{.", k, "-icon{color:inherit;}&,&:hover{color:", button.disabled.color, ";background:", button.disabled.bgColor, ";border-color:", button.disabled.borderColor, ";cursor:not-allowed;}}&.", k, "-none.", k, "-disabled,&.", k, "-link.", k, "-disabled{&,&:hover{background:transparent;}}", _mapInstanceProperty(sizes).call(sizes, function (size) {
|
|
203
|
+
}), "&.", k, "-secondary{color:", secondary.color, ";border-color:", secondary.borderColor, ";&:hover,&:focus{background:", secondary.hoverBgColor, ";}&:active{background:", secondary.activeBgColor, ";}}", color && /*#__PURE__*/css("&.", k, "-custom{color:", color, ";border-color:", color, ";&:hover,&:focus{background:", palette(color, -4), ";}&:active{background:", palette(color, -3), ";}}"), " &.", k, "-link{color:", link.color, ";&:hover{color:", link.hoverColor, ";background:", link.hoverBgColor, ";}}&.", k, "-none,&.", k, "-link,&.", k, "-flat{background:transparent;&,&:hover{border:none;}&.", k, "-active{color:", theme.color.primary, ";}}&.", k, "-none:hover{background:", button.none.hoverBgColor, ";}&.", k, "-flat{background:", button.none.hoverBgColor, ";}&.", k, "-disabled{.", k, "-icon{color:inherit;}&,&:hover{color:", button.disabled.color, ";background:", button.disabled.bgColor, ";border-color:", button.disabled.borderColor, ";cursor:not-allowed;}}&.", k, "-none.", k, "-disabled,&.", k, "-link.", k, "-disabled{&,&:hover{background:transparent;}}", _mapInstanceProperty(sizes).call(sizes, function (size) {
|
|
204
204
|
var styles = button[size];
|
|
205
205
|
return /*#__PURE__*/css("&.", k, "-", size, "{font-size:", styles.fontSize, ";height:", styles.height, ";padding:", styles.padding, ";&.", k, "-btn-icon{width:", styles.height, ";}}");
|
|
206
206
|
}), "&.", k, "-btn-icon{width:", button.height, ";padding:0;.", k, "-icon{margin:0;}}&.", k, "-fluid{width:100%;padding:0;}&.", k, "-circle{border-radius:calc(", button.large.height, " / 2);}&.", k, "-loading{", _mapInstanceProperty(types).call(types, function (type) {
|
|
@@ -211,7 +211,7 @@ export var makeButtonStyles = cache(function makeButtonStyles(k, iconSide) {
|
|
|
211
211
|
ghostColor = _button$type.ghostColor,
|
|
212
212
|
borderColor = _button$type.borderColor;
|
|
213
213
|
return /*#__PURE__*/css("&.", k, "-", type, "{color:", ghostColor, ";border-color:", borderColor, ";&:hover{color:", palette(ghostColor, -1), ";border-color:", palette(ghostColor, -1), ";}&:active{color:", palette(ghostColor, 1), ";border-color:", palette(ghostColor, 1), ";}}");
|
|
214
|
-
}), "&.", k, "-disabled{&,&:hover{color:", button.disabled.color, ";border-color:", button.disabled.ghostBorderColor, ";background:transparent;}}}"),
|
|
214
|
+
}), " ", color && /*#__PURE__*/css("&.", k, "-custom{color:", color, ";border-color:", color, ";&:hover{color:", palette(color, -1), ";border-color:", palette(color, -1), ";}&:active{color:", palette(color, 1), ";border-color:", palette(color, 1), ";}}"), "&.", k, "-disabled{&,&:hover{color:", button.disabled.color, ";border-color:", button.disabled.ghostBorderColor, ";background:transparent;}}}"),
|
|
215
215
|
/*#__PURE__*/
|
|
216
216
|
// dynamic styles
|
|
217
217
|
css(".", k, "-icon{", iconSide === 'right' ? "margin-left: " + button.icon.gap + ";" : "margin-right: " + button.icon.gap + ";", ";}", !iconSide && /*#__PURE__*/css("&.", k, "-loading{&:not(.", k, "-btn-icon){padding-left:calc(", getLeft(button.padding), " + 1em);", _mapInstanceProperty(sizes).call(sizes, function (size) {
|
|
@@ -34,8 +34,8 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
34
34
|
}), (_$blocks['body'] = function ($super) {
|
|
35
35
|
var _ref;
|
|
36
36
|
return [_$ce(2, 'div', [!hideIcon && !icon ? _$cc(Icon, {
|
|
37
|
-
'className': _$cn(iconClassName || (_ref = {}, _ref[k + "-icon-success-fill"] = type === 'success', _ref[k + "-icon-warning-fill"] = type === 'warning'
|
|
38
|
-
'color': type === 'error' ? 'danger' : type === 'confirm' ? '
|
|
37
|
+
'className': _$cn(iconClassName || (_ref = {}, _ref[k + "-icon-success-fill"] = type === 'success', _ref[k + "-icon-warning-fill"] = type === 'warning' || type === 'confirm', _ref[k + "-icon-error-fill"] = type === 'error', _ref)),
|
|
38
|
+
'color': type === 'error' ? 'danger' : type === 'confirm' ? 'warning' : type
|
|
39
39
|
}) : undefined, icon], 0, _$cn(k + "-dialog-tip-icon")), _$ce(2, 'div', [title ? _$ce(2, 'div', title, 0, _$cn(k + "-alert-dialog-title")) : undefined, content], 0, _$cn(k + "-alert-dialog-wrapper"))];
|
|
40
40
|
}, __$blocks['body'] = function ($super, data) {
|
|
41
41
|
var block = $blocks['body'];
|
|
@@ -12,6 +12,8 @@ export interface SwitchProps<True = any, False = any> {
|
|
|
12
12
|
height?: number | string;
|
|
13
13
|
size?: Sizes;
|
|
14
14
|
disabled?: boolean;
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
beforeChange?: (value: True | False | undefined) => boolean | Promise<boolean>;
|
|
15
17
|
}
|
|
16
18
|
export interface SwitchEvents {
|
|
17
19
|
click: [MouseEvent];
|
|
@@ -32,7 +34,7 @@ export declare class Switch<True = true, False = false> extends Component<Switch
|
|
|
32
34
|
private onClick;
|
|
33
35
|
private onClickOnHandle;
|
|
34
36
|
private onKeypress;
|
|
35
|
-
toggle(isKeypress: boolean): void
|
|
37
|
+
toggle(isKeypress: boolean): Promise<void>;
|
|
36
38
|
isChecked(): boolean;
|
|
37
39
|
check(): void;
|
|
38
40
|
uncheck(): void;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
1
2
|
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
2
4
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
|
|
3
5
|
import { __decorate } from "tslib";
|
|
4
6
|
import { Component, createRef } from 'intact';
|
|
@@ -17,14 +19,17 @@ var typeDefs = {
|
|
|
17
19
|
width: [Number, String],
|
|
18
20
|
height: [Number, String],
|
|
19
21
|
size: sizes,
|
|
20
|
-
disabled: Boolean
|
|
22
|
+
disabled: Boolean,
|
|
23
|
+
loading: Boolean,
|
|
24
|
+
beforeChange: Function
|
|
21
25
|
};
|
|
22
26
|
var defaults = function defaults() {
|
|
23
27
|
return {
|
|
24
28
|
value: false,
|
|
25
29
|
trueValue: true,
|
|
26
30
|
falseValue: false,
|
|
27
|
-
size: 'default'
|
|
31
|
+
size: 'default',
|
|
32
|
+
loading: false
|
|
28
33
|
};
|
|
29
34
|
};
|
|
30
35
|
var events = {
|
|
@@ -62,18 +67,65 @@ export var Switch = /*#__PURE__*/function (_Component) {
|
|
|
62
67
|
this.toggle(true);
|
|
63
68
|
}
|
|
64
69
|
};
|
|
65
|
-
_proto.toggle = function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
_proto.toggle = /*#__PURE__*/function () {
|
|
71
|
+
var _toggle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(isKeypress) {
|
|
72
|
+
var _this$get, disabled, beforeChange, value, ret;
|
|
73
|
+
return _regeneratorRuntime.wrap(function _callee$(_context2) {
|
|
74
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
75
|
+
case 0:
|
|
76
|
+
_this$get = this.get(), disabled = _this$get.disabled, beforeChange = _this$get.beforeChange, value = _this$get.value;
|
|
77
|
+
if (!disabled) {
|
|
78
|
+
_context2.next = 3;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
return _context2.abrupt("return");
|
|
82
|
+
case 3:
|
|
83
|
+
// if is not keypress, we blur it to remove focus style
|
|
84
|
+
if (!isKeypress) {
|
|
85
|
+
this.elementRef.value.blur();
|
|
86
|
+
}
|
|
87
|
+
if (!beforeChange) {
|
|
88
|
+
_context2.next = 15;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
this.set({
|
|
92
|
+
disabled: true,
|
|
93
|
+
loading: true
|
|
94
|
+
});
|
|
95
|
+
_context2.prev = 6;
|
|
96
|
+
_context2.next = 9;
|
|
97
|
+
return beforeChange(value);
|
|
98
|
+
case 9:
|
|
99
|
+
ret = _context2.sent;
|
|
100
|
+
if (ret) {
|
|
101
|
+
_context2.next = 12;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
return _context2.abrupt("return");
|
|
105
|
+
case 12:
|
|
106
|
+
_context2.prev = 12;
|
|
107
|
+
this.set({
|
|
108
|
+
disabled: false,
|
|
109
|
+
loading: false
|
|
110
|
+
});
|
|
111
|
+
return _context2.finish(12);
|
|
112
|
+
case 15:
|
|
113
|
+
if (this.isChecked()) {
|
|
114
|
+
this.uncheck();
|
|
115
|
+
} else {
|
|
116
|
+
this.check();
|
|
117
|
+
}
|
|
118
|
+
case 16:
|
|
119
|
+
case "end":
|
|
120
|
+
return _context2.stop();
|
|
121
|
+
}
|
|
122
|
+
}, _callee, this, [[6,, 12, 15]]);
|
|
123
|
+
}));
|
|
124
|
+
function toggle(_x) {
|
|
125
|
+
return _toggle.apply(this, arguments);
|
|
70
126
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
} else {
|
|
74
|
-
this.check();
|
|
75
|
-
}
|
|
76
|
-
};
|
|
127
|
+
return toggle;
|
|
128
|
+
}();
|
|
77
129
|
_proto.isChecked = function isChecked() {
|
|
78
130
|
return this.get('value') === this.get('trueValue');
|
|
79
131
|
};
|
|
@@ -4,6 +4,7 @@ import BasicDemo from '~/components/switch/demos/basic';
|
|
|
4
4
|
import DisabledDemo from '~/components/switch/demos/disabled';
|
|
5
5
|
import ValueDemo from '~/components/switch/demos/value';
|
|
6
6
|
import WidthHeightDemo from '~/components/switch/demos/widthHeight';
|
|
7
|
+
import BeforeChangeDemo from '~/components/switch/demos/beforeChange';
|
|
7
8
|
import { mount, unmount, dispatchEvent, wait } from '../../test/utils';
|
|
8
9
|
describe('Switch', function () {
|
|
9
10
|
afterEach(function () {
|
|
@@ -239,4 +240,24 @@ describe('Switch', function () {
|
|
|
239
240
|
}
|
|
240
241
|
}, _callee6);
|
|
241
242
|
})));
|
|
243
|
+
it('beforeChange', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
|
|
244
|
+
var _mount7, instance, element, _element$querySelecto5, el1, el2;
|
|
245
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
246
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
247
|
+
case 0:
|
|
248
|
+
_mount7 = mount(BeforeChangeDemo), instance = _mount7[0], element = _mount7[1];
|
|
249
|
+
_element$querySelecto5 = element.querySelectorAll('.k-switch'), el1 = _element$querySelecto5[0], el2 = _element$querySelecto5[1];
|
|
250
|
+
el1.click();
|
|
251
|
+
el2.click();
|
|
252
|
+
_context7.next = 6;
|
|
253
|
+
return wait(1000);
|
|
254
|
+
case 6:
|
|
255
|
+
expect(instance.get('value1')).to.be.true;
|
|
256
|
+
expect(instance.get('value2')).to.be.false;
|
|
257
|
+
case 8:
|
|
258
|
+
case "end":
|
|
259
|
+
return _context7.stop();
|
|
260
|
+
}
|
|
261
|
+
}, _callee7);
|
|
262
|
+
})));
|
|
242
263
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
2
2
|
import _Object$assign from "@babel/runtime-corejs3/core-js/object/assign";
|
|
3
|
-
import { createVNode as _$cv, className as _$cn, createElementVNode as _$ce, isChecked as _$isc, linkEvent as _$le, setCheckboxModel as _$scm, noop as _$no } from 'intact';
|
|
3
|
+
import { createVNode as _$cv, className as _$cn, createElementVNode as _$ce, isChecked as _$isc, linkEvent as _$le, setCheckboxModel as _$scm, noop as _$no, createUnknownComponentVNode as _$cc } from 'intact';
|
|
4
4
|
import { makeStyles } from './styles';
|
|
5
5
|
import { addStyle, getRestProps } from '../utils';
|
|
6
|
+
import { Icon } from '../icon';
|
|
6
7
|
var _$tmp0 = {
|
|
7
8
|
'src': 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
|
|
8
9
|
};
|
|
@@ -25,7 +26,8 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
25
26
|
width = _this$get.width,
|
|
26
27
|
height = _this$get.height,
|
|
27
28
|
size = _this$get.size,
|
|
28
|
-
disabled = _this$get.disabled
|
|
29
|
+
disabled = _this$get.disabled,
|
|
30
|
+
loading = _this$get.loading;
|
|
29
31
|
var _this$draggable = this.draggable,
|
|
30
32
|
start = _this$draggable.start,
|
|
31
33
|
dragging = _this$draggable.dragging,
|
|
@@ -36,6 +38,7 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
36
38
|
var onStyle;
|
|
37
39
|
var offStyle;
|
|
38
40
|
var barStyle;
|
|
41
|
+
var iconStyle;
|
|
39
42
|
if (width || height) {
|
|
40
43
|
var _style = {};
|
|
41
44
|
onStyle = {};
|
|
@@ -60,6 +63,9 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
60
63
|
barStyle = {
|
|
61
64
|
width: value === trueValue ? '100%' : height + "px"
|
|
62
65
|
};
|
|
66
|
+
iconStyle = {
|
|
67
|
+
fontSize: height * 0.7 + "px"
|
|
68
|
+
};
|
|
63
69
|
}
|
|
64
70
|
style = addStyle(style, _style);
|
|
65
71
|
}
|
|
@@ -106,10 +112,14 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
106
112
|
return block ? block.call($this, callBlock, data) : callBlock();
|
|
107
113
|
}, __$blocks['on'](_$no)), 0, _$cn(k + "-switch-on"), {
|
|
108
114
|
'style': onStyle
|
|
109
|
-
}) : undefined, _$ce(2, 'div',
|
|
115
|
+
}) : undefined, _$ce(2, 'div', [loading ? _$cc(Icon, {
|
|
116
|
+
'className': _$cn(k + "-switch-icon ion-load-c"),
|
|
117
|
+
'rotate': true,
|
|
118
|
+
'style': iconStyle
|
|
119
|
+
}) : undefined, _$ce(2, 'div', _$ce(2, 'img', null, 1, null, _$tmp0), 2, _$cn(k + "-switch-handle"), {
|
|
110
120
|
'ev-click': this.onClickOnHandle,
|
|
111
121
|
'ev-mousedown': start
|
|
112
|
-
}),
|
|
122
|
+
})], 0, _$cn(k + "-switch-wrapper"))], 0, _$cn(k + "-switch-bar"), {
|
|
113
123
|
'style': barStyle
|
|
114
124
|
}, null, barRef)]);
|
|
115
125
|
}
|
|
@@ -34,25 +34,29 @@ var defaults = {
|
|
|
34
34
|
default: {
|
|
35
35
|
width: "45px",
|
|
36
36
|
height: "24px",
|
|
37
|
-
padding: "3px"
|
|
37
|
+
padding: "3px",
|
|
38
|
+
iconSize: "16px"
|
|
38
39
|
},
|
|
39
40
|
// large
|
|
40
41
|
large: {
|
|
41
42
|
width: "58px",
|
|
42
43
|
height: "30px",
|
|
43
|
-
padding: "3px"
|
|
44
|
+
padding: "3px",
|
|
45
|
+
iconSize: "20px"
|
|
44
46
|
},
|
|
45
47
|
// small
|
|
46
48
|
small: {
|
|
47
49
|
width: "30px",
|
|
48
50
|
height: "16px",
|
|
49
|
-
padding: "2px"
|
|
51
|
+
padding: "2px",
|
|
52
|
+
iconSize: "10px"
|
|
50
53
|
},
|
|
51
54
|
// mini
|
|
52
55
|
mini: {
|
|
53
56
|
width: "18px",
|
|
54
57
|
height: "10px",
|
|
55
|
-
padding: "1px"
|
|
58
|
+
padding: "1px",
|
|
59
|
+
iconSize: "6px"
|
|
56
60
|
},
|
|
57
61
|
// disabled
|
|
58
62
|
get disabledBgColor() {
|
|
@@ -67,11 +71,12 @@ setDefault(function () {
|
|
|
67
71
|
makeStyles == null || makeStyles.clearCache();
|
|
68
72
|
});
|
|
69
73
|
export var makeStyles = cache(function makeStyles(k) {
|
|
70
|
-
return /*#__PURE__*/css("display:inline-block;vertical-align:middle;background:", kswitch.bgColor, ";position:relative;cursor:pointer;user-select:none;overflow:hidden;box-sizing:content-box;transition:background ", kswitch.transition, ";input{opacity:0;position:absolute;}.", k, "-switch-bar,.", k, "-switch-off{box-sizing:border-box;}.", k, "-switch-bar{position:absolute;text-align:right;overflow:hidden;}.", k, "-switch-wrapper{display:inline-block;position:relative;z-index:1;border-radius:", kswitch.handleBorderRadius, ";}.", k, "-switch-bar,.", k, "-switch-wrapper{height:100%;background:", kswitch.bgColor, ";transition:all ", kswitch.transition, ";}&:hover{&,.", k, "-switch-bar,.", k, "-switch-wrapper{background:", kswitch.hoverBgColor, ";}}.", k, "-switch-handle{border-radius:", kswitch.handleBorderRadius, ";background:", kswitch.handleBgColor, ";height:100%;cursor:pointer;transition:left ", kswitch.transition, ";display:inline-block;img{height:100%;visibility:hidden;}}.", k, "-switch-on,.", k, "-switch-off{position:absolute;font-size:", kswitch.fontSize, ";color:", kswitch.color, ";text-align:center;}&.", k, "-dragging{.", k, "-switch-bar,.", k, "-switch-wrapper{background:", kswitch.checked.bgColor, ";transition:background ", kswitch.transition, ";}}&:focus{outline:none;}", _mapInstanceProperty(sizes).call(sizes, function (size) {
|
|
74
|
+
return /*#__PURE__*/css("display:inline-block;vertical-align:middle;background:", kswitch.bgColor, ";position:relative;cursor:pointer;user-select:none;overflow:hidden;box-sizing:content-box;transition:background ", kswitch.transition, ";input{opacity:0;position:absolute;}.", k, "-switch-bar,.", k, "-switch-off{box-sizing:border-box;}.", k, "-switch-bar{position:absolute;text-align:right;overflow:hidden;}.", k, "-switch-wrapper{display:inline-block;position:relative;z-index:1;border-radius:", kswitch.handleBorderRadius, ";}.", k, "-switch-bar,.", k, "-switch-wrapper{height:100%;background:", kswitch.bgColor, ";transition:all ", kswitch.transition, ";}&:hover{&,.", k, "-switch-bar,.", k, "-switch-wrapper{background:", kswitch.hoverBgColor, ";}}.", k, "-switch-handle{border-radius:", kswitch.handleBorderRadius, ";background:", kswitch.handleBgColor, ";height:100%;cursor:pointer;transition:left ", kswitch.transition, ";display:inline-block;img{height:100%;visibility:hidden;}}.", k, "-switch-icon{position:absolute;left:50%;top:50%;transform:translate(-50%, -50%);}.", k, "-switch-on,.", k, "-switch-off{position:absolute;font-size:", kswitch.fontSize, ";color:", kswitch.color, ";text-align:center;}&.", k, "-dragging{.", k, "-switch-bar,.", k, "-switch-wrapper{background:", kswitch.checked.bgColor, ";transition:background ", kswitch.transition, ";}}&:focus{outline:none;}", _mapInstanceProperty(sizes).call(sizes, function (size) {
|
|
71
75
|
var _kswitch$size = kswitch[size],
|
|
72
76
|
width = _kswitch$size.width,
|
|
73
77
|
height = _kswitch$size.height,
|
|
74
|
-
padding = _kswitch$size.padding
|
|
75
|
-
|
|
78
|
+
padding = _kswitch$size.padding,
|
|
79
|
+
iconSize = _kswitch$size.iconSize;
|
|
80
|
+
return /*#__PURE__*/css("&.", k, "-", size, ",&.", k, "-", size, " .", k, "-switch-on,&.", k, "-", size, " .", k, "-switch-off{width:", width, ";height:", height, ";}&.", k, "-", size, "{border-radius:", height, ";.", k, "-switch-bar{width:", height, ";border-radius:", height, ";}.", k, "-switch-wrapper{padding:", padding, ";}.", k, "-switch-on,.", k, "-switch-off{line-height:", height, ";left:0;}.", k, "-switch-on{padding:0 ", height, " 0 calc(", height, " / 3);}.", k, "-switch-off{padding:0 calc(", height, " / 3) 0 ", height, ";}.", k, "-switch-icon{font-size:", iconSize, ";}}");
|
|
76
81
|
}), "&.", k, "-checked{.", k, "-switch-bar,.", k, "-switch-wrapper{background:", kswitch.checked.bgColor, ";}.", k, "-switch-bar{width:100%;}&:hover{.", k, "-switch-bar,.", k, "-switch-wrapper{background:", kswitch.checked.hoverBgColor, ";}}}&.", k, "-disabled{&,.", k, "-switch-handle{cursor:not-allowed;}&,.", k, "-switch-bar,.", k, "-switch-wrapper{background:", kswitch.disabledBgColor, ";}&.", k, "-checked{&,.", k, "-switch-bar,.", k, "-switch-wrapper{background:", kswitch.checked.disabledBgColor, ";}}}");
|
|
77
82
|
});
|