antd-solid 0.0.11 → 0.0.13
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/css/index.css +10 -73
- package/dist/index.esm.js +7802 -2378
- package/dist/index.umd.js +1 -1
- package/es/Alert/index.d.ts +10 -0
- package/es/Alert/index.js +26 -0
- package/es/Button/index.d.ts +32 -0
- package/es/Button/index.js +123 -0
- package/es/Button/index.scss.js +6 -0
- package/es/Checkbox/Group.d.ts +19 -0
- package/es/Checkbox/Group.js +49 -0
- package/es/Checkbox/index.d.ts +15 -0
- package/es/Checkbox/index.js +60 -0
- package/es/CodeInput/index.d.ts +18 -0
- package/es/CodeInput/index.js +72 -0
- package/es/Collapse/Item.d.ts +46 -0
- package/es/Collapse/Item.js +130 -0
- package/es/Collapse/context.d.ts +5 -0
- package/es/Collapse/context.js +8 -0
- package/es/Collapse/index.d.ts +25 -10
- package/es/Collapse/index.js +95 -74
- package/es/Collapse/utils.d.ts +8 -0
- package/es/Collapse/utils.js +35 -0
- package/es/ColorPicker/ColorPickerInput.d.ts +3 -0
- package/es/ColorPicker/ColorPickerInput.js +250 -0
- package/es/ColorPicker/ColorPickerSelect.d.ts +3 -0
- package/es/ColorPicker/ColorPickerSelect.js +71 -0
- package/es/ColorPicker/ColorPickerSlider.d.ts +3 -0
- package/es/ColorPicker/ColorPickerSlider.js +115 -0
- package/es/ColorPicker/color.d.ts +24 -0
- package/es/ColorPicker/color.js +63 -0
- package/es/ColorPicker/context.d.ts +9 -0
- package/es/ColorPicker/context.js +5 -0
- package/es/ColorPicker/index.d.ts +31 -0
- package/es/ColorPicker/index.js +139 -0
- package/es/Command/context.d.ts +9 -0
- package/es/Command/context.js +11 -0
- package/es/Command/createCommand.d.ts +17 -0
- package/es/Command/createCommand.js +112 -0
- package/es/Command/index.d.ts +7 -0
- package/es/Command/index.js +9 -0
- package/es/Command/useCommandProps.d.ts +13 -0
- package/es/Command/useCommandProps.js +28 -0
- package/es/Compact/CompactContextIsolator.d.ts +3 -0
- package/es/Compact/CompactContextIsolator.js +15 -0
- package/es/Compact/context.d.ts +4 -0
- package/es/Compact/context.js +7 -0
- package/es/Compact/index.d.ts +14 -0
- package/es/Compact/index.js +32 -0
- package/es/Compact/index.scss.js +6 -0
- package/es/ConfigProvider/context.d.ts +11 -0
- package/es/ConfigProvider/context.js +15 -0
- package/es/ConfigProvider/dark/colorAlgorithm.d.ts +2 -0
- package/es/ConfigProvider/dark/colorAlgorithm.js +9 -0
- package/es/ConfigProvider/dark/colors.d.ts +3 -0
- package/es/ConfigProvider/dark/colors.js +47 -0
- package/es/ConfigProvider/dark/index.d.ts +2 -0
- package/es/ConfigProvider/dark/index.js +11 -0
- package/es/ConfigProvider/index.d.ts +32 -0
- package/es/ConfigProvider/index.js +44 -0
- package/es/ConfigProvider/light/colorAlgorithm.d.ts +2 -0
- package/es/ConfigProvider/light/colorAlgorithm.js +9 -0
- package/es/ConfigProvider/light/colors.d.ts +3 -0
- package/es/ConfigProvider/light/colors.js +45 -0
- package/es/ConfigProvider/light/index.d.ts +2 -0
- package/es/ConfigProvider/light/index.js +11 -0
- package/es/ConfigProvider/seed.d.ts +3 -0
- package/es/ConfigProvider/seed.js +22 -0
- package/es/ConfigProvider/types/index.d.ts +594 -0
- package/es/ConfigProvider/types/index.js +1 -0
- package/es/ConfigProvider/utils/genColorMapToken.d.ts +7 -0
- package/es/ConfigProvider/utils/genColorMapToken.js +85 -0
- package/es/ConfigProvider/utils/getAlphaColor.d.ts +2 -0
- package/es/ConfigProvider/utils/getAlphaColor.js +44 -0
- package/es/ConfigProvider/utils/index.d.ts +3 -0
- package/es/ConfigProvider/utils/index.js +181 -0
- package/es/ContextMenu/index.d.ts +8 -0
- package/es/ContextMenu/index.js +99 -0
- package/es/Cursor/index.d.ts +6 -0
- package/es/Cursor/index.js +71 -0
- package/es/DelayShow/index.d.ts +16 -0
- package/es/DelayShow/index.js +27 -0
- package/es/Divider/index.d.ts +17 -0
- package/es/Divider/index.js +71 -0
- package/es/Drawer/index.d.ts +20 -16
- package/es/Drawer/index.js +162 -112
- package/es/Drawer/index.scss.js +1 -1
- package/es/Dropdown/index.d.ts +16 -0
- package/es/Dropdown/index.js +47 -0
- package/es/Element/index.d.ts +10 -0
- package/es/Element/index.js +42 -0
- package/es/Empty/PRESENTED_IMAGE_SIMPLE.d.ts +2 -1
- package/es/Empty/PRESENTED_IMAGE_SIMPLE.js +25 -9
- package/es/Empty/assets/EmptySvg.js +1 -1
- package/es/Empty/assets/SimpleEmptySvg.js +1 -1
- package/es/Empty/index.d.ts +9 -3
- package/es/Empty/index.js +24 -9
- package/es/Form/Form.d.ts +8 -5
- package/es/Form/Form.js +50 -34
- package/es/Form/FormItem.d.ts +10 -5
- package/es/Form/FormItem.js +121 -104
- package/es/Form/context.d.ts +9 -9
- package/es/Form/context.js +4 -2
- package/es/Fragment/index.d.ts +4 -0
- package/es/Fragment/index.js +7 -0
- package/es/Image/index.d.ts +10 -0
- package/es/Image/index.js +37 -0
- package/es/Input/TextArea.d.ts +23 -0
- package/es/Input/TextArea.js +84 -0
- package/es/Input/index.d.ts +44 -0
- package/es/Input/index.js +213 -0
- package/es/Input/index.scss.js +6 -0
- package/es/InputNumber/index.d.ts +30 -0
- package/es/InputNumber/index.js +122 -0
- package/es/{InputNumber.test.js → InputNumber/index.test.js} +2 -1
- package/es/Menu/InternalMenu.d.ts +22 -0
- package/es/Menu/InternalMenu.js +196 -0
- package/es/Menu/index.d.ts +75 -0
- package/es/Menu/index.js +64 -0
- package/es/Message/Message.d.ts +9 -0
- package/es/Message/Message.js +34 -0
- package/es/Message/index.d.ts +12 -0
- package/es/Message/index.js +80 -0
- package/es/Message/index.scss.js +6 -0
- package/es/Message/useMessage.d.ts +6 -0
- package/es/Message/useMessage.js +54 -0
- package/es/Modal/index.d.ts +73 -0
- package/es/Modal/index.js +237 -0
- package/es/Modal/index.scss.js +6 -0
- package/es/Modal/useModal.d.ts +5 -0
- package/es/Modal/useModal.js +51 -0
- package/es/Modal/warning.d.ts +5 -0
- package/es/Modal/warning.js +43 -0
- package/es/{Popconfirm.d.ts → Popconfirm/index.d.ts} +2 -2
- package/es/Popconfirm/index.js +62 -0
- package/es/{Popover.d.ts → Popover/index.d.ts} +2 -2
- package/es/{Popover.js → Popover/index.js} +7 -12
- package/es/Progress/Circle.d.ts +16 -0
- package/es/Progress/Circle.js +122 -0
- package/es/Progress/index.d.ts +6 -4
- package/es/Progress/index.js +75 -60
- package/es/Radio/Button.d.ts +7 -0
- package/es/Radio/Button.js +72 -0
- package/es/Radio/Group.d.ts +18 -0
- package/es/Radio/Group.js +57 -0
- package/es/Radio/index.d.ts +14 -0
- package/es/Radio/index.js +68 -0
- package/es/RangeInput/index.d.ts +23 -0
- package/es/RangeInput/index.js +208 -0
- package/es/Result/index.js +49 -0
- package/es/Segmented/index.d.ts +10 -7
- package/es/Segmented/index.js +54 -53
- package/es/Select/index.d.ts +17 -0
- package/es/Select/index.js +75 -0
- package/es/SelectInput/index.d.ts +39 -0
- package/es/SelectInput/index.js +245 -0
- package/es/Slider/index.d.ts +47 -0
- package/es/Slider/index.js +177 -0
- package/es/Space/index.d.ts +13 -0
- package/es/Space/index.js +16 -0
- package/es/Spin/index.d.ts +19 -0
- package/es/Spin/index.js +82 -0
- package/es/{Switch.d.ts → Switch/index.d.ts} +9 -0
- package/es/Switch/index.js +41 -0
- package/es/{Table.d.ts → Table/index.d.ts} +6 -2
- package/es/Table/index.js +71 -0
- package/es/Tabs/index.d.ts +49 -0
- package/es/Tabs/index.js +256 -0
- package/es/Timeline/index.js +31 -0
- package/es/Tooltip/context.d.ts +5 -0
- package/es/Tooltip/context.js +5 -0
- package/es/Tooltip/index.d.ts +64 -0
- package/es/Tooltip/index.js +499 -0
- package/es/Transformer/index.d.ts +88 -0
- package/es/Transformer/index.js +882 -0
- package/es/Tree/SingleLevelTree.d.ts +28 -0
- package/es/Tree/SingleLevelTree.js +299 -0
- package/es/Tree/index.d.ts +83 -0
- package/es/Tree/index.js +197 -0
- package/es/TreeFor/index.d.ts +31 -0
- package/es/TreeFor/index.js +80 -0
- package/es/TreeSelect/index.d.ts +26 -0
- package/es/TreeSelect/index.js +98 -0
- package/es/Upload/index.d.ts +64 -0
- package/es/Upload/index.js +112 -0
- package/es/assets/svg/ColorPickUp.d.ts +4 -0
- package/es/assets/svg/ColorPickUp.js +25 -0
- package/es/assets/svg/Crosshair.d.ts +7 -0
- package/es/assets/svg/Crosshair.js +51 -0
- package/es/assets/svg/Resize.d.ts +4 -0
- package/es/assets/svg/Resize.js +25 -0
- package/es/assets/svg/Rotate.d.ts +4 -0
- package/es/assets/svg/Rotate.js +20 -0
- package/es/assets/svg/RotateArrow.d.ts +4 -0
- package/es/assets/svg/RotateArrow.js +21 -0
- package/es/assets/svg/common.d.ts +2 -0
- package/es/assets/svg/common.js +9 -0
- package/es/hooks/createControllableValue.d.ts +1 -1
- package/es/hooks/createControllableValue.js +16 -17
- package/es/hooks/createTransition.d.ts +6 -2
- package/es/hooks/createTransition.js +12 -8
- package/es/hooks/useClickAway.d.ts +1 -1
- package/es/hooks/useClickAway.js +4 -3
- package/es/hooks/useComponentSize.d.ts +3 -0
- package/es/hooks/useComponentSize.js +12 -0
- package/es/hooks/useCounter.d.ts +12 -0
- package/es/hooks/useCounter.js +30 -0
- package/es/hooks/useFocus.d.ts +2 -0
- package/es/hooks/useFocus.js +24 -0
- package/es/hooks/useHover.d.ts +2 -0
- package/es/hooks/useHover.js +33 -0
- package/es/hooks/useLocale.d.ts +1 -0
- package/es/hooks/useLocale.js +11 -0
- package/es/hooks/useMouse.d.ts +1 -0
- package/es/hooks/useMouse.js +18 -0
- package/es/hooks/useScroll.d.ts +2 -0
- package/es/hooks/useScroll.js +29 -0
- package/es/hooks/useSize.d.ts +8 -2
- package/es/hooks/useSize.js +25 -13
- package/es/hooks/useVirtualList.d.ts +14 -0
- package/es/hooks/useVirtualList.js +45 -0
- package/es/index.d.ts +59 -8
- package/es/index.js +53 -23
- package/es/locale/en_US.d.ts +3 -0
- package/es/locale/en_US.js +9 -0
- package/es/locale/index.d.ts +5 -0
- package/es/locale/index.js +1 -0
- package/es/locale/zh_CN.d.ts +3 -0
- package/es/locale/zh_CN.js +9 -0
- package/es/types/index.d.ts +11 -2
- package/es/utils/animation.d.ts +6 -0
- package/es/utils/animation.js +20 -0
- package/es/utils/array.d.ts +2 -1
- package/es/utils/array.js +5 -1
- package/es/utils/domPoint.d.ts +7 -0
- package/es/utils/domPoint.js +11 -0
- package/es/utils/math.d.ts +17 -0
- package/es/utils/math.js +25 -0
- package/es/utils/number.d.ts +1 -0
- package/es/utils/number.js +14 -0
- package/es/utils/setupGlobalDrag.d.ts +10 -0
- package/es/utils/setupGlobalDrag.js +38 -0
- package/es/utils/solid.d.ts +2 -2
- package/es/utils/solid.js +7 -8
- package/package.json +10 -11
- package/es/Button.d.ts +0 -19
- package/es/Button.js +0 -73
- package/es/ColorPicker.d.ts +0 -8
- package/es/ColorPicker.js +0 -6
- package/es/Compact.d.ts +0 -12
- package/es/Compact.js +0 -17
- package/es/DatePicker.d.ts +0 -19
- package/es/DatePicker.js +0 -9
- package/es/Image.d.ts +0 -9
- package/es/Image.js +0 -22
- package/es/Input.d.ts +0 -29
- package/es/Input.js +0 -144
- package/es/InputNumber.d.ts +0 -11
- package/es/InputNumber.js +0 -92
- package/es/Modal.d.ts +0 -48
- package/es/Modal.js +0 -209
- package/es/Popconfirm.js +0 -64
- package/es/Radio.d.ts +0 -27
- package/es/Radio.js +0 -93
- package/es/Result.js +0 -29
- package/es/Select.d.ts +0 -16
- package/es/Select.js +0 -113
- package/es/Skeleton.d.ts +0 -9
- package/es/Skeleton.js +0 -9
- package/es/Spin.d.ts +0 -9
- package/es/Spin.js +0 -22
- package/es/Switch.js +0 -30
- package/es/Table.js +0 -57
- package/es/Tabs.d.ts +0 -17
- package/es/Tabs.js +0 -117
- package/es/Timeline.js +0 -30
- package/es/Tooltip.d.ts +0 -34
- package/es/Tooltip.js +0 -302
- package/es/Tree.d.ts +0 -28
- package/es/Tree.js +0 -198
- package/es/Upload.d.ts +0 -11
- package/es/Upload.js +0 -6
- package/es/hooks/createUpdateEffect.d.ts +0 -5
- package/es/hooks/createUpdateEffect.js +0 -12
- package/es/utils/EventEmitter.d.ts +0 -7
- package/es/utils/EventEmitter.js +0 -13
- package/es/utils/ReactToSolid.d.ts +0 -8
- package/es/utils/ReactToSolid.js +0 -30
- package/es/utils/SolidToReact.d.ts +0 -8
- package/es/utils/SolidToReact.js +0 -23
- package/es/utils/component.d.ts +0 -31
- package/es/utils/component.js +0 -68
- package/es/utils/zh_CN.d.ts +0 -2
- package/es/utils/zh_CN.js +0 -236
- package/src/Button.tsx +0 -128
- package/src/Collapse/index.tsx +0 -86
- package/src/ColorPicker.tsx +0 -11
- package/src/Compact.tsx +0 -15
- package/src/DatePicker.tsx +0 -30
- package/src/Drawer/index.scss +0 -53
- package/src/Drawer/index.tsx +0 -212
- 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/Form/Form.tsx +0 -94
- package/src/Form/FormItem.tsx +0 -141
- package/src/Form/context.ts +0 -16
- package/src/Form/index.ts +0 -13
- 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 -220
- package/src/Popconfirm.tsx +0 -75
- package/src/Popover.tsx +0 -30
- package/src/Progress/index.tsx +0 -73
- package/src/Radio.tsx +0 -142
- 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 -340
- package/src/Tree.tsx +0 -246
- package/src/Upload.tsx +0 -10
- package/src/hooks/createControllableValue.ts +0 -68
- package/src/hooks/createTransition.ts +0 -52
- 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 -47
- 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 -61
- package/src/utils/zh_CN.ts +0 -236
- /package/es/{InputNumber.test.d.ts → InputNumber/index.test.d.ts} +0 -0
- /package/es/{Result.d.ts → Result/index.d.ts} +0 -0
- /package/es/{Timeline.d.ts → Timeline/index.d.ts} +0 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { delegateEvents, createComponent, insert, effect, className, use, spread, mergeProps, template } from 'solid-js/web';
|
|
2
|
+
import { isNil, omit } from 'lodash-es';
|
|
3
|
+
import { useContext, splitProps, onMount, createMemo, Show } from 'solid-js';
|
|
4
|
+
import cs from 'classnames';
|
|
5
|
+
import createControllableValue from '../hooks/createControllableValue.js';
|
|
6
|
+
import { setRef } from '../utils/solid.js';
|
|
7
|
+
import Element from '../Element/index.js';
|
|
8
|
+
import TextArea from './TextArea.js';
|
|
9
|
+
import useComponentSize from '../hooks/useComponentSize.js';
|
|
10
|
+
import './index.scss.js';
|
|
11
|
+
import useFocus from '../hooks/useFocus.js';
|
|
12
|
+
import CompactContext from '../Compact/context.js';
|
|
13
|
+
|
|
14
|
+
var _tmpl$ = /*#__PURE__*/template(`<div>`),
|
|
15
|
+
_tmpl$2 = /*#__PURE__*/template(`<div class=mr-4px>`),
|
|
16
|
+
_tmpl$3 = /*#__PURE__*/template(`<span class="ml-4px i-ant-design:close-circle-filled cursor-pointer text-[var(--ant-color-text-quaternary)] hover:text-[var(--ant-color-text-tertiary)] active:text-[var(--ant-color-text)]">`),
|
|
17
|
+
_tmpl$4 = /*#__PURE__*/template(`<div class=ml-4px>`),
|
|
18
|
+
_tmpl$5 = /*#__PURE__*/template(`<div class="[display:var(--actions-display)] absolute top-0 bottom-0 right-0 h-[calc(100%-2px)] translate-y-1px -translate-x-1px">`),
|
|
19
|
+
_tmpl$6 = /*#__PURE__*/template(`<div><input>`);
|
|
20
|
+
const statusClassDict = {
|
|
21
|
+
default: (disabled, foucs) => {
|
|
22
|
+
if (disabled) {
|
|
23
|
+
return 'border-[--ant-color-border]';
|
|
24
|
+
}
|
|
25
|
+
if (foucs) {
|
|
26
|
+
return 'border-[--ant-color-primary] [box-shadow:0_0_0_2px_rgba(5,145,255,0.1)]';
|
|
27
|
+
}
|
|
28
|
+
return 'border-[--ant-color-border] hover:border-[--ant-color-primary]';
|
|
29
|
+
},
|
|
30
|
+
error: (disabled, foucs) => {
|
|
31
|
+
if (disabled) {
|
|
32
|
+
return 'border-[--ant-color-error]';
|
|
33
|
+
}
|
|
34
|
+
if (foucs) {
|
|
35
|
+
return 'border-[--ant-color-error] [box-shadow:0_0_0_2px_rgba(255,38,5,.06)]';
|
|
36
|
+
}
|
|
37
|
+
return 'border-[--ant-color-error] hover:border-[--ant-color-error-border-hover]';
|
|
38
|
+
},
|
|
39
|
+
warning: (disabled, foucs) => {
|
|
40
|
+
if (disabled) {
|
|
41
|
+
return 'border-[--ant-color-warning]';
|
|
42
|
+
}
|
|
43
|
+
if (foucs) {
|
|
44
|
+
return 'border-[--ant-color-warning] [box-shadow:0_0_0_2px_rgba(255,215,5,.1)]';
|
|
45
|
+
}
|
|
46
|
+
return 'border-[--ant-color-warning] hover:border-[--ant-color-warning-border-hover]';
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
function CommonInput(props) {
|
|
50
|
+
const size = useComponentSize(() => props.size);
|
|
51
|
+
const {
|
|
52
|
+
compact
|
|
53
|
+
} = useContext(CompactContext);
|
|
54
|
+
const [_, inputProps] = splitProps(props, ['defaultValue', 'value', 'onChange', 'onPressEnter', 'onKeyDown', 'size', 'autoFocus', 'status', 'actions', 'addonBefore', 'addonAfter', 'prefix', 'suffix', 'allowClear']);
|
|
55
|
+
let inputRef;
|
|
56
|
+
const foucs = useFocus(() => inputRef);
|
|
57
|
+
onMount(() => {
|
|
58
|
+
if (props.autoFocus) {
|
|
59
|
+
inputRef?.focus();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const isControlled = () => Object.keys(props).includes('value');
|
|
63
|
+
const [value, setValue] = createControllableValue(props, {
|
|
64
|
+
trigger: null
|
|
65
|
+
});
|
|
66
|
+
const showClearBtn = createMemo(() => !props.disabled && props.allowClear && value());
|
|
67
|
+
const addonBefore = createMemo(() => props.addonBefore);
|
|
68
|
+
const addonAfter = createMemo(() => props.addonAfter);
|
|
69
|
+
const prefix = createMemo(() => props.prefix);
|
|
70
|
+
const suffix = createMemo(() => props.suffix);
|
|
71
|
+
const actions = createMemo(() => props.actions);
|
|
72
|
+
return createComponent(Element, {
|
|
73
|
+
block: true,
|
|
74
|
+
get ["class"]() {
|
|
75
|
+
return cs(props.rootClass, 'flex', 'ant-input-group', compact && 'ant-compact-item p[.ant-compact>]:not-first:ml--1px', {
|
|
76
|
+
small: 'h-24px',
|
|
77
|
+
middle: 'h-32px',
|
|
78
|
+
large: 'h-40px'
|
|
79
|
+
}[size()]);
|
|
80
|
+
},
|
|
81
|
+
get style() {
|
|
82
|
+
return {
|
|
83
|
+
'--ant-input-padding': {
|
|
84
|
+
small: '0 7px',
|
|
85
|
+
middle: '4px 11px',
|
|
86
|
+
large: '7px 11px'
|
|
87
|
+
}[size()],
|
|
88
|
+
'--ant-input-font-size': {
|
|
89
|
+
small: 'var(--ant-font-size)',
|
|
90
|
+
middle: 'var(--ant-font-size)',
|
|
91
|
+
large: 'var(--ant-font-size-lg)'
|
|
92
|
+
}[size()],
|
|
93
|
+
'--ant-input-border-radius': {
|
|
94
|
+
small: 'var(--ant-border-radius-sm)',
|
|
95
|
+
middle: 'var(--ant-border-radius)',
|
|
96
|
+
large: 'var(--ant-border-radius-lg)'
|
|
97
|
+
}[size()],
|
|
98
|
+
...props.rootStyle
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
get children() {
|
|
102
|
+
return [createComponent(Show, {
|
|
103
|
+
get when() {
|
|
104
|
+
return !isNil(addonBefore());
|
|
105
|
+
},
|
|
106
|
+
get children() {
|
|
107
|
+
var _el$ = _tmpl$();
|
|
108
|
+
insert(_el$, addonBefore);
|
|
109
|
+
effect(() => className(_el$, cs('ant-input-addon', 'shrink-0 flex justify-center items-center px-11px bg-[rgba(0,0,0,.02)] [border:1px_solid_var(--ant-color-border)] border-r-0')));
|
|
110
|
+
return _el$;
|
|
111
|
+
}
|
|
112
|
+
}), (() => {
|
|
113
|
+
var _el$2 = _tmpl$6(),
|
|
114
|
+
_el$4 = _el$2.firstChild;
|
|
115
|
+
insert(_el$2, createComponent(Show, {
|
|
116
|
+
get when() {
|
|
117
|
+
return !isNil(prefix());
|
|
118
|
+
},
|
|
119
|
+
get children() {
|
|
120
|
+
var _el$3 = _tmpl$2();
|
|
121
|
+
insert(_el$3, prefix);
|
|
122
|
+
return _el$3;
|
|
123
|
+
}
|
|
124
|
+
}), _el$4);
|
|
125
|
+
use(el => {
|
|
126
|
+
setRef(props, el);
|
|
127
|
+
inputRef = el;
|
|
128
|
+
}, _el$4);
|
|
129
|
+
spread(_el$4, mergeProps(inputProps, {
|
|
130
|
+
get ["class"]() {
|
|
131
|
+
return cs('w-full h-full [font-size:var(--ant-input-font-size)] [outline:none] placeholder-text-[var(--ant-color-text-placeholder)] bg-transparent', props.disabled && 'color-[var(--ant-color-text-disabled)] cursor-not-allowed', props.class);
|
|
132
|
+
},
|
|
133
|
+
get value() {
|
|
134
|
+
return value() ?? '';
|
|
135
|
+
},
|
|
136
|
+
"onInput": e => {
|
|
137
|
+
setValue(e.target.value);
|
|
138
|
+
try {
|
|
139
|
+
props.onChange?.(e);
|
|
140
|
+
} finally {
|
|
141
|
+
if (isControlled() && e.target.value !== props.value) {
|
|
142
|
+
e.target.value = props.value ?? '';
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
"onKeyDown": e => {
|
|
147
|
+
if (e.key === 'Enter') {
|
|
148
|
+
props.onPressEnter?.(e);
|
|
149
|
+
}
|
|
150
|
+
props.onKeyDown?.(e);
|
|
151
|
+
}
|
|
152
|
+
}), false, false);
|
|
153
|
+
insert(_el$2, createComponent(Show, {
|
|
154
|
+
get when() {
|
|
155
|
+
return showClearBtn();
|
|
156
|
+
},
|
|
157
|
+
get children() {
|
|
158
|
+
var _el$5 = _tmpl$3();
|
|
159
|
+
_el$5.$$click = e => {
|
|
160
|
+
e.stopPropagation();
|
|
161
|
+
inputRef.value = '';
|
|
162
|
+
const inputEvent = new InputEvent('input', {
|
|
163
|
+
bubbles: true
|
|
164
|
+
});
|
|
165
|
+
inputRef.dispatchEvent(inputEvent);
|
|
166
|
+
inputRef?.focus();
|
|
167
|
+
};
|
|
168
|
+
return _el$5;
|
|
169
|
+
}
|
|
170
|
+
}), null);
|
|
171
|
+
insert(_el$2, createComponent(Show, {
|
|
172
|
+
get when() {
|
|
173
|
+
return !isNil(suffix());
|
|
174
|
+
},
|
|
175
|
+
get children() {
|
|
176
|
+
var _el$6 = _tmpl$4();
|
|
177
|
+
insert(_el$6, suffix);
|
|
178
|
+
return _el$6;
|
|
179
|
+
}
|
|
180
|
+
}), null);
|
|
181
|
+
insert(_el$2, createComponent(Show, {
|
|
182
|
+
get when() {
|
|
183
|
+
return !isNil(actions());
|
|
184
|
+
},
|
|
185
|
+
get children() {
|
|
186
|
+
var _el$7 = _tmpl$5();
|
|
187
|
+
insert(_el$7, actions);
|
|
188
|
+
return _el$7;
|
|
189
|
+
}
|
|
190
|
+
}), null);
|
|
191
|
+
effect(() => className(_el$2, cs('ant-input-affix-wrapper', 'flex items-center w-full relative p:hover-child[input]:border-[--ant-color-primary] bg-[--ant-color-bg-container] p-[--ant-input-padding] border-1px border-solid', ['[--actions-display:none]', !props.disabled && 'hover:[--actions-display:block]'], statusClassDict[props.status ?? 'default'](!!props.disabled, foucs()))));
|
|
192
|
+
return _el$2;
|
|
193
|
+
})(), createComponent(Show, {
|
|
194
|
+
get when() {
|
|
195
|
+
return !isNil(addonAfter());
|
|
196
|
+
},
|
|
197
|
+
get children() {
|
|
198
|
+
var _el$8 = _tmpl$();
|
|
199
|
+
insert(_el$8, addonAfter);
|
|
200
|
+
effect(() => className(_el$8, cs('ant-input-addon', 'shrink-0 flex justify-center items-center px-11px bg-[rgba(0,0,0,.02)] [border:1px_solid_var(--ant-color-border)] border-l-0')));
|
|
201
|
+
return _el$8;
|
|
202
|
+
}
|
|
203
|
+
})];
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const Input = props => {
|
|
208
|
+
return createComponent(CommonInput, mergeProps(() => omit(props, ['actions'])));
|
|
209
|
+
};
|
|
210
|
+
Input.TextArea = TextArea;
|
|
211
|
+
delegateEvents(["click"]);
|
|
212
|
+
|
|
213
|
+
export { CommonInput, Input as default, statusClassDict };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import styleInject from '../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js';
|
|
2
|
+
|
|
3
|
+
var css_248z = ".ant-input-group > :first-child {\n border-top-left-radius: var(--ant-input-border-radius);\n border-bottom-left-radius: var(--ant-input-border-radius);\n}\n.ant-input-group > :last-child {\n border-top-right-radius: var(--ant-input-border-radius);\n border-bottom-right-radius: var(--ant-input-border-radius);\n}\n\n.ant-compact > :not(:first-child).ant-input-group.ant-compact-item > :first-child, .ant-compact > :not(:first-child) .ant-input-group.ant-compact-item > :first-child {\n border-top-left-radius: 0px;\n border-bottom-left-radius: 0px;\n}\n.ant-compact > :not(:last-child).ant-input-group.ant-compact-item > :last-child, .ant-compact > :not(:last-child) .ant-input-group.ant-compact-item > :last-child {\n border-top-right-radius: 0px;\n border-bottom-right-radius: 0px;\n}";
|
|
4
|
+
styleInject(css_248z);
|
|
5
|
+
|
|
6
|
+
export { css_248z as default };
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* 占位值,为空时显示的值
|
|
8
|
+
*/
|
|
9
|
+
placeholderValue?: number | null | undefined;
|
|
10
|
+
onChange?: (value: number | null) => void;
|
|
11
|
+
min?: number;
|
|
12
|
+
max?: number;
|
|
13
|
+
precision?: number;
|
|
14
|
+
/**
|
|
15
|
+
* 每次改变步数,可以为小数
|
|
16
|
+
* 默认 1
|
|
17
|
+
*/
|
|
18
|
+
step?: number;
|
|
19
|
+
/**
|
|
20
|
+
* 指定输入框展示值的格式
|
|
21
|
+
*/
|
|
22
|
+
formatter?: (value: number | string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* 是否显示增减按钮
|
|
25
|
+
* 默认 true
|
|
26
|
+
*/
|
|
27
|
+
controls?: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare const InputNumber: Component<InputNumberProps>;
|
|
30
|
+
export default InputNumber;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { delegateEvents, createComponent, mergeProps as mergeProps$1, memo, template } from 'solid-js/web';
|
|
2
|
+
import { mergeProps, splitProps, createSignal, untrack, createMemo, createRenderEffect, on } from 'solid-js';
|
|
3
|
+
import { isNumber, isNil, clamp, floor } from 'lodash-es';
|
|
4
|
+
import NP from 'number-precision';
|
|
5
|
+
import { CommonInput } from '../Input/index.js';
|
|
6
|
+
import { dispatchEventHandlerUnion } from '../utils/solid.js';
|
|
7
|
+
|
|
8
|
+
var _tmpl$ = /*#__PURE__*/template(`<div class="flex flex-col h-full w-[--ant-input-number-handle-width] [border-left:1px_solid_var(--ant-color-border)] bg-[--ant-color-bg-container]"><div class="text-12px flex justify-center items-center h-1/2 cursor-pointer opacity-70 hover:h-100% hover:text-[var(--ant-color-primary)] transition-color transition-height transition-duration-500"><div class=i-ant-design:up-outlined></div></div><div class="[border-top:1px_solid_var(--ant-color-border)] text-12px flex justify-center items-center h-1/2 cursor-pointer opacity-70 hover:h-100% hover:text-[var(--ant-color-primary)] transition-color transition-height transition-duration-500"><div class=i-ant-design:down-outlined>`);
|
|
9
|
+
const isEmptyValue = value => isNil(value) || value === '';
|
|
10
|
+
const InputNumber = _props => {
|
|
11
|
+
const props = mergeProps({
|
|
12
|
+
min: -Infinity,
|
|
13
|
+
max: Infinity,
|
|
14
|
+
step: 1,
|
|
15
|
+
controls: true
|
|
16
|
+
}, _props);
|
|
17
|
+
const [_, inputProps] = splitProps(props, ['defaultValue', 'value', 'onChange', 'onBlur', 'formatter']);
|
|
18
|
+
// 为什么不使用 Object.hasOwn?
|
|
19
|
+
// solid 的 proxy 对象对于任何 key,都会返回 true
|
|
20
|
+
const isControlled = () => Object.keys(props).includes('value');
|
|
21
|
+
const clampValue = v => untrack(() => clamp(v, props.min, props.max));
|
|
22
|
+
const floorValue = v => untrack(() => typeof props.precision === 'number' ? floor(v, props.precision) : v);
|
|
23
|
+
const [value, setValue] = createSignal(untrack(() => props.defaultValue));
|
|
24
|
+
const displayValue = createMemo(() => props.formatter ? props.formatter(value() ?? '') : value());
|
|
25
|
+
createRenderEffect(on(() => props.value, () => {
|
|
26
|
+
if (isControlled()) {
|
|
27
|
+
setValue(props.value);
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
const [focusing, setFocusing] = createSignal(false);
|
|
31
|
+
createRenderEffect(() => {
|
|
32
|
+
if (!isNumber(value()) && isNumber(props.placeholderValue) && !focusing()) {
|
|
33
|
+
setValue(props.placeholderValue);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
// 上一个格式正确的值
|
|
37
|
+
let validValue = null;
|
|
38
|
+
const updateValidValue = v => {
|
|
39
|
+
let valueNum = null;
|
|
40
|
+
if (!isEmptyValue(v)) {
|
|
41
|
+
valueNum = Number(v);
|
|
42
|
+
if (Number.isNaN(valueNum) || valueNum !== floorValue(valueNum)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
valueNum = isNumber(valueNum) ? clampValue(valueNum) : valueNum;
|
|
47
|
+
if (validValue === valueNum) return false;
|
|
48
|
+
validValue = valueNum;
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
updateValidValue(untrack(value));
|
|
52
|
+
const add = addon => {
|
|
53
|
+
let newValue;
|
|
54
|
+
if (isEmptyValue(value())) {
|
|
55
|
+
newValue = addon;
|
|
56
|
+
} else {
|
|
57
|
+
const num = Number(value());
|
|
58
|
+
newValue = NP.plus(Number.isNaN(num) ? validValue ?? 0 : num, addon);
|
|
59
|
+
}
|
|
60
|
+
const success = updateValidValue(newValue);
|
|
61
|
+
setValue(validValue);
|
|
62
|
+
if (success) props.onChange?.(validValue);
|
|
63
|
+
};
|
|
64
|
+
const up = () => {
|
|
65
|
+
add(props.step);
|
|
66
|
+
};
|
|
67
|
+
const down = () => {
|
|
68
|
+
add(-props.step);
|
|
69
|
+
};
|
|
70
|
+
return createComponent(CommonInput, mergeProps$1(inputProps, {
|
|
71
|
+
get rootStyle() {
|
|
72
|
+
return {
|
|
73
|
+
'--ant-input-number-handle-width': '22px',
|
|
74
|
+
...props.rootStyle
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
get actions() {
|
|
78
|
+
return memo(() => !!props.controls)() ? (() => {
|
|
79
|
+
var _el$ = _tmpl$(),
|
|
80
|
+
_el$2 = _el$.firstChild,
|
|
81
|
+
_el$3 = _el$2.nextSibling;
|
|
82
|
+
_el$2.$$click = up;
|
|
83
|
+
_el$3.$$click = down;
|
|
84
|
+
return _el$;
|
|
85
|
+
})() : undefined;
|
|
86
|
+
},
|
|
87
|
+
get value() {
|
|
88
|
+
return `${(focusing() ? value() : displayValue()) ?? ''}`;
|
|
89
|
+
},
|
|
90
|
+
onKeyDown: e => {
|
|
91
|
+
switch (e.key) {
|
|
92
|
+
case 'ArrowUp':
|
|
93
|
+
up();
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
return;
|
|
96
|
+
case 'ArrowDown':
|
|
97
|
+
down();
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
onChange: e => {
|
|
102
|
+
const newValue = e.target.value;
|
|
103
|
+
setValue(newValue);
|
|
104
|
+
const success = updateValidValue(newValue);
|
|
105
|
+
if (success) props.onChange?.(validValue);
|
|
106
|
+
},
|
|
107
|
+
onFocus: e => {
|
|
108
|
+
dispatchEventHandlerUnion(props.onFocus, e);
|
|
109
|
+
setFocusing(true);
|
|
110
|
+
},
|
|
111
|
+
onBlur: e => {
|
|
112
|
+
const success = updateValidValue(value());
|
|
113
|
+
setValue(validValue);
|
|
114
|
+
if (success) props.onChange?.(validValue);
|
|
115
|
+
dispatchEventHandlerUnion(props.onBlur, e);
|
|
116
|
+
setFocusing(false);
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
119
|
+
};
|
|
120
|
+
delegateEvents(["click"]);
|
|
121
|
+
|
|
122
|
+
export { InputNumber as default };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createComponent } from 'solid-js/web';
|
|
2
2
|
import { describe, it, vi, expect } from 'vitest';
|
|
3
3
|
import { render, fireEvent } from '@solidjs/testing-library';
|
|
4
|
-
import InputNumber from './
|
|
4
|
+
import InputNumber from './index.js';
|
|
5
5
|
import '@testing-library/jest-dom';
|
|
6
6
|
|
|
7
7
|
describe('InputNumber component', () => {
|
|
8
8
|
it('onChange', () => {
|
|
9
9
|
const onChange = vi.fn();
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
10
11
|
const {
|
|
11
12
|
getByPlaceholderText
|
|
12
13
|
} = render(() => createComponent(InputNumber, {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type MenuProps } from '.';
|
|
2
|
+
import { type StyleProps } from '../types';
|
|
3
|
+
interface InternalMenuProps<T = any> extends Pick<MenuProps<T>, 'mode' | 'items' | 'selectable' | 'onClick' | 'onSelect' | 'onDeselect'>, StyleProps {
|
|
4
|
+
/**
|
|
5
|
+
* 当前选中的菜单项 key 数组
|
|
6
|
+
*/
|
|
7
|
+
selectedKeys: T[];
|
|
8
|
+
/**
|
|
9
|
+
* 当前展开的 SubMenu 菜单项 key 数组
|
|
10
|
+
*/
|
|
11
|
+
expandedKeys: T[];
|
|
12
|
+
/**
|
|
13
|
+
* SubMenu 展开/关闭的回调
|
|
14
|
+
*/
|
|
15
|
+
onExpandedKeysChange: (expandedKeys: T[]) => void;
|
|
16
|
+
/**
|
|
17
|
+
* 父级 keys
|
|
18
|
+
*/
|
|
19
|
+
parentKeys?: T[];
|
|
20
|
+
}
|
|
21
|
+
declare function InternalMenu<T = any>(props: InternalMenuProps<T>): import("solid-js").JSX.Element;
|
|
22
|
+
export default InternalMenu;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { delegateEvents, createComponent, insert, mergeProps, effect, className, style, template } from 'solid-js/web';
|
|
2
|
+
import { For, createMemo, Show, Switch, Match } from 'solid-js';
|
|
3
|
+
import { isEmpty } from 'lodash-es';
|
|
4
|
+
import cs from 'classnames';
|
|
5
|
+
import Popover from '../Popover/index.js';
|
|
6
|
+
import { unwrapStringOrJSXElement } from '../utils/solid.js';
|
|
7
|
+
import DelayShow from '../DelayShow/index.js';
|
|
8
|
+
|
|
9
|
+
var _tmpl$ = /*#__PURE__*/template(`<div class="h-1px bg-[var(--ant-color-split)] my-[var(--ant-margin-xxs)]">`),
|
|
10
|
+
_tmpl$2 = /*#__PURE__*/template(`<div><div>`),
|
|
11
|
+
_tmpl$3 = /*#__PURE__*/template(`<div>`),
|
|
12
|
+
_tmpl$4 = /*#__PURE__*/template(`<span class="i-ant-design:right-outlined w-0.7em absolute top-1/2 right-[var(--ant-padding)] translate-y--1/2">`),
|
|
13
|
+
_tmpl$5 = /*#__PURE__*/template(`<span class="i-ant-design:up-outlined w-0.7em absolute top-1/2 right-[var(--ant-padding)] translate-y--1/2">`),
|
|
14
|
+
_tmpl$6 = /*#__PURE__*/template(`<span class="i-ant-design:down-outlined w-0.7em absolute top-1/2 right-[var(--ant-padding)] translate-y--1/2">`);
|
|
15
|
+
function isMenuDividerType(value) {
|
|
16
|
+
return value.type === 'divider';
|
|
17
|
+
}
|
|
18
|
+
function InternalMenu(props) {
|
|
19
|
+
return createComponent(For, {
|
|
20
|
+
get each() {
|
|
21
|
+
return props.items;
|
|
22
|
+
},
|
|
23
|
+
children: item => {
|
|
24
|
+
if (isMenuDividerType(item)) return _tmpl$();
|
|
25
|
+
const keyPath = createMemo(() => [...(props.parentKeys ?? []), item.key]);
|
|
26
|
+
const expanded = createMemo(() => props.expandedKeys?.includes(item.key));
|
|
27
|
+
const hasChildren = createMemo(() => !isEmpty(item.children));
|
|
28
|
+
const getLabel = options => (() => {
|
|
29
|
+
var _el$2 = _tmpl$2(),
|
|
30
|
+
_el$3 = _el$2.firstChild;
|
|
31
|
+
_el$3.$$click = () => {
|
|
32
|
+
options?.onClick?.();
|
|
33
|
+
if (!hasChildren()) {
|
|
34
|
+
const info = {
|
|
35
|
+
key: item.key,
|
|
36
|
+
keyPath: keyPath()
|
|
37
|
+
};
|
|
38
|
+
item.onClick?.(info);
|
|
39
|
+
props.onClick?.(info);
|
|
40
|
+
if (props.selectable) {
|
|
41
|
+
props.onSelect?.({
|
|
42
|
+
...info,
|
|
43
|
+
selectedKeys: [item.key]
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
insert(_el$3, () => unwrapStringOrJSXElement(item.label), null);
|
|
49
|
+
insert(_el$3, createComponent(Show, {
|
|
50
|
+
get when() {
|
|
51
|
+
return hasChildren();
|
|
52
|
+
},
|
|
53
|
+
get children() {
|
|
54
|
+
return options?.expandIcon;
|
|
55
|
+
}
|
|
56
|
+
}), null);
|
|
57
|
+
effect(_p$ => {
|
|
58
|
+
var _v$ = cs(item.disabled && 'cursor-not-allowed'),
|
|
59
|
+
_v$2 = cs('relative rounded-[var(--ant-border-radius-lg)] cursor-pointer flex items-center m-[--ant-menu-item-margin] min-h-[--ant-menu-item-height]', item.disabled ? 'text-[--ant-color-text-disabled]' : props.selectedKeys.includes(item.key) ? 'bg-[--ant-control-item-bg-active] text-[--ant-color-primary]' : 'text-[--ant-color-text] hover:bg-[var(--ant-color-bg-text-hover)]', !hasChildren() ? ['px-[--ant-padding-sm]', props.selectable && 'active:bg-[var(--ant-control-item-bg-active)]'] : 'pl-[var(--ant-padding)] pr-[calc(var(--ant-padding)+0.7em+var(--ant-margin-xs))]', item.disabled && 'pointer-events-none'),
|
|
60
|
+
_v$3 = props.mode === 'inline' ? `calc(${keyPath().length} * var(--ant-padding))` : undefined;
|
|
61
|
+
_v$ !== _p$.e && className(_el$2, _p$.e = _v$);
|
|
62
|
+
_v$2 !== _p$.t && className(_el$3, _p$.t = _v$2);
|
|
63
|
+
_v$3 !== _p$.a && ((_p$.a = _v$3) != null ? _el$3.style.setProperty("padding-left", _v$3) : _el$3.style.removeProperty("padding-left"));
|
|
64
|
+
return _p$;
|
|
65
|
+
}, {
|
|
66
|
+
e: undefined,
|
|
67
|
+
t: undefined,
|
|
68
|
+
a: undefined
|
|
69
|
+
});
|
|
70
|
+
return _el$2;
|
|
71
|
+
})();
|
|
72
|
+
return createComponent(Show, {
|
|
73
|
+
get when() {
|
|
74
|
+
return hasChildren();
|
|
75
|
+
},
|
|
76
|
+
get fallback() {
|
|
77
|
+
return getLabel();
|
|
78
|
+
},
|
|
79
|
+
get children() {
|
|
80
|
+
return createComponent(Switch, {
|
|
81
|
+
get children() {
|
|
82
|
+
return [createComponent(Match, {
|
|
83
|
+
get when() {
|
|
84
|
+
return props.mode === 'vertical';
|
|
85
|
+
},
|
|
86
|
+
get children() {
|
|
87
|
+
return createComponent(Popover, {
|
|
88
|
+
trigger: "hover",
|
|
89
|
+
get open() {
|
|
90
|
+
return expanded();
|
|
91
|
+
},
|
|
92
|
+
onOpenChange: value => {
|
|
93
|
+
if (item.disabled) return;
|
|
94
|
+
if (value) {
|
|
95
|
+
props.onExpandedKeysChange(keyPath());
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
props.onExpandedKeysChange([]);
|
|
99
|
+
},
|
|
100
|
+
placement: "rightTop",
|
|
101
|
+
arrow: false,
|
|
102
|
+
content: () => (() => {
|
|
103
|
+
var _el$6 = _tmpl$3();
|
|
104
|
+
insert(_el$6, createComponent(InternalMenu, mergeProps(props, {
|
|
105
|
+
get items() {
|
|
106
|
+
return item.children;
|
|
107
|
+
},
|
|
108
|
+
get parentKeys() {
|
|
109
|
+
return keyPath();
|
|
110
|
+
},
|
|
111
|
+
onClick: info => {
|
|
112
|
+
props.onExpandedKeysChange([]);
|
|
113
|
+
props.onClick?.(info);
|
|
114
|
+
}
|
|
115
|
+
})));
|
|
116
|
+
effect(_p$ => {
|
|
117
|
+
var _v$4 = props.class,
|
|
118
|
+
_v$5 = props.style;
|
|
119
|
+
_v$4 !== _p$.e && className(_el$6, _p$.e = _v$4);
|
|
120
|
+
_p$.t = style(_el$6, _v$5, _p$.t);
|
|
121
|
+
return _p$;
|
|
122
|
+
}, {
|
|
123
|
+
e: undefined,
|
|
124
|
+
t: undefined
|
|
125
|
+
});
|
|
126
|
+
return _el$6;
|
|
127
|
+
})(),
|
|
128
|
+
contentStyle: {
|
|
129
|
+
padding: 0
|
|
130
|
+
},
|
|
131
|
+
get children() {
|
|
132
|
+
return getLabel({
|
|
133
|
+
expandIcon: _tmpl$4()
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}), createComponent(Match, {
|
|
139
|
+
get when() {
|
|
140
|
+
return props.mode === 'inline';
|
|
141
|
+
},
|
|
142
|
+
get children() {
|
|
143
|
+
var _el$4 = _tmpl$3();
|
|
144
|
+
insert(_el$4, () => getLabel({
|
|
145
|
+
onClick() {
|
|
146
|
+
if (hasChildren()) {
|
|
147
|
+
if (expanded()) {
|
|
148
|
+
props.onExpandedKeysChange(props.expandedKeys.filter(k => k !== item.key));
|
|
149
|
+
} else {
|
|
150
|
+
props.onExpandedKeysChange([...props.expandedKeys, item.key]);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
expandIcon: createComponent(Show, {
|
|
155
|
+
get when() {
|
|
156
|
+
return expanded();
|
|
157
|
+
},
|
|
158
|
+
get fallback() {
|
|
159
|
+
return _tmpl$6();
|
|
160
|
+
},
|
|
161
|
+
get children() {
|
|
162
|
+
return _tmpl$5();
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
}), null);
|
|
166
|
+
insert(_el$4, createComponent(DelayShow, {
|
|
167
|
+
get when() {
|
|
168
|
+
return expanded();
|
|
169
|
+
},
|
|
170
|
+
get children() {
|
|
171
|
+
var _el$5 = _tmpl$3();
|
|
172
|
+
insert(_el$5, createComponent(InternalMenu, mergeProps(props, {
|
|
173
|
+
get items() {
|
|
174
|
+
return item.children;
|
|
175
|
+
},
|
|
176
|
+
get parentKeys() {
|
|
177
|
+
return keyPath();
|
|
178
|
+
}
|
|
179
|
+
})));
|
|
180
|
+
effect(() => (expanded() ? 'block' : 'none') != null ? _el$5.style.setProperty("display", expanded() ? 'block' : 'none') : _el$5.style.removeProperty("display"));
|
|
181
|
+
return _el$5;
|
|
182
|
+
}
|
|
183
|
+
}), null);
|
|
184
|
+
return _el$4;
|
|
185
|
+
}
|
|
186
|
+
})];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
delegateEvents(["click"]);
|
|
195
|
+
|
|
196
|
+
export { InternalMenu as default };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type StringOrJSXElement, type StyleProps } from '../types';
|
|
2
|
+
export interface MenuItemType<T = any> {
|
|
3
|
+
key: T;
|
|
4
|
+
label: StringOrJSXElement;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
children?: MenuItem[];
|
|
7
|
+
onClick?: (info: {
|
|
8
|
+
key: T;
|
|
9
|
+
keyPath: T[];
|
|
10
|
+
}) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface MenuDividerType {
|
|
13
|
+
type: 'divider';
|
|
14
|
+
}
|
|
15
|
+
export type MenuItem<T = any> = MenuItemType<T> | MenuDividerType;
|
|
16
|
+
export interface MenuProps<T = any> extends StyleProps {
|
|
17
|
+
/**
|
|
18
|
+
* 菜单类型
|
|
19
|
+
* 默认 'vertical' | 'inline'
|
|
20
|
+
*/
|
|
21
|
+
mode?: 'vertical' | 'inline';
|
|
22
|
+
/**
|
|
23
|
+
* 菜单项
|
|
24
|
+
*/
|
|
25
|
+
items?: Array<MenuItem<T>>;
|
|
26
|
+
/**
|
|
27
|
+
* 点击 MenuItem 调用此函数
|
|
28
|
+
*/
|
|
29
|
+
onClick?: (info: {
|
|
30
|
+
key: T;
|
|
31
|
+
keyPath: T[];
|
|
32
|
+
}) => void;
|
|
33
|
+
/**
|
|
34
|
+
* 初始展开的 SubMenu 菜单项 key 数组
|
|
35
|
+
*/
|
|
36
|
+
defaultExpandedKeys?: T[];
|
|
37
|
+
/**
|
|
38
|
+
* 当前展开的 SubMenu 菜单项 key 数组
|
|
39
|
+
*/
|
|
40
|
+
expandedKeys?: T[];
|
|
41
|
+
/**
|
|
42
|
+
* SubMenu 展开/关闭的回调
|
|
43
|
+
*/
|
|
44
|
+
onExpandedKeysChange?: (expandedKeys: T[]) => void;
|
|
45
|
+
/**
|
|
46
|
+
* 是否允许选中
|
|
47
|
+
*/
|
|
48
|
+
selectable?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* 初始选中的菜单项 key 数组
|
|
51
|
+
*/
|
|
52
|
+
defaultSelectedKeys?: T[];
|
|
53
|
+
/**
|
|
54
|
+
* 当前选中的菜单项 key 数组
|
|
55
|
+
*/
|
|
56
|
+
selectedKeys?: T[];
|
|
57
|
+
/**
|
|
58
|
+
* 被选中时调用
|
|
59
|
+
*/
|
|
60
|
+
onSelect?: (info: {
|
|
61
|
+
key: T;
|
|
62
|
+
keyPath: T[];
|
|
63
|
+
selectedKeys: T[];
|
|
64
|
+
}) => void;
|
|
65
|
+
/**
|
|
66
|
+
* 取消选中时调用,仅在 multiple 生效
|
|
67
|
+
*/
|
|
68
|
+
onDeselect?: (info: {
|
|
69
|
+
key: T;
|
|
70
|
+
keyPath: T[];
|
|
71
|
+
selectedKeys: T[];
|
|
72
|
+
}) => void;
|
|
73
|
+
}
|
|
74
|
+
declare function Menu<T = any>(_props: MenuProps<T>): import("solid-js").JSX.Element;
|
|
75
|
+
export default Menu;
|