antd-solid 0.0.3 → 0.0.5
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.css +69 -0
- package/dist/index.esm.js +2369 -0
- package/dist/index.umd.js +1 -0
- package/package.json +5 -3
- package/.eslintignore +0 -2
- package/.eslintrc.cjs +0 -36
- package/.husky/pre-commit +0 -4
- package/.prettierrc +0 -11
- package/.vscode/settings.json +0 -13
- package/docs/.vitepress/components/Code.vue +0 -175
- package/docs/.vitepress/config.ts +0 -87
- package/docs/.vitepress/theme/index.css +0 -19
- package/docs/.vitepress/theme/index.ts +0 -12
- package/docs/components/button/Base.tsx +0 -21
- package/docs/components/button/Danger.tsx +0 -21
- package/docs/components/button.md +0 -35
- package/docs/components/collapse/Base.tsx +0 -25
- package/docs/components/collapse.md +0 -26
- package/docs/components/color-picker/Base.tsx +0 -14
- package/docs/components/color-picker.md +0 -26
- package/docs/components/compact/Base.tsx +0 -27
- package/docs/components/compact.md +0 -26
- package/docs/components/date-picker/Base.tsx +0 -15
- package/docs/components/date-picker.md +0 -26
- package/docs/components/empty/Base.tsx +0 -8
- package/docs/components/empty/PRESENTED_IMAGE_SIMPLE.tsx +0 -8
- package/docs/components/empty.md +0 -32
- package/docs/components/form/Base.tsx +0 -63
- package/docs/components/form.md +0 -27
- package/docs/components/image/Base.tsx +0 -13
- package/docs/components/image.md +0 -26
- package/docs/components/input/AddonBeforeAndAfter.tsx +0 -14
- package/docs/components/input/Base.tsx +0 -15
- package/docs/components/input/Disabled.tsx +0 -19
- package/docs/components/input/PrefixAndSuffix.tsx +0 -14
- package/docs/components/input/Status.tsx +0 -25
- package/docs/components/input/TextArea.tsx +0 -14
- package/docs/components/input-number/Base.tsx +0 -15
- package/docs/components/input-number/MinMax.tsx +0 -17
- package/docs/components/input-number.md +0 -34
- package/docs/components/input.md +0 -57
- package/docs/components/modal/Base.tsx +0 -35
- package/docs/components/modal.md +0 -26
- package/docs/components/popconfirm/Base.tsx +0 -25
- package/docs/components/popconfirm.md +0 -26
- package/docs/components/popover/Base.tsx +0 -19
- package/docs/components/popover.md +0 -26
- package/docs/components/progress/Base.tsx +0 -16
- package/docs/components/progress.md +0 -26
- package/docs/components/radio/Base.tsx +0 -10
- package/docs/components/radio.md +0 -26
- package/docs/components/segmented/Base.tsx +0 -10
- package/docs/components/segmented/Block.tsx +0 -10
- package/docs/components/segmented/Disabled.tsx +0 -28
- package/docs/components/segmented.md +0 -38
- package/docs/components/select/AllowClear.tsx +0 -18
- package/docs/components/select/Base.tsx +0 -17
- package/docs/components/select.md +0 -35
- package/docs/components/switch/Base.tsx +0 -14
- package/docs/components/switch.md +0 -26
- package/docs/components/table/Base.tsx +0 -34
- package/docs/components/table.md +0 -29
- package/docs/components/tabs/Base.tsx +0 -25
- package/docs/components/tabs/Segment.tsx +0 -25
- package/docs/components/tabs.md +0 -33
- package/docs/components/tooltip/Base.tsx +0 -12
- package/docs/components/tooltip/Placement.tsx +0 -90
- package/docs/components/tooltip.md +0 -32
- package/docs/components/tree/Base.tsx +0 -45
- package/docs/components/tree.md +0 -26
- package/docs/index.md +0 -28
- package/global.d.ts +0 -9
- package/patches/vitepress@1.0.0-rc.4.patch +0 -60
- package/rollup.config.js +0 -65
- package/scripts/annotationNonProductionCode.js +0 -30
- package/scripts/cancelAnnotationNonProductionCode.js +0 -30
- 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 -12
- 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/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/src/utils/zh_CN.ts +0 -236
- package/tsconfig.json +0 -25
- package/unocss.config.ts +0 -176
package/src/Image.tsx
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Image as ImageAntd } from 'antd'
|
|
2
|
-
import { configProvider, reactToSolidComponent, replaceClassName } from './utils/component'
|
|
3
|
-
import { solidToReact } from './utils/solid'
|
|
4
|
-
import { type JSXElement, createMemo } from 'solid-js'
|
|
5
|
-
import { mapValues } from 'lodash-es'
|
|
6
|
-
|
|
7
|
-
const _Image = replaceClassName(
|
|
8
|
-
reactToSolidComponent(configProvider(ImageAntd), () => (<div class="ant-inline-flex" />) as any),
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
type ImageProps = Omit<Parameters<typeof _Image>[0], 'placeholder'> & {
|
|
12
|
-
placeholder?: JSXElement
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function Image(_props: ImageProps) {
|
|
16
|
-
const props = createMemo(() =>
|
|
17
|
-
mapValues(_props, (value, key) => {
|
|
18
|
-
switch (key) {
|
|
19
|
-
case 'placeholder':
|
|
20
|
-
return solidToReact(value)
|
|
21
|
-
default:
|
|
22
|
-
return value
|
|
23
|
-
}
|
|
24
|
-
}),
|
|
25
|
-
)
|
|
26
|
-
return <_Image {...(props() as any)} />
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default Image
|
package/src/Input.tsx
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import { isNil, omit } from 'lodash-es'
|
|
2
|
-
import { Show, createMemo, splitProps } from 'solid-js'
|
|
3
|
-
import type { JSX, JSXElement, Component } from 'solid-js'
|
|
4
|
-
import cs from 'classnames'
|
|
5
|
-
import createControllableValue from './hooks/createControllableValue'
|
|
6
|
-
import { Dynamic } from 'solid-js/web'
|
|
7
|
-
import Compact from './Compact'
|
|
8
|
-
|
|
9
|
-
type CommonInputProps<T extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement> =
|
|
10
|
-
JSX.CustomAttributes<T> & {
|
|
11
|
-
textarea?: boolean
|
|
12
|
-
defaultValue?: string | undefined
|
|
13
|
-
value?: string | undefined
|
|
14
|
-
addonBefore?: JSXElement
|
|
15
|
-
addonAfter?: JSXElement
|
|
16
|
-
prefix?: JSXElement
|
|
17
|
-
suffix?: JSXElement
|
|
18
|
-
placeholder?: string
|
|
19
|
-
/**
|
|
20
|
-
* 仅供 InputNumber 使用
|
|
21
|
-
*/
|
|
22
|
-
actions?: JSXElement
|
|
23
|
-
/**
|
|
24
|
-
* 设置校验状态
|
|
25
|
-
*/
|
|
26
|
-
status?: 'error' | 'warning'
|
|
27
|
-
onChange?: JSX.InputEventHandler<T, InputEvent>
|
|
28
|
-
onPressEnter?: JSX.EventHandler<T, KeyboardEvent>
|
|
29
|
-
onKeyDown?: JSX.EventHandler<T, KeyboardEvent>
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const statusClassDict = {
|
|
33
|
-
default: (disabled: boolean) =>
|
|
34
|
-
cs(
|
|
35
|
-
'ant-[border:1px_solid_var(--ant-color-border)]',
|
|
36
|
-
!disabled &&
|
|
37
|
-
'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)]',
|
|
38
|
-
),
|
|
39
|
-
error: (disabled: boolean) =>
|
|
40
|
-
cs(
|
|
41
|
-
'ant-[border:1px_solid_var(--ant-color-error)]',
|
|
42
|
-
!disabled &&
|
|
43
|
-
'hover:ant-border-[var(--light-error-color)] focus-within:ant-[box-shadow:0_0_0_2px_rgba(255,38,5,.06)]',
|
|
44
|
-
),
|
|
45
|
-
warning: (disabled: boolean) =>
|
|
46
|
-
cs(
|
|
47
|
-
'ant-[border:1px_solid_var(--warning-color)]',
|
|
48
|
-
!disabled &&
|
|
49
|
-
'hover:ant-border-[var(--color-warning-border-hover)] focus-within:ant-[box-shadow:0_0_0_2px_rgba(255,215,5,.1)]',
|
|
50
|
-
),
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function CommonInput<T extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement>(
|
|
54
|
-
props: CommonInputProps<T> &
|
|
55
|
-
Omit<JSX.InputHTMLAttributes<T>, 'onChange' | 'onInput' | 'onKeyDown'>,
|
|
56
|
-
) {
|
|
57
|
-
const [{ style, onChange, onPressEnter, onKeyDown }, inputProps] = splitProps(props, [
|
|
58
|
-
'defaultValue',
|
|
59
|
-
'value',
|
|
60
|
-
'class',
|
|
61
|
-
'addonBefore',
|
|
62
|
-
'addonAfter',
|
|
63
|
-
'suffix',
|
|
64
|
-
'onChange',
|
|
65
|
-
'onPressEnter',
|
|
66
|
-
'onKeyDown',
|
|
67
|
-
'actions',
|
|
68
|
-
'style',
|
|
69
|
-
])
|
|
70
|
-
|
|
71
|
-
const [_, controllableProps] = splitProps(props, ['onChange'])
|
|
72
|
-
const [value, setValue] = createControllableValue(controllableProps)
|
|
73
|
-
|
|
74
|
-
const inputWrapClass = createMemo(() =>
|
|
75
|
-
cs(
|
|
76
|
-
'ant-px-11px ant-py-4px ant-rounded-6px',
|
|
77
|
-
!props.textarea && 'ant-h-32px',
|
|
78
|
-
props.addonBefore ? 'ant-rounded-l-0' : Compact.compactItemRoundedLeftClass,
|
|
79
|
-
props.addonAfter ? 'ant-rounded-r-0' : Compact.compactItemRoundedRightClass,
|
|
80
|
-
statusClassDict[props.status ?? 'default'](!!inputProps.disabled),
|
|
81
|
-
Compact.compactItemRounded0Class,
|
|
82
|
-
Compact.compactItemZIndexClass,
|
|
83
|
-
),
|
|
84
|
-
)
|
|
85
|
-
const hasPrefixOrSuffix = createMemo(
|
|
86
|
-
() => !isNil(props.prefix) || !isNil(props.suffix) || !isNil(props.actions),
|
|
87
|
-
)
|
|
88
|
-
const inputJSX = (
|
|
89
|
-
<Dynamic<Component<JSX.InputHTMLAttributes<HTMLInputElement>>>
|
|
90
|
-
component={
|
|
91
|
-
(props.textarea ? 'textarea' : 'input') as unknown as Component<
|
|
92
|
-
JSX.InputHTMLAttributes<HTMLInputElement>
|
|
93
|
-
>
|
|
94
|
-
}
|
|
95
|
-
{...(inputProps as JSX.InputHTMLAttributes<HTMLInputElement>)}
|
|
96
|
-
class={cs(
|
|
97
|
-
'ant-w-full ant-[outline:none] ant-text-14px',
|
|
98
|
-
!hasPrefixOrSuffix() && inputWrapClass(),
|
|
99
|
-
inputProps.disabled &&
|
|
100
|
-
'ant-bg-[var(--ant-color-bg-container-disabled)] ant-cursor-not-allowed',
|
|
101
|
-
)}
|
|
102
|
-
value={value() ?? ''}
|
|
103
|
-
onInput={e => {
|
|
104
|
-
setValue(e.target.value)
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
106
|
-
onChange?.(e as any)
|
|
107
|
-
|
|
108
|
-
if (Object.keys(props).includes('value')) {
|
|
109
|
-
e.target.value = value()
|
|
110
|
-
}
|
|
111
|
-
}}
|
|
112
|
-
onKeyDown={e => {
|
|
113
|
-
if (e.key === 'Enter') {
|
|
114
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
115
|
-
onPressEnter?.(e as any)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
119
|
-
onKeyDown?.(e as any)
|
|
120
|
-
}}
|
|
121
|
-
/>
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<div class={cs('ant-flex ant-w-full', Compact.compactItemClass)} style={style}>
|
|
126
|
-
<Show when={props.addonBefore}>
|
|
127
|
-
<div
|
|
128
|
-
class={cs(
|
|
129
|
-
'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',
|
|
130
|
-
Compact.compactItemRounded0Class,
|
|
131
|
-
Compact.compactItemRoundedLeftClass,
|
|
132
|
-
)}
|
|
133
|
-
>
|
|
134
|
-
{props.addonBefore}
|
|
135
|
-
</div>
|
|
136
|
-
</Show>
|
|
137
|
-
|
|
138
|
-
<Show when={hasPrefixOrSuffix()} fallback={inputJSX}>
|
|
139
|
-
<div
|
|
140
|
-
class={cs(
|
|
141
|
-
'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)]',
|
|
142
|
-
inputWrapClass(),
|
|
143
|
-
)}
|
|
144
|
-
>
|
|
145
|
-
<Show when={props.prefix}>
|
|
146
|
-
<div class="ant-mr-4px">{props.prefix}</div>
|
|
147
|
-
</Show>
|
|
148
|
-
|
|
149
|
-
{inputJSX}
|
|
150
|
-
|
|
151
|
-
<Show when={props.suffix}>
|
|
152
|
-
<div class="ant-ml-4px">{props.suffix}</div>
|
|
153
|
-
</Show>
|
|
154
|
-
|
|
155
|
-
<Show when={props.actions}>
|
|
156
|
-
<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">
|
|
157
|
-
{props.actions}
|
|
158
|
-
</div>
|
|
159
|
-
</Show>
|
|
160
|
-
</div>
|
|
161
|
-
</Show>
|
|
162
|
-
|
|
163
|
-
<Show when={props.addonAfter}>
|
|
164
|
-
<div
|
|
165
|
-
class={cs(
|
|
166
|
-
'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',
|
|
167
|
-
Compact.compactItemRounded0Class,
|
|
168
|
-
Compact.compactItemRoundedRightClass,
|
|
169
|
-
)}
|
|
170
|
-
>
|
|
171
|
-
{props.addonAfter}
|
|
172
|
-
</div>
|
|
173
|
-
</Show>
|
|
174
|
-
</div>
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export type InputProps = Omit<CommonInputProps, 'actions' | 'textarea'> &
|
|
179
|
-
Omit<JSX.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'onInput' | 'onKeyDown'>
|
|
180
|
-
|
|
181
|
-
export type TextAreaProps = Omit<
|
|
182
|
-
CommonInputProps<HTMLTextAreaElement>,
|
|
183
|
-
'prefix' | 'suffix' | 'textarea'
|
|
184
|
-
> &
|
|
185
|
-
Omit<
|
|
186
|
-
JSX.TextareaHTMLAttributes<HTMLTextAreaElement>,
|
|
187
|
-
'actions' | 'onChange' | 'onInput' | 'onKeyDown'
|
|
188
|
-
>
|
|
189
|
-
|
|
190
|
-
const Input: Component<InputProps> & {
|
|
191
|
-
TextArea: Component<TextAreaProps>
|
|
192
|
-
} = props => {
|
|
193
|
-
return <CommonInput {...omit(props, ['actions'])} />
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
Input.TextArea = props => {
|
|
197
|
-
return (
|
|
198
|
-
<CommonInput<HTMLTextAreaElement> textarea {...omit(props, ['prefix', 'suffix', 'actions'])} />
|
|
199
|
-
)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export default Input
|
package/src/InputNumber.test.tsx
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
-
import { fireEvent, render } from '@solidjs/testing-library'
|
|
3
|
-
import InputNumber from './InputNumber'
|
|
4
|
-
import '@testing-library/jest-dom'
|
|
5
|
-
|
|
6
|
-
describe('InputNumber component', () => {
|
|
7
|
-
it('onChange', () => {
|
|
8
|
-
const onChange = vi.fn()
|
|
9
|
-
const { getByPlaceholderText } = render(() => (
|
|
10
|
-
<InputNumber placeholder="input-number" onChange={onChange} />
|
|
11
|
-
))
|
|
12
|
-
|
|
13
|
-
const input: HTMLInputElement = getByPlaceholderText('input-number')
|
|
14
|
-
input.value = '123'
|
|
15
|
-
fireEvent.input(input)
|
|
16
|
-
expect(onChange).toHaveBeenLastCalledWith(123)
|
|
17
|
-
|
|
18
|
-
input.value = '1234'
|
|
19
|
-
fireEvent.input(input)
|
|
20
|
-
expect(onChange).toBeCalledTimes(2)
|
|
21
|
-
expect(onChange).toHaveBeenLastCalledWith(1234)
|
|
22
|
-
|
|
23
|
-
input.value = '1234'
|
|
24
|
-
fireEvent.input(input)
|
|
25
|
-
expect(onChange).toBeCalledTimes(2)
|
|
26
|
-
|
|
27
|
-
input.value = '1234.'
|
|
28
|
-
fireEvent.input(input)
|
|
29
|
-
expect(onChange).toBeCalledTimes(2)
|
|
30
|
-
|
|
31
|
-
input.value = '1234.0'
|
|
32
|
-
fireEvent.input(input)
|
|
33
|
-
expect(onChange).toBeCalledTimes(2)
|
|
34
|
-
|
|
35
|
-
input.value = '1234.01'
|
|
36
|
-
fireEvent.input(input)
|
|
37
|
-
expect(onChange).toBeCalledTimes(3)
|
|
38
|
-
|
|
39
|
-
input.value = '123x'
|
|
40
|
-
fireEvent.input(input)
|
|
41
|
-
expect(onChange).toBeCalledTimes(3)
|
|
42
|
-
|
|
43
|
-
fireEvent.blur(input)
|
|
44
|
-
expect(onChange).toBeCalledTimes(3)
|
|
45
|
-
})
|
|
46
|
-
})
|
package/src/InputNumber.tsx
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { type Component, createEffect, on, splitProps, untrack, createSignal, mergeProps } from 'solid-js'
|
|
2
|
-
import { CommonInput, type InputProps } from './Input'
|
|
3
|
-
import { clamp, isNil } from 'lodash-es'
|
|
4
|
-
import { dispatchEventHandlerUnion } from './utils/solid'
|
|
5
|
-
|
|
6
|
-
export interface InputNumberProps
|
|
7
|
-
extends Omit<
|
|
8
|
-
InputProps,
|
|
9
|
-
'defaultValue' | 'value' | 'onChange' | 'inputAfter' | 'onKeyDown' | 'min' | 'max' | 'suffix'
|
|
10
|
-
> {
|
|
11
|
-
defaultValue?: number | null | undefined
|
|
12
|
-
value?: number | null | undefined
|
|
13
|
-
onChange?: (value: number | null) => void
|
|
14
|
-
min?: number
|
|
15
|
-
max?: number
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const isEmptyValue = (value: number | string | null | undefined) => isNil(value) || value === ''
|
|
19
|
-
|
|
20
|
-
const actionBtnClass =
|
|
21
|
-
'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'
|
|
22
|
-
|
|
23
|
-
const InputNumber: Component<InputNumberProps> = _props => {
|
|
24
|
-
const props = mergeProps({
|
|
25
|
-
min: -Infinity,
|
|
26
|
-
max: Infinity,
|
|
27
|
-
}, _props)
|
|
28
|
-
const [_, inputProps] = splitProps(props, [
|
|
29
|
-
'defaultValue',
|
|
30
|
-
'value',
|
|
31
|
-
'onChange',
|
|
32
|
-
'onBlur',
|
|
33
|
-
])
|
|
34
|
-
|
|
35
|
-
const clampValue = (v: number) => untrack(() => clamp(v, props.min, props.max))
|
|
36
|
-
|
|
37
|
-
let prev: number | null = null
|
|
38
|
-
const updatePrev = (v: number | null) => {
|
|
39
|
-
if (prev === v) return
|
|
40
|
-
|
|
41
|
-
prev = v
|
|
42
|
-
props.onChange?.(prev)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const [value, setValue] = createSignal<number | string | null | undefined>(untrack(() => props.value ?? props.defaultValue))
|
|
46
|
-
createEffect(on(() => props.value, () => {
|
|
47
|
-
setValue(props.value)
|
|
48
|
-
}, {
|
|
49
|
-
defer: true
|
|
50
|
-
}))
|
|
51
|
-
|
|
52
|
-
const add = (addon: number) => {
|
|
53
|
-
let newValue: number | null
|
|
54
|
-
if (isEmptyValue(value())) {
|
|
55
|
-
newValue = clampValue(addon)
|
|
56
|
-
} else {
|
|
57
|
-
const num = Number(value())
|
|
58
|
-
newValue = Number.isNaN(num) ? null : clampValue(num + addon)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (!Object.keys(props).includes('value')) {
|
|
62
|
-
setValue(newValue)
|
|
63
|
-
}
|
|
64
|
-
updatePrev(newValue)
|
|
65
|
-
}
|
|
66
|
-
const up = () => {
|
|
67
|
-
add(1)
|
|
68
|
-
}
|
|
69
|
-
const down = () => {
|
|
70
|
-
add(-1)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<CommonInput
|
|
75
|
-
{...inputProps}
|
|
76
|
-
actions={
|
|
77
|
-
<div class="ant-flex ant-flex-col ant-h-full ant-w-24px ant-[border-left:1px_solid_var(--ant-color-border)]">
|
|
78
|
-
<div class={actionBtnClass} onClick={up}>
|
|
79
|
-
<div class="i-ant-design:up-outlined" />
|
|
80
|
-
</div>
|
|
81
|
-
<div
|
|
82
|
-
class={`ant-[border-top:1px_solid_var(--ant-color-border)] ${actionBtnClass}`}
|
|
83
|
-
onClick={down}
|
|
84
|
-
>
|
|
85
|
-
<div class="i-ant-design:down-outlined" />
|
|
86
|
-
</div>
|
|
87
|
-
</div>
|
|
88
|
-
}
|
|
89
|
-
value={`${value() ?? ''}`}
|
|
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
|
-
|
|
105
|
-
let newValueNum: number | null = Number(newValue)
|
|
106
|
-
if (Number.isNaN(newValueNum)) return
|
|
107
|
-
|
|
108
|
-
if (isEmptyValue(newValue)) {
|
|
109
|
-
newValueNum = null
|
|
110
|
-
} else {
|
|
111
|
-
newValueNum = clampValue(newValueNum)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
updatePrev(newValueNum)
|
|
115
|
-
}}
|
|
116
|
-
onBlur={e => {
|
|
117
|
-
setValue(props.value ?? prev)
|
|
118
|
-
|
|
119
|
-
dispatchEventHandlerUnion(props.onBlur, e)
|
|
120
|
-
}}
|
|
121
|
-
/>
|
|
122
|
-
)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export default InputNumber
|
package/src/Modal.tsx
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { type JSXElement, Show, createSignal, untrack, type Ref, mergeProps } from 'solid-js'
|
|
2
|
-
import { Portal, render } from 'solid-js/web'
|
|
3
|
-
import Button from './Button'
|
|
4
|
-
import cs from 'classnames'
|
|
5
|
-
|
|
6
|
-
export interface ModalInstance {
|
|
7
|
-
open: () => void
|
|
8
|
-
close: () => void
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface ModalProps {
|
|
12
|
-
ref?: Ref<ModalInstance>
|
|
13
|
-
title?: JSXElement
|
|
14
|
-
defaultOpen?: boolean
|
|
15
|
-
width?: string
|
|
16
|
-
height?: string
|
|
17
|
-
children?: JSXElement
|
|
18
|
-
/**
|
|
19
|
-
* 垂直居中展示 Modal
|
|
20
|
-
*/
|
|
21
|
-
centered?: boolean
|
|
22
|
-
/**
|
|
23
|
-
* 点击蒙层是否允许关闭
|
|
24
|
-
* 默认 true
|
|
25
|
-
*/
|
|
26
|
-
maskClosable?: boolean
|
|
27
|
-
/**
|
|
28
|
-
* 设置为 false 时隐藏关闭按钮
|
|
29
|
-
*/
|
|
30
|
-
closeIcon?: boolean
|
|
31
|
-
footer?: boolean | ((modal: ModalInstance) => JSXElement)
|
|
32
|
-
/**
|
|
33
|
-
* 关闭时销毁 Modal 里的子元素
|
|
34
|
-
*/
|
|
35
|
-
destroyOnClose?: boolean
|
|
36
|
-
/**
|
|
37
|
-
* 返回 true,会自动关闭 modal
|
|
38
|
-
*/
|
|
39
|
-
onOk?: () => boolean | Promise<boolean>
|
|
40
|
-
afterClose?: () => void
|
|
41
|
-
/**
|
|
42
|
-
* 自定义渲染对话框
|
|
43
|
-
*/
|
|
44
|
-
modalRender?: () => JSXElement
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface MethodProps
|
|
48
|
-
extends Pick<ModalProps, 'title' | 'children' | 'onOk' | 'afterClose'> {}
|
|
49
|
-
|
|
50
|
-
function Modal(_props: ModalProps) {
|
|
51
|
-
const props = mergeProps({ footer: true }, _props)
|
|
52
|
-
const [open, setOpen] = createSignal(props.defaultOpen ?? false)
|
|
53
|
-
const [hide, setHide] = createSignal(false)
|
|
54
|
-
|
|
55
|
-
const instance: ModalInstance = {
|
|
56
|
-
open() {
|
|
57
|
-
setOpen(true)
|
|
58
|
-
setHide(false)
|
|
59
|
-
},
|
|
60
|
-
close() {
|
|
61
|
-
untrack(() => {
|
|
62
|
-
if (props.destroyOnClose) {
|
|
63
|
-
setOpen(false)
|
|
64
|
-
} else {
|
|
65
|
-
setHide(true)
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
},
|
|
69
|
-
}
|
|
70
|
-
untrack(() => {
|
|
71
|
-
if (typeof props.ref === 'function') {
|
|
72
|
-
props.ref?.(instance)
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
const close = () => {
|
|
77
|
-
instance.close()
|
|
78
|
-
props.afterClose?.()
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const [confirmLoading, setConfirmLoading] = createSignal(false)
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<Show when={open()}>
|
|
85
|
-
<Portal>
|
|
86
|
-
<div
|
|
87
|
-
class={cs(
|
|
88
|
-
'ant-fixed ant-justify-center ant-inset-0 ant-bg-[rgba(0,0,0,.45)] ant-flex ant-z-1000',
|
|
89
|
-
props.centered && 'ant-items-center',
|
|
90
|
-
)}
|
|
91
|
-
onClick={() => {
|
|
92
|
-
if (props.maskClosable ?? true) {
|
|
93
|
-
close()
|
|
94
|
-
}
|
|
95
|
-
}}
|
|
96
|
-
style={{ display: hide() ? 'none' : undefined }}
|
|
97
|
-
>
|
|
98
|
-
<Show when={typeof props.modalRender !== 'function'} fallback={props.modalRender!()}>
|
|
99
|
-
<div
|
|
100
|
-
class={cs(
|
|
101
|
-
'ant-absolute ant-px-24px ant-py-20px ant-rounded-8px ant-overflow-hidden ant-bg-white ant-flex ant-flex-col',
|
|
102
|
-
// '!ant-[animation-duration:.5s]',
|
|
103
|
-
!props.centered && 'ant-top-100px',
|
|
104
|
-
)}
|
|
105
|
-
onClick={e => {
|
|
106
|
-
e.stopPropagation()
|
|
107
|
-
}}
|
|
108
|
-
style={{
|
|
109
|
-
width: props.width ?? '520px',
|
|
110
|
-
height: props.height,
|
|
111
|
-
}}
|
|
112
|
-
>
|
|
113
|
-
{/* 关闭按钮 */}
|
|
114
|
-
<Show when={props.closeIcon !== false}>
|
|
115
|
-
<Button
|
|
116
|
-
type="text"
|
|
117
|
-
class={cs(
|
|
118
|
-
'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)]',
|
|
119
|
-
)}
|
|
120
|
-
onClick={close}
|
|
121
|
-
>
|
|
122
|
-
<span class="i-ant-design:close-outlined" />
|
|
123
|
-
</Button>
|
|
124
|
-
</Show>
|
|
125
|
-
|
|
126
|
-
<div class="ant-text-[rgba(0,0,0,.88)] ant-text-16px ant-font-600 ant-mb-8px">
|
|
127
|
-
{props.title}
|
|
128
|
-
</div>
|
|
129
|
-
<div class="ant-grow">{props.children}</div>
|
|
130
|
-
|
|
131
|
-
<Show when={props.footer !== false}>
|
|
132
|
-
<div class="ant-mt-12px">
|
|
133
|
-
<Show when={typeof props.footer !== 'function'} fallback={typeof props.footer === 'function' && props.footer(instance)}>
|
|
134
|
-
<div class='ant-flex ant-gap-8px ant-justify-end'>
|
|
135
|
-
<Button onClick={close}>取消</Button>
|
|
136
|
-
<Button
|
|
137
|
-
type="primary"
|
|
138
|
-
loading={confirmLoading()}
|
|
139
|
-
// eslint-disable-next-line solid/reactivity, @typescript-eslint/no-misused-promises
|
|
140
|
-
onClick={async () => {
|
|
141
|
-
if (!props.onOk) return
|
|
142
|
-
|
|
143
|
-
let res = props.onOk?.()
|
|
144
|
-
if (res instanceof Promise) {
|
|
145
|
-
setConfirmLoading(true)
|
|
146
|
-
res = await res.finally(() => setConfirmLoading(false))
|
|
147
|
-
}
|
|
148
|
-
if (res) {
|
|
149
|
-
instance.close()
|
|
150
|
-
}
|
|
151
|
-
}}
|
|
152
|
-
>
|
|
153
|
-
确定
|
|
154
|
-
</Button>
|
|
155
|
-
</div>
|
|
156
|
-
</Show>
|
|
157
|
-
</div>
|
|
158
|
-
</Show>
|
|
159
|
-
</div>
|
|
160
|
-
</Show>
|
|
161
|
-
</div>
|
|
162
|
-
</Portal>
|
|
163
|
-
</Show>
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
Modal.warning = (props: MethodProps) => {
|
|
168
|
-
const div = document.createElement('div')
|
|
169
|
-
document.body.appendChild(div)
|
|
170
|
-
const dispose = render(
|
|
171
|
-
() => (
|
|
172
|
-
<Modal
|
|
173
|
-
width="416px"
|
|
174
|
-
maskClosable={false}
|
|
175
|
-
closeIcon={false}
|
|
176
|
-
{...props}
|
|
177
|
-
title={
|
|
178
|
-
<>
|
|
179
|
-
<span class="i-ant-design:exclamation-circle ant-text-22px ant-mr-12px ant-text-[var(--warning-color)]" />
|
|
180
|
-
{props.title}
|
|
181
|
-
</>
|
|
182
|
-
}
|
|
183
|
-
children={<div class="ant-ml-34px">{props.children}</div>}
|
|
184
|
-
defaultOpen
|
|
185
|
-
afterClose={() => {
|
|
186
|
-
document.body.removeChild(div)
|
|
187
|
-
dispose()
|
|
188
|
-
props.afterClose?.()
|
|
189
|
-
}}
|
|
190
|
-
/>
|
|
191
|
-
),
|
|
192
|
-
div,
|
|
193
|
-
)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export default Modal
|
package/src/Popconfirm.tsx
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { type Component, type JSXElement, createSignal, mergeProps, untrack, splitProps } from 'solid-js'
|
|
2
|
-
import Button from './Button'
|
|
3
|
-
import Tooltip, { type TooltipProps } from './Tooltip'
|
|
4
|
-
|
|
5
|
-
interface PopconfirmProps extends Pick<TooltipProps, 'placement' | 'arrow'> {
|
|
6
|
-
title?: JSXElement
|
|
7
|
-
content?: JSXElement
|
|
8
|
-
children: JSXElement
|
|
9
|
-
onCancel?: () => void
|
|
10
|
-
onConfirm?: () => void
|
|
11
|
-
/**
|
|
12
|
-
* 确认按钮文字
|
|
13
|
-
* 默认:确定
|
|
14
|
-
*/
|
|
15
|
-
okText?: string
|
|
16
|
-
/**
|
|
17
|
-
* 取消按钮文字
|
|
18
|
-
* 默认:取消
|
|
19
|
-
*/
|
|
20
|
-
cancelText?: string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const Popconfirm: Component<PopconfirmProps> = props => {
|
|
24
|
-
const mergedProps = mergeProps({ okText: '确定', cancelText: '取消' }, props)
|
|
25
|
-
const [tooltipProps] = splitProps(props, ['placement', 'arrow'])
|
|
26
|
-
const [open, setOpen] = createSignal(false)
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<Tooltip
|
|
30
|
-
mode="light"
|
|
31
|
-
trigger="click"
|
|
32
|
-
open={open()}
|
|
33
|
-
onOpenChange={setOpen}
|
|
34
|
-
content={
|
|
35
|
-
<div>
|
|
36
|
-
<div class="ant-mb-8px ant-flex ant-items-center">
|
|
37
|
-
<span class="i-ant-design:exclamation-circle-fill ant-text-#faad14" />
|
|
38
|
-
<span class="ant-ml-8px ant-text-[rgba(0,0,0,0.88)] ant-font-600">{mergedProps.title}</span>
|
|
39
|
-
</div>
|
|
40
|
-
|
|
41
|
-
<div class="ant-ml-22px ant-mb-8px ant-text-[rgba(0,0,0,0.88)]">{mergedProps.content}</div>
|
|
42
|
-
|
|
43
|
-
<div class="ant-text-right">
|
|
44
|
-
<Button
|
|
45
|
-
class="ant-ml-8px"
|
|
46
|
-
size="small"
|
|
47
|
-
onClick={() => {
|
|
48
|
-
setOpen(false)
|
|
49
|
-
untrack(() => mergedProps.onCancel?.())
|
|
50
|
-
}}
|
|
51
|
-
>
|
|
52
|
-
{mergedProps.cancelText}
|
|
53
|
-
</Button>
|
|
54
|
-
<Button
|
|
55
|
-
class="ant-ml-8px"
|
|
56
|
-
type="primary"
|
|
57
|
-
size="small"
|
|
58
|
-
onClick={() => {
|
|
59
|
-
setOpen(false)
|
|
60
|
-
untrack(() => mergedProps.onConfirm?.())
|
|
61
|
-
}}
|
|
62
|
-
>
|
|
63
|
-
{mergedProps.okText}
|
|
64
|
-
</Button>
|
|
65
|
-
</div>
|
|
66
|
-
</div>
|
|
67
|
-
}
|
|
68
|
-
{...tooltipProps}
|
|
69
|
-
>
|
|
70
|
-
{mergedProps.children}
|
|
71
|
-
</Tooltip>
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export default Popconfirm
|
package/src/Popover.tsx
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { type Component, type JSXElement, Show } from 'solid-js'
|
|
2
|
-
import Tooltip, { Content, type TooltipProps } from './Tooltip'
|
|
3
|
-
|
|
4
|
-
interface PopoverProps extends TooltipProps {
|
|
5
|
-
title?: JSXElement
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const Popover: Component<PopoverProps> = props => {
|
|
9
|
-
return (
|
|
10
|
-
<Tooltip
|
|
11
|
-
mode="light"
|
|
12
|
-
{...props}
|
|
13
|
-
content={close =>
|
|
14
|
-
<div>
|
|
15
|
-
<Show when={props.title}>
|
|
16
|
-
<div class="ant-mb-8px ant-flex ant-items-center">
|
|
17
|
-
<span class="ant-text-[rgba(0,0,0,0.88)] ant-font-600">{props.title}</span>
|
|
18
|
-
</div>
|
|
19
|
-
</Show>
|
|
20
|
-
|
|
21
|
-
<div class="ant-text-[rgba(0,0,0,0.88)]">
|
|
22
|
-
<Content content={props.content} close={close} />
|
|
23
|
-
</div>
|
|
24
|
-
</div>
|
|
25
|
-
}
|
|
26
|
-
/>
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default Popover
|