From 870732da6164dc9078fd3e4a94163cce07ce5b12 Mon Sep 17 00:00:00 2001 From: parkdoyeon1 Date: Wed, 14 Jun 2023 20:27:36 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=92=84=20::=20DropdownItem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/SunshijoDesign/DropDown/DropdownItem.swift | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Sources/SunshijoDesign/DropDown/DropdownItem.swift diff --git a/Sources/SunshijoDesign/DropDown/DropdownItem.swift b/Sources/SunshijoDesign/DropDown/DropdownItem.swift new file mode 100644 index 0000000..00cc3b1 --- /dev/null +++ b/Sources/SunshijoDesign/DropDown/DropdownItem.swift @@ -0,0 +1,7 @@ +import Foundation + +struct DropdownItem: Identifiable { + let id: Int + let title: String + let onSelect: () -> Void +} From 24e4feb4bbab32100a88cfa967765eaea72053e8 Mon Sep 17 00:00:00 2001 From: parkdoyeon1 Date: Wed, 14 Jun 2023 20:30:05 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=92=84=20::=20DropDownMenu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DropDown/DropdownMenu.swift | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Sources/SunshijoDesign/DropDown/DropdownMenu.swift diff --git a/Sources/SunshijoDesign/DropDown/DropdownMenu.swift b/Sources/SunshijoDesign/DropDown/DropdownMenu.swift new file mode 100644 index 0000000..5e71365 --- /dev/null +++ b/Sources/SunshijoDesign/DropDown/DropdownMenu.swift @@ -0,0 +1,86 @@ +import SwiftUI + +struct DropdownMenu: View { + @State var isSelecting = false + @State var selectionTitle = "" + @State var selectedRowId = 0 + let items: [DropdownItem] + + var body: some View { + GeometryReader { _ in + VStack(spacing: 0) { + HStack { + Text(selectionTitle) + .sdText(type: .medium16, textColor: .GrayScale.gray900) + Spacer().frame(width: 6) + Image(systemName: "chevron.down") + .font(.system(size: 16, weight: .semibold)) + .rotationEffect(.degrees( isSelecting ? -180 : 0)) + } + .foregroundColor(.black) + + if isSelecting { + ScrollView { + VStack(spacing: 3) { + dropDownItemsList() + } + } + .background(Color.white) + .cornerRadius(5) + .shadow(color: Color.black.opacity(0.3), radius: 10, x: 0, y: 5) + .frame(height: 90) + } + } + .frame(maxWidth: .infinity) + .padding(.vertical) + .background(Color(uiColor: UIColor.systemBackground)) + .cornerRadius(10) + .onTapGesture { + isSelecting.toggle() + } + .onAppear { + selectedRowId = items[0].id + selectionTitle = items[0].title + } + .animation(.easeInOut(duration: 0.3)) + } + } + + private func dropDownItemsList() -> some View { + ForEach(items) { item in + DropdownMenuItemView(isSelecting: $isSelecting, selectionId: $selectedRowId, selectiontitle: $selectionTitle, item: item) + } + } +} + + +struct CustomDropdownMenu_Previews: PreviewProvider { + static var previews: some View { + VStack(alignment: .leading) { + HStack { + DropdownMenu(items: (1...12).map { index in + DropdownItem(id: index, title: "\(index)월", onSelect: {}) + }) + .padding(.leading, 40) + Spacer() + } + } + + } +} + +extension View { + func customDropdownMenu(items: [DropdownItem]) -> some View { + ZStack { + VStack { + DropdownMenu(items: items) + // .padding(.horizontal) + Spacer() + } + .zIndex(10) + self + .offset(y: 60) + .zIndex(1) + } + } +} From cde7add120deca1e75c7e9c97b91f7f48dc24e52 Mon Sep 17 00:00:00 2001 From: parkdoyeon1 Date: Wed, 14 Jun 2023 20:30:34 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=92=84=20::=20GrayScale=20gray10=20sh?= =?UTF-8?q?adowColor=20Add?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/SunshijoDesign/Color/GrayScale.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/SunshijoDesign/Color/GrayScale.swift b/Sources/SunshijoDesign/Color/GrayScale.swift index 2c872d6..10271bb 100644 --- a/Sources/SunshijoDesign/Color/GrayScale.swift +++ b/Sources/SunshijoDesign/Color/GrayScale.swift @@ -15,6 +15,7 @@ public extension Color.GrayScale { static let gray700: Color = #colorLiteral(red: 0.3019607663, green: 0.3019607663, blue: 0.3019607663, alpha: 1).color static let gray800: Color = #colorLiteral(red: 0.1607843041, green: 0.1607843041, blue: 0.1607843041, alpha: 1).color static let gray900: Color = #colorLiteral(red: 0.1019608006, green: 0.1019608006, blue: 0.1019608006, alpha: 1).color + static let gray10: Color = #colorLiteral(red: 0.178817153, green: 0.1396981776, blue: 0.1832496524, alpha: 1).color } // MARK: - White From dfe9a7559159868d9aa2719d15fe8dd6b1730d16 Mon Sep 17 00:00:00 2001 From: parkdoyeon1 Date: Wed, 14 Jun 2023 20:30:52 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=92=84=20::=20DropdownMenuItem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DropDown/DropdownMenuItemView.swift | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Sources/SunshijoDesign/DropDown/DropdownMenuItemView.swift diff --git a/Sources/SunshijoDesign/DropDown/DropdownMenuItemView.swift b/Sources/SunshijoDesign/DropDown/DropdownMenuItemView.swift new file mode 100644 index 0000000..c1a8768 --- /dev/null +++ b/Sources/SunshijoDesign/DropDown/DropdownMenuItemView.swift @@ -0,0 +1,31 @@ +import SwiftUI + +struct DropdownMenuItemView: View { + @Binding var isSelecting: Bool + @Binding var selectionId: Int + @Binding var selectiontitle: String + + let item: DropdownItem + + var body: some View { + Button(action: { + isSelecting = false + DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { + selectionId = item.id + } + selectiontitle = item.title + item.onSelect() + }) { + HStack(spacing: 20) { + Text(item.title) + .sdText(type: .medium16, textColor: .GrayScale.gray900) + Image(systemName: "checkmark") + .font(.system(size: 14, weight: .bold)) + .opacity(selectionId == item.id ? 1 : 0) + } + .frame(height: 20) + .foregroundColor(.black) + } + } + +} From a2c625e3b056e7d79b57121e5647c5b246dc2b8a Mon Sep 17 00:00:00 2001 From: parkdoyeon1 Date: Wed, 14 Jun 2023 20:31:12 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=92=84=20::=20DropdownPreview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DropDown/Preview/DropdownPreview.swift | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Sources/SunshijoDesign/DropDown/Preview/DropdownPreview.swift diff --git a/Sources/SunshijoDesign/DropDown/Preview/DropdownPreview.swift b/Sources/SunshijoDesign/DropDown/Preview/DropdownPreview.swift new file mode 100644 index 0000000..d1e95d3 --- /dev/null +++ b/Sources/SunshijoDesign/DropDown/Preview/DropdownPreview.swift @@ -0,0 +1,25 @@ +import SwiftUI + +struct DropdownPreview: View { + var body: some View { + VStack(alignment: .leading) { + Text("학사일정") + .sdText(type: .semiBold24, textColor: .GrayScale.gray900) + .padding(.top, 45) + HStack { + DropdownMenu(items: (1...12).map { index in + DropdownItem(id: index, title: "\(index)월", onSelect: {}) + }) + .padding(.leading, 44) + Spacer() + } + } + } + +} + +struct ContentView_Previews: PreviewProvider { + static var previews: some View { + DropdownPreview() + } +} From d21e463b1766e57ad7997b5e753a0466ea15e24d Mon Sep 17 00:00:00 2001 From: parkdoyeon1 Date: Thu, 15 Jun 2023 23:57:04 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=94=A5=20::=20dropdown=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DropDown/DropdownItem.swift | 7 -- .../DropDown/DropdownMenu.swift | 86 ------------------- .../DropDown/DropdownMenuItemView.swift | 31 ------- 3 files changed, 124 deletions(-) delete mode 100644 Sources/SunshijoDesign/DropDown/DropdownItem.swift delete mode 100644 Sources/SunshijoDesign/DropDown/DropdownMenu.swift delete mode 100644 Sources/SunshijoDesign/DropDown/DropdownMenuItemView.swift diff --git a/Sources/SunshijoDesign/DropDown/DropdownItem.swift b/Sources/SunshijoDesign/DropDown/DropdownItem.swift deleted file mode 100644 index 00cc3b1..0000000 --- a/Sources/SunshijoDesign/DropDown/DropdownItem.swift +++ /dev/null @@ -1,7 +0,0 @@ -import Foundation - -struct DropdownItem: Identifiable { - let id: Int - let title: String - let onSelect: () -> Void -} diff --git a/Sources/SunshijoDesign/DropDown/DropdownMenu.swift b/Sources/SunshijoDesign/DropDown/DropdownMenu.swift deleted file mode 100644 index 5e71365..0000000 --- a/Sources/SunshijoDesign/DropDown/DropdownMenu.swift +++ /dev/null @@ -1,86 +0,0 @@ -import SwiftUI - -struct DropdownMenu: View { - @State var isSelecting = false - @State var selectionTitle = "" - @State var selectedRowId = 0 - let items: [DropdownItem] - - var body: some View { - GeometryReader { _ in - VStack(spacing: 0) { - HStack { - Text(selectionTitle) - .sdText(type: .medium16, textColor: .GrayScale.gray900) - Spacer().frame(width: 6) - Image(systemName: "chevron.down") - .font(.system(size: 16, weight: .semibold)) - .rotationEffect(.degrees( isSelecting ? -180 : 0)) - } - .foregroundColor(.black) - - if isSelecting { - ScrollView { - VStack(spacing: 3) { - dropDownItemsList() - } - } - .background(Color.white) - .cornerRadius(5) - .shadow(color: Color.black.opacity(0.3), radius: 10, x: 0, y: 5) - .frame(height: 90) - } - } - .frame(maxWidth: .infinity) - .padding(.vertical) - .background(Color(uiColor: UIColor.systemBackground)) - .cornerRadius(10) - .onTapGesture { - isSelecting.toggle() - } - .onAppear { - selectedRowId = items[0].id - selectionTitle = items[0].title - } - .animation(.easeInOut(duration: 0.3)) - } - } - - private func dropDownItemsList() -> some View { - ForEach(items) { item in - DropdownMenuItemView(isSelecting: $isSelecting, selectionId: $selectedRowId, selectiontitle: $selectionTitle, item: item) - } - } -} - - -struct CustomDropdownMenu_Previews: PreviewProvider { - static var previews: some View { - VStack(alignment: .leading) { - HStack { - DropdownMenu(items: (1...12).map { index in - DropdownItem(id: index, title: "\(index)월", onSelect: {}) - }) - .padding(.leading, 40) - Spacer() - } - } - - } -} - -extension View { - func customDropdownMenu(items: [DropdownItem]) -> some View { - ZStack { - VStack { - DropdownMenu(items: items) - // .padding(.horizontal) - Spacer() - } - .zIndex(10) - self - .offset(y: 60) - .zIndex(1) - } - } -} diff --git a/Sources/SunshijoDesign/DropDown/DropdownMenuItemView.swift b/Sources/SunshijoDesign/DropDown/DropdownMenuItemView.swift deleted file mode 100644 index c1a8768..0000000 --- a/Sources/SunshijoDesign/DropDown/DropdownMenuItemView.swift +++ /dev/null @@ -1,31 +0,0 @@ -import SwiftUI - -struct DropdownMenuItemView: View { - @Binding var isSelecting: Bool - @Binding var selectionId: Int - @Binding var selectiontitle: String - - let item: DropdownItem - - var body: some View { - Button(action: { - isSelecting = false - DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { - selectionId = item.id - } - selectiontitle = item.title - item.onSelect() - }) { - HStack(spacing: 20) { - Text(item.title) - .sdText(type: .medium16, textColor: .GrayScale.gray900) - Image(systemName: "checkmark") - .font(.system(size: 14, weight: .bold)) - .opacity(selectionId == item.id ? 1 : 0) - } - .frame(height: 20) - .foregroundColor(.black) - } - } - -}