Skip to content

Commit

Permalink
chore: re-order
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Apr 18, 2024
1 parent 48dd7a5 commit b8940b0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/components/collapse/collapse.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { animated, useSpring } from '@react-spring/web'
import { useMount } from 'ahooks'
import { DownOutline } from 'antd-mobile-icons'
import classNames from 'classnames'
import type { FC, ReactElement, ReactNode } from 'react'
import React, { isValidElement, useRef } from 'react'
import { DownOutline } from 'antd-mobile-icons'
import { NativeProps, withNativeProps } from '../../utils/native-props'
import { useShouldRender } from '../../utils/should-render'
import { traverseReactNode } from '../../utils/traverse-react-node'
Expand Down Expand Up @@ -211,11 +211,11 @@ export const Collapse: FC<CollapseProps> = props => {
}

const arrow = mergeProp(
panel.props.arrowIcon,
panel.props.arrow,
mergedProps.arrowIcon,
<DownOutline />,
mergedProps.arrow,
<DownOutline />
mergedProps.arrowIcon,
panel.props.arrow,
panel.props.arrowIcon
)

const arrowIcon =
Expand Down
6 changes: 3 additions & 3 deletions src/components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ const Dropdown = forwardRef<DropdownRef, PropsWithChildren<DropdownProps>>(
},
active: child.key === value,
arrowIcon: mergeProp(
child.props.arrowIcon,
child.props.arrow,
mergedProps.arrow,
mergedProps.arrowIcon,
mergedProps.arrow
child.props.arrow,
child.props.arrowIcon
),
}
items.push(child)
Expand Down
4 changes: 2 additions & 2 deletions src/components/list/list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export const ListItem: FC<ListItemProps> = props => {

const showArrow = arrow ?? arrowIcon ?? clickable
const mergedArrowIcon = mergeProp(
arrowIcon !== true ? arrowIcon : null,
componentConfig.arrowIcon,
arrow !== true ? arrow : null,
componentConfig.arrowIcon
arrowIcon !== true ? arrowIcon : null
)

const content = (
Expand Down
10 changes: 7 additions & 3 deletions src/utils/with-default-props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ export function mergeProps(...items: any[]) {

/**
* Merge props and return the first non-undefined value.
* The later has higher priority. e.g. (10, 1, 5) => 5 wins.
* This is useful with legacy props that have been deprecated.
*/
export function mergeProp<T>(...propList: T[]): T | undefined {
for (let i = 0; i < propList.length; i++) {
export function mergeProp<T, DefaultT extends T>(
defaultProp: DefaultT,
...propList: T[]
): T | undefined {
for (let i = propList.length - 1; i >= 0; i -= 1) {
if (propList[i] !== undefined) {
return propList[i]
}
}
return undefined
return defaultProp
}

0 comments on commit b8940b0

Please sign in to comment.