1 /* 2 * Copyright (c) 2022 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_CORE_COMPONENTS_NG_PATTERN_STEPPER_STEPPER_ITEM_LAYOUT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_STEPPER_STEPPER_ITEM_LAYOUT_PROPERTY_H 18 19 #include "base/i18n/localization.h" 20 #include "core/components_ng/base/inspector_filter.h" 21 #include "core/components_ng/layout/layout_property.h" 22 23 namespace OHOS::Ace::NG { 24 25 class ACE_EXPORT StepperItemLayoutProperty : public LayoutProperty { 26 DECLARE_ACE_TYPE(StepperItemLayoutProperty, LayoutProperty); 27 28 public: 29 StepperItemLayoutProperty() = default; 30 ~StepperItemLayoutProperty() override = default; 31 Clone()32 RefPtr<LayoutProperty> Clone() const override 33 { 34 auto value = MakeRefPtr<StepperItemLayoutProperty>(); 35 value->LayoutProperty::UpdateLayoutProperty(AceType::DynamicCast<LayoutProperty>(this)); 36 value->propLeftLabel_ = CloneLeftLabel(); 37 value->propRightLabel_ = CloneRightLabel(); 38 value->propLabelStatus_ = CloneLabelStatus(); 39 return value; 40 } 41 Reset()42 void Reset() override 43 { 44 LayoutProperty::Reset(); 45 ResetLeftLabel(); 46 ResetRightLabel(); 47 ResetLabelStatus(); 48 } 49 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)50 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 51 { 52 LayoutProperty::ToJsonValue(json, filter); 53 /* no fixed attr below, just return */ 54 if (filter.IsFastFilter()) { 55 return; 56 } 57 json->PutExtAttr("prevLabel", 58 GetLeftLabel().value_or(Localization::GetInstance()->GetEntryLetters("stepper.back")).c_str(), filter); 59 json->PutExtAttr("nextLabel", 60 GetRightLabel().value_or(Localization::GetInstance()->GetEntryLetters("stepper.next")).c_str(), filter); 61 static const std::map<std::string, std::string> STATUS_TO_STRING = { { "normal", "ItemState.Normal" }, 62 { "disabled", "ItemState.Disabled" }, { "waiting", "ItemState.Waiting" }, { "skip", "ItemState.Skip" } }; 63 json->PutExtAttr("status", STATUS_TO_STRING.at(GetLabelStatus().value_or("normal")).c_str(), filter); 64 } 65 66 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LeftLabel, std::string, PROPERTY_UPDATE_LAYOUT); 67 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RightLabel, std::string, PROPERTY_UPDATE_LAYOUT); 68 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LabelStatus, std::string, PROPERTY_UPDATE_LAYOUT); 69 70 private: 71 ACE_DISALLOW_COPY_AND_MOVE(StepperItemLayoutProperty); 72 }; 73 74 } // namespace OHOS::Ace::NG 75 76 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_STEPPER_STEPPER_ITEM_LAYOUT_PROPERTY_H 77