1/* 2 * Copyright (c) 2023 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 16/// <reference path='./import.ts' /> 17class CheckboxGroupSelectAllModifier extends ModifierWithKey<boolean> { 18 constructor(value: boolean) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('checkboxgroupSelectAll'); 22 applyPeer(node: KNode, reset: boolean) { 23 if (reset) { 24 getUINativeModule().checkboxgroup.resetCheckboxGroupSelectAll(node); 25 } else { 26 getUINativeModule().checkboxgroup.setCheckboxGroupSelectAll(node, this.value); 27 } 28 } 29} 30 31class CheckboxGroupSelectedColorModifier extends ModifierWithKey<ResourceColor> { 32 constructor(value: ResourceColor) { 33 super(value); 34 } 35 static identity: Symbol = Symbol('checkboxgroupSelectedColor'); 36 applyPeer(node: KNode, reset: boolean) { 37 if (reset) { 38 getUINativeModule().checkboxgroup.resetCheckboxGroupSelectedColor(node); 39 } else { 40 getUINativeModule().checkboxgroup.setCheckboxGroupSelectedColor(node, this.value); 41 } 42 } 43 44 checkObjectDiff() { 45 return !isBaseOrResourceEqual(this.stageValue, this.value); 46 } 47} 48 49class CheckboxGroupUnselectedColorModifier extends ModifierWithKey<ResourceColor> { 50 constructor(value: ResourceColor) { 51 super(value); 52 } 53 static identity: Symbol = Symbol('checkboxgroupUnselectedColor'); 54 applyPeer(node: KNode, reset: boolean) { 55 if (reset) { 56 getUINativeModule().checkboxgroup.resetCheckboxGroupUnSelectedColor(node); 57 } else { 58 getUINativeModule().checkboxgroup.setCheckboxGroupUnSelectedColor(node, this.value); 59 } 60 } 61 62 checkObjectDiff() { 63 return !isBaseOrResourceEqual(this.stageValue, this.value); 64 } 65} 66class CheckboxGroupMarkModifier extends ModifierWithKey<MarkStyle> { 67 constructor(value: MarkStyle) { 68 super(value); 69 } 70 static identity: Symbol = Symbol('checkboxgroupMark'); 71 applyPeer(node: KNode, reset: boolean): void { 72 if (reset) { 73 getUINativeModule().checkboxgroup.resetCheckboxGroupMark(node); 74 } else { 75 getUINativeModule().checkboxgroup.setCheckboxGroupMark(node, this.value?.strokeColor, this.value?.size, this.value?.strokeWidth); 76 } 77 } 78 79 checkObjectDiff(): boolean { 80 let colorEQ = isBaseOrResourceEqual(this.stageValue.strokeColor, this.value.strokeColor); 81 let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size); 82 let widthEQ = isBaseOrResourceEqual(this.stageValue.strokeWidth, this.value.strokeWidth); 83 return !colorEQ || !sizeEQ || !widthEQ; 84 } 85} 86 87class CheckboxGroupWidthModifier extends ModifierWithKey<Length> { 88 constructor(value: Length) { 89 super(value); 90 } 91 static identity: Symbol = Symbol('checkboxGroupWidth'); 92 applyPeer(node: KNode, reset: boolean): void { 93 if (reset) { 94 getUINativeModule().checkboxgroup.resetCheckboxGroupWidth(node); 95 } else { 96 getUINativeModule().checkboxgroup.setCheckboxGroupWidth(node, this.value); 97 } 98 } 99 100 checkObjectDiff(): boolean { 101 return !isBaseOrResourceEqual(this.stageValue, this.value); 102 } 103} 104 105class CheckboxGroupSizeModifier extends ModifierWithKey<SizeOptions> { 106 constructor(value: SizeOptions) { 107 super(value); 108 } 109 static identity: Symbol = Symbol('checkboxGroupSize'); 110 applyPeer(node: KNode, reset: boolean): void { 111 if (reset) { 112 getUINativeModule().checkboxgroup.resetCheckboxGroupSize(node); 113 } else { 114 getUINativeModule().checkboxgroup.setCheckboxGroupSize(node, this.value.width, this.value.height); 115 } 116 } 117 118 checkObjectDiff(): boolean { 119 return !isBaseOrResourceEqual(this.stageValue.width, this.value.width) || 120 !isBaseOrResourceEqual(this.stageValue.height, this.value.height); 121 } 122} 123 124class CheckboxGroupHeightModifier extends ModifierWithKey<Length> { 125 constructor(value: Length) { 126 super(value); 127 } 128 static identity: Symbol = Symbol('checkboxGroupHeight'); 129 applyPeer(node: KNode, reset: boolean): void { 130 if (reset) { 131 getUINativeModule().checkboxgroup.resetCheckboxGroupHeight(node); 132 } else { 133 getUINativeModule().checkboxgroup.setCheckboxGroupHeight(node, this.value); 134 } 135 } 136 137 checkObjectDiff(): boolean { 138 return !isBaseOrResourceEqual(this.stageValue, this.value); 139 } 140} 141 142class CheckboxGroupStyleModifier extends ModifierWithKey<CheckBoxShape> { 143 constructor(value: CheckBoxShape) { 144 super(value); 145 } 146 static identity: Symbol = Symbol('checkboxgroupStyle'); 147 applyPeer(node: KNode, reset: boolean) { 148 if (reset) { 149 getUINativeModule().checkboxgroup.resetCheckboxGroupStyle(node); 150 } else { 151 getUINativeModule().checkboxgroup.setCheckboxGroupStyle(node, this.value); 152 } 153 } 154 155 checkObjectDiff() { 156 return !isBaseOrResourceEqual(this.stageValue, this.value); 157 } 158} 159 160class ArkCheckboxGroupComponent extends ArkComponent implements CheckboxGroupAttribute { 161 constructor(nativePtr: KNode, classType?: ModifierType) { 162 super(nativePtr, classType); 163 } 164 selectAll(value: boolean): this { 165 modifierWithKey(this._modifiersWithKeys, CheckboxGroupSelectAllModifier.identity, CheckboxGroupSelectAllModifier, value); 166 return this; 167 } 168 selectedColor(value: ResourceColor): this { 169 modifierWithKey(this._modifiersWithKeys, CheckboxGroupSelectedColorModifier.identity, CheckboxGroupSelectedColorModifier, value); 170 return this; 171 } 172 unselectedColor(value: ResourceColor): this { 173 modifierWithKey(this._modifiersWithKeys, CheckboxGroupUnselectedColorModifier.identity, CheckboxGroupUnselectedColorModifier, value); 174 return this; 175 } 176 mark(value: MarkStyle): this { 177 modifierWithKey( 178 this._modifiersWithKeys, CheckboxGroupMarkModifier.identity, CheckboxGroupMarkModifier, value); 179 return this; 180 } 181 onChange(callback: (event: CheckboxGroupResult) => void): CheckboxGroupAttribute { 182 throw new Error('Method not implemented.'); 183 } 184 size(value: SizeOptions): this { 185 modifierWithKey( 186 this._modifiersWithKeys, CheckboxGroupSizeModifier.identity, CheckboxGroupSizeModifier, value); 187 return this; 188 } 189 width(value: Length): this { 190 modifierWithKey(this._modifiersWithKeys, CheckboxGroupWidthModifier.identity, CheckboxGroupWidthModifier, value); 191 return this; 192 } 193 height(value: Length): this { 194 modifierWithKey(this._modifiersWithKeys, CheckboxGroupHeightModifier.identity, 195 CheckboxGroupHeightModifier, value); 196 return this; 197 } 198 checkboxShape(value: CheckBoxShape): this { 199 modifierWithKey(this._modifiersWithKeys, CheckboxGroupStyleModifier.identity, CheckboxGroupStyleModifier, value); 200 return this; 201 } 202} 203// @ts-ignore 204globalThis.CheckboxGroup.attributeModifier = function (modifier: ArkComponent): void { 205 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 206 return new ArkCheckboxGroupComponent(nativePtr); 207 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 208 return new modifierJS.CheckboxGroupModifier(nativePtr, classType); 209 }); 210}; 211