Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Tabbar): harmony adaptation #2783

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading