1e75ebbc8Sopenharmony_ci/* 2e75ebbc8Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3e75ebbc8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e75ebbc8Sopenharmony_ci * you may not use this file except in compliance with the License. 5e75ebbc8Sopenharmony_ci * You may obtain a copy of the License at 6e75ebbc8Sopenharmony_ci * 7e75ebbc8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e75ebbc8Sopenharmony_ci * 9e75ebbc8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e75ebbc8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e75ebbc8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e75ebbc8Sopenharmony_ci * See the License for the specific language governing permissions and 13e75ebbc8Sopenharmony_ci * limitations under the License. 14e75ebbc8Sopenharmony_ci */ 15e75ebbc8Sopenharmony_ci 16e75ebbc8Sopenharmony_ciimport Log from '../default/Log'; 17e75ebbc8Sopenharmony_ciimport StyleConfiguration, { IconComponentStyle } from './common/StyleConfiguration' 18e75ebbc8Sopenharmony_ci 19e75ebbc8Sopenharmony_ciconst TAG = 'iconComponent' 20e75ebbc8Sopenharmony_ci 21e75ebbc8Sopenharmony_ci@Component 22e75ebbc8Sopenharmony_ciexport default struct iconComponent { 23e75ebbc8Sopenharmony_ci @State iconOff: string = "" 24e75ebbc8Sopenharmony_ci @State iconOn: string = "" 25e75ebbc8Sopenharmony_ci @Prop iconOffStr: string 26e75ebbc8Sopenharmony_ci @Prop iconOnStr: string 27e75ebbc8Sopenharmony_ci private useIconStr = false 28e75ebbc8Sopenharmony_ci @State mIconIsHover: boolean = false 29e75ebbc8Sopenharmony_ci @Link changeSwitch: boolean 30e75ebbc8Sopenharmony_ci @State style: IconComponentStyle = StyleConfiguration.getIconComponentStyle() 31e75ebbc8Sopenharmony_ci 32e75ebbc8Sopenharmony_ci aboutToAppear() { 33e75ebbc8Sopenharmony_ci Log.showInfo(TAG,`aboutToAppear, ${this.changeSwitch} ${JSON.stringify(this.iconOff)} ${JSON.stringify(this.iconOn)} , useIconStr: ${this.useIconStr}`) 34e75ebbc8Sopenharmony_ci } 35e75ebbc8Sopenharmony_ci 36e75ebbc8Sopenharmony_ci aboutToDisappear() { 37e75ebbc8Sopenharmony_ci Log.showInfo(TAG, 'aboutToDisappear') 38e75ebbc8Sopenharmony_ci } 39e75ebbc8Sopenharmony_ci 40e75ebbc8Sopenharmony_ci build() { 41e75ebbc8Sopenharmony_ci Stack() { 42e75ebbc8Sopenharmony_ci Flex() 43e75ebbc8Sopenharmony_ci .backgroundColor(this.changeSwitch ? this.style.iconOnBG : this.style.iconOffBG) 44e75ebbc8Sopenharmony_ci .clip(new Circle({ width: this.style.circleWidth, height: this.style.circleHeight })) 45e75ebbc8Sopenharmony_ci .width(this.style.circleWidth) 46e75ebbc8Sopenharmony_ci .height(this.style.circleHeight) 47e75ebbc8Sopenharmony_ci Flex() 48e75ebbc8Sopenharmony_ci .backgroundColor(this.mIconIsHover ? this.style.hoverColor : this.style.transparentColor) 49e75ebbc8Sopenharmony_ci .clip(new Circle({ width: this.style.circleWidth, height: this.style.circleHeight })) 50e75ebbc8Sopenharmony_ci .width(this.style.circleWidth) 51e75ebbc8Sopenharmony_ci .height(this.style.circleHeight) 52e75ebbc8Sopenharmony_ci Image(this.changeSwitch == false ? (this.useIconStr ? this.iconOffStr : this.iconOff) : (this.useIconStr ? this.iconOnStr : this.iconOn)) 53e75ebbc8Sopenharmony_ci .size({ width: this.style.iconWidth, height: this.style.iconHeight }) 54e75ebbc8Sopenharmony_ci .objectFit(ImageFit.Contain) 55e75ebbc8Sopenharmony_ci .fillColor(this.changeSwitch ? this.style.iconOnColor : this.style.iconOffColor) 56e75ebbc8Sopenharmony_ci .onHover((isHover) => { 57e75ebbc8Sopenharmony_ci this.mIconIsHover = isHover; 58e75ebbc8Sopenharmony_ci }) 59e75ebbc8Sopenharmony_ci } 60e75ebbc8Sopenharmony_ci .width(this.style.circleWidth) 61e75ebbc8Sopenharmony_ci .height(this.style.circleHeight) 62e75ebbc8Sopenharmony_ci } 63e75ebbc8Sopenharmony_ci} 64