1import { Constants } from './Constants'; 2/* 3 * Copyright (c) 2022 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17@Observed 18export class TabItem { 19 public name: Resource; 20 public iconResource: Resource; 21 public iconSelectedResource: Resource; 22 public iconDefault: Resource = $r('sys.color.ohos_id_color_bottom_tab_icon_off'); 23 public iconSelected: Resource | null = null; 24 public textColorDefault: Resource = $r('sys.color.ohos_id_color_text_primary'); 25 public textColorSelected: Resource = $r('sys.color.ohos_id_color_bottom_tab_text_on'); 26 public textFamilyDefault: Resource = $r('sys.string.ohos_id_text_font_family_medium'); 27 public textFamilySelected: Resource = $r('sys.string.ohos_id_text_font_family_medium'); 28 public isSelected: boolean; 29 public componentKey: string; 30 31 constructor(name: Resource, iconResource: Resource, iconSelectedResource: Resource, 32 isSelected: boolean, textColorDefault: Resource, componentKey: string) { 33 this.name = name; 34 this.iconResource = iconResource; 35 this.iconSelectedResource = iconSelectedResource; 36 this.isSelected = isSelected; 37 this.textColorDefault = textColorDefault; 38 this.componentKey = componentKey; 39 } 40 41 getConditionIcon(isSelected: boolean): Resource { 42 return isSelected ? this.iconSelected as Resource : this.iconDefault; 43 } 44 45 getIcon(isSelected: boolean): Resource { 46 return isSelected ? this.iconSelectedResource : this.iconResource; 47 } 48 49 getTextColor(): Resource { 50 return this.isSelected ? this.textColorSelected : this.textColorDefault; 51 } 52 53 getTextFamily(): Resource { 54 return this.isSelected ? this.textColorSelected : this.textColorDefault; 55 } 56} 57 58// Tab Bar which only has text 59// For Album Set 60@Observed 61export class TabItemWithText { 62 public name: Resource; 63 public isSelected: boolean; 64 public textSizeDefault: Resource = $r('sys.float.ohos_id_text_size_body1'); 65 public textSizeSelected: Resource = $r('sys.float.ohos_id_text_size_sub_title2'); 66 public textWeightDefault: FontWeight = FontWeight.Regular; 67 public textWeightSelected: FontWeight = FontWeight.Medium; 68 public textColorDefault: Resource = $r('sys.color.ohos_id_color_bottom_tab_text_off'); 69 public textColorSelected: Resource = $r('app.color.color_system_highlight'); 70 71 constructor(name: Resource, isSelected: boolean) { 72 this.name = name; 73 this.isSelected = isSelected; 74 } 75 76 getTextSize(): Resource { 77 return this.isSelected ? this.textSizeSelected : this.textSizeDefault; 78 } 79 80 getTextWeight(): FontWeight { 81 return this.isSelected ? this.textWeightSelected : this.textWeightDefault; 82 } 83 84 getTextColor(): Resource { 85 return this.isSelected ? this.textColorSelected : this.textColorDefault; 86 } 87}