From 05c2769f775e69adce388ef98364c6a07223a0eb Mon Sep 17 00:00:00 2001 From: oasis Date: Tue, 19 Nov 2024 14:54:53 +0800 Subject: [PATCH 1/3] fix(pagination): color of icon --- src/packages/pagination/pagination.taro.tsx | 22 ++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/packages/pagination/pagination.taro.tsx b/src/packages/pagination/pagination.taro.tsx index fa06c5b938..95418dbefb 100644 --- a/src/packages/pagination/pagination.taro.tsx +++ b/src/packages/pagination/pagination.taro.tsx @@ -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 { harmony } from '@/utils/platform-taro' export interface PaginationProps extends BasicComponent { defaultValue: number @@ -105,6 +106,15 @@ export const Pagination: FunctionComponent< setCurrentPage(curPage) } + function addColorForHarmony(maybeElement: ReactNode, color: string) { + if (React.isValidElement(maybeElement) && harmony()) { + return React.cloneElement(maybeElement, { + color, + }) + } + return maybeElement + } + return ( {(mode === 'multi' || mode === 'simple') && ( @@ -117,7 +127,10 @@ export const Pagination: FunctionComponent< )} onClick={(e) => handleSelectPage(currentPage - 1)} > - {prev || locale.pagination.prev} + {addColorForHarmony( + prev || locale.pagination.prev, + currentPage === 1 ? '#c2c4cc' : '#ff0f23' + )} {mode === 'multi' && ( @@ -154,7 +167,10 @@ export const Pagination: FunctionComponent< )} onClick={(e) => handleSelectPage(currentPage + 1)} > - {next || locale.pagination.next} + {addColorForHarmony( + next || locale.pagination.next, + currentPage >= pageCount ? '#c2c4cc' : '#ff0f23' + )} )} From ddf58c143926536b3c5188ba2b14c53ce973118f Mon Sep 17 00:00:00 2001 From: oasis Date: Wed, 20 Nov 2024 15:10:36 +0800 Subject: [PATCH 2/3] fix: review --- src/packages/pagination/pagination.taro.tsx | 11 +---------- src/utils/add-color-for-harmony.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 src/utils/add-color-for-harmony.ts diff --git a/src/packages/pagination/pagination.taro.tsx b/src/packages/pagination/pagination.taro.tsx index 95418dbefb..dc83a70f3b 100644 --- a/src/packages/pagination/pagination.taro.tsx +++ b/src/packages/pagination/pagination.taro.tsx @@ -4,7 +4,7 @@ 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 { harmony } from '@/utils/platform-taro' +import addColorForHarmony from '@/utils/add-color-for-harmony' export interface PaginationProps extends BasicComponent { defaultValue: number @@ -106,15 +106,6 @@ export const Pagination: FunctionComponent< setCurrentPage(curPage) } - function addColorForHarmony(maybeElement: ReactNode, color: string) { - if (React.isValidElement(maybeElement) && harmony()) { - return React.cloneElement(maybeElement, { - color, - }) - } - return maybeElement - } - return ( {(mode === 'multi' || mode === 'simple') && ( diff --git a/src/utils/add-color-for-harmony.ts b/src/utils/add-color-for-harmony.ts new file mode 100644 index 0000000000..cf4b63c611 --- /dev/null +++ b/src/utils/add-color-for-harmony.ts @@ -0,0 +1,13 @@ +import React, { ReactNode } from 'react' +import { harmony } from './platform-taro' + +function addColorForHarmony(maybeElement: ReactNode, color: string) { + if (React.isValidElement(maybeElement) && harmony()) { + return React.cloneElement(maybeElement, { + color, + }) + } + return maybeElement +} + +export default addColorForHarmony From 5ed403d97a11dc59a90a33873c919c831f197f3b Mon Sep 17 00:00:00 2001 From: oasis Date: Wed, 20 Nov 2024 16:15:25 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20ai=E2=80=99s=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/add-color-for-harmony.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/utils/add-color-for-harmony.ts b/src/utils/add-color-for-harmony.ts index cf4b63c611..471f7b3f80 100644 --- a/src/utils/add-color-for-harmony.ts +++ b/src/utils/add-color-for-harmony.ts @@ -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(maybeElement, { + return React.cloneElement(maybeElement as ReactElement, { color, }) }