mirror of
https://github.com/zhigang1992/react.git
synced 2026-01-29 17:18:13 +08:00
23 lines
719 B
TypeScript
23 lines
719 B
TypeScript
import React, { ReactNode } from 'react'
|
|
|
|
export const sortChildren = (
|
|
children: ReactNode | undefined,
|
|
folderComponentType: React.ElementType,
|
|
) => {
|
|
return React.Children.toArray(children).sort((a, b) => {
|
|
if (!React.isValidElement(a) || !React.isValidElement(b)) return 0
|
|
if (a.type !== b.type) return a.type !== folderComponentType ? 1 : -1
|
|
return `${a.props.name}`.charCodeAt(0) - `${b.props.name}`.charCodeAt(0)
|
|
})
|
|
}
|
|
|
|
export const makeChildPath = (name: string, parentPath?: string) => {
|
|
if (!parentPath) return name
|
|
return `${parentPath}/${name}`
|
|
}
|
|
|
|
export const stopPropagation = (event: React.MouseEvent) => {
|
|
event.stopPropagation()
|
|
event.nativeEvent.stopImmediatePropagation()
|
|
}
|