button fixes
This commit is contained in:
parent
4c656b54f1
commit
4dde423d2f
@ -25,6 +25,8 @@ public class ButtonModel: MoleculeProtocol {
|
|||||||
public var action: ActionProtocol
|
public var action: ActionProtocol
|
||||||
public var style: ButtonStyle? = .primary
|
public var style: ButtonStyle? = .primary
|
||||||
public var size: ButtonSize? = .standard
|
public var size: ButtonSize? = .standard
|
||||||
|
public var required: Bool?
|
||||||
|
public var requiredGroups: [String]?
|
||||||
|
|
||||||
init(with title: String, action: ActionProtocol) {
|
init(with title: String, action: ActionProtocol) {
|
||||||
self.title = title
|
self.title = title
|
||||||
@ -37,6 +39,8 @@ public class ButtonModel: MoleculeProtocol {
|
|||||||
case action
|
case action
|
||||||
case style
|
case style
|
||||||
case size
|
case size
|
||||||
|
case required
|
||||||
|
case requiredGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
@ -44,6 +48,8 @@ public class ButtonModel: MoleculeProtocol {
|
|||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
title = try typeContainer.decode(String.self, forKey: .title)
|
title = try typeContainer.decode(String.self, forKey: .title)
|
||||||
action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
||||||
|
required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required)
|
||||||
|
requiredGroups = try typeContainer.decodeIfPresent([String].self, forKey: .requiredGroups)
|
||||||
if let style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style) {
|
if let style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style) {
|
||||||
self.style = style
|
self.style = style
|
||||||
}
|
}
|
||||||
@ -59,5 +65,6 @@ public class ButtonModel: MoleculeProtocol {
|
|||||||
try container.encodeModel(action, forKey: .action)
|
try container.encodeModel(action, forKey: .action)
|
||||||
try container.encodeIfPresent(style, forKey: .style)
|
try container.encodeIfPresent(style, forKey: .style)
|
||||||
try container.encodeIfPresent(size, forKey: .size)
|
try container.encodeIfPresent(size, forKey: .size)
|
||||||
|
try container.encodeIfPresent(required, forKey: .required)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,16 @@ extension PrimaryButton: ModelMoleculeViewProtocol {
|
|||||||
guard let model = model as? ButtonModel else { return }
|
guard let model = model as? ButtonModel else { return }
|
||||||
setTitle(model.title, for: .normal)
|
setTitle(model.title, for: .normal)
|
||||||
backgroundColor = model.backgroundColor?.uiColor
|
backgroundColor = model.backgroundColor?.uiColor
|
||||||
|
|
||||||
|
self.validationRequired = model.required ?? false
|
||||||
|
self.requiredGroupsList = model.requiredGroups
|
||||||
|
|
||||||
|
if self.validationRequired,
|
||||||
|
let selfForm = self as? FormValidationEnableDisableProtocol {
|
||||||
|
FormValidator.setupValidation(molecule: selfForm, delegate: delegateObject?.formValidationProtocol)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if let style = model.style {
|
if let style = model.style {
|
||||||
switch style {
|
switch style {
|
||||||
case .primary:
|
case .primary:
|
||||||
|
|||||||
@ -46,6 +46,9 @@ static CGFloat const PrimaryButtonSmallHeight = 30.0;
|
|||||||
// set YES to skip highlight method, for customer color button
|
// set YES to skip highlight method, for customer color button
|
||||||
@property (nonatomic) BOOL skipHighlighted;
|
@property (nonatomic) BOOL skipHighlighted;
|
||||||
|
|
||||||
|
@property (nonatomic) BOOL validationRequired;
|
||||||
|
@property (nullable, nonatomic, strong) NSArray *requiredGroupsList;
|
||||||
|
|
||||||
// The main creation functions, changed to black button for 2.0 for default
|
// The main creation functions, changed to black button for 2.0 for default
|
||||||
+ (nullable instancetype)primaryButton:(BOOL)enabled;
|
+ (nullable instancetype)primaryButton:(BOOL)enabled;
|
||||||
+ (nullable instancetype)primarySmallButton:(BOOL)enabled;
|
+ (nullable instancetype)primarySmallButton:(BOOL)enabled;
|
||||||
|
|||||||
@ -20,8 +20,6 @@
|
|||||||
|
|
||||||
@interface PrimaryButton() <FormValidationEnableDisableProtocol>
|
@interface PrimaryButton() <FormValidationEnableDisableProtocol>
|
||||||
|
|
||||||
@property (nonatomic) BOOL validationRequired;
|
|
||||||
@property (nonatomic, strong) NSArray *requiredGroupsList;
|
|
||||||
@property (nonatomic) BOOL smallButton;
|
@property (nonatomic) BOOL smallButton;
|
||||||
@property (assign, nonatomic) BOOL tinyButton;
|
@property (assign, nonatomic) BOOL tinyButton;
|
||||||
@property (nonatomic) CGFloat sizeForSizing;
|
@property (nonatomic) CGFloat sizeForSizing;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user