Skip to content

Commit

Permalink
fix: ai’s review
Browse files Browse the repository at this point in the history
  • Loading branch information
oasis-cloud committed Nov 20, 2024
1 parent ddf58c1 commit 5ed403d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/utils/add-color-for-harmony.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import React, { ReactNode } from 'react'
import React, { ReactElement, ReactNode } from 'react'
import { harmony } from './platform-taro'

interface ColorProps {
color?: string
}

/**
* 为支持 Harmony 的 React 元素添加颜色属性
* @param maybeElement - 要处理的 React 节点
* @param color - 要添加的颜色值(如:'#ff0000')
* @returns 处理后的 React 节点
*/
function addColorForHarmony(maybeElement: ReactNode, color: string) {
if (React.isValidElement(maybeElement) && harmony()) {
return React.cloneElement<any>(maybeElement, {
return React.cloneElement<ColorProps>(maybeElement as ReactElement, {
color,
})
}
Expand Down

0 comments on commit 5ed403d

Please sign in to comment.