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 49 50class CheckboxGroupUnselectedColorModifier extends ModifierWithKey<ResourceColor> { 51 constructor(value: ResourceColor) { 52 super(value); 53 } 54 static identity: Symbol = Symbol('checkboxgroupUnselectedColor'); 55 applyPeer(node: KNode, reset: boolean) { 56 if (reset) { 57 getUINativeModule().checkboxgroup.resetCheckboxGroupUnSelectedColor(node); 58 } else { 59 getUINativeModule().checkboxgroup.setCheckboxGroupUnSelectedColor(node, this.value); 60 } 61 } 62 63 checkObjectDiff() { 64 return !isBaseOrResourceEqual(this.stageValue, this.value); 65 } 66} 67class CheckboxGroupMarkModifier extends ModifierWithKey<MarkStyle> { 68 constructor(value: MarkStyle) { 69 super(value); 70 } 71 static identity: Symbol = Symbol('checkboxgroupMark'); 72 applyPeer(node: KNode, reset: boolean): void { 73 if (reset) { 74 getUINativeModule().checkboxgroup.resetCheckboxGroupMark(node); 75 } else { 76 getUINativeModule().checkboxgroup.setCheckboxGroupMark(node, this.value?.strokeColor, this.value?.size, this.value?.strokeWidth); 77 } 78 } 79 80 checkObjectDiff(): boolean { 81 let colorEQ = isBaseOrResourceEqual(this.stageValue.strokeColor, this.value.strokeColor); 82 let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size); 83 let widthEQ = isBaseOrResourceEqual(this.stageValue.strokeWidth, this.value.strokeWidth); 84 return !colorEQ || !sizeEQ || !widthEQ; 85 } 86} 87 88class CheckboxGroupWidthModifier extends ModifierWithKey<Length> { 89 constructor(value: Length) { 90 super(value); 91 } 92 static identity: Symbol = Symbol('checkboxGroupWidth'); 93 applyPeer(node: KNode, reset: boolean): void { 94 if (reset) { 95 getUINativeModule().checkboxgroup.resetCheckboxGroupWidth(node); 96 } else { 97 getUINativeModule().checkboxgroup.setCheckboxGroupWidth(node, this.value); 98 } 99 } 100 101 checkObjectDiff(): boolean { 102 return !isBaseOrResourceEqual(this.stageValue, this.value); 103 } 104} 105 106class CheckboxGroupSizeModifier extends ModifierWithKey<SizeOptions> { 107 constructor(value: SizeOptions) { 108 super(value); 109 } 110 static identity: Symbol = Symbol('checkboxGroupSize'); 111 applyPeer(node: KNode, reset: boolean): void { 112 if (reset) { 113 getUINativeModule().checkboxgroup.resetCheckboxGroupSize(node); 114 } else { 115 getUINativeModule().checkboxgroup.setCheckboxGroupSize(node, this.value.width, this.value.height); 116 } 117 } 118 119 checkObjectDiff(): boolean { 120 return !isBaseOrResourceEqual(this.stageValue.width, this.value.width) || 121 !isBaseOrResourceEqual(this.stageValue.height, this.value.height); 122 } 123} 124 125class CheckboxGroupHeightModifier extends ModifierWithKey<Length> { 126 constructor(value: Length) { 127 super(value); 128 } 129 static identity: Symbol = Symbol('checkboxGroupHeight'); 130 applyPeer(node: KNode, reset: boolean): void { 131 if (reset) { 132 getUINativeModule().checkboxgroup.resetCheckboxGroupHeight(node); 133 } else { 134 getUINativeModule().checkboxgroup.setCheckboxGroupHeight(node, this.value); 135 } 136 } 137 138 checkObjectDiff(): boolean { 139 return !isBaseOrResourceEqual(this.stageValue, this.value); 140 } 141} 142 143class CheckboxGroupStyleModifier extends ModifierWithKey<CheckBoxShape> { 144 constructor(value: CheckBoxShape) { 145 super(value); 146 } 147 static identity: Symbol = Symbol('checkboxgroupStyle'); 148 applyPeer(node: KNode, reset: boolean) { 149 if (reset) { 150 getUINativeModule().checkboxgroup.resetCheckboxGroupStyle(node); 151 } else { 152 getUINativeModule().checkboxgroup.setCheckboxGroupStyle(node, this.value); 153 } 154 } 155 156 checkObjectDiff() { 157 return !isBaseOrResourceEqual(this.stageValue, this.value); 158 } 159} 160 161class CheckBoxGroupOptionsModifier extends ModifierWithKey<CheckboxGroupOptions> { 162 constructor(value: CheckboxGroupOptions) { 163 super(value); 164 } 165 static identity: Symbol = Symbol('checkboxGroupOptions'); 166 applyPeer(node: KNode, reset: boolean): void { 167 if (reset) { 168 getUINativeModule().checkbox.setCheckboxGroupOptions(node, undefined); 169 } else { 170 getUINativeModule().checkbox.setCheckboxGroupOptions(node, this.value.group); 171 } 172 } 173 174 checkObjectDiff(): boolean { 175 return !isBaseOrResourceEqual(this.stageValue.group, this.value.group); 176 } 177} 178 179class CheckboxGroupOnChangeModifier extends ModifierWithKey<OnCheckboxGroupChangeCallback> { 180 constructor(value: OnCheckboxGroupChangeCallback) { 181 super(value); 182 } 183 static identity: Symbol = Symbol('checkboxOnChange'); 184 applyPeer(node: KNode, reset: boolean): void { 185 if (reset) { 186 getUINativeModule().checkboxgroup.resetCheckboxGroupOnChange(node); 187 } else { 188 getUINativeModule().checkboxgroup.setCheckboxGroupOnChange(node, this.value); 189 } 190 } 191} 192 193class ArkCheckboxGroupComponent extends ArkComponent implements CheckboxGroupAttribute { 194 constructor(nativePtr: KNode, classType?: ModifierType) { 195 super(nativePtr, classType); 196 } 197 allowChildCount(): number { 198 return 0; 199 } 200 initialize(value: Object[]): this { 201 if (!value.length) { 202 return this; 203 } 204 if (!isUndefined(value[0]) && !isNull(value[0]) && isObject(value[0])) { 205 modifierWithKey(this._modifiersWithKeys, CheckBoxGroupOptionsModifier.identity, CheckBoxGroupOptionsModifier, 206 value[0]); 207 } else { 208 modifierWithKey(this._modifiersWithKeys, CheckBoxGroupOptionsModifier.identity, CheckBoxGroupOptionsModifier, 209 undefined); 210 } 211 return this; 212 } 213 selectAll(value: boolean): this { 214 modifierWithKey(this._modifiersWithKeys, CheckboxGroupSelectAllModifier.identity, CheckboxGroupSelectAllModifier, value); 215 return this; 216 } 217 selectedColor(value: ResourceColor): this { 218 modifierWithKey(this._modifiersWithKeys, CheckboxGroupSelectedColorModifier.identity, CheckboxGroupSelectedColorModifier, value); 219 return this; 220 } 221 unselectedColor(value: ResourceColor): this { 222 modifierWithKey(this._modifiersWithKeys, CheckboxGroupUnselectedColorModifier.identity, CheckboxGroupUnselectedColorModifier, value); 223 return this; 224 } 225 mark(value: MarkStyle): this { 226 modifierWithKey( 227 this._modifiersWithKeys, CheckboxGroupMarkModifier.identity, CheckboxGroupMarkModifier, value); 228 return this; 229 } 230 onChange(callback: OnCheckboxGroupChangeCallback ): this { 231 modifierWithKey(this._modifiersWithKeys, CheckboxGroupOnChangeModifier.identity, CheckboxGroupOnChangeModifier, callback); 232 return this; 233 } 234 size(value: SizeOptions): this { 235 modifierWithKey( 236 this._modifiersWithKeys, CheckboxGroupSizeModifier.identity, CheckboxGroupSizeModifier, value); 237 return this; 238 } 239 width(value: Length): this { 240 modifierWithKey(this._modifiersWithKeys, CheckboxGroupWidthModifier.identity, CheckboxGroupWidthModifier, value); 241 return this; 242 } 243 height(value: Length): this { 244 modifierWithKey(this._modifiersWithKeys, CheckboxGroupHeightModifier.identity, 245 CheckboxGroupHeightModifier, value); 246 return this; 247 } 248 checkboxShape(value: CheckBoxShape): this { 249 modifierWithKey(this._modifiersWithKeys, CheckboxGroupStyleModifier.identity, CheckboxGroupStyleModifier, value); 250 return this; 251 } 252} 253// @ts-ignore 254globalThis.CheckboxGroup.attributeModifier = function (modifier: ArkComponent): void { 255 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 256 return new ArkCheckboxGroupComponent(nativePtr); 257 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 258 return new modifierJS.CheckboxGroupModifier(nativePtr, classType); 259 }); 260}; 261