18779efd5Sopenharmony_ci/**
28779efd5Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
38779efd5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48779efd5Sopenharmony_ci * you may not use this file except in compliance with the License.
58779efd5Sopenharmony_ci * You may obtain a copy of the License at
68779efd5Sopenharmony_ci *
78779efd5Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88779efd5Sopenharmony_ci *
98779efd5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108779efd5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118779efd5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128779efd5Sopenharmony_ci * See the License for the specific language governing permissions and
138779efd5Sopenharmony_ci * limitations under the License.
148779efd5Sopenharmony_ci */
158779efd5Sopenharmony_ci
168779efd5Sopenharmony_ci/**
178779efd5Sopenharmony_ci * Custom pop-up menu
188779efd5Sopenharmony_ci */
198779efd5Sopenharmony_ci@Component
208779efd5Sopenharmony_ciexport struct DetailMenu {
218779efd5Sopenharmony_ci  @State showPopup: boolean = false;
228779efd5Sopenharmony_ci  private menuItems: Array<{ [key: string]: any }>
238779efd5Sopenharmony_ci  private menuImage: Resource = $r('app.media.ic_public_more');
248779efd5Sopenharmony_ci  private sizeType: SizeType = SizeType.LG;
258779efd5Sopenharmony_ci  private placement: Placement = Placement.BottomLeft;
268779efd5Sopenharmony_ci  private menuText: Resource = null;
278779efd5Sopenharmony_ci  private menuTextColor: Resource = $r('sys.color.ohos_id_color_text_primary');
288779efd5Sopenharmony_ci
298779efd5Sopenharmony_ci  @Builder PopupBuilder() {
308779efd5Sopenharmony_ci    Column() {
318779efd5Sopenharmony_ci      List() {
328779efd5Sopenharmony_ci        ForEach(this.menuItems, (item, index) => {
338779efd5Sopenharmony_ci          ListItem() {
348779efd5Sopenharmony_ci            Button({ type: ButtonType.Normal, stateEffect: true }) {
358779efd5Sopenharmony_ci              Text(item.value)
368779efd5Sopenharmony_ci                .fontSize($r('sys.float.ohos_id_text_size_body1'))
378779efd5Sopenharmony_ci                .lineHeight(21)
388779efd5Sopenharmony_ci                .width('100%')
398779efd5Sopenharmony_ci                .height($r('app.float.id_item_height_mid'))
408779efd5Sopenharmony_ci                .padding({ left: $r('app.float.id_card_margin_max'), right: $r('app.float.id_card_margin_max') })
418779efd5Sopenharmony_ci                .fontWeight(FontWeight.Regular)
428779efd5Sopenharmony_ci                .fontColor($r('sys.color.ohos_id_color_text_primary'))
438779efd5Sopenharmony_ci            }
448779efd5Sopenharmony_ci            .width('100%')
458779efd5Sopenharmony_ci            .height($r('app.float.id_item_height_mid'))
468779efd5Sopenharmony_ci            .borderRadius(16)
478779efd5Sopenharmony_ci            .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary'))
488779efd5Sopenharmony_ci            .onClick(() => {
498779efd5Sopenharmony_ci              item.action();
508779efd5Sopenharmony_ci            })
518779efd5Sopenharmony_ci          }
528779efd5Sopenharmony_ci        }, item => JSON.stringify(item))
538779efd5Sopenharmony_ci      }
548779efd5Sopenharmony_ci      .listDirection(Axis.Vertical)
558779efd5Sopenharmony_ci      .divider({ strokeWidth: 0.5, color: $r('sys.color.ohos_id_color_list_separator'),
568779efd5Sopenharmony_ci        startMargin: $r('app.float.id_card_margin_max'), endMargin: $r('app.float.id_card_margin_max') })
578779efd5Sopenharmony_ci      .scrollBar(BarState.Off)
588779efd5Sopenharmony_ci      .edgeEffect(EdgeEffect.None)
598779efd5Sopenharmony_ci      .chainAnimation(false)
608779efd5Sopenharmony_ci    }
618779efd5Sopenharmony_ci    .backgroundColor(Color.White)
628779efd5Sopenharmony_ci    .width(this.sizeType == SizeType.LG ? 186 : 144)
638779efd5Sopenharmony_ci    .borderRadius(16)
648779efd5Sopenharmony_ci    .padding({ top: $r('app.float.id_card_margin_mid'), bottom: $r('app.float.id_card_margin_mid'),
658779efd5Sopenharmony_ci      left: $r('app.float.id_card_margin_mid'), right: $r('app.float.id_card_margin_mid') })
668779efd5Sopenharmony_ci  }
678779efd5Sopenharmony_ci
688779efd5Sopenharmony_ci  build() {
698779efd5Sopenharmony_ci    Column() {
708779efd5Sopenharmony_ci      Image(this.menuImage)
718779efd5Sopenharmony_ci        .width($r('app.float.id_card_image_small'))
728779efd5Sopenharmony_ci        .height($r('app.float.id_card_image_small'))
738779efd5Sopenharmony_ci      if (this.menuText != null) {
748779efd5Sopenharmony_ci        Text(this.menuText)
758779efd5Sopenharmony_ci          .fontSize(10)
768779efd5Sopenharmony_ci          .lineHeight(14)
778779efd5Sopenharmony_ci          .fontColor(this.menuTextColor)
788779efd5Sopenharmony_ci          .margin({ top: $r('app.float.id_card_margin_mid') })
798779efd5Sopenharmony_ci      }
808779efd5Sopenharmony_ci    }
818779efd5Sopenharmony_ci    .margin({ right: $r('app.float.id_card_margin_max') })
828779efd5Sopenharmony_ci    .onClick(() => {
838779efd5Sopenharmony_ci      this.showPopup = !this.showPopup;
848779efd5Sopenharmony_ci    })
858779efd5Sopenharmony_ci    .bindPopup(this.showPopup, {
868779efd5Sopenharmony_ci      builder: this.PopupBuilder,
878779efd5Sopenharmony_ci      placement: this.placement,
888779efd5Sopenharmony_ci      maskColor:'#00ffffff',
898779efd5Sopenharmony_ci      popupColor: $r('sys.color.ohos_id_color_background'),
908779efd5Sopenharmony_ci      enableArrow: false,
918779efd5Sopenharmony_ci      onStateChange: (e) => {
928779efd5Sopenharmony_ci        if (!e.isVisible) {
938779efd5Sopenharmony_ci          this.showPopup = false;
948779efd5Sopenharmony_ci        }
958779efd5Sopenharmony_ci      }
968779efd5Sopenharmony_ci    })
978779efd5Sopenharmony_ci  }
988779efd5Sopenharmony_ci}