Skip to content

Commit

Permalink
Merge pull request #331 from GSM-MSG/330-design-system-file-field
Browse files Browse the repository at this point in the history
🔀 :: [#330] DesignSystem / FileField
  • Loading branch information
kimsh153 authored May 30, 2024
2 parents a7f554e + 7a30fcc commit 14b7b5c
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "file.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions Projects/Core/DesignSystem/Sources/File/FileField.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import SwiftUI
import ViewUtil
import UniformTypeIdentifiers

public struct FileField: View {
@State var fileText: String
@State var isShow: Bool
@State var isError: Bool
let errorText: String
let allowedContentTypes: [UTType]
let action: (URL) -> Void

public init(
fileText: String,
isShow: Bool,
isError: Bool = false,
errorText: String = "",
allowedContentTypes: [UTType] = [.content],
action: @escaping (URL) -> Void
) {
self.fileText = fileText
self.isShow = isShow
self.isError = isError
self.errorText = errorText
self.allowedContentTypes = allowedContentTypes
self.action = action
}

public var body: some View {
SMSTextField(
"",
text: Binding(
get: { fileText },
set: { _ in }
),
errorText: errorText,
isError: isError,
isOnClear: false
)
.disabled(true)
.overlay(alignment: .trailing) {
SMSIcon(.file)
.padding(.trailing, 12)
}
.simultaneousGesture(
TapGesture()
.onEnded {
self.isShow = true
}
)
.fileImporter(
isPresented: Binding(
get: { isShow },
set: { active in
isShow = active
}
),
allowedContentTypes: allowedContentTypes
) { result in
switch result {
case .success(let url):
fileText = url.lastPathComponent
action(url)

case .failure:
self.isError = true
}
}
}
}
4 changes: 4 additions & 0 deletions Projects/Core/DesignSystem/Sources/Icon/SMSIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public struct SMSIcon: View {
case check
case checkmark
case downChevron
case file
case filter
case greenCheck
case photo
Expand Down Expand Up @@ -74,6 +75,9 @@ public struct SMSIcon: View {
case .downChevron:
return DesignSystemAsset.Icons.downChevron.swiftUIImage

case .file:
return DesignSystemAsset.Icons.file.swiftUIImage

case .filter:
return DesignSystemAsset.Icons.filter.swiftUIImage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct SMSTextEditor: View {
.onSubmit(onSubmit)
.smsFont(.body1, color: .neutral(.n50))
.focused($isFocused)

SMSIcon(.xmark)
.buttonWrapper {
text = ""
Expand All @@ -54,7 +54,7 @@ public struct SMSTextEditor: View {
.onTapGesture {
isFocused = true
}

if text.isEmpty {
Text(placeholder)
.smsFont(.body1, color: .neutral(.n30))
Expand Down

0 comments on commit 14b7b5c

Please sign in to comment.