antd-solid 0.0.6 → 0.0.8
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/dist/index.esm.js +2356 -0
- package/dist/index.umd.js +1 -0
- package/es/Button.d.ts +19 -0
- package/es/Button.js +73 -0
- package/es/Collapse/index.d.ts +16 -0
- package/es/Collapse/index.js +87 -0
- package/es/ColorPicker.d.ts +8 -0
- package/es/ColorPicker.js +6 -0
- package/es/Compact.d.ts +12 -0
- package/es/Compact.js +17 -0
- package/es/DatePicker.d.ts +19 -0
- package/es/DatePicker.js +9 -0
- package/es/Empty/PRESENTED_IMAGE_SIMPLE.d.ts +3 -0
- package/es/Empty/PRESENTED_IMAGE_SIMPLE.js +14 -0
- package/es/Empty/assets/EmptySvg.d.ts +2 -0
- package/es/Empty/assets/EmptySvg.js +6 -0
- package/es/Empty/assets/SimpleEmptySvg.d.ts +2 -0
- package/es/Empty/assets/SimpleEmptySvg.js +6 -0
- package/es/Empty/index.d.ts +5 -0
- package/es/Empty/index.js +16 -0
- package/es/Image.d.ts +9 -0
- package/es/Image.js +22 -0
- package/es/Input.d.ts +29 -0
- package/es/Input.js +144 -0
- package/es/InputNumber.d.ts +11 -0
- package/es/InputNumber.js +92 -0
- package/es/InputNumber.test.d.ts +1 -0
- package/es/InputNumber.test.js +42 -0
- package/es/Modal.d.ts +47 -0
- package/es/Modal.js +195 -0
- package/es/Popconfirm.d.ts +21 -0
- package/es/Popconfirm.js +64 -0
- package/es/Popover.d.ts +7 -0
- package/es/Popover.js +36 -0
- package/es/Progress.d.ts +7 -0
- package/es/Progress.js +6 -0
- package/es/Radio.d.ts +27 -0
- package/es/Radio.js +89 -0
- package/es/Result.d.ts +10 -0
- package/es/Result.js +29 -0
- package/es/Segmented/index.d.ts +21 -0
- package/es/Segmented/index.js +72 -0
- package/es/Select.d.ts +16 -0
- package/es/Select.js +113 -0
- package/es/Skeleton.d.ts +9 -0
- package/es/Skeleton.js +9 -0
- package/es/Spin.d.ts +9 -0
- package/es/Spin.js +22 -0
- package/es/Switch.d.ts +8 -0
- package/es/Switch.js +30 -0
- package/es/Table.d.ts +11 -0
- package/es/Table.js +57 -0
- package/es/Tabs.d.ts +17 -0
- package/es/Tabs.js +117 -0
- package/es/Timeline.d.ts +13 -0
- package/es/Timeline.js +30 -0
- package/es/Tooltip.d.ts +34 -0
- package/es/Tooltip.js +302 -0
- package/es/Tree.d.ts +28 -0
- package/es/Tree.js +198 -0
- package/es/Upload.d.ts +11 -0
- package/es/Upload.js +6 -0
- package/es/form/Form.d.ts +18 -0
- package/es/form/Form.js +70 -0
- package/es/form/FormItem.d.ts +19 -0
- package/es/form/FormItem.js +141 -0
- package/es/form/context.d.ts +12 -0
- package/es/form/context.js +5 -0
- package/es/form/index.d.ts +8 -0
- package/es/form/index.js +7 -0
- package/es/hooks/createControllableValue.d.ts +16 -0
- package/es/hooks/createControllableValue.js +41 -0
- package/es/hooks/createUpdateEffect.d.ts +5 -0
- package/es/hooks/createUpdateEffect.js +12 -0
- package/es/hooks/index.d.ts +2 -0
- package/es/hooks/index.js +2 -0
- package/es/hooks/useClickAway.d.ts +2 -0
- package/es/hooks/useClickAway.js +17 -0
- package/es/hooks/useSize.d.ts +5 -0
- package/es/hooks/useSize.js +22 -0
- package/es/index.d.ts +42 -0
- package/es/index.js +29 -0
- package/es/types/index.d.ts +3 -0
- package/es/types/index.js +1 -0
- package/es/utils/EventEmitter.d.ts +7 -0
- package/es/utils/EventEmitter.js +13 -0
- package/es/utils/ReactToSolid.d.ts +8 -0
- package/es/utils/ReactToSolid.js +30 -0
- package/es/utils/SolidToReact.d.ts +8 -0
- package/es/utils/SolidToReact.js +23 -0
- package/es/utils/array.d.ts +15 -0
- package/es/utils/array.js +19 -0
- package/es/utils/component.d.ts +31 -0
- package/es/utils/component.js +68 -0
- package/es/utils/solid.d.ts +15 -0
- package/es/utils/solid.js +32 -0
- package/es/utils/zh_CN.d.ts +2 -0
- package/{src/utils/zh_CN.ts → es/utils/zh_CN.js} +34 -34
- package/package.json +7 -6
- package/src/Button.tsx +0 -125
- package/src/Collapse/index.tsx +0 -86
- package/src/ColorPicker.tsx +0 -11
- package/src/Compact.tsx +0 -15
- package/src/DatePicker.tsx +0 -22
- package/src/Empty/PRESENTED_IMAGE_SIMPLE.tsx +0 -15
- package/src/Empty/assets/EmptySvg.tsx +0 -43
- package/src/Empty/assets/SimpleEmptySvg.tsx +0 -16
- package/src/Empty/index.tsx +0 -20
- package/src/Image.tsx +0 -29
- package/src/Input.tsx +0 -202
- package/src/InputNumber.test.tsx +0 -46
- package/src/InputNumber.tsx +0 -125
- package/src/Modal.tsx +0 -196
- package/src/Popconfirm.tsx +0 -75
- package/src/Popover.tsx +0 -30
- package/src/Progress.tsx +0 -4
- package/src/Radio.tsx +0 -132
- package/src/Result.tsx +0 -38
- package/src/Segmented/index.tsx +0 -95
- package/src/Select.tsx +0 -128
- package/src/Skeleton.tsx +0 -14
- package/src/Spin.tsx +0 -23
- package/src/Switch.tsx +0 -34
- package/src/Table.tsx +0 -53
- package/src/Tabs.tsx +0 -131
- package/src/Timeline.tsx +0 -33
- package/src/Tooltip.tsx +0 -355
- package/src/Tree.tsx +0 -246
- package/src/Upload.tsx +0 -10
- package/src/form/Form.tsx +0 -94
- package/src/form/FormItem.tsx +0 -139
- package/src/form/context.ts +0 -16
- package/src/form/index.ts +0 -13
- package/src/hooks/createControllableValue.ts +0 -68
- package/src/hooks/createUpdateEffect.ts +0 -16
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useClickAway.ts +0 -18
- package/src/hooks/useSize.ts +0 -26
- package/src/index.ts +0 -44
- package/src/types/index.ts +0 -5
- package/src/utils/EventEmitter.ts +0 -15
- package/src/utils/ReactToSolid.tsx +0 -38
- package/src/utils/SolidToReact.tsx +0 -27
- package/src/utils/array.ts +0 -21
- package/src/utils/component.tsx +0 -85
- package/src/utils/solid.ts +0 -53
- /package/{dist → css}/index.css +0 -0
package/es/Input.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { createComponent, Dynamic, mergeProps, insert, effect, className, style, template } from 'solid-js/web';
|
|
2
|
+
import { isNil, omit } from 'lodash-es';
|
|
3
|
+
import { splitProps, createMemo, Show } from 'solid-js';
|
|
4
|
+
import cs from 'classnames';
|
|
5
|
+
import createControllableValue from './hooks/createControllableValue.js';
|
|
6
|
+
import Compact from './Compact.js';
|
|
7
|
+
|
|
8
|
+
const _tmpl$ = /*#__PURE__*/template(`<div>`),
|
|
9
|
+
_tmpl$2 = /*#__PURE__*/template(`<div class="ant-mr-4px">`),
|
|
10
|
+
_tmpl$3 = /*#__PURE__*/template(`<div class="ant-ml-4px">`),
|
|
11
|
+
_tmpl$4 = /*#__PURE__*/template(`<div class="ant-[display:var(--input-after-display)] ant-absolute ant-top-0 ant-bottom-0 ant-right-0 ant-h-[calc(100%-2px)] ant-translate-y-1px -ant-translate-x-1px">`);
|
|
12
|
+
const statusClassDict = {
|
|
13
|
+
default: disabled => cs('ant-[border:1px_solid_var(--ant-color-border)]', !disabled && 'hover:ant-border-[var(--primary-color)] focus-within:ant-border-[var(--primary-color)] focus-within:ant-[box-shadow:0_0_0_2px_rgba(5,145,255,0.1)]'),
|
|
14
|
+
error: disabled => cs('ant-[border:1px_solid_var(--ant-color-error)]', !disabled && 'hover:ant-border-[var(--light-error-color)] focus-within:ant-[box-shadow:0_0_0_2px_rgba(255,38,5,.06)]'),
|
|
15
|
+
warning: disabled => cs('ant-[border:1px_solid_var(--warning-color)]', !disabled && 'hover:ant-border-[var(--color-warning-border-hover)] focus-within:ant-[box-shadow:0_0_0_2px_rgba(255,215,5,.1)]')
|
|
16
|
+
};
|
|
17
|
+
function CommonInput(props) {
|
|
18
|
+
const [{
|
|
19
|
+
style: style$1,
|
|
20
|
+
onChange,
|
|
21
|
+
onPressEnter,
|
|
22
|
+
onKeyDown
|
|
23
|
+
}, inputProps] = splitProps(props, ['defaultValue', 'value', 'class', 'addonBefore', 'addonAfter', 'suffix', 'onChange', 'onPressEnter', 'onKeyDown', 'actions', 'style']);
|
|
24
|
+
const [_, controllableProps] = splitProps(props, ['onChange']);
|
|
25
|
+
const [value, setValue] = createControllableValue(controllableProps);
|
|
26
|
+
const inputWrapClass = createMemo(() => cs('ant-px-11px ant-py-4px ant-rounded-6px', !props.textarea && 'ant-h-32px', props.addonBefore ? 'ant-rounded-l-0' : Compact.compactItemRoundedLeftClass, props.addonAfter ? 'ant-rounded-r-0' : Compact.compactItemRoundedRightClass, statusClassDict[props.status ?? 'default'](!!inputProps.disabled), Compact.compactItemRounded0Class, Compact.compactItemZIndexClass));
|
|
27
|
+
const hasPrefixOrSuffix = createMemo(() => !isNil(props.prefix) || !isNil(props.suffix) || !isNil(props.actions));
|
|
28
|
+
const inputJSX = createComponent(Dynamic, mergeProps({
|
|
29
|
+
get component() {
|
|
30
|
+
return props.textarea ? 'textarea' : 'input';
|
|
31
|
+
}
|
|
32
|
+
}, inputProps, {
|
|
33
|
+
get ["class"]() {
|
|
34
|
+
return cs('ant-w-full ant-[outline:none] ant-text-14px', !hasPrefixOrSuffix() && inputWrapClass(), inputProps.disabled && 'ant-bg-[var(--ant-color-bg-container-disabled)] ant-cursor-not-allowed');
|
|
35
|
+
},
|
|
36
|
+
get value() {
|
|
37
|
+
return value() ?? '';
|
|
38
|
+
},
|
|
39
|
+
onInput: e => {
|
|
40
|
+
setValue(e.target.value);
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
42
|
+
onChange?.(e);
|
|
43
|
+
if (Object.keys(props).includes('value')) {
|
|
44
|
+
e.target.value = value();
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
onKeyDown: e => {
|
|
48
|
+
if (e.key === 'Enter') {
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
50
|
+
onPressEnter?.(e);
|
|
51
|
+
}
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
53
|
+
onKeyDown?.(e);
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
return (() => {
|
|
57
|
+
const _el$ = _tmpl$();
|
|
58
|
+
insert(_el$, createComponent(Show, {
|
|
59
|
+
get when() {
|
|
60
|
+
return props.addonBefore;
|
|
61
|
+
},
|
|
62
|
+
get children() {
|
|
63
|
+
const _el$2 = _tmpl$();
|
|
64
|
+
insert(_el$2, () => props.addonBefore);
|
|
65
|
+
effect(() => className(_el$2, cs('ant-shrink-0 ant-flex ant-justify-center ant-items-center ant-px-11px ant-bg-[rgba(0,0,0,.02)] ant-[border:1px_solid_var(--ant-color-border)] ant-border-r-0 ant-rounded-l-6px ant-text-14px', Compact.compactItemRounded0Class, Compact.compactItemRoundedLeftClass)));
|
|
66
|
+
return _el$2;
|
|
67
|
+
}
|
|
68
|
+
}), null);
|
|
69
|
+
insert(_el$, createComponent(Show, {
|
|
70
|
+
get when() {
|
|
71
|
+
return hasPrefixOrSuffix();
|
|
72
|
+
},
|
|
73
|
+
fallback: inputJSX,
|
|
74
|
+
get children() {
|
|
75
|
+
const _el$3 = _tmpl$();
|
|
76
|
+
insert(_el$3, createComponent(Show, {
|
|
77
|
+
get when() {
|
|
78
|
+
return props.prefix;
|
|
79
|
+
},
|
|
80
|
+
get children() {
|
|
81
|
+
const _el$4 = _tmpl$2();
|
|
82
|
+
insert(_el$4, () => props.prefix);
|
|
83
|
+
return _el$4;
|
|
84
|
+
}
|
|
85
|
+
}), null);
|
|
86
|
+
insert(_el$3, inputJSX, null);
|
|
87
|
+
insert(_el$3, createComponent(Show, {
|
|
88
|
+
get when() {
|
|
89
|
+
return props.suffix;
|
|
90
|
+
},
|
|
91
|
+
get children() {
|
|
92
|
+
const _el$5 = _tmpl$3();
|
|
93
|
+
insert(_el$5, () => props.suffix);
|
|
94
|
+
return _el$5;
|
|
95
|
+
}
|
|
96
|
+
}), null);
|
|
97
|
+
insert(_el$3, createComponent(Show, {
|
|
98
|
+
get when() {
|
|
99
|
+
return props.actions;
|
|
100
|
+
},
|
|
101
|
+
get children() {
|
|
102
|
+
const _el$6 = _tmpl$4();
|
|
103
|
+
insert(_el$6, () => props.actions);
|
|
104
|
+
return _el$6;
|
|
105
|
+
}
|
|
106
|
+
}), null);
|
|
107
|
+
effect(() => className(_el$3, cs('ant-flex ant-items-center ant-w-full ant-relative ant-[--input-after-display:none] hover:ant-[--input-after-display:block] p:hover-child[input]:ant-border-[var(--primary-color)]', inputWrapClass())));
|
|
108
|
+
return _el$3;
|
|
109
|
+
}
|
|
110
|
+
}), null);
|
|
111
|
+
insert(_el$, createComponent(Show, {
|
|
112
|
+
get when() {
|
|
113
|
+
return props.addonAfter;
|
|
114
|
+
},
|
|
115
|
+
get children() {
|
|
116
|
+
const _el$7 = _tmpl$();
|
|
117
|
+
insert(_el$7, () => props.addonAfter);
|
|
118
|
+
effect(() => className(_el$7, cs('ant-shrink-0 ant-flex ant-justify-center ant-items-center ant-px-11px ant-bg-[rgba(0,0,0,.02)] ant-[border:1px_solid_var(--ant-color-border)] ant-border-l-0 ant-rounded-r-6px ant-text-14px', Compact.compactItemRounded0Class, Compact.compactItemRoundedRightClass)));
|
|
119
|
+
return _el$7;
|
|
120
|
+
}
|
|
121
|
+
}), null);
|
|
122
|
+
effect(_p$ => {
|
|
123
|
+
const _v$ = cs('ant-flex ant-w-full', Compact.compactItemClass),
|
|
124
|
+
_v$2 = style$1;
|
|
125
|
+
_v$ !== _p$._v$ && className(_el$, _p$._v$ = _v$);
|
|
126
|
+
_p$._v$2 = style(_el$, _v$2, _p$._v$2);
|
|
127
|
+
return _p$;
|
|
128
|
+
}, {
|
|
129
|
+
_v$: undefined,
|
|
130
|
+
_v$2: undefined
|
|
131
|
+
});
|
|
132
|
+
return _el$;
|
|
133
|
+
})();
|
|
134
|
+
}
|
|
135
|
+
const Input = props => {
|
|
136
|
+
return createComponent(CommonInput, mergeProps(() => omit(props, ['actions'])));
|
|
137
|
+
};
|
|
138
|
+
Input.TextArea = props => {
|
|
139
|
+
return createComponent(CommonInput, mergeProps({
|
|
140
|
+
textarea: true
|
|
141
|
+
}, () => omit(props, ['prefix', 'suffix', 'actions'])));
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export { CommonInput, Input as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Component } from 'solid-js';
|
|
2
|
+
import { type InputProps } from './Input';
|
|
3
|
+
export interface InputNumberProps extends Omit<InputProps, 'defaultValue' | 'value' | 'onChange' | 'inputAfter' | 'onKeyDown' | 'min' | 'max' | 'suffix'> {
|
|
4
|
+
defaultValue?: number | null | undefined;
|
|
5
|
+
value?: number | null | undefined;
|
|
6
|
+
onChange?: (value: number | null) => void;
|
|
7
|
+
min?: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
}
|
|
10
|
+
declare const InputNumber: Component<InputNumberProps>;
|
|
11
|
+
export default InputNumber;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { delegateEvents, createComponent, mergeProps as mergeProps$1, template } from 'solid-js/web';
|
|
2
|
+
import { mergeProps, splitProps, createSignal, untrack, createEffect, on } from 'solid-js';
|
|
3
|
+
import { CommonInput } from './Input.js';
|
|
4
|
+
import { isNil, clamp } from 'lodash-es';
|
|
5
|
+
import { dispatchEventHandlerUnion } from './utils/solid.js';
|
|
6
|
+
|
|
7
|
+
const _tmpl$ = /*#__PURE__*/template(`<div class="ant-flex ant-flex-col ant-h-full ant-w-24px ant-[border-left:1px_solid_var(--ant-color-border)]"><div class="ant-text-12px ant-flex ant-justify-center ant-items-center ant-h-1/2 ant-cursor-pointer ant-opacity-70 hover:ant-h-100% hover:ant-text-[var(--primary-color)] ant-transition-color ant-transition-height ant-transition-duration-500"><div class="i-ant-design:up-outlined"></div></div><div class="ant-[border-top:1px_solid_var(--ant-color-border)] ant-text-12px ant-flex ant-justify-center ant-items-center ant-h-1/2 ant-cursor-pointer ant-opacity-70 hover:ant-h-100% hover:ant-text-[var(--primary-color)] ant-transition-color ant-transition-height ant-transition-duration-500"><div class="i-ant-design:down-outlined">`);
|
|
8
|
+
const isEmptyValue = value => isNil(value) || value === '';
|
|
9
|
+
const InputNumber = _props => {
|
|
10
|
+
const props = mergeProps({
|
|
11
|
+
min: -Infinity,
|
|
12
|
+
max: Infinity
|
|
13
|
+
}, _props);
|
|
14
|
+
const [_, inputProps] = splitProps(props, ['defaultValue', 'value', 'onChange', 'onBlur']);
|
|
15
|
+
const clampValue = v => untrack(() => clamp(v, props.min, props.max));
|
|
16
|
+
let prev = null;
|
|
17
|
+
const updatePrev = v => {
|
|
18
|
+
if (prev === v) return;
|
|
19
|
+
prev = v;
|
|
20
|
+
props.onChange?.(prev);
|
|
21
|
+
};
|
|
22
|
+
const [value, setValue] = createSignal(untrack(() => props.value ?? props.defaultValue));
|
|
23
|
+
createEffect(on(() => props.value, () => {
|
|
24
|
+
setValue(props.value);
|
|
25
|
+
}, {
|
|
26
|
+
defer: true
|
|
27
|
+
}));
|
|
28
|
+
const add = addon => {
|
|
29
|
+
let newValue;
|
|
30
|
+
if (isEmptyValue(value())) {
|
|
31
|
+
newValue = clampValue(addon);
|
|
32
|
+
} else {
|
|
33
|
+
const num = Number(value());
|
|
34
|
+
newValue = Number.isNaN(num) ? null : clampValue(num + addon);
|
|
35
|
+
}
|
|
36
|
+
if (!Object.keys(props).includes('value')) {
|
|
37
|
+
setValue(newValue);
|
|
38
|
+
}
|
|
39
|
+
updatePrev(newValue);
|
|
40
|
+
};
|
|
41
|
+
const up = () => {
|
|
42
|
+
add(1);
|
|
43
|
+
};
|
|
44
|
+
const down = () => {
|
|
45
|
+
add(-1);
|
|
46
|
+
};
|
|
47
|
+
return createComponent(CommonInput, mergeProps$1(inputProps, {
|
|
48
|
+
get actions() {
|
|
49
|
+
return (() => {
|
|
50
|
+
const _el$ = _tmpl$(),
|
|
51
|
+
_el$2 = _el$.firstChild,
|
|
52
|
+
_el$3 = _el$2.nextSibling;
|
|
53
|
+
_el$2.$$click = up;
|
|
54
|
+
_el$3.$$click = down;
|
|
55
|
+
return _el$;
|
|
56
|
+
})();
|
|
57
|
+
},
|
|
58
|
+
get value() {
|
|
59
|
+
return `${value() ?? ''}`;
|
|
60
|
+
},
|
|
61
|
+
onKeyDown: e => {
|
|
62
|
+
switch (e.key) {
|
|
63
|
+
case 'ArrowUp':
|
|
64
|
+
up();
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
return;
|
|
67
|
+
case 'ArrowDown':
|
|
68
|
+
down();
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
onChange: e => {
|
|
73
|
+
const newValue = e.target.value;
|
|
74
|
+
setValue(newValue);
|
|
75
|
+
let newValueNum = Number(newValue);
|
|
76
|
+
if (Number.isNaN(newValueNum)) return;
|
|
77
|
+
if (isEmptyValue(newValue)) {
|
|
78
|
+
newValueNum = null;
|
|
79
|
+
} else {
|
|
80
|
+
newValueNum = clampValue(newValueNum);
|
|
81
|
+
}
|
|
82
|
+
updatePrev(newValueNum);
|
|
83
|
+
},
|
|
84
|
+
onBlur: e => {
|
|
85
|
+
setValue(props.value ?? prev);
|
|
86
|
+
dispatchEventHandlerUnion(props.onBlur, e);
|
|
87
|
+
}
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
delegateEvents(["click"]);
|
|
91
|
+
|
|
92
|
+
export { InputNumber as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createComponent } from 'solid-js/web';
|
|
2
|
+
import { describe, it, vi, expect } from 'vitest';
|
|
3
|
+
import { render, fireEvent } from '@solidjs/testing-library';
|
|
4
|
+
import InputNumber from './InputNumber.js';
|
|
5
|
+
import '@testing-library/jest-dom';
|
|
6
|
+
|
|
7
|
+
describe('InputNumber component', () => {
|
|
8
|
+
it('onChange', () => {
|
|
9
|
+
const onChange = vi.fn();
|
|
10
|
+
const {
|
|
11
|
+
getByPlaceholderText
|
|
12
|
+
} = render(() => createComponent(InputNumber, {
|
|
13
|
+
placeholder: "input-number",
|
|
14
|
+
onChange: onChange
|
|
15
|
+
}));
|
|
16
|
+
const input = getByPlaceholderText('input-number');
|
|
17
|
+
input.value = '123';
|
|
18
|
+
fireEvent.input(input);
|
|
19
|
+
expect(onChange).toHaveBeenLastCalledWith(123);
|
|
20
|
+
input.value = '1234';
|
|
21
|
+
fireEvent.input(input);
|
|
22
|
+
expect(onChange).toBeCalledTimes(2);
|
|
23
|
+
expect(onChange).toHaveBeenLastCalledWith(1234);
|
|
24
|
+
input.value = '1234';
|
|
25
|
+
fireEvent.input(input);
|
|
26
|
+
expect(onChange).toBeCalledTimes(2);
|
|
27
|
+
input.value = '1234.';
|
|
28
|
+
fireEvent.input(input);
|
|
29
|
+
expect(onChange).toBeCalledTimes(2);
|
|
30
|
+
input.value = '1234.0';
|
|
31
|
+
fireEvent.input(input);
|
|
32
|
+
expect(onChange).toBeCalledTimes(2);
|
|
33
|
+
input.value = '1234.01';
|
|
34
|
+
fireEvent.input(input);
|
|
35
|
+
expect(onChange).toBeCalledTimes(3);
|
|
36
|
+
input.value = '123x';
|
|
37
|
+
fireEvent.input(input);
|
|
38
|
+
expect(onChange).toBeCalledTimes(3);
|
|
39
|
+
fireEvent.blur(input);
|
|
40
|
+
expect(onChange).toBeCalledTimes(3);
|
|
41
|
+
});
|
|
42
|
+
});
|
package/es/Modal.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type JSXElement, type Ref } from 'solid-js';
|
|
2
|
+
export interface ModalInstance {
|
|
3
|
+
open: () => void;
|
|
4
|
+
close: () => void;
|
|
5
|
+
}
|
|
6
|
+
export interface ModalProps {
|
|
7
|
+
ref?: Ref<ModalInstance>;
|
|
8
|
+
title?: JSXElement;
|
|
9
|
+
defaultOpen?: boolean;
|
|
10
|
+
width?: string;
|
|
11
|
+
height?: string;
|
|
12
|
+
children?: JSXElement;
|
|
13
|
+
/**
|
|
14
|
+
* 垂直居中展示 Modal
|
|
15
|
+
*/
|
|
16
|
+
centered?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 点击蒙层是否允许关闭
|
|
19
|
+
* 默认 true
|
|
20
|
+
*/
|
|
21
|
+
maskClosable?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 设置为 false 时隐藏关闭按钮
|
|
24
|
+
*/
|
|
25
|
+
closeIcon?: boolean;
|
|
26
|
+
footer?: boolean | ((modal: ModalInstance) => JSXElement);
|
|
27
|
+
/**
|
|
28
|
+
* 关闭时销毁 Modal 里的子元素
|
|
29
|
+
*/
|
|
30
|
+
destroyOnClose?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 返回 true,会自动关闭 modal
|
|
33
|
+
*/
|
|
34
|
+
onOk?: () => boolean | Promise<boolean>;
|
|
35
|
+
afterClose?: () => void;
|
|
36
|
+
/**
|
|
37
|
+
* 自定义渲染对话框
|
|
38
|
+
*/
|
|
39
|
+
modalRender?: () => JSXElement;
|
|
40
|
+
}
|
|
41
|
+
export interface MethodProps extends Pick<ModalProps, 'title' | 'children' | 'onOk' | 'afterClose'> {
|
|
42
|
+
}
|
|
43
|
+
declare function Modal(_props: ModalProps): import("solid-js").JSX.Element;
|
|
44
|
+
declare namespace Modal {
|
|
45
|
+
var warning: (props: MethodProps) => void;
|
|
46
|
+
}
|
|
47
|
+
export default Modal;
|
package/es/Modal.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { delegateEvents, createComponent, Portal, insert, memo, effect, className, render, mergeProps as mergeProps$1, template } from 'solid-js/web';
|
|
2
|
+
import { mergeProps, createSignal, untrack, Show } from 'solid-js';
|
|
3
|
+
import Button from './Button.js';
|
|
4
|
+
import cs from 'classnames';
|
|
5
|
+
|
|
6
|
+
const _tmpl$ = /*#__PURE__*/template(`<span class="i-ant-design:close-outlined">`),
|
|
7
|
+
_tmpl$2 = /*#__PURE__*/template(`<div class="ant-flex ant-gap-8px ant-justify-end">`),
|
|
8
|
+
_tmpl$3 = /*#__PURE__*/template(`<div class="ant-mt-12px">`),
|
|
9
|
+
_tmpl$4 = /*#__PURE__*/template(`<div><div class="ant-text-[rgba(0,0,0,.88)] ant-text-16px ant-font-600 ant-mb-8px"></div><div class="ant-grow">`),
|
|
10
|
+
_tmpl$5 = /*#__PURE__*/template(`<div>`),
|
|
11
|
+
_tmpl$6 = /*#__PURE__*/template(`<span class="i-ant-design:exclamation-circle ant-text-22px ant-mr-12px ant-text-[var(--warning-color)]">`),
|
|
12
|
+
_tmpl$7 = /*#__PURE__*/template(`<div class="ant-ml-34px">`);
|
|
13
|
+
function Modal(_props) {
|
|
14
|
+
const props = mergeProps({
|
|
15
|
+
footer: true
|
|
16
|
+
}, _props);
|
|
17
|
+
const [open, setOpen] = createSignal(props.defaultOpen ?? false);
|
|
18
|
+
const [hide, setHide] = createSignal(false);
|
|
19
|
+
const instance = {
|
|
20
|
+
open() {
|
|
21
|
+
setOpen(true);
|
|
22
|
+
setHide(false);
|
|
23
|
+
},
|
|
24
|
+
close() {
|
|
25
|
+
untrack(() => {
|
|
26
|
+
if (props.destroyOnClose) {
|
|
27
|
+
setOpen(false);
|
|
28
|
+
} else {
|
|
29
|
+
setHide(true);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
untrack(() => {
|
|
35
|
+
if (typeof props.ref === 'function') {
|
|
36
|
+
props.ref?.(instance);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const close = () => {
|
|
40
|
+
instance.close();
|
|
41
|
+
props.afterClose?.();
|
|
42
|
+
};
|
|
43
|
+
const [confirmLoading, setConfirmLoading] = createSignal(false);
|
|
44
|
+
return createComponent(Show, {
|
|
45
|
+
get when() {
|
|
46
|
+
return open();
|
|
47
|
+
},
|
|
48
|
+
get children() {
|
|
49
|
+
return createComponent(Portal, {
|
|
50
|
+
get children() {
|
|
51
|
+
const _el$ = _tmpl$5();
|
|
52
|
+
_el$.$$click = () => {
|
|
53
|
+
if (props.maskClosable ?? true) {
|
|
54
|
+
close();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
insert(_el$, createComponent(Show, {
|
|
58
|
+
get when() {
|
|
59
|
+
return typeof props.modalRender !== 'function';
|
|
60
|
+
},
|
|
61
|
+
get fallback() {
|
|
62
|
+
return props.modalRender();
|
|
63
|
+
},
|
|
64
|
+
get children() {
|
|
65
|
+
const _el$2 = _tmpl$4(),
|
|
66
|
+
_el$4 = _el$2.firstChild,
|
|
67
|
+
_el$5 = _el$4.nextSibling;
|
|
68
|
+
_el$2.$$click = e => {
|
|
69
|
+
e.stopPropagation();
|
|
70
|
+
};
|
|
71
|
+
insert(_el$2, createComponent(Show, {
|
|
72
|
+
get when() {
|
|
73
|
+
return props.closeIcon !== false;
|
|
74
|
+
},
|
|
75
|
+
get children() {
|
|
76
|
+
return createComponent(Button, {
|
|
77
|
+
type: "text",
|
|
78
|
+
get ["class"]() {
|
|
79
|
+
return cs('ant-rm-size-btn !ant-w-22px !ant-h-22px !ant-flex !ant-justify-center !ant-items-center ant-text-center ant-text-18px !ant-absolute !ant-top-16px !ant-right-16px ant-z-1000 ant-text-[rgba(0,0,0,.45)] hover:!ant-text-[rgba(0,0,0,.88)]');
|
|
80
|
+
},
|
|
81
|
+
onClick: close,
|
|
82
|
+
get children() {
|
|
83
|
+
return _tmpl$();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}), _el$4);
|
|
88
|
+
insert(_el$4, () => props.title);
|
|
89
|
+
insert(_el$5, () => props.children);
|
|
90
|
+
insert(_el$2, createComponent(Show, {
|
|
91
|
+
get when() {
|
|
92
|
+
return props.footer !== false;
|
|
93
|
+
},
|
|
94
|
+
get children() {
|
|
95
|
+
const _el$6 = _tmpl$3();
|
|
96
|
+
insert(_el$6, createComponent(Show, {
|
|
97
|
+
get when() {
|
|
98
|
+
return typeof props.footer !== 'function';
|
|
99
|
+
},
|
|
100
|
+
get fallback() {
|
|
101
|
+
return memo(() => typeof props.footer === 'function')() && props.footer(instance);
|
|
102
|
+
},
|
|
103
|
+
get children() {
|
|
104
|
+
const _el$7 = _tmpl$2();
|
|
105
|
+
insert(_el$7, createComponent(Button, {
|
|
106
|
+
onClick: close,
|
|
107
|
+
children: "\u53D6\u6D88"
|
|
108
|
+
}), null);
|
|
109
|
+
insert(_el$7, createComponent(Button, {
|
|
110
|
+
type: "primary",
|
|
111
|
+
get loading() {
|
|
112
|
+
return confirmLoading();
|
|
113
|
+
},
|
|
114
|
+
onClick: async () => {
|
|
115
|
+
if (!props.onOk) return;
|
|
116
|
+
let res = props.onOk?.();
|
|
117
|
+
if (res instanceof Promise) {
|
|
118
|
+
setConfirmLoading(true);
|
|
119
|
+
res = await res.finally(() => setConfirmLoading(false));
|
|
120
|
+
}
|
|
121
|
+
if (res) {
|
|
122
|
+
instance.close();
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
children: "\u786E\u5B9A"
|
|
126
|
+
}), null);
|
|
127
|
+
return _el$7;
|
|
128
|
+
}
|
|
129
|
+
}));
|
|
130
|
+
return _el$6;
|
|
131
|
+
}
|
|
132
|
+
}), null);
|
|
133
|
+
effect(_p$ => {
|
|
134
|
+
const _v$ = cs('ant-absolute ant-px-24px ant-py-20px ant-rounded-8px ant-overflow-hidden ant-bg-white ant-flex ant-flex-col',
|
|
135
|
+
// '!ant-[animation-duration:.5s]',
|
|
136
|
+
!props.centered && 'ant-top-100px'),
|
|
137
|
+
_v$2 = props.width ?? '520px',
|
|
138
|
+
_v$3 = props.height;
|
|
139
|
+
_v$ !== _p$._v$ && className(_el$2, _p$._v$ = _v$);
|
|
140
|
+
_v$2 !== _p$._v$2 && ((_p$._v$2 = _v$2) != null ? _el$2.style.setProperty("width", _v$2) : _el$2.style.removeProperty("width"));
|
|
141
|
+
_v$3 !== _p$._v$3 && ((_p$._v$3 = _v$3) != null ? _el$2.style.setProperty("height", _v$3) : _el$2.style.removeProperty("height"));
|
|
142
|
+
return _p$;
|
|
143
|
+
}, {
|
|
144
|
+
_v$: undefined,
|
|
145
|
+
_v$2: undefined,
|
|
146
|
+
_v$3: undefined
|
|
147
|
+
});
|
|
148
|
+
return _el$2;
|
|
149
|
+
}
|
|
150
|
+
}));
|
|
151
|
+
effect(_p$ => {
|
|
152
|
+
const _v$4 = cs('ant-fixed ant-justify-center ant-inset-0 ant-bg-[rgba(0,0,0,.45)] ant-flex ant-z-1000', props.centered && 'ant-items-center'),
|
|
153
|
+
_v$5 = hide() ? 'none' : undefined;
|
|
154
|
+
_v$4 !== _p$._v$4 && className(_el$, _p$._v$4 = _v$4);
|
|
155
|
+
_v$5 !== _p$._v$5 && ((_p$._v$5 = _v$5) != null ? _el$.style.setProperty("display", _v$5) : _el$.style.removeProperty("display"));
|
|
156
|
+
return _p$;
|
|
157
|
+
}, {
|
|
158
|
+
_v$4: undefined,
|
|
159
|
+
_v$5: undefined
|
|
160
|
+
});
|
|
161
|
+
return _el$;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
Modal.warning = props => {
|
|
168
|
+
const div = document.createElement('div');
|
|
169
|
+
document.body.appendChild(div);
|
|
170
|
+
const dispose = render(() => createComponent(Modal, mergeProps$1({
|
|
171
|
+
width: "416px",
|
|
172
|
+
maskClosable: false,
|
|
173
|
+
closeIcon: false
|
|
174
|
+
}, props, {
|
|
175
|
+
get title() {
|
|
176
|
+
return [_tmpl$6(), memo(() => props.title)];
|
|
177
|
+
},
|
|
178
|
+
get children() {
|
|
179
|
+
return (() => {
|
|
180
|
+
const _el$9 = _tmpl$7();
|
|
181
|
+
insert(_el$9, () => props.children);
|
|
182
|
+
return _el$9;
|
|
183
|
+
})();
|
|
184
|
+
},
|
|
185
|
+
defaultOpen: true,
|
|
186
|
+
afterClose: () => {
|
|
187
|
+
document.body.removeChild(div);
|
|
188
|
+
dispose();
|
|
189
|
+
props.afterClose?.();
|
|
190
|
+
}
|
|
191
|
+
})), div);
|
|
192
|
+
};
|
|
193
|
+
delegateEvents(["click"]);
|
|
194
|
+
|
|
195
|
+
export { Modal as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Component, type JSXElement } from 'solid-js';
|
|
2
|
+
import { type TooltipProps } from './Tooltip';
|
|
3
|
+
interface PopconfirmProps extends Pick<TooltipProps, 'placement' | 'arrow'> {
|
|
4
|
+
title?: JSXElement;
|
|
5
|
+
content?: JSXElement;
|
|
6
|
+
children: JSXElement;
|
|
7
|
+
onCancel?: () => void;
|
|
8
|
+
onConfirm?: () => void;
|
|
9
|
+
/**
|
|
10
|
+
* 确认按钮文字
|
|
11
|
+
* 默认:确定
|
|
12
|
+
*/
|
|
13
|
+
okText?: string;
|
|
14
|
+
/**
|
|
15
|
+
* 取消按钮文字
|
|
16
|
+
* 默认:取消
|
|
17
|
+
*/
|
|
18
|
+
cancelText?: string;
|
|
19
|
+
}
|
|
20
|
+
declare const Popconfirm: Component<PopconfirmProps>;
|
|
21
|
+
export default Popconfirm;
|
package/es/Popconfirm.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createComponent, mergeProps as mergeProps$1, insert, template } from 'solid-js/web';
|
|
2
|
+
import { mergeProps, splitProps, createSignal, untrack } from 'solid-js';
|
|
3
|
+
import Button from './Button.js';
|
|
4
|
+
import Tooltip from './Tooltip.js';
|
|
5
|
+
|
|
6
|
+
const _tmpl$ = /*#__PURE__*/template(`<div><div class="ant-mb-8px ant-flex ant-items-center"><span class="i-ant-design:exclamation-circle-fill ant-text-#faad14"></span><span class="ant-ml-8px ant-text-[rgba(0,0,0,0.88)] ant-font-600"></span></div><div class="ant-ml-22px ant-mb-8px ant-text-[rgba(0,0,0,0.88)]"></div><div class="ant-text-right">`);
|
|
7
|
+
const Popconfirm = props => {
|
|
8
|
+
const mergedProps = mergeProps({
|
|
9
|
+
okText: '确定',
|
|
10
|
+
cancelText: '取消'
|
|
11
|
+
}, props);
|
|
12
|
+
const [tooltipProps] = splitProps(props, ['placement', 'arrow']);
|
|
13
|
+
const [open, setOpen] = createSignal(false);
|
|
14
|
+
return createComponent(Tooltip, mergeProps$1({
|
|
15
|
+
mode: "light",
|
|
16
|
+
trigger: "click",
|
|
17
|
+
get open() {
|
|
18
|
+
return open();
|
|
19
|
+
},
|
|
20
|
+
onOpenChange: setOpen,
|
|
21
|
+
get content() {
|
|
22
|
+
return (() => {
|
|
23
|
+
const _el$ = _tmpl$(),
|
|
24
|
+
_el$2 = _el$.firstChild,
|
|
25
|
+
_el$3 = _el$2.firstChild,
|
|
26
|
+
_el$4 = _el$3.nextSibling,
|
|
27
|
+
_el$5 = _el$2.nextSibling,
|
|
28
|
+
_el$6 = _el$5.nextSibling;
|
|
29
|
+
insert(_el$4, () => mergedProps.title);
|
|
30
|
+
insert(_el$5, () => mergedProps.content);
|
|
31
|
+
insert(_el$6, createComponent(Button, {
|
|
32
|
+
"class": "ant-ml-8px",
|
|
33
|
+
size: "small",
|
|
34
|
+
onClick: () => {
|
|
35
|
+
setOpen(false);
|
|
36
|
+
untrack(() => mergedProps.onCancel?.());
|
|
37
|
+
},
|
|
38
|
+
get children() {
|
|
39
|
+
return mergedProps.cancelText;
|
|
40
|
+
}
|
|
41
|
+
}), null);
|
|
42
|
+
insert(_el$6, createComponent(Button, {
|
|
43
|
+
"class": "ant-ml-8px",
|
|
44
|
+
type: "primary",
|
|
45
|
+
size: "small",
|
|
46
|
+
onClick: () => {
|
|
47
|
+
setOpen(false);
|
|
48
|
+
untrack(() => mergedProps.onConfirm?.());
|
|
49
|
+
},
|
|
50
|
+
get children() {
|
|
51
|
+
return mergedProps.okText;
|
|
52
|
+
}
|
|
53
|
+
}), null);
|
|
54
|
+
return _el$;
|
|
55
|
+
})();
|
|
56
|
+
}
|
|
57
|
+
}, tooltipProps, {
|
|
58
|
+
get children() {
|
|
59
|
+
return mergedProps.children;
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export { Popconfirm as default };
|
package/es/Popover.d.ts
ADDED
package/es/Popover.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createComponent, mergeProps, insert, template } from 'solid-js/web';
|
|
2
|
+
import { Show } from 'solid-js';
|
|
3
|
+
import Tooltip, { Content } from './Tooltip.js';
|
|
4
|
+
|
|
5
|
+
const _tmpl$ = /*#__PURE__*/template(`<div class="ant-mb-8px ant-flex ant-items-center"><span class="ant-text-[rgba(0,0,0,0.88)] ant-font-600">`),
|
|
6
|
+
_tmpl$2 = /*#__PURE__*/template(`<div><div class="ant-text-[rgba(0,0,0,0.88)]">`);
|
|
7
|
+
const Popover = props => {
|
|
8
|
+
return createComponent(Tooltip, mergeProps({
|
|
9
|
+
mode: "light"
|
|
10
|
+
}, props, {
|
|
11
|
+
content: close => (() => {
|
|
12
|
+
const _el$ = _tmpl$2(),
|
|
13
|
+
_el$4 = _el$.firstChild;
|
|
14
|
+
insert(_el$, createComponent(Show, {
|
|
15
|
+
get when() {
|
|
16
|
+
return props.title;
|
|
17
|
+
},
|
|
18
|
+
get children() {
|
|
19
|
+
const _el$2 = _tmpl$(),
|
|
20
|
+
_el$3 = _el$2.firstChild;
|
|
21
|
+
insert(_el$3, () => props.title);
|
|
22
|
+
return _el$2;
|
|
23
|
+
}
|
|
24
|
+
}), _el$4);
|
|
25
|
+
insert(_el$4, createComponent(Content, {
|
|
26
|
+
get content() {
|
|
27
|
+
return props.content;
|
|
28
|
+
},
|
|
29
|
+
close: close
|
|
30
|
+
}));
|
|
31
|
+
return _el$;
|
|
32
|
+
})()
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { Popover as default };
|
package/es/Progress.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare const _default: import("solid-js").Component<Omit<Omit<import("antd").ProgressProps & import("react").RefAttributes<HTMLDivElement>, "className"> & {
|
|
3
|
+
class?: string | undefined;
|
|
4
|
+
}, "children"> & {
|
|
5
|
+
children?: import("solid-js").JSX.Element;
|
|
6
|
+
}>;
|
|
7
|
+
export default _default;
|