antd-solid 0.0.5 → 0.0.6
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/package.json +3 -2
- package/src/Button.tsx +125 -0
- package/src/Collapse/index.tsx +86 -0
- package/src/ColorPicker.tsx +11 -0
- package/src/Compact.tsx +15 -0
- package/src/DatePicker.tsx +22 -0
- package/src/Empty/PRESENTED_IMAGE_SIMPLE.tsx +15 -0
- package/src/Empty/assets/EmptySvg.tsx +43 -0
- package/src/Empty/assets/SimpleEmptySvg.tsx +16 -0
- package/src/Empty/index.tsx +20 -0
- package/src/Image.tsx +29 -0
- package/src/Input.tsx +202 -0
- package/src/InputNumber.test.tsx +46 -0
- package/src/InputNumber.tsx +125 -0
- package/src/Modal.tsx +196 -0
- package/src/Popconfirm.tsx +75 -0
- package/src/Popover.tsx +30 -0
- package/src/Progress.tsx +4 -0
- package/src/Radio.tsx +132 -0
- package/src/Result.tsx +38 -0
- package/src/Segmented/index.tsx +95 -0
- package/src/Select.tsx +128 -0
- package/src/Skeleton.tsx +14 -0
- package/src/Spin.tsx +23 -0
- package/src/Switch.tsx +34 -0
- package/src/Table.tsx +53 -0
- package/src/Tabs.tsx +131 -0
- package/src/Timeline.tsx +33 -0
- package/src/Tooltip.tsx +355 -0
- package/src/Tree.tsx +246 -0
- package/src/Upload.tsx +10 -0
- package/src/form/Form.tsx +94 -0
- package/src/form/FormItem.tsx +139 -0
- package/src/form/context.ts +16 -0
- package/src/form/index.ts +13 -0
- package/src/hooks/createControllableValue.ts +68 -0
- package/src/hooks/createUpdateEffect.ts +16 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useClickAway.ts +18 -0
- package/src/hooks/useSize.ts +26 -0
- package/src/types/index.ts +5 -0
- package/src/utils/EventEmitter.ts +15 -0
- package/src/utils/ReactToSolid.tsx +38 -0
- package/src/utils/SolidToReact.tsx +27 -0
- package/src/utils/array.ts +21 -0
- package/src/utils/component.tsx +85 -0
- package/src/utils/solid.ts +53 -0
- package/src/utils/zh_CN.ts +236 -0
- package/dist/index.esm.js +0 -2369
- package/dist/index.umd.js +0 -1
|
@@ -0,0 +1,125 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
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
|
|
@@ -0,0 +1,75 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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
|
package/src/Progress.tsx
ADDED
package/src/Radio.tsx
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Component,
|
|
3
|
+
type JSXElement,
|
|
4
|
+
type ParentProps,
|
|
5
|
+
type JSX,
|
|
6
|
+
untrack,
|
|
7
|
+
For,
|
|
8
|
+
createSelector,
|
|
9
|
+
mergeProps,
|
|
10
|
+
} from 'solid-js'
|
|
11
|
+
import { Dynamic } from 'solid-js/web'
|
|
12
|
+
import cs from 'classnames'
|
|
13
|
+
import createControllableValue from './hooks/createControllableValue'
|
|
14
|
+
|
|
15
|
+
export interface RadioProps extends ParentProps {
|
|
16
|
+
defaultChecked?: boolean
|
|
17
|
+
checked?: boolean
|
|
18
|
+
/**
|
|
19
|
+
* input 的 value
|
|
20
|
+
*/
|
|
21
|
+
value?: string
|
|
22
|
+
onChange?: JSX.ChangeEventHandler<HTMLInputElement, Event>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface RadioGroupProps {
|
|
26
|
+
defaultValue?: string
|
|
27
|
+
value?: string
|
|
28
|
+
onChange?: JSX.ChangeEventHandler<HTMLInputElement, Event>
|
|
29
|
+
optionType?: 'default' | 'button'
|
|
30
|
+
options: Array<{ label: JSXElement; value: string; disabled?: boolean }>
|
|
31
|
+
block?: boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const Radio: Component<RadioProps> & {
|
|
35
|
+
Group: Component<RadioGroupProps>
|
|
36
|
+
Button: Component<RadioProps>
|
|
37
|
+
} = props => {
|
|
38
|
+
const [checked, setChecked] = createControllableValue(props, {
|
|
39
|
+
defaultValue: false,
|
|
40
|
+
defaultValuePropName: 'defaultChecked',
|
|
41
|
+
valuePropName: 'checked',
|
|
42
|
+
trigger: undefined,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<label class="ant-inline-flex ant-gap-4px">
|
|
47
|
+
<input
|
|
48
|
+
checked={checked()}
|
|
49
|
+
value={props.value ?? ''}
|
|
50
|
+
type="radio"
|
|
51
|
+
onInput={e => {
|
|
52
|
+
setChecked(e.target.checked)
|
|
53
|
+
untrack(() => props.onChange?.(e))
|
|
54
|
+
}}
|
|
55
|
+
/>
|
|
56
|
+
{props.children}
|
|
57
|
+
</label>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
Radio.Button = props => {
|
|
62
|
+
const [checked, setChecked] = createControllableValue(props, {
|
|
63
|
+
defaultValue: false,
|
|
64
|
+
defaultValuePropName: 'defaultChecked',
|
|
65
|
+
valuePropName: 'checked',
|
|
66
|
+
trigger: undefined,
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<label
|
|
71
|
+
class={cs(
|
|
72
|
+
'ant-px-15px ant-[border:1px_solid_rgb(217,217,217)] first:ant-rounded-l-6px last:ant-rounded-r-6px ant-h-32px ant-inline-flex ant-items-center hover:ant-text-[var(--primary-color)] not[:last-child]:ant-border-r-transparent ant-cursor-pointer ant-flex-grow ant-justify-center',
|
|
73
|
+
checked() &&
|
|
74
|
+
'ant-text-[var(--primary-color)] ant-[border:1px_solid_var(--primary-color)] !ant-border-r-[var(--primary-color)]',
|
|
75
|
+
)}
|
|
76
|
+
>
|
|
77
|
+
<input
|
|
78
|
+
class="ant-w-0 ant-h-0"
|
|
79
|
+
checked={checked()}
|
|
80
|
+
value={props.value ?? ''}
|
|
81
|
+
type="radio"
|
|
82
|
+
onInput={e => {
|
|
83
|
+
setChecked(e.target.checked)
|
|
84
|
+
untrack(() => props.onChange?.(e))
|
|
85
|
+
}}
|
|
86
|
+
/>
|
|
87
|
+
{props.children}
|
|
88
|
+
</label>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
Radio.Group = _props => {
|
|
93
|
+
const props = mergeProps(
|
|
94
|
+
{
|
|
95
|
+
optionType: 'default',
|
|
96
|
+
} as RadioGroupProps,
|
|
97
|
+
_props,
|
|
98
|
+
)
|
|
99
|
+
const [value, setValue] = createControllableValue<string>(props, {
|
|
100
|
+
trigger: undefined,
|
|
101
|
+
})
|
|
102
|
+
const isChecked = createSelector(value)
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div
|
|
106
|
+
class={cs(
|
|
107
|
+
props.block ? 'ant-flex' : 'ant-inline-flex',
|
|
108
|
+
props.optionType === 'default' ? 'ant-gap-8px' : '',
|
|
109
|
+
)}
|
|
110
|
+
>
|
|
111
|
+
<For each={props.options}>
|
|
112
|
+
{option => (
|
|
113
|
+
<Dynamic
|
|
114
|
+
component={props.optionType === 'default' ? Radio : Radio.Button}
|
|
115
|
+
checked={isChecked(option.value)}
|
|
116
|
+
value={option.value}
|
|
117
|
+
onChange={
|
|
118
|
+
(e => {
|
|
119
|
+
setValue(option.value)
|
|
120
|
+
untrack(() => props.onChange?.(e))
|
|
121
|
+
}) as JSX.ChangeEventHandler<HTMLInputElement, Event>
|
|
122
|
+
}
|
|
123
|
+
>
|
|
124
|
+
{option.label}
|
|
125
|
+
</Dynamic>
|
|
126
|
+
)}
|
|
127
|
+
</For>
|
|
128
|
+
</div>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export default Radio
|
package/src/Result.tsx
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type JSXElement, type Component, type ParentProps } from 'solid-js'
|
|
2
|
+
import cs from 'classnames'
|
|
3
|
+
|
|
4
|
+
type ResultStatusType = 'success' | 'error' | 'info' | 'warning'
|
|
5
|
+
|
|
6
|
+
export interface ResultProps extends ParentProps {
|
|
7
|
+
status?: ResultStatusType
|
|
8
|
+
title?: JSXElement
|
|
9
|
+
subTitle?: JSXElement
|
|
10
|
+
extra?: JSXElement
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const statusIconMap = {
|
|
14
|
+
success: 'ant-text-#52c41a i-ant-design:check-circle-filled',
|
|
15
|
+
info: 'ant-text-[var(--primary-color)] i-ant-design:exclamation-circle-filled',
|
|
16
|
+
warning: 'ant-text-#faad14 i-ant-design:warning-filled',
|
|
17
|
+
error: 'ant-text-#ff4d4f i-ant-design:close-circle-filled',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const Result: Component<ResultProps> = props => {
|
|
21
|
+
return (
|
|
22
|
+
<div class="ant-text-center ant-px-32px ant-py-48px">
|
|
23
|
+
<div class="ant-mb-24px">
|
|
24
|
+
<span class={cs(statusIconMap[props.status!], 'ant-text-72px')} />
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
<div class="ant-my-8px ant-text-[rgba(0,0,0,.88)] ant-text-24px">{props.title}</div>
|
|
28
|
+
|
|
29
|
+
<div class="ant-text-[rgba(0,0,0,.45)] ant-text-14px">{props.subTitle}</div>
|
|
30
|
+
|
|
31
|
+
<div class="ant-mt-24px">{props.extra}</div>
|
|
32
|
+
|
|
33
|
+
<div class="ant-mt-24px">{props.children}</div>
|
|
34
|
+
</div>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default Result
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type Component, For, createSelector, type JSX, Show } from 'solid-js'
|
|
2
|
+
import cs from 'classnames'
|
|
3
|
+
import { type StringOrJSXElement, type Key } from '../types'
|
|
4
|
+
import createControllableValue from '../hooks/createControllableValue'
|
|
5
|
+
import { unwrapStringOrJSXElement } from '../utils/solid'
|
|
6
|
+
|
|
7
|
+
export interface SegmentedProps {
|
|
8
|
+
block?: boolean
|
|
9
|
+
disabled?: boolean
|
|
10
|
+
options: Array<
|
|
11
|
+
| string
|
|
12
|
+
| number
|
|
13
|
+
| {
|
|
14
|
+
label: StringOrJSXElement
|
|
15
|
+
value: string
|
|
16
|
+
disabled?: boolean
|
|
17
|
+
onClick?: (
|
|
18
|
+
e: MouseEvent & {
|
|
19
|
+
currentTarget: HTMLDivElement
|
|
20
|
+
target: Element
|
|
21
|
+
},
|
|
22
|
+
) => void
|
|
23
|
+
}
|
|
24
|
+
>
|
|
25
|
+
value?: Key
|
|
26
|
+
onChange?: (value: Key) => void
|
|
27
|
+
class?: string
|
|
28
|
+
style?: JSX.CSSProperties
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const unWarpValue = (value: SegmentedProps['options'][0]) =>
|
|
32
|
+
typeof value === 'object' ? value.value : value
|
|
33
|
+
|
|
34
|
+
const Segmented: Component<SegmentedProps> = props => {
|
|
35
|
+
const [value, setValue] = createControllableValue<Key>(props, {
|
|
36
|
+
defaultValue: unWarpValue(props.options[0]),
|
|
37
|
+
})
|
|
38
|
+
const isSelected = createSelector(value)
|
|
39
|
+
|
|
40
|
+
const isDisabledValue = (v: SegmentedProps['options'][0]) => {
|
|
41
|
+
if (props.disabled) return true
|
|
42
|
+
return typeof v === 'object' ? v.disabled : false
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div
|
|
47
|
+
class={cs(
|
|
48
|
+
'ant-bg-[var(--ant-color-bg-layout)] ant-rounded-[var(--ant-border-radius)] ant-p-2px',
|
|
49
|
+
props.block ? 'ant-flex' : 'ant-inline-flex',
|
|
50
|
+
props.class,
|
|
51
|
+
)}
|
|
52
|
+
style={{
|
|
53
|
+
'--ant-segmented-item-color': 'rgba(0, 0, 0, 0.65)',
|
|
54
|
+
'--ant-segmented-item-hover-bg': 'rgba(0, 0, 0, 0.06)',
|
|
55
|
+
'--ant-segmented-item-active-bg': 'rgba(0, 0, 0, 0.15)',
|
|
56
|
+
...props.style,
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
<For each={props.options}>
|
|
60
|
+
{item => (
|
|
61
|
+
<div
|
|
62
|
+
class={cs(
|
|
63
|
+
props.block && 'ant-basis-0 ant-grow-1',
|
|
64
|
+
isDisabledValue(item) && 'ant-cursor-not-allowed',
|
|
65
|
+
)}
|
|
66
|
+
>
|
|
67
|
+
<div
|
|
68
|
+
class={cs(
|
|
69
|
+
'ant-rounded-[var(--ant-border-radius-sm)] ant-px-[var(--ant-padding-sm)] where:ant-cursor-pointer ant-leading-28px where:hover:ant-bg-[var(--ant-segmented-item-hover-bg)] where:active:ant-bg-[var(--ant-segmented-item-active-bg)]',
|
|
70
|
+
isSelected(unWarpValue(item)) &&
|
|
71
|
+
'ant-bg-white ant-shadow-[var(--ant-box-shadow-tertiary)]',
|
|
72
|
+
props.block && 'ant-flex ant-justify-center',
|
|
73
|
+
isDisabledValue(item) &&
|
|
74
|
+
'ant-[pointer-events:none] ant-text-[var(--ant-color-text-disabled)]',
|
|
75
|
+
)}
|
|
76
|
+
onClick={e => {
|
|
77
|
+
setValue(unWarpValue(item))
|
|
78
|
+
typeof item === 'object' && item.onClick?.(e)
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
<Show
|
|
82
|
+
when={typeof item !== 'object'}
|
|
83
|
+
fallback={typeof item === 'object' && unwrapStringOrJSXElement(item.label)}
|
|
84
|
+
>
|
|
85
|
+
{item as string | number}
|
|
86
|
+
</Show>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
)}
|
|
90
|
+
</For>
|
|
91
|
+
</div>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export default Segmented
|