-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #591 from kiwicom/587-create-coupon-component
Added `Coupon` component
- Loading branch information
Showing
8 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import SwiftUI | ||
|
||
/// Orbit component that highlights promo codes. | ||
/// | ||
/// - Note: [Orbit definition](https://orbit.kiwi/components/visuals/coupon/) | ||
public struct Coupon: View { | ||
|
||
let label: String | ||
let size: Text.Size | ||
|
||
public var body: some View { | ||
Text(label, size: size, isSelectable: true) | ||
.fontWeight(.medium) | ||
.kerning(0.75) | ||
.padding(.horizontal, .xxSmall) | ||
.padding(.vertical, .xxxSmall) | ||
.overlay( | ||
RoundedRectangle(cornerRadius: BorderRadius.desktop) | ||
.stroke(style: StrokeStyle(lineWidth: 1, dash: [2])) | ||
.foregroundColor(.cloudDark) | ||
) | ||
} | ||
} | ||
|
||
// MARK: - Inits | ||
public extension Coupon { | ||
|
||
/// Creates Orbit Coupon component. | ||
init(_ label: String = "", size: Text.Size = .normal) { | ||
self.label = label | ||
self.size = size | ||
} | ||
} | ||
|
||
// MARK: - Previews | ||
struct CouponPreviews: PreviewProvider { | ||
|
||
static var previews: some View { | ||
PreviewWrapper { | ||
standalone | ||
mix | ||
} | ||
.previewLayout(.sizeThatFits) | ||
} | ||
|
||
static var standalone: some View { | ||
VStack(spacing: 0) { | ||
Coupon("COUPONCODE") | ||
Coupon() // EmptyView | ||
Coupon("") // EmptyView | ||
} | ||
.padding(.medium) | ||
.previewDisplayName() | ||
} | ||
|
||
static var mix: some View { | ||
HStack(alignment: .firstTextBaseline, spacing: .small) { | ||
Coupon("HXT3B81F", size: .small) | ||
.textColor(.blueDark) | ||
.previewDisplayName() | ||
|
||
Text("PROMOCODE", size: .small) | ||
} | ||
.padding(.medium) | ||
} | ||
} |
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,29 @@ | ||
import SwiftUI | ||
import Orbit | ||
|
||
struct StorybookCoupon { | ||
|
||
static var basic: some View { | ||
VStack(alignment: .leading, spacing: .medium) { | ||
Coupon("COUPONCODE") | ||
|
||
HStack(alignment: .firstTextBaseline, spacing: .xSmall) { | ||
Coupon("HXT3B81F", size: .small) | ||
.textColor(.blueDark) | ||
.previewDisplayName() | ||
|
||
Text("PROMOCODE", size: .small) | ||
} | ||
} | ||
.previewDisplayName() | ||
} | ||
} | ||
|
||
struct StorybookCouponPreviews: PreviewProvider { | ||
|
||
static var previews: some View { | ||
OrbitPreviewWrapper { | ||
StorybookCoupon.basic | ||
} | ||
} | ||
} |
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
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
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,9 @@ | ||
import XCTest | ||
@testable import Orbit | ||
|
||
class CouponTests: SnapshotTestCase { | ||
|
||
func testCoupons() { | ||
assert(CouponPreviews.standalone) | ||
} | ||
} |
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