• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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
16const __ArcAlphabetIndexer__ = requireInternal('arkui.ArcAlphabetIndexer');
17const ModifierMap = requireNapi('arkui.modifier').ModifierMap;
18const ModifierUtils = requireNapi('arkui.modifier').ModifierUtils;
19const LengthUnit = requireNapi('arkui.node').LengthUnit;
20
21class ArcAlphabetIndexerColorModifier extends ModifierWithKey {
22    static identity = Symbol('color');
23    constructor(value) {
24        super(value);
25    }
26    applyPeer(node, reset) {
27        if (reset || !this.value) {
28            getUINativeModule().alphabetIndexer.resetColor(node);
29        }
30        else {
31            getUINativeModule().alphabetIndexer.setColor(node, this.value.color);
32        }
33    }
34    checkObjectDiff() {
35        if (!this.stageValue && !this.value) {
36            return false;
37        } else if (this.stageValue && this.value) {
38            return this.stageValue.color !== this.value.color;
39        }
40        return true;
41    }
42}
43
44class ArcAlphabetIndexerSelectedColorModifier extends ModifierWithKey {
45    static identity = Symbol('selectedColor');
46    constructor(value) {
47        super(value);
48    }
49    applyPeer(node, reset) {
50        if (reset || !this.value) {
51            getUINativeModule().alphabetIndexer.resetSelectedColor(node);
52        }
53        else {
54            getUINativeModule().alphabetIndexer.setSelectedColor(node, this.value.color);
55        }
56    }
57    checkObjectDiff() {
58        if (!this.stageValue && !this.value) {
59            return false;
60        } else if (this.stageValue && this.value) {
61            return this.stageValue.color !== this.value.color;
62        }
63        return true;
64    }
65}
66
67class ArcAlphabetIndexerPopupColorModifier extends ModifierWithKey {
68    static identity = Symbol('popupColor');
69    constructor(value) {
70        super(value);
71    }
72    applyPeer(node, reset) {
73        if (reset || !this.value) {
74            getUINativeModule().alphabetIndexer.resetPopupColor(node);
75        }
76        else {
77            getUINativeModule().alphabetIndexer.setPopupColor(node, this.value.color);
78        }
79    }
80    checkObjectDiff() {
81        if (!this.stageValue && !this.value) {
82            return false;
83        } else if (this.stageValue && this.value) {
84            return this.stageValue.color !== this.value.color;
85        }
86        return true;
87    }
88}
89
90class ArcAlphabetIndexerSelectedBackgroundColorModifier extends ModifierWithKey {
91    static identity = Symbol('selectedBackgroundColor');
92    constructor(value) {
93        super(value);
94    }
95    applyPeer(node, reset) {
96        if (reset || !this.value) {
97            getUINativeModule().alphabetIndexer.resetSelectedBackgroundColor(node);
98        }
99        else {
100            getUINativeModule().alphabetIndexer.setSelectedBackgroundColor(node, this.value.color);
101        }
102    }
103    checkObjectDiff() {
104        if (!this.stageValue && !this.value) {
105            return false;
106        } else if (this.stageValue && this.value) {
107            return this.stageValue.color !== this.value.color;
108        }
109        return true;
110    }
111}
112
113class ArcAlphabetIndexerPopupBackgroundModifier extends ModifierWithKey {
114    static identity = Symbol('popupBackground');
115    constructor(value) {
116        super(value);
117    }
118    applyPeer(node, reset) {
119        if (reset || !this.value) {
120            getUINativeModule().alphabetIndexer.resetPopupBackground(node);
121        }
122        else {
123            getUINativeModule().alphabetIndexer.setPopupBackground(node, this.value.color);
124        }
125    }
126    checkObjectDiff() {
127        if (!this.stageValue && !this.value) {
128            return false;
129        } else if (this.stageValue && this.value) {
130            return this.stageValue.color !== this.value.color;
131        }
132        return true;
133    }
134}
135
136class ArcAlphabetIndexerItemSizeModifier extends ModifierWithKey {
137    static identity = Symbol('itemSize');
138    constructor(value) {
139        super(value);
140    }
141    applyPeer(node, reset) {
142        if (reset || !this.value) {
143            getUINativeModule().alphabetIndexer.resetItemSize(node);
144        }
145        else {
146            let size = `${this.value.value}${LengthUnit[this.value.unit]}`;
147            getUINativeModule().alphabetIndexer.setItemSize(node, size);
148        }
149    }
150    checkObjectDiff() {
151        if (!this.stageValue && !this.value) {
152            return false;
153        } else if (this.stageValue && this.value) {
154            if (this.stageValue.value !== this.value.value ||
155                this.stageValue.unit !== this.value.unit) {
156                return true;
157            }
158            return false;
159        }
160        return true;
161    }
162}
163
164class ArcAlphabetIndexerComponent extends ArkAlphabetIndexerComponent {
165    constructor(nativePtr, classType) {
166        super(nativePtr, classType);
167    }
168    color(color) {
169        modifierWithKey(this._modifiersWithKeys, ArcAlphabetIndexerColorModifier.identity, ArcAlphabetIndexerColorModifier, color);
170        return this;
171    }
172    selectedColor(color) {
173        modifierWithKey(this._modifiersWithKeys, ArcAlphabetIndexerSelectedColorModifier.identity, ArcAlphabetIndexerSelectedColorModifier, color);
174        return this;
175    }
176    popupColor(color) {
177        modifierWithKey(this._modifiersWithKeys, ArcAlphabetIndexerPopupColorModifier.identity, ArcAlphabetIndexerPopupColorModifier, color);
178        return this;
179    }
180    selectedBackgroundColor(color) {
181        modifierWithKey(this._modifiersWithKeys, ArcAlphabetIndexerSelectedBackgroundColorModifier.identity,
182            ArcAlphabetIndexerSelectedBackgroundColorModifier, color);
183        return this;
184    }
185    popupBackground(color) {
186        modifierWithKey(this._modifiersWithKeys, ArcAlphabetIndexerPopupBackgroundModifier.identity, ArcAlphabetIndexerPopupBackgroundModifier, color);
187        return this;
188    }
189    itemSize(size) {
190        modifierWithKey(this._modifiersWithKeys, ArcAlphabetIndexerItemSizeModifier.identity, ArcAlphabetIndexerItemSizeModifier, size);
191        return this;
192    }
193}
194
195class ArcAlphabetIndexerModifier extends ArcAlphabetIndexerComponent {
196    constructor(nativePtr, classType) {
197        super(nativePtr, classType);
198        this._modifiersWithKeys = new ModifierMap();
199    }
200    applyNormalAttribute(instance) {
201        ModifierUtils.applySetOnChange(this);
202        ModifierUtils.applyAndMergeModifier(instance, this);
203    }
204}
205
206class ArcAlphabetIndexer extends AlphabetIndexer {
207    static attributeModifier(modifier) {
208        attributeModifierFunc.call(this, modifier, (nativePtr) => {
209            return new ArcAlphabetIndexerComponent(nativePtr);
210        }, (nativePtr, classType, modifierJS) => {
211            return new ArcAlphabetIndexerModifier(nativePtr, classType);
212        });
213    }
214
215    static create(value) {
216        AlphabetIndexer.createArc(value);
217    }
218
219    static color(value) {
220        if (value) {
221            value = value.color;
222        }
223        AlphabetIndexer.color(value);
224    }
225
226    static selectedColor(value) {
227        if (value) {
228            value = value.color;
229        }
230        AlphabetIndexer.selectedColor(value);
231    }
232
233    static popupColor(value) {
234        if (value) {
235            value = value.color;
236        }
237        AlphabetIndexer.popupColor(value);
238    }
239
240    static selectedBackgroundColor(value) {
241        if (value) {
242            value = value.color;
243        }
244        AlphabetIndexer.selectedBackgroundColor(value);
245    }
246
247    static popupBackground(value) {
248        if (value) {
249            value = value.color;
250        }
251        AlphabetIndexer.popupBackground(value);
252    }
253
254    static itemSize(value) {
255        if (value) {
256            value = `${value.value}${LengthUnit[value.unit]}`;
257        }
258        AlphabetIndexer.itemSize(value);
259    }
260
261    static usePopup(value) {
262        AlphabetIndexer.usingPopup(value);
263    }
264}
265
266export default {
267    ArcAlphabetIndexer,
268};
269