1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16exports.source = ` 17@Extend Text.fancy(color:string){ 18 .backgroundColor(color) 19} 20 21@Extend 22Text.superFancy(size:number){ 23 .fontSize(size) 24 .fancy(Color.Red) 25} 26 27@Extend(Button) 28function fancy(color:string){ 29 .backgroundColor(color) 30 .width(200) 31 .height(100) 32} 33 34@Entry 35@Component 36struct FancyText { 37 build() { 38 Row() { 39 Text("Just Fancy").fancy(Color.Yellow) 40 Text("Super Fancy Text").height(70).superFancy(24) 41 Button("Fancy Button").fancy(Color.Green) 42 } 43 } 44}` 45 46exports.expectResult = 47`"use strict"; 48function __Text__fancy(color) { 49 Text.backgroundColor(color); 50} 51function __Text__superFancy(size) { 52 Text.fontSize(size); 53 __Text__fancy(Color.Red); 54} 55function __Button__fancy(color) { 56 Button.backgroundColor(color); 57 Button.width(200); 58 Button.height(100); 59} 60class FancyText extends View { 61 constructor(compilerAssignedUniqueChildId, parent, params) { 62 super(compilerAssignedUniqueChildId, parent); 63 this.updateWithValueParams(params); 64 } 65 updateWithValueParams(params) { 66 } 67 aboutToBeDeleted() { 68 SubscriberManager.Get().delete(this.id()); 69 } 70 render() { 71 Row.create(); 72 Text.create("Just Fancy"); 73 __Text__fancy(Color.Yellow); 74 Text.pop(); 75 Text.create("Super Fancy Text"); 76 Text.height(70); 77 __Text__superFancy(24); 78 Text.pop(); 79 Button.createWithLabel("Fancy Button"); 80 __Button__fancy(Color.Green); 81 Button.pop(); 82 Row.pop(); 83 } 84} 85loadDocument(new FancyText("1", undefined, {})); 86` 87