1c41cb6d2Sopenharmony_ci/**
2c41cb6d2Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3c41cb6d2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c41cb6d2Sopenharmony_ci * you may not use this file except in compliance with the License.
5c41cb6d2Sopenharmony_ci * You may obtain a copy of the License at
6c41cb6d2Sopenharmony_ci *
7c41cb6d2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8c41cb6d2Sopenharmony_ci *
9c41cb6d2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c41cb6d2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c41cb6d2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c41cb6d2Sopenharmony_ci * See the License for the specific language governing permissions and
13c41cb6d2Sopenharmony_ci * limitations under the License.
14c41cb6d2Sopenharmony_ci */
15c41cb6d2Sopenharmony_ci
16c41cb6d2Sopenharmony_ciimport ComponentConfig from './ComponentConfig';
17c41cb6d2Sopenharmony_ci
18c41cb6d2Sopenharmony_ci/**
19c41cb6d2Sopenharmony_ci * Standard dialog button layout, which contains two choice buttons.
20c41cb6d2Sopenharmony_ci * Click events can be defined by two parameters: firstClickEvent and secondClickEvent.
21c41cb6d2Sopenharmony_ci */
22c41cb6d2Sopenharmony_ci@Component
23c41cb6d2Sopenharmony_ciexport struct DialogButtonLayout {
24c41cb6d2Sopenharmony_ci  @State secondButtonState: boolean = true;
25c41cb6d2Sopenharmony_ci  private firstTitle: string | Resource = $r("app.string.cancel");
26c41cb6d2Sopenharmony_ci  private secondTitle: string | Resource = $r("app.string.confirm");
27c41cb6d2Sopenharmony_ci
28c41cb6d2Sopenharmony_ci  build() {
29c41cb6d2Sopenharmony_ci    DialogButtonLayoutWithState({
30c41cb6d2Sopenharmony_ci      firstTitle: this.firstTitle,
31c41cb6d2Sopenharmony_ci      secondTitle: this.secondTitle,
32c41cb6d2Sopenharmony_ci      firstClickEvent: this.firstClickEvent,
33c41cb6d2Sopenharmony_ci      secondClickEvent: this.secondClickEvent,
34c41cb6d2Sopenharmony_ci      secondButtonState: this.secondButtonState,
35c41cb6d2Sopenharmony_ci    })
36c41cb6d2Sopenharmony_ci  }
37c41cb6d2Sopenharmony_ci
38c41cb6d2Sopenharmony_ci  private firstClickEvent: (event: ClickEvent) => void = (event: ClickEvent) => {
39c41cb6d2Sopenharmony_ci  };
40c41cb6d2Sopenharmony_ci  private secondClickEvent: (event: ClickEvent) => void = (event: ClickEvent) => {
41c41cb6d2Sopenharmony_ci  };
42c41cb6d2Sopenharmony_ci}
43c41cb6d2Sopenharmony_ci
44c41cb6d2Sopenharmony_ci/**
45c41cb6d2Sopenharmony_ci * Standard dialog button layout, which contains two choices buttons.
46c41cb6d2Sopenharmony_ci *
47c41cb6d2Sopenharmony_ci * @secondButtonState the click state of second button.
48c41cb6d2Sopenharmony_ci */
49c41cb6d2Sopenharmony_ci@Component
50c41cb6d2Sopenharmony_ciexport struct DialogButtonLayoutWithState {
51c41cb6d2Sopenharmony_ci  @Prop secondButtonState: boolean = true;
52c41cb6d2Sopenharmony_ci  private firstTitle: string | Resource = $r("app.string.cancel");
53c41cb6d2Sopenharmony_ci  private secondTitle: string | Resource = $r("app.string.add");
54c41cb6d2Sopenharmony_ci
55c41cb6d2Sopenharmony_ci  build() {
56c41cb6d2Sopenharmony_ci    Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) {
57c41cb6d2Sopenharmony_ci      Button(this.firstTitle)
58c41cb6d2Sopenharmony_ci        .backgroundColor(Color.White)
59c41cb6d2Sopenharmony_ci        .fontSize($r("app.float.font_16"))
60c41cb6d2Sopenharmony_ci        .fontColor($r("app.color.font_color_007DFF"))
61c41cb6d2Sopenharmony_ci        .fontWeight(FontWeight.Medium)
62c41cb6d2Sopenharmony_ci        .width(ComponentConfig.WH_50_100)
63c41cb6d2Sopenharmony_ci        .onClick((event) => this.firstClickEvent(event as ClickEvent))
64c41cb6d2Sopenharmony_ci        .height($r("app.float.wh_value_40"))
65c41cb6d2Sopenharmony_ci
66c41cb6d2Sopenharmony_ci      Divider()
67c41cb6d2Sopenharmony_ci        .strokeWidth('1vp')
68c41cb6d2Sopenharmony_ci        .color($r("sys.color.ohos_id_color_list_separator"))
69c41cb6d2Sopenharmony_ci        .vertical(true)
70c41cb6d2Sopenharmony_ci        .height($r("app.float.wh_value_40"))
71c41cb6d2Sopenharmony_ci        .opacity($r("app.float.opacity_0_2"))
72c41cb6d2Sopenharmony_ci
73c41cb6d2Sopenharmony_ci      Button(this.secondTitle)
74c41cb6d2Sopenharmony_ci        .backgroundColor(Color.White)
75c41cb6d2Sopenharmony_ci        .fontSize($r("app.float.font_16"))
76c41cb6d2Sopenharmony_ci        .fontColor($r("app.color.font_color_007DFF"))
77c41cb6d2Sopenharmony_ci        .fontWeight(FontWeight.Medium)
78c41cb6d2Sopenharmony_ci        .width(ComponentConfig.WH_50_100)
79c41cb6d2Sopenharmony_ci        .enabled(this.secondButtonState)
80c41cb6d2Sopenharmony_ci        .opacity(this.secondButtonState ? 1 : 0.5)
81c41cb6d2Sopenharmony_ci        .onClick(event => this.secondClickEvent(event as ClickEvent))
82c41cb6d2Sopenharmony_ci        .height($r("app.float.wh_value_40"))
83c41cb6d2Sopenharmony_ci    }
84c41cb6d2Sopenharmony_ci    .margin({ bottom: $r("app.float.wh_value_16") })
85c41cb6d2Sopenharmony_ci  }
86c41cb6d2Sopenharmony_ci
87c41cb6d2Sopenharmony_ci  private firstClickEvent: (event: ClickEvent) => void = (event: ClickEvent) => {
88c41cb6d2Sopenharmony_ci  };
89c41cb6d2Sopenharmony_ci  private secondClickEvent: (event: ClickEvent) => void = (event: ClickEvent) => {
90c41cb6d2Sopenharmony_ci  };
91c41cb6d2Sopenharmony_ci}