1//@ts-nocheck 2/** 3 * Copyright (c) 2021-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 17import ComponentConfig from './ComponentConfig'; 18 19/** 20 * Standard dialog button layout, which contains two choice buttons. 21 * Click events can be defined by two parameters: firstClickEvent and secondClickEvent. 22 */ 23@Component 24export struct DialogButtonLayout { 25 @State secondButtonState: boolean = true; 26 private firstTitle: string | Resource = $r("app.string.cancel"); 27 private secondTitle: string | Resource = $r("app.string.confirm"); 28 private firstClickEvent: (event: ClickEvent) => void; 29 private secondClickEvent: (event: ClickEvent) => void; 30 31 build() { 32 DialogButtonLayoutWithState({ 33 firstTitle: this.firstTitle, 34 secondTitle: this.secondTitle, 35 firstClickEvent: this.firstClickEvent, 36 secondClickEvent: this.secondClickEvent, 37 secondButtonState: this.secondButtonState, 38 }) 39 } 40} 41 42/** 43 * Standard dialog button layout, which contains two choices buttons. 44 * 45 * @secondButtonState the click state of second button. 46 */ 47@Component 48export struct DialogButtonLayoutWithState { 49 private firstTitle: string | Resource = $r("app.string.cancel"); 50 private secondTitle: string | Resource = $r("app.string.add"); 51 private firstClickEvent: (event: ClickEvent) => void; 52 private secondClickEvent: (event: ClickEvent) => void; 53 @Prop secondButtonState: boolean; 54 55 build() { 56 Flex({ direction: FlexDirection.Row, alignItems: Alignment.Center }) { 57 Button(this.firstTitle) 58 .backgroundColor(Color.White) 59 .fontSize($r("app.float.font_16")) 60 .fontColor($r("app.color.font_color_007DFF")) 61 .fontWeight(FontWeight.Medium) 62 .width(ComponentConfig.WH_50_100) 63 .onClick((event) => this.firstClickEvent(event)) 64 .height($r("app.float.wh_value_40")) 65 66 Divider() 67 .strokeWidth($r("app.float.wh_value_1")) 68 .color($r("sys.color.ohos_id_color_list_separator")) 69 .vertical(true) 70 .height($r("app.float.wh_value_40")) 71 .opacity($r("app.float.opacity_0_2")) 72 73 Button(this.secondTitle) 74 .backgroundColor(Color.White) 75 .fontSize($r("app.float.font_16")) 76 .fontColor($r("app.color.font_color_007DFF")) 77 .fontWeight(FontWeight.Medium) 78 .width(ComponentConfig.WH_50_100) 79 .enabled(this.secondButtonState) 80 .opacity(this.secondButtonState ? 1 : 0.5) 81 .onClick(event => this.secondClickEvent(event)) 82 .height($r("app.float.wh_value_40")) 83 } 84 .margin({ bottom: $r("app.float.wh_value_16") }) 85 } 86}