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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_STEPPER_ITEM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_STEPPER_ITEM_H
18 
19 #include "core/components/stepper/stepper_item_component.h"
20 #include "frameworks/bridge/common/dom/dom_node.h"
21 
22 namespace OHOS::Ace::Framework {
23 
24 class DOMStepperItem final : public DOMNode {
25     DECLARE_ACE_TYPE(DOMStepperItem, DOMNode);
26 
27 public:
28     DOMStepperItem(NodeId nodeId, const std::string& nodeName, int32_t index);
29     ~DOMStepperItem() override = default;
30 
SetLabel(const StepperLabels & label)31     void SetLabel(const StepperLabels& label)
32     {
33         label_ = label;
34     }
35 
GetLabel()36     const StepperLabels& GetLabel() const
37     {
38         return label_;
39     }
40 
GetTextStyle()41     const TextStyle& GetTextStyle() const
42     {
43         return textStyle_;
44     }
45 
GetSpecializedComponent()46     RefPtr<Component> GetSpecializedComponent() override
47     {
48         return stepperItemComponent_;
49     }
50 
GetItemIndex()51     int32_t GetItemIndex() const
52     {
53         return itemIndex_;
54     }
55 
56     void InitializeStyle() override;
57 
58 protected:
59     void OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot) override;
60     void OnChildNodeRemoved(const RefPtr<DOMNode>& child) override;
61     bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override;
62     bool AddSpecializedEvent(int32_t pageId, const std::string& event) override;
63     void PrepareSpecializedComponent() override;
64     RefPtr<Component> CompositeSpecializedComponent(const std::vector<RefPtr<SingleChild>>& components) override;
65     void ResetInitializedStyle() override;
66 
67 private:
68     void AddStepperItem(const RefPtr<DOMNode>& node, int32_t slot);
69     void RemoveStepperItem(const RefPtr<DOMNode>& node);
70 
71     RefPtr<StepperItemComponent> stepperItemComponent_;
72     TextStyle textStyle_;
73     StepperLabels label_;
74     EventMarker appearEventId_;
75     EventMarker disappearEventId_;
76     int32_t itemIndex_ = -1;
77     FlexDirection flexDirection_ { FlexDirection::ROW };
78     FlexAlign flexMainAlign_ { FlexAlign::FLEX_START };
79     FlexAlign flexCrossAlign_ { FlexAlign::FLEX_START };
80     RefPtr<FlexComponent> flexComponent_;
81     RefPtr<DisplayComponent> displayComponent_;
82 };
83 
84 } // namespace OHOS::Ace::Framework
85 
86 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_STEPPER_ITEM_H
87