antd-solid 0.0.7 → 0.0.9

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.
Files changed (102) hide show
  1. package/dist/index.esm.js +0 -13
  2. package/dist/index.umd.js +1 -1
  3. package/es/Button.d.ts +19 -0
  4. package/es/Button.js +73 -0
  5. package/es/Collapse/index.d.ts +16 -0
  6. package/es/Collapse/index.js +87 -0
  7. package/es/ColorPicker.d.ts +8 -0
  8. package/es/ColorPicker.js +6 -0
  9. package/es/Compact.d.ts +12 -0
  10. package/es/Compact.js +17 -0
  11. package/es/DatePicker.d.ts +19 -0
  12. package/es/DatePicker.js +9 -0
  13. package/es/Empty/PRESENTED_IMAGE_SIMPLE.d.ts +3 -0
  14. package/es/Empty/PRESENTED_IMAGE_SIMPLE.js +14 -0
  15. package/es/Empty/assets/EmptySvg.d.ts +2 -0
  16. package/es/Empty/assets/EmptySvg.js +6 -0
  17. package/es/Empty/assets/SimpleEmptySvg.d.ts +2 -0
  18. package/es/Empty/assets/SimpleEmptySvg.js +6 -0
  19. package/es/Empty/index.d.ts +5 -0
  20. package/es/Empty/index.js +16 -0
  21. package/es/Image.d.ts +9 -0
  22. package/es/Image.js +22 -0
  23. package/es/Input.d.ts +29 -0
  24. package/es/Input.js +144 -0
  25. package/es/InputNumber.d.ts +11 -0
  26. package/es/InputNumber.js +92 -0
  27. package/es/InputNumber.test.d.ts +1 -0
  28. package/es/InputNumber.test.js +42 -0
  29. package/es/Modal.d.ts +47 -0
  30. package/es/Modal.js +195 -0
  31. package/es/Popconfirm.d.ts +21 -0
  32. package/es/Popconfirm.js +64 -0
  33. package/es/Popover.d.ts +7 -0
  34. package/es/Popover.js +36 -0
  35. package/es/Progress.d.ts +7 -0
  36. package/es/Progress.js +6 -0
  37. package/es/Radio.d.ts +27 -0
  38. package/es/Radio.js +89 -0
  39. package/es/Result.d.ts +10 -0
  40. package/es/Result.js +29 -0
  41. package/es/Segmented/index.d.ts +21 -0
  42. package/es/Segmented/index.js +72 -0
  43. package/es/Select.d.ts +16 -0
  44. package/es/Select.js +113 -0
  45. package/es/Skeleton.d.ts +9 -0
  46. package/es/Skeleton.js +9 -0
  47. package/es/Spin.d.ts +9 -0
  48. package/es/Spin.js +22 -0
  49. package/es/Switch.d.ts +8 -0
  50. package/es/Switch.js +30 -0
  51. package/es/Table.d.ts +11 -0
  52. package/es/Table.js +57 -0
  53. package/es/Tabs.d.ts +17 -0
  54. package/es/Tabs.js +117 -0
  55. package/es/Timeline.d.ts +13 -0
  56. package/es/Timeline.js +30 -0
  57. package/es/Tooltip.d.ts +34 -0
  58. package/es/Tooltip.js +302 -0
  59. package/es/Tree.d.ts +28 -0
  60. package/es/Tree.js +198 -0
  61. package/es/Upload.d.ts +11 -0
  62. package/es/Upload.js +6 -0
  63. package/es/form/Form.d.ts +18 -0
  64. package/es/form/Form.js +70 -0
  65. package/es/form/FormItem.d.ts +19 -0
  66. package/es/form/FormItem.js +141 -0
  67. package/es/form/context.d.ts +12 -0
  68. package/es/form/context.js +5 -0
  69. package/es/form/index.d.ts +8 -0
  70. package/es/form/index.js +7 -0
  71. package/es/hooks/createControllableValue.d.ts +16 -0
  72. package/es/hooks/createControllableValue.js +41 -0
  73. package/es/hooks/createUpdateEffect.d.ts +5 -0
  74. package/es/hooks/createUpdateEffect.js +12 -0
  75. package/es/hooks/index.d.ts +2 -0
  76. package/es/hooks/index.js +2 -0
  77. package/es/hooks/useClickAway.d.ts +2 -0
  78. package/es/hooks/useClickAway.js +17 -0
  79. package/es/hooks/useSize.d.ts +5 -0
  80. package/es/hooks/useSize.js +22 -0
  81. package/es/index.d.ts +42 -0
  82. package/es/index.js +29 -0
  83. package/es/types/index.d.ts +3 -0
  84. package/es/types/index.js +1 -0
  85. package/es/utils/EventEmitter.d.ts +7 -0
  86. package/es/utils/EventEmitter.js +13 -0
  87. package/es/utils/ReactToSolid.d.ts +8 -0
  88. package/es/utils/ReactToSolid.js +30 -0
  89. package/es/utils/SolidToReact.d.ts +8 -0
  90. package/es/utils/SolidToReact.js +23 -0
  91. package/es/utils/array.d.ts +15 -0
  92. package/es/utils/array.js +19 -0
  93. package/es/utils/component.d.ts +31 -0
  94. package/es/utils/component.js +68 -0
  95. package/es/utils/solid.d.ts +15 -0
  96. package/es/utils/solid.js +32 -0
  97. package/es/utils/zh_CN.d.ts +2 -0
  98. package/es/utils/zh_CN.js +236 -0
  99. package/package.json +6 -4
  100. package/src/DatePicker.tsx +20 -12
  101. package/src/Tooltip.tsx +0 -15
  102. /package/{dist → css}/index.css +0 -0
@@ -0,0 +1,14 @@
1
+ import { insert, createComponent, template } from 'solid-js/web';
2
+ import EmptySvg from './assets/SimpleEmptySvg.js';
3
+
4
+ const _tmpl$ = /*#__PURE__*/template(`<div class="ant-my-[var(--ant-margin-xl)] ant-mx-[var(--ant-margin-xs)]"><div class="ant-mb-[var(--ant-margin-xs)] ant-flex ant-justify-center"></div><div class="ant-text-[var(--ant-color-text-disabled)] ant-text-center">暂无数据`);
5
+ const PRESENTED_IMAGE_SIMPLE = () => {
6
+ return (() => {
7
+ const _el$ = _tmpl$(),
8
+ _el$2 = _el$.firstChild;
9
+ insert(_el$2, createComponent(EmptySvg, {}));
10
+ return _el$;
11
+ })();
12
+ };
13
+
14
+ export { PRESENTED_IMAGE_SIMPLE as default };
@@ -0,0 +1,2 @@
1
+ declare const EmptySvg: () => import("solid-js").JSX.Element;
2
+ export default EmptySvg;
@@ -0,0 +1,6 @@
1
+ import { template } from 'solid-js/web';
2
+
3
+ const _tmpl$ = /*#__PURE__*/template(`<svg width="184" height="100" viewBox="0 0 184 152" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><g transform="translate(24 31.67)"><ellipse fill-opacity=".8" fill="#F5F5F7" cx="67.797" cy="106.89" rx="67.797" ry="12.668"></ellipse><path d="M122.034 69.674L98.109 40.229c-1.148-1.386-2.826-2.225-4.593-2.225h-51.44c-1.766 0-3.444.839-4.592 2.225L13.56 69.674v15.383h108.475V69.674z" fill="#AEB8C2"></path><path d="M101.537 86.214L80.63 61.102c-1.001-1.207-2.507-1.867-4.048-1.867H31.724c-1.54 0-3.047.66-4.048 1.867L6.769 86.214v13.792h94.768V86.214z" fill="url(#linearGradient-1)" transform="translate(13.56)"></path><path d="M33.83 0h67.933a4 4 0 0 1 4 4v93.344a4 4 0 0 1-4 4H33.83a4 4 0 0 1-4-4V4a4 4 0 0 1 4-4z" fill="#F5F5F7"></path><path d="M42.678 9.953h50.237a2 2 0 0 1 2 2V36.91a2 2 0 0 1-2 2H42.678a2 2 0 0 1-2-2V11.953a2 2 0 0 1 2-2zM42.94 49.767h49.713a2.262 2.262 0 1 1 0 4.524H42.94a2.262 2.262 0 0 1 0-4.524zM42.94 61.53h49.713a2.262 2.262 0 1 1 0 4.525H42.94a2.262 2.262 0 0 1 0-4.525zM121.813 105.032c-.775 3.071-3.497 5.36-6.735 5.36H20.515c-3.238 0-5.96-2.29-6.734-5.36a7.309 7.309 0 0 1-.222-1.79V69.675h26.318c2.907 0 5.25 2.448 5.25 5.42v.04c0 2.971 2.37 5.37 5.277 5.37h34.785c2.907 0 5.277-2.421 5.277-5.393V75.1c0-2.972 2.343-5.426 5.25-5.426h26.318v33.569c0 .617-.077 1.216-.221 1.789z" fill="#DCE0E6"></path></g><path d="M149.121 33.292l-6.83 2.65a1 1 0 0 1-1.317-1.23l1.937-6.207c-2.589-2.944-4.109-6.534-4.109-10.408C138.802 8.102 148.92 0 161.402 0 173.881 0 184 8.102 184 18.097c0 9.995-10.118 18.097-22.599 18.097-4.528 0-8.744-1.066-12.28-2.902z" fill="#DCE0E6"></path><g transform="translate(149.65 15.383)" fill="#FFF"><ellipse cx="20.654" cy="3.167" rx="2.849" ry="2.815"></ellipse><path d="M5.698 5.63H0L2.898.704zM9.259.704h4.985V5.63H9.259z">`);
4
+ const EmptySvg = () => _tmpl$();
5
+
6
+ export { EmptySvg as default };
@@ -0,0 +1,2 @@
1
+ declare const EmptySvg: () => import("solid-js").JSX.Element;
2
+ export default EmptySvg;
@@ -0,0 +1,6 @@
1
+ import { template } from 'solid-js/web';
2
+
3
+ const _tmpl$ = /*#__PURE__*/template(`<svg width="64" height="41" viewBox="0 0 64 41" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 1)" fill="none" fill-rule="evenodd"><ellipse fill="#f5f5f5" cx="32" cy="33" rx="32" ry="7"></ellipse><g fill-rule="nonzero" stroke="#d9d9d9"><path d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path><path d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z" fill="#fafafa">`);
4
+ const EmptySvg = () => _tmpl$();
5
+
6
+ export { EmptySvg as default };
@@ -0,0 +1,5 @@
1
+ import { type Component } from 'solid-js';
2
+ declare const Empty: Component & {
3
+ PRESENTED_IMAGE_SIMPLE: Component;
4
+ };
5
+ export default Empty;
@@ -0,0 +1,16 @@
1
+ import { insert, createComponent, template } from 'solid-js/web';
2
+ import PRESENTED_IMAGE_SIMPLE from './PRESENTED_IMAGE_SIMPLE.js';
3
+ import EmptySvg from './assets/EmptySvg.js';
4
+
5
+ const _tmpl$ = /*#__PURE__*/template(`<div><div class="ant-mb-[var(--ant-margin-xs)] ant-flex ant-justify-center"></div><div class="ant-text-[var(--ant-color-text)] ant-text-center">暂无数据`);
6
+ const Empty = () => {
7
+ return (() => {
8
+ const _el$ = _tmpl$(),
9
+ _el$2 = _el$.firstChild;
10
+ insert(_el$2, createComponent(EmptySvg, {}));
11
+ return _el$;
12
+ })();
13
+ };
14
+ Empty.PRESENTED_IMAGE_SIMPLE = PRESENTED_IMAGE_SIMPLE;
15
+
16
+ export { Empty as default };
package/es/Image.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { type JSXElement } from 'solid-js';
2
+ declare const _Image: import("solid-js").Component<Omit<import("antd").ImageProps, "className"> & {
3
+ class?: string | undefined;
4
+ }>;
5
+ type ImageProps = Omit<Parameters<typeof _Image>[0], 'placeholder'> & {
6
+ placeholder?: JSXElement;
7
+ };
8
+ declare function Image(_props: ImageProps): import("solid-js").JSX.Element;
9
+ export default Image;
package/es/Image.js ADDED
@@ -0,0 +1,22 @@
1
+ import { createComponent, mergeProps, template } from 'solid-js/web';
2
+ import { Image as Image$1 } from 'antd';
3
+ import { replaceClassName, reactToSolidComponent, configProvider } from './utils/component.js';
4
+ import { solidToReact } from './utils/solid.js';
5
+ import { createMemo } from 'solid-js';
6
+ import { mapValues } from 'lodash-es';
7
+
8
+ const _tmpl$ = /*#__PURE__*/template(`<div class="ant-inline-flex">`);
9
+ const _Image = replaceClassName(reactToSolidComponent(configProvider(Image$1), () => _tmpl$()));
10
+ function Image(_props) {
11
+ const props = createMemo(() => mapValues(_props, (value, key) => {
12
+ switch (key) {
13
+ case 'placeholder':
14
+ return solidToReact(value);
15
+ default:
16
+ return value;
17
+ }
18
+ }));
19
+ return createComponent(_Image, mergeProps(props));
20
+ }
21
+
22
+ export { Image as default };
package/es/Input.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ import type { JSX, JSXElement, Component } from 'solid-js';
2
+ type CommonInputProps<T extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement> = JSX.CustomAttributes<T> & {
3
+ textarea?: boolean;
4
+ defaultValue?: string | undefined;
5
+ value?: string | undefined;
6
+ addonBefore?: JSXElement;
7
+ addonAfter?: JSXElement;
8
+ prefix?: JSXElement;
9
+ suffix?: JSXElement;
10
+ placeholder?: string;
11
+ /**
12
+ * 仅供 InputNumber 使用
13
+ */
14
+ actions?: JSXElement;
15
+ /**
16
+ * 设置校验状态
17
+ */
18
+ status?: 'error' | 'warning';
19
+ onChange?: JSX.InputEventHandler<T, InputEvent>;
20
+ onPressEnter?: JSX.EventHandler<T, KeyboardEvent>;
21
+ onKeyDown?: JSX.EventHandler<T, KeyboardEvent>;
22
+ };
23
+ export declare function CommonInput<T extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement>(props: CommonInputProps<T> & Omit<JSX.InputHTMLAttributes<T>, 'onChange' | 'onInput' | 'onKeyDown'>): JSX.Element;
24
+ export type InputProps = Omit<CommonInputProps, 'actions' | 'textarea'> & Omit<JSX.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'onInput' | 'onKeyDown'>;
25
+ export type TextAreaProps = Omit<CommonInputProps<HTMLTextAreaElement>, 'prefix' | 'suffix' | 'textarea'> & Omit<JSX.TextareaHTMLAttributes<HTMLTextAreaElement>, 'actions' | 'onChange' | 'onInput' | 'onKeyDown'>;
26
+ declare const Input: Component<InputProps> & {
27
+ TextArea: Component<TextAreaProps>;
28
+ };
29
+ export default Input;
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 };