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/Tooltip.tsx
DELETED
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
import { compact } from 'lodash-es'
|
|
2
|
-
import {
|
|
3
|
-
type Component,
|
|
4
|
-
type JSXElement,
|
|
5
|
-
type JSX,
|
|
6
|
-
children,
|
|
7
|
-
createEffect,
|
|
8
|
-
Show,
|
|
9
|
-
mergeProps,
|
|
10
|
-
onCleanup,
|
|
11
|
-
createMemo,
|
|
12
|
-
createSignal,
|
|
13
|
-
} from 'solid-js'
|
|
14
|
-
import { Portal } from 'solid-js/web'
|
|
15
|
-
import cs from 'classnames'
|
|
16
|
-
import createControllableValue from './hooks/createControllableValue'
|
|
17
|
-
import { useClickAway } from './hooks'
|
|
18
|
-
import { toArray } from './utils/array'
|
|
19
|
-
|
|
20
|
-
type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu'
|
|
21
|
-
type TooltipPlacement =
|
|
22
|
-
| 'top'
|
|
23
|
-
| 'left'
|
|
24
|
-
| 'right'
|
|
25
|
-
| 'bottom'
|
|
26
|
-
| 'topLeft'
|
|
27
|
-
| 'topRight'
|
|
28
|
-
| 'bottomLeft'
|
|
29
|
-
| 'bottomRight'
|
|
30
|
-
| 'leftTop'
|
|
31
|
-
| 'leftBottom'
|
|
32
|
-
| 'rightTop'
|
|
33
|
-
| 'rightBottom'
|
|
34
|
-
|
|
35
|
-
export interface TooltipProps {
|
|
36
|
-
/**
|
|
37
|
-
* 默认: hover
|
|
38
|
-
*/
|
|
39
|
-
trigger?: ActionType | ActionType[]
|
|
40
|
-
/**
|
|
41
|
-
* 默认: top
|
|
42
|
-
*/
|
|
43
|
-
placement?: TooltipPlacement
|
|
44
|
-
contentStyle?: JSX.CSSProperties
|
|
45
|
-
content?: JSXElement | ((close: () => void) => JSXElement)
|
|
46
|
-
children?: JSXElement
|
|
47
|
-
open?: boolean
|
|
48
|
-
onOpenChange?: (open: boolean) => void
|
|
49
|
-
/**
|
|
50
|
-
* 默认: dark
|
|
51
|
-
*/
|
|
52
|
-
mode?: 'dark' | 'light'
|
|
53
|
-
/**
|
|
54
|
-
* 默认: true
|
|
55
|
-
*/
|
|
56
|
-
arrow?: boolean | { pointAtCenter: boolean }
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const Content: Component<{
|
|
60
|
-
content: TooltipProps['content']
|
|
61
|
-
close: () => void
|
|
62
|
-
}> = props => {
|
|
63
|
-
return (
|
|
64
|
-
<Show when={typeof props.content === 'function'} fallback={props.content as JSXElement}>
|
|
65
|
-
{typeof props.content === 'function' && props.content(props.close)}
|
|
66
|
-
</Show>
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const Tooltip: Component<TooltipProps> = _props => {
|
|
71
|
-
const props = mergeProps(
|
|
72
|
-
{
|
|
73
|
-
trigger: 'hover',
|
|
74
|
-
placement: 'top',
|
|
75
|
-
mode: 'dark',
|
|
76
|
-
arrow: true,
|
|
77
|
-
},
|
|
78
|
-
_props,
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
const resolvedChildren = children(() => _props.children)
|
|
82
|
-
let content: HTMLDivElement
|
|
83
|
-
const [open, setOpen] = createControllableValue(_props, {
|
|
84
|
-
defaultValue: false,
|
|
85
|
-
valuePropName: 'open',
|
|
86
|
-
trigger: 'onOpenChange',
|
|
87
|
-
})
|
|
88
|
-
const reverseOpen = () => setOpen(v => !v)
|
|
89
|
-
|
|
90
|
-
createEffect(() => {
|
|
91
|
-
const _children = resolvedChildren() as Element
|
|
92
|
-
toArray(props.trigger).forEach(trigger => {
|
|
93
|
-
switch (trigger) {
|
|
94
|
-
case 'hover':
|
|
95
|
-
_children.addEventListener('mouseenter', reverseOpen)
|
|
96
|
-
_children.addEventListener('mouseleave', reverseOpen)
|
|
97
|
-
onCleanup(() => {
|
|
98
|
-
_children.removeEventListener('mouseenter', reverseOpen)
|
|
99
|
-
_children.removeEventListener('mouseleave', reverseOpen)
|
|
100
|
-
})
|
|
101
|
-
break
|
|
102
|
-
case 'click':
|
|
103
|
-
_children.addEventListener('click', reverseOpen)
|
|
104
|
-
onCleanup(() => {
|
|
105
|
-
_children.removeEventListener('click', reverseOpen)
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
useClickAway(
|
|
109
|
-
() => setOpen(false),
|
|
110
|
-
() => compact([content, _children]),
|
|
111
|
-
)
|
|
112
|
-
break
|
|
113
|
-
case 'focus':
|
|
114
|
-
_children.addEventListener('focus', reverseOpen)
|
|
115
|
-
_children.addEventListener('blur', reverseOpen)
|
|
116
|
-
onCleanup(() => {
|
|
117
|
-
_children.removeEventListener('focus', reverseOpen)
|
|
118
|
-
_children.removeEventListener('blur', reverseOpen)
|
|
119
|
-
})
|
|
120
|
-
break
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
const [childrenRect, setChildrenRect] = createSignal(new DOMRect())
|
|
126
|
-
createEffect(() => {
|
|
127
|
-
if (open()) {
|
|
128
|
-
const _children = resolvedChildren() as Element
|
|
129
|
-
setChildrenRect(_children.getBoundingClientRect())
|
|
130
|
-
}
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
const firstDirection = createMemo(() => {
|
|
134
|
-
if (props.placement.startsWith('bottom')) return 'bottom'
|
|
135
|
-
if (props.placement.startsWith('left')) return 'left'
|
|
136
|
-
if (props.placement.startsWith('right')) return 'right'
|
|
137
|
-
return 'top'
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
const secondDirection = createMemo(() => {
|
|
141
|
-
if (props.placement.endsWith('Left')) return 'left'
|
|
142
|
-
if (props.placement.endsWith('Right')) return 'right'
|
|
143
|
-
if (props.placement.endsWith('Top')) return 'top'
|
|
144
|
-
if (props.placement.endsWith('Bottom')) return 'bottom'
|
|
145
|
-
return 'center'
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
const arrowOffset = createMemo(() => (props.arrow ? 8 : 0))
|
|
149
|
-
const contentPositionStyle = createMemo(() => {
|
|
150
|
-
switch (props.placement) {
|
|
151
|
-
case 'top':
|
|
152
|
-
return {
|
|
153
|
-
top: `${childrenRect().top - arrowOffset()}px`,
|
|
154
|
-
left: `${childrenRect().left + childrenRect().width / 2}px`,
|
|
155
|
-
transform: 'translate(-50%, -100%)',
|
|
156
|
-
} as JSX.CSSProperties
|
|
157
|
-
case 'topLeft':
|
|
158
|
-
return {
|
|
159
|
-
top: `${childrenRect().top - arrowOffset()}px`,
|
|
160
|
-
left: `${childrenRect().left}px`,
|
|
161
|
-
transform: 'translate(0, -100%)',
|
|
162
|
-
} as JSX.CSSProperties
|
|
163
|
-
case 'topRight':
|
|
164
|
-
return {
|
|
165
|
-
top: `${childrenRect().top - arrowOffset()}px`,
|
|
166
|
-
left: `${childrenRect().right}px`,
|
|
167
|
-
transform: 'translate(-100%, -100%)',
|
|
168
|
-
} as JSX.CSSProperties
|
|
169
|
-
case 'bottom':
|
|
170
|
-
return {
|
|
171
|
-
top: `${childrenRect().bottom + arrowOffset()}px`,
|
|
172
|
-
left: `${childrenRect().left + childrenRect().width / 2}px`,
|
|
173
|
-
transform: 'translate(-50%, 0)',
|
|
174
|
-
} as JSX.CSSProperties
|
|
175
|
-
case 'bottomLeft':
|
|
176
|
-
return {
|
|
177
|
-
top: `${childrenRect().bottom + arrowOffset()}px`,
|
|
178
|
-
left: `${childrenRect().left}px`,
|
|
179
|
-
} as JSX.CSSProperties
|
|
180
|
-
case 'bottomRight':
|
|
181
|
-
return {
|
|
182
|
-
top: `${childrenRect().bottom + arrowOffset()}px`,
|
|
183
|
-
left: `${childrenRect().right}px`,
|
|
184
|
-
transform: 'translate(-100%, 0)',
|
|
185
|
-
} as JSX.CSSProperties
|
|
186
|
-
case 'left':
|
|
187
|
-
return {
|
|
188
|
-
top: `${childrenRect().top + childrenRect().height / 2}px`,
|
|
189
|
-
left: `${childrenRect().left - arrowOffset()}px`,
|
|
190
|
-
transform: 'translate(-100%, -50%)',
|
|
191
|
-
} as JSX.CSSProperties
|
|
192
|
-
case 'leftTop':
|
|
193
|
-
return {
|
|
194
|
-
top: `${childrenRect().top}px`,
|
|
195
|
-
left: `${childrenRect().left - arrowOffset()}px`,
|
|
196
|
-
transform: 'translate(-100%)',
|
|
197
|
-
} as JSX.CSSProperties
|
|
198
|
-
case 'leftBottom':
|
|
199
|
-
return {
|
|
200
|
-
top: `${childrenRect().bottom}px`,
|
|
201
|
-
left: `${childrenRect().left - arrowOffset()}px`,
|
|
202
|
-
transform: 'translate(-100%, -100%)',
|
|
203
|
-
} as JSX.CSSProperties
|
|
204
|
-
case 'right':
|
|
205
|
-
return {
|
|
206
|
-
top: `${childrenRect().top + childrenRect().height / 2}px`,
|
|
207
|
-
left: `${childrenRect().right + arrowOffset()}px`,
|
|
208
|
-
transform: 'translate(0, -50%)',
|
|
209
|
-
} as JSX.CSSProperties
|
|
210
|
-
case 'rightTop':
|
|
211
|
-
return {
|
|
212
|
-
top: `${childrenRect().top}px`,
|
|
213
|
-
left: `${childrenRect().right + arrowOffset()}px`,
|
|
214
|
-
} as JSX.CSSProperties
|
|
215
|
-
case 'rightBottom':
|
|
216
|
-
return {
|
|
217
|
-
top: `${childrenRect().bottom}px`,
|
|
218
|
-
left: `${childrenRect().right + arrowOffset()}px`,
|
|
219
|
-
transform: 'translate(0, -100%)',
|
|
220
|
-
} as JSX.CSSProperties
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
const arrowStyle = createMemo(() => {
|
|
224
|
-
switch (props.placement) {
|
|
225
|
-
case 'top':
|
|
226
|
-
return {
|
|
227
|
-
'border-top-color': 'var(--color)',
|
|
228
|
-
top: '100%',
|
|
229
|
-
filter: 'drop-shadow(3px 2px 2px rgba(0, 0, 0, 0.08))',
|
|
230
|
-
left: '50%',
|
|
231
|
-
transform: 'translateX(-50%)',
|
|
232
|
-
} as JSX.CSSProperties
|
|
233
|
-
case 'topLeft':
|
|
234
|
-
return {
|
|
235
|
-
'border-top-color': 'var(--color)',
|
|
236
|
-
top: '100%',
|
|
237
|
-
filter: 'drop-shadow(3px 2px 2px rgba(0, 0, 0, 0.08))',
|
|
238
|
-
left: '8px',
|
|
239
|
-
} as JSX.CSSProperties
|
|
240
|
-
case 'topRight':
|
|
241
|
-
return {
|
|
242
|
-
'border-top-color': 'var(--color)',
|
|
243
|
-
top: '100%',
|
|
244
|
-
filter: 'drop-shadow(3px 2px 2px rgba(0, 0, 0, 0.08))',
|
|
245
|
-
right: '8px',
|
|
246
|
-
} as JSX.CSSProperties
|
|
247
|
-
case 'bottom':
|
|
248
|
-
return {
|
|
249
|
-
'border-bottom-color': 'var(--color)',
|
|
250
|
-
bottom: '100%',
|
|
251
|
-
filter: 'drop-shadow(3px 2px 2px rgba(0, 0, 0, 0.08))',
|
|
252
|
-
left: '50%',
|
|
253
|
-
transform: 'translateX(-50%)',
|
|
254
|
-
} as JSX.CSSProperties
|
|
255
|
-
case 'bottomLeft':
|
|
256
|
-
return {
|
|
257
|
-
'border-bottom-color': 'var(--color)',
|
|
258
|
-
bottom: '100%',
|
|
259
|
-
filter: 'drop-shadow(3px 2px 2px rgba(0, 0, 0, 0.08))',
|
|
260
|
-
left: '8px',
|
|
261
|
-
} as JSX.CSSProperties
|
|
262
|
-
case 'bottomRight':
|
|
263
|
-
return {
|
|
264
|
-
'border-bottom-color': 'var(--color)',
|
|
265
|
-
bottom: '100%',
|
|
266
|
-
filter: 'drop-shadow(3px 2px 2px rgba(0, 0, 0, 0.08))',
|
|
267
|
-
right: '8px',
|
|
268
|
-
} as JSX.CSSProperties
|
|
269
|
-
case 'left':
|
|
270
|
-
return {
|
|
271
|
-
'border-left-color': 'var(--color)',
|
|
272
|
-
top: '50%',
|
|
273
|
-
right: 0,
|
|
274
|
-
transform: 'translate(100%, -50%)',
|
|
275
|
-
} as JSX.CSSProperties
|
|
276
|
-
case 'leftTop':
|
|
277
|
-
return {
|
|
278
|
-
'border-left-color': 'var(--color)',
|
|
279
|
-
top: '8px',
|
|
280
|
-
right: 0,
|
|
281
|
-
transform: 'translate(100%, 0)',
|
|
282
|
-
} as JSX.CSSProperties
|
|
283
|
-
case 'leftBottom':
|
|
284
|
-
return {
|
|
285
|
-
'border-left-color': 'var(--color)',
|
|
286
|
-
bottom: '8px',
|
|
287
|
-
right: 0,
|
|
288
|
-
transform: 'translate(100%, 0)',
|
|
289
|
-
} as JSX.CSSProperties
|
|
290
|
-
case 'right':
|
|
291
|
-
return {
|
|
292
|
-
'border-right-color': 'var(--color)',
|
|
293
|
-
top: '50%',
|
|
294
|
-
left: 0,
|
|
295
|
-
transform: 'translate(-100%, -50%)',
|
|
296
|
-
} as JSX.CSSProperties
|
|
297
|
-
case 'rightTop':
|
|
298
|
-
return {
|
|
299
|
-
'border-right-color': 'var(--color)',
|
|
300
|
-
top: '8px',
|
|
301
|
-
left: 0,
|
|
302
|
-
transform: 'translate(-100%, 0)',
|
|
303
|
-
} as JSX.CSSProperties
|
|
304
|
-
case 'rightBottom':
|
|
305
|
-
return {
|
|
306
|
-
'border-right-color': 'var(--color)',
|
|
307
|
-
bottom: '8px',
|
|
308
|
-
left: 0,
|
|
309
|
-
transform: 'translate(-100%, 0)',
|
|
310
|
-
} as JSX.CSSProperties
|
|
311
|
-
}
|
|
312
|
-
})
|
|
313
|
-
|
|
314
|
-
return (
|
|
315
|
-
<>
|
|
316
|
-
{resolvedChildren()}
|
|
317
|
-
|
|
318
|
-
<Show when={open()}>
|
|
319
|
-
<Portal>
|
|
320
|
-
{/* Portal 存在缺陷,onClick 依然会沿着 solid 的组件树向上传播,因此需要 stopPropagation */}
|
|
321
|
-
<div
|
|
322
|
-
ref={content!}
|
|
323
|
-
class={cs(
|
|
324
|
-
'ant-z-1000 ant-fixed ant-absolute ant-px-8px ant-py-6px ant-rounded-8px ant-box-content ant-[box-shadow:0_6px_16px_0_rgba(0,0,0,0.08),0_3px_6px_-4px_rgba(0,0,0,0.12),0_9px_28px_8px_rgba(0,0,0,0.05)]',
|
|
325
|
-
props.mode === 'dark' ? 'ant-bg-[rgba(0,0,0,0.85)] ant-text-white' : 'ant-bg-white',
|
|
326
|
-
)}
|
|
327
|
-
style={{
|
|
328
|
-
...contentPositionStyle(),
|
|
329
|
-
...props.contentStyle,
|
|
330
|
-
}}
|
|
331
|
-
onClick={e => {
|
|
332
|
-
e.stopPropagation()
|
|
333
|
-
}}
|
|
334
|
-
>
|
|
335
|
-
<Content content={props.content} close={() => setOpen(false)} />
|
|
336
|
-
|
|
337
|
-
<Show when={props.arrow}>
|
|
338
|
-
<div
|
|
339
|
-
class={cs(
|
|
340
|
-
'ant-w-8px ant-h-8px ant-absolute ant-border-solid ant-border-4px ant-border-transparent',
|
|
341
|
-
)}
|
|
342
|
-
style={{
|
|
343
|
-
'--color': props.mode === 'dark' ? 'rgba(0,0,0,0.85)' : 'white',
|
|
344
|
-
...arrowStyle(),
|
|
345
|
-
}}
|
|
346
|
-
/>
|
|
347
|
-
</Show>
|
|
348
|
-
</div>
|
|
349
|
-
</Portal>
|
|
350
|
-
</Show>
|
|
351
|
-
</>
|
|
352
|
-
)
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export default Tooltip
|
package/src/Tree.tsx
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
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 hover:ant-bg-[var(--hover-bg-color)] 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: setSelectedNodes as unknown as Setter<Array<{}>>,
|
|
219
|
-
draggableNode,
|
|
220
|
-
setDraggableNode: setDraggableNode as unknown as Setter<{} | null>,
|
|
221
|
-
draggableIndexes,
|
|
222
|
-
setDraggableIndexes,
|
|
223
|
-
isDraggable,
|
|
224
|
-
targetNode,
|
|
225
|
-
setTargetNode: setTargetNode as unknown as Setter<{} | null>,
|
|
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
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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
|
package/src/form/Form.tsx
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type JSXElement,
|
|
3
|
-
type Ref,
|
|
4
|
-
mergeProps,
|
|
5
|
-
type Setter,
|
|
6
|
-
onMount,
|
|
7
|
-
createSignal,
|
|
8
|
-
createMemo,
|
|
9
|
-
} from 'solid-js'
|
|
10
|
-
import { get, max, set } from 'lodash-es'
|
|
11
|
-
import Context from './context'
|
|
12
|
-
import { type Schema } from 'yup'
|
|
13
|
-
|
|
14
|
-
export interface FormInstance<T extends {} = {}> {
|
|
15
|
-
validateFields: () => Promise<T>
|
|
16
|
-
setFieldValue: (name: Parameters<typeof set>[1], value: any) => void
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface FormProps<T extends {} = {}> {
|
|
20
|
-
ref?: Ref<FormInstance<T>>
|
|
21
|
-
/**
|
|
22
|
-
* 表单布局
|
|
23
|
-
* 默认: horizontal
|
|
24
|
-
*/
|
|
25
|
-
layout?: 'horizontal' | 'vertical' | 'inline'
|
|
26
|
-
children: JSXElement
|
|
27
|
-
initialValues?: T
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function Form<T extends {} = {}>(_props: FormProps<T>) {
|
|
31
|
-
const props = mergeProps({ layout: 'horizontal' } as FormProps, _props)
|
|
32
|
-
const rulesDict: Record<string, Schema[]> = {}
|
|
33
|
-
const setErrMsgDict: Record<string, Setter<string>> = {}
|
|
34
|
-
|
|
35
|
-
const values = props.initialValues ? { ...props.initialValues } : ({} as T)
|
|
36
|
-
const formInstance: FormInstance<T> = {
|
|
37
|
-
async validateFields() {
|
|
38
|
-
const promises = Object.entries(rulesDict).flatMap(([name, rules]) => {
|
|
39
|
-
return rules.map(
|
|
40
|
-
async rule =>
|
|
41
|
-
await rule.validate(get(values, name)).catch(err => {
|
|
42
|
-
setErrMsgDict[name](err.message)
|
|
43
|
-
throw err
|
|
44
|
-
}),
|
|
45
|
-
)
|
|
46
|
-
})
|
|
47
|
-
const results = await Promise.allSettled(promises)
|
|
48
|
-
if (results.some(result => result.status === 'rejected')) {
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
50
|
-
throw {
|
|
51
|
-
errorFields: results.filter(res => res.status === 'rejected'),
|
|
52
|
-
values,
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return values as T
|
|
56
|
-
},
|
|
57
|
-
setFieldValue(name, value) {
|
|
58
|
-
set(values, name, value)
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
onMount(() => {
|
|
63
|
-
if (typeof _props.ref === 'function') {
|
|
64
|
-
_props.ref?.(formInstance)
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
// 存储 form item 的 dom 节点宽度
|
|
69
|
-
const [itemWidthDict, setItemWidthDict] = createSignal<Record<string, number>>({})
|
|
70
|
-
const maxItemWidth = createMemo(() => max(Object.values(itemWidthDict())))
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<form
|
|
74
|
-
onSubmit={e => {
|
|
75
|
-
e.preventDefault()
|
|
76
|
-
}}
|
|
77
|
-
>
|
|
78
|
-
<Context.Provider
|
|
79
|
-
value={{
|
|
80
|
-
formInstance,
|
|
81
|
-
rulesDict,
|
|
82
|
-
setErrMsgDict,
|
|
83
|
-
initialValues: props.initialValues as {},
|
|
84
|
-
setItemWidthDict,
|
|
85
|
-
maxItemWidth,
|
|
86
|
-
}}
|
|
87
|
-
>
|
|
88
|
-
{props.children}
|
|
89
|
-
</Context.Provider>
|
|
90
|
-
</form>
|
|
91
|
-
)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export default Form
|