Skip to content

Commit

Permalink
feat(Tabbar): harmony 适配 (#2783)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyatong authored Nov 21, 2024
1 parent beb7be2 commit 0648882
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
"author": "hx"
},
{
"version": "2.0.0",
"version": "3.0.0",
"name": "Tabbar",
"type": "component",
"cName": "标签栏",
Expand Down
10 changes: 10 additions & 0 deletions src/packages/tabbaritem/tabbaritem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,20 @@
color: $tabbar-active-color;

.nut-tabbar-item-icon-box {
/* #ifdef harmony*/
color: $tabbar-active-color;
/* #endif*/
/* #ifndef harmony*/
color: inherit;
/* #endif*/

.nut-icon {
/* #ifdef harmony*/
color: $tabbar-active-color;
/* #endif*/
/* #ifndef harmony*/
color: inherit;
/* #endif*/
}
}
}
Expand Down
26 changes: 23 additions & 3 deletions src/packages/tabbaritem/tabbaritem.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { View } from '@tarojs/components'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
import Badge from '@/packages/badge/index.taro'
import TabbarContext from '@/packages/tabbar/context'
import addColorForHarmony from '@/utils/add-color-for-harmony'

export interface TabbarItemProps extends BasicComponent {
title: ReactNode
Expand Down Expand Up @@ -83,13 +84,32 @@ export const TabbarItem: FunctionComponent<Partial<TabbarItemProps>> = (
{icon ? (
<>
<Badge {...badgeProps}>
<View className={boxPrefix}>{icon}</View>
<View className={boxPrefix}>
{addColorForHarmony(
icon,
active ? ctx?.activeColor : ctx?.inactiveColor
)}
</View>
</Badge>
<View className={titleClass}>{title}</View>
<View
className={titleClass}
style={{
color: active ? ctx?.activeColor : ctx?.inactiveColor,
}}
>
{title}
</View>
</>
) : (
<Badge {...badgeProps}>
<View className={titleClass}>{title}</View>
<View
className={titleClass}
style={{
color: active ? ctx?.activeColor : ctx?.inactiveColor,
}}
>
{title}
</View>
</Badge>
)}
</View>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/add-color-for-harmony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface ColorProps {
* @param color - 要添加的颜色值(如:'#ff0000')
* @returns 处理后的 React 节点
*/
function addColorForHarmony(maybeElement: ReactNode, color: string) {
function addColorForHarmony(maybeElement: ReactNode, color?: string) {
if (React.isValidElement(maybeElement) && harmony()) {
return React.cloneElement<ColorProps>(maybeElement as ReactElement, {
color,
Expand Down

0 comments on commit 0648882

Please sign in to comment.