antd-solid 0.0.2
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/.eslintrc.cjs +36 -0
- package/.prettierrc +11 -0
- package/.vscode/settings.json +13 -0
- package/README.md +11 -0
- package/docs/.vitepress/components/Code.vue +59 -0
- package/docs/.vitepress/config.ts +49 -0
- package/docs/.vitepress/theme/index.css +15 -0
- package/docs/.vitepress/theme/index.ts +13 -0
- package/docs/components/Button.tsx +20 -0
- package/docs/components/Table.tsx +34 -0
- package/docs/components/button.md +23 -0
- package/docs/components/table.md +23 -0
- package/docs/index.md +28 -0
- package/package.json +62 -0
- package/rollup.config.js +25 -0
- package/src/Button.css +14 -0
- package/src/Button.tsx +86 -0
- package/src/ColorPicker.tsx +66 -0
- package/src/DatePicker.tsx +12 -0
- package/src/Form.tsx +98 -0
- package/src/Image.tsx +29 -0
- package/src/Input.tsx +110 -0
- package/src/InputNumber.test.tsx +46 -0
- package/src/InputNumber.tsx +119 -0
- package/src/Modal.tsx +168 -0
- package/src/Popconfirm.tsx +73 -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/Select.tsx +6 -0
- package/src/Skeleton.tsx +14 -0
- package/src/Spin.tsx +23 -0
- package/src/Switch.tsx +34 -0
- package/src/Table.tsx +46 -0
- package/src/Tabs.tsx +88 -0
- package/src/Timeline.tsx +33 -0
- package/src/Tooltip.tsx +209 -0
- package/src/Tree.tsx +246 -0
- package/src/Upload.tsx +10 -0
- package/src/hooks/createControllableValue.ts +65 -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/index.css +21 -0
- package/src/index.ts +37 -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 +48 -0
- package/tsconfig.json +23 -0
- package/unocss.config.ts +92 -0
package/src/Tree.tsx
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { isEmpty } from 'lodash-es'
|
|
2
|
+
import {
|
|
3
|
+
type Accessor,
|
|
4
|
+
createContext,
|
|
5
|
+
createSignal,
|
|
6
|
+
Index,
|
|
7
|
+
type JSXElement,
|
|
8
|
+
type Setter,
|
|
9
|
+
Show,
|
|
10
|
+
untrack,
|
|
11
|
+
useContext,
|
|
12
|
+
createSelector,
|
|
13
|
+
} from 'solid-js'
|
|
14
|
+
import cs from 'classnames'
|
|
15
|
+
|
|
16
|
+
export interface TreeProps<T extends {} = {}> {
|
|
17
|
+
class?: string
|
|
18
|
+
defaultSelectedNodes?: T[]
|
|
19
|
+
treeData?: T[]
|
|
20
|
+
/**
|
|
21
|
+
* 是否节点占据一行
|
|
22
|
+
*/
|
|
23
|
+
blockNode?: boolean
|
|
24
|
+
defaultExpandAll?: boolean
|
|
25
|
+
/**
|
|
26
|
+
* 设置节点可拖拽
|
|
27
|
+
*/
|
|
28
|
+
draggable?: boolean
|
|
29
|
+
titleRender: (
|
|
30
|
+
node: T,
|
|
31
|
+
info: {
|
|
32
|
+
indexes: number[]
|
|
33
|
+
},
|
|
34
|
+
) => JSXElement
|
|
35
|
+
children: (node: T) => T[] | undefined
|
|
36
|
+
onSelect?: (node: T) => void
|
|
37
|
+
onDrop?: (info: {
|
|
38
|
+
dragNode: T
|
|
39
|
+
targetNode: T
|
|
40
|
+
dragIndexes: number[]
|
|
41
|
+
targetIndexes: number[]
|
|
42
|
+
}) => void
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface SingleLevelTreeProps<T extends {} = {}> extends Omit<TreeProps<T>, 'class'> {
|
|
46
|
+
indent: number
|
|
47
|
+
parentIndexes?: number[]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const TreeContext = createContext(
|
|
51
|
+
{} as unknown as {
|
|
52
|
+
selectedNodes: Accessor<Array<{}>>
|
|
53
|
+
setSelectedNodes: Setter<Array<{}>>
|
|
54
|
+
draggableNode: Accessor<{} | null>
|
|
55
|
+
setDraggableNode: Setter<{} | null>
|
|
56
|
+
draggableIndexes: Accessor<number[] | null>
|
|
57
|
+
setDraggableIndexes: Setter<number[] | null>
|
|
58
|
+
isDraggable: (key: {} | null) => boolean
|
|
59
|
+
targetNode: Accessor<{} | null>
|
|
60
|
+
setTargetNode: Setter<{} | null>
|
|
61
|
+
targetIndexes: Accessor<number[] | null>
|
|
62
|
+
setTargetIndexes: Setter<number[] | null>
|
|
63
|
+
isTarget: (key: {} | null) => boolean
|
|
64
|
+
draggable: TreeProps['draggable'] | undefined
|
|
65
|
+
onDrop: TreeProps['onDrop'] | undefined
|
|
66
|
+
},
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 单层级 tree
|
|
71
|
+
*/
|
|
72
|
+
function SingleLevelTree<T extends {} = {}>(props: SingleLevelTreeProps<T>) {
|
|
73
|
+
const [expanded, setExpanded] = createSignal(props.defaultExpandAll)
|
|
74
|
+
const {
|
|
75
|
+
selectedNodes,
|
|
76
|
+
setSelectedNodes,
|
|
77
|
+
draggableNode,
|
|
78
|
+
setDraggableNode,
|
|
79
|
+
draggableIndexes,
|
|
80
|
+
setDraggableIndexes,
|
|
81
|
+
isDraggable,
|
|
82
|
+
targetNode,
|
|
83
|
+
setTargetNode,
|
|
84
|
+
targetIndexes,
|
|
85
|
+
setTargetIndexes,
|
|
86
|
+
isTarget,
|
|
87
|
+
draggable,
|
|
88
|
+
onDrop,
|
|
89
|
+
} = useContext(TreeContext)
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<Index each={props.treeData}>
|
|
93
|
+
{(item, i) => {
|
|
94
|
+
const indexes = [...(props.parentIndexes ?? []), i]
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<>
|
|
98
|
+
<div
|
|
99
|
+
class={cs(
|
|
100
|
+
'ant-flex ant-items-center ant-h-28px ant-pb-4px',
|
|
101
|
+
isDraggable(item()) && 'ant-[border:1px_solid_var(--primary-color)] ant-bg-white',
|
|
102
|
+
draggableNode() && 'child[]:ant-pointer-events-none',
|
|
103
|
+
)}
|
|
104
|
+
draggable={draggable}
|
|
105
|
+
onDragStart={() => {
|
|
106
|
+
setDraggableNode(item() as {})
|
|
107
|
+
setDraggableIndexes(indexes)
|
|
108
|
+
}}
|
|
109
|
+
onDragEnter={() => {
|
|
110
|
+
if (item() !== draggableNode()) {
|
|
111
|
+
setTargetNode(item() as {})
|
|
112
|
+
setTargetIndexes(indexes)
|
|
113
|
+
}
|
|
114
|
+
}}
|
|
115
|
+
onDragLeave={e => {
|
|
116
|
+
if (item() === targetNode() && e.relatedTarget) {
|
|
117
|
+
setTargetNode(null)
|
|
118
|
+
setTargetIndexes(null)
|
|
119
|
+
}
|
|
120
|
+
}}
|
|
121
|
+
onDragEnd={() => {
|
|
122
|
+
onDrop?.({
|
|
123
|
+
dragNode: draggableNode()!,
|
|
124
|
+
dragIndexes: draggableIndexes()!,
|
|
125
|
+
targetNode: targetNode()!,
|
|
126
|
+
targetIndexes: targetIndexes()!,
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
setDraggableNode(null)
|
|
130
|
+
setDraggableIndexes(null)
|
|
131
|
+
setTargetNode(null)
|
|
132
|
+
setTargetIndexes(null)
|
|
133
|
+
}}
|
|
134
|
+
>
|
|
135
|
+
<div class="flex-shrink-0" role={'indent' as any}>
|
|
136
|
+
{/* eslint-disable-next-line solid/prefer-for */}
|
|
137
|
+
{Array(props.indent)
|
|
138
|
+
.fill(0)
|
|
139
|
+
.map(() => (
|
|
140
|
+
<span class="ant-inline-block ant-w-24px" />
|
|
141
|
+
))}
|
|
142
|
+
</div>
|
|
143
|
+
<div class="ant-flex-shrink-0 ant-w-24px ant-h-24px ant-flex ant-items-center ant-justify-center">
|
|
144
|
+
<span class="i-ant-design:holder-outlined" />
|
|
145
|
+
</div>
|
|
146
|
+
<div
|
|
147
|
+
class={cs(
|
|
148
|
+
'ant-flex-shrink-0 ant-w-24px ant-h-24px ant-flex ant-items-center ant-justify-center ant-cursor-pointer',
|
|
149
|
+
isEmpty(props.children(item())) && 'opacity-0',
|
|
150
|
+
)}
|
|
151
|
+
>
|
|
152
|
+
<Show
|
|
153
|
+
when={expanded()}
|
|
154
|
+
fallback={
|
|
155
|
+
<span
|
|
156
|
+
class={'i-ant-design:plus-square-outlined'}
|
|
157
|
+
onClick={[setExpanded, true]}
|
|
158
|
+
/>
|
|
159
|
+
}
|
|
160
|
+
>
|
|
161
|
+
<span
|
|
162
|
+
class={'i-ant-design:minus-square-outlined'}
|
|
163
|
+
onClick={[setExpanded, false]}
|
|
164
|
+
/>
|
|
165
|
+
</Show>
|
|
166
|
+
</div>
|
|
167
|
+
<div
|
|
168
|
+
class={cs(
|
|
169
|
+
'ant-h-full ant-leading-24px ant-hover:bg-[rgba(0,0,0,.04)] ant-rounded-1 ant-px-1 ant-cursor-pointer ant-relative',
|
|
170
|
+
props.blockNode && 'w-full',
|
|
171
|
+
selectedNodes()?.includes(item()) && '!ant-bg-[var(--active-bg-color)]',
|
|
172
|
+
isTarget(item()) &&
|
|
173
|
+
"before:ant-content-[''] before:ant-inline-block before:ant-w-8px before:ant-h-8px before:ant-absolute before:ant-bottom-0 before:ant-left-0 before:-ant-translate-x-full before:ant-translate-y-1/2 before:ant-rounded-1/2 before:ant-[border:2px_solid_var(--primary-color)] after:ant-content-[''] after:ant-inline-block after:ant-h-2px after:ant-absolute after:ant-left-0 after:ant-right-0 after:ant-bottom--1px after:ant-bg-[var(--primary-color)]",
|
|
174
|
+
)}
|
|
175
|
+
onClick={() => {
|
|
176
|
+
setSelectedNodes([item()])
|
|
177
|
+
props.onSelect?.(item())
|
|
178
|
+
}}
|
|
179
|
+
>
|
|
180
|
+
{props.titleRender(item(), { indexes })}
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<Show when={expanded() && !isEmpty(props.children(item()))}>
|
|
185
|
+
<SingleLevelTree
|
|
186
|
+
treeData={props.children(item())}
|
|
187
|
+
indent={props.indent + 1}
|
|
188
|
+
parentIndexes={indexes}
|
|
189
|
+
blockNode={props.blockNode}
|
|
190
|
+
defaultExpandAll={props.defaultExpandAll}
|
|
191
|
+
titleRender={props.titleRender}
|
|
192
|
+
children={props.children}
|
|
193
|
+
onSelect={node => untrack(() => props.onSelect?.(node))}
|
|
194
|
+
/>
|
|
195
|
+
</Show>
|
|
196
|
+
</>
|
|
197
|
+
)
|
|
198
|
+
}}
|
|
199
|
+
</Index>
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function Tree<T extends {} = {}>(props: TreeProps<T>) {
|
|
204
|
+
const [selectedNodes, setSelectedNodes] = createSignal<T[]>(props.defaultSelectedNodes ?? [])
|
|
205
|
+
|
|
206
|
+
const [draggableNode, setDraggableNode] = createSignal<T | null>(null)
|
|
207
|
+
const isDraggable = createSelector<T | null, T | null>(draggableNode)
|
|
208
|
+
const [draggableIndexes, setDraggableIndexes] = createSignal<number[] | null>(null)
|
|
209
|
+
|
|
210
|
+
const [targetNode, setTargetNode] = createSignal<T | null>(null)
|
|
211
|
+
const isTarget = createSelector<T | null, T | null>(targetNode)
|
|
212
|
+
const [targetIndexes, setTargetIndexes] = createSignal<number[] | null>(null)
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<TreeContext.Provider
|
|
216
|
+
value={{
|
|
217
|
+
selectedNodes,
|
|
218
|
+
setSelectedNodes,
|
|
219
|
+
draggableNode,
|
|
220
|
+
setDraggableNode,
|
|
221
|
+
draggableIndexes,
|
|
222
|
+
setDraggableIndexes,
|
|
223
|
+
isDraggable,
|
|
224
|
+
targetNode,
|
|
225
|
+
setTargetNode,
|
|
226
|
+
targetIndexes,
|
|
227
|
+
setTargetIndexes,
|
|
228
|
+
isTarget,
|
|
229
|
+
draggable: props.draggable,
|
|
230
|
+
onDrop: props.onDrop,
|
|
231
|
+
}}
|
|
232
|
+
>
|
|
233
|
+
<SingleLevelTree
|
|
234
|
+
treeData={props.treeData}
|
|
235
|
+
indent={0}
|
|
236
|
+
blockNode={props.blockNode}
|
|
237
|
+
defaultExpandAll={props.defaultExpandAll}
|
|
238
|
+
titleRender={props.titleRender}
|
|
239
|
+
children={props.children}
|
|
240
|
+
onSelect={node => untrack(() => props.onSelect?.(node))}
|
|
241
|
+
/>
|
|
242
|
+
</TreeContext.Provider>
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export default Tree
|
package/src/Upload.tsx
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { reactToSolidComponent, replaceChildren, replaceClassName } from './utils/component'
|
|
2
|
+
import { Upload as UploadAntd } from 'antd'
|
|
3
|
+
|
|
4
|
+
export type { UploadFile } from 'antd/es/upload'
|
|
5
|
+
|
|
6
|
+
const Upload = replaceChildren(replaceClassName(reactToSolidComponent(UploadAntd)))
|
|
7
|
+
|
|
8
|
+
export type UploadProps = Parameters<typeof Upload>[0]
|
|
9
|
+
|
|
10
|
+
export default Upload
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Setter, Signal, createSignal } from 'solid-js'
|
|
2
|
+
import createUpdateEffect from './createUpdateEffect'
|
|
3
|
+
|
|
4
|
+
export interface Options<T> {
|
|
5
|
+
defaultValue?: T
|
|
6
|
+
defaultValuePropName?: string
|
|
7
|
+
valuePropName?: string
|
|
8
|
+
trigger?: string | undefined
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type Props = Record<string, any>
|
|
12
|
+
|
|
13
|
+
export interface StandardProps<T> {
|
|
14
|
+
value: T
|
|
15
|
+
defaultValue?: T
|
|
16
|
+
onChange: (val: T) => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function createControllableValue<T = any>(props: StandardProps<T>): Signal<T>
|
|
20
|
+
function createControllableValue<T = any>(props: Props, options?: Options<T>): Signal<T>
|
|
21
|
+
function createControllableValue<T = any>(props: Props, options: Options<T> = {}) {
|
|
22
|
+
const {
|
|
23
|
+
defaultValuePropName = 'defaultValue',
|
|
24
|
+
valuePropName = 'value',
|
|
25
|
+
trigger = 'onChange',
|
|
26
|
+
} = options
|
|
27
|
+
|
|
28
|
+
const getValue = () => props[valuePropName] as T
|
|
29
|
+
// 为什么不使用 Object.hasOwn?
|
|
30
|
+
// solid 的 proxy 对象对于任何 key,都会返回 true
|
|
31
|
+
const isControlled = () => Object.keys(props).includes(valuePropName)
|
|
32
|
+
|
|
33
|
+
let defaultValue = options.defaultValue
|
|
34
|
+
if (isControlled()) {
|
|
35
|
+
defaultValue = getValue()
|
|
36
|
+
} else if (Object.keys(props).includes(defaultValuePropName)) {
|
|
37
|
+
defaultValue = props[defaultValuePropName]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const [value, _setValue] = createSignal(defaultValue)
|
|
41
|
+
|
|
42
|
+
createUpdateEffect(getValue, () => {
|
|
43
|
+
if (!isControlled()) return
|
|
44
|
+
|
|
45
|
+
// @ts-expect-error
|
|
46
|
+
_setValue(getValue())
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const setValue: Setter<T> = (v => {
|
|
50
|
+
const newValue = _setValue(v)
|
|
51
|
+
|
|
52
|
+
if (trigger) {
|
|
53
|
+
const onChange = props[trigger]
|
|
54
|
+
if (typeof onChange === 'function') {
|
|
55
|
+
onChange(newValue)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return newValue
|
|
60
|
+
}) as Setter<T>
|
|
61
|
+
|
|
62
|
+
return [value, setValue] as Signal<T>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default createControllableValue
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createEffect, on } from 'solid-js'
|
|
2
|
+
import type { Accessor, AccessorArray, NoInfer, OnEffectFunction } from 'solid-js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 等同于 createEffect,但是会忽略首次执行,只在依赖更新时执行。
|
|
6
|
+
*/
|
|
7
|
+
export default function createUpdateEffect<S, Next extends Prev, Prev = Next>(
|
|
8
|
+
deps: AccessorArray<S> | Accessor<S>,
|
|
9
|
+
fn: OnEffectFunction<S, undefined | NoInfer<Prev>, Next>,
|
|
10
|
+
) {
|
|
11
|
+
createEffect(
|
|
12
|
+
on(deps, fn, {
|
|
13
|
+
defer: true,
|
|
14
|
+
}),
|
|
15
|
+
)
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Accessor, onCleanup } from 'solid-js'
|
|
2
|
+
import { toArray } from '../utils/array'
|
|
3
|
+
|
|
4
|
+
export default function useClickAway<T extends Event = Event>(
|
|
5
|
+
onClickAway: (event: T) => void,
|
|
6
|
+
target?: Accessor<Element | Element[]>,
|
|
7
|
+
) {
|
|
8
|
+
const onClick = (event: Event) => {
|
|
9
|
+
const targets = target ? toArray(target()) : []
|
|
10
|
+
if (targets.every(item => !item.contains(event.target as Node))) {
|
|
11
|
+
onClickAway(event as T)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
document.body.addEventListener('click', onClick)
|
|
15
|
+
onCleanup(() => {
|
|
16
|
+
document.body.removeEventListener('click', onClick)
|
|
17
|
+
})
|
|
18
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Accessor, createSignal, onCleanup, onMount } from 'solid-js'
|
|
2
|
+
|
|
3
|
+
function getTarget(target: Element | Accessor<Element>) {
|
|
4
|
+
return target instanceof Element ? target : target()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default function useSize(target: Element | Accessor<Element>) {
|
|
8
|
+
const [size, setSize] = createSignal<{
|
|
9
|
+
width: number
|
|
10
|
+
height: number
|
|
11
|
+
}>()
|
|
12
|
+
|
|
13
|
+
onMount(() => {
|
|
14
|
+
const _target = getTarget(target)
|
|
15
|
+
const ro = new ResizeObserver(() => {
|
|
16
|
+
setSize({
|
|
17
|
+
width: _target.clientWidth,
|
|
18
|
+
height: _target.clientHeight,
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
ro.observe(_target)
|
|
22
|
+
onCleanup(() => ro.disconnect())
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return size
|
|
26
|
+
}
|
package/src/index.css
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
body {
|
|
2
|
+
--primary-color: #52c41a;
|
|
3
|
+
--light-primary-color: #95de64;
|
|
4
|
+
--dark-primary-color: #237804;
|
|
5
|
+
--active-bg-color: #d9f7be;
|
|
6
|
+
|
|
7
|
+
--error-color: #ff4d4f;
|
|
8
|
+
--warning-color: #faad14;
|
|
9
|
+
|
|
10
|
+
--border-color: #d9d9d9;
|
|
11
|
+
--secondary-border-color: #f0f0f0;
|
|
12
|
+
|
|
13
|
+
--light-color: rgba(0, 0, 0, 0.45);
|
|
14
|
+
--dark-color: rgba(0, 0, 0, 0.88);
|
|
15
|
+
|
|
16
|
+
--light-bg-color: #fafafa;
|
|
17
|
+
|
|
18
|
+
--secondary-border-color: #f0f0f0;
|
|
19
|
+
|
|
20
|
+
font-size: 14px;
|
|
21
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import 'uno.css'
|
|
2
|
+
|
|
3
|
+
export { default as Button } from './Button'
|
|
4
|
+
export { default as Input } from './Input'
|
|
5
|
+
export type { InputProps } from './Input'
|
|
6
|
+
export { default as InputNumber } from './InputNumber'
|
|
7
|
+
export type { InputNumberProps } from './InputNumber'
|
|
8
|
+
export { default as Timeline } from './Timeline'
|
|
9
|
+
export { default as Modal } from './Modal'
|
|
10
|
+
export { default as DatePicker } from './DatePicker'
|
|
11
|
+
export { default as Select } from './Select'
|
|
12
|
+
export { default as Tree } from './Tree'
|
|
13
|
+
export type { TreeProps } from './Tree'
|
|
14
|
+
export { default as Popover } from './Popover'
|
|
15
|
+
export { default as Tooltip } from './Tooltip'
|
|
16
|
+
export { default as ColorPicker } from './ColorPicker'
|
|
17
|
+
export type { ColorPickerProps } from './ColorPicker'
|
|
18
|
+
export { default as Result } from './Result'
|
|
19
|
+
export { default as Progress } from './Progress'
|
|
20
|
+
export { default as Tabs } from './Tabs'
|
|
21
|
+
export type { TabsProps, Tab } from './Tabs'
|
|
22
|
+
export { default as Popconfirm } from './Popconfirm'
|
|
23
|
+
export { default as Upload } from './Upload'
|
|
24
|
+
export type { UploadProps, UploadFile } from './Upload'
|
|
25
|
+
export { default as Radio } from './Radio'
|
|
26
|
+
export type { RadioProps, RadioGroupProps } from './Radio'
|
|
27
|
+
export { default as Form } from './Form'
|
|
28
|
+
export type { FormProps, FormItemProps, FormItemComponentProps } from './Form'
|
|
29
|
+
export { default as Switch } from './Switch'
|
|
30
|
+
export type { SwitchProps } from './Switch'
|
|
31
|
+
export { default as Skeleton } from './Skeleton'
|
|
32
|
+
export { default as Spin } from './Spin'
|
|
33
|
+
export { default as Image } from './Image'
|
|
34
|
+
export { default as Table } from './Table'
|
|
35
|
+
export type { TableProps, Column } from './Table'
|
|
36
|
+
|
|
37
|
+
export { message } from 'antd'
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
3
|
+
// import { renderToString } from 'react-dom/server'
|
|
4
|
+
import { onMount, onCleanup, createEffect, createMemo } from 'solid-js'
|
|
5
|
+
|
|
6
|
+
interface ReactToSolidProps<P extends {} = {}> {
|
|
7
|
+
component: React.FunctionComponent<P> | React.ComponentClass<P>
|
|
8
|
+
props: P
|
|
9
|
+
container?: Element
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function ReactToSolid<P extends {} = {}>(props: ReactToSolidProps<P>) {
|
|
13
|
+
let root: Root
|
|
14
|
+
|
|
15
|
+
const rootEle = createMemo(
|
|
16
|
+
() => props.container ?? ((<div role={'ReactToSolid' as any} />) as Element),
|
|
17
|
+
)
|
|
18
|
+
onMount(() => {
|
|
19
|
+
root = createRoot(rootEle())
|
|
20
|
+
onCleanup(() => {
|
|
21
|
+
root.unmount()
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
createEffect(() => {
|
|
26
|
+
root.render(React.createElement(props.component, { ...props.props }))
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// if (import.meta.env.SSR) {
|
|
30
|
+
// // eslint-disable-next-line solid/reactivity
|
|
31
|
+
// const node = React.createElement(props.component, { ...props.props })
|
|
32
|
+
// // eslint-disable-next-line solid/components-return-once, solid/no-innerhtml
|
|
33
|
+
// return <div innerHTML={renderToString(node)} />
|
|
34
|
+
// }
|
|
35
|
+
return <>{rootEle}</>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default ReactToSolid
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { type FunctionComponent, type ReactElement, useEffect, useRef } from 'react'
|
|
2
|
+
import { type JSX } from 'solid-js'
|
|
3
|
+
import { render } from 'solid-js/web'
|
|
4
|
+
|
|
5
|
+
export interface SolidToReactProps {
|
|
6
|
+
children?: JSX.Element
|
|
7
|
+
container?: ReactElement
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const SolidToReact: FunctionComponent<SolidToReactProps> = ({ children, container }) => {
|
|
11
|
+
const ref = useRef<HTMLDivElement>()
|
|
12
|
+
|
|
13
|
+
useEffect(() => render(() => children, ref.current!), [])
|
|
14
|
+
|
|
15
|
+
// if (import.meta.env.SSR) {
|
|
16
|
+
// return React.createElement('div', {
|
|
17
|
+
// dangerouslySetInnerHTML: { __html: renderToString(() => children) },
|
|
18
|
+
// })
|
|
19
|
+
// }
|
|
20
|
+
return container
|
|
21
|
+
? React.cloneElement(container, {
|
|
22
|
+
ref,
|
|
23
|
+
})
|
|
24
|
+
: React.createElement('div', { ref, role: 'SolidToReact' })
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default SolidToReact
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 如果传入一个非数组字段,则将其转化为数组
|
|
3
|
+
* @param value
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export function toArray<T>(value: T | T[]) {
|
|
7
|
+
return Array.isArray(value) ? value : [value]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface StandardNode {
|
|
11
|
+
children?: this[]
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 将数组中每个对象的 children 拍扁后返回
|
|
15
|
+
* @param nodes
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export function flatChildren<T extends StandardNode = StandardNode>(nodes: T[] | undefined): T[] {
|
|
19
|
+
if (!nodes) return []
|
|
20
|
+
return nodes.flatMap(node => [node, ...flatChildren(node.children)])
|
|
21
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { type Component, createMemo, type JSXElement } from 'solid-js'
|
|
3
|
+
import { omit } from 'lodash-es'
|
|
4
|
+
import { solidToReact } from './solid'
|
|
5
|
+
import ReactToSolid from './ReactToSolid'
|
|
6
|
+
import { ConfigProvider } from 'antd'
|
|
7
|
+
import zhCN from 'antd/locale/zh_CN'
|
|
8
|
+
import { type ConfigProviderProps } from 'antd/es/config-provider'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 将组件 props 中的 className 替换为 class
|
|
12
|
+
* @param C
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export function replaceClassName<
|
|
16
|
+
T extends { className?: string },
|
|
17
|
+
Target extends Omit<T, 'className'> & { class?: string },
|
|
18
|
+
>(C: Component<T>): Component<Target> {
|
|
19
|
+
return function (_props: Target) {
|
|
20
|
+
const props = createMemo(() => {
|
|
21
|
+
return {
|
|
22
|
+
...omit(_props, 'class'),
|
|
23
|
+
className: _props.class,
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
return <C {...(props() as unknown as T)} />
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 将组件 props 中的 children 替换为 JSXElement
|
|
32
|
+
* @param C
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
export function replaceChildren<
|
|
36
|
+
T extends { children?: React.ReactNode },
|
|
37
|
+
Target extends Omit<T, 'children'> & { children?: JSXElement },
|
|
38
|
+
>(C: Component<T>): Component<Target> {
|
|
39
|
+
return function (_props: Target) {
|
|
40
|
+
const props = createMemo(() => {
|
|
41
|
+
return {
|
|
42
|
+
..._props,
|
|
43
|
+
children: solidToReact(_props.children),
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
return <C {...(props() as unknown as T)} />
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function reactToSolidComponent<P extends {} = {}>(
|
|
51
|
+
component: React.FunctionComponent<P> | React.ComponentClass<P>,
|
|
52
|
+
container?: Element | (() => Element),
|
|
53
|
+
) {
|
|
54
|
+
return function (props: P) {
|
|
55
|
+
return (
|
|
56
|
+
<ReactToSolid
|
|
57
|
+
component={component}
|
|
58
|
+
props={props}
|
|
59
|
+
container={typeof container === 'function' ? container() : container}
|
|
60
|
+
/>
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 返回被 ConfigProvider 包裹后的 component
|
|
67
|
+
* @param component
|
|
68
|
+
* @param configProviderProps
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
export function configProvider<P extends {} = {}>(
|
|
72
|
+
component: React.FunctionComponent<P> | React.ComponentClass<P>,
|
|
73
|
+
configProviderProps?: ConfigProviderProps,
|
|
74
|
+
) {
|
|
75
|
+
return function (props: P) {
|
|
76
|
+
return React.createElement(
|
|
77
|
+
ConfigProvider,
|
|
78
|
+
{
|
|
79
|
+
locale: zhCN,
|
|
80
|
+
...configProviderProps,
|
|
81
|
+
},
|
|
82
|
+
React.createElement(component, props),
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { type JSXElement , type JSX } from 'solid-js'
|
|
3
|
+
import { isNil } from 'lodash-es'
|
|
4
|
+
import SolidToReact from './SolidToReact'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 判断 JSXElement 是否是基础类型
|
|
8
|
+
* @param value JSXElement
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export function isBaseType(
|
|
12
|
+
value: JSXElement,
|
|
13
|
+
): value is string | number | boolean | null | undefined {
|
|
14
|
+
return (
|
|
15
|
+
typeof value === 'string' ||
|
|
16
|
+
typeof value === 'number' ||
|
|
17
|
+
typeof value === 'boolean' ||
|
|
18
|
+
value === null ||
|
|
19
|
+
value === undefined
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function solidToReact(children: JSXElement) {
|
|
24
|
+
return isBaseType(children)
|
|
25
|
+
? children
|
|
26
|
+
: React.createElement(SolidToReact, {
|
|
27
|
+
children,
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function dispatchEventHandlerUnion<T, E extends Event>(
|
|
32
|
+
handler: JSX.EventHandlerUnion<T, E> | undefined,
|
|
33
|
+
e: E & {
|
|
34
|
+
currentTarget: T
|
|
35
|
+
target: Element
|
|
36
|
+
},
|
|
37
|
+
) {
|
|
38
|
+
if (isNil(handler)) {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (typeof handler === 'function') {
|
|
43
|
+
handler(e)
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
handler[0](handler[1], e);
|
|
48
|
+
}
|