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, { IconTitleBaseStyle } from './common/StyleConfiguration'
18e75ebbc8Sopenharmony_ciimport iconComponent from './iconComponent'
19e75ebbc8Sopenharmony_ci
20e75ebbc8Sopenharmony_ciconst TAG = 'iconTitleBase'
21e75ebbc8Sopenharmony_ci
22e75ebbc8Sopenharmony_ci@Component
23e75ebbc8Sopenharmony_ciexport default struct iconBaseComponent {
24e75ebbc8Sopenharmony_ci  private iconOn: any
25e75ebbc8Sopenharmony_ci  private iconOff: any
26e75ebbc8Sopenharmony_ci  @State iconOffStr: string = ""
27e75ebbc8Sopenharmony_ci  @State iconOnStr: string = ""
28e75ebbc8Sopenharmony_ci  @Link mTitle: Resource
29e75ebbc8Sopenharmony_ci  @State mTitleStr: string = ""
30e75ebbc8Sopenharmony_ci  private useIconStr = false
31e75ebbc8Sopenharmony_ci  private useTitleStr = false
32e75ebbc8Sopenharmony_ci  private mClickEvent: Function
33e75ebbc8Sopenharmony_ci  private mLongClickEvent: Function
34e75ebbc8Sopenharmony_ci  @State mTextIsHover: boolean = false
35e75ebbc8Sopenharmony_ci  @Link changeSwitch: boolean
36e75ebbc8Sopenharmony_ci  @State style: IconTitleBaseStyle = StyleConfiguration.getIconTitleBaseStyle()
37e75ebbc8Sopenharmony_ci
38e75ebbc8Sopenharmony_ci  aboutToAppear() {
39e75ebbc8Sopenharmony_ci    Log.showInfo(TAG, 'aboutToAppear')
40e75ebbc8Sopenharmony_ci  }
41e75ebbc8Sopenharmony_ci
42e75ebbc8Sopenharmony_ci  aboutToDisappear() {
43e75ebbc8Sopenharmony_ci    Log.showInfo(TAG, 'aboutToDisappear')
44e75ebbc8Sopenharmony_ci  }
45e75ebbc8Sopenharmony_ci
46e75ebbc8Sopenharmony_ci  build() {
47e75ebbc8Sopenharmony_ci    Row() {
48e75ebbc8Sopenharmony_ci      Row() {
49e75ebbc8Sopenharmony_ci        iconComponent({
50e75ebbc8Sopenharmony_ci          useIconStr: this.useIconStr,
51e75ebbc8Sopenharmony_ci          iconOff: this.iconOff,
52e75ebbc8Sopenharmony_ci          iconOn: this.iconOn,
53e75ebbc8Sopenharmony_ci          iconOffStr: this.iconOffStr,
54e75ebbc8Sopenharmony_ci          iconOnStr: this.iconOnStr,
55e75ebbc8Sopenharmony_ci          changeSwitch: $changeSwitch,
56e75ebbc8Sopenharmony_ci        })
57e75ebbc8Sopenharmony_ci      }
58e75ebbc8Sopenharmony_ci      .height('100%')
59e75ebbc8Sopenharmony_ci      .margin({left: this.style.marginLeft, right: this.style.componentGap})
60e75ebbc8Sopenharmony_ci      .onClick(() => {
61e75ebbc8Sopenharmony_ci        Log.showDebug(TAG, `start clickEvent ${this.changeSwitch}`);
62e75ebbc8Sopenharmony_ci        if (this.mClickEvent) {
63e75ebbc8Sopenharmony_ci          this.mClickEvent()
64e75ebbc8Sopenharmony_ci        }
65e75ebbc8Sopenharmony_ci        Log.showDebug(TAG, `end clickEvent ${this.changeSwitch}`);
66e75ebbc8Sopenharmony_ci      })
67e75ebbc8Sopenharmony_ci
68e75ebbc8Sopenharmony_ci      Row() {
69e75ebbc8Sopenharmony_ci        Text(this.useTitleStr ? this.mTitleStr : this.mTitle)
70e75ebbc8Sopenharmony_ci          .fontSize(this.style.titleSize)
71e75ebbc8Sopenharmony_ci          .fontColor(this.style.titleColor)
72e75ebbc8Sopenharmony_ci          .textOverflow({ overflow: TextOverflow.Ellipsis })
73e75ebbc8Sopenharmony_ci          .maxLines(2)
74e75ebbc8Sopenharmony_ci          .margin({left: this.style.textMargin, right: this.style.textMargin})
75e75ebbc8Sopenharmony_ci          .onHover((isHover) => {
76e75ebbc8Sopenharmony_ci            this.mTextIsHover = isHover;
77e75ebbc8Sopenharmony_ci          })
78e75ebbc8Sopenharmony_ci      }
79e75ebbc8Sopenharmony_ci      .width(this.style.textHoverWidth)
80e75ebbc8Sopenharmony_ci      .height(this.style.textHoverHeight)
81e75ebbc8Sopenharmony_ci      .margin({right: this.style.marginRight})
82e75ebbc8Sopenharmony_ci      .backgroundColor(this.mTextIsHover ? this.style.hoverColor : this.style.transparentColor)
83e75ebbc8Sopenharmony_ci      .borderRadius(this.style.textHoverRadius)
84e75ebbc8Sopenharmony_ci      .clip(true)
85e75ebbc8Sopenharmony_ci    }
86e75ebbc8Sopenharmony_ci    .borderRadius(this.style.borderRadius)
87e75ebbc8Sopenharmony_ci    .clip(true)
88e75ebbc8Sopenharmony_ci    .backgroundColor(this.style.backgroundColor)
89e75ebbc8Sopenharmony_ci    .height('100%')
90e75ebbc8Sopenharmony_ci    .width('100%')
91e75ebbc8Sopenharmony_ci  }
92e75ebbc8Sopenharmony_ci}