Skip to content

Commit

Permalink
fix(pagination): color of icon (#2769)
Browse files Browse the repository at this point in the history
* fix(pagination): color of icon

* fix: review

* fix: ai’s review
  • Loading branch information
oasis-cloud authored Nov 20, 2024
1 parent 85a05cd commit 5bcca3b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/packages/pagination/pagination.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { FunctionComponent, useMemo, ReactNode } from 'react'
import React, { FunctionComponent, ReactNode, useMemo } from 'react'
import classNames from 'classnames'
import { View } from '@tarojs/components'
import { useConfig } from '@/packages/configprovider/index.taro'
import { usePropsValue } from '@/utils/use-props-value'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
import addColorForHarmony from '@/utils/add-color-for-harmony'

export interface PaginationProps extends BasicComponent {
defaultValue: number
Expand Down Expand Up @@ -117,7 +118,10 @@ export const Pagination: FunctionComponent<
)}
onClick={(e) => handleSelectPage(currentPage - 1)}
>
{prev || locale.pagination.prev}
{addColorForHarmony(
prev || locale.pagination.prev,
currentPage === 1 ? '#c2c4cc' : '#ff0f23'
)}
</View>
{mode === 'multi' && (
<View className={`${classPrefix}-contain`}>
Expand Down Expand Up @@ -154,7 +158,10 @@ export const Pagination: FunctionComponent<
)}
onClick={(e) => handleSelectPage(currentPage + 1)}
>
{next || locale.pagination.next}
{addColorForHarmony(
next || locale.pagination.next,
currentPage >= pageCount ? '#c2c4cc' : '#ff0f23'
)}
</View>
</>
)}
Expand Down
23 changes: 23 additions & 0 deletions src/utils/add-color-for-harmony.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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<ColorProps>(maybeElement as ReactElement, {
color,
})
}
return maybeElement
}

export default addColorForHarmony

0 comments on commit 5bcca3b

Please sign in to comment.