Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge :: 디자인 시스템의 View들을 모아서 볼 수 있는 View를 만듭니다 #36

Merged
merged 4 commits into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Projects/App/Sources/Application/DMSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DesignSystem
struct DMSApp: App {
var body: some Scene {
WindowGroup {
Text("WOW")
DesignSystemPlaygroundView()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import SwiftUI

public struct DMScheckboxStyle: ToggleStyle {
@Environment(\.isEnabled) var isEnabled: Bool

public func makeBody(configuration: Self.Configuration) -> some View {

Expand All @@ -9,6 +10,7 @@ public struct DMScheckboxStyle: ToggleStyle {
.resizable()
.frame(width: 24, height: 24)
.foregroundColor(configuration.isOn ? .PrimaryVariant.primary : .GrayScale.gray5)
.opacity(isEnabled ? 1.0 : 0.5)
.onTapGesture {
configuration.isOn.toggle()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import SwiftUI

public struct DesignSystemPlaygroundView: View {
let list: [(String, AnyView)] = [
("Color", AnyView(ColorPlaygroundView())),
("Text", AnyView(FontPlaygroundView())),
("Button", AnyView(ButtonPlaygroundView())),
("Switch", AnyView(SwitchPlaygroundView())),
("Checkbox", AnyView(CheckboxPlaygroundView())),
("TextField", AnyView(TextFieldPlaygroundView())),
("RadioButton", AnyView(RadiobuttonPlaygroundView()))
]

public init() {}

public var body: some View {
NavigationView {
List(list, id: \.0) { item in
NavigationLink {
item.1
} label: {
Text(item.0)
}
}
.navigationTitle("DesignSystem")
}
}
}

struct DeisgnSystemPlaygroundView_Previews: PreviewProvider {
static var previews: some View {
DesignSystemPlaygroundView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import SwiftUI

struct ButtonPlaygroundView: View {
var body: some View {
ScrollView {
VStack {
Group {
DMSButton(text: "Contained", color: .PrimaryVariant.primary)

DMSButton(text: "Contained", color: .PrimaryVariant.primary)
.disabled(true)

DMSButton(text: "Outlined", style: .outlined, color: .PrimaryVariant.primary)

DMSButton(text: "Outlined", style: .outlined, color: .PrimaryVariant.primary)
.disabled(true)

DMSButton(text: "Text", style: .text, color: .PrimaryVariant.primary)

DMSButton(text: "Text", style: .text, color: .PrimaryVariant.primary)
.disabled(true)

DMSButton(text: "Underlined", style: .underline, color: .PrimaryVariant.primary)

DMSButton(text: "Underlined", style: .underline, color: .PrimaryVariant.primary)
.disabled(true)
}
.padding(.vertical, 5)
}
}
}
}

struct ButtonPlaygroundView_Previews: PreviewProvider {
static var previews: some View {
ButtonPlaygroundView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import SwiftUI

struct CheckboxPlaygroundView: View {
@State var isOn = false
var body: some View {
ScrollView {
VStack {
DMSCheckBox(isOn: $isOn)

DMSCheckBox(isOn: $isOn)
.disabled(true)
}
}
}
}

struct CheckboxPlaygroundView_Previews: PreviewProvider {
static var previews: some View {
CheckboxPlaygroundView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import SwiftUI

struct ColorPlaygroundView: View {
let colors: [[Color]] = [
[
.PrimaryVariant.lighten2,
.PrimaryVariant.lighten2,
.PrimaryVariant.primary,
.PrimaryVariant.darken1,
.PrimaryVariant.darken2
],
[
.GrayScale.gray1,
.GrayScale.gray2,
.GrayScale.gray3,
.GrayScale.gray4,
.GrayScale.gray5,
.GrayScale.gray6,
.GrayScale.gray7,
.GrayScale.gray8,
.GrayScale.gray9
],
[
.System.background,
.System.surface,
.System.error,
.System.onError,
.System.onPrimary,
.System.onBackground,
.System.title,
.System.text,
.System.iconActive,
.System.iconInactive,
.System.line
]
]
let columns: [GridItem] = Array(repeating: .init(.flexible()), count: 10)

var body: some View {
ScrollView {
VStack {
ForEach(colors, id: \.hashValue) { subColors in
LazyVGrid(columns: columns) {
ForEach(subColors, id: \.hashValue) { color in
RoundedRectangle(cornerRadius: 4)
.fill(color)
.frame(height: 40)
}
}
.padding(.vertical)
}
}
}
.frame(maxWidth: .infinity)
.padding(.horizontal)
}
}

struct ColorPlaygroundView_Previews: PreviewProvider {
static var previews: some View {
ColorPlaygroundView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import SwiftUI

struct FontPlaygroundView: View {
let fonts: [(String, [DMSFontStyle])] = [
("Title", [
.title(.extraLarge),
.title(.large),
.title(.medium),
.title(.small),
.title(.extraSmall)
]),
("Text", [
.text(.twoExtraLarge),
.text(.extraLarge),
.text(.large),
.text(.medium),
.text(.small),
.text(.extraSmall),
.text(.twoExtraSmall)
]),
("Button", [
.button(.default)
])
]
var body: some View {
ScrollView {
VStack(alignment: .leading) {
ForEach(fonts, id: \.0) { proto in
Section {
Text(proto.0)
.dmsFont(.title(.extraLarge))
}

VStack(alignment: .leading) {
ForEach(proto.1, id: \.hashValue) { item in
Text("SampleText")
.dmsFont(item)
}
}
.padding(.vertical, 5)
}
}
.padding(.horizontal)
}
.frame(maxWidth: .infinity)
}
}

struct FontPlaygroundView_Previews: PreviewProvider {
static var previews: some View {
FontPlaygroundView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SwiftUI

struct RadiobuttonPlaygroundView: View {
@State var isOn = false
var body: some View {
ScrollView {
VStack {
DMSRadioButton(isOn: $isOn)

DMSRadioButton(isOn: $isOn)
.disabled(true)
}
.padding()
}
}
}

struct RadiobuttonPlaygroundView_Previews: PreviewProvider {
static var previews: some View {
RadiobuttonPlaygroundView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import SwiftUI

struct SwitchPlaygroundView: View {
@State var isOn = false
var body: some View {
ScrollView {
VStack {
DMSSwitch(isOn: $isOn)

DMSSwitch(isOn: $isOn)
.disabled(true)
}
.padding()
}
.frame(maxWidth: .infinity)
}
}

struct SwitchPlaygroundView_Previews: PreviewProvider {
static var previews: some View {
SwitchPlaygroundView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import SwiftUI

struct TextFieldPlaygroundView: View {
@State var text1 = ""
@State var text2 = ""
@State var text3 = ""
@State var text4 = ""
@State var text5 = ""
@State var text6 = ""
@State var isError1 = false

var body: some View {
ScrollView {
VStack(spacing: 40) {
DMSFloatingTextField("아이디", text: $text1)

SecureDMSFloatingTextField("비밀번호", text: $text2)

DMSFloatingTextField("HelpText", text: $text3, helpMessage: "HelpText")

DMSFloatingTextField(
"Error",
text: $text4,
helpMessage: "HelpText",
isError: isError1,
errorMessage: "Error Message"
) {
isError1.toggle()
}

DMSFormTextField("제목을 입력해주세요", text: $text5)

DMSFormTextEditor("내용을 입력해주세요", text: $text6)
}
.padding()
}
}
}

struct TextFieldPlaygroundView_Previews: PreviewProvider {
static var previews: some View {
TextFieldPlaygroundView()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public struct DMSRadioButton: View {
@Environment(\.isEnabled) private var isEnabled: Bool

public init(
isOn: Binding<Bool> = .constant(false)
isOn: Binding<Bool>
) {
self._isOn = isOn
}
Expand All @@ -15,22 +15,27 @@ public struct DMSRadioButton: View {
self.isOn.toggle()
} label: {
ZStack {
Circle()
.fill(Color.PrimaryVariant.primary)
.frame(width: 20, height: 20)
Circle()
.fill(Color.white)
.frame(width: 15, height: 15)
Circle()
.fill(Color.PrimaryVariant.primary)
.frame(width: 10, height: 10)
Group {
Circle()
.stroke(isOn ? Color.PrimaryVariant.primary : .GrayScale.gray5, lineWidth: 2)
.frame(width: 20, height: 20)

Circle()
.fill(isOn ? Color.PrimaryVariant.primary : .clear)
.frame(width: 10, height: 10)
}
.opacity(isEnabled ? 1.0 : 0.5)
}
}
}
}

struct DMSRadioButton_Previews: PreviewProvider {
static var previews: some View {
DMSRadioButton(isOn: .constant(true))
VStack {
DMSRadioButton(isOn: .constant(true))

DMSRadioButton(isOn: .constant(false))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ protocol DMSFontable {
var weight: Font.Weight { get }
}

public enum DMSFontStyle {
public enum DMSFontStyle: Hashable {
case title(DMSFontStyle.Title)
case text(DMSFontStyle.Text)
case button(DMSFontStyle.Button)
Expand Down