-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FXIOS-7395 [v120] Link button (#16858)
* Create link button in component library * Add sample app link button example * Make adjustment to link button config * swiftlint
- Loading branch information
Showing
6 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
BrowserKit/Sources/ComponentLibrary/Buttons/LinkButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import Common | ||
import UIKit | ||
|
||
public class LinkButton: ResizableButton, ThemeApplicable { | ||
private struct UX { | ||
static let buttonCornerRadius: CGFloat = 13 | ||
static let buttonVerticalInset: CGFloat = 12 | ||
static let buttonHorizontalInset: CGFloat = 16 | ||
} | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
|
||
backgroundColor = .clear | ||
titleLabel?.adjustsFontForContentSizeCategory = true | ||
contentEdgeInsets = UIEdgeInsets(top: UX.buttonVerticalInset, | ||
left: UX.buttonHorizontalInset, | ||
bottom: UX.buttonVerticalInset, | ||
right: UX.buttonHorizontalInset) | ||
} | ||
|
||
public func configure(viewModel: LinkButtonViewModel) { | ||
accessibilityIdentifier = viewModel.a11yIdentifier | ||
setTitle(viewModel.title, for: .normal) | ||
titleLabel?.font = DefaultDynamicFontHelper.preferredFont(withTextStyle: .body, | ||
size: viewModel.fontSize) | ||
titleLabel?.textAlignment = viewModel.textAlignment | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: ThemeApplicable | ||
|
||
public func applyTheme(theme: Theme) { | ||
setTitleColor(theme.colors.textAccent, for: .normal) | ||
setTitleColor(theme.colors.actionPrimaryHover, for: .highlighted) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
BrowserKit/Sources/ComponentLibrary/Buttons/LinkButtonViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import UIKit | ||
import Foundation | ||
|
||
/// The view model used to configure a `LinkButton` | ||
public struct LinkButtonViewModel { | ||
public let title: String | ||
public let a11yIdentifier: String | ||
public let fontSize: CGFloat | ||
public let textAlignment: NSTextAlignment | ||
|
||
public init(title: String, | ||
a11yIdentifier: String, | ||
fontSize: CGFloat = 16, | ||
textAlignment: NSTextAlignment = .left) { | ||
self.title = title | ||
self.a11yIdentifier = a11yIdentifier | ||
self.fontSize = fontSize | ||
self.textAlignment = textAlignment | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...it/Sources/ComponentLibrary/Documentation.docc/General Components/LinkButton.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# ``ComponentLibrary/LinkButton`` | ||
|
||
The button which is used for actions that looks like a webview link. | ||
|
||
## Overview | ||
|
||
The `LinkButton` is a subclass of the `UIButton`. This means properties of the `UIButton` are accessible, but for easy conveniance it's recommended to configure the button title, font and accessibility identifier through it's' view model ``LinkButtonViewModel``. The colors and spacing of the button although accessible shouldn't be adjusted and should be used as is. | ||
|
||
## Illustration | ||
|
||
> This image is illustrative only. For precise examples of iOS implementation, please run the SampleApplication. | ||
![The LinkButton on iOS]LinkButton | ||
|
||
## Topics | ||
|
||
### View Model | ||
|
||
- ``LinkButtonViewModel`` |
Binary file added
BIN
+3.15 KB
BrowserKit/Sources/ComponentLibrary/Documentation.docc/Resources/LinkButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.05 KB
...erKit/Sources/ComponentLibrary/Documentation.docc/Resources/LinkButton~dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters